Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zstd Compressor #10058

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
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
26 changes: 26 additions & 0 deletions packages/compressors/zstd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@parcel/compressor-zstd",
"version": "2.13.3",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/parcel"
},
"repository": {
"type": "git",
"url": "https://github.com/parcel-bundler/parcel.git"
},
"main": "lib/ZstdCompressor.js",
"source": "src/ZstdCompressor.js",
"engines": {
"node": ">= 16.0.0",
"parcel": "^2.13.3"
},
"dependencies": {
"@mongodb-js/zstd": "^2.0.0",
"@parcel/plugin": "2.13.3"
}
}
26 changes: 26 additions & 0 deletions packages/compressors/zstd/src/ZstdCompressor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @flow
import {Compressor} from '@parcel/plugin';
import {compress} from '@mongodb-js/zstd';
import {Transform} from 'stream';

export default (new Compressor({
compress({options, stream}) {
if (options.mode !== 'production') {
return null;
}

return {
stream: stream.pipe(
new Transform({
transform(chunk, encoding, cb) {
compress(chunk, 19).then(
compressed => cb(null, compressed),
error => cb(error, null),
);
},
}),
),
type: 'zst',
};
},
}): Compressor);
3 changes: 2 additions & 1 deletion packages/core/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"tailwindcss": "^3.0.2",
"tempy": "^0.3.0",
"wasm-sourcemap": "^1.0.0",
"ws": "^8.18.0"
"ws": "^8.18.0",
"@mongodb-js/zstd": "^2.0.0"
}
}
28 changes: 18 additions & 10 deletions packages/core/integration-tests/test/compressors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,44 @@ import assert from 'assert';
import path from 'path';
import zlib from 'zlib';
import {bundle, outputFS, distDir} from '@parcel/test-utils';
import {decompress} from '@mongodb-js/zstd';

describe('compressors', function () {
it('should not compress output with gzip and brotli in development', async function () {
it('should not compress output with gzip, brotli, or zstd in development', async function () {
await bundle(path.join(__dirname, 'integration/compressors/index.js'));

let output = await outputFS.readdir(distDir);
assert.deepEqual(output.sort(), ['index.js', 'index.js.map']);
});

it('should compress output with gzip and brotli', async function () {
it('should compress output with gzip, brotli, and zstd', async function () {
await bundle(path.join(__dirname, 'integration/compressors/index.js'), {
mode: 'production',
});

let output = await outputFS.readdir(distDir);
assert.deepEqual(output.sort(), [
'index.js',
'index.js.br',
'index.js.gz',
'index.js.map',
'index.js.map.br',
'index.js.map.gz',
]);
assert.deepEqual(
output.sort(),
[
'index.js',
'index.js.br',
'index.js.gz',
'index.js.zst',
'index.js.map',
'index.js.map.br',
'index.js.map.gz',
'index.js.map.zst',
].sort(),
);

let raw = await outputFS.readFile(path.join(distDir, 'index.js'));
let gz = await outputFS.readFile(path.join(distDir, 'index.js.gz'));
let br = await outputFS.readFile(path.join(distDir, 'index.js.br'));
let zstd = await outputFS.readFile(path.join(distDir, 'index.js.zst'));

assert(zlib.gunzipSync(gz).equals(raw));
assert(zlib.brotliDecompressSync(br).equals(raw));
assert((await decompress(zstd)).equals(raw));
});

it('should be able to disable raw output', async function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["@parcel/config-default"],
"compressors": {
"*": ["...", "@parcel/compressor-gzip", "@parcel/compressor-brotli"]
"*": ["...", "@parcel/compressor-gzip", "@parcel/compressor-brotli", "@parcel/compressor-zstd"]
}
}
Loading