Skip to content

Commit 325fab0

Browse files
committed
doc: move module core module doc to separate page
The `module` core module is available for both CJS and ESM users, it deserves its own page.
1 parent 3b84048 commit 325fab0

File tree

7 files changed

+200
-198
lines changed

7 files changed

+200
-198
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
files: [
4545
'doc/api/esm.md',
4646
'doc/api/modules.md',
47+
'doc/api/modules_module.md',
4748
'test/es-module/test-esm-type-flag.js',
4849
'test/es-module/test-esm-type-flag-alias.js',
4950
'*.mjs',

doc/api/deprecations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2828,7 +2828,7 @@ Type: Documentation-only
28282828
[`http.request()`]: http.html#http_http_request_options_callback
28292829
[`https.get()`]: https.html#https_https_get_options_callback
28302830
[`https.request()`]: https.html#https_https_request_options_callback
2831-
[`module.createRequire()`]: modules.html#modules_module_createrequire_filename
2831+
[`module.createRequire()`]: modules_module.html#modules_module_module_createrequire_filename
28322832
[`os.networkInterfaces()`]: os.html#os_os_networkinterfaces
28332833
[`os.tmpdir()`]: os.html#os_os_tmpdir
28342834
[`process.env`]: process.html#process_process_env

doc/api/esm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,8 +1949,8 @@ success!
19491949
[`import()`]: #esm_import_expressions
19501950
[`import.meta.url`]: #esm_import_meta
19511951
[`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
1952-
[`module.createRequire()`]: modules.html#modules_module_createrequire_filename
1953-
[`module.syncBuiltinESMExports()`]: modules.html#modules_module_syncbuiltinesmexports
1952+
[`module.createRequire()`]: modules_module.html#modules_module_module_createrequire_filename
1953+
[`module.syncBuiltinESMExports()`]: modules_module.html#modules_module_module_syncbuiltinesmexports
19541954
[`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource
19551955
[`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
19561956
[`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer

doc/api/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* [Inspector](inspector.html)
3737
* [Internationalization](intl.html)
3838
* [Modules](modules.html)
39+
* [Modules: `module` core module](modules_module.html)
3940
* [Net](net.html)
4041
* [OS](os.html)
4142
* [Path](path.html)

doc/api/modules.md

Lines changed: 0 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -951,197 +951,10 @@ Since `require()` returns the `module.exports`, and the `module` is typically
951951
*only* available within a specific module's code, it must be explicitly exported
952952
in order to be used.
953953

954-
## The `Module` object
955-
956-
<!-- YAML
957-
added: v0.3.7
958-
-->
959-
960-
* {Object}
961-
962-
Provides general utility methods when interacting with instances of
963-
`Module`, the `module` variable often seen in file modules. Accessed
964-
via `require('module')`.
965-
966-
### `module.builtinModules`
967-
<!-- YAML
968-
added:
969-
- v9.3.0
970-
- v8.10.0
971-
- v6.13.0
972-
-->
973-
974-
* {string[]}
975-
976-
A list of the names of all modules provided by Node.js. Can be used to verify
977-
if a module is maintained by a third party or not.
978-
979-
`module` in this context isn't the same object that's provided
980-
by the [module wrapper][]. To access it, require the `Module` module:
981-
982-
```js
983-
const builtin = require('module').builtinModules;
984-
```
985-
986-
### `module.createRequire(filename)`
987-
<!-- YAML
988-
added: v12.2.0
989-
-->
990-
991-
* `filename` {string|URL} Filename to be used to construct the require
992-
function. Must be a file URL object, file URL string, or absolute path
993-
string.
994-
* Returns: {require} Require function
995-
996-
```js
997-
import { createRequire } from 'module';
998-
const require = createRequire(import.meta.url);
999-
1000-
// sibling-module.js is a CommonJS module.
1001-
const siblingModule = require('./sibling-module');
1002-
```
1003-
1004-
### `module.createRequireFromPath(filename)`
1005-
<!-- YAML
1006-
added: v10.12.0
1007-
deprecated: v12.2.0
1008-
-->
1009-
1010-
> Stability: 0 - Deprecated: Please use [`createRequire()`][] instead.
1011-
1012-
* `filename` {string} Filename to be used to construct the relative require
1013-
function.
1014-
* Returns: {require} Require function
1015-
1016-
```js
1017-
const { createRequireFromPath } = require('module');
1018-
const requireUtil = createRequireFromPath('../src/utils/');
1019-
1020-
// Require `../src/utils/some-tool`
1021-
requireUtil('./some-tool');
1022-
```
1023-
1024-
### `module.syncBuiltinESMExports()`
1025-
<!-- YAML
1026-
added: v12.12.0
1027-
-->
1028-
1029-
The `module.syncBuiltinESMExports()` method updates all the live bindings for
1030-
builtin ES Modules to match the properties of the CommonJS exports. It does
1031-
not add or remove exported names from the ES Modules.
1032-
1033-
```js
1034-
const fs = require('fs');
1035-
const { syncBuiltinESMExports } = require('module');
1036-
1037-
fs.readFile = null;
1038-
1039-
delete fs.readFileSync;
1040-
1041-
fs.newAPI = function newAPI() {
1042-
// ...
1043-
};
1044-
1045-
syncBuiltinESMExports();
1046-
1047-
import('fs').then((esmFS) => {
1048-
assert.strictEqual(esmFS.readFile, null);
1049-
assert.strictEqual('readFileSync' in fs, true);
1050-
assert.strictEqual(esmFS.newAPI, undefined);
1051-
});
1052-
```
1053-
1054-
## Source map v3 support
1055-
<!-- YAML
1056-
added:
1057-
- v13.7.0
1058-
- v12.17.0
1059-
-->
1060-
1061-
> Stability: 1 - Experimental
1062-
1063-
Helpers for interacting with the source map cache. This cache is
1064-
populated when source map parsing is enabled and
1065-
[source map include directives][] are found in a modules' footer.
1066-
1067-
To enable source map parsing, Node.js must be run with the flag
1068-
[`--enable-source-maps`][], or with code coverage enabled by setting
1069-
[`NODE_V8_COVERAGE=dir`][].
1070-
1071-
```js
1072-
const { findSourceMap, SourceMap } = require('module');
1073-
```
1074-
1075-
### `module.findSourceMap(path[, error])`
1076-
<!-- YAML
1077-
added:
1078-
- v13.7.0
1079-
- v12.17.0
1080-
-->
1081-
1082-
* `path` {string}
1083-
* `error` {Error}
1084-
* Returns: {module.SourceMap}
1085-
1086-
`path` is the resolved path for the file for which a corresponding source map
1087-
should be fetched.
1088-
1089-
The `error` instance should be passed as the second parameter to `findSourceMap`
1090-
in exceptional flows, e.g., when an overridden
1091-
[`Error.prepareStackTrace(error, trace)`][] is invoked. Modules are not added to
1092-
the module cache until they are successfully loaded, in these cases source maps
1093-
will be associated with the `error` instance along with the `path`.
1094-
1095-
### Class: `module.SourceMap`
1096-
<!-- YAML
1097-
added:
1098-
- v13.7.0
1099-
- v12.17.0
1100-
-->
1101-
1102-
#### `new SourceMap(payload)`
1103-
1104-
* `payload` {Object}
1105-
1106-
Creates a new `sourceMap` instance.
1107-
1108-
`payload` is an object with keys matching the [Source map v3 format][]:
1109-
1110-
* `file`: {string}
1111-
* `version`: {number}
1112-
* `sources`: {string[]}
1113-
* `sourcesContent`: {string[]}
1114-
* `names`: {string[]}
1115-
* `mappings`: {string}
1116-
* `sourceRoot`: {string}
1117-
1118-
#### `sourceMap.payload`
1119-
1120-
* Returns: {Object}
1121-
1122-
Getter for the payload used to construct the [`SourceMap`][] instance.
1123-
1124-
#### `sourceMap.findEntry(lineNumber, columnNumber)`
1125-
1126-
* `lineNumber` {number}
1127-
* `columnNumber` {number}
1128-
* Returns: {Object}
1129-
1130-
Given a line number and column number in the generated source file, returns
1131-
an object representing the position in the original file. The object returned
1132-
consists of the following keys:
1133-
1134-
* generatedLine: {number}
1135-
* generatedColumn: {number}
1136-
* originalSource: {string}
1137-
* originalLine: {number}
1138-
* originalColumn: {number}
1139-
1140954
[GLOBAL_FOLDERS]: #modules_loading_from_the_global_folders
1141955
[`Error`]: errors.html#errors_class_error
1142956
[`__dirname`]: #modules_dirname
1143957
[`__filename`]: #modules_filename
1144-
[`createRequire()`]: #modules_module_createrequire_filename
1145958
[`module` object]: #modules_the_module_object
1146959
[`module.id`]: #modules_module_id
1147960
[`module.children`]: #modules_module_children
@@ -1150,12 +963,5 @@ consists of the following keys:
1150963
[an error]: errors.html#errors_err_require_esm
1151964
[exports shortcut]: #modules_exports_shortcut
1152965
[module resolution]: #modules_all_together
1153-
[module wrapper]: #modules_the_module_wrapper
1154966
[native addons]: addons.html
1155967
[`require.main`]: #modules_require_main
1156-
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
1157-
[`--enable-source-maps`]: cli.html#cli_enable_source_maps
1158-
[`NODE_V8_COVERAGE=dir`]: cli.html#cli_node_v8_coverage_dir
1159-
[`Error.prepareStackTrace(error, trace)`]: https://v8.dev/docs/stack-trace-api#customizing-stack-traces
1160-
[`SourceMap`]: modules.html#modules_class_module_sourcemap
1161-
[Source map v3 format]: https://sourcemaps.info/spec.html#h.mofvlxcwqzej

0 commit comments

Comments
 (0)