From 88af91a5134a617d22c44595f819111baaf23957 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 21 Feb 2021 18:14:00 +0800 Subject: [PATCH 1/5] Chore: upgrade dependencies of browser test --- .github/workflows/ci.yml | 2 ++ karma.conf.js | 16 +++++++++++++++- package.json | 16 ++++++++++------ tests/lib/linter/linter.js | 23 +---------------------- webpack.config.js | 10 ++++++++++ 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7d5bc03d80..460130a5658 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,8 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 + with: + node-version: '12' - name: Install Packages run: npm install - name: Test diff --git a/karma.conf.js b/karma.conf.js index 974c8972136..3c227da7092 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,5 +1,6 @@ "use strict"; const os = require("os"); +const webpack = require("webpack"); if (os.arch() === "arm64") { @@ -20,7 +21,7 @@ module.exports = function(config) { * frameworks to use * available frameworks: https://npmjs.org/browse/keyword/karma-adapter */ - frameworks: ["mocha"], + frameworks: ["mocha", "webpack"], // list of files / patterns to load in the browser @@ -44,6 +45,19 @@ module.exports = function(config) { }, webpack: { mode: "none", + plugins: [ + new webpack.ProvidePlugin({ + process: "process/browser" + }) + ], + resolve: { + alias: { + "../../../lib/linter$": "../../../build/eslint.js" + }, + fallback: { + path: "path-browserify" + } + }, stats: "errors-only" }, webpackMiddleware: { diff --git a/package.json b/package.json index fe5a3ba4720..768623b82dd 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "@babel/core": "^7.4.3", "@babel/preset-env": "^7.4.3", "acorn": "^7.2.0", + "assert": "^2.0.0", "babel-loader": "^8.0.5", "chai": "^4.0.1", "cheerio": "^0.22.0", @@ -108,11 +109,11 @@ "fs-teardown": "^0.1.0", "glob": "^7.1.6", "jsdoc": "^3.5.5", - "karma": "^4.0.1", + "karma": "^6.1.1", "karma-chrome-launcher": "^3.1.0", - "karma-mocha": "^1.3.0", - "karma-mocha-reporter": "^2.2.3", - "karma-webpack": "^4.0.0-rc.6", + "karma-mocha": "^2.0.1", + "karma-mocha-reporter": "^2.2.5", + "karma-webpack": "^5.0.0", "lint-staged": "^10.1.2", "load-perf": "^0.2.0", "markdownlint": "^0.19.0", @@ -122,6 +123,8 @@ "mocha-junit-reporter": "^1.23.0", "npm-license": "^0.3.3", "nyc": "^15.0.1", + "path-browserify": "^1.0.1", + "process": "^0.11.10", "proxyquire": "^2.0.1", "puppeteer": "^4.0.0", "recast": "^0.19.0", @@ -129,8 +132,9 @@ "shelljs": "^0.8.2", "sinon": "^9.0.1", "temp": "^0.9.0", - "webpack": "^4.35.0", - "webpack-cli": "^3.3.5", + "util": "^0.12.3", + "webpack": "^5.23.0", + "webpack-cli": "^4.5.0", "yorkie": "^2.0.0" }, "keywords": [ diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index f999dd3ad9d..976bd765755 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -5,27 +5,6 @@ "use strict"; -//------------------------------------------------------------------------------ -// Helper -//------------------------------------------------------------------------------ - -/** - * To make sure this works in both browsers and Node.js - * @param {string} name Name of the module to require - * @param {Object} windowName name of the window - * @returns {Object} Required object - * @private - */ -function compatRequire(name, windowName) { - if (typeof window === "object") { // eslint-disable-line no-undef - return window[windowName || name]; // eslint-disable-line no-undef - } - if (typeof require === "function") { - return require(name); - } - throw new Error(`Cannot find object '${name}'.`); -} - //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ @@ -35,7 +14,7 @@ const assert = require("chai").assert, esprima = require("esprima"), testParsers = require("../../fixtures/parsers/linter-test-parsers"); -const { Linter } = compatRequire("../../../lib/linter", "eslint"); +const { Linter } = require("../../../lib/linter"); //------------------------------------------------------------------------------ // Constants diff --git a/webpack.config.js b/webpack.config.js index 2b56290b346..2d4a5ab0e7a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,7 @@ "use strict"; +const webpack = require("webpack"); +/** @type {webpack.Configuration} */ module.exports = { mode: "none", entry: { @@ -42,7 +44,15 @@ module.exports = { } ] }, + plugins: [ + new webpack.ProvidePlugin({ + process: "process/browser" + }) + ], resolve: { + fallback: { + path: "path-browserify" + }, mainFields: ["browser", "main", "module"] }, stats: "errors-only" From dc026879a5028f0e7a82455e4e4dcd1a4c36c36d Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Wed, 24 Feb 2021 14:20:08 +0800 Subject: [PATCH 2/5] Chore: simplify Node.js modules polyfill --- package.json | 4 +--- webpack.config.js | 11 +++-------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 768623b82dd..a557b1afd83 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,6 @@ "@babel/core": "^7.4.3", "@babel/preset-env": "^7.4.3", "acorn": "^7.2.0", - "assert": "^2.0.0", "babel-loader": "^8.0.5", "chai": "^4.0.1", "cheerio": "^0.22.0", @@ -121,10 +120,9 @@ "memfs": "^3.0.1", "mocha": "^7.1.1", "mocha-junit-reporter": "^1.23.0", + "node-polyfill-webpack-plugin": "^1.0.3", "npm-license": "^0.3.3", "nyc": "^15.0.1", - "path-browserify": "^1.0.1", - "process": "^0.11.10", "proxyquire": "^2.0.1", "puppeteer": "^4.0.0", "recast": "^0.19.0", diff --git a/webpack.config.js b/webpack.config.js index 2d4a5ab0e7a..b256f442460 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,7 @@ "use strict"; -const webpack = require("webpack"); +const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); -/** @type {webpack.Configuration} */ +/** @type {import("webpack").Configuration} */ module.exports = { mode: "none", entry: { @@ -45,14 +45,9 @@ module.exports = { ] }, plugins: [ - new webpack.ProvidePlugin({ - process: "process/browser" - }) + new NodePolyfillPlugin() ], resolve: { - fallback: { - path: "path-browserify" - }, mainFields: ["browser", "main", "module"] }, stats: "errors-only" From e262102c98193a40782dd6b7ce955e8b10cd5865 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 2 Mar 2021 09:11:45 +0800 Subject: [PATCH 3/5] Chore: remove unnecessary dependency --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index a557b1afd83..37f796b4b49 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,6 @@ "shelljs": "^0.8.2", "sinon": "^9.0.1", "temp": "^0.9.0", - "util": "^0.12.3", "webpack": "^5.23.0", "webpack-cli": "^4.5.0", "yorkie": "^2.0.0" From 61894247977888e66e6b9146499a9ae111e924bb Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Tue, 2 Mar 2021 09:13:38 +0800 Subject: [PATCH 4/5] Chore: simplify webpack config in Karma --- karma.conf.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 3c227da7092..c82bc984158 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,6 +1,6 @@ "use strict"; const os = require("os"); -const webpack = require("webpack"); +const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); if (os.arch() === "arm64") { @@ -46,16 +46,11 @@ module.exports = function(config) { webpack: { mode: "none", plugins: [ - new webpack.ProvidePlugin({ - process: "process/browser" - }) + new NodePolyfillPlugin() ], resolve: { alias: { "../../../lib/linter$": "../../../build/eslint.js" - }, - fallback: { - path: "path-browserify" } }, stats: "errors-only" From b0e3f18277167b3ff49e0292c9cd6531f3a687f1 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 4 Mar 2021 22:19:34 +0800 Subject: [PATCH 5/5] Chore: clean up entries in Karma config --- karma.conf.js | 1 - 1 file changed, 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index c82bc984158..05f1a1ceb6e 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -26,7 +26,6 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - "build/eslint.js", "tests/lib/linter/linter.js" ],