From bd57e37aeb6db70e860c0c9eb0716b780d3ceb91 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 15 Feb 2019 11:35:30 +0800 Subject: [PATCH 1/9] Build: switch from browserify to webpack (fixes #11366) --- Makefile.js | 49 ++++++++++++++++++++++++++++++++++++++----------- karma.conf.js | 13 ++++++++----- package.json | 9 +++++---- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Makefile.js b/Makefile.js index fa9227a5b1c..23f5bb3a6a4 100644 --- a/Makefile.js +++ b/Makefile.js @@ -25,6 +25,7 @@ const lodash = require("lodash"), semver = require("semver"), ejs = require("ejs"), loadPerf = require("load-perf"), + webpack = require("webpack"), yaml = require("js-yaml"); const { cat, cd, cp, echo, exec, exit, find, ls, mkdir, pwd, rm, test } = require("shelljs"); @@ -820,17 +821,43 @@ target.browserify = function() { mkdir(BUILD_DIR); } - // 2. browserify the temp directory - exec(`${getBinFile("browserify")} -x espree lib/linter.js -o ${BUILD_DIR}eslint.js -s eslint --global-transform [ babelify --presets [ @babel/preset-env ] ]`); - - // 3. Browserify espree - exec(`${getBinFile("browserify")} -r espree -o ${TEMP_DIR}espree.js --global-transform [ babelify --presets [ @babel/preset-env ] ]`); - - // 4. Concatenate Babel polyfill, Espree, and ESLint files together - cat("./node_modules/@babel/polyfill/dist/polyfill.js", `${TEMP_DIR}espree.js`, `${BUILD_DIR}eslint.js`).to(`${BUILD_DIR}eslint.js`); - - // 5. remove temp directory - rm("-rf", TEMP_DIR); + // 2. run webpack + webpack({ + mode: "none", + entry: ["@babel/polyfill", "./lib/linter.js"], + output: { + path: path.join(__dirname, BUILD_DIR), + filename: "eslint.js", + library: "eslint", + libraryTarget: "umd", + globalObject: "this" + }, + module: { + rules: [ + { + test: path.resolve("./lib/linter.js"), + loader: "string-replace-loader", + options: { + search: "require(parserName)", + replace: "(parserName === \"espree\" ? require(\"espree\") : require(parserName))" + } + }, + { + test: /\.js$/, + loader: "babel-loader", + options: { + presets: ["@babel/preset-env"] + }, + exclude: /node_modules/ + } + ] + } + }, (err, stats) => { + if (err || stats.hasErrors()) { + console.error("webpack build failed."); + exit(1); + } + }); }; target.checkRuleFiles = function() { diff --git a/karma.conf.js b/karma.conf.js index 9b26395e988..43ec559ac5a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -32,12 +32,15 @@ module.exports = function(config) { // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { - "tests/lib/linter.js": ["babel"] + "tests/lib/linter.js": ["webpack"] }, - babelPreprocessor: { - options: { - presets: ["@babel/preset-env"] - } + webpack: { + mode: "none", + stats: "errors-only" + }, + webpackMiddleware: { + stats: "errors-only", + clientLogLevel: "error" }, diff --git a/package.json b/package.json index cd25a4013a8..0be3cb7a127 100644 --- a/package.json +++ b/package.json @@ -76,10 +76,9 @@ "@babel/core": "^7.2.2", "@babel/polyfill": "^7.2.5", "@babel/preset-env": "^7.3.1", - "babelify": "^10.0.0", + "babel-loader": "^8.0.5", "beefy": "^2.1.8", "brfs": "^2.0.0", - "browserify": "^16.2.2", "chai": "^4.0.1", "cheerio": "^0.22.0", "common-tags": "^1.8.0", @@ -96,10 +95,10 @@ "istanbul": "^0.4.5", "jsdoc": "^3.5.5", "karma": "^3.1.4", - "karma-babel-preprocessor": "^8.0.0", "karma-chrome-launcher": "^2.2.0", "karma-mocha": "^1.3.0", "karma-mocha-reporter": "^2.2.3", + "karma-webpack": "^3.0.5", "leche": "^2.2.3", "load-perf": "^0.2.0", "markdownlint": "^0.12.0", @@ -110,8 +109,10 @@ "puppeteer": "^1.12.2", "shelljs": "^0.8.2", "sinon": "^3.3.0", + "string-replace-loader": "^2.1.1", "temp": "^0.9.0", - "through": "^2.3.8" + "through": "^2.3.8", + "webpack": "^4.29.3" }, "keywords": [ "ast", From 0716b1e485179958f90b0729c84a0b59ed2dfeeb Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 15 Feb 2019 12:03:26 +0800 Subject: [PATCH 2/9] Build: use webpack-cli --- Makefile.js | 37 +------------------------------------ package.json | 3 ++- webpack.config.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 37 deletions(-) create mode 100644 webpack.config.js diff --git a/Makefile.js b/Makefile.js index 23f5bb3a6a4..1db20a1a5dd 100644 --- a/Makefile.js +++ b/Makefile.js @@ -822,42 +822,7 @@ target.browserify = function() { } // 2. run webpack - webpack({ - mode: "none", - entry: ["@babel/polyfill", "./lib/linter.js"], - output: { - path: path.join(__dirname, BUILD_DIR), - filename: "eslint.js", - library: "eslint", - libraryTarget: "umd", - globalObject: "this" - }, - module: { - rules: [ - { - test: path.resolve("./lib/linter.js"), - loader: "string-replace-loader", - options: { - search: "require(parserName)", - replace: "(parserName === \"espree\" ? require(\"espree\") : require(parserName))" - } - }, - { - test: /\.js$/, - loader: "babel-loader", - options: { - presets: ["@babel/preset-env"] - }, - exclude: /node_modules/ - } - ] - } - }, (err, stats) => { - if (err || stats.hasErrors()) { - console.error("webpack build failed."); - exit(1); - } - }); + exec(`${getBinFile("webpack")} --output-path=${path.resolve(__dirname, BUILD_DIR)}`); }; target.checkRuleFiles = function() { diff --git a/package.json b/package.json index 0be3cb7a127..e0f96665c28 100644 --- a/package.json +++ b/package.json @@ -112,7 +112,8 @@ "string-replace-loader": "^2.1.1", "temp": "^0.9.0", "through": "^2.3.8", - "webpack": "^4.29.3" + "webpack": "^4.29.3", + "webpack-cli": "^3.2.3" }, "keywords": [ "ast", diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 00000000000..2af0586dad1 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,33 @@ +const path = require("path"); + +module.exports = { + mode: "none", + entry: ["@babel/polyfill", "./lib/linter.js"], + output: { + filename: "eslint.js", + library: "eslint", + libraryTarget: "umd", + globalObject: "this" + }, + module: { + rules: [ + { + test: path.resolve("./lib/linter.js"), + loader: "string-replace-loader", + options: { + search: "require(parserName)", + replace: "(parserName === \"espree\" ? require(\"espree\") : require(parserName))" + } + }, + { + test: /\.js$/, + loader: "babel-loader", + options: { + presets: ["@babel/preset-env"] + }, + exclude: /node_modules/ + } + ] + }, + stats: "errors-only" +}; From 7170b814432311a6da6c3ab1785b5901bd2908d0 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 15 Feb 2019 12:06:00 +0800 Subject: [PATCH 3/9] Chore: fix linting errors --- Makefile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.js b/Makefile.js index 1db20a1a5dd..acdd8ad2891 100644 --- a/Makefile.js +++ b/Makefile.js @@ -25,7 +25,6 @@ const lodash = require("lodash"), semver = require("semver"), ejs = require("ejs"), loadPerf = require("load-perf"), - webpack = require("webpack"), yaml = require("js-yaml"); const { cat, cd, cp, echo, exec, exit, find, ls, mkdir, pwd, rm, test } = require("shelljs"); From 59bc5935296acbe24ab8fd94d70882c36a457022 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 15 Feb 2019 14:32:46 +0800 Subject: [PATCH 4/9] Chore: define "espree" in constructor of `Linter` --- lib/linter.js | 1 + package.json | 1 - webpack.config.js | 10 ---------- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/linter.js b/lib/linter.js index 29505e9ac02..ea46fcd1b51 100644 --- a/lib/linter.js +++ b/lib/linter.js @@ -776,6 +776,7 @@ module.exports = class Linter { ruleMaps.set(this, new Rules()); this.version = pkg.version; this.environments = new Environments(); + this.defineParser("espree", require("espree")); } /** diff --git a/package.json b/package.json index e0f96665c28..e710e682e35 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,6 @@ "puppeteer": "^1.12.2", "shelljs": "^0.8.2", "sinon": "^3.3.0", - "string-replace-loader": "^2.1.1", "temp": "^0.9.0", "through": "^2.3.8", "webpack": "^4.29.3", diff --git a/webpack.config.js b/webpack.config.js index 2af0586dad1..209c75a9e4b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,3 @@ -const path = require("path"); - module.exports = { mode: "none", entry: ["@babel/polyfill", "./lib/linter.js"], @@ -11,14 +9,6 @@ module.exports = { }, module: { rules: [ - { - test: path.resolve("./lib/linter.js"), - loader: "string-replace-loader", - options: { - search: "require(parserName)", - replace: "(parserName === \"espree\" ? require(\"espree\") : require(parserName))" - } - }, { test: /\.js$/, loader: "babel-loader", From 031379f75ced70b85e304f658da27b11e2f9e99c Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 15 Feb 2019 14:38:37 +0800 Subject: [PATCH 5/9] Build: tweak karma --- karma.conf.js | 4 +--- package.json | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 43ec559ac5a..554eb50284d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -16,7 +16,6 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - "node_modules/mocha/mocha.js", "node_modules/chai/chai.js", "node_modules/sinon/pkg/sinon.js", "build/eslint.js", @@ -39,8 +38,7 @@ module.exports = function(config) { stats: "errors-only" }, webpackMiddleware: { - stats: "errors-only", - clientLogLevel: "error" + logLevel: "error" }, diff --git a/package.json b/package.json index e710e682e35..7baebdd56c4 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "karma-chrome-launcher": "^2.2.0", "karma-mocha": "^1.3.0", "karma-mocha-reporter": "^2.2.3", - "karma-webpack": "^3.0.5", + "karma-webpack": "^4.0.0-rc.6", "leche": "^2.2.3", "load-perf": "^0.2.0", "markdownlint": "^0.12.0", From b7ceb74c98edfa7675f5a9a912d453c202601069 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 15 Feb 2019 17:01:42 +0800 Subject: [PATCH 6/9] Chore: tweak karma test --- karma.conf.js | 2 -- tests/lib/linter.js | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 554eb50284d..595ba0c591d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -16,8 +16,6 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - "node_modules/chai/chai.js", - "node_modules/sinon/pkg/sinon.js", "build/eslint.js", "tests/lib/linter.js" ], diff --git a/tests/lib/linter.js b/tests/lib/linter.js index 564bcee6b21..0cd7e0d5a23 100644 --- a/tests/lib/linter.js +++ b/tests/lib/linter.js @@ -32,9 +32,9 @@ function compatRequire(name, windowName) { // Requirements //------------------------------------------------------------------------------ -const assert = compatRequire("chai").assert, - sinon = compatRequire("sinon"), - path = compatRequire("path"), +const assert = require("chai").assert, + sinon = require("sinon"), + path = require("path"), Linter = compatRequire("../../lib/linter", "eslint"); //------------------------------------------------------------------------------ From 70b5a6df22fe35ad6239f07e8765b96ad87f3301 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 15 Feb 2019 17:05:18 +0800 Subject: [PATCH 7/9] Chore: fix linting errors --- tests/lib/linter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/lib/linter.js b/tests/lib/linter.js index 0cd7e0d5a23..78a31380eb2 100644 --- a/tests/lib/linter.js +++ b/tests/lib/linter.js @@ -34,8 +34,9 @@ function compatRequire(name, windowName) { const assert = require("chai").assert, sinon = require("sinon"), - path = require("path"), - Linter = compatRequire("../../lib/linter", "eslint"); + path = require("path"); + +const Linter = compatRequire("../../lib/linter", "eslint"); //------------------------------------------------------------------------------ // Constants From c35639a9e39f67e22bee9b5262495af8fd55827b Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sat, 16 Feb 2019 09:13:42 +0800 Subject: [PATCH 8/9] Build: improve browerify step --- Makefile.js | 17 +++-------------- lib/linter.js | 4 +++- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/Makefile.js b/Makefile.js index acdd8ad2891..d3974e5e988 100644 --- a/Makefile.js +++ b/Makefile.js @@ -796,7 +796,7 @@ target.gensite = function(prereleaseVersion) { // 13. Update demos, but only for non-prereleases if (!prereleaseVersion) { echo("> Updating the demos (Step 13)"); - target.browserify(); + target.browserify("production"); cp("-f", "build/eslint.js", `${SITE_DIR}js/app/eslint.js`); } else { echo("> Skipped updating the demos (Step 13)"); @@ -809,19 +809,8 @@ target.gensite = function(prereleaseVersion) { echo("Done generating eslint.org"); }; -target.browserify = function() { - - // 1. create temp and build directory - if (!test("-d", TEMP_DIR)) { - mkdir(TEMP_DIR); - } - - if (!test("-d", BUILD_DIR)) { - mkdir(BUILD_DIR); - } - - // 2. run webpack - exec(`${getBinFile("webpack")} --output-path=${path.resolve(__dirname, BUILD_DIR)}`); +target.browserify = function(mode = "none") { + exec(`${getBinFile("webpack")} --mode=${mode} --output-path=${path.resolve(__dirname, BUILD_DIR)}`); }; target.checkRuleFiles = function() { diff --git a/lib/linter.js b/lib/linter.js index ea46fcd1b51..2abd2d3ff1b 100644 --- a/lib/linter.js +++ b/lib/linter.js @@ -11,6 +11,7 @@ const eslintScope = require("eslint-scope"), evk = require("eslint-visitor-keys"), + espree = require("espree"), lodash = require("lodash"), CodePathAnalyzer = require("./code-path-analysis/code-path-analyzer"), ConfigOps = require("./config/config-ops"), @@ -776,7 +777,8 @@ module.exports = class Linter { ruleMaps.set(this, new Rules()); this.version = pkg.version; this.environments = new Environments(); - this.defineParser("espree", require("espree")); + + this.defineParser("espree", espree); } /** From cdcdeb7d62f46245f27f1c2b63293be2079ee923 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 17 Feb 2019 10:38:57 +0800 Subject: [PATCH 9/9] Chore: rename make file task --- Makefile.js | 6 +++--- docs/developer-guide/development-environment.md | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile.js b/Makefile.js index d3974e5e988..99d0052680f 100644 --- a/Makefile.js +++ b/Makefile.js @@ -595,7 +595,7 @@ target.test = function() { errors++; } - target.browserify(); + target.webpack(); lastReturn = exec(`${getBinFile("karma")} start karma.conf.js`); if (lastReturn.code !== 0) { @@ -796,7 +796,7 @@ target.gensite = function(prereleaseVersion) { // 13. Update demos, but only for non-prereleases if (!prereleaseVersion) { echo("> Updating the demos (Step 13)"); - target.browserify("production"); + target.webpack("production"); cp("-f", "build/eslint.js", `${SITE_DIR}js/app/eslint.js`); } else { echo("> Skipped updating the demos (Step 13)"); @@ -809,7 +809,7 @@ target.gensite = function(prereleaseVersion) { echo("Done generating eslint.org"); }; -target.browserify = function(mode = "none") { +target.webpack = function(mode = "none") { exec(`${getBinFile("webpack")} --mode=${mode} --output-path=${path.resolve(__dirname, BUILD_DIR)}`); }; diff --git a/docs/developer-guide/development-environment.md b/docs/developer-guide/development-environment.md index 3b3a12fb279..a93e1efbc24 100644 --- a/docs/developer-guide/development-environment.md +++ b/docs/developer-guide/development-environment.md @@ -83,7 +83,7 @@ Be sure to run this after making changes and before sending a pull request with Runs just the JavaScript and JSON linting on the repository -#### npm run browserify +#### npm run webpack Generates `build/eslint.js`, a version of ESLint for use in the browser diff --git a/package.json b/package.json index 7baebdd56c4..5a6500c844e 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "publish-release": "node Makefile.js publishRelease", "docs": "node Makefile.js docs", "gensite": "node Makefile.js gensite", - "browserify": "node Makefile.js browserify", + "webpack": "node Makefile.js webpack", "perf": "node Makefile.js perf", "profile": "beefy tests/bench/bench.js --open -- -t brfs -t ./tests/bench/xform-rules.js -r espree", "coveralls": "cat ./coverage/lcov.info | coveralls"