@@ -487,10 +487,11 @@ const stale = getLoadedModuleUrls().filter((url) => url.includes("/src/"));
487487invalidateModules (stale);
488488```
489489
490- ` getLoadedModuleUrls() ` reports the ** URL-like** keys only: registry entries
491- that are ` blob: ` -prefixed or contain ` :// ` . A module keyed by a plain
492- filesystem path is not in the result, so the eviction set a dev client computes
493- from it covers served modules rather than the app's own bundled files.
490+ ` getLoadedModuleUrls() ` reports the ** URL-like** keys only: ` blob: ` URLs and
491+ http(s) URLs. A file module, keyed by its filesystem path and any query it was
492+ imported with, is never in the result, even when that query holds ` :// ` , so the
493+ eviction set a dev client computes from it covers served modules rather than
494+ the app's own bundled files.
494495
495496` createRequire ` gives a module-relative ` require ` from anywhere, including an
496497ES module that has no ` __filename ` :
@@ -565,7 +566,8 @@ ending in `/` must have a target ending in `/`.
565566
566567A **scope key is matched as a plain prefix of the importing module's canonical
567568registry key** — an absolute ` http (s)` URL for a served module, or a canonical
568- absolute path for a file on disk. That key is this runtime's analogue of the
569+ absolute path for a file on disk, without the query a file module may have been
570+ imported with. That key is this runtime's analogue of the
569571web's resolved referrer URL, which is what scope prefixes match in a browser.
570572An ` http (s)` scope key is spelled the way registry keys are (see
571573[Registry canonicalization](#registry-canonicalization)) when the map is
@@ -811,16 +813,57 @@ lowercase host, no default port).
811813An import -map entry is never refused — it is explicit configuration, so it may
812814point an HTTP module at a ` ~/` path — though a relative or root- relative target
813815still resolves against the importer' s URL. A specifier with any other URL
814- scheme (`data:`, `file:/x`) is never looked up on disk, and `import()` of a
815- `blob:nativescript/…` URL loads from the blob store. A refused specifier fails
816+ scheme (`data:`, `file:/x`) is never looked up on disk. A refused specifier fails
816817before anything is fetched or read from disk, with an `Error` whose message
817818names the specifier, the importer and what to use instead;
818819`createRequire(<file path>)` is the explicit way for an HTTP module to reach
819820CommonJS or ES modules on disk.
820821
821- From a file module, a static `import ' pkg? x' ` and `import(' pkg? x' )` alike look
822- `pkg?x` up in the import map as written. An import-map target is never looked
823- up in the map a second time, by a static import or by `import()`.
822+ From a file module, `import ' pkg? x' ` and `import(' pkg? x' )` both look `pkg?x`
823+ up in the import map, exactly as written: an entry for `pkg` does not match it,
824+ while a `pkg/` prefix entry matches `pkg/x.js?v=1`. A query or fragment is
825+ dropped only when a file path is derived, so `./x.js?v=1` and `./x.js#f` load
826+ `x.js`.
827+
828+ #### File module identity
829+
830+ As in browsers and Node, the query is part of a file module' s identity:
831+ ` ./x.js?v=1` , ` ./x.js?v=2` and ` ./x.js` are three instances of one file, each
832+ evaluated once, whether imported statically or with ` import()` ; an import -map
833+ target' s query counts the same way. `./x.js?` is a fourth: the URL standard
834+ keeps an empty query distinct from none. The fragment is not part of the
835+ identity — `./x.js#a` and `./x.js#b` are the `./x.js` instance — matching how
836+ this loader keys http(s) modules. The query is kept as the URL parser
837+ serializes it.
838+
839+ Inside such a module, `import.meta.url` carries the query
840+ (`file://<app root>/x.js?v=1`) while `import.meta.dirname` does not, and
841+ relative imports, `createRequire(import.meta.url)`, `new Worker(' ./ w .js ' )` and
842+ import-map scopes resolve exactly as for the module without a query. Anything
843+ that names a file without a specifier — the entry module, a worker' s script,
844+ ` require()` of an ES module — loads the instance without a query . The code
845+ cache is per file, shared by every instance . File modules are not listed by
846+ ` getLoadedModuleUrls()` , with or without a query, and ` invalidateModules()`
847+ given a ` file://` URL with a query drops only that instance.
848+
849+ A module ' s `file://` URL spells its path verbatim after `file://`, so a `#` in
850+ a directory or file name is part of the path there, not a fragment: a relative
851+ `import()`, `createRequire(import.meta.url)` and `new Worker(' ./ w .js ' )` from a
852+ script under `a#b/` resolve inside `a#b/`. A `?` in a file name is not
853+ supported: wherever a module' s key or URL is read as a path, a ` ?` starts its
854+ query.
855+
856+ ` import()` resolves its specifier once, by the same rules and against the same
857+ importer as a static import from the module that calls it, so the import map is
858+ applied once: an entry' s target is never looked up in the map again, and a
859+ `./x` or `../x` that names no file is reported as written
860+ (`Cannot find module ' ./ x' (tried <path>)`), as a static import reports it.
861+
862+ `import()` of a `blob:` URL loads from the blob store, from any importer. The
863+ store is looked up the way the File API resolves a blob URL: without the
864+ fragment and with the query, so `blobUrl + ' #f' ` loads the blob and
865+ `blobUrl + ' ? x' ` rejects with `Blob not found`. A blob URL with and without a
866+ fragment is one module. A static import of a `blob:` URL does not resolve.
824867
825868### The `require()` specifier
826869
0 commit comments