@@ -1134,25 +1134,26 @@ condition list **must** be passed through to the `defaultResolve` function.
1134
1134
```js
1135
1135
/**
1136
1136
* @param {string} specifier
1137
- * @param {object} context
1138
- * @param {string} context. parentURL
1139
- * @param {string[]} context. conditions
1140
- * @param {function} defaultResolve
1141
- * @returns {object} response
1142
- * @returns {string} response. url
1137
+ * @param {{
1138
+ * parentURL: !(string | undefined),
1139
+ * conditions: !(Array<string>),
1140
+ * }} context
1141
+ * @param {Function} defaultResolve
1142
+ * @returns {!(Promise<{ url: string }>)}
1143
1143
*/
1144
1144
export async function resolve (specifier , context , defaultResolve ) {
1145
1145
const { parentURL = null } = context ;
1146
- if (someCondition) {
1146
+ if (Math . random () > 0.5 ) { // Some condition.
1147
1147
// For some or all specifiers, do some custom logic for resolving.
1148
- // Always return an object of the form {url: <string>}
1148
+ // Always return an object of the form {url: <string>}.
1149
1149
return {
1150
- url: (parentURL) ?
1151
- new URL (specifier, parentURL).href : new URL (specifier).href
1150
+ url: parentURL ?
1151
+ new URL (specifier, parentURL).href :
1152
+ new URL (specifier).href ,
1152
1153
};
1153
1154
}
1154
- if (anotherCondition) {
1155
- // When calling the defaultResolve, the arguments can be modified. In this
1155
+ if (Math . random () < 0.5 ) { // Another condition.
1156
+ // When calling ` defaultResolve` , the arguments can be modified. In this
1156
1157
// case it's adding another value for matching conditional exports.
1157
1158
return defaultResolve (specifier, {
1158
1159
... context,
@@ -1195,18 +1196,17 @@ not a string, it will be converted to a string using [`util.TextDecoder`][].
1195
1196
` ` ` js
1196
1197
/**
1197
1198
* @param {string} url
1198
- * @param {object} context (currently empty)
1199
- * @param {function} defaultGetFormat
1200
- * @returns {object} response
1201
- * @returns {string} response.format
1199
+ * @param {Object} context (currently empty)
1200
+ * @param {Function} defaultGetFormat
1201
+ * @returns {Promise<{ format: string }>}
1202
1202
*/
1203
1203
export async function getFormat (url , context , defaultGetFormat ) {
1204
- if (someCondition) {
1204
+ if (Math . random () > 0.5 ) { // Some condition.
1205
1205
// For some or all URLs, do some custom logic for determining format.
1206
1206
// Always return an object of the form {format: <string>}, where the
1207
1207
// format is one of the strings in the table above.
1208
1208
return {
1209
- format: ' module'
1209
+ format: ' module' ,
1210
1210
};
1211
1211
}
1212
1212
// Defer to Node.js for all other URLs.
@@ -1226,19 +1226,17 @@ potentially avoid reading files from disk.
1226
1226
` ` ` js
1227
1227
/**
1228
1228
* @param {string} url
1229
- * @param {object} context
1230
- * @param {string} context.format
1231
- * @param {function} defaultGetSource
1232
- * @returns {object} response
1233
- * @returns {string|buffer} response.source
1229
+ * @param {{ format: string }} context
1230
+ * @param {Function} defaultGetSource
1231
+ * @returns {Promise<{ source: !(SharedArrayBuffer | string | Uint8Array) }>}
1234
1232
*/
1235
1233
export async function getSource (url , context , defaultGetSource ) {
1236
1234
const { format } = context;
1237
- if (someCondition) {
1235
+ if (Math . random () > 0.5 ) { // Some condition.
1238
1236
// For some or all URLs, do some custom logic for retrieving the source.
1239
1237
// Always return an object of the form {source: <string|buffer>}.
1240
1238
return {
1241
- source: ' ...'
1239
+ source: ' ...' ,
1242
1240
};
1243
1241
}
1244
1242
// Defer to Node.js for all other URLs.
@@ -1265,28 +1263,25 @@ unknown-to-Node.js file extensions. See the [transpiler loader example][] below.
1265
1263
1266
1264
` ` ` js
1267
1265
/**
1268
- * @param {string|buffer } source
1269
- * @param {object} context
1270
- * @param {string} context. url
1271
- * @param {string} context. format
1272
- * @param {function} defaultTransformSource
1273
- * @returns {object} response
1274
- * @returns {string|buffer} response.source
1266
+ * @param {!(SharedArrayBuffer | string | Uint8Array) } source
1267
+ * @param {{
1268
+ * url: string,
1269
+ * format: string,
1270
+ * }} context
1271
+ * @param {Function} defaultTransformSource
1272
+ * @returns {Promise<{ source: !(SharedArrayBuffer | string | Uint8Array) }>}
1275
1273
*/
1276
- export async function transformSource (source ,
1277
- context ,
1278
- defaultTransformSource ) {
1274
+ export async function transformSource (source , context , defaultTransformSource ) {
1279
1275
const { url , format } = context;
1280
- if (someCondition) {
1276
+ if (Math . random () > 0.5 ) { // Some condition.
1281
1277
// For some or all URLs, do some custom logic for modifying the source.
1282
1278
// Always return an object of the form {source: <string|buffer>}.
1283
1279
return {
1284
- source: ' ...'
1280
+ source: ' ...' ,
1285
1281
};
1286
1282
}
1287
1283
// Defer to Node.js for all other sources.
1288
- return defaultTransformSource (
1289
- source, context, defaultTransformSource);
1284
+ return defaultTransformSource (source, context, defaultTransformSource);
1290
1285
}
1291
1286
` ` `
1292
1287
0 commit comments