@@ -2172,6 +2172,109 @@ describe("HTTP ESM Loader", function() {
21722172 } ) ;
21732173 } ) ;
21742174 } ) ;
2175+
2176+ // The spelling of these URLs is what dev tooling compares module URLs
2177+ // against, so it must survive every route into the loader byte for byte.
2178+ describe ( "module URLs in the shapes dev tooling emits" , function ( ) {
2179+ var nsModule = require ( "ns:module" ) ;
2180+
2181+ afterEach ( function ( ) {
2182+ nsModule . configureLoader ( { importMap : { imports : { } } } ) ;
2183+ } ) ;
2184+
2185+ // Each module reports the request target the server saw and its own
2186+ // import.meta.url.
2187+ function expectSpelledAsWritten ( ns , url ) {
2188+ var target = url . slice ( url . indexOf ( "/" , url . indexOf ( "://" ) + 3 ) ) ;
2189+ var q = target . indexOf ( "?" ) ;
2190+ expect ( ns . url ) . toBe ( url ) ;
2191+ expect ( ns . path ) . toBe ( q < 0 ? target : target . slice ( 0 , q ) ) ;
2192+ expect ( ns . query ) . toBe ( q < 0 ? "" : target . slice ( q + 1 ) ) ;
2193+ expect ( nsModule . getLoadedModuleUrls ( ) ) . toContain ( url ) ;
2194+ }
2195+
2196+ function expectEvicted ( urls ) {
2197+ nsModule . invalidateModules ( urls ) ;
2198+ var loaded = nsModule . getLoadedModuleUrls ( ) ;
2199+ urls . forEach ( function ( url ) {
2200+ expect ( loaded ) . not . toContain ( url ) ;
2201+ } ) ;
2202+ }
2203+
2204+ it ( "keeps them as written when a file module imports them" , function ( done ) {
2205+ var origin = getHostOrigin ( ) ;
2206+ if ( ! origin ) {
2207+ pending ( "REPORT_BASEURL not set; skipping host HTTP tests" ) ;
2208+ done ( ) ;
2209+ return ;
2210+ }
2211+ var written = origin . replace ( "127.0.0.1" , "LOCALHOST" ) ;
2212+ var base = origin + "/esm/resolve/tooling-direct" ;
2213+ var urls = [
2214+ base + "/ns/m/src/app.ts?v=abc" ,
2215+ base + "/ns/core/index.js" ,
2216+ base + "/ns/node/x" ,
2217+ base + "/ns/m/node_modules/pkg/index.js" ,
2218+ base + "/ns/asm?path=%2Fsrc%2FApp.vue&mode=inline" ,
2219+ base + "/ns/asm?path=/src/App.vue&mode=inline" ,
2220+ base + "/ns/sfc/src/App.vue?vue&type=script" ,
2221+ base + "/ns/m/q.js?b=2&a=1" ,
2222+ base + "/@ng/component?c=x&t=1" ,
2223+ base + "/@id/__x00__virtual:thing" ,
2224+ base + "/@fs/Users/me/proj/x.ts" ,
2225+ written + "/esm/resolve/tooling-direct/ns/m/upper.js?v=1" ,
2226+ ] ;
2227+ Promise . all ( urls . map ( function ( url ) {
2228+ return import ( url ) ;
2229+ } ) ) . then ( function ( namespaces ) {
2230+ namespaces . forEach ( function ( ns , i ) {
2231+ expectSpelledAsWritten ( ns , urls [ i ] ) ;
2232+ } ) ;
2233+ expectEvicted ( urls ) ;
2234+ done ( ) ;
2235+ } ) . catch ( function ( error ) {
2236+ expect ( "rejected: " + formatError ( error ) ) . toBe ( "resolved" ) ;
2237+ done ( ) ;
2238+ } ) ;
2239+ } ) ;
2240+
2241+ it ( "keeps them as written when an import-map entry targets them" , function ( done ) {
2242+ var origin = getHostOrigin ( ) ;
2243+ if ( ! origin ) {
2244+ pending ( "REPORT_BASEURL not set; skipping host HTTP tests" ) ;
2245+ done ( ) ;
2246+ return ;
2247+ }
2248+ var written = origin . replace ( "127.0.0.1" , "LOCALHOST" ) ;
2249+ var base = origin + "/esm/resolve/tooling-mapped" ;
2250+ var dynamicUrl = base + "/ns/m/src/dynamic.ts?v=abc" ;
2251+ var staticUrl = base + "/ns/asm?path=%2Fsrc%2FApp.vue&mode=inline" ;
2252+ var upperUrl = written + "/esm/resolve/tooling-mapped/ns/m/upper.js?b=2&a=1" ;
2253+ nsModule . configureLoader ( {
2254+ importMap : {
2255+ imports : {
2256+ "ns-tooling-url-dynamic" : dynamicUrl ,
2257+ "ns-tooling-url-static" : staticUrl ,
2258+ "ns-tooling-url-upper" : upperUrl ,
2259+ } ,
2260+ } ,
2261+ } ) ;
2262+ Promise . all ( [
2263+ import ( "ns-tooling-url-dynamic" ) ,
2264+ import ( "~/tests/esm/tooling-url/static-importer.mjs" ) ,
2265+ import ( "ns-tooling-url-upper" ) ,
2266+ ] ) . then ( function ( namespaces ) {
2267+ expectSpelledAsWritten ( namespaces [ 0 ] , dynamicUrl ) ;
2268+ expectSpelledAsWritten ( namespaces [ 1 ] . dep , staticUrl ) ;
2269+ expectSpelledAsWritten ( namespaces [ 2 ] , upperUrl ) ;
2270+ expectEvicted ( [ dynamicUrl , staticUrl , upperUrl ] ) ;
2271+ done ( ) ;
2272+ } ) . catch ( function ( error ) {
2273+ expect ( "rejected: " + formatError ( error ) ) . toBe ( "resolved" ) ;
2274+ done ( ) ;
2275+ } ) ;
2276+ } ) ;
2277+ } ) ;
21752278} ) ;
21762279
21772280// Focused, deterministic coverage for the native HTTP canonical-key function.
@@ -2184,15 +2287,86 @@ describe("HTTP canonical key (ns:module canonicalizeHttpUrlKey)", function () {
21842287 return require ( "ns:module" ) . canonicalizeHttpUrlKey ;
21852288 }
21862289
2290+ // A registered key is canonicalized again whenever it is looked up, so a key
2291+ // must be a fixed point.
21872292 function checkKey ( input , expected ) {
21882293 var canon = getCanon ( ) ;
21892294 if ( typeof canon !== "function" ) {
21902295 pending ( "ns:module.canonicalizeHttpUrlKey not exposed (release build)" ) ;
21912296 return ;
21922297 }
21932298 expect ( canon ( input ) ) . toBe ( expected ) ;
2299+ expect ( canon ( expected ) ) . toBe ( expected ) ;
21942300 }
21952301
2302+ // [input, key with no vocabulary, key under TOOLING_VOCABULARY]
2303+ var TOOLING_URLS = [
2304+ [ "http://h:5173/ns/m/src/app.ts?v=abc" ,
2305+ "http://h:5173/ns/m/src/app.ts?v=abc" ,
2306+ "http://h:5173/ns/m/src/app.ts" ] ,
2307+ [ "http://h:5173/ns/core/index.js" ,
2308+ "http://h:5173/ns/core/index.js" ,
2309+ "http://h:5173/ns/core/index.js" ] ,
2310+ [ "http://h:5173/ns/node/x" ,
2311+ "http://h:5173/ns/node/x" ,
2312+ "http://h:5173/ns/node/x" ] ,
2313+ [ "http://h:5173/ns/m/node_modules/pkg/index.js?v=abc" ,
2314+ "http://h:5173/ns/m/node_modules/pkg/index.js?v=abc" ,
2315+ "http://h:5173/ns/m/node_modules/pkg/index.js" ] ,
2316+ [ "http://h:5173/ns/asm?path=%2Fsrc%2FApp.vue&mode=inline" ,
2317+ "http://h:5173/ns/asm?path=%2Fsrc%2FApp.vue&mode=inline" ,
2318+ "http://h:5173/ns/asm?mode=inline&path=%2Fsrc%2FApp.vue" ] ,
2319+ [ "http://h:5173/ns/asm?path=/src/App.vue&mode=inline" ,
2320+ "http://h:5173/ns/asm?path=/src/App.vue&mode=inline" ,
2321+ "http://h:5173/ns/asm?mode=inline&path=/src/App.vue" ] ,
2322+ [ "http://h:5173/ns/sfc/src/App.vue?vue&type=script" ,
2323+ "http://h:5173/ns/sfc/src/App.vue?vue&type=script" ,
2324+ "http://h:5173/ns/sfc/src/App.vue?type=script&vue" ] ,
2325+ [ "http://h:5173/ns/m/q.js?b=2&a=1" ,
2326+ "http://h:5173/ns/m/q.js?b=2&a=1" ,
2327+ "http://h:5173/ns/m/q.js?a=1&b=2" ] ,
2328+ [ "http://h:5173/@ng/component?c=x&t=1" ,
2329+ "http://h:5173/@ng/component?c=x&t=1" ,
2330+ "http://h:5173/@ng/component?c=x&t=1" ] ,
2331+ [ "http://h:5173/@id/__x00__virtual:thing?import" ,
2332+ "http://h:5173/@id/__x00__virtual:thing?import" ,
2333+ "http://h:5173/@id/__x00__virtual:thing" ] ,
2334+ [ "http://h:5173/@fs/Users/me/proj/x.ts?t=1" ,
2335+ "http://h:5173/@fs/Users/me/proj/x.ts?t=1" ,
2336+ "http://h:5173/@fs/Users/me/proj/x.ts" ] ,
2337+ [ "http://h:5173/node_modules/.vite/deps/pkg.js?v=abc" ,
2338+ "http://h:5173/node_modules/.vite/deps/pkg.js?v=abc" ,
2339+ "http://h:5173/node_modules/.vite/deps/pkg.js" ] ,
2340+ [ "http://MyMac.local:5173/ns/m/app.js?v=1" ,
2341+ "http://MyMac.local:5173/ns/m/app.js?v=1" ,
2342+ "http://MyMac.local:5173/ns/m/app.js" ] ,
2343+ [ "http://MyMac.local:5173/ns/m/app.js?" ,
2344+ "http://MyMac.local:5173/ns/m/app.js?" ,
2345+ "http://MyMac.local:5173/ns/m/app.js" ] ,
2346+ [ "http://MyMac.local:5173/ns/m/app.js#" ,
2347+ "http://MyMac.local:5173/ns/m/app.js" ,
2348+ "http://MyMac.local:5173/ns/m/app.js" ] ,
2349+ [ "http://h:80/ns/m/app.js?v=1" ,
2350+ "http://h:80/ns/m/app.js?v=1" ,
2351+ "http://h:80/ns/m/app.js" ] ,
2352+ [ "http://192.168.1.20:5173/ns/m/app.js?v=1" ,
2353+ "http://192.168.1.20:5173/ns/m/app.js?v=1" ,
2354+ "http://192.168.1.20:5173/ns/m/app.js" ] ,
2355+ [ "http://[::1]:5173/ns/m/app.js?v=1" ,
2356+ "http://[::1]:5173/ns/m/app.js?v=1" ,
2357+ "http://[::1]:5173/ns/m/app.js" ] ,
2358+ // The URL parser rejects a zone id; the key keeps the URL as written.
2359+ [ "http://[fe80::1%25en0]:5173/ns/m/app.js?v=1#x" ,
2360+ "http://[fe80::1%25en0]:5173/ns/m/app.js?v=1" ,
2361+ "http://[fe80::1%25en0]:5173/ns/m/app.js" ] ,
2362+ ] ;
2363+
2364+ var TOOLING_VOCABULARY = {
2365+ stripParams : [ "t" , "v" , "import" ] ,
2366+ forPathPrefixes : [ "/ns/" , "/@id/" , "/@fs/" , "/node_modules/.vite/" ] ,
2367+ preserveQueryFor : [ "/@ng/component" ] ,
2368+ } ;
2369+
21962370 it ( "is exposed as a function in debug builds" , function ( ) {
21972371 var canon = getCanon ( ) ;
21982372 if ( typeof canon !== "function" ) {
@@ -2249,6 +2423,38 @@ describe("HTTP canonical key (ns:module canonicalizeHttpUrlKey)", function () {
22492423 checkKey ( "https://cdn.example.com/lib.js?token=abc#frag" ,
22502424 "https://cdn.example.com/lib.js?token=abc" ) ;
22512425 } ) ;
2426+
2427+ it ( "keeps the URLs dev tooling emits as written" , function ( ) {
2428+ TOOLING_URLS . forEach ( function ( row ) {
2429+ checkKey ( row [ 0 ] , row [ 1 ] ) ;
2430+ } ) ;
2431+ } ) ;
2432+ } ) ;
2433+
2434+ describe ( "with a tooling-shaped vocabulary" , function ( ) {
2435+ beforeEach ( function ( ) {
2436+ var nsModule = require ( "ns:module" ) ;
2437+ if ( typeof nsModule . canonicalizeHttpUrlKey !== "function" ) {
2438+ return ;
2439+ }
2440+ nsModule . configureLoader ( { canonicalization : TOOLING_VOCABULARY } ) ;
2441+ } ) ;
2442+
2443+ afterEach ( function ( ) {
2444+ var nsModule = require ( "ns:module" ) ;
2445+ if ( typeof nsModule . canonicalizeHttpUrlKey !== "function" ) {
2446+ return ;
2447+ }
2448+ nsModule . configureLoader ( {
2449+ canonicalization : { stripParams : [ ] , forPathPrefixes : [ ] , preserveQueryFor : [ ] } ,
2450+ } ) ;
2451+ } ) ;
2452+
2453+ it ( "keys the URLs dev tooling emits" , function ( ) {
2454+ TOOLING_URLS . forEach ( function ( row ) {
2455+ checkKey ( row [ 0 ] , row [ 2 ] ) ;
2456+ } ) ;
2457+ } ) ;
22522458 } ) ;
22532459
22542460 // Canonicalization config is process-wide, so each spec here installs its
0 commit comments