Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: polyfill node:module #148

Merged
merged 1 commit into from
Nov 22, 2023
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Using this preset, we can convert a code that is depending on Node.js to work an
| [node:http](https://nodejs.org/api/http.html) | Polyfilled | [unenv/node/http](./src/runtime/node/http) |
| [node:https](https://nodejs.org/api/https.html) | Mocked | - |
| [node:inspector](https://nodejs.org/api/inspector.html) | Mocked | - |
| [node:module](https://nodejs.org/api/module.html) | Mocked | - |
| [node:module](https://nodejs.org/api/module.html) | Polyfilled | [unenv/node/module](./src/runtime/node/module) - |
| [node:net](https://nodejs.org/api/net.html) | Polyfilled | [unenv/node/net](./src/runtime/node/net) |
| [node:os](https://nodejs.org/api/os.html) | Mocked | - |
| [node:path](https://nodejs.org/api/path.html) | Polyfilled | [unenv/node/path](./src/runtime/node/path) |
Expand Down
52 changes: 52 additions & 0 deletions src/runtime/node/module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// https://nodejs.org/api/module.html
import type nodeModule from "node:module";
import { notImplemented, notImplementedClass } from "../../_internal/utils";

export const builtinModules: typeof nodeModule.builtinModules = [];

export const createRequire = notImplemented(
"module.createRequire",
) as typeof nodeModule.createRequire;

export const runMain = notImplemented(
"module.runMain",
) as typeof nodeModule.runMain;

export const isBuiltin = notImplemented(
"module.isBuiltin",
) as typeof nodeModule.isBuiltin;

export const register = notImplemented(
"module.register",
) as typeof nodeModule.register;

export const syncBuiltinESMExports = notImplemented(
"module.syncBuiltinESMExports",
) as typeof nodeModule.syncBuiltinESMExports;

export const findSourceMap = notImplemented(
"module.syncBuiltinESMExports",
) as typeof nodeModule.findSourceMap;

export const wrap = notImplemented("module.wrap") as typeof nodeModule.wrap;

export const Module = notImplementedClass(
"module.Module",
) as typeof nodeModule.Module;

export const SourceMap = notImplementedClass(
"module.SourceMap",
) as typeof nodeModule.SourceMap;

export default <typeof nodeModule>{
Module,
SourceMap,
builtinModules,
createRequire,
runMain,
wrap,
isBuiltin,
register,
syncBuiltinESMExports,
findSourceMap,
};