Skip to content

Commit

Permalink
feat: polyfill node:module (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Nov 22, 2023
1 parent f778562 commit f6f276e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
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,
};

0 comments on commit f6f276e

Please sign in to comment.