importmap-rails 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4edb628879c46f984d95884b643013077f408a899a1633f7007ef3274393b65
4
- data.tar.gz: 627f45fe257131d3432d1f2cf210eb0fd133e286c293b101cfaf5b5a77840a47
3
+ metadata.gz: 1ad1aceb19e574cd589057539db280a47635d950f02b927fe6cdad83b86ba43e
4
+ data.tar.gz: e6b47536890332ef62639c37cb19ea82b73cc32a51baa3904e1e32c78aa2203c
5
5
  SHA512:
6
- metadata.gz: cd44cdb515fed52817f75d453e274846979e9649e997bd4b2b67689a6761b294c33fdf1b7a9909042da0da2b99d11cbb1ad1a626519a2f528aa4cab5b61869ae
7
- data.tar.gz: 301873edf08bb1c486dcdbebe65afbe5b3ff2d43fd9a78c51b9791e07152ae0742e93fcfd92fb936e2ce97adacc3e9ff3f6d2b3eacd15683e153e1c8d457997d
6
+ metadata.gz: 27c39e5a9a516c97a601f86deb47c93f4653dcbd1f1f774ea3256065c15addf1913338d74f44a4549b0e56d246f8b68b3a05b747b0ccf52937aa64a947886a72
7
+ data.tar.gz: e05d2fc49ec7a8955fda9fbbda78fa717399d8c3cae9d1fef0c5a94957b6678e45cfd8d1eabf2d78516f94ecfb4458c32c637ae59e1c03466f0a7bfaacd9f5ba
@@ -1 +1 @@
1
- //= require ./es-module-shims@0.12.6.js
1
+ //= require ./es-module-shims@0.12.7.js
@@ -1,4 +1,4 @@
1
- /* ES Module Shims 0.12.6 */
1
+ /* ES Module Shims 0.12.7 */
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
@@ -271,7 +271,7 @@
271
271
 
272
272
  let waitingForImportMapsInterval;
273
273
  let firstTopLevelProcess = true;
274
- async function topLevelLoad (url, fetchOpts, source, nativelyLoaded) {
274
+ async function topLevelLoad (url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
275
275
  // no need to even fetch if we have feature support
276
276
  await featureDetectionPromise;
277
277
  if (waitingForImportMapsInterval > 0) {
@@ -285,7 +285,7 @@
285
285
  await importMapPromise;
286
286
  // early analysis opt-out
287
287
  if (nativelyLoaded && supportsDynamicImport && supportsImportMeta && supportsImportMaps && supportsJsonAssertions && supportsCssAssertions && !importMapSrcOrLazy) {
288
- // dont reexec inline for polyfills -> just return null
288
+ // dont reexec inline for polyfills -> just return null (since no module id for executed inline module scripts)
289
289
  return source && nativelyLoaded ? null : dynamicImport(source ? createBlob(source) : url);
290
290
  }
291
291
  await init;
@@ -294,17 +294,30 @@
294
294
  await loadAll(load, seen);
295
295
  lastLoad = undefined;
296
296
  resolveDeps(load, seen);
297
+ await lastStaticLoadPromise;
297
298
  if (source && !shimMode && !load.n) {
299
+ if (lastStaticLoadPromise) {
300
+ didExecForReadyPromise = true;
301
+ if (domContentLoaded)
302
+ didExecForDomContentLoaded = true;
303
+ }
298
304
  const module = dynamicImport(createBlob(source));
299
305
  if (shouldRevokeBlobURLs) revokeObjectURLs(Object.keys(seen));
300
306
  return module;
301
307
  }
302
308
  const module = await dynamicImport(load.b);
309
+ if (lastStaticLoadPromise && (!nativelyLoaded || load.b !== load.u)) {
310
+ didExecForReadyPromise = true;
311
+ if (domContentLoaded)
312
+ didExecForDomContentLoaded = true;
313
+ }
303
314
  // if the top-level load is a shell, run its update function
304
315
  if (load.s) {
305
316
  (await dynamicImport(load.s)).u$_(module);
306
317
  }
307
318
  if (shouldRevokeBlobURLs) revokeObjectURLs(Object.keys(seen));
319
+ // when tla is supported, this should return the tla promise as an actual handle
320
+ // so readystate can still correspond to the sync subgraph exec completions
308
321
  return module;
309
322
  }
310
323
 
@@ -354,6 +367,7 @@
354
367
  const skip = esmsInitOptions.skip || /^https?:\/\/(cdn\.skypack\.dev|jspm\.dev)\//;
355
368
  const onerror = esmsInitOptions.onerror || ((e) => { throw e; });
356
369
  const shouldRevokeBlobURLs = esmsInitOptions.revokeBlobURLs;
370
+ const noLoadEventRetriggers = esmsInitOptions.noLoadEventRetriggers;
357
371
 
358
372
  function urlJsString (url) {
359
373
  return `'${url.replace(/'/g, "\\'")}'`;
@@ -550,7 +564,7 @@
550
564
  return load;
551
565
  }
552
566
 
553
- async function processScripts () {
567
+ function processScripts () {
554
568
  if (waitingForImportMapsInterval > 0 && document.readyState !== 'loading') {
555
569
  clearTimeout(waitingForImportMapsInterval);
556
570
  waitingForImportMapsInterval = 0;
@@ -558,7 +572,7 @@
558
572
  for (const link of document.querySelectorAll('link[rel="modulepreload"]'))
559
573
  processPreload(link);
560
574
  for (const script of document.querySelectorAll('script[type="module-shim"],script[type="importmap-shim"],script[type="module"],script[type="importmap"]'))
561
- await processScript(script);
575
+ processScript(script);
562
576
  }
563
577
 
564
578
  function getFetchOpts (script) {
@@ -576,12 +590,29 @@
576
590
  return fetchOpts;
577
591
  }
578
592
 
579
- async function processScript (script, dynamic) {
593
+ let staticLoadCnt = 0;
594
+ let didExecForReadyPromise = false;
595
+ let didExecForDomContentLoaded = false;
596
+ let lastStaticLoadPromise = Promise.resolve();
597
+ let domContentLoaded = false;
598
+ document.addEventListener('DOMContentLoaded', () => domContentLoaded = true);
599
+ function staticLoadCheck () {
600
+ staticLoadCnt--;
601
+ if (staticLoadCnt === 0 && !noLoadEventRetriggers) {
602
+ if (didExecForDomContentLoaded)
603
+ document.dispatchEvent(new Event('DOMContentLoaded'));
604
+ if (didExecForReadyPromise && document.readyState === 'complete')
605
+ document.dispatchEvent(new Event('readystatechange'));
606
+ }
607
+ }
608
+
609
+ function processScript (script, dynamic) {
580
610
  if (script.ep) // ep marker = script processed
581
611
  return;
582
612
  const shim = script.type.endsWith('-shim');
583
613
  if (shim) shimMode = true;
584
- const type = shim ? script.type.slice(0, -5) : script.type;
614
+ const type = shimMode ? script.type.slice(0, -5) : script.type;
615
+ // dont process module scripts in shim mode or noshim module scripts in polyfill mode
585
616
  if (!shim && shimMode || script.getAttribute('noshim') !== null)
586
617
  return;
587
618
  // empty inline scripts sometimes show before domready
@@ -589,7 +620,14 @@
589
620
  return;
590
621
  script.ep = true;
591
622
  if (type === 'module') {
592
- await topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shim).catch(onerror);
623
+ const isReadyScript = document.readyState !== 'complete';
624
+ if (isReadyScript) staticLoadCnt++;
625
+ const p = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, isReadyScript && lastStaticLoadPromise);
626
+ p.catch(onerror);
627
+ if (isReadyScript) {
628
+ lastStaticLoadPromise = p.catch(staticLoadCheck);
629
+ p.then(staticLoadCheck);
630
+ }
593
631
  }
594
632
  else if (type === 'importmap') {
595
633
  importMapPromise = importMapPromise.then(async () => {
@@ -655,4 +693,4 @@
655
693
  waitingForImportMapsInterval = setInterval(processScripts, 20);
656
694
  }
657
695
 
658
- }());
696
+ }());
@@ -1,3 +1,3 @@
1
1
  module Importmap
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
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.2
4
+ version: 0.3.3
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-08-23 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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.6.js
37
+ - app/assets/javascripts/es-module-shims@0.12.7.js
38
38
  - app/helpers/importmap/importmap_tags_helper.rb
39
39
  - lib/importmap-rails.rb
40
40
  - lib/importmap/engine.rb