Skip to content

Commit

Permalink
move functionality behind compatibility flag
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Aug 21, 2024
1 parent 361bdb9 commit ff27190
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/node/internal/compatibility-flags.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export const specCompliantResponseRedirect: boolean;
export const workerdExperimental: boolean;
export const durableObjectGetExisting: boolean;
export const vectorizeQueryMetadataOptional: boolean;
export const nodeJsZlib: boolean;
46 changes: 28 additions & 18 deletions src/node/zlib.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import {
crc32,
constants,
Gzip,
Gunzip,
Deflate,
DeflateRaw,
Inflate,
InflateRaw,
Unzip,
createGzip,
createGunzip,
createDeflate,
createDeflateRaw,
createInflate,
createInflateRaw,
createUnzip,
} from 'node-internal:internal_zlib';
import * as zlib from 'node-internal:internal_zlib';
import { crc32, constants } from 'node-internal:internal_zlib';
import { nodeJsZlib } from 'workerd:compatibility-flags';

function protectMethod(method: unknown): unknown {
if (nodeJsZlib) {
return function notImplemented() {
throw new Error('Compatibility flag "nodejs_zlib" is not enabled');
};
}

return method;
}

const Gzip = protectMethod(zlib.Gzip);
const Gunzip = protectMethod(zlib.Gunzip);
const Deflate = protectMethod(zlib.Deflate);
const DeflateRaw = protectMethod(zlib.DeflateRaw);
const Inflate = protectMethod(zlib.Inflate);
const InflateRaw = protectMethod(zlib.InflateRaw);
const Unzip = protectMethod(zlib.Unzip);
const createGzip = protectMethod(zlib.createGzip);
const createGunzip = protectMethod(zlib.createGunzip);
const createDeflate = protectMethod(zlib.createDeflate);
const createDeflateRaw = protectMethod(zlib.createDeflateRaw);
const createInflate = protectMethod(zlib.createInflate);
const createInflateRaw = protectMethod(zlib.createInflateRaw);
const createUnzip = protectMethod(zlib.createUnzip);

export {
crc32,
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/node/tests/zlib-nodejs-test.wd-test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const unitTests :Workerd.Config = (
(name = "worker", esModule = embed "zlib-nodejs-test.js")
],
compatibilityDate = "2023-01-15",
compatibilityFlags = ["experimental", "nodejs_compat"],
compatibilityFlags = ["experimental", "nodejs_compat", "nodejs_zlib"],
)
),
],
Expand Down
8 changes: 8 additions & 0 deletions src/workerd/io/compatibility-date.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,12 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
packages = "2024-03-01", backport = 0)
$experimental;
# Enables Python Workers and uses the bundle from the Pyodide source directory directly. For testing only.

nodeJsZlib @59 :Bool
$compatEnableFlag("nodejs_zlib")
$compatDisableFlag("no_nodejs_zlib")
$experimental;
# Enables node:zlib implementation while it is in-development.
# Once the node:zlib implementation is complete, this will be automatically enabled when
# nodejs_compat is enabled.
}

0 comments on commit ff27190

Please sign in to comment.