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

fix: Disable compile time evaluation of import.meta.url #897

Merged
merged 9 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ function ncc (
loader: eval('__dirname + "/loaders/shebang-loader.js"')
}]
}
]
],
parser: {
javascript: { importMeta: false },
},
bjoluc marked this conversation as resolved.
Show resolved Hide resolved
},
plugins
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/import-meta-esm/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(import.meta.url);
7 changes: 7 additions & 0 deletions test/unit/import-meta-esm/output-coverage.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
36 changes: 27 additions & 9 deletions test/watcher.test.js
Original file line number Diff line number Diff line change
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);
});

51 changes: 32 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
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.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224"
bjoluc marked this conversation as resolved.
Show resolved Hide resolved
integrity sha512-PB3ldyrcnAicT35TWPs5IcwKD8S333HMaa2VVv4+wdvebJkjWuW/xESoB8IwRcog8HYVYamb1g/R31Qv5Bx03g==
dependencies:
"@types/eslint" "*"
"@types/estree" "*"
Expand All @@ -2329,11 +2329,16 @@
"@types/estree" "*"
"@types/json-schema" "*"

"@types/estree@*", "@types/estree@^0.0.50":
"@types/estree@*":
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@^0.0.51":
version "0.0.51"
resolved "https://registry.npmjs.org/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40"
integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==

"@types/[email protected]":
version "0.0.42"
resolved "https://registry.yarnpkg.com/@types/express-jwt/-/express-jwt-0.0.42.tgz#4f04e1fadf9d18725950dc041808a4a4adf7f5ae"
Expand Down Expand Up @@ -5797,14 +5802,22 @@ 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:
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==
dependencies:
graceful-fs "^4.2.4"
tapable "^2.2.0"

enhanced-resolve@^5.9.2:
version "5.9.2"
resolved "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.2.tgz#0224dcd6a43389ebfb2d55efee517e5466772dd9"
integrity sha512-GIm3fQfwLJ8YZx2smuHpBKkXC1yOk+OBEmKckVyL0i/ea8mqDEykK3ld5dgH1QYPNyT/lIllxV2LULnxCHaHkA==
dependencies:
graceful-fs "^4.2.4"
tapable "^2.2.0"

enquirer@^2.3.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d"
Expand Down Expand Up @@ -15717,9 +15730,9 @@ 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"
resolved "https://registry.npmjs.org/watchpack/-/watchpack-2.3.1.tgz#4200d9447b401156eeca7767ee610f8809bc9d25"
integrity sha512-x0t0JuydIo8qCNctdDrn1OzH/qDzk2+rdCOC3YzumZ42fiMqmQ7T3xQurykYMhYfHaPHTp4ZxAx2NfUo1K6QaA==
dependencies:
glob-to-regexp "^0.4.1"
Expand Down Expand Up @@ -15757,40 +15770,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.npmjs.org/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