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

update webpack, fix runtime location, fix undeclared variable, omit env vars from cache version #23113

Merged
merged 10 commits into from
Mar 17, 2021
22 changes: 2 additions & 20 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ export default async function getBaseWebpackConfig(
splitChunks: isServer ? false : splitChunksConfig,
runtimeChunk: isServer
? isWebpack5 && !isLikeServerless
? { name: `${dev ? '' : 'chunks/'}webpack-runtime` }
? { name: 'webpack-runtime' }
: undefined
: { name: CLIENT_STATIC_FILES_RUNTIME_WEBPACK },
minimize: !(dev || isServer),
Expand Down Expand Up @@ -1217,22 +1217,6 @@ export default async function getBaseWebpackConfig(
webpackConfig.optimization.usedExports = false
}

const nextPublicVariables = Object.keys(process.env)
.reduce((acc: string[], key: string) => {
if (key.startsWith('NEXT_PUBLIC_')) {
return [...acc, `${key}=${process.env[key]}`]
}
return acc
}, [])
.join('|')

const nextEnvVariables = Object.keys(config.env).reduce(
(prev: string, key: string) => {
return `${prev}|${key}=${config.env[key]}`
},
''
)

const configVars = JSON.stringify({
crossOrigin: config.crossOrigin,
pageExtensions: config.pageExtensions,
Expand All @@ -1257,10 +1241,8 @@ export default async function getBaseWebpackConfig(
type: 'filesystem',
// Includes:
// - Next.js version
// - NEXT_PUBLIC_ variable values (they affect caching) TODO: make this module usage only
// - next.config.js `env` key
// - next.config.js keys that affect compilation
version: `${process.env.__NEXT_VERSION}|${nextPublicVariables}|${nextEnvVariables}|${configVars}`,
version: `${process.env.__NEXT_VERSION}|${configVars}`,
cacheDirectory: path.join(dir, '.next', 'cache', 'webpack'),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ module.exports = function () {
var hot = {
// private stuff
_acceptedDependencies: {},
_acceptedErrorHandlers: {},
_declinedDependencies: {},
_selfAccepted: false,
_selfDeclined: false,
Expand All @@ -118,13 +119,18 @@ module.exports = function () {

// Module API
active: true,
accept: function (dep, callback) {
accept: function (dep, callback, errorHandler) {
if (dep === undefined) hot._selfAccepted = true;
else if (typeof dep === "function") hot._selfAccepted = dep;
else if (typeof dep === "object" && dep !== null)
for (var i = 0; i < dep.length; i++)
else if (typeof dep === "object" && dep !== null) {
for (var i = 0; i < dep.length; i++) {
hot._acceptedDependencies[dep[i]] = callback || function () {};
else hot._acceptedDependencies[dep] = callback || function () {};
hot._acceptedErrorHandlers[dep[i]] = errorHandler;
}
} else {
hot._acceptedDependencies[dep] = callback || function () {};
hot._acceptedErrorHandlers[dep] = errorHandler;
}
},
decline: function (dep) {
if (dep === undefined) hot._selfDeclined = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,19 @@ module.exports = function () {
var outdatedSelfAcceptedModules = [];
for (var j = 0; j < outdatedModules.length; j++) {
var outdatedModuleId = outdatedModules[j];
var module = $moduleCache$[outdatedModuleId];
if (
$moduleCache$[outdatedModuleId] &&
$moduleCache$[outdatedModuleId].hot._selfAccepted &&
module &&
module.hot._selfAccepted &&
// removed self-accepted modules should not be required
appliedUpdate[outdatedModuleId] !== warnUnexpectedRequire &&
// when called invalidate self-accepting is not possible
!$moduleCache$[outdatedModuleId].hot._selfInvalidated
!module.hot._selfInvalidated
) {
outdatedSelfAcceptedModules.push({
module: outdatedModuleId,
require: $moduleCache$[outdatedModuleId].hot._requireSelf,
errorHandler: $moduleCache$[outdatedModuleId].hot._selfAccepted
require: module.hot._requireSelf,
errorHandler: module.hot._selfAccepted
});
}
}
Expand Down Expand Up @@ -303,31 +304,58 @@ module.exports = function () {
moduleOutdatedDependencies =
outdatedDependencies[outdatedModuleId];
var callbacks = [];
var errorHandlers = [];
var dependenciesForCallbacks = [];
for (var j = 0; j < moduleOutdatedDependencies.length; j++) {
var dependency = moduleOutdatedDependencies[j];
var acceptCallback =
module.hot._acceptedDependencies[dependency];
var errorHandler =
module.hot._acceptedErrorHandlers[dependency];
if (acceptCallback) {
if (callbacks.indexOf(acceptCallback) !== -1) continue;
callbacks.push(acceptCallback);
errorHandlers.push(errorHandler);
dependenciesForCallbacks.push(dependency);
}
}
for (var k = 0; k < callbacks.length; k++) {
try {
callbacks[k].call(null, moduleOutdatedDependencies);
} catch (err) {
if (options.onErrored) {
options.onErrored({
type: "accept-errored",
moduleId: outdatedModuleId,
dependencyId: dependenciesForCallbacks[k],
error: err
});
}
if (!options.ignoreErrored) {
reportError(err);
if (typeof errorHandlers[k] === "function") {
try {
errorHandlers[k](err, {
moduleId: outdatedModuleId,
dependencyId: dependenciesForCallbacks[k]
});
} catch (err2) {
if (options.onErrored) {
options.onErrored({
type: "accept-error-handler-errored",
moduleId: outdatedModuleId,
dependencyId: dependenciesForCallbacks[k],
error: err2,
originalError: err
});
}
if (!options.ignoreErrored) {
reportError(err2);
reportError(err);
}
}
} else {
if (options.onErrored) {
options.onErrored({
type: "accept-errored",
moduleId: outdatedModuleId,
dependencyId: dependenciesForCallbacks[k],
error: err
});
}
if (!options.ignoreErrored) {
reportError(err);
}
}
}
}
Expand All @@ -344,7 +372,10 @@ module.exports = function () {
} catch (err) {
if (typeof item.errorHandler === "function") {
try {
item.errorHandler(err);
item.errorHandler(err, {
moduleId: moduleId,
module: $moduleCache$[moduleId]
});
} catch (err2) {
if (options.onErrored) {
options.onErrored({
Expand All @@ -356,8 +387,8 @@ module.exports = function () {
}
if (!options.ignoreErrored) {
reportError(err2);
reportError(err);
}
reportError(err);
}
} else {
if (options.onErrored) {
Expand Down
24 changes: 12 additions & 12 deletions packages/next/bundles/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==

"@types/node@*":
version "14.14.32"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.32.tgz#90c5c4a8d72bbbfe53033f122341343249183448"
integrity sha512-/Ctrftx/zp4m8JOujM5ZhwzlWLx22nbQJiVqz8/zE15gOeEW+uly3FSX4fGFpcfEvFzXcMCJwq9lGVWgyARXhg==
version "14.14.35"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.35.tgz#42c953a4e2b18ab931f72477e7012172f4ffa313"
integrity sha512-Lt+wj8NVPx0zUmUwumiVXapmaLUcAk3yPuHCFVXras9k5VT9TdhJqKqGVUQCD60OTMCl0qxJ57OiTL0Mic3Iag==

"@webassemblyjs/ast@1.11.0":
version "1.11.0"
Expand Down Expand Up @@ -165,9 +165,9 @@
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==

acorn@^8.0.4:
version "8.0.5"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.0.5.tgz#a3bfb872a74a6a7f661bc81b9849d9cac12601b7"
integrity sha512-v+DieK/HJkJOpFBETDJioequtc3PfxsWMaxIdIwujtF7FEV/MAyDQLlm6/zPvr7Mix07mLh6ccVwIsloceodlg==
version "8.1.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.1.0.tgz#52311fd7037ae119cbb134309e901aa46295b3fe"
integrity sha512-LWCF/Wn0nfHOmJ9rzQApGnxnvgfROzGilS8936rqN/lfcYkY9MYZzdMqN+2NJ4SlTc+m5HiSa+kNfDtI64dwUA==

ajv-keywords@^3.5.2:
version "3.5.2"
Expand Down Expand Up @@ -223,9 +223,9 @@ commander@^2.20.0:
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

electron-to-chromium@^1.3.634:
version "1.3.682"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.682.tgz#f4b5c8d4479df96b61e508a721d6c32c1262ef23"
integrity sha512-zok2y37qR00U14uM6qBz/3iIjWHom2eRfC2S1StA0RslP7x34jX+j4mxv80t8OEOHLJPVG54ZPeaFxEI7gPrwg==
version "1.3.690"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.690.tgz#54df63ec42fba6b8e9e05fe4be52caeeedb6e634"
integrity sha512-zPbaSv1c8LUKqQ+scNxJKv01RYFkVVF1xli+b+3Ty8ONujHjAMg+t/COmdZqrtnS1gT+g4hbSodHillymt1Lww==

enhanced-resolve@^5.7.0:
version "5.7.0"
Expand Down Expand Up @@ -476,9 +476,9 @@ watchpack@^2.0.0:
source-map "^0.6.1"

"webpack5@npm:webpack@5":
version "5.24.4"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.24.4.tgz#37d8cf95841dd23c809ea02931294b3455d74a59"
integrity sha512-RXOdxF9hFFFhg47BryCgyFrEyyu7Y/75/uiI2DoUiTMqysK+WczVSTppvkR47oZcmI/DPaXCiCiaXBP8QjkNpA==
version "5.26.2"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.26.2.tgz#b61c018c9abdb7c67b08e2783ba46fe8723f59e8"
integrity sha512-h07tAPeQceEO3Idrevqv4ECcpMH8Zp0aUUJ+IytujWTVf6TF5PI3rKVw0Z+7rNjU4qJuEx18BykFxgRvR9VgEQ==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.46"
Expand Down
14 changes: 10 additions & 4 deletions packages/next/compiled/webpack/HotModuleReplacement.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ module.exports = function () {
var hot = {
// private stuff
_acceptedDependencies: {},
_acceptedErrorHandlers: {},
_declinedDependencies: {},
_selfAccepted: false,
_selfDeclined: false,
Expand All @@ -118,13 +119,18 @@ module.exports = function () {

// Module API
active: true,
accept: function (dep, callback) {
accept: function (dep, callback, errorHandler) {
if (dep === undefined) hot._selfAccepted = true;
else if (typeof dep === "function") hot._selfAccepted = dep;
else if (typeof dep === "object" && dep !== null)
for (var i = 0; i < dep.length; i++)
else if (typeof dep === "object" && dep !== null) {
for (var i = 0; i < dep.length; i++) {
hot._acceptedDependencies[dep[i]] = callback || function () {};
else hot._acceptedDependencies[dep] = callback || function () {};
hot._acceptedErrorHandlers[dep[i]] = errorHandler;
}
} else {
hot._acceptedDependencies[dep] = callback || function () {};
hot._acceptedErrorHandlers[dep] = errorHandler;
}
},
decline: function (dep) {
if (dep === undefined) hot._selfDeclined = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,19 @@ module.exports = function () {
var outdatedSelfAcceptedModules = [];
for (var j = 0; j < outdatedModules.length; j++) {
var outdatedModuleId = outdatedModules[j];
var module = $moduleCache$[outdatedModuleId];
if (
$moduleCache$[outdatedModuleId] &&
$moduleCache$[outdatedModuleId].hot._selfAccepted &&
module &&
module.hot._selfAccepted &&
// removed self-accepted modules should not be required
appliedUpdate[outdatedModuleId] !== warnUnexpectedRequire &&
// when called invalidate self-accepting is not possible
!$moduleCache$[outdatedModuleId].hot._selfInvalidated
!module.hot._selfInvalidated
) {
outdatedSelfAcceptedModules.push({
module: outdatedModuleId,
require: $moduleCache$[outdatedModuleId].hot._requireSelf,
errorHandler: $moduleCache$[outdatedModuleId].hot._selfAccepted
require: module.hot._requireSelf,
errorHandler: module.hot._selfAccepted
});
}
}
Expand Down Expand Up @@ -303,31 +304,58 @@ module.exports = function () {
moduleOutdatedDependencies =
outdatedDependencies[outdatedModuleId];
var callbacks = [];
var errorHandlers = [];
var dependenciesForCallbacks = [];
for (var j = 0; j < moduleOutdatedDependencies.length; j++) {
var dependency = moduleOutdatedDependencies[j];
var acceptCallback =
module.hot._acceptedDependencies[dependency];
var errorHandler =
module.hot._acceptedErrorHandlers[dependency];
if (acceptCallback) {
if (callbacks.indexOf(acceptCallback) !== -1) continue;
callbacks.push(acceptCallback);
errorHandlers.push(errorHandler);
dependenciesForCallbacks.push(dependency);
}
}
for (var k = 0; k < callbacks.length; k++) {
try {
callbacks[k].call(null, moduleOutdatedDependencies);
} catch (err) {
if (options.onErrored) {
options.onErrored({
type: "accept-errored",
moduleId: outdatedModuleId,
dependencyId: dependenciesForCallbacks[k],
error: err
});
}
if (!options.ignoreErrored) {
reportError(err);
if (typeof errorHandlers[k] === "function") {
try {
errorHandlers[k](err, {
moduleId: outdatedModuleId,
dependencyId: dependenciesForCallbacks[k]
});
} catch (err2) {
if (options.onErrored) {
options.onErrored({
type: "accept-error-handler-errored",
moduleId: outdatedModuleId,
dependencyId: dependenciesForCallbacks[k],
error: err2,
originalError: err
});
}
if (!options.ignoreErrored) {
reportError(err2);
reportError(err);
}
}
} else {
if (options.onErrored) {
options.onErrored({
type: "accept-errored",
moduleId: outdatedModuleId,
dependencyId: dependenciesForCallbacks[k],
error: err
});
}
if (!options.ignoreErrored) {
reportError(err);
}
}
}
}
Expand All @@ -344,7 +372,10 @@ module.exports = function () {
} catch (err) {
if (typeof item.errorHandler === "function") {
try {
item.errorHandler(err);
item.errorHandler(err, {
moduleId: moduleId,
module: $moduleCache$[moduleId]
});
} catch (err2) {
if (options.onErrored) {
options.onErrored({
Expand All @@ -356,8 +387,8 @@ module.exports = function () {
}
if (!options.ignoreErrored) {
reportError(err2);
reportError(err);
}
reportError(err);
}
} else {
if (options.onErrored) {
Expand Down
Loading