Compare commits

...

4 Commits

Author SHA1 Message Date
Alexander Akait 9bf42dcf0b
Merge f95bc4e7b4 into 85bacbdc6e 2025-10-07 00:50:36 +03:00
Alexander Akait 85bacbdc6e
fix: default import of commonjs externals for SystemJS format
Github Actions / lint (push) Waiting to run Details
Github Actions / validate-legacy-node (push) Waiting to run Details
Github Actions / benchmark (1/4) (push) Waiting to run Details
Github Actions / benchmark (2/4) (push) Waiting to run Details
Github Actions / benchmark (3/4) (push) Waiting to run Details
Github Actions / benchmark (4/4) (push) Waiting to run Details
Github Actions / basic (push) Waiting to run Details
Github Actions / unit (push) Waiting to run Details
Github Actions / integration (10.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (10.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (10.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (10.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (12.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (14.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (16.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (18.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (20.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (20.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (20.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (22.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (22.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, macos-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, macos-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, ubuntu-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, ubuntu-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (24.x, windows-latest, a) (push) Blocked by required conditions Details
Github Actions / integration (24.x, windows-latest, b) (push) Blocked by required conditions Details
Github Actions / integration (lts/*, ubuntu-latest, a, 1) (push) Blocked by required conditions Details
Github Actions / integration (lts/*, ubuntu-latest, b, 1) (push) Blocked by required conditions Details
2025-10-06 23:44:25 +03:00
alexander-akait f95bc4e7b4 ci: debug codspeed 2025-10-04 14:48:57 +03:00
alexander-akait 0f668bd546 refactor: benchmarks 2025-10-04 14:37:41 +03:00
12 changed files with 209 additions and 44 deletions

View File

@ -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 }}

View File

@ -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 {

View File

@ -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}`);
}
},
{

View File

@ -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;

View File

@ -0,0 +1,11 @@
const a = 10;
const b = 20;
class MyClass {
getValue() {
return "my-class";
}
}
export default MyClass;
export { a, b };

View File

@ -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"
}
}
}
];

View File

@ -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);
});

View File

@ -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)");
}
};

View File

@ -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")
})
]
}
];

View File

@ -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);
});

View File

@ -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)");
}
};

View File

@ -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")
})
]
}
];