bare-module 7.1.0 → 7.2.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 +45 -3
- package/index.d.ts +22 -2
- package/lib/loader.d.ts +22 -5
- package/lib/loader.js +219 -25
- package/lib/module.js +9 -13
- package/package.json +3 -3
- package/prebuilds/android-arm/bare-module.bare +0 -0
- package/prebuilds/android-arm64/bare-module.bare +0 -0
- package/prebuilds/android-ia32/bare-module.bare +0 -0
- package/prebuilds/android-x64/bare-module.bare +0 -0
- package/prebuilds/darwin-arm64/bare-module.bare +0 -0
- package/prebuilds/darwin-x64/bare-module.bare +0 -0
- package/prebuilds/ios-arm64/bare-module.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-module.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-module.bare +0 -0
- package/prebuilds/linux-arm64/bare-module.bare +0 -0
- package/prebuilds/linux-x64/bare-module.bare +0 -0
- package/prebuilds/win32-arm64/bare-module.bare +0 -0
- package/prebuilds/win32-x64/bare-module.bare +0 -0
package/README.md
CHANGED
|
@@ -301,7 +301,9 @@ options = {
|
|
|
301
301
|
// The import attributes which instruct how the file or module should be loaded.
|
|
302
302
|
// `type` is one of the strings `script`, `module`, `json`, `bundle`, `addon`,
|
|
303
303
|
// `binary` and `text`. A type that is not one of them is turned down rather
|
|
304
|
-
// than passed over, as is a `type` that is not a string.
|
|
304
|
+
// than passed over, as is a `type` that is not a string. `imports` is the
|
|
305
|
+
// specifier of an "imports" map to apply to the module and its dependencies,
|
|
306
|
+
// resolved relative to the module calling `require()`.
|
|
305
307
|
with: { type: 'json' }
|
|
306
308
|
}
|
|
307
309
|
```
|
|
@@ -314,10 +316,26 @@ The module representing the entry script where the program was launched.
|
|
|
314
316
|
|
|
315
317
|
The registry of loaded modules for this module's graph, keyed by URL href.
|
|
316
318
|
|
|
317
|
-
### `const path = require.resolve(specifier[, parentURL])`
|
|
319
|
+
### `const path = require.resolve(specifier[, parentURL][, options])`
|
|
318
320
|
|
|
319
321
|
Use the internal machinery of `require()` to resolve the `specifier` string relative to the URL `parentURL` and return the path string.
|
|
320
322
|
|
|
323
|
+
Options include:
|
|
324
|
+
|
|
325
|
+
```js
|
|
326
|
+
options = {
|
|
327
|
+
// The import attributes which instruct how the file or module would be
|
|
328
|
+
// loaded, as for `require()`. If passed, the graph of the resolved module is
|
|
329
|
+
// linked, but not evaluated, with the attributes applied so that its
|
|
330
|
+
// resolutions are recorded in `module.resolutions`. This allows the module to
|
|
331
|
+
// later be prepared from its path alone, such as when spawning a thread with
|
|
332
|
+
// an imports map applied.
|
|
333
|
+
with: { imports: './imports.json' }
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
When `parentURL` is passed, the resolutions are recorded for `parentURL` rather than the calling module. This is useful when resolving on behalf of another module.
|
|
338
|
+
|
|
321
339
|
### `require.addon([specifier][, parentURL])`
|
|
322
340
|
|
|
323
341
|
Also used to import modules but specifically loads only addon modules. `specifier` is resolved relative to `parentURL` using the [addon resolution](https://github.com/holepunchto/bare-addon-resolve#algorithm) algorithm.
|
|
@@ -379,10 +397,12 @@ The directory name of the current module.
|
|
|
379
397
|
|
|
380
398
|
The file name of the current module.
|
|
381
399
|
|
|
382
|
-
### `const href = import.meta.resolve(specifier[, parentURL])`
|
|
400
|
+
### `const href = import.meta.resolve(specifier[, parentURL][, options])`
|
|
383
401
|
|
|
384
402
|
A module-relative resolution function which returns the URL string for the module. The `specifier` is a string which is resolved relative to the `parentURL` which is a WHATWG URL.
|
|
385
403
|
|
|
404
|
+
Options are the same as for [`require.resolve()`](#const-path--requireresolvespecifier-parenturl-options).
|
|
405
|
+
|
|
386
406
|
### `import.meta.addon([specifier][, parentURL])`
|
|
387
407
|
|
|
388
408
|
Also used to import modules but specifically loads only addon modules. `specifier` is resolved relative to `parentURL` using the [addon resolution](https://github.com/holepunchto/bare-addon-resolve#algorithm) algorithm.
|
|
@@ -589,6 +609,18 @@ Link the module graph rooted at `entry`, a WHATWG `URL`, awaiting each read thro
|
|
|
589
609
|
|
|
590
610
|
The synchronous equivalent of `loader.link()`. It drives the protocol's synchronous methods (`resolveSync`, `existsSync`, `readSync`, and `listSync`), which throw an `UNEXPECTED_PROMISE` error when the protocol can only answer asynchronously.
|
|
591
611
|
|
|
612
|
+
### `const modules = await loader.instantiate(urls[, options])`
|
|
613
|
+
|
|
614
|
+
Compile the modules at `urls` and everything they reach, without evaluating any of them. `urls` is a WHATWG `URL`, a string, or any number of either. Returns the module records.
|
|
615
|
+
|
|
616
|
+
This is the phase `loader.link()` performs on the way to an entry, for modules the graph already holds and is not entering through, so it answers whether a source can be run at all without any of the consequences of running it. Unlike `link()` it does not set `loader.main`.
|
|
617
|
+
|
|
618
|
+
A module the graph has already compiled is left as it is, so this is asked after a `patch()` rather than before one. What it answers is whether the source compiles, and not whether everything it names exists: an unresolved specifier is deferred, which is what lets a module name something that is not there on this platform and never ask for it.
|
|
619
|
+
|
|
620
|
+
### `const modules = loader.instantiateSync(urls[, options])`
|
|
621
|
+
|
|
622
|
+
The synchronous equivalent of `loader.instantiate()`.
|
|
623
|
+
|
|
592
624
|
### `const exports = await loader.import(entry[, options])`
|
|
593
625
|
|
|
594
626
|
Link and evaluate the graph rooted at `entry`, returning its exports. Awaits the entry's evaluation, so a top-level `await` in the entry settles before the exports are returned.
|
|
@@ -597,6 +629,16 @@ Link and evaluate the graph rooted at `entry`, returning its exports. Awaits the
|
|
|
597
629
|
|
|
598
630
|
The synchronous equivalent of `loader.import()`. It cannot await, so a top-level `await` in the entry is unsupported.
|
|
599
631
|
|
|
632
|
+
### `const urls = loader.patch(bundle)`
|
|
633
|
+
|
|
634
|
+
Make the contents of `bundle` what the graph reads, in front of whatever it read before, and forget what it knew about each key. Returns the URLs the patch covers. A later patch of the same key wins over an earlier one.
|
|
635
|
+
|
|
636
|
+
Forgetting a module is not re-reading it: nothing runs again until something asks for it, and whoever already imported it keeps what it exported. Reaching a patched module through an importer the graph still holds requires evicting that importer too.
|
|
637
|
+
|
|
638
|
+
### `const urls = loader.evict(urls)`
|
|
639
|
+
|
|
640
|
+
Forget what the graph knows about the modules at `urls`, a WHATWG `URL`, a string, or any number of either, so that they are read and resolved again when next asked for. Returns the URLs that were known.
|
|
641
|
+
|
|
600
642
|
### `const module = loader.get(url)`
|
|
601
643
|
|
|
602
644
|
Return the module record cached under `url`, a WHATWG `URL`, or `null` if none is loaded.
|
package/index.d.ts
CHANGED
|
@@ -22,7 +22,12 @@ interface Attributes {
|
|
|
22
22
|
* How the module should be loaded: one of `'script'`, `'module'`, `'json'`, `'bundle'`,
|
|
23
23
|
* `'addon'`, `'binary'`, or `'text'`.
|
|
24
24
|
*/
|
|
25
|
-
type
|
|
25
|
+
type?: Lowercase<keyof typeof constants>
|
|
26
|
+
/**
|
|
27
|
+
* The specifier of an `"imports"` map to apply to the module and its dependencies, resolved
|
|
28
|
+
* relative to the parent URL.
|
|
29
|
+
*/
|
|
30
|
+
imports?: string
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
interface Module {
|
|
@@ -98,7 +103,22 @@ declare namespace Module {
|
|
|
98
103
|
(parentURL: string | URL, opts?: RequireOptions): unknown
|
|
99
104
|
main: Module
|
|
100
105
|
cache: Cache
|
|
101
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Resolve `specifier` relative to `parentURL` without evaluating the matching module. If
|
|
108
|
+
* import attributes are passed, the graph of the module is linked with them so that its
|
|
109
|
+
* resolutions are recorded.
|
|
110
|
+
* @param specifier - The module specifier to resolve.
|
|
111
|
+
* @param parentURL - The WHATWG `URL` to resolve `specifier` relative to. Defaults to the URL
|
|
112
|
+
* of the module that `require()` was created for.
|
|
113
|
+
* @param opts - Resolve options; `with` holds the import attributes.
|
|
114
|
+
* @returns The path of the resolved module.
|
|
115
|
+
* @throws {MODULE_NOT_FOUND} no module matching `specifier` could be found relative to
|
|
116
|
+
* `parentURL`.
|
|
117
|
+
*/
|
|
118
|
+
resolve: {
|
|
119
|
+
(specifier: string, opts?: RequireOptions): string
|
|
120
|
+
(specifier: string, parentURL?: string | URL, opts?: RequireOptions): string
|
|
121
|
+
}
|
|
102
122
|
/**
|
|
103
123
|
* Resolve `specifier` relative to `parentURL` and evaluate the matching addon.
|
|
104
124
|
* @param specifier - The addon specifier to resolve. Defaults to `'.'`.
|
package/lib/loader.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Buffer from 'bare-buffer'
|
|
2
|
+
import Bundle from 'bare-bundle'
|
|
2
3
|
import URL from 'bare-url'
|
|
3
4
|
import { Builtins, ImportsMap, ResolutionsMap } from 'bare-module-resolve'
|
|
4
|
-
import { Attributes, Cache
|
|
5
|
+
import Module, { Attributes, Cache } from '..'
|
|
5
6
|
import Protocol from './protocol'
|
|
6
7
|
|
|
7
8
|
interface ModuleLoader {
|
|
@@ -20,11 +21,27 @@ interface ModuleLoader {
|
|
|
20
21
|
|
|
21
22
|
get(url: URL): Module | null
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
patch(bundle: Bundle): URL[]
|
|
25
|
+
evict(urls: URL | string | Iterable<URL | string>): URL[]
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
instantiate(
|
|
28
|
+
urls: URL | string | Iterable<URL | string>,
|
|
29
|
+
opts?: ModuleLoader.LinkOptions
|
|
30
|
+
): Promise<Module[]>
|
|
31
|
+
instantiateSync(
|
|
32
|
+
urls: URL | string | Iterable<URL | string>,
|
|
33
|
+
opts?: ModuleLoader.LinkOptions
|
|
34
|
+
): Module[]
|
|
35
|
+
|
|
36
|
+
link(
|
|
37
|
+
entry: URL,
|
|
38
|
+
source?: Buffer | string | null,
|
|
39
|
+
opts?: ModuleLoader.LinkOptions
|
|
40
|
+
): Promise<Module>
|
|
41
|
+
linkSync(entry: URL, source?: Buffer | string | null, opts?: ModuleLoader.LinkOptions): Module
|
|
42
|
+
|
|
43
|
+
import(entry: URL, opts?: ModuleLoader.ImportOptions): Promise<unknown>
|
|
44
|
+
importSync(entry: URL, opts?: ModuleLoader.ImportOptions): unknown
|
|
28
45
|
}
|
|
29
46
|
|
|
30
47
|
declare class ModuleLoader {
|
package/lib/loader.js
CHANGED
|
@@ -23,6 +23,8 @@ const engines = Bare.versions
|
|
|
23
23
|
|
|
24
24
|
const cacheOwners = new WeakMap()
|
|
25
25
|
|
|
26
|
+
const defaultProtocol = new ModuleProtocol()
|
|
27
|
+
|
|
26
28
|
function assertProtocol(protocol) {
|
|
27
29
|
if (ModuleProtocol.isProtocol(protocol)) return protocol
|
|
28
30
|
|
|
@@ -98,6 +100,14 @@ function assertURL(url, name) {
|
|
|
98
100
|
throw new TypeError(`${name} must be a URL. Received type ${typeof url} (${url})`)
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
function* eachURL(urls) {
|
|
104
|
+
if (isURL(urls) || typeof urls === 'string') urls = [urls]
|
|
105
|
+
|
|
106
|
+
for (const url of urls) {
|
|
107
|
+
yield assertURL(typeof url === 'string' ? new URL(url) : url, 'URL')
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
101
111
|
function typeAttributeFor(attributes) {
|
|
102
112
|
if (attributes === undefined || attributes === null) return undefined
|
|
103
113
|
|
|
@@ -170,7 +180,7 @@ module.exports = class ModuleLoader {
|
|
|
170
180
|
concurrency
|
|
171
181
|
} = opts
|
|
172
182
|
|
|
173
|
-
this._protocol = protocol === null ?
|
|
183
|
+
this._protocol = protocol === null ? defaultProtocol : assertProtocol(protocol)
|
|
174
184
|
this._defaultType = defaultTypeFor(defaultType)
|
|
175
185
|
this._builtins = builtinsFor(builtins)
|
|
176
186
|
this._imports = importsFor(imports)
|
|
@@ -193,7 +203,7 @@ module.exports = class ModuleLoader {
|
|
|
193
203
|
// other, protocol and builtins and all. The cache is therefore claimed
|
|
194
204
|
// before anything is read into it, and what it already holds is checked
|
|
195
205
|
// against the claim.
|
|
196
|
-
claimCache(this)
|
|
206
|
+
this._graph = claimCache(this)
|
|
197
207
|
|
|
198
208
|
for (const href in this._cache) {
|
|
199
209
|
const record = this._cache[href]
|
|
@@ -220,6 +230,75 @@ module.exports = class ModuleLoader {
|
|
|
220
230
|
return this._cached(assertURL(url, 'URL').href) || null
|
|
221
231
|
}
|
|
222
232
|
|
|
233
|
+
patch(bundle) {
|
|
234
|
+
const graph = this._graph
|
|
235
|
+
|
|
236
|
+
if (graph.patches === null) {
|
|
237
|
+
graph.patches = new Map()
|
|
238
|
+
graph.reader = patching(graph.protocol, graph.patches)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const patched = []
|
|
242
|
+
|
|
243
|
+
for (const href of bundle.keys()) {
|
|
244
|
+
const url = new URL(href)
|
|
245
|
+
|
|
246
|
+
graph.patches.set(href, bundle)
|
|
247
|
+
|
|
248
|
+
this._forget(url)
|
|
249
|
+
|
|
250
|
+
const imports = bundle.resolutions[href]
|
|
251
|
+
|
|
252
|
+
if (imports) this._resolutions[href] = imports
|
|
253
|
+
|
|
254
|
+
patched.push(url)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return patched
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
evict(urls) {
|
|
261
|
+
const evicted = []
|
|
262
|
+
|
|
263
|
+
for (const url of eachURL(urls)) {
|
|
264
|
+
if (this._forget(url)) evicted.push(url)
|
|
265
|
+
|
|
266
|
+
delete this._resolutions[url.href]
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return evicted
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async instantiate(urls, opts = {}) {
|
|
273
|
+
const records = []
|
|
274
|
+
|
|
275
|
+
for (const url of eachURL(urls)) {
|
|
276
|
+
if (url.protocol === 'builtin:') this._lookup(url)
|
|
277
|
+
else await this._link(this._root(url, null, opts), this._protocolFor(url))
|
|
278
|
+
|
|
279
|
+
records.push(this._lookup(traverse.alias(url, opts)))
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
this._instantiate()
|
|
283
|
+
|
|
284
|
+
return records
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
instantiateSync(urls, opts = {}) {
|
|
288
|
+
const records = []
|
|
289
|
+
|
|
290
|
+
for (const url of eachURL(urls)) {
|
|
291
|
+
if (url.protocol === 'builtin:') this._lookup(url)
|
|
292
|
+
else this._linkSync(this._root(url, null, opts), this._protocolFor(url))
|
|
293
|
+
|
|
294
|
+
records.push(this._lookup(traverse.alias(url, opts)))
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
this._instantiate()
|
|
298
|
+
|
|
299
|
+
return records
|
|
300
|
+
}
|
|
301
|
+
|
|
223
302
|
async link(entry, source = null, opts = {}) {
|
|
224
303
|
assertURL(entry, 'Entry')
|
|
225
304
|
|
|
@@ -308,15 +387,15 @@ module.exports = class ModuleLoader {
|
|
|
308
387
|
}
|
|
309
388
|
|
|
310
389
|
_answersFor(protocol) {
|
|
311
|
-
return protocol === this.
|
|
390
|
+
return protocol === this._graph.reader ? this._answers : null
|
|
312
391
|
}
|
|
313
392
|
|
|
314
393
|
_protocolFor(url) {
|
|
315
394
|
const bundle = this._bundleFor(url)
|
|
316
395
|
|
|
317
|
-
if (bundle === null) return this.
|
|
396
|
+
if (bundle === null) return this._graph.reader
|
|
318
397
|
|
|
319
|
-
return this.
|
|
398
|
+
return this._graph.reader.extend({
|
|
320
399
|
resolve(context, url) {
|
|
321
400
|
return bundleOwns(bundle, url) ? url : context.resolve(url)
|
|
322
401
|
},
|
|
@@ -397,6 +476,24 @@ module.exports = class ModuleLoader {
|
|
|
397
476
|
return null
|
|
398
477
|
}
|
|
399
478
|
|
|
479
|
+
_forget(url) {
|
|
480
|
+
const { href } = url
|
|
481
|
+
|
|
482
|
+
const known = href in this._cache
|
|
483
|
+
|
|
484
|
+
delete this._cache[href]
|
|
485
|
+
|
|
486
|
+
this._visited.delete(href)
|
|
487
|
+
this._packages.delete(href)
|
|
488
|
+
|
|
489
|
+
this._answers.listed.delete(href)
|
|
490
|
+
this._answers.resolved.delete(href)
|
|
491
|
+
|
|
492
|
+
if (this._main !== null && this._main.url.href === href) this._main = null
|
|
493
|
+
|
|
494
|
+
return known
|
|
495
|
+
}
|
|
496
|
+
|
|
400
497
|
_builtinRecord(url) {
|
|
401
498
|
const name = url.pathname
|
|
402
499
|
|
|
@@ -564,7 +661,7 @@ module.exports = class ModuleLoader {
|
|
|
564
661
|
if (href in this._resolutions === false) this._resolutions[href] = bundle.resolutions[href]
|
|
565
662
|
}
|
|
566
663
|
|
|
567
|
-
const protocol = this.
|
|
664
|
+
const protocol = this._graph.reader.extend({
|
|
568
665
|
exists(context, url) {
|
|
569
666
|
if (bundleOwns(bundle, url)) return true
|
|
570
667
|
|
|
@@ -686,24 +783,20 @@ module.exports = class ModuleLoader {
|
|
|
686
783
|
require.main = loader.main
|
|
687
784
|
require.cache = loader.cache
|
|
688
785
|
|
|
689
|
-
require.resolve = function (specifier, parentURL
|
|
690
|
-
return urlToPath(loader.
|
|
786
|
+
require.resolve = function (specifier, parentURL, opts) {
|
|
787
|
+
return urlToPath(loader._resolveModule(referrer, specifier, 'require', parentURL, opts))
|
|
691
788
|
}
|
|
692
789
|
|
|
693
|
-
require.asset = function (specifier, parentURL
|
|
694
|
-
return urlToPath(
|
|
695
|
-
loader._resolveArtifact(referrer, specifier, 'asset', toURL(parentURL, referrer.url))
|
|
696
|
-
)
|
|
790
|
+
require.asset = function (specifier, parentURL) {
|
|
791
|
+
return urlToPath(loader._resolveArtifact(referrer, specifier, 'asset', parentURL))
|
|
697
792
|
}
|
|
698
793
|
|
|
699
|
-
require.addon = function (specifier = '.', parentURL
|
|
700
|
-
return loader._addon(referrer, specifier,
|
|
794
|
+
require.addon = function (specifier = '.', parentURL) {
|
|
795
|
+
return loader._addon(referrer, specifier, parentURL)
|
|
701
796
|
}
|
|
702
797
|
|
|
703
|
-
require.addon.resolve = function (specifier = '.', parentURL
|
|
704
|
-
return urlToPath(
|
|
705
|
-
loader._resolveArtifact(referrer, specifier, 'addon', toURL(parentURL, referrer.url))
|
|
706
|
-
)
|
|
798
|
+
require.addon.resolve = function (specifier = '.', parentURL) {
|
|
799
|
+
return urlToPath(loader._resolveArtifact(referrer, specifier, 'addon', parentURL))
|
|
707
800
|
}
|
|
708
801
|
|
|
709
802
|
require.addon.host = Bare.Addon.host
|
|
@@ -731,7 +824,10 @@ module.exports = class ModuleLoader {
|
|
|
731
824
|
let record = this._lookup(url)
|
|
732
825
|
|
|
733
826
|
if (record === null) {
|
|
734
|
-
this.linkSync(url, null, {
|
|
827
|
+
this.linkSync(url, null, {
|
|
828
|
+
attributes: this._resolveAttributesSync(attributes, parentURL),
|
|
829
|
+
importType: lex.constants.REQUIRE
|
|
830
|
+
})
|
|
735
831
|
|
|
736
832
|
record = this.get(url)
|
|
737
833
|
}
|
|
@@ -887,13 +983,67 @@ module.exports = class ModuleLoader {
|
|
|
887
983
|
throw notFound(condition, specifier, parentURL, candidates)
|
|
888
984
|
}
|
|
889
985
|
|
|
890
|
-
|
|
986
|
+
_resolveModule(referrer, specifier, condition, parentURL, opts) {
|
|
987
|
+
if (isOptions(parentURL)) {
|
|
988
|
+
opts = parentURL
|
|
989
|
+
parentURL = undefined
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
parentURL = parentURLFor(referrer, parentURL)
|
|
993
|
+
|
|
994
|
+
const url = this._resolveSync(specifier, parentURL, condition)
|
|
995
|
+
|
|
996
|
+
const attributes = opts && opts.with
|
|
997
|
+
|
|
998
|
+
// The graph is linked as it would be when the resolved module is loaded,
|
|
999
|
+
// without being evaluated, so that its resolutions are recorded for anyone
|
|
1000
|
+
// preparing it from the resolved URL alone.
|
|
1001
|
+
if (attributes !== undefined && attributes !== null) {
|
|
1002
|
+
const importType =
|
|
1003
|
+
lex.constants.RESOLVE |
|
|
1004
|
+
(condition === 'require' ? lex.constants.REQUIRE : lex.constants.IMPORT)
|
|
1005
|
+
|
|
1006
|
+
this._linkResolved(url, parentURL, attributes, importType)
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
return url
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
_linkResolved(url, parentURL, attributes, importType) {
|
|
1013
|
+
if (this._lookup(url) !== null) return
|
|
1014
|
+
|
|
1015
|
+
attributes = this._resolveAttributesSync(attributes, parentURL)
|
|
1016
|
+
|
|
1017
|
+
this._linkSync(this._root(url, null, { attributes, importType }), this._protocolFor(url))
|
|
1018
|
+
|
|
1019
|
+
this._instantiate()
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
_resolveAttributesSync(attributes, parentURL) {
|
|
1023
|
+
if (!hasImportsAttribute(attributes)) return attributes
|
|
1024
|
+
|
|
1025
|
+
const url = this._resolveSync(attributes.imports, parentURL, 'default')
|
|
1026
|
+
|
|
1027
|
+
return { ...attributes, imports: url.href }
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
async _resolveAttributes(attributes, parentURL) {
|
|
1031
|
+
if (!hasImportsAttribute(attributes)) return attributes
|
|
1032
|
+
|
|
1033
|
+
const url = await this._resolve(attributes.imports, parentURL, 'default')
|
|
1034
|
+
|
|
1035
|
+
return { ...attributes, imports: url.href }
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
_resolveArtifact(referrer, specifier, condition, parentURL) {
|
|
1039
|
+
parentURL = parentURLFor(referrer, parentURL)
|
|
1040
|
+
|
|
891
1041
|
const url = parentURL === referrer.url ? referrer._resolve(specifier, condition) : null
|
|
892
1042
|
|
|
893
1043
|
return url === null ? this._resolveSync(specifier, parentURL, condition) : url
|
|
894
1044
|
}
|
|
895
1045
|
|
|
896
|
-
_addon(referrer, specifier, parentURL
|
|
1046
|
+
_addon(referrer, specifier, parentURL) {
|
|
897
1047
|
const url = this._resolveArtifact(referrer, specifier, 'addon', parentURL)
|
|
898
1048
|
|
|
899
1049
|
const record = this._lookup(url) || this._addonRecord(url)
|
|
@@ -998,12 +1148,16 @@ function claimCache(loader) {
|
|
|
998
1148
|
const owner = cacheOwners.get(loader._cache)
|
|
999
1149
|
|
|
1000
1150
|
if (owner === undefined) {
|
|
1001
|
-
|
|
1151
|
+
const graph = {
|
|
1002
1152
|
protocol: loader._protocol,
|
|
1003
|
-
builtins: loader._builtins
|
|
1004
|
-
|
|
1153
|
+
builtins: loader._builtins,
|
|
1154
|
+
patches: null,
|
|
1155
|
+
reader: loader._protocol
|
|
1156
|
+
}
|
|
1005
1157
|
|
|
1006
|
-
|
|
1158
|
+
cacheOwners.set(loader._cache, graph)
|
|
1159
|
+
|
|
1160
|
+
return graph
|
|
1007
1161
|
}
|
|
1008
1162
|
|
|
1009
1163
|
if (owner.protocol !== loader._protocol) {
|
|
@@ -1013,6 +1167,8 @@ function claimCache(loader) {
|
|
|
1013
1167
|
if (owner.builtins !== loader._builtins) {
|
|
1014
1168
|
throw errors.CACHE_INCOMPATIBLE('Cache is read with different builtins')
|
|
1015
1169
|
}
|
|
1170
|
+
|
|
1171
|
+
return owner
|
|
1016
1172
|
}
|
|
1017
1173
|
|
|
1018
1174
|
function assertCompatible(loader, href, record) {
|
|
@@ -1181,6 +1337,30 @@ function resolveEntry(specifier, condition) {
|
|
|
1181
1337
|
return { type, specifier, names: [], attributes: {}, position: [0, 0, 0] }
|
|
1182
1338
|
}
|
|
1183
1339
|
|
|
1340
|
+
function patching(protocol, patches) {
|
|
1341
|
+
return protocol.extend({
|
|
1342
|
+
exists(context, url) {
|
|
1343
|
+
return patches.has(url.href) || context.exists(url)
|
|
1344
|
+
},
|
|
1345
|
+
|
|
1346
|
+
existsSync(context, url) {
|
|
1347
|
+
return patches.has(url.href) || context.existsSync(url)
|
|
1348
|
+
},
|
|
1349
|
+
|
|
1350
|
+
read(context, url) {
|
|
1351
|
+
const patch = patches.get(url.href)
|
|
1352
|
+
|
|
1353
|
+
return patch === undefined ? context.read(url) : patch.read(url.href)
|
|
1354
|
+
},
|
|
1355
|
+
|
|
1356
|
+
readSync(context, url) {
|
|
1357
|
+
const patch = patches.get(url.href)
|
|
1358
|
+
|
|
1359
|
+
return patch === undefined ? context.readSync(url) : patch.read(url.href)
|
|
1360
|
+
}
|
|
1361
|
+
})
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1184
1364
|
function toURL(value, base) {
|
|
1185
1365
|
if (isURL(value)) return value
|
|
1186
1366
|
|
|
@@ -1197,6 +1377,20 @@ function bundleOwns(bundle, url) {
|
|
|
1197
1377
|
return bundle.exists(url.href)
|
|
1198
1378
|
}
|
|
1199
1379
|
|
|
1380
|
+
function parentURLFor(referrer, parentURL) {
|
|
1381
|
+
return parentURL === undefined ? referrer.url : toURL(parentURL, referrer.url)
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
function isOptions(value) {
|
|
1385
|
+
return typeof value === 'object' && value !== null && !URL.isURL(value)
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
function hasImportsAttribute(attributes) {
|
|
1389
|
+
return (
|
|
1390
|
+
typeof attributes === 'object' && attributes !== null && typeof attributes.imports === 'string'
|
|
1391
|
+
)
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1200
1394
|
function isTerminalResolution(url, condition) {
|
|
1201
1395
|
const protocol = url.protocol
|
|
1202
1396
|
|
package/lib/module.js
CHANGED
|
@@ -285,7 +285,7 @@ async function ondynamicimport(specifier, attributes, referrerName, id) {
|
|
|
285
285
|
url = await loader._resolve(specifier, referrer.url, 'import')
|
|
286
286
|
|
|
287
287
|
record = await loader.link(url, null, {
|
|
288
|
-
attributes,
|
|
288
|
+
attributes: await loader._resolveAttributes(attributes, referrer.url),
|
|
289
289
|
importType: lex.constants.IMPORT | lex.constants.DYNAMIC
|
|
290
290
|
})
|
|
291
291
|
} else {
|
|
@@ -343,24 +343,20 @@ function onmeta(id, meta) {
|
|
|
343
343
|
meta.dirname = record.dirname
|
|
344
344
|
meta.filename = record.filename
|
|
345
345
|
|
|
346
|
-
meta.resolve = function (specifier) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return url === null
|
|
350
|
-
? record._loader._resolveSync(specifier, record.url, 'import').href
|
|
351
|
-
: url.href
|
|
346
|
+
meta.resolve = function (specifier, parentURL, opts) {
|
|
347
|
+
return record._loader._resolveModule(record, specifier, 'import', parentURL, opts).href
|
|
352
348
|
}
|
|
353
349
|
|
|
354
|
-
meta.asset = function (specifier) {
|
|
355
|
-
return record._loader._resolveArtifact(record, specifier, 'asset').href
|
|
350
|
+
meta.asset = function (specifier, parentURL) {
|
|
351
|
+
return record._loader._resolveArtifact(record, specifier, 'asset', parentURL).href
|
|
356
352
|
}
|
|
357
353
|
|
|
358
|
-
meta.addon = function (specifier = '.') {
|
|
359
|
-
return record._loader._addon(record, specifier)
|
|
354
|
+
meta.addon = function (specifier = '.', parentURL) {
|
|
355
|
+
return record._loader._addon(record, specifier, parentURL)
|
|
360
356
|
}
|
|
361
357
|
|
|
362
|
-
meta.addon.resolve = function (specifier = '.') {
|
|
363
|
-
return record._loader._resolveArtifact(record, specifier, 'addon').href
|
|
358
|
+
meta.addon.resolve = function (specifier = '.', parentURL) {
|
|
359
|
+
return record._loader._resolveArtifact(record, specifier, 'addon', parentURL).href
|
|
364
360
|
}
|
|
365
361
|
|
|
366
362
|
meta.addon.host = Bare.Addon.host
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-module",
|
|
3
|
-
"version": "7.1
|
|
3
|
+
"version": "7.2.1",
|
|
4
4
|
"description": "The module system that powers Bare",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package": "./package.json",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"bare-bundle": "^1.11.0",
|
|
50
|
-
"bare-module-lexer": "^1.
|
|
50
|
+
"bare-module-lexer": "^1.7.0",
|
|
51
51
|
"bare-module-resolve": "^1.12.3",
|
|
52
|
-
"bare-module-traverse": "~2.5.
|
|
52
|
+
"bare-module-traverse": "~2.5.7",
|
|
53
53
|
"bare-path": "^3.0.0",
|
|
54
54
|
"bare-type-stripper": "^0.1.2",
|
|
55
55
|
"bare-url": "^2.0.1",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|