Skip to content

Commit

Permalink
[Miniflare 2] Remove experimental flag requirement for nodejs_compat …
Browse files Browse the repository at this point in the history
…modules (#548)

* Remove experimental flag requirement for node modules

* Move experimental compat flag tests to nodejs_compat
  • Loading branch information
DaniFoldi authored Mar 23, 2023
1 parent f9ca91f commit eaed542
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 4 additions & 8 deletions packages/core/src/plugins/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import * as buffer from "./buffer";
import * as events from "./events";
import * as util from "./util";

export function additionalNodeModules(experimental: boolean) {
export function additionalNodeModules(_experimental: boolean) {
const modules: AdditionalModules = {
"node:assert": assert,
"node:async_hooks": async_hooks,
"node:buffer": buffer,
"node:events": events,
"node:util": util,
};

if (experimental) {
// TODO(soon): remove experimental designations when removed in `workerd`
modules["node:assert"] = assert;
modules["node:buffer"] = buffer;
modules["node:util"] = util;
}

return modules;
}
10 changes: 8 additions & 2 deletions packages/core/test/plugins/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,21 @@ test("CorePlugin: nodejs_compat compatibility flag includes Node.js modules", as
let plugin = new CorePlugin({ ...ctx, compat });
let modules = (await plugin.setup()).additionalModules!;
const names = Object.keys(modules).sort();
t.deepEqual(names, ["node:async_hooks", "node:events"]);
t.deepEqual(names, [
"node:assert",
"node:async_hooks",
"node:buffer",
"node:events",
"node:util",
]);

compat = new Compatibility(undefined, ["nodejs_compat", "experimental"]);
plugin = new CorePlugin({ ...ctx, compat });
modules = (await plugin.setup()).additionalModules!;
const experimentalNames = Object.keys(modules).filter(
(name) => !names.includes(name)
);
t.deepEqual(experimentalNames, ["node:assert", "node:buffer", "node:util"]);
t.deepEqual(experimentalNames, []);

// We're using Node's implementations of these modules' exports, so don't
// bother testing their functionality. Instead, just check we've got the
Expand Down

0 comments on commit eaed542

Please sign in to comment.