Skip to content

Commit 2da54ab

Browse files
committed
Fix tests
1 parent 8ab4370 commit 2da54ab

File tree

3 files changed

+37
-46
lines changed

3 files changed

+37
-46
lines changed

.github/workflows/config.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,6 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
# Oldest maintenance LTS, End-of-Life 2025-04-30
11-
test-node-18:
12-
runs-on: ubuntu-latest
13-
container:
14-
image: node:18.19
15-
env:
16-
NODE_OPTIONS: --openssl-legacy-provider
17-
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v4
20-
- name: Set up Node.js
21-
run: |
22-
echo "Node version: $(node --version)"
23-
echo "NPM version: $(npm --version)"
24-
npm install
25-
npm run ci
26-
- name: Unset NODE_OPTIONS
27-
run: |
28-
unset NODE_OPTIONS
29-
3010
test:
3111
runs-on: ubuntu-latest
3212
strategy:

lib/index.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class BundleTrackerPlugin {
5656
};
5757
this.name = 'BundleTrackerPlugin';
5858

59+
this.output = {};
5960
this.outputChunkDir = '';
6061
this.outputTrackerFile = '';
6162
this.outputTrackerDir = '';
@@ -145,29 +146,8 @@ class BundleTrackerPlugin {
145146
_handleCompile(compiler) {
146147
this._writeOutput(compiler, { status: 'compile' });
147148
}
148-
/**
149-
* Handle compile hook
150-
* @param {Compiler} compiler
151-
* @param {Stats} stats
152-
*/
153-
_handleDone(compiler, stats) {
154-
if (stats.hasErrors()) {
155-
const findError = compilation => {
156-
if (compilation.errors.length > 0) {
157-
return compilation.errors[0];
158-
}
159-
return compilation.children.find(child => findError(child));
160-
};
161-
const error = findError(stats.compilation);
162-
this._writeOutput(compiler, {
163-
status: 'error',
164-
error: error?.name ?? 'unknown-error',
165-
message: stripAnsi(error['message']),
166-
});
167-
168-
return;
169-
}
170149

150+
_handleAssetEmitted(_compiler, _, stats) {
171151
/** @type {Contents} */
172152
const output = { status: 'done', assets: {}, chunks: {} };
173153
Object.entries(stats.compilation.assets).map(([assetName, _]) => {
@@ -200,19 +180,46 @@ class BundleTrackerPlugin {
200180

201181
output.assets[assetName] = fileInfo;
202182
});
183+
this.output = output;
184+
}
185+
186+
/**
187+
* Handle compile hook
188+
* @param {Compiler} compiler
189+
* @param {Stats} stats
190+
*/
191+
_handleDone(compiler, stats) {
192+
if (stats.hasErrors()) {
193+
const findError = compilation => {
194+
if (compilation.errors.length > 0) {
195+
return compilation.errors[0];
196+
}
197+
return compilation.children.find(child => findError(child));
198+
};
199+
const error = findError(stats.compilation);
200+
this._writeOutput(compiler, {
201+
status: 'error',
202+
error: error?.name ?? 'unknown-error',
203+
message: stripAnsi(error['message']),
204+
});
205+
206+
return;
207+
}
208+
203209
stats.compilation.chunkGroups.forEach(chunkGroup => {
204210
if (!chunkGroup.isInitial()) return;
205211

206-
output.chunks[chunkGroup.name] = chunkGroup.getFiles();
212+
this.output.chunks[chunkGroup.name] = chunkGroup.getFiles();
207213
});
208214

209215
if (this.options.logTime === true) {
210-
output.startTime = stats.startTime;
211-
output.endTime = stats.endTime;
216+
this.output.startTime = stats.startTime;
217+
this.output.endTime = stats.endTime;
212218
}
213219

214-
this._writeOutput(compiler, output);
220+
this._writeOutput(compiler, this.output);
215221
}
222+
216223
/**
217224
* Method called by webpack to apply plugin hook
218225
* @param {Compiler} compiler
@@ -221,6 +228,7 @@ class BundleTrackerPlugin {
221228
this._setParamsFromCompiler(compiler);
222229

223230
compiler.hooks.compile.tap(this.name, this._handleCompile.bind(this, compiler));
231+
compiler.hooks.assetEmitted.tap(this.name, this._handleAssetEmitted.bind(this, compiler));
224232
compiler.hooks.done.tap(this.name, this._handleDone.bind(this, compiler));
225233
}
226234
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
],
1212
"homepage": "https://github.com/django-webpack/webpack-bundle-tracker",
1313
"bugs": "https://github.com/django-webpack/webpack-bundle-tracker/issues",
14+
"engines": {
15+
"node": ">=22.0.0"
16+
},
1417
"repository": {
1518
"type": "git",
1619
"url": "git+https://github.com/django-webpack/webpack-bundle-tracker.git"

0 commit comments

Comments
 (0)