importmap-rails 0.2.6 → 0.3.2

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: 271785dcc1a13f77093f95d79b7463f615754ea02129d6b7a8ff1d0fb32caf83
4
- data.tar.gz: af98f4e072978fd478ae00bc80d34a9357fd2375fde1bb246125852dbd65f92b
3
+ metadata.gz: c4edb628879c46f984d95884b643013077f408a899a1633f7007ef3274393b65
4
+ data.tar.gz: 627f45fe257131d3432d1f2cf210eb0fd133e286c293b101cfaf5b5a77840a47
5
5
  SHA512:
6
- metadata.gz: 5775f5dd5149baa20c4cc4a9dde8caee59caffcddb2eb4c8ae65c20b5b90a7f8299957760cc6accffd192c250f37e0ec09f871a7b8354301aecf679f4a02ef8a
7
- data.tar.gz: baa9e8cd92f9d5d315d65924aa4e289d3dda8a920619fc202fcbd9e797df68ea1da80cab5569ec41ed6f21c9dd1c5d3cac5c17ac2a4975c84161590d99d6b36f
6
+ metadata.gz: cd44cdb515fed52817f75d453e274846979e9649e997bd4b2b67689a6761b294c33fdf1b7a9909042da0da2b99d11cbb1ad1a626519a2f528aa4cab5b61869ae
7
+ data.tar.gz: 301873edf08bb1c486dcdbebe65afbe5b3ff2d43fd9a78c51b9791e07152ae0742e93fcfd92fb936e2ce97adacc3e9ff3f6d2b3eacd15683e153e1c8d457997d
data/README.md CHANGED
@@ -13,14 +13,14 @@ There's [native support for import maps in Chrome/Edge 89+](https://caniuse.com/
13
13
  2. Run `./bin/bundle install`
14
14
  3. Run `./bin/rails importmap:install`
15
15
 
16
- By default, all the files in `app/assets/javascripts` and the three major Rails JavaScript libraries are already mapped. You can add more mappings in `config/initializers/importmap.rb`.
16
+ By default, all the files in `app/assets/javascripts` and the three major Rails JavaScript libraries are already mapped. You can add more mappings in `config/importmap.rb`.
17
17
 
18
18
  Note: In order to use JavaScript from Rails frameworks like Action Cable, Action Text, and Active Storage, you must be running Rails 7.0+. This was the first version that shipped with ESM compatible builds of these libraries.
19
19
 
20
20
 
21
21
  ## Usage
22
22
 
23
- The import map is configured programmatically through the `Rails.application.config.importmap` assignment, which by default is setup in `config/initializers/importmap.rb` after running the installer. (Note that since this is a config initializer, you must restart your development server after making any changes.)
23
+ The import map is configured programmatically through the `Rails.application.config.importmap` assignment, which by default is setup in `config/importmap.rb` after running the installer. This file is automatically reloaded in development upon changes, but note that you must restart the server if you remove pins and need them gone from the rendered importmap or list of preloads.
24
24
 
25
25
  This programmatically configured import map is inlined in the `<head>` of your application layout using `<%= javascript_importmap_tags %>`, which will setup the JSON configuration inside a `<script type="importmap">` tag. After that, the [es-module-shim](https://github.com/guybedford/es-module-shims) is loaded, and then finally the application entrypoint is imported via `<script type="module">import "application"</script>`. That logical entrypoint, `application`, is mapped in the importmap script tag to the file `app/assets/javascripts/application.js`, which is copied and digested by the asset pipeline.
26
26
 
@@ -29,19 +29,9 @@ It's in `app/assets/javascripts/application.js` you setup your application by im
29
29
  It makes sense to use logical names that match the package names used by NPM, such that if you later want to start transpiling or bundling your code, you'll not have to change any module imports.
30
30
 
31
31
 
32
- ## Use with Hotwire
33
-
34
- This gem was designed for use with [Hotwire](https://hotwired.dev) in mind. The Hotwire gems, like [turbo-rails](https://github.com/hotwired/turbo-rails) and [stimulus-rails](https://github.com/hotwired/stimulus-rails) (both bundled as [hotwire-rails](https://github.com/hotwired/hotwire-rails)), are automatically configured for use with `importmap-rails`. This means you won't have to manually setup the path mapping in `config/initializers/importmap.rb`, and instead can simply refer to the logical names directly in your `app/assets/javascripts/application.js`, like so:
35
-
36
- ```js
37
- import "@hotwired/turbo-rails"
38
- import "@hotwired/stimulus-autoloader"
39
- ```
40
-
41
-
42
32
  ## Use with Skypack (and other CDNs)
43
33
 
44
- Instead of mapping JavaScript modules to files in your application's path, you can also reference them directly from JavaScript CDNs like Skypack. Simply add them to the `config/initializers/importmap.rb` with the URL instead of the local path:
34
+ Instead of mapping JavaScript modules to files in your application's path, you can also reference them directly from JavaScript CDNs like Skypack. Simply add them to the `config/importmap.rb` with the URL instead of the local path:
45
35
 
46
36
  ```ruby
47
37
  Rails.application.config.importmap.draw do
@@ -61,12 +51,12 @@ console.log(md5("Hash it out"))
61
51
 
62
52
  ## Preloading pinned modules
63
53
 
64
- To mitigate the waterfall effect where the browser has to load one file after another before it can get to the deepest nested import, we use [modulepreload links](https://developers.google.com/web/updates/2017/12/modulepreload) in [browsers that support it](https://caniuse.com/?search=modulepreload). Pinned modules are preloaded by default, but you can turn this off with `preload: false`.
54
+ To mitigate the waterfall effect where the browser has to load one file after another before it can get to the deepest nested import, we use [modulepreload links](https://developers.google.com/web/updates/2017/12/modulepreload). Pinned modules are preloaded by default, but you can turn this off with `preload: false`.
65
55
 
66
56
  Example:
67
57
 
68
58
  ```ruby
69
- # config/initializers/importmap.rb
59
+ # config/importmap.rb
70
60
  Rails.application.config.importmap.draw do
71
61
  pin "trix", to: "https://cdn.skypack.dev/trix"
72
62
  pin "md5", to: "https://cdn.skypack.dev/md5", preload: false
@@ -94,5 +84,3 @@ While import maps are native in Chrome and Edge, they need a shim in other brows
94
84
  ## License
95
85
 
96
86
  Importmap for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
97
-
98
-
@@ -1 +1 @@
1
- //= require ./es-module-shims@0.12.2.js
1
+ //= require ./es-module-shims@0.12.6.js
@@ -1,6 +1,6 @@
1
- /* ES Module Shims 0.12.2 */
1
+ /* ES Module Shims 0.12.6 */
2
2
  (function () {
3
- // Temporary hack around https://github.com/guybedford/es-module-shims/issues/148
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 && !nativelyLoaded && !shimMode && !load.n) {
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
- return topLevelLoad(resolve(id, parentUrl).r || throwUnresolved(id, parentUrl), { credentials: 'same-origin' });
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
- return resolve(id, `${parentUrl}`).r || throwUnresolved(id, parentUrl);
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 fetchOptsMap = new Map();
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
- const res = await fetchHook(url, fetchOptsMap.get(url) || fetchOpts);
486
- if (!res.ok)
487
- throw new Error(`${res.status} ${res.statusText} ${res.url}`);
488
- load.r = res.url;
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
- // prepopulate the load record
620
- const fetchOpts = getFetchOpts(link);
621
- // save preloaded fetch options for later load
622
- fetchOptsMap.set(link.href, fetchOpts);
623
- fetch(link.href, fetchOpts);
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
- const urlResolved = resolveIfNotPlainOrUrl(id, parentUrl);
628
- const resolved = resolveImportMap(importMap, urlResolved || id, parentUrl);
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
+ }());
@@ -2,8 +2,8 @@ module Importmap::ImportmapTagsHelper
2
2
  # Setup all script tags needed to use an importmap-powered entrypoint (which defaults to application.js)
3
3
  def javascript_importmap_tags(entry_point = "application")
4
4
  safe_join [
5
- javascript_importmap_module_preload_tags,
6
5
  javascript_inline_importmap_tag,
6
+ javascript_importmap_module_preload_tags,
7
7
  javascript_importmap_shim_tag,
8
8
  javascript_import_module_tag(entry_point)
9
9
  ], "\n"
@@ -6,6 +6,18 @@ module Importmap
6
6
 
7
7
  config.autoload_once_paths = %W( #{root}/app/helpers )
8
8
 
9
+ initializer "importmap.reloader" do |app|
10
+ app.config.paths.add "config/importmap.rb"
11
+
12
+ reloader = Importmap::Reloader.new
13
+
14
+ reloader.execute
15
+ app.reloaders << reloader
16
+ app.reloader.to_run do
17
+ reloader.execute
18
+ end
19
+ end
20
+
9
21
  initializer "importmap.assets" do
10
22
  if Rails.application.config.respond_to?(:assets)
11
23
  Rails.application.config.assets.precompile += %w( es-module-shims.js )
data/lib/importmap/map.rb CHANGED
@@ -10,12 +10,12 @@ class Importmap::Map
10
10
  instance_eval(&block)
11
11
  end
12
12
 
13
- def pin(name, to: nil, preload: false)
13
+ def pin(name, to: nil, preload: true)
14
14
  @files[name] = MappedFile.new(name: name, path: to || "#{name}.js", preload: preload)
15
15
  end
16
16
 
17
- def pin_all_from(path, under: nil, preload: false)
18
- @directories[path] = MappedDir.new(path: path, under: under, preload: preload)
17
+ def pin_all_from(dir, under: nil, to: nil, preload: true)
18
+ @directories[dir] = MappedDir.new(dir: dir, under: under, path: to, preload: preload)
19
19
  end
20
20
 
21
21
  def preloaded_module_paths(resolver:)
@@ -32,7 +32,7 @@ class Importmap::Map
32
32
 
33
33
  private
34
34
  MappedFile = Struct.new(:name, :path, :preload, keyword_init: true)
35
- MappedDir = Struct.new(:path, :under, :preload, keyword_init: true)
35
+ MappedDir = Struct.new(:dir, :path, :under, :preload, keyword_init: true)
36
36
 
37
37
  def cache_as(name)
38
38
  if (cached && result = instance_variable_get("@cached_#{name}"))
@@ -63,11 +63,11 @@ class Importmap::Map
63
63
 
64
64
  def expand_directories_into(paths)
65
65
  @directories.values.each do |mapping|
66
- if (absolute_path = absolute_root_of(mapping.path)).exist?
66
+ if (absolute_path = absolute_root_of(mapping.dir)).exist?
67
67
  find_javascript_files_in_tree(absolute_path).each do |filename|
68
68
  module_filename = filename.relative_path_from(absolute_path)
69
- module_name = module_name_from(module_filename, mapping.under)
70
- module_path = mapping.under ? absolute_path.basename.join(module_filename).to_s : module_filename.to_s
69
+ module_name = module_name_from(module_filename, mapping)
70
+ module_path = module_path_from(module_filename, mapping)
71
71
 
72
72
  paths[module_name] = MappedFile.new(name: module_name, path: module_path, preload: mapping.preload)
73
73
  end
@@ -75,16 +75,12 @@ class Importmap::Map
75
75
  end
76
76
  end
77
77
 
78
- # Strip off the extension, /index, or any versioning data for an absolute module name.
79
- def module_name_from(filename, under)
80
- filename_without_ext = filename.to_s.remove(filename.extname)
78
+ def module_name_from(filename, mapping)
79
+ [ mapping.under, filename.to_s.remove(filename.extname).remove(/\/?index$/).presence ].compact.join("/")
80
+ end
81
81
 
82
- if filename_without_ext == "index" && under
83
- under
84
- else
85
- module_name = filename_without_ext.split("@").first
86
- under ? "#{under}/#{module_name}" : module_name
87
- end
82
+ def module_path_from(filename, mapping)
83
+ [ mapping.path || mapping.under, filename.to_s ].join("/")
88
84
  end
89
85
 
90
86
  def find_javascript_files_in_tree(path)
@@ -0,0 +1,20 @@
1
+ class Importmap::Reloader
2
+ delegate :execute_if_updated, :execute, :updated?, to: :updater
3
+
4
+ def reload!
5
+ import_map_paths.each { |path| load path }
6
+ end
7
+
8
+ private
9
+ def updater
10
+ @updater ||= config.file_watcher.new(import_map_paths) { reload! }
11
+ end
12
+
13
+ def import_map_paths
14
+ config.paths["config/importmap.rb"].existent
15
+ end
16
+
17
+ def config
18
+ Rails.application.config
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Importmap
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -2,4 +2,5 @@ module Importmap
2
2
  end
3
3
 
4
4
  require "importmap/version"
5
+ require "importmap/reloader"
5
6
  require "importmap/engine"
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  say "Create application.js module as entrypoint"
12
12
  create_file Rails.root.join("app/javascript/application.js") do <<-JS
13
- // Configure your import map in config/initializers/importmap.rb
13
+ // Configure your import map in config/importmap.rb
14
14
 
15
15
  // import "@rails/actioncable"
16
16
  // import "@rails/activestorage"
@@ -20,8 +20,8 @@ end
20
20
  say "Ensure JavaScript files are in the asset pipeline manifest"
21
21
  append_to_file Rails.root.join("app/assets/config/manifest.js"), %(//= link_tree ../../javascript .js\n)
22
22
 
23
- say "Configure importmap paths in config/initializers/importmap.rb"
24
- create_file Rails.root.join("config/initializers/importmap.rb") do <<-RUBY
23
+ say "Configure importmap paths in config/importmap.rb"
24
+ create_file Rails.root.join("config/importmap.rb") do <<-RUBY
25
25
  Rails.application.config.importmap.draw do
26
26
  pin "application"
27
27
 
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.2.6
4
+ version: 0.3.2
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-16 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,11 +34,12 @@ 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.2.js
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
41
41
  - lib/importmap/map.rb
42
+ - lib/importmap/reloader.rb
42
43
  - lib/importmap/version.rb
43
44
  - lib/install/install.rb
44
45
  - lib/shim.js