From 9bae0692857f778bcd2b860c0107a706b74ad17b Mon Sep 17 00:00:00 2001 From: Chunpeng Huo Date: Thu, 28 May 2020 16:53:19 +1000 Subject: [PATCH] chore(cli-bundler): switch to querystring-browser-stub and fs-browser-stub --- lib/build/stub-module.js | 9 ++++--- package.json | 31 +++++++++++----------- spec/lib/build/stub-module.spec.js | 41 +++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/lib/build/stub-module.js b/lib/build/stub-module.js index f3e532fad..57ef46c5c 100644 --- a/lib/build/stub-module.js +++ b/lib/build/stub-module.js @@ -20,7 +20,7 @@ const UNAVAIABLE_CORE_MODULES = [ 'cluster', 'dgram', 'dns', - 'fs', + // 'fs', 'net', 'readline', 'repl', @@ -50,8 +50,11 @@ module.exports = function(moduleId, root) { } if (moduleId === 'querystring') { - // using querystring-es3 next version 1.0.0-0 - return {name: 'querystring', path: resolvePath('querystring-es3', root)}; + return {name: 'querystring', path: resolvePath('querystring-browser-stub', root)}; + } + + if (moduleId === 'fs') { + return {name: 'fs', path: resolvePath('fs-browser-stub', root)}; } if (moduleId === 'sys') { diff --git a/package.json b/package.json index 2c0a12d4d..792dad192 100644 --- a/package.json +++ b/package.json @@ -38,12 +38,12 @@ "url": "https://github.com/aurelia/cli" }, "dependencies": { - "@babel/core": "^7.9.6", - "@babel/plugin-proposal-class-properties": "^7.8.3", - "@babel/plugin-proposal-decorators": "^7.8.3", - "@babel/plugin-transform-modules-amd": "^7.9.6", - "@babel/plugin-transform-modules-commonjs": "^7.9.6", - "@babel/register": "^7.9.0", + "@babel/core": "^7.10.1", + "@babel/plugin-proposal-class-properties": "^7.10.1", + "@babel/plugin-proposal-decorators": "^7.10.1", + "@babel/plugin-transform-modules-amd": "^7.10.1", + "@babel/plugin-transform-modules-commonjs": "^7.10.1", + "@babel/register": "^7.10.1", "ansi-colors": "^4.1.1", "assert": "^2.0.0", "aurelia-dependency-injection": "^1.5.2", @@ -57,10 +57,11 @@ "convert-source-map": "^1.7.0", "crypto-browserify": "^3.12.0", "del": "^5.1.0", - "domain-browser": "^4.0.0", + "domain-browser": "^4.4.0", "enquirer": "^2.3.5", "esprima": "^4.0.1", "events": "^3.1.0", + "fs-browser-stub": "^1.0.1", "gulp": "^4.0.2", "htmlparser2": "^4.1.0", "https-browserify": "^1.0.0", @@ -72,31 +73,31 @@ "path-browserify": "1.0.1", "process": "^0.11.10", "punycode": "^2.1.1", - "querystring-es3": "1.0.0-0", + "querystring-browser-stub": "^1.0.0", "readable-stream": "^3.6.0", "resolve": "^1.17.0", "semver": "^7.3.2", "stream-browserify": "^3.0.0", - "stream-http": "^3.1.0", + "stream-http": "^3.1.1", "string_decoder": "^1.3.0", - "terser": "^4.6.12", + "terser": "^4.7.0", "timers-browserify": "^2.0.11", "tty-browserify": "0.0.1", - "typescript": "^3.8.3", + "typescript": "^3.9.3", "url": "^0.11.0", - "util": "^0.12.2", + "util": "^0.12.3", "vm-browserify": "^1.1.2" }, "devDependencies": { - "@types/node": "^13.13.4", + "@types/node": "^14.0.5", "babel-eslint": "^10.1.0", "gulp-bump": "^3.1.3", - "gulp-conventional-changelog": "^2.0.29", + "gulp-conventional-changelog": "^2.0.32", "gulp-eslint": "^6.0.0", "jasmine": "^3.5.0", "jasmine-spec-reporter": "^5.0.2", "mock-fs": "^4.12.0", - "nodemon": "^2.0.3", + "nodemon": "^2.0.4", "nyc": "^15.0.1", "yargs": "^15.3.1" } diff --git a/spec/lib/build/stub-module.spec.js b/spec/lib/build/stub-module.spec.js index 99315ae50..cc9ee0c2d 100644 --- a/spec/lib/build/stub-module.spec.js +++ b/spec/lib/build/stub-module.spec.js @@ -8,11 +8,50 @@ describe('StubCoreNodejsModule', () => { }); }); + it('stubs domain', () => { + expect(stubModule('domain', 'src')).toEqual({ + name: 'domain', + path: '../node_modules/domain-browser' + }); + }); + + it('stubs http', () => { + expect(stubModule('http', 'src')).toEqual({ + name: 'http', + path: '../node_modules/stream-http' + }); + }); + + it('stubs querystring', () => { + expect(stubModule('querystring', 'src')).toEqual({ + name: 'querystring', + path: '../node_modules/querystring-browser-stub' + }); + }); + + it('stubs fs', () => { + expect(stubModule('fs', 'src')).toEqual({ + name: 'fs', + path: '../node_modules/fs-browser-stub' + }); + }); + it('ignores sys', () => { expect(stubModule('sys', 'src')).toBeUndefined(); }); + it('stubModule stubs zlib', () => { + expect(stubModule('zlib', 'src')).toEqual({ + name: 'zlib', + path: '../node_modules/browserify-zlib' + }); + }); + it('stubs empty module for some core module', () => { - expect(stubModule('fs', 'src')).toBe('define(function(){});'); + expect(stubModule('dns', 'src')).toBe('define(function(){});'); + }); + + it('stubs empty module for __ignore__', () => { + expect(stubModule('__ignore__', 'src')).toBe('define(function(){});'); }); });