Skip to content
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

chore: use rollup instead of webpack and esbuild #1701

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ yarn-error.log
/examples/implementation_languages/typescript/*.js
/examples/implementation_languages/coffeescript/*.js
/examples/parser/minification/gen/

.rollup.cache
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@

# prettier ignores
/packages/cst-dts-gen/test/snapshots/**/output.d.ts

.rollup.cache
8 changes: 6 additions & 2 deletions packages/chevrotain/.mocharc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = {
recursive: true,
require: ["./test/test.config", "source-map-support/register"],
require: [
"./test/test.config",
"source-map-support/register",
"ts-node/register"
],
reporter: "spec",
spec: "./lib/test/**/*spec.js"
spec: "./test/**/*spec.ts"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "build tests and source first, then run built tests" seemed a bit awkward. Also it had problems with wrong source lines in stack traces.

This runs the .ts spec files directly on the .ts source. This should have the advantage that the coverage report is more useful as it applies to the the .ts source. Also fix-coverage-report shouldn't be necessary anymore (?)

}
1 change: 1 addition & 0 deletions packages/chevrotain/nyc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
exclude: [
"lib/test/**/*.*",
"test/test.config.js",
"test",
// unable to exclude specific deperacted function in this file
// due to transpilation step "moving" the ignore comments around.
"lib/src/parse/errors_public.js"
Expand Down
32 changes: 14 additions & 18 deletions packages/chevrotain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
"CHANGELOG.md"
],
"typings": "./chevrotain.d.ts",
"main": "./lib/src/api.js",
"main": "./lib/chevrotain.js",
"exports": {
"require": "./lib/src/api.js",
"import": "./lib_esm/api_esm.mjs"
"require": "./lib/chevrotain.js",
"import": "./lib/chevrotain.mjs"
},
"repository": {
"type": "git",
Expand All @@ -50,44 +50,40 @@
"homepage": "https://chevrotain.io/docs/",
"scripts": {
"---------- CI FLOWS --------": "",
"build": "npm-run-all clean compile bundle",
"build": "npm-run-all clean bundle",
"test": "npm-run-all coverage",
"version": "tsc ./src/version.ts --outDir lib/src && node ./scripts/version-update.js",
"---------- DEV FLOWS --------": "",
"watch": "tsc -w",
"unit-tests": "mocha",
"quick-build": "tsc && yarn run bundle",
"quick-build": "yarn run bundle",
"---------- BUILD STEPS --------": "",
"clean": "shx rm -rf coverage dev lib lib_esm",
"compile": "tsc && node ./scripts/fix-coverage-report.js && npm-run-all gen-esm-wrapper",
"compile:watch": "tsc -w",
"gen-esm-wrapper": "gen-esm-wrapper . ./lib_esm/api_esm.mjs",
"coverage": "nyc mocha",
"---------- BUNDLING --------": "",
"bundle": "npm-run-all bundle:**",
"bundle:regular": "webpack --config webpack_release.config.js",
"bundle:min": "webpack --config webpack_release_min.config.js",
"bundle:esm:regular": "esbuild ./lib/src/api.js --bundle --sourcemap --format=esm --outfile=lib_esm/chevrotain.mjs",
"bundle:esm:min": "esbuild ./lib/src/api.js --bundle --minify --format=esm --sourcemap --outfile=lib_esm/chevrotain.min.mjs"
"bundle": "rollup --config",
"bundle:watch": "rollup --config --watch"
},
"dependencies": {
"@chevrotain/types": "^9.1.0",
"@chevrotain/utils": "^9.1.0",
"regexp-to-ast": "0.5.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-typescript": "^8.3.0",
"@types/sinon-chai": "3.2.5",
"error-stack-parser": "2.0.6",
"esbuild": "0.13.8",
"gen-esm-wrapper": "1.1.3",
"gitty": "3.7.2",
"jsdom": "18.0.0",
"jsonfile": "6.1.0",
"require-from-string": "2.0.2",
"rollup": "^2.59.0",
"rollup-plugin-terser": "^7.0.2",
"sinon": "11.1.2",
"sinon-chai": "3.7.0",
"webpack": "5.59.1",
"webpack-cli": "4.9.1",
"ts-node": "^10.4.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these deps are no longer needed (from previous version with mocha + tsnode)

"tslib": "^2.3.1",
"xregexp": "5.1.0"
}
}
82 changes: 82 additions & 0 deletions packages/chevrotain/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const typescriptPlugin = require("@rollup/plugin-typescript")
const { default: nodeResolvePlugin } = require("@rollup/plugin-node-resolve")
const typescript = require("typescript")
const { terser } = require("rollup-plugin-terser")
const commonjsPlugin = require("@rollup/plugin-commonjs")

const pkg = require("./package.json")

module.exports = [
// no deps
{
input: "src/api.ts",
output: [
["commonjs", false],
["es", false]
].map(([format, compress]) => ({
format: format,
entryFileNames:
"chevrotain" +
(compress ? ".min" : "") +
(format === "es" ? ".mjs" : ".js"),
sourcemap: true,
dir: "lib",
name: "chevrotain",
exports: "named"
})),
external: Object.keys(pkg.dependencies),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not we include everything in the bundle?

plugins: [typescriptPlugin({ typescript })],
onwarn: function (warning, warn) {
if ("THIS_IS_UNDEFINED" === warning.code) return
// if ('CIRCULAR_DEPENDENCY' === warning.code) return
warn(warning)
}
},

// bundle
{
input: "src/api.ts",
output: [
["es", false, true],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do these combination mean?

["es", true, true],
["umd", false, true],
["umd", true, true]
].map(([format, compress]) => ({
format: format,
entryFileNames:
"chevrotain-bundle" +
(compress ? ".min" : "") +
(format === "es" ? ".mjs" : ".js"),
sourcemap: true,
dir: "lib",
name: "chevrotain",
exports: "named",
plugins: compress
? [
terser({
compress: {
passes: 3,
unsafe: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we know everything works after bundling particularly when using unsafe minification modes? what benefit does unsafe produce in the bundle size?

ecma: 7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ecma 7 means ECMAScript 2017? or 2016?
anyhow we are officially targeting ECMAScript 2015, so this does not seem to make sense.

},
toplevel: true,
mangle: {
properties: { regex: /^_/ }
}
})
]
: []
})),
external: [],
plugins: [
typescriptPlugin({ typescript }),
nodeResolvePlugin(),
commonjsPlugin()
],
onwarn: function (warning, warn) {
if ("THIS_IS_UNDEFINED" === warning.code) return
// if ('CIRCULAR_DEPENDENCY' === warning.code) return
warn(warning)
}
}
]
30 changes: 0 additions & 30 deletions packages/chevrotain/scripts/fix-coverage-report.js

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"target": "ES5",
"composite": true,
"newLine": "lf",
"module": "CommonJS",
"removeComments": false,
"sourceMap": true,
Expand Down