Skip to content

Commit

Permalink
fix: Disable compile time evaluation of import.meta.url (#897)
Browse files Browse the repository at this point in the history
I'm affected by webpack/webpack#14445, fixed in webpack/webpack#15246, available in webpack >= [v5.68.0](https://github.com/webpack/webpack/releases/tag/v5.68.0), so I'd love to have an ncc version using webpack >= v5.68.0!

Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
bjoluc and styfle committed Sep 30, 2022
1 parent be7f614 commit 3a83d6d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -109,7 +109,7 @@
"vue": "^2.5.17",
"vue-server-renderer": "^2.5.17",
"web-vitals": "^0.2.4",
"webpack": "5.62.1",
"webpack": "5.70.0",
"when": "^3.7.8"
},
"resolutions": {
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Expand Up @@ -376,7 +376,10 @@ function ncc (
loader: eval('__dirname + "/loaders/shebang-loader.js"')
}]
}
]
],
parser: {
javascript: { importMeta: false },
},
},
plugins
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/import-meta-esm/input.js
@@ -0,0 +1 @@
console.log(import.meta.url);
7 changes: 7 additions & 0 deletions test/unit/import-meta-esm/output-coverage.js
@@ -0,0 +1,7 @@
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
console.log(import.meta.url);
7 changes: 7 additions & 0 deletions test/unit/import-meta-esm/output.js
@@ -0,0 +1,7 @@
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
console.log(import.meta.url);
3 changes: 3 additions & 0 deletions test/unit/import-meta-esm/package.json
@@ -0,0 +1,3 @@
{
"type": "module"
}
36 changes: 27 additions & 9 deletions test/watcher.test.js
Expand Up @@ -13,6 +13,7 @@ class CustomWatchFileSystem {
// paused allows the watchers to stay open for the next build
this.paused = false;
this.changeCallback = undefined;
this.changeCallbackUndelayed = undefined;
this.watchStart = watchStart;
this.watchEnd = watchEnd;

Expand All @@ -21,6 +22,8 @@ class CustomWatchFileSystem {
this.dirs = undefined;
this.missing = undefined;
this.timestamps = new Map();
this.changes = new Set();
this.removals = new Set();

// this will be populated for us by ncc
this.inputFileSystem = undefined;
Expand All @@ -38,11 +41,21 @@ class CustomWatchFileSystem {
for (const file of removed)
this.timestamps.set(file, null);

for (const file of changed)
for (const file of changed) {
this.changes.add(file);
this.inputFileSystem.purge(file);
for (const file of removed)
}
for (const file of removed) {
this.removals.add(file);
this.inputFileSystem.purge(file);
}

this.changeCallbackUndelayed(
null,
this.timestamps,
this.timestamps,
removed
);
this.changeCallback(
null,
this.timestamps,
Expand All @@ -53,7 +66,7 @@ class CustomWatchFileSystem {
}

// This is called on every rebuild
watch (files, dirs, missing, startTime, options, changeCallback) {
watch (files, dirs, missing, startTime, options, changeCallback, changeCallbackUndelayed) {
this.files = new Set(files);
this.dirs = new Set(dirs);
this.missing = new Set(missing);
Expand All @@ -70,6 +83,7 @@ class CustomWatchFileSystem {

this.paused = false;
this.changeCallback = changeCallback;
this.changeCallbackUndelayed = changeCallbackUndelayed;

// ...Start watching files, dirs, missing
setImmediate(() => {
Expand All @@ -83,12 +97,12 @@ class CustomWatchFileSystem {
pause: () => {
this.paused = true;
},
getFileTimestamps: () => {
return this.timestamps;
},
getContextTimestamps: () => {
return this.timestamps;
}
getInfo: () => ({
changes: this.changes,
removals: this.removals,
fileTimeInfoEntries: this.timestamps,
contextTimeInfoEntries: this.timestamps,
}),
};
}
}
Expand All @@ -98,6 +112,8 @@ jest.setTimeout(30000);
it('Should support custom watch API', async () => {
let buildCnt = 0;
const buildFile = path.resolve('./test/integration/twilio.js');
const initialBuildFileContents = fs.readFileSync(buildFile).toString();

await new Promise((resolve, reject) => {
const watcher = new CustomWatchFileSystem(function watchStart (files, dirs, missing) {
expect(files._set.size).toBeGreaterThan(100);
Expand Down Expand Up @@ -136,5 +152,7 @@ it('Should support custom watch API', async () => {
console.time('Watched Build');
});
});

fs.writeFileSync(buildFile, initialBuildFileContents);
});

42 changes: 21 additions & 21 deletions yarn.lock
Expand Up @@ -2313,10 +2313,10 @@
dependencies:
"@types/ms" "*"

"@types/eslint-scope@^3.7.0":
version "3.7.0"
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.0.tgz#4792816e31119ebd506902a482caec4951fabd86"
integrity sha512-O/ql2+rrCUe2W2rs7wMR+GqPRcgB6UiqN5RhrR5xruFlY7l9YLMn0ZkDzjoHLeiFkR8MCQZVudUuuvQ2BLC9Qw==
"@types/eslint-scope@^3.7.3":
version "3.7.3"
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224"
integrity sha512-PB3ldyrcnAicT35TWPs5IcwKD8S333HMaa2VVv4+wdvebJkjWuW/xESoB8IwRcog8HYVYamb1g/R31Qv5Bx03g==
dependencies:
"@types/eslint" "*"
"@types/estree" "*"
Expand All @@ -2329,10 +2329,10 @@
"@types/estree" "*"
"@types/json-schema" "*"

"@types/estree@*", "@types/estree@^0.0.50":
version "0.0.50"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.50.tgz#1e0caa9364d3fccd2931c3ed96fdbeaa5d4cca83"
integrity sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw==
"@types/estree@*", "@types/estree@^0.0.51":
version "0.0.51"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40"
integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==

"@types/express-jwt@0.0.42":
version "0.0.42"
Expand Down Expand Up @@ -5797,7 +5797,7 @@ engine.io@~5.1.1:
engine.io-parser "~4.0.0"
ws "~7.4.2"

enhanced-resolve@^5.0.0, enhanced-resolve@^5.7.0, enhanced-resolve@^5.8.3:
enhanced-resolve@^5.0.0, enhanced-resolve@^5.7.0, enhanced-resolve@^5.9.2:
version "5.9.3"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.9.3.tgz#44a342c012cbc473254af5cc6ae20ebd0aae5d88"
integrity sha512-Bq9VSor+kjvW3f9/MiiR4eE3XYgOl7/rS8lnSxbRbF3kS0B2r+Y9w5krBWxZgDxASVZbdYrn5wT4j/Wb0J9qow==
Expand Down Expand Up @@ -15717,7 +15717,7 @@ watchify@^3.3.0:
through2 "^2.0.0"
xtend "^4.0.0"

watchpack@^2.2.0:
watchpack@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.3.1.tgz#4200d9447b401156eeca7767ee610f8809bc9d25"
integrity sha512-x0t0JuydIo8qCNctdDrn1OzH/qDzk2+rdCOC3YzumZ42fiMqmQ7T3xQurykYMhYfHaPHTp4ZxAx2NfUo1K6QaA==
Expand Down Expand Up @@ -15757,40 +15757,40 @@ webidl-conversions@^6.1.0:
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-6.1.0.tgz#9111b4d7ea80acd40f5270d666621afa78b69514"
integrity sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w==

webpack-sources@^3.0.0, webpack-sources@^3.2.0:
webpack-sources@^3.0.0, webpack-sources@^3.2.3:
version "3.2.3"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==

webpack@5.62.1:
version "5.62.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.62.1.tgz#06f09b56a7b1bb13ed5137ad4b118358a90c9505"
integrity sha512-jNLtnWChS2CMZ7vqWtztv0G6fYB5hz11Zsadp5tE7e4/66zVDj7/KUeQZOsOl8Hz5KrLJH1h2eIDl6AnlyE12Q==
webpack@5.70.0:
version "5.70.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.70.0.tgz#3461e6287a72b5e6e2f4872700bc8de0d7500e6d"
integrity sha512-ZMWWy8CeuTTjCxbeaQI21xSswseF2oNOwc70QSKNePvmxE7XW36i7vpBMYZFAUHPwQiEbNGCEYIOOlyRbdGmxw==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.50"
"@types/eslint-scope" "^3.7.3"
"@types/estree" "^0.0.51"
"@webassemblyjs/ast" "1.11.1"
"@webassemblyjs/wasm-edit" "1.11.1"
"@webassemblyjs/wasm-parser" "1.11.1"
acorn "^8.4.1"
acorn-import-assertions "^1.7.6"
browserslist "^4.14.5"
chrome-trace-event "^1.0.2"
enhanced-resolve "^5.8.3"
enhanced-resolve "^5.9.2"
es-module-lexer "^0.9.0"
eslint-scope "5.1.1"
events "^3.2.0"
glob-to-regexp "^0.4.1"
graceful-fs "^4.2.4"
graceful-fs "^4.2.9"
json-parse-better-errors "^1.0.2"
loader-runner "^4.2.0"
mime-types "^2.1.27"
neo-async "^2.6.2"
schema-utils "^3.1.0"
tapable "^2.1.1"
terser-webpack-plugin "^5.1.3"
watchpack "^2.2.0"
webpack-sources "^3.2.0"
watchpack "^2.3.1"
webpack-sources "^3.2.3"

websocket-driver@>=0.5.1:
version "0.7.4"
Expand Down

0 comments on commit 3a83d6d

Please sign in to comment.