Skip to content

Commit cea97cf

Browse files
matejchalkBioPhoton
authored andcommitted
chore: implement custom tsup executor to replace rollup
1 parent a93a082 commit cea97cf

File tree

11 files changed

+1343
-654
lines changed

11 files changed

+1343
-654
lines changed

package-lock.json

Lines changed: 1237 additions & 571 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"name": "@quality-metrics-cli/source",
33
"version": "0.0.0",
44
"license": "MIT",
5-
"scripts": {
6-
"postinstall": "patch-package"
7-
},
5+
"scripts": {},
86
"private": true,
97
"workspaces": [
108
"dist/packages/*"
@@ -13,7 +11,8 @@
1311
"@nx/devkit": "16.7.4",
1412
"@swc/helpers": "~0.5.0",
1513
"jiti": "^1.19.3",
16-
"tslib": "^2.3.0"
14+
"tslib": "^2.3.0",
15+
"tsup": "^7.2.0"
1716
},
1817
"devDependencies": {
1918
"@nx/jest": "16.7.4",
@@ -37,10 +36,10 @@
3736
"lighthouse": "^11.0.0",
3837
"nx": "16.7.0",
3938
"nx-cloud": "latest",
40-
"patch-package": "^8.0.0",
4139
"prettier": "^2.6.2",
4240
"ts-jest": "^29.1.0",
4341
"ts-node": "10.9.1",
42+
"type-fest": "^4.3.1",
4443
"typescript": "~5.1.3",
4544
"verdaccio": "^5.0.4",
4645
"vite": "~4.3.9",

packages/cli/project.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@
55
"projectType": "library",
66
"targets": {
77
"build": {
8-
"executor": "@nx/rollup:rollup",
8+
"executor": "@quality-metrics/nx-plugin:tsup",
99
"outputs": ["{options.outputPath}"],
1010
"options": {
1111
"outputPath": "dist/packages/cli",
1212
"main": "packages/cli/src/index.ts",
1313
"tsConfig": "packages/cli/tsconfig.lib.json",
14-
"assets": [],
1514
"project": "packages/cli/package.json",
16-
"compiler": "tsc",
17-
"format": ["esm"],
18-
"external": "all",
19-
"rollupConfig": "rollup.config.js"
15+
"format": ["esm"]
2016
}
2117
},
2218
"publish": {

packages/nx-plugin/src/executors/tsup/executor.spec.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/nx-plugin/src/executors/tsup/executor.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
1+
import { readJsonFile, writeJsonFile } from '@nx/devkit';
2+
import { basename } from 'path';
3+
import { build } from 'tsup';
4+
import type { PackageJson } from 'type-fest';
15
import { TsupExecutorSchema } from './schema';
26

37
export default async function runExecutor(options: TsupExecutorSchema) {
4-
console.log('Executor ran for Tsup', options);
8+
await build({
9+
entry: [options.main],
10+
outDir: options.outputPath,
11+
tsconfig: options.tsConfig,
12+
platform: 'node',
13+
format: options.format,
14+
dts: true,
15+
cjsInterop: true,
16+
splitting: true,
17+
clean: options.deleteOutputPath,
18+
skipNodeModulesBundle: true,
19+
});
20+
21+
const packageJson = readJsonFile<PackageJson>(options.project);
22+
23+
const entryName = basename(options.main).replace(/\.[tj]s$/, '');
24+
const typesPath = options.format.includes('cjs')
25+
? `./${entryName}.d.ts`
26+
: `./${entryName}.d.mts`;
27+
const esmPath = `./${entryName}.mjs`;
28+
const cjsPath = `./${entryName}.js`;
29+
30+
packageJson.exports = {
31+
'.': {
32+
types: typesPath,
33+
...(options.format.includes('esm') && { import: esmPath }),
34+
...(options.format.includes('cjs') && { require: cjsPath }),
35+
default: options.format.includes('cjs') ? cjsPath : esmPath,
36+
},
37+
'./package.json': './package.json',
38+
};
39+
packageJson.main = options.format.includes('cjs') ? cjsPath : esmPath;
40+
if (options.format.includes('esm')) {
41+
packageJson.module = esmPath;
42+
}
43+
packageJson.types = typesPath;
44+
45+
writeJsonFile(`${options.outputPath}/package.json`, packageJson);
46+
547
return {
648
success: true,
749
};
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
export interface TsupExecutorSchema {} // eslint-disable-line
1+
export type TsupExecutorSchema = {
2+
project: string;
3+
main: string;
4+
outputPath: string;
5+
deleteOutputPath: boolean;
6+
tsConfig: string;
7+
format: ('esm' | 'cjs')[];
8+
};
Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
11
{
22
"$schema": "http://json-schema.org/schema",
33
"version": 2,
4-
"title": "Tsup executor",
4+
"title": "tsup executor",
55
"description": "",
66
"type": "object",
7-
"properties": {},
8-
"required": []
7+
"properties": {
8+
"project": {
9+
"type": "string",
10+
"description": "The path to package.json file.",
11+
"x-priority": "important"
12+
},
13+
"main": {
14+
"type": "string",
15+
"description": "The path to the entry file, relative to project.",
16+
"alias": "entryFile",
17+
"x-completion-type": "file",
18+
"x-completion-glob": "**/*@(.js|.ts)",
19+
"x-priority": "important"
20+
},
21+
"outputPath": {
22+
"type": "string",
23+
"description": "The output path of the generated files.",
24+
"x-completion-type": "directory",
25+
"x-priority": "important"
26+
},
27+
"deleteOutputPath": {
28+
"type": "boolean",
29+
"description": "Delete the output path before building.",
30+
"default": true
31+
},
32+
"tsConfig": {
33+
"type": "string",
34+
"description": "The path to tsconfig file.",
35+
"x-completion-type": "file",
36+
"x-completion-glob": "tsconfig.*.json",
37+
"x-priority": "important"
38+
},
39+
"format": {
40+
"type": "array",
41+
"description": "List of module formats to output. Defaults to both ESM and CJS.",
42+
"alias": "f",
43+
"items": {
44+
"type": "string",
45+
"enum": ["esm", "cjs"]
46+
},
47+
"default": ["esm", "cjs"]
48+
}
49+
},
50+
"required": ["tsConfig", "main", "outputPath"]
951
}

packages/plugin-eslint/project.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@
55
"projectType": "library",
66
"targets": {
77
"build": {
8-
"executor": "@nx/rollup:rollup",
8+
"executor": "@quality-metrics/nx-plugin:tsup",
99
"outputs": ["{options.outputPath}"],
1010
"options": {
1111
"outputPath": "dist/packages/plugin-eslint",
1212
"main": "packages/plugin-eslint/src/index.ts",
1313
"tsConfig": "packages/plugin-eslint/tsconfig.lib.json",
14-
"assets": [],
15-
"project": "packages/plugin-eslint/package.json",
16-
"compiler": "tsc",
17-
"format": ["cjs", "esm"],
18-
"external": "all",
19-
"generateExportsField": true,
20-
"rollupConfig": "rollup.config.js"
14+
"project": "packages/plugin-eslint/package.json"
2115
}
2216
},
2317
"publish": {

packages/plugin-lighthouse/project.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55
"projectType": "library",
66
"targets": {
77
"build": {
8-
"executor": "@nx/rollup:rollup",
8+
"executor": "@quality-metrics/nx-plugin:tsup",
99
"outputs": ["{options.outputPath}"],
1010
"options": {
1111
"outputPath": "dist/packages/plugin-lighthouse",
1212
"main": "packages/plugin-lighthouse/src/index.ts",
1313
"tsConfig": "packages/plugin-lighthouse/tsconfig.lib.json",
14-
"assets": [],
1514
"project": "packages/plugin-lighthouse/package.json",
16-
"compiler": "tsc",
17-
"format": ["esm"],
18-
"external": "all",
19-
"generateExportsField": true,
20-
"rollupConfig": "rollup.config.js"
15+
"format": ["esm"]
2116
}
2217
},
2318
"lint": {

patches/@nx+rollup+16.7.0.patch

Lines changed: 0 additions & 22 deletions
This file was deleted.

rollup.config.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)