Skip to content

Commit d3bf829

Browse files
fix: respect cacheable
1 parent 2de3b64 commit d3bf829

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

src/WorkerPool.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,18 @@ class PoolWorker {
320320
// initialise logger by name in jobData
321321
const { data } = message;
322322
const { data: jobData } = this.jobs[id];
323-
if (!Object.hasOwnProperty.call(jobData.loggers, data.name)) {
324-
jobData.loggers[data.name] = jobData.getLogger(data.name);
323+
const internalName = data.name || '__internal__';
324+
if (!Object.hasOwnProperty.call(jobData.loggers, internalName)) {
325+
jobData.loggers[internalName] = jobData.getLogger(data.name);
325326
}
326327
finalCallback();
327328
break;
328329
}
329330
case 'logger': {
330331
const { data } = message;
331332
const { data: jobData } = this.jobs[id];
332-
const logger = jobData.loggers[data.name];
333+
const internalName = data.name || '__internal__';
334+
const logger = jobData.loggers[internalName];
333335
logger[data.method](...data.args);
334336
finalCallback();
335337
break;

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ function pitch() {
6363
},
6464
(err, r) => {
6565
if (r) {
66+
this.cacheable(r.cacheable);
67+
6668
r.fileDependencies.forEach((d) => this.addDependency(d));
6769
r.contextDependencies.forEach((d) => this.addContextDependency(d));
6870
r.missingDependencies.forEach((d) => this.addMissingDependency(d));

src/worker.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ const queue = asyncQueue(({ id, data }, taskCallback) => {
240240
return options;
241241
},
242242
getLogger: (name) => {
243-
if (typeof name === 'function') {
244-
// eslint-disable-next-line no-param-reassign
245-
name = name();
246-
}
247243
function writeLoggerJson(method, args) {
248244
writeJson({
249245
type: 'logger',

test/__snapshots__/webpack.test.js.snap

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ Test Message Error],
77
]
88
`;
99

10+
exports[`Works with test-loader: logs 1`] = `
11+
[
12+
[
13+
{
14+
"args": [
15+
"test message",
16+
],
17+
"trace": undefined,
18+
"type": "info",
19+
},
20+
],
21+
[
22+
{
23+
"args": [
24+
"test message",
25+
],
26+
"trace": undefined,
27+
"type": "log",
28+
},
29+
],
30+
]
31+
`;
32+
1033
exports[`Works with test-loader: result 1`] = `
1134
{
1235
"addBuildDependency": "function",

test/basic-loader-test/test-loader.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const path = require('path');
22

33
module.exports = async function testLoader() {
4+
this.cacheable(false);
5+
46
const options = this.getOptions();
57
const callback = this.async();
68

@@ -10,6 +12,15 @@ module.exports = async function testLoader() {
1012
this.addDependency(require.resolve('./dep.js'));
1113
this.addBuildDependency(require.resolve('./build-dep.js'));
1214
this.addContextDependency(path.resolve(__dirname, './directory'));
15+
16+
const logger = this.getLogger('name');
17+
18+
logger.info('test message');
19+
20+
const logger1 = this.getLogger();
21+
22+
logger1.log('test message');
23+
1324
// Todo fix me
1425
// this.addMissingDependency(require.resolve("./missing-dep.js"));
1526

@@ -38,6 +49,7 @@ module.exports = async function testLoader() {
3849
currentRequest: this.currentRequest,
3950
previousRequest: this.previousRequest,
4051
query: this.query,
52+
// Todo fix me
4153
data: this.data,
4254
hot: this.hot,
4355
cacheable: typeof this.cacheable,

test/webpack.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,17 @@ test('Works with test-loader', (done) => {
5959
expect(stats.compilation.errors).toMatchSnapshot('errors');
6060
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
6161

62+
const logs = Array.from(stats.compilation.logging.entries())
63+
.filter((item) => /file\.js\?q=1#hash/.test(item[0]))
64+
.map((item) => item[1].map(({ time, ...rest }) => rest));
65+
66+
expect(logs).toMatchSnapshot('logs');
67+
6268
const [testMod] = [...stats.compilation.modules].filter(
6369
(i) => i.rawRequest === './file.js?q=1#hash'
6470
);
6571

72+
expect(testMod.buildInfo.cacheable).toBe(false);
6673
// eslint-disable-next-line no-eval, no-underscore-dangle
6774
expect(eval(testMod._source.source())).toMatchSnapshot('result');
6875

0 commit comments

Comments
 (0)