mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-09-29 01:59:48 +08:00
build: use tsup instead of esbuild for packages (@fehmer) (#6309)
This commit is contained in:
parent
4a22c0647b
commit
2b2d1a153e
14 changed files with 503 additions and 238 deletions
|
@ -2,25 +2,25 @@
|
|||
"name": "@monkeytype/contracts",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "rimraf ./dist && monkeytype-esbuild --watch",
|
||||
"build": "rimraf ./dist && npm run madge && monkeytype-esbuild",
|
||||
"dev": "tsup-node --watch",
|
||||
"build": "npm run madge && tsup-node",
|
||||
"test": "vitest run",
|
||||
"madge": " madge --circular --extensions ts ./src",
|
||||
"ts-check": "tsc --noEmit",
|
||||
"lint": "eslint \"./**/*.ts\""
|
||||
},
|
||||
"dependencies": {
|
||||
"peerDependencies": {
|
||||
"@ts-rest/core": "3.51.0",
|
||||
"zod": "3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@monkeytype/esbuild": "workspace:*",
|
||||
"@monkeytype/eslint-config": "workspace:*",
|
||||
"@monkeytype/tsup-config": "workspace:*",
|
||||
"@monkeytype/typescript-config": "workspace:*",
|
||||
"chokidar": "3.6.0",
|
||||
"eslint": "8.57.1",
|
||||
"madge": "8.0.0",
|
||||
"rimraf": "6.0.1",
|
||||
"tsup": "8.4.0",
|
||||
"typescript": "5.5.4",
|
||||
"vitest": "2.1.9"
|
||||
},
|
||||
|
@ -28,12 +28,12 @@
|
|||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
"require": "./dist/index.js"
|
||||
},
|
||||
"./*": {
|
||||
"types": "./src/*.ts",
|
||||
"import": "./dist/*.mjs",
|
||||
"require": "./dist/*.cjs"
|
||||
"require": "./dist/*.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
3
packages/contracts/tsup.config.js
Normal file
3
packages/contracts/tsup.config.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { extendConfig } from "@monkeytype/tsup-config";
|
||||
|
||||
export default extendConfig();
|
|
@ -1,95 +0,0 @@
|
|||
const esbuild = require("esbuild");
|
||||
const { readdirSync, statSync } = require("fs");
|
||||
const { join, extname } = require("path");
|
||||
const chokidar = require("chokidar");
|
||||
|
||||
//check if watch parameter is passed
|
||||
const isWatch = process.argv.includes("--watch");
|
||||
|
||||
// Recursive function to get all .ts files in a directory
|
||||
const getAllFiles = (dirPath, arrayOfFiles = []) => {
|
||||
const files = readdirSync(dirPath);
|
||||
|
||||
files.forEach((file) => {
|
||||
const filePath = join(dirPath, file);
|
||||
if (statSync(filePath).isDirectory()) {
|
||||
arrayOfFiles = getAllFiles(filePath, arrayOfFiles);
|
||||
} else if (extname(file) === ".ts") {
|
||||
arrayOfFiles.push(filePath);
|
||||
}
|
||||
});
|
||||
|
||||
return arrayOfFiles;
|
||||
};
|
||||
|
||||
// Get all TypeScript files from the src directory and subdirectories
|
||||
const entryPoints = getAllFiles("./src");
|
||||
|
||||
// Function to generate output file names
|
||||
const getOutfile = (entryPoint, format) => {
|
||||
const relativePath = entryPoint.replace(/src[/\\]/, "");
|
||||
const fileBaseName = relativePath.replace(".ts", "");
|
||||
return `./dist/${fileBaseName}.${format === "esm" ? "mjs" : "cjs"}`;
|
||||
};
|
||||
|
||||
// Common build settings
|
||||
const commonSettings = {
|
||||
bundle: true,
|
||||
sourcemap: true,
|
||||
minify: true,
|
||||
};
|
||||
|
||||
function buildAll(silent, stopOnError) {
|
||||
console.log("Building all files...");
|
||||
entryPoints.forEach((entry) => {
|
||||
build(entry, silent, stopOnError);
|
||||
});
|
||||
}
|
||||
|
||||
function build(entry, silent, stopOnError) {
|
||||
if (!silent) console.log("Building", entry);
|
||||
|
||||
// ESM build
|
||||
esbuild
|
||||
.build({
|
||||
...commonSettings,
|
||||
entryPoints: [entry],
|
||||
format: "esm",
|
||||
outfile: getOutfile(entry, "esm"),
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(`Failed to build ${entry} to ESM:`, e);
|
||||
if (stopOnError) process.exit(1);
|
||||
});
|
||||
|
||||
// CommonJS build
|
||||
esbuild
|
||||
.build({
|
||||
...commonSettings,
|
||||
entryPoints: [entry],
|
||||
format: "cjs",
|
||||
outfile: getOutfile(entry, "cjs"),
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(`Failed to build ${entry} to CJS:`, e);
|
||||
if (stopOnError) process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
if (isWatch) {
|
||||
buildAll(true, false);
|
||||
console.log("Starting watch mode...");
|
||||
chokidar.watch("./src/**/*.ts").on(
|
||||
"change",
|
||||
(_path) => {
|
||||
console.log("File change detected...");
|
||||
// build(path, false, false);
|
||||
buildAll(false, false);
|
||||
},
|
||||
{
|
||||
ignoreInitial: true,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
buildAll(false, true);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"name": "@monkeytype/esbuild",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "eslint \"./**/*.js\""
|
||||
},
|
||||
"bin": {
|
||||
"monkeytype-esbuild": "./index.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "0.25.0",
|
||||
"eslint": "8.57.1"
|
||||
}
|
||||
}
|
|
@ -2,20 +2,20 @@
|
|||
"name": "@monkeytype/funbox",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "rimraf ./dist && monkeytype-esbuild --watch",
|
||||
"build": "rimraf ./dist && npm run madge && monkeytype-esbuild",
|
||||
"dev": "tsup-node --watch",
|
||||
"build": "npm run madge && tsup-node",
|
||||
"madge": " madge --circular --extensions ts ./src",
|
||||
"ts-check": "tsc --noEmit",
|
||||
"lint": "eslint \"./**/*.ts\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@monkeytype/esbuild": "workspace:*",
|
||||
"@monkeytype/eslint-config": "workspace:*",
|
||||
"@monkeytype/tsup-config": "workspace:*",
|
||||
"@monkeytype/typescript-config": "workspace:*",
|
||||
"chokidar": "3.6.0",
|
||||
"eslint": "8.57.1",
|
||||
"madge": "8.0.0",
|
||||
"rimraf": "6.0.1",
|
||||
"tsup": "8.4.0",
|
||||
"typescript": "5.5.4",
|
||||
"vitest": "2.1.9"
|
||||
},
|
||||
|
@ -26,7 +26,7 @@
|
|||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
"require": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
3
packages/funbox/tsup.config.js
Normal file
3
packages/funbox/tsup.config.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { extendConfig } from "@monkeytype/tsup-config";
|
||||
|
||||
export default extendConfig(() => ({ entry: ["src/index.ts"] }));
|
24
packages/tsup-config/package.json
Normal file
24
packages/tsup-config/package.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "@monkeytype/tsup-config",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "tsup-node --watch",
|
||||
"build": "tsup-node",
|
||||
"ts-check": "tsc --noEmit"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"tsup": "8.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@monkeytype/typescript-config": "workspace:*",
|
||||
"eslint": "8.57.1",
|
||||
"typescript": "5.5.4"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
}
|
23
packages/tsup-config/src/index.ts
Normal file
23
packages/tsup-config/src/index.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { defineConfig, Options } from "tsup";
|
||||
|
||||
export function extendConfig(
|
||||
customizer?: (options: Options) => Options
|
||||
// tsup uses MaybePromise which is not exported
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
): (options: Options) => any {
|
||||
return (options) => {
|
||||
const overrideOptions = customizer?.(options);
|
||||
const config: Options = {
|
||||
entry: ["src/**/*.ts"],
|
||||
splitting: false,
|
||||
sourcemap: true,
|
||||
clean: !(options.watch === true || options.watch === "true"),
|
||||
format: ["cjs", "esm"],
|
||||
dts: false,
|
||||
minify: true,
|
||||
...(overrideOptions || {}),
|
||||
};
|
||||
|
||||
return defineConfig(config);
|
||||
};
|
||||
}
|
15
packages/tsup-config/tsconfig.json
Normal file
15
packages/tsup-config/tsconfig.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"extends": "@monkeytype/typescript-config/base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"moduleResolution": "Node",
|
||||
"module": "ES6",
|
||||
"target": "ES2015",
|
||||
"lib": ["es2016"]
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
10
packages/tsup-config/tsup.config.js
Normal file
10
packages/tsup-config/tsup.config.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { defineConfig } from "tsup";
|
||||
|
||||
export default defineConfig((_options) => ({
|
||||
entry: ["src/index.ts"],
|
||||
splitting: false,
|
||||
sourcemap: false,
|
||||
clear: !_options.watch,
|
||||
format: ["cjs", "esm"],
|
||||
dts: false,
|
||||
}));
|
|
@ -1,36 +1,30 @@
|
|||
{
|
||||
"name": "@monkeytype/util",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "rimraf ./dist && monkeytype-esbuild --watch",
|
||||
"build": "rimraf ./dist && npm run madge && monkeytype-esbuild",
|
||||
"dev": "tsup-node --watch",
|
||||
"build": "npm run madge && tsup-node",
|
||||
"test": "vitest run",
|
||||
"madge": " madge --circular --extensions ts ./src",
|
||||
"ts-check": "tsc --noEmit",
|
||||
"lint": "eslint \"./**/*.ts\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@monkeytype/esbuild": "workspace:*",
|
||||
"@monkeytype/eslint-config": "workspace:*",
|
||||
"@monkeytype/tsup-config": "workspace:*",
|
||||
"@monkeytype/typescript-config": "workspace:*",
|
||||
"chokidar": "3.6.0",
|
||||
"eslint": "8.57.1",
|
||||
"madge": "8.0.0",
|
||||
"rimraf": "6.0.1",
|
||||
"tsup": "8.4.0",
|
||||
"typescript": "5.5.4",
|
||||
"vitest": "2.1.9",
|
||||
"zod": "3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./*": {
|
||||
"types": "./src/*.ts",
|
||||
"import": "./dist/*.mjs",
|
||||
"require": "./dist/*.cjs"
|
||||
"require": "./dist/*.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
3
packages/util/tsup.config.js
Normal file
3
packages/util/tsup.config.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { extendConfig } from "@monkeytype/tsup-config";
|
||||
|
||||
export default extendConfig();
|
511
pnpm-lock.yaml
generated
511
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue