Skip to content

Commit f656d1a

Browse files
anonrigvicb
andauthored
remove node:module polyfills (#10431)
Co-authored-by: Victor Berchet <[email protected]>
1 parent 25ef29d commit f656d1a

File tree

6 files changed

+57
-105
lines changed

6 files changed

+57
-105
lines changed

.changeset/cruel-terms-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/unenv-preset": patch
3+
---
4+
5+
Remove node:module polyfills

packages/unenv-preset/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"peerDependencies": {
5151
"unenv": "2.0.0-rc.19",
52-
"workerd": "^1.20250816.0"
52+
"workerd": "^1.20250823.0"
5353
},
5454
"peerDependenciesMeta": {
5555
"workerd": {

packages/unenv-preset/src/preset.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const nativeModules = [
3030
"path/posix",
3131
"path/win32",
3232
"querystring",
33+
"module",
3334
"stream",
3435
"stream/consumers",
3536
"stream/promises",
@@ -44,7 +45,7 @@ const nativeModules = [
4445
];
4546

4647
// Modules implemented via a mix of workerd APIs and polyfills.
47-
const hybridModules = ["console", "crypto", "module", "process", "util"];
48+
const hybridModules = ["console", "crypto", "process", "util"];
4849

4950
/**
5051
* Creates the Cloudflare preset for the given compatibility date and compatibility flags

packages/unenv-preset/src/runtime/node/module.ts

Lines changed: 0 additions & 102 deletions
This file was deleted.

packages/wrangler/e2e/unenv-preset/worker/index.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const WorkerdTests: Record<string, () => void> = {
116116
"path/posix",
117117
"path/win32",
118118
"querystring",
119+
"module",
119120
"stream",
120121
"stream/consumers",
121122
"stream/promises",
@@ -387,4 +388,51 @@ export const WorkerdTests: Record<string, () => void> = {
387388
assert.throws(() => fs.openAsBlob("/tmp/sync"), /not implemented/);
388389
}
389390
},
391+
392+
async testModule() {
393+
const module = await import("node:module");
394+
const exportNames = [
395+
"createRequire",
396+
"enableCompileCache",
397+
"findSourceMap",
398+
"getCompileCacheDir",
399+
"getSourceMapsSupport",
400+
"isBuiltin",
401+
"register",
402+
"runMain",
403+
"setSourceMapsSupport",
404+
"stripTypeScriptTypes",
405+
"syncBuiltinESMExports",
406+
"wrap",
407+
"flushCompileCache",
408+
"findPackageJSON",
409+
"_debug",
410+
"_findPath",
411+
"_initPaths",
412+
"_load",
413+
"_preloadModules",
414+
"_resolveFilename",
415+
"_resolveLookupPaths",
416+
"_nodeModulePaths",
417+
"Module",
418+
"SourceMap",
419+
];
420+
421+
for (const name of exportNames) {
422+
// @ts-expect-error TS7053
423+
assert.strictEqual(typeof module[name], "function");
424+
}
425+
426+
// @ts-expect-error TS2339 Invalid node/types.
427+
assert.ok(Array.isArray(module.globalPaths));
428+
assert.ok(Array.isArray(module.builtinModules));
429+
// @ts-expect-error TS2339 Invalid node/types.
430+
assert.strictEqual(typeof module.constants, "object");
431+
// @ts-expect-error TS2339 Invalid node/types.
432+
assert.strictEqual(typeof module._cache, "object");
433+
// @ts-expect-error TS2339 Invalid node/types.
434+
assert.strictEqual(typeof module._extensions, "object");
435+
// @ts-expect-error TS2339 Invalid node/types.
436+
assert.strictEqual(typeof module._pathCache, "object");
437+
},
390438
};

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)