importmap-rails 0.7.3 → 0.7.4
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 +4 -4
- data/app/assets/javascripts/es-module-shims.js +101 -80
- data/lib/importmap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ce5ca88f369995c2b29b27b38e5f3539101b8c314237825cf5dc4bc1a653e32
|
4
|
+
data.tar.gz: a88e63335529c55217e121f9fabbff574da4010bbeecf948a7ec3f4d3ec505ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ce4de1dd05d813987bbb663b60ef6023624eaf092d8578a87691998ceef32fb5d39fca5fd86cd8fd33a87d197bc28e345901d4e9cacbef235d953e5ea6aa70
|
7
|
+
data.tar.gz: b047cc3f19efc2d462fdc456b9c5dc95581e2bc79e53196575a096771a51a83e7334568f3eceda567775acd254d49437d34156b4432f08b942651052c059352b
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* ES Module Shims 1.0.
|
1
|
+
/* ES Module Shims 1.0.4 */
|
2
2
|
(function () {
|
3
3
|
|
4
4
|
const edge = navigator.userAgent.match(/Edge\/\d\d\.\d+$/);
|
@@ -201,7 +201,7 @@
|
|
201
201
|
let shimMode = !!esmsInitOptions$1.shimMode;
|
202
202
|
const resolveHook = shimMode && esmsInitOptions$1.resolve;
|
203
203
|
|
204
|
-
const skip = esmsInitOptions$1.skip ? new RegExp(esmsInitOptions$1.skip) :
|
204
|
+
const skip = esmsInitOptions$1.skip ? new RegExp(esmsInitOptions$1.skip) : null;
|
205
205
|
|
206
206
|
let nonce = esmsInitOptions$1.nonce;
|
207
207
|
|
@@ -329,7 +329,35 @@
|
|
329
329
|
|
330
330
|
let importMap = { imports: {}, scopes: {} };
|
331
331
|
let importMapSrcOrLazy = false;
|
332
|
-
let
|
332
|
+
let baselinePassthrough;
|
333
|
+
|
334
|
+
const initPromise = featureDetectionPromise.then(() => {
|
335
|
+
baselinePassthrough = supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy && !false;
|
336
|
+
// shim mode is determined on initialization, no late shim mode
|
337
|
+
if (!shimMode && document.querySelectorAll('script[type="module-shim"],script[type="importmap-shim"]').length)
|
338
|
+
setShimMode();
|
339
|
+
if (shimMode || !baselinePassthrough) {
|
340
|
+
new MutationObserver(mutations => {
|
341
|
+
for (const mutation of mutations) {
|
342
|
+
if (mutation.type !== 'childList') continue;
|
343
|
+
for (const node of mutation.addedNodes) {
|
344
|
+
if (node.tagName === 'SCRIPT') {
|
345
|
+
if (!shimMode && node.type === 'module' || shimMode && node.type === 'module-shim')
|
346
|
+
processScript(node);
|
347
|
+
if (!shimMode && node.type === 'importmap' || shimMode && node.type === 'importmap-shim')
|
348
|
+
processImportMap(node);
|
349
|
+
}
|
350
|
+
else if (node.tagName === 'LINK' && node.rel === 'modulepreload')
|
351
|
+
processPreload(node);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}).observe(document, { childList: true, subtree: true });
|
355
|
+
processImportMaps();
|
356
|
+
processScriptsAndPreloads();
|
357
|
+
return undefined;
|
358
|
+
}
|
359
|
+
});
|
360
|
+
let importMapPromise = initPromise;
|
333
361
|
|
334
362
|
let acceptingImportMaps = true;
|
335
363
|
let nativeAcceptingImportMaps = true;
|
@@ -344,7 +372,7 @@
|
|
344
372
|
}
|
345
373
|
await importMapPromise;
|
346
374
|
// early analysis opt-out - no need to even fetch if we have feature support
|
347
|
-
if (!shimMode &&
|
375
|
+
if (!shimMode && baselinePassthrough) {
|
348
376
|
// for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
|
349
377
|
if (nativelyLoaded)
|
350
378
|
return null;
|
@@ -390,7 +418,17 @@
|
|
390
418
|
}
|
391
419
|
|
392
420
|
async function importShim (id, parentUrl = baseUrl, _assertion) {
|
393
|
-
|
421
|
+
// needed for shim check
|
422
|
+
await initPromise;
|
423
|
+
if (acceptingImportMaps || shimMode || !baselinePassthrough) {
|
424
|
+
processImportMaps();
|
425
|
+
if (!shimMode) {
|
426
|
+
acceptingImportMaps = false;
|
427
|
+
}
|
428
|
+
else {
|
429
|
+
nativeAcceptingImportMaps = false;
|
430
|
+
}
|
431
|
+
}
|
394
432
|
await importMapPromise;
|
395
433
|
return topLevelLoad((await resolve(id, parentUrl)).r || throwUnresolved(id, parentUrl), { credentials: 'same-origin' });
|
396
434
|
}
|
@@ -400,7 +438,6 @@
|
|
400
438
|
const meta = {};
|
401
439
|
|
402
440
|
async function importMetaResolve (id, parentUrl = this.url) {
|
403
|
-
await importMapPromise;
|
404
441
|
return (await resolve(id, `${parentUrl}`)).r || throwUnresolved(id, parentUrl);
|
405
442
|
}
|
406
443
|
|
@@ -608,7 +645,7 @@
|
|
608
645
|
if (d !== -1) return;
|
609
646
|
if (!r)
|
610
647
|
throwUnresolved(n, load.r || load.u);
|
611
|
-
if (skip.test(r)) return { b: r };
|
648
|
+
if (skip && skip.test(r)) return { b: r };
|
612
649
|
if (childFetchOpts.integrity)
|
613
650
|
childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
|
614
651
|
return getOrCreateLoad(r, childFetchOpts).f;
|
@@ -618,19 +655,16 @@
|
|
618
655
|
return load;
|
619
656
|
}
|
620
657
|
|
621
|
-
function
|
658
|
+
function processScriptsAndPreloads () {
|
659
|
+
for (const script of document.querySelectorAll(shimMode ? 'script[type="module-shim"]' : 'script[type="module"]'))
|
660
|
+
processScript(script);
|
622
661
|
for (const link of document.querySelectorAll('link[rel="modulepreload"]'))
|
623
662
|
processPreload(link);
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
setShimMode();
|
630
|
-
}
|
631
|
-
}
|
632
|
-
for (const script of scripts)
|
633
|
-
processScript(script);
|
663
|
+
}
|
664
|
+
|
665
|
+
function processImportMaps () {
|
666
|
+
for (const script of document.querySelectorAll(shimMode ? 'script[type="importmap-shim"]' : 'script[type="importmap"]'))
|
667
|
+
processImportMap(script);
|
634
668
|
}
|
635
669
|
|
636
670
|
function getFetchOpts (script) {
|
@@ -656,73 +690,74 @@
|
|
656
690
|
document.dispatchEvent(new Event('DOMContentLoaded'));
|
657
691
|
}
|
658
692
|
// this should always trigger because we assume es-module-shims is itself a domcontentloaded requirement
|
659
|
-
document.addEventListener('DOMContentLoaded',
|
693
|
+
document.addEventListener('DOMContentLoaded', async () => {
|
694
|
+
await initPromise;
|
695
|
+
domContentLoadedCheck();
|
696
|
+
if (shimMode || !baselinePassthrough) {
|
697
|
+
processImportMaps();
|
698
|
+
processScriptsAndPreloads();
|
699
|
+
}
|
700
|
+
});
|
660
701
|
|
661
702
|
let readyStateCompleteCnt = 1;
|
662
703
|
if (document.readyState === 'complete')
|
663
704
|
readyStateCompleteCheck();
|
664
705
|
else
|
665
|
-
document.addEventListener('readystatechange',
|
706
|
+
document.addEventListener('readystatechange', async () => {
|
707
|
+
await initPromise;
|
708
|
+
readyStateCompleteCheck();
|
709
|
+
});
|
666
710
|
function readyStateCompleteCheck () {
|
667
711
|
if (--readyStateCompleteCnt === 0 && !noLoadEventRetriggers)
|
668
712
|
document.dispatchEvent(new Event('readystatechange'));
|
669
713
|
}
|
670
714
|
|
671
|
-
function
|
672
|
-
if (
|
715
|
+
function processImportMap (script) {
|
716
|
+
if (!acceptingImportMaps)
|
673
717
|
return;
|
674
|
-
|
675
|
-
if (shim && !shimMode) setShimMode();
|
676
|
-
const type = shimMode ? script.type.slice(0, -5) : script.type;
|
677
|
-
// dont process module scripts in shim mode or noshim module scripts in polyfill mode
|
678
|
-
if (!shim && shimMode || script.getAttribute('noshim') !== null)
|
718
|
+
if (script.ep) // ep marker = script processed
|
679
719
|
return;
|
680
720
|
// empty inline scripts sometimes show before domready
|
681
721
|
if (!script.src && !script.innerHTML)
|
682
722
|
return;
|
683
723
|
script.ep = true;
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
if (isReadyScript) readyStateCompleteCnt++;
|
690
|
-
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
691
|
-
const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, isReadyScript && lastStaticLoadPromise).then(() => {
|
692
|
-
if (!noLoadEventRetriggers)
|
693
|
-
triggerLoadEvent(script);
|
694
|
-
}).catch(e => {
|
695
|
-
if (!noLoadEventRetriggers)
|
696
|
-
triggerLoadEvent(script);
|
697
|
-
// setTimeout(() => { throw e; });
|
698
|
-
onerror(e);
|
699
|
-
});
|
700
|
-
if (isReadyScript)
|
701
|
-
lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
|
702
|
-
if (isDomContentLoadedScript)
|
703
|
-
loadPromise.then(domContentLoadedCheck);
|
724
|
+
// we dont currently support multiple, external or dynamic imports maps in polyfill mode to match native
|
725
|
+
if (script.src || !nativeAcceptingImportMaps) {
|
726
|
+
if (!shimMode)
|
727
|
+
return;
|
728
|
+
importMapSrcOrLazy = true;
|
704
729
|
}
|
705
|
-
|
706
|
-
|
707
|
-
if (script.src || !nativeAcceptingImportMaps) {
|
708
|
-
if (!shimMode)
|
709
|
-
return;
|
710
|
-
importMapSrcOrLazy = true;
|
711
|
-
}
|
712
|
-
if (!shimMode) {
|
713
|
-
acceptingImportMaps = false;
|
714
|
-
}
|
715
|
-
else {
|
716
|
-
nativeAcceptingImportMaps = false;
|
717
|
-
}
|
718
|
-
importMapPromise = importMapPromise.then(async () => {
|
719
|
-
importMap = resolveAndComposeImportMap(script.src ? await (await fetchHook(script.src)).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
|
720
|
-
});
|
730
|
+
if (!shimMode) {
|
731
|
+
acceptingImportMaps = false;
|
721
732
|
}
|
733
|
+
else {
|
734
|
+
nativeAcceptingImportMaps = false;
|
735
|
+
}
|
736
|
+
importMapPromise = importMapPromise.then(async () => {
|
737
|
+
importMap = resolveAndComposeImportMap(script.src ? await (await fetchHook(script.src)).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
|
738
|
+
});
|
722
739
|
}
|
723
740
|
|
724
|
-
function
|
725
|
-
script.
|
741
|
+
function processScript (script) {
|
742
|
+
if (script.ep) // ep marker = script processed
|
743
|
+
return;
|
744
|
+
if (script.getAttribute('noshim') !== null)
|
745
|
+
return;
|
746
|
+
// empty inline scripts sometimes show before domready
|
747
|
+
if (!script.src && !script.innerHTML)
|
748
|
+
return;
|
749
|
+
script.ep = true;
|
750
|
+
// does this load block readystate complete
|
751
|
+
const isReadyScript = readyStateCompleteCnt > 0;
|
752
|
+
// does this load block DOMContentLoaded
|
753
|
+
const isDomContentLoadedScript = domContentLoadedCnt > 0;
|
754
|
+
if (isReadyScript) readyStateCompleteCnt++;
|
755
|
+
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
756
|
+
const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, isReadyScript && lastStaticLoadPromise).catch(onerror);
|
757
|
+
if (isReadyScript)
|
758
|
+
lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
|
759
|
+
if (isDomContentLoadedScript)
|
760
|
+
loadPromise.then(domContentLoadedCheck);
|
726
761
|
}
|
727
762
|
|
728
763
|
const fetchCache = {};
|
@@ -735,22 +770,8 @@
|
|
735
770
|
fetchCache[link.href] = doFetch(link.href, getFetchOpts(link));
|
736
771
|
}
|
737
772
|
|
738
|
-
new MutationObserver(mutations => {
|
739
|
-
for (const mutation of mutations) {
|
740
|
-
if (mutation.type !== 'childList') continue;
|
741
|
-
for (const node of mutation.addedNodes) {
|
742
|
-
if (node.tagName === 'SCRIPT' && node.type)
|
743
|
-
processScript(node);
|
744
|
-
else if (node.tagName === 'LINK' && node.rel === 'modulepreload')
|
745
|
-
processPreload(node);
|
746
|
-
}
|
747
|
-
}
|
748
|
-
}).observe(document, { childList: true, subtree: true });
|
749
|
-
|
750
773
|
function throwUnresolved (id, parentUrl) {
|
751
774
|
throw Error("Unable to resolve specifier '" + id + (parentUrl ? "' from " + parentUrl : "'"));
|
752
775
|
}
|
753
776
|
|
754
|
-
|
755
|
-
|
756
|
-
}());
|
777
|
+
}());
|
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.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|