Skip to content

Commit 7498e2b

Browse files
Bump dev-only version deps, and upgrade to bun for cli speed
1 parent eb8c6f2 commit 7498e2b

File tree

85 files changed

+18962
-195202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+18962
-195202
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
2+
.husky/_
23
lerna-debug.log
3-
npm-debug.log
4+
npm-debug.log

.husky/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
bunx lint-staged --config lint-staged.config.js

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ We will find solutions to these issues before removing the _(experimental)_ flag
200200
Type: `Array<String|RegExp>`<br>
201201
Default: `[]`
202202

203-
When `granularLoaderData` is enabled, SMP prepends its timing loader to each matching
203+
When you enable `granularLoaderData`, SMP prepends its timing loader to each matching
204204
loader rule. Use this option to skip rules whose loader chain contains a matching
205205
loader name or regular expression. String matching checks both the original loader
206206
request and the normalized package name. E.g.

__tests__/common/jest.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1+
const {
2+
beforeAll,
3+
describe,
4+
expect,
5+
it,
6+
setDefaultTimeout,
7+
} = require("bun:test");
18
const SpeedMeasurePlugin = require("../../..");
29
const webpack = require("webpack");
310
const { readFileSync } = require("fs");
411
const webpackConfig = require("./webpack.config");
512

6-
const getStandardConf = conf => {
13+
const getStandardConf = (conf) => {
714
if (typeof conf === "function") conf = conf();
815
const arr = Array.isArray(conf) ? conf : [conf];
916

10-
return arr.map(
11-
subConf => (typeof subConf === "function" ? subConf() : subConf)
17+
return arr.map((subConf) =>
18+
typeof subConf === "function" ? subConf() : subConf
1219
);
1320
};
1421

1522
let i = 0;
16-
const prepareSmpWebpackConfig = conf => {
23+
const prepareSmpWebpackConfig = (conf) => {
1724
if (Array.isArray(conf)) return conf.map(prepareSmpWebpackConfig);
1825
if (typeof conf === "function")
1926
return (...args) => prepareSmpWebpackConfig(conf(...args));
@@ -25,38 +32,89 @@ const prepareSmpWebpackConfig = conf => {
2532
});
2633
};
2734

28-
const genSmpWebpackConfig = smp =>
35+
const genSmpWebpackConfig = (smp) =>
2936
smp.wrap(prepareSmpWebpackConfig(webpackConfig));
3037

31-
const runWebpack = config =>
38+
const withCapturedOutput = (fn) => {
39+
const output = [];
40+
const writes = {
41+
stdout: process.stdout.write,
42+
stderr: process.stderr.write,
43+
};
44+
const emitWarning = process.emitWarning;
45+
const capture = (chunk, encoding, callback) => {
46+
output.push(Buffer.isBuffer(chunk) ? chunk.toString() : chunk);
47+
if (typeof encoding === "function") encoding();
48+
if (typeof callback === "function") callback();
49+
return true;
50+
};
51+
52+
process.stdout.write = capture;
53+
process.stderr.write = capture;
54+
process.emitWarning = (...args) => {
55+
const [warning] = args;
56+
output.push(
57+
warning instanceof Error
58+
? `${warning.name}: ${warning.message}\n`
59+
: `${warning}\n`
60+
);
61+
};
62+
63+
const restore = () => {
64+
process.stdout.write = writes.stdout;
65+
process.stderr.write = writes.stderr;
66+
process.emitWarning = emitWarning;
67+
};
68+
const flush = () => {
69+
restore();
70+
const replay = output.join("");
71+
if (replay) {
72+
writes.stderr.call(process.stderr, replay);
73+
}
74+
};
75+
76+
return fn({
77+
restore,
78+
flush,
79+
});
80+
};
81+
82+
const runWebpack = (config) =>
3283
new Promise((resolve, reject) => {
3384
const standardConf = getStandardConf(config);
34-
webpack(standardConf, (err, stats) => {
35-
if (err || stats.hasErrors()) return reject(err || stats);
36-
const fileContent = standardConf.map(conf =>
37-
readFileSync(conf.output.path + "/bundle.js").toString()
38-
);
39-
resolve(fileContent.join("\n///////// new file /////////\n"));
85+
withCapturedOutput(({ restore, flush }) => {
86+
webpack(standardConf, (err, stats) => {
87+
if (err || stats.hasErrors()) {
88+
flush();
89+
return reject(err || stats);
90+
}
91+
92+
restore();
93+
const fileContent = standardConf.map((conf) =>
94+
readFileSync(conf.output.path + "/bundle.js").toString()
95+
);
96+
resolve(fileContent.join("\n///////// new file /////////\n"));
97+
});
4098
});
4199
});
42100

43-
jest.setTimeout(20000);
101+
setDefaultTimeout(20000);
44102

45103
const testRef = {};
46104

47105
describe("smp", () => {
48106
beforeAll(() =>
49-
runWebpack(webpackConfig).then(file => (testRef.distApp = file))
107+
runWebpack(webpackConfig).then((file) => (testRef.distApp = file))
50108
);
51109

52110
describe(__dirname.split("/").pop(), () => {
53111
const smp = new SpeedMeasurePlugin({
54-
outputTarget: output => (testRef.smpOutput = output),
112+
outputTarget: (output) => (testRef.smpOutput = output),
55113
});
56114
const smpWebpackConfig = genSmpWebpackConfig(smp);
57115

58116
beforeAll(() =>
59-
runWebpack(smpWebpackConfig).then(file => (testRef.smpDistApp = file))
117+
runWebpack(smpWebpackConfig).then((file) => (testRef.smpDistApp = file))
60118
);
61119

62120
it("should generate the same app.js content", () => {
@@ -66,7 +124,7 @@ describe("smp", () => {
66124
it("should generate the same app.js content after 2 runs", () => {
67125
const dupSmpWebpackConfig = genSmpWebpackConfig(smp);
68126

69-
return runWebpack(dupSmpWebpackConfig).then(dupSmpDistApp => {
127+
return runWebpack(dupSmpWebpackConfig).then((dupSmpDistApp) => {
70128
expect(dupSmpDistApp).toEqual(testRef.smpDistApp);
71129
expect(dupSmpDistApp).toEqual(testRef.distApp);
72130
});

0 commit comments

Comments
 (0)