Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
chore(website): update build script to use esbuild instead of rollup#6716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
01b9f00
chore(website-eslint): update build script to use esbuild instead of …
armano2ae2b1b1
Merge remote-tracking branch 'origin/v6' into chore/website-eslint-im…
armano2539e391
fix: correct linting issues
armano2730a92c
Merge remote-tracking branch 'origin/v6' into chore/website-eslint-im…
armano23a68591
chore: build bundle from source code and remove unnecessary use-at-yo…
armano2f6fb77f
fix: correct displaying errors and warning
armano222b855b
fix: build code as iife to not pollute global scope
armano2f1799d9
fix: use banner & footer as amd wrapper
armano258d543d
fix: add missing support for aliases
armano2cf761c6
Merge branch 'v6' into chore/website-eslint-improve-build
armano28c9a0cd
chore: restore missing comment
armano22d992dc
chore: remove rollup from renovate
armano2File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
15 changes: 0 additions & 15 deletions.github/renovate.json5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletionspackages/scope-manager/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 3 additions & 11 deletionspackages/typescript-estree/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletionspackages/typescript-estree/src/use-at-your-own-risk.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// required by website | ||
export * from './create-program/getScriptKind'; | ||
export * from './ast-converter'; | ||
export type { ParseSettings } from './parseSettings'; | ||
// required by packages/utils/src/ts-estree.ts | ||
export * from './getModifiers'; | ||
export { typescriptVersionIsAtLeast } from './version-check'; |
6 changes: 1 addition & 5 deletionspackages/visitor-keys/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletionspackages/website-eslint/build.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/* eslint-disable no-process-exit, no-console */ | ||
import * as fs from 'node:fs/promises'; | ||
import { createRequire } from 'node:module'; | ||
import * as path from 'node:path'; | ||
import * as esbuild from 'esbuild'; | ||
function requireResolved(targetPath: string): string { | ||
return createRequire(__filename).resolve(targetPath); | ||
} | ||
function normalizePath(filePath: string): string { | ||
return filePath.replace(/\\/g, '/'); | ||
} | ||
function requireMock(targetPath: string): Promise<string> { | ||
return fs.readFile(requireResolved(targetPath), 'utf8'); | ||
} | ||
function makeFilter(filePath: string | string[]): { filter: RegExp } { | ||
const paths = Array.isArray(filePath) ? filePath : [filePath]; | ||
const norm = paths.map(item => | ||
normalizePath(item).replace(/\//g, '[\\\\/]').replace(/\./g, '\\.'), | ||
); | ||
return { filter: new RegExp('(' + norm.join('|') + ')$') }; | ||
} | ||
function createResolve( | ||
targetPath: string, | ||
join: string, | ||
): esbuild.OnResolveResult { | ||
const resolvedPackage = requireResolved(targetPath + '/package.json'); | ||
return { | ||
path: path.join(resolvedPackage, '../src/', join), | ||
}; | ||
} | ||
async function buildPackage(name: string, file: string): Promise<void> { | ||
const eslintRoot = requireResolved('eslint/package.json'); | ||
const linterPath = path.join(eslintRoot, '../lib/linter/linter.js'); | ||
const rulesPath = path.join(eslintRoot, '../lib/rules/index.js'); | ||
await esbuild.build({ | ||
entryPoints: { | ||
[name]: requireResolved(file), | ||
}, | ||
format: 'cjs', | ||
platform: 'browser', | ||
bundle: true, | ||
external: [], | ||
minify: true, | ||
treeShaking: true, | ||
write: true, | ||
target: 'es2020', | ||
sourcemap: 'linked', | ||
outdir: './dist/', | ||
supported: {}, | ||
banner: { | ||
// https://github.com/evanw/esbuild/issues/819 | ||
js: `define(['exports', 'vs/language/typescript/tsWorker'], function (exports) {`, | ||
}, | ||
footer: { | ||
// https://github.com/evanw/esbuild/issues/819 | ||
js: `});`, | ||
}, | ||
define: { | ||
'process.env.NODE_ENV': '"production"', | ||
'process.env.NODE_DEBUG': 'false', | ||
'process.env.IGNORE_TEST_WIN32': 'true', | ||
'process.env.DEBUG': 'false', | ||
'process.emitWarning': 'console.warn', | ||
'process.platform': '"browser"', | ||
'process.env.TIMING': 'undefined', | ||
'define.amd': 'false', | ||
global: 'window', | ||
}, | ||
alias: { | ||
util: requireResolved('./src/mock/util.js'), | ||
assert: requireResolved('./src/mock/assert.js'), | ||
path: requireResolved('./src/mock/path.js'), | ||
typescript: requireResolved('./src/mock/typescript.js'), | ||
'lru-cache': requireResolved('./src/mock/lru-cache.js'), | ||
}, | ||
plugins: [ | ||
{ | ||
name: 'replace-plugin', | ||
setup(build): void { | ||
build.onLoad( | ||
makeFilter([ | ||
'/eslint-utils/rule-tester/RuleTester.ts', | ||
'/ts-eslint/ESLint.ts', | ||
'/ts-eslint/RuleTester.ts', | ||
'/ts-eslint/CLIEngine.ts', | ||
]), | ||
async args => { | ||
console.log('onLoad:replace', args.path); | ||
const contents = await requireMock('./src/mock/empty.js'); | ||
return { contents, loader: 'js' }; | ||
}, | ||
); | ||
build.onLoad( | ||
makeFilter('/eslint/lib/unsupported-api.js'), | ||
async args => { | ||
console.log('onLoad:eslint:unsupported-api', args.path); | ||
let contents = await requireMock('./src/mock/eslint-rules.js'); | ||
// this is needed to bypass system module resolver | ||
contents = contents.replace( | ||
'vt:eslint/rules', | ||
normalizePath(rulesPath), | ||
); | ||
return { contents, loader: 'js' }; | ||
}, | ||
); | ||
build.onLoad(makeFilter('/eslint/lib/api.js'), async args => { | ||
console.log('onLoad:eslint', args.path); | ||
let text = await requireMock('./src/mock/eslint.js'); | ||
// this is needed to bypass system module resolver | ||
text = text.replace('vt:eslint/linter', normalizePath(linterPath)); | ||
return { contents: text, loader: 'js' }; | ||
}); | ||
build.onResolve( | ||
makeFilter([ | ||
'@typescript-eslint/typescript-estree', | ||
'@typescript-eslint/typescript-estree/use-at-your-own-risk', | ||
]), | ||
() => | ||
createResolve( | ||
'@typescript-eslint/typescript-estree', | ||
'use-at-your-own-risk.ts', | ||
), | ||
); | ||
const anyAlias = /^(@typescript-eslint\/[a-z-]+)\/([a-z-]+)$/; | ||
build.onResolve({ filter: anyAlias }, args => { | ||
const parts = args.path.match(anyAlias); | ||
if (parts) { | ||
return createResolve(parts[1], `${parts[2]}/index.ts`); | ||
} | ||
return null; | ||
}); | ||
build.onResolve(makeFilter('@typescript-eslint/[a-z-]+'), args => | ||
createResolve(args.path, 'index.ts'), | ||
); | ||
build.onEnd(e => { | ||
for (const error of e.errors) { | ||
console.error(error); | ||
} | ||
for (const warning of e.warnings) { | ||
console.warn(warning); | ||
} | ||
}); | ||
}, | ||
}, | ||
], | ||
}); | ||
} | ||
console.time('building eslint for web'); | ||
buildPackage('index', './src/index.js') | ||
.then(() => { | ||
console.timeEnd('building eslint for web'); | ||
}) | ||
.catch((e: unknown) => { | ||
console.error(String(e)); | ||
process.exit(1); | ||
}); |
16 changes: 4 additions & 12 deletionspackages/website-eslint/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
96 changes: 0 additions & 96 deletionspackages/website-eslint/rollup-plugin/replace.js
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.