Skip to content

Commit 4eb0e3a

Browse files
authored
chore(website): update build script to use esbuild instead of rollup (#6716)
1 parent 2db2bfc commit 4eb0e3a

File tree

23 files changed

+251
-423
lines changed

23 files changed

+251
-423
lines changed

.github/renovate.json5

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
1616
'@nrwl/jest',
1717
'@nrwl/nx-cloud',
1818
'@nrwl/tao',
19-
// TODO - once we bump pass the major, we can remove these. Currently renovate is creating broken, immortal PRs
20-
'@rollup/plugin-babel',
21-
'@rollup/plugin-commonjs',
22-
'@rollup/plugin-json',
23-
'@rollup/plugin-node-resolve',
24-
'@rollup/plugin-replace',
25-
'@rollup/plugin-terser',
26-
'@rollup/pluginutils',
27-
'rollup-plugin-terser',
28-
'rollup',
2919
],
3020
ignorePaths: [
3121
// integration test package.json's should never be updated as they're purposely fixed tests
@@ -85,11 +75,6 @@
8575
matchPackagePrefixes: ['@types/jest', 'jest-', '@jest/'],
8676
groupName: 'jest',
8777
},
88-
{
89-
matchPackagePrefixes: ['@rollup', 'rollup-'],
90-
matchPackageNames: ['rollup'],
91-
groupName: 'rollup',
92-
},
9378
],
9479
postUpdateOptions: [
9580
// run yarn dedupe to cleanup the lockfile after updates

packages/scope-manager/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
"types": "./dist/index.d.ts",
1515
"default": "./dist/index.js"
1616
},
17-
"./package.json": "./package.json",
18-
"./use-at-your-own-risk/analyze": {
19-
"types": "./dist/analyze.d.ts",
20-
"default": "./dist/analyze.js"
21-
}
17+
"./package.json": "./package.json"
2218
},
2319
"engines": {
2420
"node": "^14.18.0 || ^16.0.0 || >=18.0.0"

packages/typescript-estree/package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,9 @@
1515
"default": "./dist/index.js"
1616
},
1717
"./package.json": "./package.json",
18-
"./use-at-your-own-risk/ast-converter": {
19-
"types": "./dist/ast-converter.d.ts",
20-
"default": "./dist/ast-converter.js"
21-
},
22-
"./use-at-your-own-risk/parseSettings": {
23-
"types": "./dist/parseSettings/index.d.ts",
24-
"default": "./dist/parseSettings/index.js"
25-
},
26-
"./use-at-your-own-risk/getScriptKind": {
27-
"types": "./dist/create-program/getScriptKind.d.ts",
28-
"default": "./dist/create-program/getScriptKind.js"
18+
"./use-at-your-own-risk": {
19+
"types": "./dist/use-at-your-own-risk.d.ts",
20+
"default": "./dist/use-at-your-own-risk.js"
2921
}
3022
},
3123
"engines": {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// required by website
2+
export * from './create-program/getScriptKind';
3+
export * from './ast-converter';
4+
export type { ParseSettings } from './parseSettings';
5+
6+
// required by packages/utils/src/ts-estree.ts
7+
export * from './getModifiers';
8+
export { typescriptVersionIsAtLeast } from './version-check';

packages/visitor-keys/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
"types": "./dist/index.d.ts",
1616
"default": "./dist/index.js"
1717
},
18-
"./package.json": "./package.json",
19-
"./use-at-your-own-risk/visitor-keys": {
20-
"types": "./dist/visitor-keys.d.ts",
21-
"default": "./dist/visitor-keys.js"
22-
}
18+
"./package.json": "./package.json"
2319
},
2420
"engines": {
2521
"node": "^14.18.0 || ^16.0.0 || >=18.0.0"

packages/website-eslint/build.ts

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/* eslint-disable no-process-exit, no-console */
2+
3+
import * as fs from 'node:fs/promises';
4+
import { createRequire } from 'node:module';
5+
import * as path from 'node:path';
6+
7+
import * as esbuild from 'esbuild';
8+
9+
function requireResolved(targetPath: string): string {
10+
return createRequire(__filename).resolve(targetPath);
11+
}
12+
13+
function normalizePath(filePath: string): string {
14+
return filePath.replace(/\\/g, '/');
15+
}
16+
17+
function requireMock(targetPath: string): Promise<string> {
18+
return fs.readFile(requireResolved(targetPath), 'utf8');
19+
}
20+
21+
function makeFilter(filePath: string | string[]): { filter: RegExp } {
22+
const paths = Array.isArray(filePath) ? filePath : [filePath];
23+
const norm = paths.map(item =>
24+
normalizePath(item).replace(/\//g, '[\\\\/]').replace(/\./g, '\\.'),
25+
);
26+
return { filter: new RegExp('(' + norm.join('|') + ')$') };
27+
}
28+
29+
function createResolve(
30+
targetPath: string,
31+
join: string,
32+
): esbuild.OnResolveResult {
33+
const resolvedPackage = requireResolved(targetPath + '/package.json');
34+
return {
35+
path: path.join(resolvedPackage, '../src/', join),
36+
};
37+
}
38+
39+
async function buildPackage(name: string, file: string): Promise<void> {
40+
const eslintRoot = requireResolved('eslint/package.json');
41+
const linterPath = path.join(eslintRoot, '../lib/linter/linter.js');
42+
const rulesPath = path.join(eslintRoot, '../lib/rules/index.js');
43+
44+
await esbuild.build({
45+
entryPoints: {
46+
[name]: requireResolved(file),
47+
},
48+
format: 'cjs',
49+
platform: 'browser',
50+
bundle: true,
51+
external: [],
52+
minify: true,
53+
treeShaking: true,
54+
write: true,
55+
target: 'es2020',
56+
sourcemap: 'linked',
57+
outdir: './dist/',
58+
supported: {},
59+
banner: {
60+
// https://github.com/evanw/esbuild/issues/819
61+
js: `define(['exports', 'vs/language/typescript/tsWorker'], function (exports) {`,
62+
},
63+
footer: {
64+
// https://github.com/evanw/esbuild/issues/819
65+
js: `});`,
66+
},
67+
define: {
68+
'process.env.NODE_ENV': '"production"',
69+
'process.env.NODE_DEBUG': 'false',
70+
'process.env.IGNORE_TEST_WIN32': 'true',
71+
'process.env.DEBUG': 'false',
72+
'process.emitWarning': 'console.warn',
73+
'process.platform': '"browser"',
74+
'process.env.TIMING': 'undefined',
75+
'define.amd': 'false',
76+
global: 'window',
77+
},
78+
alias: {
79+
util: requireResolved('./src/mock/util.js'),
80+
assert: requireResolved('./src/mock/assert.js'),
81+
path: requireResolved('./src/mock/path.js'),
82+
typescript: requireResolved('./src/mock/typescript.js'),
83+
'lru-cache': requireResolved('./src/mock/lru-cache.js'),
84+
},
85+
plugins: [
86+
{
87+
name: 'replace-plugin',
88+
setup(build): void {
89+
build.onLoad(
90+
makeFilter([
91+
'/eslint-utils/rule-tester/RuleTester.ts',
92+
'/ts-eslint/ESLint.ts',
93+
'/ts-eslint/RuleTester.ts',
94+
'/ts-eslint/CLIEngine.ts',
95+
]),
96+
async args => {
97+
console.log('onLoad:replace', args.path);
98+
const contents = await requireMock('./src/mock/empty.js');
99+
return { contents, loader: 'js' };
100+
},
101+
);
102+
build.onLoad(
103+
makeFilter('/eslint/lib/unsupported-api.js'),
104+
async args => {
105+
console.log('onLoad:eslint:unsupported-api', args.path);
106+
let contents = await requireMock('./src/mock/eslint-rules.js');
107+
// this is needed to bypass system module resolver
108+
contents = contents.replace(
109+
'vt:eslint/rules',
110+
normalizePath(rulesPath),
111+
);
112+
return { contents, loader: 'js' };
113+
},
114+
);
115+
build.onLoad(makeFilter('/eslint/lib/api.js'), async args => {
116+
console.log('onLoad:eslint', args.path);
117+
let text = await requireMock('./src/mock/eslint.js');
118+
// this is needed to bypass system module resolver
119+
text = text.replace('vt:eslint/linter', normalizePath(linterPath));
120+
return { contents: text, loader: 'js' };
121+
});
122+
build.onResolve(
123+
makeFilter([
124+
'@typescript-eslint/typescript-estree',
125+
'@typescript-eslint/typescript-estree/use-at-your-own-risk',
126+
]),
127+
() =>
128+
createResolve(
129+
'@typescript-eslint/typescript-estree',
130+
'use-at-your-own-risk.ts',
131+
),
132+
);
133+
const anyAlias = /^(@typescript-eslint\/[a-z-]+)\/([a-z-]+)$/;
134+
build.onResolve({ filter: anyAlias }, args => {
135+
const parts = args.path.match(anyAlias);
136+
if (parts) {
137+
return createResolve(parts[1], `${parts[2]}/index.ts`);
138+
}
139+
return null;
140+
});
141+
build.onResolve(makeFilter('@typescript-eslint/[a-z-]+'), args =>
142+
createResolve(args.path, 'index.ts'),
143+
);
144+
build.onEnd(e => {
145+
for (const error of e.errors) {
146+
console.error(error);
147+
}
148+
for (const warning of e.warnings) {
149+
console.warn(warning);
150+
}
151+
});
152+
},
153+
},
154+
],
155+
});
156+
}
157+
158+
console.time('building eslint for web');
159+
160+
buildPackage('index', './src/index.js')
161+
.then(() => {
162+
console.timeEnd('building eslint for web');
163+
})
164+
.catch((e: unknown) => {
165+
console.error(String(e));
166+
process.exit(1);
167+
});

packages/website-eslint/package.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,22 @@
1717
"node": "^14.18.0 || ^16.0.0 || >=18.0.0"
1818
},
1919
"scripts": {
20-
"build": "rollup --config=rollup.config.js",
20+
"build": "yarn tsx ./build.ts",
2121
"format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore",
2222
"lint": "nx lint",
2323
"typecheck": "tsc --noEmit"
2424
},
25-
"dependencies": {
26-
"@typescript-eslint/types": "5.56.0",
27-
"@typescript-eslint/utils": "5.56.0"
28-
},
2925
"devDependencies": {
30-
"@rollup/plugin-commonjs": "^23.0.0",
31-
"@rollup/plugin-json": "^5.0.0",
32-
"@rollup/plugin-node-resolve": "^15.0.0",
33-
"@rollup/plugin-terser": "^0.4.0",
34-
"@rollup/pluginutils": "^5.0.0",
3526
"@typescript-eslint/eslint-plugin": "5.56.0",
3627
"@typescript-eslint/parser": "5.56.0",
3728
"@typescript-eslint/scope-manager": "5.56.0",
3829
"@typescript-eslint/typescript-estree": "5.56.0",
3930
"@typescript-eslint/visitor-keys": "5.56.0",
31+
"@typescript-eslint/types": "5.56.0",
32+
"@typescript-eslint/utils": "5.56.0",
4033
"eslint": "*",
34+
"esbuild": "~0.17.12",
4135
"esquery": "*",
42-
"magic-string": "0.25.9",
43-
"rollup": "^2.75.4",
4436
"semver": "^7.3.7"
4537
}
4638
}

packages/website-eslint/rollup-plugin/replace.js

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

0 commit comments

Comments
 (0)