237 lines
13 KiB
JSON
237 lines
13 KiB
JSON
{
|
|
"type": "module",
|
|
"source": "doc/api/module.md",
|
|
"modules": [
|
|
{
|
|
"textRaw": "Modules: `module` API",
|
|
"name": "modules:_`module`_api",
|
|
"introduced_in": "v0.3.7",
|
|
"modules": [
|
|
{
|
|
"textRaw": "The `Module` object",
|
|
"name": "the_`module`_object",
|
|
"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>",
|
|
"properties": [
|
|
{
|
|
"textRaw": "`builtinModules` {string[]}",
|
|
"type": "string[]",
|
|
"name": "builtinModules",
|
|
"meta": {
|
|
"added": [
|
|
"v9.3.0",
|
|
"v8.10.0",
|
|
"v6.13.0"
|
|
],
|
|
"changes": []
|
|
},
|
|
"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_cjs.html#modules_cjs_the_module_wrapper\">module wrapper</a>. To access it, require the <code>Module</code> module:</p>\n<pre><code class=\"language-js\">// module.mjs\n// In an ECMAScript module\nimport { builtinModules as builtin } from 'module';\n</code></pre>\n<pre><code class=\"language-js\">// module.cjs\n// In a CommonJS module\nconst builtin = require('module').builtinModules;\n</code></pre>"
|
|
}
|
|
],
|
|
"methods": [
|
|
{
|
|
"textRaw": "`module.createRequire(filename)`",
|
|
"type": "method",
|
|
"name": "createRequire",
|
|
"meta": {
|
|
"added": [
|
|
"v12.2.0"
|
|
],
|
|
"changes": []
|
|
},
|
|
"signatures": [
|
|
{
|
|
"return": {
|
|
"textRaw": "Returns: {require} Require function",
|
|
"name": "return",
|
|
"type": "require",
|
|
"desc": "Require function"
|
|
},
|
|
"params": [
|
|
{
|
|
"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.",
|
|
"name": "filename",
|
|
"type": "string|URL",
|
|
"desc": "Filename to be used to construct the require function. Must be a file URL object, file URL string, or absolute path string."
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"desc": "<pre><code class=\"language-js\">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>"
|
|
},
|
|
{
|
|
"textRaw": "`module.createRequireFromPath(filename)`",
|
|
"type": "method",
|
|
"name": "createRequireFromPath",
|
|
"meta": {
|
|
"added": [
|
|
"v10.12.0"
|
|
],
|
|
"deprecated": [
|
|
"v12.2.0"
|
|
],
|
|
"changes": []
|
|
},
|
|
"stability": 0,
|
|
"stabilityText": "Deprecated: Please use [`createRequire()`][] instead.",
|
|
"signatures": [
|
|
{
|
|
"return": {
|
|
"textRaw": "Returns: {require} Require function",
|
|
"name": "return",
|
|
"type": "require",
|
|
"desc": "Require function"
|
|
},
|
|
"params": [
|
|
{
|
|
"textRaw": "`filename` {string} Filename to be used to construct the relative require function.",
|
|
"name": "filename",
|
|
"type": "string",
|
|
"desc": "Filename to be used to construct the relative require function."
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"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>"
|
|
},
|
|
{
|
|
"textRaw": "`module.syncBuiltinESMExports()`",
|
|
"type": "method",
|
|
"name": "syncBuiltinESMExports",
|
|
"meta": {
|
|
"added": [
|
|
"v12.12.0"
|
|
],
|
|
"changes": []
|
|
},
|
|
"signatures": [
|
|
{
|
|
"params": []
|
|
}
|
|
],
|
|
"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 { syncBuiltinESMExports } = require('module');\n\nfs.readFile = null;\n\ndelete fs.readFileSync;\n\nfs.newAPI = function newAPI() {\n // ...\n};\n\nsyncBuiltinESMExports();\n\nimport('fs').then((esmFS) => {\n assert.strictEqual(esmFS.readFile, null);\n assert.strictEqual('readFileSync' in fs, true);\n assert.strictEqual(esmFS.newAPI, undefined);\n});\n</code></pre>"
|
|
}
|
|
],
|
|
"type": "module",
|
|
"displayName": "The `Module` object"
|
|
},
|
|
{
|
|
"textRaw": "Source map v3 support",
|
|
"name": "source_map_v3_support",
|
|
"meta": {
|
|
"added": [
|
|
"v13.7.0",
|
|
"v12.17.0"
|
|
],
|
|
"changes": []
|
|
},
|
|
"stability": 1,
|
|
"stabilityText": "Experimental",
|
|
"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-js\">// module.mjs\n// In an ECMAScript module\nimport { findSourceMap, SourceMap } from 'module';\n</code></pre>\n<pre><code class=\"language-js\">// module.cjs\n// In a CommonJS module\nconst { findSourceMap, SourceMap } = require('module');\n</code></pre>",
|
|
"methods": [
|
|
{
|
|
"textRaw": "`module.findSourceMap(path[, error])`",
|
|
"type": "method",
|
|
"name": "findSourceMap",
|
|
"meta": {
|
|
"added": [
|
|
"v13.7.0",
|
|
"v12.17.0"
|
|
],
|
|
"changes": []
|
|
},
|
|
"signatures": [
|
|
{
|
|
"return": {
|
|
"textRaw": "Returns: {module.SourceMap}",
|
|
"name": "return",
|
|
"type": "module.SourceMap"
|
|
},
|
|
"params": [
|
|
{
|
|
"textRaw": "`path` {string}",
|
|
"name": "path",
|
|
"type": "string"
|
|
},
|
|
{
|
|
"textRaw": "`error` {Error}",
|
|
"name": "error",
|
|
"type": "Error"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"desc": "<p><code>path</code> is the resolved path for the file for which a corresponding source map\nshould be fetched.</p>\n<p>The <code>error</code> instance should be passed as the second parameter to <code>findSourceMap</code>\nin exceptional flows, such as when an overridden\n<a href=\"https://v8.dev/docs/stack-trace-api#customizing-stack-traces\"><code>Error.prepareStackTrace(error, trace)</code></a> is invoked. Modules are not added to\nthe module cache until they are successfully loaded. In these cases, source maps\nare associated with the <code>error</code> instance along with the <code>path</code>.</p>"
|
|
}
|
|
],
|
|
"classes": [
|
|
{
|
|
"textRaw": "Class: `module.SourceMap`",
|
|
"type": "class",
|
|
"name": "module.SourceMap",
|
|
"meta": {
|
|
"added": [
|
|
"v13.7.0",
|
|
"v12.17.0"
|
|
],
|
|
"changes": []
|
|
},
|
|
"properties": [
|
|
{
|
|
"textRaw": "`payload` Returns: {Object}",
|
|
"type": "Object",
|
|
"name": "return",
|
|
"desc": "<p>Getter for the payload used to construct the <a href=\"#module_class_module_sourcemap\"><code>SourceMap</code></a> instance.</p>"
|
|
}
|
|
],
|
|
"methods": [
|
|
{
|
|
"textRaw": "`sourceMap.findEntry(lineNumber, columnNumber)`",
|
|
"type": "method",
|
|
"name": "findEntry",
|
|
"signatures": [
|
|
{
|
|
"return": {
|
|
"textRaw": "Returns: {Object}",
|
|
"name": "return",
|
|
"type": "Object"
|
|
},
|
|
"params": [
|
|
{
|
|
"textRaw": "`lineNumber` {number}",
|
|
"name": "lineNumber",
|
|
"type": "number"
|
|
},
|
|
{
|
|
"textRaw": "`columnNumber` {number}",
|
|
"name": "columnNumber",
|
|
"type": "number"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"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</ul>"
|
|
}
|
|
],
|
|
"signatures": [
|
|
{
|
|
"params": [
|
|
{
|
|
"textRaw": "`payload` {Object}",
|
|
"name": "payload",
|
|
"type": "Object"
|
|
}
|
|
],
|
|
"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>"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"type": "module",
|
|
"displayName": "Source map v3 support"
|
|
}
|
|
],
|
|
"type": "module",
|
|
"displayName": "Modules: `module` API"
|
|
}
|
|
]
|
|
} |