Skip to content

Commit c3111d0

Browse files
committed
remove node:module polyfills
1 parent 88fd2f9 commit c3111d0

File tree

4 files changed

+50
-103
lines changed

4 files changed

+50
-103
lines changed

.changeset/cruel-terms-smell.md

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

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",
@@ -43,7 +44,7 @@ const nativeModules = [
4344
];
4445

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

4849
/**
4950
* 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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const WorkerdTests: Record<string, () => void> = {
115115
"path/posix",
116116
"path/win32",
117117
"querystring",
118+
"module",
118119
"stream",
119120
"stream/consumers",
120121
"stream/promises",
@@ -329,4 +330,45 @@ export const WorkerdTests: Record<string, () => void> = {
329330
});
330331
assert.deepStrictEqual(result, { test: "require" });
331332
},
333+
334+
async testModule() {
335+
const module = await import("node:module");
336+
const exportNames = [
337+
"createRequire",
338+
"enableCompileCache",
339+
"findSourceMap",
340+
"getCompileCacheDir",
341+
"getSourceMapsSupport",
342+
"isBuiltin",
343+
"register",
344+
"runMain",
345+
"setSourceMapsSupport",
346+
"stripTypeScriptTypes",
347+
"syncBuiltinESMExports",
348+
"wrap",
349+
"flushCompileCache",
350+
"findPackageJSON",
351+
"_debug",
352+
"_findPath",
353+
"_initPaths",
354+
"_load",
355+
"_preloadModules",
356+
"_resolveFilename",
357+
"_resolveLookupPaths",
358+
"_nodeModulePaths",
359+
"Module",
360+
"SourceMap",
361+
];
362+
363+
for (const name of exportNames) {
364+
assert.strictEqual(typeof module[name], "function");
365+
}
366+
367+
assert.ok(Array.isArray(module.globalPaths));
368+
assert.ok(Array.isArray(module.builtinModules));
369+
assert.strictEqual(typeof module.constants, "object");
370+
assert.strictEqual(typeof module._cache, "object");
371+
assert.strictEqual(typeof module._extensions, "object");
372+
assert.strictEqual(typeof module._pathCache, "object");
373+
},
332374
};

0 commit comments

Comments
 (0)