| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent befbaf3 commit 44e6c01
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1184,11 +1184,19 @@ CommonJS modules loaded. | |||
| 1184 | 1184 | ||
| 1185 | 1185 | ### Hooks | |
| 1186 | 1186 | ||
| 1187 | - #### <code>resolve</code> hook | ||
| 1187 | + #### `resolve(specifier, context, defaultResolve)` | ||
| 1188 | 1188 | ||
| 1189 | 1189 | > Note: The loaders API is being redesigned. This hook may disappear or its | |
| 1190 | 1190 | > signature may change. Do not rely on the API described below. | |
| 1191 | 1191 | ||
| 1192 | + * `specifier` {string} | ||
| 1193 | + * `context` {Object} | ||
| 1194 | + * `conditions` {string[]} | ||
| 1195 | + * `parentURL` {string} | ||
| 1196 | + * `defaultResolve` {Function} | ||
| 1197 | + * Returns: {Object} | ||
| 1198 | + * `url` {string} | ||
| 1199 | + | ||
| 1192 | 1200 | The `resolve` hook returns the resolved file URL for a given module specifier | |
| 1193 | 1201 | and parent URL. The module specifier is the string in an `import` statement or | |
| 1194 | 1202 | `import()` expression, and the parent URL is the URL of the module that imported | |
@@ -1209,11 +1217,11 @@ Node.js module specifier resolution behavior_ when calling `defaultResolve`, the | |||
| 1209 | 1217 | /** | |
| 1210 | 1218 | * @param {string} specifier | |
| 1211 | 1219 | * @param {{ | |
| 1220 | + * conditions: !Array<string>, | ||
| 1212 | 1221 | * parentURL: !(string | undefined), | |
| 1213 | - * conditions: !(Array<string>), | ||
| 1214 | 1222 | * }} context | |
| 1215 | 1223 | * @param {Function} defaultResolve | |
| 1216 | - * @returns {!(Promise<{ url: string }>)} | ||
| 1224 | + * @returns {Promise<{ url: string }>} | ||
| 1217 | 1225 | */ | |
| 1218 | 1226 | export async function resolve(specifier, context, defaultResolve) { | |
| 1219 | 1227 | const { parentURL = null } = context; | |
@@ -1239,29 +1247,34 @@ export async function resolve(specifier, context, defaultResolve) { | |||
| 1239 | 1247 | } | |
| 1240 | 1248 | ``` | |
| 1241 | 1249 | ||
| 1242 | - #### <code>getFormat</code> hook | ||
| 1250 | + #### `getFormat(url, context, defaultGetFormat)` | ||
| 1243 | 1251 | ||
| 1244 | 1252 | > Note: The loaders API is being redesigned. This hook may disappear or its | |
| 1245 | 1253 | > signature may change. Do not rely on the API described below. | |
| 1246 | 1254 | ||
| 1255 | + * `url` {string} | ||
| 1256 | + * `context` {Object} | ||
| 1257 | + * `defaultGetFormat` {Function} | ||
| 1258 | + * Returns: {Object} | ||
| 1259 | + * `format` {string} | ||
| 1260 | + | ||
| 1247 | 1261 | The `getFormat` hook provides a way to define a custom method of determining how | |
| 1248 | 1262 | a URL should be interpreted. The `format` returned also affects what the | |
| 1249 | 1263 | acceptable forms of source values are for a module when parsing. This can be one | |
| 1250 | 1264 | of the following: | |
| 1251 | 1265 | ||
| 1252 | - | `format` | Description | Acceptable Types For `source` Returned by `getSource` or `transformSource` | | ||
| 1253 | - | --- | --- | --- | | ||
| 1254 | - | `'builtin'` | Load a Node.js builtin module | Not applicable | | ||
| 1255 | - | `'commonjs'` | Load a Node.js CommonJS module | Not applicable | | ||
| 1256 | - | `'json'` | Load a JSON file | { [ArrayBuffer][], [string][], [TypedArray][] } | | ||
| 1257 | - | `'module'` | Load an ES module | { [ArrayBuffer][], [string][], [TypedArray][] } | | ||
| 1258 | - | `'wasm'` | Load a WebAssembly module | { [ArrayBuffer][], [string][], [TypedArray][] } | | ||
| 1266 | + | `format` | Description | Acceptable Types For `source` Returned by `getSource` or `transformSource` | | ||
| 1267 | + | ------------ | ------------------------------ | -------------------------------------------------------------------------- | | ||
| 1268 | + | `'builtin'` | Load a Node.js builtin module | Not applicable | | ||
| 1269 | + | `'commonjs'` | Load a Node.js CommonJS module | Not applicable | | ||
| 1270 | + | `'json'` | Load a JSON file | { [`string`][], [`ArrayBuffer`][], [`TypedArray`][] } | | ||
| 1271 | + | `'module'` | Load an ES module | { [`string`][], [`ArrayBuffer`][], [`TypedArray`][] } | | ||
| 1272 | + | `'wasm'` | Load a WebAssembly module | { [`ArrayBuffer`][], [`TypedArray`][] } | | ||
| 1259 | 1273 | ||
| 1260 | 1274 | Note: These types all correspond to classes defined in ECMAScript. | |
| 1261 | 1275 | ||
| 1262 | - * The specific [ArrayBuffer][] object is a [SharedArrayBuffer][]. | ||
| 1263 | - * The specific [string][] object is not the class constructor, but an instance. | ||
| 1264 | - * The specific [TypedArray][] object is a [Uint8Array][]. | ||
| 1276 | + * The specific [`ArrayBuffer`][] object is a [`SharedArrayBuffer`][]. | ||
| 1277 | + * The specific [`TypedArray`][] object is a [`Uint8Array`][]. | ||
| 1265 | 1278 | ||
| 1266 | 1279 | Note: If the source value of a text-based format (i.e., `'json'`, `'module'`) is | |
| 1267 | 1280 | not a string, it will be converted to a string using [`util.TextDecoder`][]. | |
@@ -1287,11 +1300,18 @@ export async function getFormat(url, context, defaultGetFormat) { | |||
| 1287 | 1300 | } | |
| 1288 | 1301 | ``` | |
| 1289 | 1302 | ||
| 1290 | - #### <code>getSource</code> hook | ||
| 1303 | + #### `getSource(url, context, defaultGetSource)` | ||
| 1291 | 1304 | ||
| 1292 | 1305 | > Note: The loaders API is being redesigned. This hook may disappear or its | |
| 1293 | 1306 | > signature may change. Do not rely on the API described below. | |
| 1294 | 1307 | ||
| 1308 | + * `url` {string} | ||
| 1309 | + * `context` {Object} | ||
| 1310 | + * `format` {string} | ||
| 1311 | + * `defaultGetSource` {Function} | ||
| 1312 | + * Returns: {Object} | ||
| 1313 | + * `source` {string|SharedArrayBuffer|Uint8Array} | ||
| 1314 | + | ||
| 1295 | 1315 | The `getSource` hook provides a way to define a custom method for retrieving | |
| 1296 | 1316 | the source code of an ES module specifier. This would allow a loader to | |
| 1297 | 1317 | potentially avoid reading files from disk. | |
@@ -1301,7 +1321,7 @@ potentially avoid reading files from disk. | |||
| 1301 | 1321 | * @param {string} url | |
| 1302 | 1322 | * @param {{ format: string }} context | |
| 1303 | 1323 | * @param {Function} defaultGetSource | |
| 1304 | - * @returns {Promise<{ source: !(SharedArrayBuffer | string | Uint8Array) }>} | ||
| 1324 | + * @returns {Promise<{ source: !(string | SharedArrayBuffer | Uint8Array) }>} | ||
| 1305 | 1325 | */ | |
| 1306 | 1326 | export async function getSource(url, context, defaultGetSource) { | |
| 1307 | 1327 | const { format } = context; | |
@@ -1317,11 +1337,18 @@ export async function getSource(url, context, defaultGetSource) { | |||
| 1317 | 1337 | } | |
| 1318 | 1338 | ``` | |
| 1319 | 1339 | ||
| 1320 | - #### <code>transformSource</code> hook | ||
| 1340 | + #### `transformSource(source, context, defaultTransformSource)` | ||
| 1321 | 1341 | ||
| 1322 | 1342 | > Note: The loaders API is being redesigned. This hook may disappear or its | |
| 1323 | 1343 | > signature may change. Do not rely on the API described below. | |
| 1324 | 1344 | ||
| 1345 | + * `source` {string|SharedArrayBuffer|Uint8Array} | ||
| 1346 | + * `context` {Object} | ||
| 1347 | + * `format` {string} | ||
| 1348 | + * `url` {string} | ||
| 1349 | + * Returns: {Object} | ||
| 1350 | + * `source` {string|SharedArrayBuffer|Uint8Array} | ||
| 1351 | + | ||
| 1325 | 1352 | The `transformSource` hook provides a way to modify the source code of a loaded | |
| 1326 | 1353 | ES module file after the source string has been loaded but before Node.js has | |
| 1327 | 1354 | done anything with it. | |
@@ -1332,13 +1359,13 @@ unknown-to-Node.js file extensions. See the [transpiler loader example][] below. | |||
| 1332 | 1359 | ||
| 1333 | 1360 | ```js | |
| 1334 | 1361 | /** | |
| 1335 | - * @param {!(SharedArrayBuffer | string | Uint8Array)} source | ||
| 1362 | + * @param {!(string | SharedArrayBuffer | Uint8Array)} source | ||
| 1336 | 1363 | * @param {{ | |
| 1337 | - * url: string, | ||
| 1338 | 1364 | * format: string, | |
| 1365 | + * url: string, | ||
| 1339 | 1366 | * }} context | |
| 1340 | 1367 | * @param {Function} defaultTransformSource | |
| 1341 | - * @returns {Promise<{ source: !(SharedArrayBuffer | string | Uint8Array) }>} | ||
| 1368 | + * @returns {Promise<{ source: !(string | SharedArrayBuffer | Uint8Array) }>} | ||
| 1342 | 1369 | */ | |
| 1343 | 1370 | export async function transformSource(source, context, defaultTransformSource) { | |
| 1344 | 1371 | const { url, format } = context; | |
@@ -1354,11 +1381,13 @@ export async function transformSource(source, context, defaultTransformSource) { | |||
| 1354 | 1381 | } | |
| 1355 | 1382 | ``` | |
| 1356 | 1383 | ||
| 1357 | - #### <code>getGlobalPreloadCode</code> hook | ||
| 1384 | + #### `getGlobalPreloadCode()` | ||
| 1358 | 1385 | ||
| 1359 | 1386 | > Note: The loaders API is being redesigned. This hook may disappear or its | |
| 1360 | 1387 | > signature may change. Do not rely on the API described below. | |
| 1361 | 1388 | ||
| 1389 | + * Returns: {string} | ||
| 1390 | + | ||
| 1362 | 1391 | Sometimes it can be necessary to run some code inside of the same global scope | |
| 1363 | 1392 | that the application will run in. This hook allows to return a string that will | |
| 1364 | 1393 | be ran as sloppy-mode script on startup. | |
@@ -1909,12 +1938,12 @@ success! | |||
| 1909 | 1938 | [`import`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import | |
| 1910 | 1939 | [`module.createRequire()`]: modules.html#modules_module_createrequire_filename | |
| 1911 | 1940 | [`module.syncBuiltinESMExports()`]: modules.html#modules_module_syncbuiltinesmexports | |
| 1912 | - [`transformSource` hook]: #esm_code_transformsource_code_hook | ||
| 1913 | - [ArrayBuffer]: https://www.ecma-international.org/ecma-262/6.0/#sec-arraybuffer-constructor | ||
| 1914 | - [SharedArrayBuffer]: https://tc39.es/ecma262/#sec-sharedarraybuffer-constructor | ||
| 1915 | - [string]: https://www.ecma-international.org/ecma-262/6.0/#sec-string-constructor | ||
| 1916 | - [TypedArray]: https://www.ecma-international.org/ecma-262/6.0/#sec-typedarray-objects | ||
| 1917 | - [Uint8Array]: https://www.ecma-international.org/ecma-262/6.0/#sec-uint8array | ||
| 1941 | + [`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource | ||
| 1942 | + [`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ||
| 1943 | + [`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer | ||
| 1944 | + [`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String | ||
| 1945 | + [`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
| 1946 | + [`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array | ||
| 1918 | 1947 | [`util.TextDecoder`]: util.html#util_class_util_textdecoder | |
| 1919 | 1948 | [import an ES or CommonJS module for its side effects only]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Import_a_module_for_its_side_effects_only | |
| 1920 | 1949 | [special scheme]: https://url.spec.whatwg.org/#special-scheme | |
| Back | FazBrowse Home | New Git URL |
0 commit comments