Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/components/ModulesTreemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function getSizeSwitchItems() {

if (window.compressionAlgorithm === 'brotli') items.push({label: 'Brotli', prop: 'brotliSize'});

if (window.compressionAlgorithm === 'zstd') items.push({label: 'Zstandard', prop: 'zstdSize'});

return items;
};

Expand Down
2 changes: 1 addition & 1 deletion client/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import localStorage from './localStorage';

export class Store {
cid = 0;
sizes = new Set(['statSize', 'parsedSize', 'gzipSize', 'brotliSize']);
sizes = new Set(['statSize', 'parsedSize', 'gzipSize', 'brotliSize', 'zstdSize']);

@observable.ref allChunks;
@observable.shallow selectedChunks;
Expand Down
2 changes: 2 additions & 0 deletions src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
asset.parsedSize = Buffer.byteLength(assetSources.src);
if (compressionAlgorithm === 'gzip') asset.gzipSize = getCompressedSize('gzip', assetSources.src);
if (compressionAlgorithm === 'brotli') asset.brotliSize = getCompressedSize('brotli', assetSources.src);
if (compressionAlgorithm === 'zstd') asset.zstdSize = getCompressedSize('zstd', assetSources.src);
}

// Picking modules from current bundle script
Expand Down Expand Up @@ -169,6 +170,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
parsedSize: asset.parsedSize,
gzipSize: asset.gzipSize,
brotliSize: asset.brotliSize,
zstdSize: asset.zstdSize,
groups: Object.values(asset.tree.children).map(i => i.toChartData()),
isInitialByEntrypoint: chunkToInitialByEntrypoint[filename] ?? {}
}));
Expand Down
2 changes: 1 addition & 1 deletion src/bin/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Logger = require('../Logger');
const utils = require('../utils');

const SIZES = new Set(['stat', 'parsed', 'gzip']);
const COMPRESSION_ALGORITHMS = new Set(['gzip', 'brotli']);
const COMPRESSION_ALGORITHMS = new Set(['gzip', 'brotli', 'zstd']);

const program = commander
.version(require('../../package.json').version)
Expand Down
1 change: 1 addition & 0 deletions src/sizeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const zlib = require('zlib');
export function getCompressedSize(compressionAlgorithm, input) {
if (compressionAlgorithm === 'gzip') return zlib.gzipSync(input, {level: 9}).length;
if (compressionAlgorithm === 'brotli') return zlib.brotliCompressSync(input).length;
if (compressionAlgorithm === 'zstd') return zlib.zstdCompressSync(input).length;

throw new Error(`Unsupported compression algorithm: ${compressionAlgorithm}.`);
}
4 changes: 4 additions & 0 deletions src/tree/ConcatenatedModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export default class ConcatenatedModule extends Module {
return this.getBrotliSize() ?? this.getEstimatedSize('brotliSize');
}

get zstdSize() {
return this.getZstdSize() ?? this.getEstimatedSize('zstdSize');
}

getEstimatedSize(sizeType) {
const parentModuleSize = this.parent[sizeType];

Expand Down
5 changes: 5 additions & 0 deletions src/tree/ContentFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default class ContentFolder extends BaseFolder {
return this.getSize('brotliSize');
}

get zstdSize() {
return this.getSize('zstdSize');
}

getSize(sizeType) {
const ownerModuleSize = this.ownerModule[sizeType];

Expand All @@ -33,6 +37,7 @@ export default class ContentFolder extends BaseFolder {
parsedSize: this.parsedSize,
gzipSize: this.gzipSize,
brotliSize: this.brotliSize,
zstdSize: this.zstdSize,
inaccurateSizes: true
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/tree/ContentModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default class ContentModule extends Module {
return this.getSize('brotliSize');
}

get zstdSize() {
return this.getSize('zstdSize');
}

getSize(sizeType) {
const ownerModuleSize = this.ownerModule[sizeType];

Expand Down
7 changes: 6 additions & 1 deletion src/tree/Folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default class Folder extends BaseFolder {
return this.opts.compressionAlgorithm === 'brotli' ? this.getCompressedSize('brotli') : undefined;
}

get zstdSize() {
return this.opts.compressionAlgorithm === 'zstd' ? this.getCompressedSize('zstd') : undefined;
}

getCompressedSize(compressionAlgorithm) {
const key = `_${compressionAlgorithm}Size`;

Expand Down Expand Up @@ -71,7 +75,8 @@ export default class Folder extends BaseFolder {
...super.toChartData(),
parsedSize: this.parsedSize,
gzipSize: this.gzipSize,
brotliSize: this.brotliSize
brotliSize: this.brotliSize,
zstdSize: this.zstdSize
};
}

Expand Down
12 changes: 11 additions & 1 deletion src/tree/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class Module extends Node {
this.data.parsedSrc = value;
delete this._gzipSize;
delete this._brotliSize;
delete this._zstdSize;
}

get size() {
Expand All @@ -39,6 +40,10 @@ export default class Module extends Node {
return this.getBrotliSize();
}

get zstdSize() {
return this.getZstdSize();
}

getParsedSize() {
return this.src ? this.src.length : undefined;
}
Expand All @@ -51,6 +56,10 @@ export default class Module extends Node {
return this.opts.compressionAlgorithm === 'brotli' ? this.getCompressedSize('brotli') : undefined;
}

getZstdSize() {
return this.opts.compressionAlgorithm === 'zstd' ? this.getCompressedSize('zstd') : undefined;
}

getCompressedSize(compressionAlgorithm) {
const key = `_${compressionAlgorithm}Size`;
if (!(key in this)) {
Expand Down Expand Up @@ -78,7 +87,8 @@ export default class Module extends Node {
statSize: this.size,
parsedSize: this.parsedSize,
gzipSize: this.gzipSize,
brotliSize: this.brotliSize
brotliSize: this.brotliSize,
zstdSize: this.zstdSize
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function resolveTitle(reportTitle) {
}

function resolveDefaultSizes(defaultSizes, compressionAlgorithm) {
if (['gzip', 'brotli'].includes(defaultSizes)) return compressionAlgorithm;
if (['gzip', 'brotli', 'zstd'].includes(defaultSizes)) return compressionAlgorithm;
return defaultSizes;
}

Expand Down
5 changes: 5 additions & 0 deletions test/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ describe('Analyzer', function () {
expect(await getCompressionAlgorithm()).to.equal('gzip');
});

it('should accept --compression-algorithm zstd', async function () {
generateReportFrom('with-modules-chunk.json', '--compression-algorithm zstd');
expect(await getCompressionAlgorithm()).to.equal('zstd');
});

it('should default to gzip', async function () {
generateReportFrom('with-modules-chunk.json');
expect(await getCompressionAlgorithm()).to.equal('gzip');
Expand Down
10 changes: 9 additions & 1 deletion test/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ describe('Plugin', function () {
await webpackCompile(config, '4.44.2');
await expectValidReport({parsedSize: 1311, gzipSize: undefined, brotliSize: 302});
});

it('should support zstd', async function () {
const config = makeWebpackConfig({analyzerOpts: {compressionAlgorithm: 'zstd'}});
await webpackCompile(config, '4.44.2');
await expectValidReport({parsedSize: 1311, gzipSize: undefined, brotliSize: undefined, zstdSize: 345});
});
});
});

Expand All @@ -208,7 +214,9 @@ describe('Plugin', function () {
label: bundleLabel,
statSize,
parsedSize,
gzipSize
gzipSize,
brotliSize: opts.brotliSize,
zstdSize: opts.zstdSize
});
}

Expand Down
Loading