-
Notifications
You must be signed in to change notification settings - Fork 181
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS-380 Bundle bridge using esbuild #4901
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f6a46ec
Bundle bridge with esbuild
vdiez 288eb6f
fix eslint-import requires
vdiez 335c45d
Wrapping up
vdiez 5f369a8
Fix test tarball
vdiez e64b9d1
postcss fix
vdiez 5e3d237
update test
zglicz f2a2380
postcss fix
vdiez 89c9165
Fix constructor rename and stylelint dynamic imports
vdiez bf0c21d
Support run-node binary
vdiez 6938e3b
Support run-node binary
vdiez 284ec54
Add minify
vdiez 0196ef7
fix tests
zglicz cb88aaa
Merge branch 'bundle-esbuild' of github.com:SonarSource/SonarJS into …
zglicz 34b0fb3
Merge branch 'master' into bundle-esbuild
zglicz 0cfeb2a
reduce jar size
zglicz 684b412
Add comments to esbuild script
vdiez 4fbcd08
fix backslashes on windows
vdiez 1559ab8
Fix Vue parser for JS
vdiez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Maven | ||
target/ | ||
bin/ | ||
|
||
lib/ | ||
node_modules/ | ||
|
This file contains 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,110 @@ | ||
import esbuild from 'esbuild'; | ||
import textReplace from 'esbuild-plugin-text-replace'; | ||
import { copy } from 'esbuild-plugin-copy'; | ||
|
||
await esbuild.build({ | ||
entryPoints: ['./server.mjs'], | ||
outfile: './bin/server.cjs', | ||
format: 'cjs', | ||
bundle: true, | ||
// we mark this file as external because it does not exist on EsLint any more and in any case | ||
// the code never reaches this dynamic require as this is a fallback if 'eslint/use-at-your-own-risk' | ||
// does not exist. we need to keep an eye on this in the future. | ||
external: ['eslint/lib/util/glob-util'], | ||
platform: 'node', | ||
minify: true, | ||
plugins: [ | ||
textReplace({ | ||
include: /server\.mjs$/, | ||
pattern: [['new URL(import.meta.url)', '__filename']], | ||
}), | ||
textReplace({ | ||
include: /lib[\/\\]jsts[\/\\]src[\/\\]parsers[\/\\]ast\.js$/, | ||
pattern: [['path.dirname(fileURLToPath(import.meta.url))', '__dirname']], | ||
}), | ||
// Simplify the loader function in babel. At the end it's just importing Babel parser | ||
// This matches the result of the TS compilation of the following lines | ||
// https://github.com/babel/babel/blob/v7.25.1/eslint/babel-eslint-parser/src/parse.cts#L8-L12 | ||
textReplace({ | ||
include: /node_modules[\/\\]@babel[\/\\]eslint-parser[\/\\]lib[\/\\]parse\.cjs$/, | ||
pattern: [ | ||
[/const babelParser = require.*}\)\)/gms, 'const babelParser = require("@babel/parser")'], | ||
], | ||
}), | ||
// Remove dynamic import of espree on ESLint Rule tester. In any case, it's never used in the bundle | ||
textReplace({ | ||
include: /node_modules[\/\\]eslint[\/\\]lib[\/\\]rule-tester[\/\\]rule-tester\.js$/, | ||
pattern: [ | ||
// https://github.com/eslint/eslint/blob/v8.57.0/lib/rule-tester/rule-tester.js#L56 | ||
['const espreePath = require.resolve("espree");', ''], | ||
// https://github.com/eslint/eslint/blob/v8.57.0/lib/rule-tester/rule-tester.js#L781 | ||
['config.parser = espreePath;', ''], | ||
], | ||
}), | ||
// Dynamic import in module used by eslint-import-plugin. It always resolves to node resolver | ||
textReplace({ | ||
include: /node_modules[\/\\]eslint-module-utils[\/\\]resolve\.js$/, | ||
pattern: [ | ||
[ | ||
// https://github.com/import-js/eslint-plugin-import/blob/v2.11.0/utils/resolve.js#L157 | ||
'tryRequire(`eslint-import-resolver-${name}`, sourceFile)', | ||
'require("eslint-import-resolver-node")', | ||
], | ||
], | ||
}), | ||
// the html extractor for stylelint calls a "loadSyntax" function in postcss-syntax/load-syntax.js | ||
// That function has a dynamic require which always resolves to same dependencies given | ||
// our stylelint options. | ||
textReplace({ | ||
include: /node_modules[\/\\]postcss-html[\/\\]extract\.js$/, | ||
pattern: [ | ||
[ | ||
//https://github.com/ota-meshi/postcss-html/blob/v0.36.0/extract.js#L108 | ||
'style.syntax = loadSyntax(opts, __dirname);', | ||
`style.syntax = { | ||
parse: require("postcss-html/template-parse"), | ||
stringify: require("postcss/lib/stringify") | ||
}; | ||
opts.syntax.config["css"] = { | ||
stringify: require("postcss/lib/stringify"), | ||
parse: require("postcss/lib/parse") | ||
}`, | ||
// ^^ modifying "opts.syntax.config" is a side effect done in postcss-syntax/get-syntax.js | ||
], | ||
], | ||
}), | ||
// The comparison by constructor name made by stylelint is not valid in the bundle because | ||
// the Document object is named differently. We need to compare constructor object directly | ||
textReplace({ | ||
include: /node_modules[\/\\]stylelint[\/\\]lib[\/\\]lintPostcssResult\.js$/, | ||
pattern: [ | ||
[ | ||
// https://github.com/stylelint/stylelint/blob/15.10.0/lib/lintPostcssResult.js#L52 | ||
"postcssDoc && postcssDoc.constructor.name === 'Document' ? postcssDoc.nodes : [postcssDoc]", | ||
"postcssDoc && postcssDoc.constructor === require('postcss-syntax/document') ? postcssDoc.nodes : [postcssDoc]", | ||
], | ||
], | ||
}), | ||
copy({ | ||
resolveFrom: 'cwd', | ||
assets: [ | ||
// We need to copy all typescript declaration files for type-checking, as typescript will | ||
// look for those in the filesystem | ||
{ | ||
from: ['./node_modules/typescript/lib/*.d.ts'], | ||
to: ['./bin/'], | ||
}, | ||
// We copy run-node into the bundle, as it's used from the java side on Mac | ||
{ | ||
from: ['./run-node'], | ||
to: ['./bin/'], | ||
}, | ||
// We copy the protofile as it needs to be accessible for the bundle | ||
{ | ||
from: ['./packages/jsts/src/parsers/estree.proto'], | ||
to: ['./bin/'], | ||
}, | ||
], | ||
}), | ||
], | ||
}); |
This file contains 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 |
---|---|---|
|
@@ -20,9 +20,6 @@ exports.rules = [ | |
], | ||
}, | ||
create(context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For posteriority, the lines below were removed because typescript isn't installed and available |
||
const ts = require('typescript'); | ||
console.log(`TS API in custom rule: TS version ${ts.version}`); // should print embedded typescript version | ||
|
||
console.log('Rule context options: ', context.options); | ||
return { | ||
CallExpression(node) { | ||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be worth to point a specific line in a github repo? Perhaps this way, if something changes, it would be a good starting point to investigate.
Also, it would be great, if we could assert that these replacements actually happened. If we could make the bundling fail if any of the replacements didn't occur....