• Home
  • Raw
  • Download

Lines Matching +full:hook +full:- +full:run +full:- +full:in +full:- +full:context

3 <!--introduced_in=v8.5.0-->
4 <!-- type=misc -->
5 <!-- YAML
8 - version:
9 - v14.17.0
10 pr-url: https://github.com/nodejs/node/pull/35781
12 - version:
13 - v14.13.0
14 pr-url: https://github.com/nodejs/node/pull/35249
16 - version: v14.8.0
17 pr-url: https://github.com/nodejs/node/pull/34558
18 description: Unflag Top-Level Await.
19 - version:
20 - v14.0.0
21 - v13.14.0
22 pr-url: https://github.com/nodejs/node/pull/31974
24 - version:
25 - v13.2.0
26 - v12.17.0
27 pr-url: https://github.com/nodejs/node/pull/29866
28 description: Loading ECMAScript modules no longer requires a command-line flag.
29 - version: v12.0.0
30 pr-url: https://github.com/nodejs/node/pull/26745
34 -->
36 > Stability: 2 - Stable
40 <!--name=esm-->
71 <!-- Anchors to make sure old links find a target -->
78 <!-- type=misc -->
83 `--input-type` flag. See
87 <!-- Anchors to make sure old links find a target -->
112 e.g. `'path'` in `import { sep } from 'path'`. Specifiers are also used in
121 * _Bare specifiers_ like `'some-package'` or `'some-package/shuffle'`. They can
134 Like in CommonJS, module files within packages can be accessed by appending a
136 [`"exports"`][] field, in which case files within packages can only be accessed
137 via the paths defined in [`"exports"`][].
139 For details on these package resolution rules that apply to bare specifiers in
148 This behavior matches how `import` behaves in browser environments, assuming a
157 `'https://example.com/app.js'` is not supported natively in Node.js unless using
176 <!-- YAML
178 -->
183 * `application/json` for JSON (requires [`--experimental-json-modules`](cli.md#cli_experimental_jso…
184 * `application/wasm` for Wasm (requires [`--experimental-wasm-modules`](cli.md#cli_experimental_was…
201 <!-- YAML
203 - v14.13.1
204 - v12.20.0
206 - version: v14.18.0
207 pr-url: https://github.com/nodejs/node/pull/37246
209 -->
255 [Dynamic `import()`][] is supported in both CommonJS and ES modules. In CommonJS
269 This is defined exactly the same as it is in browsers providing the URL of the
280 <!--
282 - v13.9.0
283 - v12.16.2
285 - version: v14.18.0
286 pr-url: https://github.com/nodejs/node/pull/38587
288 -->
290 > Stability: 1 - Experimental
292 This feature is only available with the `--experimental-import-meta-resolve`
300 Provides a module-relative resolution function scoped to each module, returning
303 <!-- eslint-skip -->
305 const dependencyAsset = await import.meta.resolve('component-lib/asset.css');
311 <!-- eslint-skip -->
316 This function is asynchronous because the ES module resolver in Node.js is
324 `import` statements are permitted only in ES modules, but dynamic [`import()`][]
325 expressions are supported in CommonJS for loading ES modules.
347 <!-- eslint-disable no-duplicate-imports -->
352 // for `{ default as cjsSugar }` in the above import statement:
369 <!-- eslint-skip -->
379 For better compatibility with existing usage in the JS ecosystem, Node.js
380 in addition attempts to determine the CommonJS named exports of every imported
391 The preceding module supports named imports in ES modules:
393 <!-- eslint-disable no-duplicate-imports -->
416 always correctly detect named exports. In these cases, using the default
420 and build tool and transpiler outputs. See [cjs-module-lexer][] for the exact
427 In most cases, the ES module `import` can be used to load CommonJS modules.
434 These CommonJS variables are not available in ES modules.
442 `--experimental-json-modules` flag.
446 <!-- eslint-skip -->
478 hooks can provide this workflow in the future.
489 > Stability: 1 - Experimental
491 Currently importing JSON modules are only supported in the `commonjs` mode
494 additional flag `--experimental-json-modules` when running Node.js.
496 When the `--experimental-json-modules` flag is included, both the
499 support for named exports. A cache entry is created in the CommonJS
500 cache to avoid duplication. The same object is returned in
506 <!-- eslint-skip -->
511 The `--experimental-json-modules` flag is needed for the module
516 node --experimental-json-modules index.mjs # works
523 > Stability: 1 - Experimental
526 `--experimental-wasm-modules` flag, allowing any `.wasm` files to be
529 This integration is in line with the
542 node --experimental-wasm-modules index.mjs
549 ## Top-level `await`
551 <!-- YAML
553 -->
555 > Stability: 1 - Experimental
557 The `await` keyword may be used in the top level body of an ECMAScript module.
585 '--input-type=module',
586 '--eval',
587 // Never-resolving Promise:
598 > Stability: 1 - Experimental
602 <!-- type=misc -->
605 provided via a `--experimental-loader ./loader-name.mjs` argument to Node.js.
612 #### `resolve(specifier, context, defaultResolve)`
614 > Note: The loaders API is being redesigned. This hook may disappear or its
618 * `context` {Object}
625 The `resolve` hook returns the resolved file URL for a given module specifier
626 and parent URL. The module specifier is the string in an `import` statement or
630 The `conditions` property on the `context` is an array of conditions for
635 The current [package exports conditions][Conditional Exports] are always in
636 the `context.conditions` array passed into the hook. To guarantee _default
638 `context.conditions` array passed to it _must_ include _all_ elements of the
639 `context.conditions` array originally passed into the `resolve` hook.
647 * }} context
651 export async function resolve(specifier, context, defaultResolve) {
652 const { parentURL = null } = context;
663 // When calling `defaultResolve`, the arguments can be modified. In this
666 ...context,
667 conditions: [...context.conditions, 'another-condition'],
671 return defaultResolve(specifier, context, defaultResolve);
675 #### `getFormat(url, context, defaultGetFormat)`
677 > Note: The loaders API is being redesigned. This hook may disappear or its
681 * `context` {Object}
686 The `getFormat` hook provides a way to define a custom method of determining how
692 | ------------ | ------------------------------ | -------------------------------------------------…
699 Note: These types all correspond to classes defined in ECMAScript.
704 Note: If the source value of a text-based format (i.e., `'json'`, `'module'`) is
710 * @param {Object} context (currently empty)
714 export async function getFormat(url, context, defaultGetFormat) {
718 // format is one of the strings in the preceding table.
724 return defaultGetFormat(url, context, defaultGetFormat);
728 #### `getSource(url, context, defaultGetSource)`
730 > Note: The loaders API is being redesigned. This hook may disappear or its
734 * `context` {Object}
740 The `getSource` hook provides a way to define a custom method for retrieving
747 * @param {{ format: string }} context
751 export async function getSource(url, context, defaultGetSource) {
752 const { format } = context;
761 return defaultGetSource(url, context, defaultGetSource);
765 #### `transformSource(source, context, defaultTransformSource)`
767 > Note: The loaders API is being redesigned. This hook may disappear or its
771 * `context` {Object}
777 The `transformSource` hook provides a way to modify the source code of a loaded
781 If this hook is used to convert unknown-to-Node.js file types into executable
782 JavaScript, a resolve hook is also necessary in order to register any
783 unknown-to-Node.js file extensions. See the [transpiler loader example][] below.
791 * }} context
795 export async function transformSource(source, context, defaultTransformSource) {
796 const { url, format } = context;
805 return defaultTransformSource(source, context, defaultTransformSource);
811 > Note: The loaders API is being redesigned. This hook may disappear or its
816 Sometimes it might be necessary to run some code inside of the same global scope
817 that the application runs in. This hook allows the return of a string that is
818 run as sloppy-mode script on startup.
820 Similar to how CommonJS wrappers work, the code runs in an implicit function
821 scope. The only argument is a `require`-like function that can be used to load
829 * @returns {string} Code to run before application startup
846 The various loader hooks can be used together to accomplish wide-ranging
851 In current Node.js, specifiers starting with `https://` are unsupported. The
859 // https-loader.mjs
862 export function resolve(specifier, context, defaultResolve) {
863 const { parentURL = null } = context;
866 // this hook intercepts them and converts them into absolute URLs to be
879 return defaultResolve(specifier, context, defaultResolve);
882 export function getFormat(url, context, defaultGetFormat) {
883 // This loader assumes all network-provided JavaScript is ES module code.
891 return defaultGetFormat(url, context, defaultGetFormat);
894 export function getSource(url, context, defaultGetSource) {
908 return defaultGetSource(url, context, defaultGetSource);
914 import { VERSION } from 'https://coffeescript.org/browser-compiler-modern/coffeescript.js';
920 `node --experimental-loader ./https-loader.mjs ./main.mjs`
921 prints the current version of CoffeeScript per the module at the URL in
926 Sources that are in formats Node.js doesn’t understand can be converted into
927 JavaScript using the [`transformSource` hook][]. Before that hook gets called,
936 // coffeescript-loader.mjs
942 // CoffeeScript files end in .coffee, .litcoffee or .coffee.md.
945 export function resolve(specifier, context, defaultResolve) {
946 const { parentURL = baseURL } = context;
949 // specifiers ending in the CoffeeScript file extensions.
957 return defaultResolve(specifier, context, defaultResolve);
960 export function getFormat(url, context, defaultGetFormat) {
971 return defaultGetFormat(url, context, defaultGetFormat);
974 export function transformSource(source, context, defaultTransformSource) {
975 const { url, format } = context;
984 return defaultTransformSource(source, context, defaultTransformSource);
999 export scream = (str) -> str.toUpperCase()
1003 `node --experimental-loader ./coffeescript-loader.mjs main.coffee`
1015 * FileURL-based resolution as is used by ES modules
1032 legacy CommonJS loader. Additional formats such as _"addon"_ can be extended in
1035 In the following algorithms, all subroutine errors are propagated as errors
1036 of these top-level routines unless stated otherwise.
1049 subpath in the package for the given module.
1128 > 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
1180 > 1. If _pjson.imports_ is a non-null Object, then
1191 > 1. If _matchKey_ is a key of _matchObj_ and does not end in _"/"_ or contain
1197 > 1. Let _expansionKeys_ be the list of keys of _matchObj_ either ending in
1199 > **PATTERN_KEY_COMPARE** which orders in descending order of specificity.
1200 > 1. For each key _expansionKey_ in _expansionKeys_, do
1234 > 1. Let _baseLengthA_ be the index of _"*"_ in _keyA_ plus one, if _keyA_
1236 > 1. Let _baseLengthB_ be the index of _"*"_ in _keyB_ plus one, if _keyB_
1238 > 1. If _baseLengthA_ is greater than _baseLengthB_, return -1.
1241 > 1. If _keyB_ does not contain _"*"_, return -1.
1242 > 1. If the length of _keyA_ is greater than the length of _keyB_, return -1.
1250 > 1. If _pattern_ is **false**, _subpath_ has non-zero length and _target_
1266 > 1. Assert: _resolvedTarget_ is contained in _packageURL_.
1275 > 1. Otherwise, if _target_ is a non-null Object, then
1276 > 1. If _exports_ contains any index property keys, as defined in ECMA-262
1278 > 1. For each property _p_ of _target_, in object insertion order as,
1281 > 1. Let _targetValue_ be the value of the _p_ property in _target_.
1290 > 1. For each item _targetValue_ in _target_, do
1305 > 1. If _url_ ends in _".mjs"_, then
1307 > 1. If _url_ ends in _".cjs"_, then
1310 > 1. If _url_ ends in _".js"_, then
1321 > 1. If _scopeURL_ ends in a _"node_modules"_ path segment, return **null**.
1338 > Stability: 1 - Experimental
1345 The `--experimental-specifier-resolution=[mode]` flag can be used to customize
1356 $ node --experimental-specifier-resolution=node index
1360 <!-- Note: The cjs-module-lexer link should be kept in-sync with the deps version -->
1361 [6.1.7 Array Index]: https://tc39.es/ecma262/#integer-index
1365 [Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statem…
1366 [ES Module Integration Proposal for Web Assembly]: https://github.com/webassembly/esm-integration
1370 [WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script
1373 [`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/A…
1374 [`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Obj…
1375 [`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Ty…
1376 [`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Ui…
1377 [`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
1378 [`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
1382 [`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
1387 [`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
1388 [`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource
1390 [cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.2.2
1392 [special scheme]: https://url.spec.whatwg.org/#special-scheme
1394 [the official standard format]: https://tc39.github.io/ecma262/#sec-modules