mirror of https://github.com/webpack/webpack.git
Compare commits
4 Commits
c48d17240f
...
9bf42dcf0b
Author | SHA1 | Date |
---|---|---|
|
9bf42dcf0b | |
|
85bacbdc6e | |
|
f95bc4e7b4 | |
|
0f668bd546 |
|
@ -103,6 +103,7 @@ jobs:
|
|||
mode: "instrumentation"
|
||||
token: ${{ secrets.CODSPEED_TOKEN }}
|
||||
env:
|
||||
CODSPEED_DEBUG: 1
|
||||
LAST_COMMIT: 1
|
||||
NEGATIVE_FILTER: on-schedule
|
||||
SHARD: ${{ matrix.shard }}
|
||||
|
|
|
@ -134,11 +134,21 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|||
);
|
||||
if (used) {
|
||||
if (otherUnused || used !== exportInfo.name) {
|
||||
instructions.push(
|
||||
`${external}${propertyAccess([
|
||||
used
|
||||
])} = module${propertyAccess([exportInfo.name])};`
|
||||
);
|
||||
if (exportInfo.name === "default") {
|
||||
// Ideally we should use `module && module.__esModule ? module['default'] : module`
|
||||
// But we need to keep compatibility with SystemJS format libraries (they are using `default`) and bundled SystemJS libraries from commonjs format
|
||||
instructions.push(
|
||||
`${external}${propertyAccess([
|
||||
used
|
||||
])} = module["default"] || module;`
|
||||
);
|
||||
} else {
|
||||
instructions.push(
|
||||
`${external}${propertyAccess([
|
||||
used
|
||||
])} = module${propertyAccess([exportInfo.name])};`
|
||||
);
|
||||
}
|
||||
handledNames.push(exportInfo.name);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -465,21 +465,6 @@ const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
|||
const taskCompletionMessage = () =>
|
||||
InstrumentHooks.isInstrumented() ? "Measured" : "Checked";
|
||||
|
||||
const iterationAsync = async (task) => {
|
||||
try {
|
||||
await task.fnOpts.beforeEach?.call(task, "run");
|
||||
const start = bench.opts.now();
|
||||
await task.fn();
|
||||
const end = bench.opts.now() - start || 0;
|
||||
await task.fnOpts.afterEach?.call(this, "run");
|
||||
return [start, end];
|
||||
} catch (err) {
|
||||
if (bench.opts.throws) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const wrapWithInstrumentHooksAsync = async (fn, uri) => {
|
||||
InstrumentHooks.startBenchmark();
|
||||
const result = await fn();
|
||||
|
@ -489,7 +474,29 @@ const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
|||
};
|
||||
|
||||
const runTaskAsync = async (task, uri) => {
|
||||
const { fnOpts, fn } = task;
|
||||
const { name, fn, fnOpts } = task;
|
||||
const originalFn = fn;
|
||||
|
||||
const fnWrapper = async () => {
|
||||
console.time(`Time: ${name}`);
|
||||
await originalFn();
|
||||
console.timeEnd(`Time: ${name}`);
|
||||
};
|
||||
|
||||
const iterationAsync = async (task) => {
|
||||
try {
|
||||
await task.fnOpts.beforeEach?.call(task, "run");
|
||||
const start = bench.opts.now();
|
||||
await fnWrapper();
|
||||
const end = bench.opts.now();
|
||||
await task.fnOpts.afterEach?.call(this, "run");
|
||||
return [start, end, end - start];
|
||||
} catch (err) {
|
||||
if (bench.opts.throws) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Custom setup
|
||||
await bench.opts.setup?.(task, "run");
|
||||
|
@ -507,7 +514,10 @@ const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
|||
await fnOpts?.beforeEach?.call(task, "run");
|
||||
await mongoMeasurement.start(uri);
|
||||
global.gc?.();
|
||||
await wrapWithInstrumentHooksAsync(wrapFunctionWithFrame(fn, true), uri);
|
||||
await wrapWithInstrumentHooksAsync(
|
||||
wrapFunctionWithFrame(fnWrapper, true),
|
||||
uri
|
||||
);
|
||||
await mongoMeasurement.stop(uri);
|
||||
await fnOpts?.afterEach?.call(task, "run");
|
||||
console.log(`[Codspeed] ✔ Measured ${uri}`);
|
||||
|
@ -519,21 +529,6 @@ const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
|||
logTaskCompletion(uri, taskCompletionMessage());
|
||||
};
|
||||
|
||||
const iteration = (task) => {
|
||||
try {
|
||||
task.fnOpts.beforeEach?.call(task, "run");
|
||||
const start = bench.opts.now();
|
||||
task.fn();
|
||||
const end = bench.opts.now() - start || 0;
|
||||
task.fnOpts.afterEach?.call(this, "run");
|
||||
return [start, end];
|
||||
} catch (err) {
|
||||
if (bench.opts.throws) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const wrapWithInstrumentHooks = (fn, uri) => {
|
||||
InstrumentHooks.startBenchmark();
|
||||
const result = fn();
|
||||
|
@ -543,7 +538,29 @@ const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
|||
};
|
||||
|
||||
const runTaskSync = (task, uri) => {
|
||||
const { fnOpts, fn } = task;
|
||||
const { name, fnOpts, fn } = task;
|
||||
const originalFn = fn;
|
||||
|
||||
const fnWrapper = () => {
|
||||
console.time(`Time: ${name}`);
|
||||
originalFn();
|
||||
console.timeEnd(`Time: ${name}`);
|
||||
};
|
||||
|
||||
const iteration = (task) => {
|
||||
try {
|
||||
task.fnOpts.beforeEach?.call(task, "run");
|
||||
const start = bench.opts.now();
|
||||
task.fn();
|
||||
const end = bench.opts.now() - start || 0;
|
||||
task.fnOpts.afterEach?.call(this, "run");
|
||||
return [start, end];
|
||||
} catch (err) {
|
||||
if (bench.opts.throws) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Custom setup
|
||||
bench.opts.setup?.(task, "run");
|
||||
|
@ -559,7 +576,7 @@ const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
|||
|
||||
fnOpts?.beforeEach?.call(task, "run");
|
||||
|
||||
wrapWithInstrumentHooks(wrapFunctionWithFrame(fn, false), uri);
|
||||
wrapWithInstrumentHooks(wrapFunctionWithFrame(fnWrapper, false), uri);
|
||||
|
||||
fnOpts?.afterEach?.call(task, "run");
|
||||
console.log(`[Codspeed] ✔ Measured ${uri}`);
|
||||
|
@ -693,8 +710,6 @@ async function registerSuite(bench, test, baselines) {
|
|||
bench.add(
|
||||
benchName,
|
||||
async () => {
|
||||
console.time(`Time: ${benchName}`);
|
||||
|
||||
let resolve;
|
||||
let reject;
|
||||
|
||||
|
@ -717,7 +732,6 @@ async function registerSuite(bench, test, baselines) {
|
|||
// Construct and print stats to be more accurate with real life projects
|
||||
stats.toString();
|
||||
resolve();
|
||||
console.timeEnd(`Time: ${benchName}`);
|
||||
};
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
|
@ -836,9 +850,7 @@ async function registerSuite(bench, test, baselines) {
|
|||
runWebpack(webpack, config)
|
||||
);
|
||||
} else {
|
||||
console.time(`Time: ${benchName}`);
|
||||
await runWebpack(webpack, config);
|
||||
console.timeEnd(`Time: ${benchName}`);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
const a = 10;
|
||||
const b = 20;
|
||||
|
||||
class MyClass {
|
||||
getValue() {
|
||||
return "my-class";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MyClass;
|
||||
module.exports.a = a;
|
||||
module.exports.b = b;
|
|
@ -0,0 +1,11 @@
|
|||
const a = 10;
|
||||
const b = 20;
|
||||
|
||||
class MyClass {
|
||||
getValue() {
|
||||
return "my-class";
|
||||
}
|
||||
}
|
||||
|
||||
export default MyClass;
|
||||
export { a, b };
|
|
@ -914,5 +914,25 @@ module.exports = (env, { testPath }) => [
|
|||
experiments: {
|
||||
outputModule: true
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: "./esm.js",
|
||||
output: {
|
||||
uniqueName: "system-esm",
|
||||
filename: "system-esm.js",
|
||||
library: {
|
||||
type: "system"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: "./commonjs.js",
|
||||
output: {
|
||||
uniqueName: "system-commonjs",
|
||||
filename: "system-commonjs.js",
|
||||
library: {
|
||||
type: "system"
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import MyClass, {a, b} from "library-commonjs";
|
||||
|
||||
it("should get exports from systemjs library (" + NAME + ")", function() {
|
||||
expect(new MyClass().getValue()).toBe("my-class")
|
||||
expect(a).toBe(10);
|
||||
expect(b).toBe(20);
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
const System = require("../../../helpers/fakeSystem");
|
||||
|
||||
module.exports = {
|
||||
beforeExecute: () => {
|
||||
System.init();
|
||||
},
|
||||
moduleScope(scope) {
|
||||
scope.System = System;
|
||||
scope.System.setRequire(scope.require);
|
||||
},
|
||||
afterExecute() {
|
||||
delete global.webpackChunk;
|
||||
System.execute("(anonym)");
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {(env: Env, options: TestOptions) => import("../../../../").Configuration[]} */
|
||||
module.exports = (env, { testPath }) => [
|
||||
{
|
||||
entry: "./system-external-commonjs.js",
|
||||
output: {
|
||||
library: {
|
||||
type: "system"
|
||||
}
|
||||
},
|
||||
externals: {
|
||||
"library-commonjs": path.resolve(
|
||||
testPath,
|
||||
"../0-create-library/system-commonjs.js"
|
||||
)
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
NAME: JSON.stringify("systemjs with external from commonjs format")
|
||||
})
|
||||
]
|
||||
}
|
||||
];
|
|
@ -0,0 +1,7 @@
|
|||
import MyClass, {a, b} from "library-esm";
|
||||
|
||||
it("should get exports from systemjs library (" + NAME + ")", function() {
|
||||
expect(new MyClass().getValue()).toBe("my-class")
|
||||
expect(a).toBe(10);
|
||||
expect(b).toBe(20);
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
const System = require("../../../helpers/fakeSystem");
|
||||
|
||||
module.exports = {
|
||||
beforeExecute: () => {
|
||||
System.init();
|
||||
},
|
||||
moduleScope(scope) {
|
||||
scope.System = System;
|
||||
scope.System.setRequire(scope.require);
|
||||
},
|
||||
afterExecute() {
|
||||
delete global.webpackChunk;
|
||||
System.execute("(anonym)");
|
||||
}
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const webpack = require("../../../../");
|
||||
|
||||
/** @type {(env: Env, options: TestOptions) => import("../../../../").Configuration[]} */
|
||||
module.exports = (env, { testPath }) => [
|
||||
{
|
||||
entry: "./system-external-esm.js",
|
||||
output: {
|
||||
library: {
|
||||
type: "system"
|
||||
}
|
||||
},
|
||||
externals: {
|
||||
"library-esm": path.resolve(testPath, "../0-create-library/system-esm.js")
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
NAME: JSON.stringify("systemjs with external from ES module format")
|
||||
})
|
||||
]
|
||||
}
|
||||
];
|
Loading…
Reference in New Issue