Merge pull request #10852 from martynd/DelegatedModule-Serializable

Add serialization to DelegatedModule.js and DelegatedSourceDependency.js
This commit is contained in:
Tobias Koppers 2020-06-02 17:06:34 +02:00 committed by GitHub
commit a4d06805f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 614 additions and 419 deletions

View File

@ -10,6 +10,7 @@ const Module = require("./Module");
const RuntimeGlobals = require("./RuntimeGlobals");
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
const makeSerializable = require("./util/makeSerializable");
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
@ -182,6 +183,48 @@ class DelegatedModule extends Module {
hash.update(JSON.stringify(this.request));
super.updateHash(hash, chunkGraph);
}
serialize(context) {
const { write } = context;
// constructor
write(this.sourceRequest);
write(this.delegateData);
write(this.delegationType);
write(this.userRequest);
write(this.originalRequest);
super.serialize(context);
}
static deserialize(context) {
const { read } = context;
const obj = new DelegatedModule(
read(), // sourceRequest
read(), // delegateData
read(), // delegationType
read(), // userRequest
read() // originalRequest
);
obj.deserialize(context);
return obj;
}
/**
* Assuming this module is in the cache. Update the (cached) module with
* the fresh module from the factory. Usually updates internal references
* and properties.
* @param {Module} module fresh module
* @returns {void}
*/
updateCacheModule(module) {
super.updateCacheModule(module);
const m = /** @type {DelegatedModule} */ (module);
this.delegationType = m.delegationType;
this.userRequest = m.userRequest;
this.originalRequest = m.originalRequest;
this.delegateData = m.delegateData;
}
}
makeSerializable(DelegatedModule, "webpack/lib/DelegatedModule");
module.exports = DelegatedModule;

View File

@ -8,6 +8,7 @@
const { RawSource } = require("webpack-sources");
const Module = require("./Module");
const RuntimeGlobals = require("./RuntimeGlobals");
const makeSerializable = require("./util/makeSerializable");
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
@ -119,6 +120,30 @@ class DllModule extends Module {
hash.update(this.name || "");
super.updateHash(hash, chunkGraph);
}
serialize(context) {
context.write(this.name);
super.serialize(context);
}
deserialize(context) {
this.name = context.read();
super.deserialize(context);
}
/**
* Assuming this module is in the cache. Update the (cached) module with
* the fresh module from the factory. Usually updates internal references
* and properties.
* @param {Module} module fresh module
* @returns {void}
*/
updateCacheModule(module) {
super.updateCacheModule(module);
this.dependencies = module.dependencies;
}
}
makeSerializable(DllModule, "webpack/lib/DllModule");
module.exports = DllModule;

View File

@ -148,7 +148,7 @@ const createTrace = (fs, outputPath) => {
profiler,
end: callback => {
// Wait until the write stream finishes.
fsStream.on("finish", () => {
fsStream.on("close", () => {
callback();
});
// Tear down the readable trace stream.

View File

@ -5,6 +5,7 @@
"use strict";
const makeSerializable = require("../util/makeSerializable");
const ModuleDependency = require("./ModuleDependency");
class DelegatedSourceDependency extends ModuleDependency {
@ -17,4 +18,9 @@ class DelegatedSourceDependency extends ModuleDependency {
}
}
makeSerializable(
DelegatedSourceDependency,
"webpack/lib/dependencies/DelegatedSourceDependency"
);
module.exports = DelegatedSourceDependency;

View File

@ -5,6 +5,7 @@
"use strict";
const makeSerializable = require("../util/makeSerializable");
const ModuleDependency = require("./ModuleDependency");
class EntryDependency extends ModuleDependency {
@ -20,4 +21,6 @@ class EntryDependency extends ModuleDependency {
}
}
makeSerializable(EntryDependency, "webpack/lib/dependencies/EntryDependency");
module.exports = EntryDependency;

View File

@ -0,0 +1,16 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
*/
"use strict";
class DateObjectSerializer {
serialize(obj, { write }) {
write(obj.getTime());
}
deserialize({ read }) {
return new Date(read());
}
}
module.exports = DateObjectSerializer;

View File

@ -5,6 +5,7 @@
"use strict";
const ArraySerializer = require("./ArraySerializer");
const DateObjectSerializer = require("./DateObjectSerializer");
const ErrorObjectSerializer = require("./ErrorObjectSerializer");
const MapObjectSerializer = require("./MapObjectSerializer");
const NullPrototypeObjectSerializer = require("./NullPrototypeObjectSerializer");
@ -94,6 +95,7 @@ jsTypes.set(Array, new ArraySerializer());
jsTypes.set(null, new NullPrototypeObjectSerializer());
jsTypes.set(Map, new MapObjectSerializer());
jsTypes.set(Set, new SetObjectSerializer());
jsTypes.set(Date, new DateObjectSerializer());
jsTypes.set(RegExp, new RegExpObjectSerializer());
jsTypes.set(Error, new ErrorObjectSerializer(Error));
jsTypes.set(EvalError, new ErrorObjectSerializer(EvalError));
@ -267,17 +269,26 @@ class ObjectMiddleware extends SerializerMiddleware {
} catch (e) {
// ignore -> fallback
}
if (typeof item === "object" && item !== null && item.constructor) {
if (item.constructor === Object)
return `Object { ${Object.keys(item).join(", ")} }`;
if (item.constructor === Map) return `Map { ${item.size} items }`;
if (item.constructor === Array)
return `Array { ${item.length} items }`;
if (item.constructor === Set) return `Set { ${item.size} items }`;
if (item.constructor === RegExp) return item.toString();
return `${item.constructor.name}`;
if (typeof item === "object" && item !== null) {
if (item.constructor) {
if (item.constructor === Object)
return `Object { ${Object.keys(item).join(", ")} }`;
if (item.constructor === Map) return `Map { ${item.size} items }`;
if (item.constructor === Array)
return `Array { ${item.length} items }`;
if (item.constructor === Set) return `Set { ${item.size} items }`;
if (item.constructor === RegExp) return item.toString();
return `${item.constructor.name}`;
}
return `Object [null prototype] { ${Object.keys(item).join(
", "
)} }`;
}
try {
return `${item}`;
} catch (e) {
return `(${e.message})`;
}
return `${item}`;
})
.join(" -> ");
};

View File

@ -63,8 +63,12 @@ module.exports = {
require("../dependencies/ContextElementDependency"),
"dependencies/CriticalDependencyWarning": () =>
require("../dependencies/CriticalDependencyWarning"),
"dependencies/DelegatedSourceDependency": () =>
require("../dependencies/DelegatedSourceDependency"),
"dependencies/DllEntryDependency": () =>
require("../dependencies/DllEntryDependency"),
"dependencies/EntryDependency": () =>
require("../dependencies/EntryDependency"),
"dependencies/ExportsInfoDependency": () =>
require("../dependencies/ExportsInfoDependency"),
"dependencies/HarmonyAcceptDependency": () =>
@ -144,7 +148,9 @@ module.exports = {
require("../dependencies/WebAssemblyImportDependency"),
"optimize/ConcatenatedModule": () =>
require("../optimize/ConcatenatedModule"),
DelegatedModule: () => require("../DelegatedModule"),
DependenciesBlock: () => require("../DependenciesBlock"),
DllModule: () => require("../DllModule"),
ExternalModule: () => require("../ExternalModule"),
Module: () => require("../Module"),
ModuleBuildError: () => require("../ModuleBuildError"),

View File

@ -80,7 +80,7 @@
"strip-ansi": "^6.0.0",
"style-loader": "^1.0.0",
"toml": "^3.0.0",
"tooling": "webpack/tooling#v1.7.0",
"tooling": "webpack/tooling#v1.8.0",
"ts-loader": "^6.0.4",
"typescript": "^3.9.2",
"url-loader": "^4.1.0",

View File

@ -0,0 +1,10 @@
const path = require("path");
const { describeCases } = require("./ConfigTestCases.template");
describeCases({
name: "ConfigCacheTestCases",
cache: {
type: "filesystem",
managedPaths: [path.resolve(__dirname, "../node_modules")]
}
});

View File

@ -0,0 +1,349 @@
"use strict";
const path = require("path");
const fs = require("graceful-fs");
const vm = require("vm");
const rimraf = require("rimraf");
const checkArrayExpectation = require("./checkArrayExpectation");
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
const deprecationTracking = require("./helpers/deprecationTracking");
const FakeDocument = require("./helpers/FakeDocument");
const webpack = require("..");
const prepareOptions = require("./helpers/prepareOptions");
const casesPath = path.join(__dirname, "configCases");
const categories = fs.readdirSync(casesPath).map(cat => {
return {
name: cat,
tests: fs
.readdirSync(path.join(casesPath, cat))
.filter(folder => !folder.startsWith("_"))
.sort()
};
});
const describeCases = config => {
describe(config.name, () => {
jest.setTimeout(20000);
for (const category of categories) {
describe(category.name, () => {
for (const testName of category.tests) {
describe(testName, function () {
const testDirectory = path.join(casesPath, category.name, testName);
const filterPath = path.join(testDirectory, "test.filter.js");
if (fs.existsSync(filterPath) && !require(filterPath)()) {
describe.skip(testName, () => {
it("filtered", () => {});
});
return;
}
const outBaseDir = path.join(__dirname, "js");
const testSubPath = path.join(config.name, category.name, testName);
const outputDirectory = path.join(outBaseDir, testSubPath);
const cacheDirectory = path.join(outBaseDir, ".cache", testSubPath);
let options, optionsArr, testConfig;
beforeAll(() => {
options = prepareOptions(
require(path.join(testDirectory, "webpack.config.js")),
{ testPath: outputDirectory }
);
optionsArr = [].concat(options);
optionsArr.forEach((options, idx) => {
if (!options.context) options.context = testDirectory;
if (!options.mode) options.mode = "production";
if (!options.optimization) options.optimization = {};
if (options.optimization.minimize === undefined)
options.optimization.minimize = false;
if (!options.entry) options.entry = "./index.js";
if (!options.target) options.target = "async-node";
if (!options.output) options.output = {};
if (!options.output.path) options.output.path = outputDirectory;
if (typeof options.output.pathinfo === "undefined")
options.output.pathinfo = true;
if (!options.output.filename)
options.output.filename = "bundle" + idx + ".js";
if (config.cache) {
options.cache = {
cacheDirectory,
name: `config-${idx}`,
...config.cache
};
}
});
testConfig = {
findBundle: function (i, options) {
const ext = path.extname(options.output.filename);
if (
fs.existsSync(
path.join(options.output.path, "bundle" + i + ext)
)
) {
return "./bundle" + i + ext;
}
},
timeout: 30000
};
try {
// try to load a test file
testConfig = Object.assign(
testConfig,
require(path.join(testDirectory, "test.config.js"))
);
} catch (e) {
// ignored
}
if (testConfig.timeout) setDefaultTimeout(testConfig.timeout);
});
beforeAll(() => {
rimraf.sync(cacheDirectory);
});
const handleFatalError = (err, done) => {
const fakeStats = {
errors: [
{
message: err.message,
stack: err.stack
}
]
};
if (
checkArrayExpectation(
testDirectory,
fakeStats,
"error",
"Error",
done
)
) {
return;
}
// Wait for uncaught errors to occur
setTimeout(done, 200);
return;
};
if (config.cache) {
it(`${testName} should pre-compile to fill disk cache (1st)`, done => {
rimraf.sync(outputDirectory);
fs.mkdirSync(outputDirectory, { recursive: true });
const deprecationTracker = deprecationTracking.start();
webpack(options, err => {
deprecationTracker();
if (err) return handleFatalError(err, done);
done();
});
}, 60000);
it(`${testName} should pre-compile to fill disk cache (2nd)`, done => {
rimraf.sync(outputDirectory);
fs.mkdirSync(outputDirectory, { recursive: true });
const deprecationTracker = deprecationTracking.start();
webpack(options, err => {
deprecationTracker();
if (err) return handleFatalError(err, done);
done();
});
}, 20000);
}
it(`${testName} should compile`, done => {
rimraf.sync(outputDirectory);
fs.mkdirSync(outputDirectory, { recursive: true });
const deprecationTracker = deprecationTracking.start();
webpack(options, (err, stats) => {
const deprecations = deprecationTracker();
if (err) return handleFatalError(err, done);
const statOptions = {
preset: "verbose",
colors: false
};
fs.mkdirSync(outputDirectory, { recursive: true });
fs.writeFileSync(
path.join(outputDirectory, "stats.txt"),
stats.toString(statOptions),
"utf-8"
);
const jsonStats = stats.toJson({
errorDetails: true
});
fs.writeFileSync(
path.join(outputDirectory, "stats.json"),
JSON.stringify(jsonStats, null, 2),
"utf-8"
);
if (
checkArrayExpectation(
testDirectory,
jsonStats,
"error",
"Error",
done
)
) {
return;
}
if (
checkArrayExpectation(
testDirectory,
jsonStats,
"warning",
"Warning",
done
)
) {
return;
}
if (
checkArrayExpectation(
testDirectory,
{ deprecations },
"deprecation",
"Deprecation",
done
)
) {
return;
}
const globalContext = {
console: console,
expect: expect,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
document: new FakeDocument(),
location: {
href: "https://test.cases/path/index.html",
origin: "https://test.cases",
toString() {
return "https://test.cases/path/index.html";
}
}
};
const requireCache = Object.create(null);
function _require(currentDirectory, options, module) {
if (Array.isArray(module) || /^\.\.?\//.test(module)) {
let content;
let p;
if (Array.isArray(module)) {
p = path.join(currentDirectory, ".array-require.js");
content = `module.exports = (${module
.map(arg => {
return `require(${JSON.stringify(`./${arg}`)})`;
})
.join(", ")});`;
} else {
p = path.join(currentDirectory, module);
content = fs.readFileSync(p, "utf-8");
}
if (p in requireCache) {
return requireCache[p].exports;
}
const m = {
exports: {}
};
requireCache[p] = m;
let runInNewContext = false;
const moduleScope = {
require: _require.bind(null, path.dirname(p), options),
importScripts: _require.bind(
null,
path.dirname(p),
options
),
module: m,
exports: m.exports,
__dirname: path.dirname(p),
__filename: p,
it: _it,
beforeEach: _beforeEach,
afterEach: _afterEach,
expect,
jest,
_globalAssign: { expect },
__STATS__: jsonStats,
nsObj: m => {
Object.defineProperty(m, Symbol.toStringTag, {
value: "Module"
});
return m;
}
};
if (
options.target === "web" ||
options.target === "webworker"
) {
moduleScope.window = globalContext;
moduleScope.self = globalContext;
runInNewContext = true;
}
if (testConfig.moduleScope) {
testConfig.moduleScope(moduleScope);
}
const args = Object.keys(moduleScope).join(", ");
if (!runInNewContext)
content = `Object.assign(global, _globalAssign); ${content}`;
const code = `(function({${args}}) {${content}\n})`;
const fn = runInNewContext
? vm.runInNewContext(code, globalContext, p)
: vm.runInThisContext(code, p);
fn.call(m.exports, moduleScope);
return m.exports;
} else if (
testConfig.modules &&
module in testConfig.modules
) {
return testConfig.modules[module];
} else return require(module);
}
let filesCount = 0;
if (testConfig.noTests) return process.nextTick(done);
if (testConfig.beforeExecute) testConfig.beforeExecute();
const results = [];
for (let i = 0; i < optionsArr.length; i++) {
const bundlePath = testConfig.findBundle(i, optionsArr[i]);
if (bundlePath) {
filesCount++;
results.push(
_require(outputDirectory, optionsArr[i], bundlePath)
);
}
}
// give a free pass to compilation that generated an error
if (
!jsonStats.errors.length &&
filesCount !== optionsArr.length
) {
return done(
new Error(
"Should have found at least one bundle file per webpack config"
)
);
}
Promise.all(results)
.then(() => {
if (testConfig.afterExecute) testConfig.afterExecute();
if (getNumberOfTests() < filesCount) {
return done(new Error("No tests exported by test case"));
}
done();
})
.catch(done);
});
});
const {
it: _it,
beforeEach: _beforeEach,
afterEach: _afterEach,
setDefaultTimeout,
getNumberOfTests
} = createLazyTestEnv(jasmine.getEnv(), 10000);
});
}
});
}
});
};
exports.describeCases = describeCases;

View File

@ -1,325 +1,5 @@
"use strict";
const { describeCases } = require("./ConfigTestCases.template");
const path = require("path");
const fs = require("graceful-fs");
const vm = require("vm");
const rimraf = require("rimraf");
const checkArrayExpectation = require("./checkArrayExpectation");
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
const deprecationTracking = require("./helpers/deprecationTracking");
const FakeDocument = require("./helpers/FakeDocument");
const webpack = require("..");
const prepareOptions = require("./helpers/prepareOptions");
describe("ConfigTestCases", () => {
const casesPath = path.join(__dirname, "configCases");
let categories = fs.readdirSync(casesPath);
jest.setTimeout(20000);
categories = categories.map(cat => {
return {
name: cat,
tests: fs
.readdirSync(path.join(casesPath, cat))
.filter(folder => {
return folder.indexOf("_") < 0;
})
.sort()
.filter(testName => {
const testDirectory = path.join(casesPath, cat, testName);
const filterPath = path.join(testDirectory, "test.filter.js");
if (fs.existsSync(filterPath) && !require(filterPath)()) {
describe.skip(testName, () => {
it("filtered", () => {});
});
return false;
}
return true;
})
};
});
categories.forEach(category => {
describe(category.name, () => {
category.tests.forEach(testName => {
describe(testName, function () {
const testDirectory = path.join(casesPath, category.name, testName);
const outputDirectory = path.join(
__dirname,
"js",
"config",
category.name,
testName
);
it(
testName + " should compile",
() =>
new Promise((resolve, reject) => {
const done = err => {
if (err) return reject(err);
resolve();
};
rimraf.sync(outputDirectory);
fs.mkdirSync(outputDirectory, { recursive: true });
const options = prepareOptions(
require(path.join(testDirectory, "webpack.config.js")),
{ testPath: outputDirectory }
);
const optionsArr = [].concat(options);
optionsArr.forEach((options, idx) => {
if (!options.context) options.context = testDirectory;
if (!options.mode) options.mode = "production";
if (!options.optimization) options.optimization = {};
if (options.optimization.minimize === undefined)
options.optimization.minimize = false;
if (!options.entry) options.entry = "./index.js";
if (!options.target) options.target = "async-node";
if (!options.output) options.output = {};
if (!options.output.path)
options.output.path = outputDirectory;
if (typeof options.output.pathinfo === "undefined")
options.output.pathinfo = true;
if (!options.output.filename)
options.output.filename = "bundle" + idx + ".js";
});
let testConfig = {
findBundle: function (i, options) {
const ext = path.extname(options.output.filename);
if (
fs.existsSync(
path.join(options.output.path, "bundle" + i + ext)
)
) {
return "./bundle" + i + ext;
}
},
timeout: 30000
};
try {
// try to load a test file
testConfig = Object.assign(
testConfig,
require(path.join(testDirectory, "test.config.js"))
);
} catch (e) {
// ignored
}
if (testConfig.timeout) setDefaultTimeout(testConfig.timeout);
const deprecationTracker = deprecationTracking.start();
webpack(options, (err, stats) => {
if (err) {
const fakeStats = {
errors: [
{
message: err.message,
stack: err.stack
}
]
};
if (
checkArrayExpectation(
testDirectory,
fakeStats,
"error",
"Error",
done
)
)
return;
// Wait for uncaught errors to occur
return setTimeout(done, 200);
}
const statOptions = {
preset: "verbose",
colors: false
};
fs.mkdirSync(outputDirectory, { recursive: true });
fs.writeFileSync(
path.join(outputDirectory, "stats.txt"),
stats.toString(statOptions),
"utf-8"
);
const jsonStats = stats.toJson({
errorDetails: true
});
fs.writeFileSync(
path.join(outputDirectory, "stats.json"),
JSON.stringify(jsonStats, null, 2),
"utf-8"
);
if (
checkArrayExpectation(
testDirectory,
jsonStats,
"error",
"Error",
done
)
)
return;
if (
checkArrayExpectation(
testDirectory,
jsonStats,
"warning",
"Warning",
done
)
)
return;
const deprecations = deprecationTracker();
if (
checkArrayExpectation(
testDirectory,
{ deprecations },
"deprecation",
"Deprecation",
done
)
)
return;
const globalContext = {
console: console,
expect: expect,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
document: new FakeDocument(),
location: {
href: "https://test.cases/path/index.html",
origin: "https://test.cases",
toString() {
return "https://test.cases/path/index.html";
}
}
};
const requireCache = Object.create(null);
function _require(currentDirectory, options, module) {
if (Array.isArray(module) || /^\.\.?\//.test(module)) {
let content;
let p;
if (Array.isArray(module)) {
p = path.join(currentDirectory, ".array-require.js");
content = `module.exports = (${module
.map(arg => {
return `require(${JSON.stringify(`./${arg}`)})`;
})
.join(", ")});`;
} else {
p = path.join(currentDirectory, module);
content = fs.readFileSync(p, "utf-8");
}
if (p in requireCache) {
return requireCache[p].exports;
}
const m = {
exports: {}
};
requireCache[p] = m;
let runInNewContext = false;
const moduleScope = {
require: _require.bind(null, path.dirname(p), options),
importScripts: _require.bind(
null,
path.dirname(p),
options
),
module: m,
exports: m.exports,
__dirname: path.dirname(p),
__filename: p,
it: _it,
beforeEach: _beforeEach,
afterEach: _afterEach,
expect,
jest,
_globalAssign: { expect },
__STATS__: jsonStats,
nsObj: m => {
Object.defineProperty(m, Symbol.toStringTag, {
value: "Module"
});
return m;
}
};
if (
options.target === "web" ||
options.target === "webworker"
) {
moduleScope.window = globalContext;
moduleScope.self = globalContext;
runInNewContext = true;
}
if (testConfig.moduleScope) {
testConfig.moduleScope(moduleScope);
}
const args = Object.keys(moduleScope).join(", ");
if (!runInNewContext)
content = `Object.assign(global, _globalAssign); ${content}`;
const code = `(function({${args}}) {${content}\n})`;
const fn = runInNewContext
? vm.runInNewContext(code, globalContext, p)
: vm.runInThisContext(code, p);
fn.call(m.exports, moduleScope);
return m.exports;
} else if (
testConfig.modules &&
module in testConfig.modules
) {
return testConfig.modules[module];
} else return require(module);
}
let filesCount = 0;
if (testConfig.noTests) return process.nextTick(done);
if (testConfig.beforeExecute) testConfig.beforeExecute();
const results = [];
for (let i = 0; i < optionsArr.length; i++) {
const bundlePath = testConfig.findBundle(i, optionsArr[i]);
if (bundlePath) {
filesCount++;
results.push(
_require(outputDirectory, optionsArr[i], bundlePath)
);
}
}
// give a free pass to compilation that generated an error
if (
!jsonStats.errors.length &&
filesCount !== optionsArr.length
)
return done(
new Error(
"Should have found at least one bundle file per webpack config"
)
);
Promise.all(results)
.then(() => {
if (testConfig.afterExecute) testConfig.afterExecute();
if (getNumberOfTests() < filesCount) {
return done(
new Error("No tests exported by test case")
);
}
done();
})
.catch(done);
});
})
);
const {
it: _it,
beforeEach: _beforeEach,
afterEach: _afterEach,
setDefaultTimeout,
getNumberOfTests
} = createLazyTestEnv(jasmine.getEnv(), 10000);
});
});
});
});
describeCases({
name: "ConfigTestCases"
});

View File

@ -322,4 +322,4 @@ const describeCases = config => {
});
};
module.exports.describeCases = describeCases;
exports.describeCases = describeCases;

View File

@ -0,0 +1,78 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ConfigCacheTestCases custom-modules json-custom exported tests should transform toml to json 1`] = `
Object {
"owner": Object {
"bio": "GitHub Cofounder & CEO
Likes tater tots and beer.",
"dob": "1979-05-27T07:32:00.000Z",
"name": "Tom Preston-Werner",
"organization": "GitHub",
},
"title": "TOML Example",
}
`;
exports[`ConfigCacheTestCases records issue-2991 exported tests should write relative paths to records 1`] = `
"{
\\"chunks\\": {
\\"byName\\": {
\\"main\\": 179
},
\\"bySource\\": {
\\"0 main\\": 179
},
\\"usedIds\\": [
179
]
},
\\"modules\\": {
\\"byIdentifier\\": {
\\"./test.js\\": 393,
\\"external \\\\\\"fs\\\\\\"\\": 747,
\\"external \\\\\\"path\\\\\\"\\": 622,
\\"ignored|pkgs/somepackage/foo\\": 713
},
\\"usedIds\\": [
393,
622,
713,
747
]
}
}"
`;
exports[`ConfigCacheTestCases records issue-7339 exported tests should write relative dynamic-require paths to records 1`] = `
"{
\\"chunks\\": {
\\"byName\\": {
\\"main\\": 179
},
\\"bySource\\": {
\\"0 main\\": 179
},
\\"usedIds\\": [
179
]
},
\\"modules\\": {
\\"byIdentifier\\": {
\\"./dependencies/bar.js\\": 379,
\\"./dependencies/foo.js\\": 117,
\\"./dependencies|sync|/^\\\\\\\\.\\\\\\\\/.*$/\\": 412,
\\"./test.js\\": 393,
\\"external \\\\\\"fs\\\\\\"\\": 747,
\\"external \\\\\\"path\\\\\\"\\": 622
},
\\"usedIds\\": [
117,
379,
393,
412,
622,
747
]
}
}"
`;

View File

@ -2,4 +2,4 @@ import * as _constants from './constants';
export var constants = _constants;
export { default as someFunction } from './someFunction';
console.log(constants);
if(Math.random() < 0) console.log(constants);

View File

@ -1,7 +1,7 @@
const path = require("path");
const webpack = require("../../../../");
/** @type {import("../../../../").Configuration[]} */
module.exports = [
/** @type {function(any, any): import("../../../../").Configuration[]} */
module.exports = (env, { testPath }) => [
{
output: {
filename: "commonjs.js",
@ -74,10 +74,7 @@ module.exports = [
{
output: {
filename: "index.js",
path: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/commonjs2-split-chunks"
),
path: path.resolve(testPath, "commonjs2-split-chunks"),
libraryTarget: "commonjs2"
},
target: "node",

View File

@ -1,14 +1,11 @@
var webpack = require("../../../../");
var path = require("path");
/** @type {import("../../../../").Configuration[]} */
module.exports = [
/** @type {function(any, any): import("../../../../").Configuration[]} */
module.exports = (env, { testPath }) => [
{
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/commonjs.js"
)
library: path.resolve(testPath, "../0-create-library/commonjs.js")
}
},
plugins: [
@ -20,10 +17,7 @@ module.exports = [
{
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/umd.js"
)
library: path.resolve(testPath, "../0-create-library/umd.js")
}
},
plugins: [
@ -36,10 +30,7 @@ module.exports = [
entry: "./this-test.js",
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/this.js"
)
library: path.resolve(testPath, "../0-create-library/this.js")
}
},
plugins: [
@ -52,10 +43,7 @@ module.exports = [
entry: "./var-test.js",
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/var.js"
)
library: path.resolve(testPath, "../0-create-library/var.js")
}
},
plugins: [
@ -68,8 +56,8 @@ module.exports = [
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/commonjs2-external.js"
testPath,
"../0-create-library/commonjs2-external.js"
),
external: path.resolve(__dirname, "node_modules/external.js")
}
@ -85,8 +73,8 @@ module.exports = [
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/commonjs2-split-chunks/"
testPath,
"../0-create-library/commonjs2-split-chunks/"
),
external: path.resolve(__dirname, "node_modules/external.js")
}
@ -101,10 +89,7 @@ module.exports = [
entry: "./default-test.js",
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/umd-default.js"
)
library: path.resolve(testPath, "../0-create-library/umd-default.js")
}
},
plugins: [
@ -116,10 +101,7 @@ module.exports = [
{
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/entryA.js"
)
library: path.resolve(testPath, "../0-create-library/entryA.js")
}
},
plugins: [
@ -131,10 +113,7 @@ module.exports = [
{
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/entryB.js"
)
library: path.resolve(testPath, "../0-create-library/entryB.js")
}
},
plugins: [
@ -146,10 +125,7 @@ module.exports = [
{
resolve: {
alias: {
library: path.resolve(
__dirname,
"../../../js/config/library/0-create-library/entryC.js"
)
library: path.resolve(testPath, "../0-create-library/entryC.js")
}
},
plugins: [

View File

@ -1,21 +1,18 @@
var path = require("path");
var LibManifestPlugin = require("../../../../").LibManifestPlugin;
/** @type {import("../../../../").Configuration} */
module.exports = {
/** @type {function(any, any): import("../../../../").Configuration} */
module.exports = (env, { testPath }) => ({
entry: {
bundle0: ["./"]
},
plugins: [
new LibManifestPlugin({
path: path.resolve(
__dirname,
"../../../js/config/plugins/lib-manifest-plugin/[name]-manifest.json"
),
path: path.resolve(testPath, "[name]-manifest.json"),
name: "[name]_[fullhash]"
})
],
node: {
__dirname: false
}
};
});

View File

@ -1,14 +1,11 @@
var path = require("path");
/** @type {import("../../../../").Configuration} */
module.exports = {
/** @type {function(any, any): import("../../../../").Configuration} */
module.exports = (env, { testPath }) => ({
entry: "./test",
recordsPath: path.resolve(
__dirname,
"../../../js/config/records/issue-295/records.json"
),
recordsPath: path.resolve(testPath, "records.json"),
target: "node",
node: {
__dirname: false
}
};
});

View File

@ -1,12 +1,9 @@
var path = require("path");
/** @type {import("../../../../").Configuration} */
module.exports = {
/** @type {function(any, any): import("../../../../").Configuration} */
module.exports = (env, { testPath }) => ({
entry: "./test",
recordsOutputPath: path.resolve(
__dirname,
"../../../js/config/records/issue-2991/records.json"
),
recordsOutputPath: path.resolve(testPath, "records.json"),
target: "node",
node: {
__dirname: false
@ -17,4 +14,4 @@ module.exports = {
pkgs: path.resolve(__dirname, "pkgs")
}
}
};
});

View File

@ -1,14 +1,11 @@
var path = require("path");
/** @type {import("../../../../").Configuration} */
module.exports = {
/** @type {function(any, any): import("../../../../").Configuration} */
module.exports = (env, { testPath }) => ({
entry: "./test",
recordsOutputPath: path.resolve(
__dirname,
"../../../js/config/records/issue-7339/records.json"
),
recordsOutputPath: path.resolve(testPath, "records.json"),
target: "node",
node: {
__dirname: false
}
};
});

View File

@ -1,13 +1,10 @@
var path = require("path");
/** @type {import("../../../../").Configuration} */
module.exports = {
/** @type {function(any, any): import("../../../../").Configuration} */
module.exports = (env, { testPath }) => ({
mode: "development",
entry: "./test",
recordsOutputPath: path.resolve(
__dirname,
"../../../js/config/records/stable-sort/records.json"
),
recordsOutputPath: path.resolve(testPath, "records.json"),
optimization: {
chunkIds: "size"
},
@ -15,4 +12,4 @@ module.exports = {
node: {
__dirname: false
}
};
});

10
types.d.ts vendored
View File

@ -4309,6 +4309,16 @@ declare class NodeEnvironmentPlugin {
* Options object for node compatibility features.
*/
declare interface NodeOptions {
/**
* Include a polyfill for the '__dirname' variable.
*/
__dirname?: boolean | "mock";
/**
* Include a polyfill for the '__filename' variable.
*/
__filename?: boolean | "mock";
/**
* Include a polyfill for the 'global' variable.
*/

View File

@ -6767,9 +6767,9 @@ toml@^3.0.0:
resolved "https://registry.yarnpkg.com/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee"
integrity sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==
tooling@webpack/tooling#v1.7.0:
version "1.7.0"
resolved "https://codeload.github.com/webpack/tooling/tar.gz/199a510b8e4307e5b6629b11cb2ef377d183e5cf"
tooling@webpack/tooling#v1.8.0:
version "1.8.0"
resolved "https://codeload.github.com/webpack/tooling/tar.gz/92e13cc6cf7aae31030c736427c6ebf54f5af581"
dependencies:
"@yarnpkg/lockfile" "^1.1.0"
commondir "^1.0.1"