@@ -951,197 +951,10 @@ Since `require()` returns the `module.exports`, and the `module` is typically
951
951
* only* available within a specific module's code, it must be explicitly exported
952
952
in order to be used.
953
953
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
-
1140
954
[ GLOBAL_FOLDERS ] : #modules_loading_from_the_global_folders
1141
955
[ `Error` ] : errors.html#errors_class_error
1142
956
[ `__dirname` ] : #modules_dirname
1143
957
[ `__filename` ] : #modules_filename
1144
- [` createRequire ()` ]: #modules_module_createrequire_filename
1145
958
[ `module` object ] : #modules_the_module_object
1146
959
[ `module.id` ] : #modules_module_id
1147
960
[ `module.children` ] : #modules_module_children
@@ -1150,12 +963,5 @@ consists of the following keys:
1150
963
[ an error ] : errors.html#errors_err_require_esm
1151
964
[ exports shortcut ] : #modules_exports_shortcut
1152
965
[ module resolution ] : #modules_all_together
1153
- [module wrapper]: #modules_the_module_wrapper
1154
966
[ native addons ] : addons.html
1155
967
[ `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