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
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,35 @@
zlibConstants[ck] = result[ck];
}
}
// Add Z_* constants that esbuild may strip from the browserify-zlib bundle.
if (typeof zlibConstants.Z_NO_FLUSH !== 'number') zlibConstants.Z_NO_FLUSH = 0;
if (typeof zlibConstants.Z_PARTIAL_FLUSH !== 'number') zlibConstants.Z_PARTIAL_FLUSH = 1;
if (typeof zlibConstants.Z_SYNC_FLUSH !== 'number') zlibConstants.Z_SYNC_FLUSH = 2;
if (typeof zlibConstants.Z_FULL_FLUSH !== 'number') zlibConstants.Z_FULL_FLUSH = 3;
if (typeof zlibConstants.Z_FINISH !== 'number') zlibConstants.Z_FINISH = 4;
if (typeof zlibConstants.Z_BLOCK !== 'number') zlibConstants.Z_BLOCK = 5;
if (typeof zlibConstants.Z_TREES !== 'number') zlibConstants.Z_TREES = 6;
// Return code constants
if (typeof zlibConstants.Z_OK !== 'number') zlibConstants.Z_OK = 0;
if (typeof zlibConstants.Z_STREAM_END !== 'number') zlibConstants.Z_STREAM_END = 1;
if (typeof zlibConstants.Z_NEED_DICT !== 'number') zlibConstants.Z_NEED_DICT = 2;
if (typeof zlibConstants.Z_ERRNO !== 'number') zlibConstants.Z_ERRNO = -1;
if (typeof zlibConstants.Z_STREAM_ERROR !== 'number') zlibConstants.Z_STREAM_ERROR = -2;
if (typeof zlibConstants.Z_DATA_ERROR !== 'number') zlibConstants.Z_DATA_ERROR = -3;
if (typeof zlibConstants.Z_MEM_ERROR !== 'number') zlibConstants.Z_MEM_ERROR = -4;
if (typeof zlibConstants.Z_BUF_ERROR !== 'number') zlibConstants.Z_BUF_ERROR = -5;
if (typeof zlibConstants.Z_VERSION_ERROR !== 'number') zlibConstants.Z_VERSION_ERROR = -6;
// Compression level constants
if (typeof zlibConstants.Z_NO_COMPRESSION !== 'number') zlibConstants.Z_NO_COMPRESSION = 0;
if (typeof zlibConstants.Z_BEST_SPEED !== 'number') zlibConstants.Z_BEST_SPEED = 1;
if (typeof zlibConstants.Z_BEST_COMPRESSION !== 'number') zlibConstants.Z_BEST_COMPRESSION = 9;
if (typeof zlibConstants.Z_DEFAULT_COMPRESSION !== 'number') zlibConstants.Z_DEFAULT_COMPRESSION = -1;
// Strategy constants
if (typeof zlibConstants.Z_FILTERED !== 'number') zlibConstants.Z_FILTERED = 1;
if (typeof zlibConstants.Z_HUFFMAN_ONLY !== 'number') zlibConstants.Z_HUFFMAN_ONLY = 2;
if (typeof zlibConstants.Z_RLE !== 'number') zlibConstants.Z_RLE = 3;
if (typeof zlibConstants.Z_FIXED !== 'number') zlibConstants.Z_FIXED = 4;
if (typeof zlibConstants.Z_DEFAULT_STRATEGY !== 'number') zlibConstants.Z_DEFAULT_STRATEGY = 0;
// Add mode constants that Node.js exposes but browserify-zlib does not.
if (typeof zlibConstants.DEFLATE !== 'number') zlibConstants.DEFLATE = 1;
if (typeof zlibConstants.INFLATE !== 'number') zlibConstants.INFLATE = 2;
Expand Down
63 changes: 63 additions & 0 deletions packages/secure-exec/tests/test-suite/node/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,69 @@ export function runNodePolyfillSuite(context: NodeSuiteContext): void {
});
});

it("zlib.constants has flush, return-code, level, and strategy constants", async () => {
const runtime = await context.createRuntime();
const result = await runtime.run(`
const zlib = require('zlib');
const c = zlib.constants;
module.exports = {
Z_NO_FLUSH: c.Z_NO_FLUSH,
Z_PARTIAL_FLUSH: c.Z_PARTIAL_FLUSH,
Z_SYNC_FLUSH: c.Z_SYNC_FLUSH,
Z_FULL_FLUSH: c.Z_FULL_FLUSH,
Z_FINISH: c.Z_FINISH,
Z_BLOCK: c.Z_BLOCK,
Z_TREES: c.Z_TREES,
Z_OK: c.Z_OK,
Z_STREAM_END: c.Z_STREAM_END,
Z_NEED_DICT: c.Z_NEED_DICT,
Z_ERRNO: c.Z_ERRNO,
Z_STREAM_ERROR: c.Z_STREAM_ERROR,
Z_DATA_ERROR: c.Z_DATA_ERROR,
Z_MEM_ERROR: c.Z_MEM_ERROR,
Z_BUF_ERROR: c.Z_BUF_ERROR,
Z_VERSION_ERROR: c.Z_VERSION_ERROR,
Z_NO_COMPRESSION: c.Z_NO_COMPRESSION,
Z_BEST_SPEED: c.Z_BEST_SPEED,
Z_BEST_COMPRESSION: c.Z_BEST_COMPRESSION,
Z_DEFAULT_COMPRESSION: c.Z_DEFAULT_COMPRESSION,
Z_FILTERED: c.Z_FILTERED,
Z_HUFFMAN_ONLY: c.Z_HUFFMAN_ONLY,
Z_RLE: c.Z_RLE,
Z_FIXED: c.Z_FIXED,
Z_DEFAULT_STRATEGY: c.Z_DEFAULT_STRATEGY,
};
`);
expect(result.code).toBe(0);
expect(result.exports).toEqual({
Z_NO_FLUSH: 0,
Z_PARTIAL_FLUSH: 1,
Z_SYNC_FLUSH: 2,
Z_FULL_FLUSH: 3,
Z_FINISH: 4,
Z_BLOCK: 5,
Z_TREES: 6,
Z_OK: 0,
Z_STREAM_END: 1,
Z_NEED_DICT: 2,
Z_ERRNO: -1,
Z_STREAM_ERROR: -2,
Z_DATA_ERROR: -3,
Z_MEM_ERROR: -4,
Z_BUF_ERROR: -5,
Z_VERSION_ERROR: -6,
Z_NO_COMPRESSION: 0,
Z_BEST_SPEED: 1,
Z_BEST_COMPRESSION: 9,
Z_DEFAULT_COMPRESSION: -1,
Z_FILTERED: 1,
Z_HUFFMAN_ONLY: 2,
Z_RLE: 3,
Z_FIXED: 4,
Z_DEFAULT_STRATEGY: 0,
});
});

it("zlib.constants has mode constants (DEFLATE=1..GUNZIP=7)", async () => {
const runtime = await context.createRuntime();
const result = await runtime.run(`
Expand Down