bare-module 4.7.0 → 4.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +265 -47
- package/binding.c +17 -17
- package/index.js +245 -127
- package/lib/errors.js +33 -13
- package/lib/protocol.js +9 -9
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -10,11 +10,11 @@ npm i bare-module
|
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
12
|
const Module = require('bare-module')
|
|
13
|
-
|
|
13
|
+
```
|
|
14
14
|
|
|
15
15
|
## Packages
|
|
16
16
|
|
|
17
|
-
A package is directory with a `package.json` file.
|
|
17
|
+
A package is a directory with a `package.json` file.
|
|
18
18
|
|
|
19
19
|
### Fields
|
|
20
20
|
|
|
@@ -77,7 +77,7 @@ When importing the package by name, `require('my-package')` will resolve to `<mo
|
|
|
77
77
|
|
|
78
78
|
##### Conditional exports
|
|
79
79
|
|
|
80
|
-
Conditional exports allow packages to provide different exports for different conditions, such as the
|
|
80
|
+
Conditional exports allow packages to provide different exports for different conditions, such as the loading method the importing module uses (e.g. `require()` vs `import`):
|
|
81
81
|
|
|
82
82
|
```json
|
|
83
83
|
{
|
|
@@ -121,16 +121,33 @@ To provide a fallback for when no other conditions match, the `"default"` condit
|
|
|
121
121
|
|
|
122
122
|
The following conditions are supported, listed in order from most specific to least specific as conditions should be defined:
|
|
123
123
|
|
|
124
|
-
Condition
|
|
125
|
-
|
|
126
|
-
`"
|
|
127
|
-
`"
|
|
128
|
-
`"
|
|
129
|
-
`"
|
|
130
|
-
`"
|
|
131
|
-
`"
|
|
132
|
-
`"
|
|
133
|
-
`"
|
|
124
|
+
| Condition | Description |
|
|
125
|
+
| :------------- | :---------------------------------------------------------------------------------------------------------------------------------- |
|
|
126
|
+
| `"import"` | Matches when the package is loaded via `import` or `import()`. |
|
|
127
|
+
| `"require"` | Matches when the package is loaded via `require()`. |
|
|
128
|
+
| `"asset"` | Matches when the package is loaded via `require.asset()`. |
|
|
129
|
+
| `"addon"` | Matches when the package is loaded via `require.addon()`. |
|
|
130
|
+
| `"bare"` | Matches for any [Bare](https://github.com/holepunchto/bare) environment. |
|
|
131
|
+
| `"node"` | Matches for any Node.js environment. |
|
|
132
|
+
| `"<platform>"` | Matches when equal to `Bare.platform`. See [`Bare.platform`](https://github.com/holepunchto/bare#bareplatform) for possible values. |
|
|
133
|
+
| `"<arch>"` | Matches when equal to `Bare.arch`. See [`Bare.arch`](https://github.com/holepunchto/bare#barearch) for possible values. |
|
|
134
|
+
| `"simulator"` | Matches when Bare was compiled for a simulator, i.e. when `Bare.simulator` is `true`. |
|
|
135
|
+
| `"default"` | The fallback that always matches. This condition should always be last. |
|
|
136
|
+
|
|
137
|
+
Export conditions are evaluated in the order they are defined in the `"exports"` field. This means that less specific conditionals defined first will override more specific conditions define later. For example, the following will always call `./fallback.js` because `"default"` always matches and is defined first.
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"exports": {
|
|
142
|
+
".": {
|
|
143
|
+
"default": "./fallback.js",
|
|
144
|
+
"bare": "./bare.js"
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
This is why the general rule is that conditions should be from most specific to least specific when defined.
|
|
134
151
|
|
|
135
152
|
##### Self-referencing
|
|
136
153
|
|
|
@@ -160,11 +177,74 @@ If a package defines only a single export, `"."`, it may leave out the subpath e
|
|
|
160
177
|
|
|
161
178
|
#### `"imports"`
|
|
162
179
|
|
|
180
|
+
A private mapping for import specifiers within the package itself. Similar to `"exports"`, the `"imports"` field can be used to conditional import other packages within the package. But unlike `"exports"`, `"imports"` permits mapping to external packages.
|
|
181
|
+
|
|
182
|
+
The rules are otherwise analogous to the [`"exports"`](#conditional-exports) field.
|
|
183
|
+
|
|
163
184
|
##### Subpath imports
|
|
164
185
|
|
|
186
|
+
Just like exports, subpaths can be used when importing a module internally.
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"imports": {
|
|
191
|
+
".": "./index.js",
|
|
192
|
+
"./submodule": "./lib/submodule.js"
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
165
197
|
##### Conditional imports
|
|
166
198
|
|
|
167
|
-
|
|
199
|
+
Adding conditional imports allows importing different packages based on the configured conditions. As an example:
|
|
200
|
+
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"imports": {
|
|
204
|
+
"bar": {
|
|
205
|
+
"require": "./baz.cjs",
|
|
206
|
+
"import": "./baz.mjs"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
When importing the package `bar` as `require('bar')` will resolve to `./baz.cjs`, but when importing with `import('bar')` will resolve to `./baz.mjs`.
|
|
213
|
+
|
|
214
|
+
To provide a fallback for when no other conditions are met, the `"default"` condition can be configured like so:
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{
|
|
218
|
+
"imports": {
|
|
219
|
+
"bar": {
|
|
220
|
+
"require": "./baz.cjs",
|
|
221
|
+
"asset": "./baz.txt",
|
|
222
|
+
"default": "./baz.mjs"
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
The following conditions are supported, listed in order from most specific to least specific as conditions should be defined:
|
|
229
|
+
|
|
230
|
+
| Condition | Description |
|
|
231
|
+
| :------------- | :---------------------------------------------------------------------------------------------------------------------------------- |
|
|
232
|
+
| `"import"` | Matches when the package is loaded via `import` or `import()`. |
|
|
233
|
+
| `"require"` | Matches when the package is loaded via `require()`. |
|
|
234
|
+
| `"asset"` | Matches when the package is loaded via `require.asset()`. |
|
|
235
|
+
| `"addon"` | Matches when the package is loaded via `require.addon()`. |
|
|
236
|
+
| `"bare"` | Matches for any [Bare](https://github.com/holepunchto/bare) environment. |
|
|
237
|
+
| `"node"` | Matches for any Node.js environment. |
|
|
238
|
+
| `"<platform>"` | Matches when equal to `Bare.platform`. See [`Bare.platform`](https://github.com/holepunchto/bare#bareplatform) for possible values. |
|
|
239
|
+
| `"<arch>"` | Matches when equal to `Bare.arch`. See [`Bare.arch`](https://github.com/holepunchto/bare#barearch) for possible values. |
|
|
240
|
+
| `"simulator"` | Matches when Bare was compiled for a simulator, ie when `Bare.simulator` is `true`. |
|
|
241
|
+
| `"default"` | The fallback that always matches. This condition should always be last. |
|
|
242
|
+
|
|
243
|
+
The general rule is that conditions should be from most specific to least specific when defined.
|
|
244
|
+
|
|
245
|
+
##### `#` Prefix
|
|
246
|
+
|
|
247
|
+
All import maps are private to the package and allow mapping to external packages. Entries in `"imports"` may start with `#` to disambiguate from external packages, but it is not required unlike in Node.js.
|
|
168
248
|
|
|
169
249
|
#### `"engines"`
|
|
170
250
|
|
|
@@ -176,153 +256,291 @@ If a package defines only a single export, `"."`, it may leave out the subpath e
|
|
|
176
256
|
}
|
|
177
257
|
```
|
|
178
258
|
|
|
179
|
-
The engine requirements of the package. During module resolution, the versions declared by `Bare.versions` will be tested against the requirements declared by the package and resolution fail if they're not satisfied.
|
|
259
|
+
The `"engines"` field defines the engine requirements of the package. During module resolution, the versions declared by `Bare.versions` will be tested against the requirements declared by the package and resolution fail if they're not satisfied.
|
|
180
260
|
|
|
181
261
|
## API
|
|
182
262
|
|
|
183
|
-
#### `Module.constants`
|
|
184
|
-
|
|
185
263
|
#### `Module.constants.states`
|
|
186
264
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
`
|
|
265
|
+
The flags for the current state of a module.
|
|
266
|
+
|
|
267
|
+
| Constant | Description |
|
|
268
|
+
| :------------ | :------------------------------------------- |
|
|
269
|
+
| `EVALUATED` | The module has been evaluated. |
|
|
270
|
+
| `SYNTHESIZED` | The module named exports have been detected. |
|
|
271
|
+
| `DESTROYED` | The module has been unloaded. |
|
|
192
272
|
|
|
193
273
|
#### `Module.constants.types`
|
|
194
274
|
|
|
195
|
-
Constant | Description
|
|
196
|
-
|
|
197
|
-
`SCRIPT` |
|
|
198
|
-
`MODULE` |
|
|
199
|
-
`JSON` |
|
|
200
|
-
`BUNDLE` |
|
|
201
|
-
`ADDON` |
|
|
202
|
-
`BINARY` |
|
|
203
|
-
`TEXT` |
|
|
275
|
+
| Constant | Description |
|
|
276
|
+
| :------- | :--------------------------------------------------------------------------- |
|
|
277
|
+
| `SCRIPT` | The module is a CommonJS module. |
|
|
278
|
+
| `MODULE` | The module is a ECMAScript module. |
|
|
279
|
+
| `JSON` | The module is a JSON file. |
|
|
280
|
+
| `BUNDLE` | The module is a [`bare-bundle`](https://github.com/holepunchto/bare-bundle). |
|
|
281
|
+
| `ADDON` | The module is a native addon. |
|
|
282
|
+
| `BINARY` | The module is a binary file. |
|
|
283
|
+
| `TEXT` | The module is a text file. |
|
|
204
284
|
|
|
205
285
|
#### `Module.protocol`
|
|
206
286
|
|
|
287
|
+
The default `ModuleProtocol` class for resolving, reading and loading modules. See [Protocols](#protocols) for usage.
|
|
288
|
+
|
|
207
289
|
#### `Module.cache`
|
|
208
290
|
|
|
291
|
+
The global cache of loaded modules.
|
|
292
|
+
|
|
209
293
|
#### `const url = Module.resolve(specifier, parentURL[, options])`
|
|
210
294
|
|
|
295
|
+
Resolve the module `specifier` relative to the `parentURL`. `specifier` is a string and `parentURL` is a WHATWG `URL`.
|
|
296
|
+
|
|
211
297
|
Options include:
|
|
212
298
|
|
|
213
299
|
```js
|
|
214
|
-
{
|
|
215
|
-
|
|
216
|
-
|
|
300
|
+
options = {
|
|
301
|
+
// Whether the module is called via `import` or `import()`.
|
|
302
|
+
isImport: false,
|
|
303
|
+
// The referring module.
|
|
304
|
+
referrer: null,
|
|
305
|
+
// The type of the module. See Module.constants.types for possible values. The
|
|
306
|
+
// default is the equivalent constant of the `attributes`'s `type` property.
|
|
217
307
|
type,
|
|
218
|
-
extensions
|
|
308
|
+
// A list of file extensions to look for. The default is based on the `type`
|
|
309
|
+
// option.
|
|
310
|
+
extensions: [],
|
|
311
|
+
// The ModuleProtocol to resolve the specifier. Defaults to referrer's
|
|
312
|
+
// protocol if defined, otherwise defaults to Module.protocol
|
|
219
313
|
protocol,
|
|
314
|
+
// A default "imports" map to apply to all specifiers. Follows the same
|
|
315
|
+
// syntax and rules as the "imports" property defined in `package.json`.
|
|
220
316
|
imports,
|
|
317
|
+
// A map of preresolved imports with keys being serialized parent URLs and
|
|
318
|
+
// values being "imports" maps.
|
|
221
319
|
resolutions,
|
|
320
|
+
// A map of builtin module specifiers to loaded modules. If matched by the
|
|
321
|
+
// default resolver, the protocol of the resolved URL will be `builtin:`.
|
|
222
322
|
builtins,
|
|
223
|
-
conditions
|
|
323
|
+
// The supported import conditions. "default" is always recognized.
|
|
324
|
+
conditions: [],
|
|
325
|
+
// The import attributes, e.g. the `{ type: "json" }` in:
|
|
326
|
+
// `import foo from 'foo' with { type: "json" }`
|
|
327
|
+
// or in:
|
|
328
|
+
// `require('foo', { with: { type: "json" } })`
|
|
224
329
|
attributes
|
|
225
330
|
}
|
|
226
331
|
```
|
|
227
332
|
|
|
228
333
|
#### `const module = Module.load(url[, source][, options])`
|
|
229
334
|
|
|
335
|
+
Load a module with the provided `url`. `url` is a WHATWG `URL`. If provided, the `source` will be passed to the matching `extension` for the `url`.
|
|
336
|
+
|
|
230
337
|
Options include:
|
|
231
338
|
|
|
232
339
|
```js
|
|
233
|
-
{
|
|
234
|
-
|
|
340
|
+
options = {
|
|
341
|
+
// Whether the module is called via `import` or `import()`.
|
|
342
|
+
isImport: false,
|
|
343
|
+
// Whether the module is called via `import()`.
|
|
344
|
+
isDynamicImport: false,
|
|
345
|
+
// The referring module.
|
|
346
|
+
referrer: null,
|
|
347
|
+
// The type of the module. See Module.constants.types for possible values. The
|
|
348
|
+
// default is the equivalent constant of the `attributes`'s `type` property.
|
|
235
349
|
type,
|
|
236
|
-
|
|
350
|
+
// The assumed type of a module without a type using an ambiguous extension
|
|
351
|
+
// such as `.js`. See Module.constants.types. Inherited from `referrer` if it
|
|
352
|
+
// is defined.
|
|
353
|
+
defaultType: Module.constants.types.SCRIPT,
|
|
354
|
+
// Cache to use to load the Module. Defaults to `Module.cache`.
|
|
237
355
|
cache,
|
|
356
|
+
// The module representing the entry script where the program was launched.
|
|
238
357
|
main,
|
|
358
|
+
// The ModuleProtocol to use resolve the specifier. Defaults to referrer's
|
|
359
|
+
// `protocol` if defined, otherwise defaults to `Module.protocol`.
|
|
239
360
|
protocol,
|
|
361
|
+
// A default "imports" map to apply to all specifiers. Follows the same
|
|
362
|
+
// syntax and rules as the "imports" property defined in `package.json`.
|
|
240
363
|
imports,
|
|
364
|
+
// A map of preresolved imports with keys being serialized parent URLs and
|
|
365
|
+
// values being "imports" maps.
|
|
241
366
|
resolutions,
|
|
367
|
+
// A map of builtin module specifiers to loaded modules. If the `url`'s
|
|
368
|
+
// protocol is `builtin:`, the module's exports will be set to the matching
|
|
369
|
+
// value in the map for `url.pathname`.
|
|
242
370
|
builtins,
|
|
371
|
+
// The supported import conditions. "default" is always recognized.
|
|
243
372
|
conditions,
|
|
373
|
+
// The import attributes, e.g. the `{ type: "json" }` in:
|
|
374
|
+
// `import foo from 'foo' with { type: "json" }`
|
|
375
|
+
// or in:
|
|
376
|
+
// `require('foo', { with: { type: "json" } })`
|
|
244
377
|
attributes
|
|
245
378
|
}
|
|
246
379
|
```
|
|
247
380
|
|
|
248
381
|
#### `const url = Module.asset(specifier, parentURL[, options])`
|
|
249
382
|
|
|
383
|
+
Get the asset URL by resolving `specifier` relative to `parentURL`. `specifier` is a string and `parentURL` is a WHATWG `URL`.
|
|
384
|
+
|
|
250
385
|
Options include:
|
|
251
386
|
|
|
252
387
|
```js
|
|
253
|
-
{
|
|
254
|
-
|
|
388
|
+
options = {
|
|
389
|
+
// The referring module.
|
|
390
|
+
referrer: null,
|
|
391
|
+
// The ModuleProtocol to use resolve the specifier. Defaults to referrer's
|
|
392
|
+
// protocol if defined, otherwise defaults to Module.protocol
|
|
255
393
|
protocol,
|
|
394
|
+
// A default "imports" map to apply to all specifiers. Follows the same
|
|
395
|
+
// syntax and rules as the "imports" property defined in `package.json`.
|
|
256
396
|
imports,
|
|
397
|
+
// A map of preresolved imports with keys being serialized parent URLs and
|
|
398
|
+
// values being "imports" maps.
|
|
257
399
|
resolutions,
|
|
400
|
+
// The supported import conditions. "default" is always recognized.
|
|
258
401
|
conditions
|
|
259
402
|
}
|
|
260
403
|
```
|
|
261
404
|
|
|
262
405
|
#### `module.url`
|
|
263
406
|
|
|
407
|
+
The WHATWG `URL` instance for the module.
|
|
408
|
+
|
|
264
409
|
#### `module.filename`
|
|
265
410
|
|
|
411
|
+
The pathname of the `module.url`.
|
|
412
|
+
|
|
266
413
|
#### `module.dirname`
|
|
267
414
|
|
|
415
|
+
The directory name of the module.
|
|
416
|
+
|
|
268
417
|
#### `module.type`
|
|
269
418
|
|
|
419
|
+
The type of the module. See [`Module.constants.types`](#module.constants.types) for possible values.
|
|
420
|
+
|
|
270
421
|
#### `module.defaultType`
|
|
271
422
|
|
|
423
|
+
The assumed type of a module without a `type` using an ambiguous extension, such as `.js`. See [`Module.constants.types`](#module.constants.types) for possible values.
|
|
424
|
+
|
|
272
425
|
#### `module.cache`
|
|
273
426
|
|
|
427
|
+
A cache of loaded modules for this module. Defaults to `Module.cache`.
|
|
428
|
+
|
|
274
429
|
#### `module.main`
|
|
275
430
|
|
|
431
|
+
The module representing the entry script where the program was launched.
|
|
432
|
+
|
|
276
433
|
#### `module.exports`
|
|
277
434
|
|
|
435
|
+
The exports from the module.
|
|
436
|
+
|
|
278
437
|
#### `module.imports`
|
|
279
438
|
|
|
439
|
+
The import map when the module was loaded.
|
|
440
|
+
|
|
280
441
|
#### `module.resolutions`
|
|
281
442
|
|
|
443
|
+
A map of preresolved imports with keys being serialized parent URLs and values being `"imports"` maps.
|
|
444
|
+
|
|
282
445
|
#### `module.builtins`
|
|
283
446
|
|
|
447
|
+
A map of builtin module specifiers mapped to the loaded module.
|
|
448
|
+
|
|
284
449
|
#### `module.conditions`
|
|
285
450
|
|
|
451
|
+
An array of conditions used to resolve dependencies while loading the module. See [Conditional Exports](#conditional-exports) for possible values.
|
|
452
|
+
|
|
286
453
|
#### `module.protocol`
|
|
287
454
|
|
|
455
|
+
The `ModuleProtocol` class used for resolving, reading and loading modules. See [Protocols](#protocols).
|
|
456
|
+
|
|
288
457
|
#### `module.destroy()`
|
|
289
458
|
|
|
459
|
+
Unloads the module.
|
|
460
|
+
|
|
290
461
|
### Custom `require()`
|
|
291
462
|
|
|
463
|
+
Creating a custom require allows one to create a preconfigured `require()`. This can be useful in scenarios such as a Read-Evaluate-Print-Loop (REPL) where the parent URL is set to a directory so requiring relative paths to work correctly.
|
|
464
|
+
|
|
292
465
|
#### `const require = Module.createRequire(parentURL[, options])`
|
|
293
466
|
|
|
294
467
|
Options include:
|
|
295
468
|
|
|
296
469
|
```js
|
|
297
|
-
{
|
|
298
|
-
referrer
|
|
299
|
-
|
|
300
|
-
|
|
470
|
+
options = {
|
|
471
|
+
// The module to become the `referrer` for the returned `require()`. Defaults
|
|
472
|
+
// to creating a new module instance from the `parentURL` with the same
|
|
473
|
+
// options.
|
|
474
|
+
module: null,
|
|
475
|
+
// The referring module.
|
|
476
|
+
referrer: null,
|
|
477
|
+
// The type of the module. See Module.constants.types for possible values.
|
|
478
|
+
type: Module.constants.types.SCRIPT,
|
|
479
|
+
// The assumed type of a module without a type using an ambiguous extension
|
|
480
|
+
// such as `.js`. See Module.constants.types. Inherited from `referrer` if it
|
|
481
|
+
// is defined, otherwise defaults to SCRIPT.
|
|
482
|
+
defaultType: Module.constants.types.SCRIPT,
|
|
483
|
+
// A cache of loaded modules. Inherited from `referrer` if it is defined,
|
|
484
|
+
// otherwise defaults to `Module.cache`
|
|
301
485
|
cache,
|
|
486
|
+
// The module representing the entry script where the program was launched.
|
|
302
487
|
main,
|
|
488
|
+
// The ModuleProtocol to use resolve the specifier and/or the module. Defaults to
|
|
489
|
+
// referrer's protocol if defined, otherwise defaults to Module.protocol
|
|
303
490
|
protocol,
|
|
491
|
+
// A default "imports" map to apply to all specifiers. Follows the same
|
|
492
|
+
// syntax and rules as the "imports" property defined in `package.json`.
|
|
304
493
|
imports,
|
|
494
|
+
// A map of preresolved imports with keys being serialized parent URLs and
|
|
495
|
+
// values being "imports" maps.
|
|
305
496
|
resolutions,
|
|
497
|
+
// A map of builtin module specifiers to loaded modules.
|
|
306
498
|
builtins,
|
|
499
|
+
// The supported import conditions. "default" is always recognized.
|
|
307
500
|
conditions
|
|
308
501
|
}
|
|
309
502
|
```
|
|
310
503
|
|
|
311
504
|
### Protocols
|
|
312
505
|
|
|
313
|
-
|
|
506
|
+
Protocols define how to resolve, access and load modules. Custom protocols can be defined to extend or replace how module are resolved and loaded to support things like loading modules via a [`Hyperdrive`](https://github.com/holepunchto/hyperdrive).
|
|
507
|
+
|
|
508
|
+
#### `const protocol = new Module.Protocol(methods, context = null)`
|
|
314
509
|
|
|
315
510
|
Methods include:
|
|
316
511
|
|
|
317
512
|
```js
|
|
318
|
-
{
|
|
513
|
+
methods = {
|
|
514
|
+
// function (specifier, parentURL): string
|
|
515
|
+
// A function to preprocess the `specifier` and `parentURL` before the resolve
|
|
516
|
+
// algorithm is called.
|
|
319
517
|
preresolve,
|
|
518
|
+
// function (url): string
|
|
519
|
+
// A function to process the resolved URL. Can be used to convert file paths,
|
|
520
|
+
// etc.
|
|
320
521
|
postresolve,
|
|
522
|
+
// function* (specifier, parentURL, imports): [URL]
|
|
523
|
+
// A generator to resolve the `specifier` to a URL.
|
|
321
524
|
resolve,
|
|
525
|
+
// function (url): boolean
|
|
526
|
+
// A function that returns whether the URL exists as a boolean.
|
|
322
527
|
exists,
|
|
528
|
+
// function (url): string | Buffer
|
|
529
|
+
// A function that returns the source code of a URL represented as a string or
|
|
530
|
+
// buffer.
|
|
323
531
|
read,
|
|
532
|
+
// function (url): object
|
|
533
|
+
// A function that returns the evaluated exports for the url. This is
|
|
534
|
+
// only called for Javascript modules (extensions `.js`, `.cjs` & `.mjs`)
|
|
535
|
+
// by default. If defined, this function will skip calling `read()` and
|
|
536
|
+
// evaluating the source method for the default implementations of the
|
|
537
|
+
// Javascript extensions.
|
|
324
538
|
load,
|
|
539
|
+
// function (url): URL
|
|
540
|
+
// A function used to post process URLs for addons before `postresolve()`.
|
|
325
541
|
addon,
|
|
542
|
+
// function (url): URL
|
|
543
|
+
// A function used to post process URLs for assets before `postresolve()`.
|
|
326
544
|
asset
|
|
327
545
|
}
|
|
328
546
|
```
|
package/binding.c
CHANGED
|
@@ -16,7 +16,7 @@ typedef struct {
|
|
|
16
16
|
} bare_module_context_t;
|
|
17
17
|
|
|
18
18
|
static js_module_t *
|
|
19
|
-
bare_module__on_static_import
|
|
19
|
+
bare_module__on_static_import(js_env_t *env, js_value_t *specifier, js_value_t *assertions, js_module_t *referrer, void *data) {
|
|
20
20
|
bare_module_context_t *context = (bare_module_context_t *) data;
|
|
21
21
|
|
|
22
22
|
int err;
|
|
@@ -66,7 +66,7 @@ err:
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
static js_module_t *
|
|
69
|
-
bare_module__on_dynamic_import
|
|
69
|
+
bare_module__on_dynamic_import(js_env_t *env, js_value_t *specifier, js_value_t *assertions, js_value_t *referrer, void *data) {
|
|
70
70
|
bare_module_context_t *context = (bare_module_context_t *) data;
|
|
71
71
|
|
|
72
72
|
int err;
|
|
@@ -109,7 +109,7 @@ err:
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
static void
|
|
112
|
-
bare_module__on_evaluate
|
|
112
|
+
bare_module__on_evaluate(js_env_t *env, js_module_t *module, void *data) {
|
|
113
113
|
bare_module_context_t *context = (bare_module_context_t *) data;
|
|
114
114
|
|
|
115
115
|
int err;
|
|
@@ -150,7 +150,7 @@ err:
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
static void
|
|
153
|
-
bare_module__on_meta
|
|
153
|
+
bare_module__on_meta(js_env_t *env, js_module_t *module, js_value_t *meta, void *data) {
|
|
154
154
|
bare_module_context_t *context = (bare_module_context_t *) data;
|
|
155
155
|
|
|
156
156
|
int err;
|
|
@@ -193,7 +193,7 @@ err:
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
static js_value_t *
|
|
196
|
-
bare_module_init
|
|
196
|
+
bare_module_init(js_env_t *env, js_callback_info_t *info) {
|
|
197
197
|
int err;
|
|
198
198
|
|
|
199
199
|
size_t argc = 4;
|
|
@@ -229,7 +229,7 @@ bare_module_init (js_env_t *env, js_callback_info_t *info) {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
static js_value_t *
|
|
232
|
-
bare_module_destroy
|
|
232
|
+
bare_module_destroy(js_env_t *env, js_callback_info_t *info) {
|
|
233
233
|
int err;
|
|
234
234
|
|
|
235
235
|
size_t argc = 1;
|
|
@@ -260,7 +260,7 @@ bare_module_destroy (js_env_t *env, js_callback_info_t *info) {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
static js_value_t *
|
|
263
|
-
bare_module_create_function
|
|
263
|
+
bare_module_create_function(js_env_t *env, js_callback_info_t *info) {
|
|
264
264
|
int err;
|
|
265
265
|
|
|
266
266
|
size_t argc = 4;
|
|
@@ -308,7 +308,7 @@ err:
|
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
static js_value_t *
|
|
311
|
-
bare_module_create_module
|
|
311
|
+
bare_module_create_module(js_env_t *env, js_callback_info_t *info) {
|
|
312
312
|
int err;
|
|
313
313
|
|
|
314
314
|
size_t argc = 4;
|
|
@@ -346,7 +346,7 @@ bare_module_create_module (js_env_t *env, js_callback_info_t *info) {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
static js_value_t *
|
|
349
|
-
bare_module_create_synthetic_module
|
|
349
|
+
bare_module_create_synthetic_module(js_env_t *env, js_callback_info_t *info) {
|
|
350
350
|
int err;
|
|
351
351
|
|
|
352
352
|
size_t argc = 3;
|
|
@@ -396,7 +396,7 @@ err:
|
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
static js_value_t *
|
|
399
|
-
bare_module_delete_module
|
|
399
|
+
bare_module_delete_module(js_env_t *env, js_callback_info_t *info) {
|
|
400
400
|
int err;
|
|
401
401
|
|
|
402
402
|
size_t argc = 1;
|
|
@@ -418,7 +418,7 @@ bare_module_delete_module (js_env_t *env, js_callback_info_t *info) {
|
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
static js_value_t *
|
|
421
|
-
bare_module_set_export
|
|
421
|
+
bare_module_set_export(js_env_t *env, js_callback_info_t *info) {
|
|
422
422
|
int err;
|
|
423
423
|
|
|
424
424
|
size_t argc = 3;
|
|
@@ -439,7 +439,7 @@ bare_module_set_export (js_env_t *env, js_callback_info_t *info) {
|
|
|
439
439
|
}
|
|
440
440
|
|
|
441
441
|
static js_value_t *
|
|
442
|
-
bare_module_run_module
|
|
442
|
+
bare_module_run_module(js_env_t *env, js_callback_info_t *info) {
|
|
443
443
|
int err;
|
|
444
444
|
|
|
445
445
|
size_t argc = 3;
|
|
@@ -501,7 +501,7 @@ bare_module_run_module (js_env_t *env, js_callback_info_t *info) {
|
|
|
501
501
|
}
|
|
502
502
|
|
|
503
503
|
static js_value_t *
|
|
504
|
-
bare_module_get_namespace
|
|
504
|
+
bare_module_get_namespace(js_env_t *env, js_callback_info_t *info) {
|
|
505
505
|
int err;
|
|
506
506
|
|
|
507
507
|
size_t argc = 1;
|
|
@@ -522,7 +522,7 @@ bare_module_get_namespace (js_env_t *env, js_callback_info_t *info) {
|
|
|
522
522
|
}
|
|
523
523
|
|
|
524
524
|
static js_value_t *
|
|
525
|
-
bare_module_exists
|
|
525
|
+
bare_module_exists(js_env_t *env, js_callback_info_t *info) {
|
|
526
526
|
int err;
|
|
527
527
|
|
|
528
528
|
uv_loop_t *loop;
|
|
@@ -556,7 +556,7 @@ bare_module_exists (js_env_t *env, js_callback_info_t *info) {
|
|
|
556
556
|
}
|
|
557
557
|
|
|
558
558
|
static js_value_t *
|
|
559
|
-
bare_module_realpath
|
|
559
|
+
bare_module_realpath(js_env_t *env, js_callback_info_t *info) {
|
|
560
560
|
int err;
|
|
561
561
|
|
|
562
562
|
uv_loop_t *loop;
|
|
@@ -601,7 +601,7 @@ err:
|
|
|
601
601
|
}
|
|
602
602
|
|
|
603
603
|
static js_value_t *
|
|
604
|
-
bare_module_read
|
|
604
|
+
bare_module_read(js_env_t *env, js_callback_info_t *info) {
|
|
605
605
|
int err;
|
|
606
606
|
|
|
607
607
|
uv_loop_t *loop;
|
|
@@ -679,7 +679,7 @@ err:
|
|
|
679
679
|
}
|
|
680
680
|
|
|
681
681
|
static js_value_t *
|
|
682
|
-
bare_module_exports
|
|
682
|
+
bare_module_exports(js_env_t *env, js_value_t *exports) {
|
|
683
683
|
int err;
|
|
684
684
|
|
|
685
685
|
#define V(name, fn) \
|