importmap-rails 0.3.1 → 0.3.2
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4edb628879c46f984d95884b643013077f408a899a1633f7007ef3274393b65
|
4
|
+
data.tar.gz: 627f45fe257131d3432d1f2cf210eb0fd133e286c293b101cfaf5b5a77840a47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd44cdb515fed52817f75d453e274846979e9649e997bd4b2b67689a6761b294c33fdf1b7a9909042da0da2b99d11cbb1ad1a626519a2f528aa4cab5b61869ae
|
7
|
+
data.tar.gz: 301873edf08bb1c486dcdbebe65afbe5b3ff2d43fd9a78c51b9791e07152ae0742e93fcfd92fb936e2ce97adacc3e9ff3f6d2b3eacd15683e153e1c8d457997d
|
@@ -1 +1 @@
|
|
1
|
-
//= require ./es-module-shims@0.12.
|
1
|
+
//= require ./es-module-shims@0.12.6.js
|
@@ -1,6 +1,6 @@
|
|
1
|
-
/* ES Module Shims 0.12.
|
1
|
+
/* ES Module Shims 0.12.6 */
|
2
2
|
(function () {
|
3
|
-
//
|
3
|
+
// Bail on all shimming for Chrome until https://github.com/guybedford/es-module-shims/issues/150
|
4
4
|
if (navigator.userAgent.match("Chrome")) return
|
5
5
|
|
6
6
|
const resolvedPromise = Promise.resolve();
|
@@ -16,6 +16,7 @@
|
|
16
16
|
// support browsers without dynamic import support (eg Firefox 6x)
|
17
17
|
let supportsDynamicImport = false;
|
18
18
|
let supportsJsonAssertions = false;
|
19
|
+
let supportsCssAssertions = false;
|
19
20
|
let dynamicImport;
|
20
21
|
try {
|
21
22
|
dynamicImport = (0, eval)('u=>import(u)');
|
@@ -53,6 +54,7 @@
|
|
53
54
|
let supportsImportMaps = false;
|
54
55
|
|
55
56
|
const featureDetectionPromise = Promise.all([
|
57
|
+
dynamicImport(createBlob('import"data:text/css,{}"assert{type:"css"}')).then(() => supportsCssAssertions = true, () => {}),
|
56
58
|
dynamicImport(createBlob('import"data:text/json,{}"assert{type:"json"}')).then(() => supportsJsonAssertions = true, () => {}),
|
57
59
|
dynamicImport(createBlob('import.meta')).then(() => supportsImportMeta = true, () => {}),
|
58
60
|
supportsDynamicImport && hasDocument && new Promise(resolve => {
|
@@ -263,6 +265,10 @@
|
|
263
265
|
load.n = load.d.some(dep => dep.n);
|
264
266
|
}
|
265
267
|
|
268
|
+
let importMap = { imports: {}, scopes: {} };
|
269
|
+
let importMapSrcOrLazy = false;
|
270
|
+
let importMapPromise = resolvedPromise;
|
271
|
+
|
266
272
|
let waitingForImportMapsInterval;
|
267
273
|
let firstTopLevelProcess = true;
|
268
274
|
async function topLevelLoad (url, fetchOpts, source, nativelyLoaded) {
|
@@ -278,7 +284,7 @@
|
|
278
284
|
}
|
279
285
|
await importMapPromise;
|
280
286
|
// early analysis opt-out
|
281
|
-
if (nativelyLoaded && supportsDynamicImport && supportsImportMeta && supportsImportMaps && !importMapSrcOrLazy) {
|
287
|
+
if (nativelyLoaded && supportsDynamicImport && supportsImportMeta && supportsImportMaps && supportsJsonAssertions && supportsCssAssertions && !importMapSrcOrLazy) {
|
282
288
|
// dont reexec inline for polyfills -> just return null
|
283
289
|
return source && nativelyLoaded ? null : dynamicImport(source ? createBlob(source) : url);
|
284
290
|
}
|
@@ -288,7 +294,7 @@
|
|
288
294
|
await loadAll(load, seen);
|
289
295
|
lastLoad = undefined;
|
290
296
|
resolveDeps(load, seen);
|
291
|
-
if (source && !
|
297
|
+
if (source && !shimMode && !load.n) {
|
292
298
|
const module = dynamicImport(createBlob(source));
|
293
299
|
if (shouldRevokeBlobURLs) revokeObjectURLs(Object.keys(seen));
|
294
300
|
return module;
|
@@ -323,7 +329,8 @@
|
|
323
329
|
await featureDetectionPromise;
|
324
330
|
// Make sure all the "in-flight" import maps are loaded and applied.
|
325
331
|
await importMapPromise;
|
326
|
-
|
332
|
+
const resolved = await resolve(id, parentUrl);
|
333
|
+
return topLevelLoad(resolved.r || throwUnresolved(id, parentUrl), { credentials: 'same-origin' });
|
327
334
|
}
|
328
335
|
|
329
336
|
self.importShim = importShim;
|
@@ -334,7 +341,8 @@
|
|
334
341
|
|
335
342
|
async function importMetaResolve (id, parentUrl = this.url) {
|
336
343
|
await importMapPromise;
|
337
|
-
|
344
|
+
const resolved = await resolve(id, `${parentUrl}`);
|
345
|
+
return resolved.r || throwUnresolved(id, parentUrl);
|
338
346
|
}
|
339
347
|
|
340
348
|
self._esmsm = meta;
|
@@ -374,7 +382,7 @@
|
|
374
382
|
const source = load.S;
|
375
383
|
|
376
384
|
// edge doesnt execute sibling in order, so we fix this up by ensuring all previous executions are explicit dependencies
|
377
|
-
let resolvedSource = edge && lastLoad ? `import '${lastLoad}';` : '';
|
385
|
+
let resolvedSource = edge && lastLoad ? `import '${lastLoad}';` : '';
|
378
386
|
|
379
387
|
if (!imports.length) {
|
380
388
|
resolvedSource += source;
|
@@ -449,7 +457,26 @@
|
|
449
457
|
const cssContentType = /^text\/css(;|$)/;
|
450
458
|
const wasmContentType = /^application\/wasm(;|$)/;
|
451
459
|
|
452
|
-
const
|
460
|
+
const cssUrlRegEx = /url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;
|
461
|
+
|
462
|
+
async function doFetch (url, fetchOpts) {
|
463
|
+
const res = await fetchHook(url, fetchOpts);
|
464
|
+
if (!res.ok)
|
465
|
+
throw new Error(`${res.status} ${res.statusText} ${res.url}`);
|
466
|
+
const contentType = res.headers.get('content-type');
|
467
|
+
if (jsContentType.test(contentType))
|
468
|
+
return { r: res.url, s: await res.text(), t: 'js' };
|
469
|
+
else if (jsonContentType.test(contentType))
|
470
|
+
return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
|
471
|
+
else if (cssContentType.test(contentType))
|
472
|
+
return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
|
473
|
+
JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
|
474
|
+
});export default s;`, t: 'css' };
|
475
|
+
else if (wasmContentType.test(contentType))
|
476
|
+
throw new Error('WASM modules not yet supported');
|
477
|
+
else
|
478
|
+
throw new Error(`Unknown Content-Type "${contentType}"`);
|
479
|
+
}
|
453
480
|
|
454
481
|
function getOrCreateLoad (url, fetchOpts, source) {
|
455
482
|
let load = registry[url];
|
@@ -476,27 +503,18 @@
|
|
476
503
|
// shellUrl
|
477
504
|
s: undefined,
|
478
505
|
// needsShim
|
479
|
-
n: false
|
506
|
+
n: false,
|
507
|
+
// type
|
508
|
+
t: null
|
480
509
|
};
|
481
510
|
|
482
511
|
load.f = (async () => {
|
483
512
|
if (!source) {
|
484
513
|
// preload fetch options override fetch options (race)
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
const contentType = res.headers.get('content-type');
|
490
|
-
if (jsContentType.test(contentType))
|
491
|
-
source = await res.text();
|
492
|
-
else if (jsonContentType.test(contentType))
|
493
|
-
source = `export default ${await res.text()}`;
|
494
|
-
else if (cssContentType.test(contentType))
|
495
|
-
throw new Error('CSS modules not yet supported');
|
496
|
-
else if (wasmContentType.test(contentType))
|
497
|
-
throw new Error('WASM modules not yet supported');
|
498
|
-
else
|
499
|
-
throw new Error(`Unknown Content-Type "${contentType}"`);
|
514
|
+
let t;
|
515
|
+
({ r: load.r, s: source, t } = await (fetchCache[url] || doFetch(url, fetchOpts)));
|
516
|
+
if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions)
|
517
|
+
load.n = true;
|
500
518
|
}
|
501
519
|
try {
|
502
520
|
load.a = parse(source, load.u);
|
@@ -511,13 +529,12 @@
|
|
511
529
|
|
512
530
|
load.L = load.f.then(async () => {
|
513
531
|
let childFetchOpts = fetchOpts;
|
514
|
-
load.d = await Promise.all(load.a[0].map(({ n, d, a }) => {
|
532
|
+
load.d = (await Promise.all(load.a[0].map(async ({ n, d, a }) => {
|
515
533
|
if (d >= 0 && !supportsDynamicImport ||
|
516
|
-
d === 2 && (!supportsImportMeta || source.slice(end, end + 8) === '.resolve')
|
517
|
-
a && !supportsJsonAssertions)
|
534
|
+
d === 2 && (!supportsImportMeta || source.slice(end, end + 8) === '.resolve'))
|
518
535
|
load.n = true;
|
519
536
|
if (!n) return;
|
520
|
-
const { r, m } = resolve(n, load.r || load.u);
|
537
|
+
const { r, m } = await resolve(n, load.r || load.u);
|
521
538
|
if (m && (!supportsImportMaps || importMapSrcOrLazy))
|
522
539
|
load.n = true;
|
523
540
|
if (d !== -1) return;
|
@@ -527,21 +544,12 @@
|
|
527
544
|
if (childFetchOpts.integrity)
|
528
545
|
childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
|
529
546
|
return getOrCreateLoad(r, childFetchOpts).f;
|
530
|
-
}).filter(l => l)
|
547
|
+
}))).filter(l => l);
|
531
548
|
});
|
532
549
|
|
533
550
|
return load;
|
534
551
|
}
|
535
552
|
|
536
|
-
let importMap = { imports: {}, scopes: {} };
|
537
|
-
let importMapSrcOrLazy = false;
|
538
|
-
let importMapPromise = resolvedPromise;
|
539
|
-
|
540
|
-
if (hasDocument) {
|
541
|
-
processScripts();
|
542
|
-
waitingForImportMapsInterval = setInterval(processScripts, 20);
|
543
|
-
}
|
544
|
-
|
545
553
|
async function processScripts () {
|
546
554
|
if (waitingForImportMapsInterval > 0 && document.readyState !== 'loading') {
|
547
555
|
clearTimeout(waitingForImportMapsInterval);
|
@@ -553,26 +561,6 @@
|
|
553
561
|
await processScript(script);
|
554
562
|
}
|
555
563
|
|
556
|
-
new MutationObserver(mutations => {
|
557
|
-
for (const mutation of mutations) {
|
558
|
-
if (mutation.type !== 'childList') continue;
|
559
|
-
for (const node of mutation.addedNodes) {
|
560
|
-
if (node.tagName === 'SCRIPT' && node.type)
|
561
|
-
processScript(node, !firstTopLevelProcess);
|
562
|
-
else if (node.tagName === 'LINK' && node.rel === 'modulepreload')
|
563
|
-
processPreload(node);
|
564
|
-
else if (node.querySelectorAll) {
|
565
|
-
for (const script of node.querySelectorAll('script[type="module-shim"],script[type="importmap-shim"],script[type="module"],script[type="importmap"]')) {
|
566
|
-
processScript(script, !firstTopLevelProcess);
|
567
|
-
}
|
568
|
-
for (const link of node.querySelectorAll('link[rel=modulepreload]')) {
|
569
|
-
processPreload(link);
|
570
|
-
}
|
571
|
-
}
|
572
|
-
}
|
573
|
-
}
|
574
|
-
}).observe(document, { childList: true, subtree: true });
|
575
|
-
|
576
564
|
function getFetchOpts (script) {
|
577
565
|
const fetchOpts = {};
|
578
566
|
if (script.integrity)
|
@@ -612,20 +600,49 @@
|
|
612
600
|
}
|
613
601
|
}
|
614
602
|
|
603
|
+
const fetchCache = {};
|
615
604
|
function processPreload (link) {
|
616
605
|
if (link.ep) // ep marker = processed
|
617
606
|
return;
|
618
607
|
link.ep = true;
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
608
|
+
fetchCache[link.href] = doFetch(link.href, getFetchOpts(link));
|
609
|
+
}
|
610
|
+
|
611
|
+
new MutationObserver(mutations => {
|
612
|
+
for (const mutation of mutations) {
|
613
|
+
if (mutation.type !== 'childList') continue;
|
614
|
+
for (const node of mutation.addedNodes) {
|
615
|
+
if (node.tagName === 'SCRIPT' && node.type)
|
616
|
+
processScript(node, !firstTopLevelProcess);
|
617
|
+
else if (node.tagName === 'LINK' && node.rel === 'modulepreload')
|
618
|
+
processPreload(node);
|
619
|
+
else if (node.querySelectorAll) {
|
620
|
+
for (const script of node.querySelectorAll('script[type="module-shim"],script[type="importmap-shim"],script[type="module"],script[type="importmap"]')) {
|
621
|
+
processScript(script, !firstTopLevelProcess);
|
622
|
+
}
|
623
|
+
for (const link of node.querySelectorAll('link[rel=modulepreload]')) {
|
624
|
+
processPreload(link);
|
625
|
+
}
|
626
|
+
}
|
627
|
+
}
|
628
|
+
}
|
629
|
+
}).observe(document, { childList: true, subtree: true });
|
630
|
+
|
631
|
+
async function defaultResolve (id, parentUrl) {
|
632
|
+
return resolveImportMap(importMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl);
|
624
633
|
}
|
625
634
|
|
626
|
-
function resolve (id, parentUrl) {
|
627
|
-
|
628
|
-
|
635
|
+
async function resolve (id, parentUrl) {
|
636
|
+
let urlResolved = resolveIfNotPlainOrUrl(id, parentUrl);
|
637
|
+
|
638
|
+
let resolved;
|
639
|
+
if (esmsInitOptions.resolve) {
|
640
|
+
resolved = await esmsInitOptions.resolve(id, parentUrl, defaultResolve);
|
641
|
+
}
|
642
|
+
else {
|
643
|
+
resolved = resolveImportMap(importMap, urlResolved || id, parentUrl);
|
644
|
+
}
|
645
|
+
|
629
646
|
return { r: resolved, m: urlResolved !== resolved };
|
630
647
|
}
|
631
648
|
|
@@ -633,4 +650,9 @@
|
|
633
650
|
throw Error("Unable to resolve specifier '" + id + (parentUrl ? "' from " + parentUrl : "'"));
|
634
651
|
}
|
635
652
|
|
636
|
-
|
653
|
+
if (hasDocument) {
|
654
|
+
processScripts();
|
655
|
+
waitingForImportMapsInterval = setInterval(processScripts, 20);
|
656
|
+
}
|
657
|
+
|
658
|
+
}());
|
data/lib/importmap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: importmap-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.0.0
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email: david@loudthinking.com
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -34,7 +34,7 @@ files:
|
|
34
34
|
- README.md
|
35
35
|
- Rakefile
|
36
36
|
- app/assets/javascripts/es-module-shims.js
|
37
|
-
- app/assets/javascripts/es-module-shims@0.12.
|
37
|
+
- app/assets/javascripts/es-module-shims@0.12.6.js
|
38
38
|
- app/helpers/importmap/importmap_tags_helper.rb
|
39
39
|
- lib/importmap-rails.rb
|
40
40
|
- lib/importmap/engine.rb
|
@@ -50,7 +50,7 @@ licenses:
|
|
50
50
|
metadata:
|
51
51
|
homepage_uri: https://github.com/rails/importmap-rails
|
52
52
|
source_code_uri: https://github.com/rails/importmap-rails
|
53
|
-
post_install_message:
|
53
|
+
post_install_message:
|
54
54
|
rdoc_options: []
|
55
55
|
require_paths:
|
56
56
|
- lib
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubygems_version: 3.1.4
|
69
|
-
signing_key:
|
69
|
+
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: Use ESM with importmap to manage modern JavaScript in Rails without transpiling
|
72
72
|
or bundling.
|