@rollup-extras/plugin-size 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/index.js +39 -13
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![Coverage](https://raw.githubusercontent.com/kshutkin/rollup-extras/refs/heads/coverage/plugin-size/badge.svg)
2
+
1
3
  # @rollup-extras/plugin-size
2
4
 
3
5
  Rollup plugin that reports the size of generated artifacts — raw, optionally minified, and compressed (gzip and/or brotli).
package/index.js CHANGED
@@ -202,33 +202,59 @@ export default function (options) {
202
202
 
203
203
  const flags = { gzip: normalizedOptions.gzip, brotli: normalizedOptions.brotli };
204
204
 
205
- const currentStats = {};
205
+ let currentStats = {};
206
206
 
207
- const instance = multiConfigPluginBase(false, pluginName, reportAndSave, onEachOutput);
207
+ let buildInputs = new WeakSet();
208
+ let reportComplete = false;
208
209
 
209
- if (!outputPlugin) {
210
- instance.buildStart = () => {
211
- currentStats.entries = undefined;
212
- currentStats.chunks = undefined;
213
- currentStats.assets = undefined;
214
- };
210
+ const instance = multiConfigPluginBase(false, pluginName, reportAndSave, onEachOutput, resetStats);
211
+
212
+ if (outputPlugin) {
213
+ const addInstance = instance.api.addInstance;
214
+ instance.api.addInstance = () => trackBuild(addInstance());
215
+ trackBuild(instance);
216
+ } else {
217
+ instance.buildStart = resetStats;
215
218
  }
216
219
 
217
220
  return instance;
218
221
 
222
+ function trackBuild(plugin) {
223
+ const renderStart = (plugin.renderStart);
224
+ plugin.renderStart = function (outputOptions, inputOptions) {
225
+
226
+ if (reportComplete && !buildInputs.has(inputOptions)) {
227
+ resetStats();
228
+ }
229
+ buildInputs.add(inputOptions);
230
+ return renderStart.call(this, outputOptions, inputOptions);
231
+ };
232
+ return plugin;
233
+ }
234
+
235
+ function resetStats() {
236
+ currentStats = {};
237
+ buildInputs = new WeakSet();
238
+ reportComplete = false;
239
+ }
240
+
219
241
  async function onEachOutput(outputOptions, bundle) {
220
242
  await collectStats(currentStats, outputOptions, bundle, flags, minifyFn);
221
243
  }
222
244
 
223
245
  async function reportAndSave() {
224
- const statsPath = resolve(process.cwd(), statsFile);
246
+ try {
247
+ const statsPath = resolve(process.cwd(), statsFile);
225
248
 
226
- const previousStats = await loadPreviousStats(statsPath);
249
+ const previousStats = await loadPreviousStats(statsPath);
227
250
 
228
- printReport(currentStats, previousStats, logger);
251
+ printReport(currentStats, previousStats, logger);
229
252
 
230
- if (updateStats) {
231
- await writeFile(statsPath, `${JSON.stringify(currentStats, null, 2)}\n`);
253
+ if (updateStats) {
254
+ await writeFile(statsPath, `${JSON.stringify(currentStats, null, 2)}\n`);
255
+ }
256
+ } finally {
257
+ reportComplete = true;
232
258
  }
233
259
  }
234
260
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.0",
2
+ "version": "0.3.2",
3
3
  "license": "MIT",
4
4
  "name": "@rollup-extras/plugin-size",
5
5
  "author": "Konstantin Shutkin",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@niceties/ansi": "^1.1.2",
39
39
  "@niceties/logger": "^2.1.0",
40
- "@rollup-extras/utils": "^2.0.0"
40
+ "@rollup-extras/utils": "^2.0.2"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "rollup": "^4.0.0"