1{ 2 "type": "module", 3 "source": "doc/api/module.md", 4 "modules": [ 5 { 6 "textRaw": "Modules: `module` API", 7 "name": "modules:_`module`_api", 8 "introduced_in": "v12.20.0", 9 "meta": { 10 "added": [ 11 "v0.3.7" 12 ], 13 "changes": [] 14 }, 15 "modules": [ 16 { 17 "textRaw": "The `Module` object", 18 "name": "the_`module`_object", 19 "desc": "<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\"><Object></a></li>\n</ul>\n<p>Provides general utility methods when interacting with instances of\n<code>Module</code>, the <a href=\"modules.html#modules_the_module_object\"><code>module</code></a> variable often seen in <a href=\"modules.html\">CommonJS</a> modules. Accessed\nvia <code>import 'module'</code> or <code>require('module')</code>.</p>", 20 "properties": [ 21 { 22 "textRaw": "`builtinModules` {string[]}", 23 "type": "string[]", 24 "name": "builtinModules", 25 "meta": { 26 "added": [ 27 "v9.3.0", 28 "v8.10.0", 29 "v6.13.0" 30 ], 31 "changes": [] 32 }, 33 "desc": "<p>A list of the names of all modules provided by Node.js. Can be used to verify\nif a module is maintained by a third party or not.</p>\n<p><code>module</code> in this context isn't the same object that's provided\nby the <a href=\"modules.html#modules_the_module_wrapper\">module wrapper</a>. To access it, require the <code>Module</code> module:</p>\n<pre><code class=\"language-mjs\">// module.mjs\n// In an ECMAScript module\nimport { builtinModules as builtin } from 'module';\n</code></pre>\n<pre><code class=\"language-cjs\">// module.cjs\n// In a CommonJS module\nconst builtin = require('module').builtinModules;\n</code></pre>" 34 } 35 ], 36 "methods": [ 37 { 38 "textRaw": "`module.createRequire(filename)`", 39 "type": "method", 40 "name": "createRequire", 41 "meta": { 42 "added": [ 43 "v12.2.0" 44 ], 45 "changes": [] 46 }, 47 "signatures": [ 48 { 49 "return": { 50 "textRaw": "Returns: {require} Require function", 51 "name": "return", 52 "type": "require", 53 "desc": "Require function" 54 }, 55 "params": [ 56 { 57 "textRaw": "`filename` {string|URL} Filename to be used to construct the require function. Must be a file URL object, file URL string, or absolute path string.", 58 "name": "filename", 59 "type": "string|URL", 60 "desc": "Filename to be used to construct the require function. Must be a file URL object, file URL string, or absolute path string." 61 } 62 ] 63 } 64 ], 65 "desc": "<pre><code class=\"language-mjs\">import { createRequire } from 'module';\nconst require = createRequire(import.meta.url);\n\n// sibling-module.js is a CommonJS module.\nconst siblingModule = require('./sibling-module');\n</code></pre>" 66 }, 67 { 68 "textRaw": "`module.createRequireFromPath(filename)`", 69 "type": "method", 70 "name": "createRequireFromPath", 71 "meta": { 72 "added": [ 73 "v10.12.0" 74 ], 75 "deprecated": [ 76 "v12.2.0" 77 ], 78 "changes": [] 79 }, 80 "stability": 0, 81 "stabilityText": "Deprecated: Please use [`createRequire()`][] instead.", 82 "signatures": [ 83 { 84 "return": { 85 "textRaw": "Returns: {require} Require function", 86 "name": "return", 87 "type": "require", 88 "desc": "Require function" 89 }, 90 "params": [ 91 { 92 "textRaw": "`filename` {string} Filename to be used to construct the relative require function.", 93 "name": "filename", 94 "type": "string", 95 "desc": "Filename to be used to construct the relative require function." 96 } 97 ] 98 } 99 ], 100 "desc": "<pre><code class=\"language-js\">const { createRequireFromPath } = require('module');\nconst requireUtil = createRequireFromPath('../src/utils/');\n\n// Require `../src/utils/some-tool`\nrequireUtil('./some-tool');\n</code></pre>" 101 }, 102 { 103 "textRaw": "`module.syncBuiltinESMExports()`", 104 "type": "method", 105 "name": "syncBuiltinESMExports", 106 "meta": { 107 "added": [ 108 "v12.12.0" 109 ], 110 "changes": [] 111 }, 112 "signatures": [ 113 { 114 "params": [] 115 } 116 ], 117 "desc": "<p>The <code>module.syncBuiltinESMExports()</code> method updates all the live bindings for\nbuiltin <a href=\"esm.html\">ES Modules</a> to match the properties of the <a href=\"modules.html\">CommonJS</a> exports. It\ndoes not add or remove exported names from the <a href=\"esm.html\">ES Modules</a>.</p>\n<pre><code class=\"language-js\">const fs = require('fs');\nconst assert = require('assert');\nconst { syncBuiltinESMExports } = require('module');\n\nfs.readFile = newAPI;\n\ndelete fs.readFileSync;\n\nfunction newAPI() {\n // ...\n}\n\nfs.newAPI = newAPI;\n\nsyncBuiltinESMExports();\n\nimport('fs').then((esmFS) => {\n // It syncs the existing readFile property with the new value\n assert.strictEqual(esmFS.readFile, newAPI);\n // readFileSync has been deleted from the required fs\n assert.strictEqual('readFileSync' in fs, false);\n // syncBuiltinESMExports() does not remove readFileSync from esmFS\n assert.strictEqual('readFileSync' in esmFS, true);\n // syncBuiltinESMExports() does not add names\n assert.strictEqual(esmFS.newAPI, undefined);\n});\n</code></pre>" 118 } 119 ], 120 "type": "module", 121 "displayName": "The `Module` object" 122 }, 123 { 124 "textRaw": "Source map v3 support", 125 "name": "source_map_v3_support", 126 "meta": { 127 "added": [ 128 "v13.7.0", 129 "v12.17.0" 130 ], 131 "changes": [] 132 }, 133 "stability": 1, 134 "stabilityText": "Experimental", 135 "desc": "<p>Helpers for interacting with the source map cache. This cache is\npopulated when source map parsing is enabled and\n<a href=\"https://sourcemaps.info/spec.html#h.lmz475t4mvbx\">source map include directives</a> are found in a modules' footer.</p>\n<p>To enable source map parsing, Node.js must be run with the flag\n<a href=\"cli.html#cli_enable_source_maps\"><code>--enable-source-maps</code></a>, or with code coverage enabled by setting\n<a href=\"cli.html#cli_node_v8_coverage_dir\"><code>NODE_V8_COVERAGE=dir</code></a>.</p>\n<pre><code class=\"language-mjs\">// module.mjs\n// In an ECMAScript module\nimport { findSourceMap, SourceMap } from 'module';\n</code></pre>\n<pre><code class=\"language-cjs\">// module.cjs\n// In a CommonJS module\nconst { findSourceMap, SourceMap } = require('module');\n</code></pre>\n<!-- Anchors to make sure old links find a target -->\n<p><a id=\"module_module_findsourcemap_path_error\"></a></p>", 136 "methods": [ 137 { 138 "textRaw": "`module.findSourceMap(path)`", 139 "type": "method", 140 "name": "findSourceMap", 141 "meta": { 142 "added": [ 143 "v13.7.0", 144 "v12.17.0" 145 ], 146 "changes": [] 147 }, 148 "signatures": [ 149 { 150 "return": { 151 "textRaw": "Returns: {module.SourceMap}", 152 "name": "return", 153 "type": "module.SourceMap" 154 }, 155 "params": [ 156 { 157 "textRaw": "`path` {string}", 158 "name": "path", 159 "type": "string" 160 } 161 ] 162 } 163 ], 164 "desc": "<p><code>path</code> is the resolved path for the file for which a corresponding source map\nshould be fetched.</p>" 165 } 166 ], 167 "classes": [ 168 { 169 "textRaw": "Class: `module.SourceMap`", 170 "type": "class", 171 "name": "module.SourceMap", 172 "meta": { 173 "added": [ 174 "v13.7.0", 175 "v12.17.0" 176 ], 177 "changes": [] 178 }, 179 "properties": [ 180 { 181 "textRaw": "`payload` Returns: {Object}", 182 "type": "Object", 183 "name": "return", 184 "desc": "<p>Getter for the payload used to construct the <a href=\"#module_class_module_sourcemap\"><code>SourceMap</code></a> instance.</p>" 185 } 186 ], 187 "methods": [ 188 { 189 "textRaw": "`sourceMap.findEntry(lineNumber, columnNumber)`", 190 "type": "method", 191 "name": "findEntry", 192 "signatures": [ 193 { 194 "return": { 195 "textRaw": "Returns: {Object}", 196 "name": "return", 197 "type": "Object" 198 }, 199 "params": [ 200 { 201 "textRaw": "`lineNumber` {number}", 202 "name": "lineNumber", 203 "type": "number" 204 }, 205 { 206 "textRaw": "`columnNumber` {number}", 207 "name": "columnNumber", 208 "type": "number" 209 } 210 ] 211 } 212 ], 213 "desc": "<p>Given a line number and column number in the generated source file, returns\nan object representing the position in the original file. The object returned\nconsists of the following keys:</p>\n<ul>\n<li>generatedLine: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a></li>\n<li>generatedColumn: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a></li>\n<li>originalSource: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a></li>\n<li>originalLine: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a></li>\n<li>originalColumn: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a></li>\n<li>name: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a></li>\n</ul>" 214 } 215 ], 216 "signatures": [ 217 { 218 "params": [ 219 { 220 "textRaw": "`payload` {Object}", 221 "name": "payload", 222 "type": "Object" 223 } 224 ], 225 "desc": "<p>Creates a new <code>sourceMap</code> instance.</p>\n<p><code>payload</code> is an object with keys matching the <a href=\"https://sourcemaps.info/spec.html#h.mofvlxcwqzej\">Source map v3 format</a>:</p>\n<ul>\n<li><code>file</code>: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a></li>\n<li><code>version</code>: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\"><number></a></li>\n<li><code>sources</code>: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string[]></a></li>\n<li><code>sourcesContent</code>: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string[]></a></li>\n<li><code>names</code>: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string[]></a></li>\n<li><code>mappings</code>: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a></li>\n<li><code>sourceRoot</code>: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a></li>\n</ul>" 226 } 227 ] 228 } 229 ], 230 "type": "module", 231 "displayName": "Source map v3 support" 232 } 233 ], 234 "type": "module", 235 "displayName": "Modules: `module` API" 236 } 237 ] 238}