importmap-rails 1.2.0 → 2.0.1

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: 05ae43a16c3833329dc34089eedb5b3a0f42a0263272f1f2869bdd313621b8de
4
- data.tar.gz: dad00d735e8243935eeab41506d99fb662ac660b6c85589eff96512ba0b98508
3
+ metadata.gz: f1409421a79c426cb82404b0c910dedb0c5ec2dc733304e5f907f92067cfb208
4
+ data.tar.gz: 138353eac33ffcbbe8a80ce4a8202485792e4609122409478bc5dc9fa324650d
5
5
  SHA512:
6
- metadata.gz: 2930064ddef0b52f7278fcbba4953fe82f66e3055706a4acdebedba0adb9a21377b913c7cf2730c0e8cdb32fc9518b806b6e79c6f46016a05c0e1b2479cb6b30
7
- data.tar.gz: 39c0b836a735241cabe2a734d206a2cc48f7cb6fbf6e0b5fb2633c845bef1c875e585cacd459f598df8d7b2e8bc84217631e4e669c1e7f8f18939602b763d015
6
+ metadata.gz: 3f248fc4722407b75d81d533c52b368a8a12fceaf10ba9cd7d103c10a103d0722013910eaecdc824cd5076a0fd073fefa6c08020bd97a5a5d9948fb696091416
7
+ data.tar.gz: 56ca2998ed2b6e73b50d691da2894593dbf31f2092cc16db5c26cb7aea46ebb71995660ee75945daaf5a32e355fe953d3d141b4612ab87e56744ce70e4cbcc65
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  With this approach you'll ship many small JavaScript files instead of one big JavaScript file. Thanks to HTTP/2 that no longer carries a material performance penalty during the initial transport, and in fact offers substantial benefits over the long run due to better caching dynamics. Whereas before any change to any JavaScript file included in your big bundle would invalidate the cache for the whole bundle, now only the cache for that single file is invalidated.
6
6
 
7
- There's [native support for import maps in Chrome/Edge 89+/Firefox 108+](https://caniuse.com/?search=importmap), and [a shim available](https://github.com/guybedford/es-module-shims) for any browser with basic ESM support. So your app will be able to work with all the evergreen browsers.
7
+ [Import maps are supported natively in all major, modern browsers](https://caniuse.com/?search=importmap). If you need to work with legacy browsers without native support, you can explore using [the shim available](https://github.com/guybedford/es-module-shims).
8
8
 
9
9
 
10
10
  ## Installation
@@ -16,6 +16,15 @@ Importmap for Rails is automatically included in Rails 7+ for new applications,
16
16
 
17
17
  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.
18
18
 
19
+ You can pin those libraries manually by relying on the compiled versions included in Rails like this:
20
+
21
+ ```ruby
22
+ pin "@rails/actioncable", to: "actioncable.esm.js"
23
+ pin "@rails/activestorage", to: "activestorage.esm.js"
24
+ pin "@rails/actiontext", to: "actiontext.esm.js"
25
+ pin "trix"
26
+ ```
27
+
19
28
  ## How do importmaps work?
20
29
 
21
30
  At their core, importmaps are essentially a string substitution for what are referred to as "bare module specifiers". A "bare module specifier" looks like this: `import React from "react"`. This is not compatible with the ES Module loader spec. Instead, to be ESM compatible, you must provide 1 of the 3 following types of specifiers:
@@ -57,100 +66,41 @@ import React from "react"
57
66
 
58
67
  The import map is setup through `Rails.application.importmap` via the configuration in `config/importmap.rb`. 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.
59
68
 
60
- This 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/javascript/application.js`.
69
+ This 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. Then 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/javascript/application.js`.
61
70
 
62
71
  It's in `app/javascript/application.js` you setup your application by importing any of the modules that have been defined in the import map. You can use the full ESM functionality of importing any particular export of the modules or everything.
63
72
 
64
73
  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 won't have to change any module imports.
65
74
 
75
+ ### Local modules
66
76
 
67
- ## Using npm packages via JavaScript CDNs
68
-
69
- Importmap for Rails is designed to be used with JavaScript CDNs for your npm package dependencies. The CDNs provide pre-compiled distribution versions ready to use, and offer a fast, efficient way of serving them.
70
-
71
- You can use the `./bin/importmap` command that's added as part of the install to pin, unpin, or update npm packages in your import map. This command uses an API from [JSPM.org](https://jspm.org) to resolve your package dependencies efficiently, and then add the pins to your `config/importmap.rb` file. It can resolve these dependencies from JSPM itself, but also from other CDNs, like [unpkg.com](https://unpkg.com) and [jsdelivr.com](https://www.jsdelivr.com).
72
-
73
- It works like so:
77
+ If you want to import local js module files from `app/javascript/src` or other sub-folders of `app/javascript` (such as `channels`), you must pin these to be able to import them. You can use `pin_all_from` to pick all files in a specific folder, so you don't have to `pin` each module individually.
74
78
 
75
- ```bash
76
- ./bin/importmap pin react react-dom
77
- Pinning "react" to https://ga.jspm.io/npm:react@17.0.2/index.js
78
- Pinning "react-dom" to https://ga.jspm.io/npm:react-dom@17.0.2/index.js
79
- Pinning "object-assign" to https://ga.jspm.io/npm:object-assign@4.1.1/index.js
80
- Pinning "scheduler" to https://ga.jspm.io/npm:scheduler@0.20.2/index.js
81
-
82
- ./bin/importmap json
83
-
84
- {
85
- "imports": {
86
- "application": "/assets/application-37f365cbecf1fa2810a8303f4b6571676fa1f9c56c248528bc14ddb857531b95.js",
87
- "react": "https://ga.jspm.io/npm:react@17.0.2/index.js",
88
- "react-dom": "https://ga.jspm.io/npm:react-dom@17.0.2/index.js",
89
- "object-assign": "https://ga.jspm.io/npm:object-assign@4.1.1/index.js",
90
- "scheduler": "https://ga.jspm.io/npm:scheduler@0.20.2/index.js"
91
- }
92
- }
79
+ ```rb
80
+ # config/importmap.rb
81
+ pin_all_from 'app/javascript/src', under: 'src', to: 'src'
93
82
  ```
94
83
 
95
- As you can see, the two packages react and react-dom resolve to a total of four dependencies, when resolved via the jspm default.
84
+ The `:to` parameter is only required if you want to change the destination logical import name. If you drop the :to option, you must place the :under option directly after the first parameter.
96
85
 
97
- Now you can use these in your application.js entrypoint like you would any other module:
86
+ Allows you to:
98
87
 
99
88
  ```js
100
- import React from "react"
101
- import ReactDOM from "react-dom"
89
+ // app/javascript/application.js
90
+ import { ExampleFunction } from 'src/example_function'
102
91
  ```
92
+ Which imports the function from `app/javascript/src/example_function.js`.
103
93
 
104
- You can also designate a specific version to pin:
105
-
106
- ```bash
107
- ./bin/importmap pin react@17.0.1
108
- Pinning "react" to https://ga.jspm.io/npm:react@17.0.1/index.js
109
- Pinning "object-assign" to https://ga.jspm.io/npm:object-assign@4.1.1/index.js
110
- ```
111
-
112
- Or even remove pins:
113
-
114
- ```bash
115
- ./bin/importmap unpin react
116
- Unpinning "react"
117
- Unpinning "object-assign"
118
- ```
119
-
120
- If you pin a package that has already been pinned, it'll be updated inline, along with its dependencies.
121
-
122
- You can control the environment of the package for packages with separate "production" (the default) and "development" builds:
123
-
124
- ```bash
125
- ./bin/importmap pin react --env development
126
- Pinning "react" to https://ga.jspm.io/npm:react@17.0.2/dev.index.js
127
- Pinning "object-assign" to https://ga.jspm.io/npm:object-assign@4.1.1/index.js
128
- ```
129
-
130
- You can also pick an alternative, supported CDN provider when pinning, like `unpkg` or `jsdelivr` (`jspm` is the default):
131
-
132
- ```bash
133
- ./bin/importmap pin react --from jsdelivr
134
- Pinning "react" to https://cdn.jsdelivr.net/npm/react@17.0.2/index.js
135
- ```
136
-
137
- Remember, though, that if you switch a pin from one provider to another, you may have to clean up dependencies added by the first provider that isn't used by the second provider.
138
-
139
- Run `./bin/importmap` to see all options.
140
-
141
- Note that this command is merely a convenience wrapper to resolving logical package names to CDN URLs. You can also just lookup the CDN URLs yourself, and then pin those. For example, if you wanted to use Skypack for React, you could just add the following to `config/importmap.rb`:
142
-
143
- ```ruby
144
- pin "react", to: "https://cdn.skypack.dev/react"
145
- ```
94
+ Note: Sprockets used to serve assets (albeit without filename digests) it couldn't find from the `app/javascripts` folder with logical relative paths, meaning pinning local files wasn't needed. Propshaft doesn't have this fallback, so when you use Propshaft you have to pin your local modules.
146
95
 
96
+ ## Using npm packages via JavaScript CDNs
147
97
 
148
- ## Downloading vendor files from the JavaScript CDN
98
+ Importmap for Rails downloads and vendors your npm package dependencies via JavaScript CDNs that provide pre-compiled distribution versions.
149
99
 
150
- If you don't want to use a JavaScript CDN in production, you can also download vendored files from the CDN when you're setting up your pins:
100
+ You can use the `./bin/importmap` command that's added as part of the install to pin, unpin, or update npm packages in your import map. This command uses an API from [JSPM.org](https://jspm.org) to resolve your package dependencies efficiently, and then add the pins to your `config/importmap.rb` file. It can resolve these dependencies from JSPM itself, but also from other CDNs, like [unpkg.com](https://unpkg.com) and [jsdelivr.com](https://www.jsdelivr.com).
151
101
 
152
102
  ```bash
153
- ./bin/importmap pin react --download
103
+ ./bin/importmap pin react
154
104
  Pinning "react" to vendor/react.js via download from https://ga.jspm.io/npm:react@17.0.2/index.js
155
105
  Pinning "object-assign" to vendor/object-assign.js via download from https://ga.jspm.io/npm:object-assign@4.1.1/index.js
156
106
  ```
@@ -164,33 +114,30 @@ pin "object-assign" # https://ga.jspm.io/npm:object-assign@4.1.1/index.js
164
114
 
165
115
  The packages are downloaded to `vendor/javascript`, which you can check into your source control, and they'll be available through your application's own asset pipeline serving.
166
116
 
167
- If you later wish to remove a downloaded pin, you again pass `--download`:
117
+ If you later wish to remove a downloaded pin:
168
118
 
169
119
  ```bash
170
- ./bin/importmap unpin react --download
120
+ ./bin/importmap unpin react
171
121
  Unpinning and removing "react"
172
122
  Unpinning and removing "object-assign"
173
123
  ```
174
124
 
175
- Just like with a normal pin, you can also update a pin by running the `pin --download` command again.
176
-
177
-
178
125
  ## Preloading pinned modules
179
126
 
180
- To avoid the waterfall effect where the browser has to load one file after another before it can get to the deepest nested import, importmap-rails supports [modulepreload links](https://developers.google.com/web/updates/2017/12/modulepreload). Pinned modules can be preloaded by appending `preload: true` to the pin.
127
+ To avoid the waterfall effect where the browser has to load one file after another before it can get to the deepest nested import, importmap-rails uses [modulepreload links](https://developers.google.com/web/updates/2017/12/modulepreload) by default. If you don't want to preload a dependency, because you want to load it on-demand for efficiency, append `preload: false` to the pin.
181
128
 
182
129
  Example:
183
130
 
184
131
  ```ruby
185
132
  # config/importmap.rb
186
- pin "@github/hotkey", to: "https://ga.jspm.io/npm:@github/hotkey@1.4.4/dist/index.js", preload: true
187
- pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js"
133
+ pin "@github/hotkey", to: "@github--hotkey.js" # file lives in vendor/javascript/@github--hotkey.js
134
+ pin "md5", preload: false # file lives in vendor/javascript/md5.js
188
135
 
189
136
  # app/views/layouts/application.html.erb
190
137
  <%= javascript_importmap_tags %>
191
138
 
192
139
  # will include the following link before the importmap is setup:
193
- <link rel="modulepreload" href="https://ga.jspm.io/npm:@github/hotkey@1.4.4/dist/index.js">
140
+ <link rel="modulepreload" href="/assets/javascript/@github--hotkey.js">
194
141
  ...
195
142
  ```
196
143
 
@@ -239,7 +186,7 @@ Pin your js file:
239
186
  ```rb
240
187
  # config/importmap.rb
241
188
  # ... other pins...
242
- pin "checkout"
189
+ pin "checkout", preload: false
243
190
  ```
244
191
 
245
192
  Import your module on the specific page. Note: you'll likely want to use a `content_for` block on the specifc page/partial, then yield it in your layout.
@@ -289,16 +236,6 @@ module MyEngine
289
236
  end
290
237
  ```
291
238
 
292
- ## Expected errors from using the es-module-shim
293
-
294
- While import maps are native in Chrome, Edge, and Firefox, they need a shim in other browsers that'll produce a JavaScript console error like `TypeError: Module specifier, 'application' does not start with "/", "./", or "../".`. This error is normal and does not have any user-facing consequences.
295
-
296
- In Firefox. when opening the browser console, the asm.js module lexer build will run in unoptimized mode due to the debugger attaching. This gives a warning message `"asm.js type error: Disabled because no suitable wasm compiler is available"` which is as expected. When the console is closed again, the asm.js optimizations are fully applied, and this can even be verified with the console open by disabling the debugger in `about:config` and reloading the page.
297
-
298
- ## Turning off the shim
299
-
300
- Under certain circumstances, like running system tests using chromedriver under CI (which may be resource constrained and trigger errors in certain cases), you may want to explicitly turn off including the shim. You can do this by calling the bulk tag helper with `javascript_importmap_tags("application", shim: false)`. Thus you can pass in something like `shim: !ENV["CI"]`. If you want, and are sure you're not doing any full-page caching, you can also connect this directive to a user agent check (using a gem like `useragent`) to check whether the browser is chrome/edge 89+/firefox 108+. But you really shouldn't have to, as the shim is designed to gracefully work with natively compatible drivers.
301
-
302
239
  ## Checking for outdated or vulnerable packages
303
240
 
304
241
  Importmap for Rails provides two commands to check your pinned packages:
@@ -1,13 +1,11 @@
1
1
  module Importmap::ImportmapTagsHelper
2
2
  # Setup all script tags needed to use an importmap-powered entrypoint (which defaults to application.js)
3
- def javascript_importmap_tags(entry_point = "application", shim: true, importmap: Rails.application.importmap)
3
+ def javascript_importmap_tags(entry_point = "application", importmap: Rails.application.importmap)
4
4
  safe_join [
5
5
  javascript_inline_importmap_tag(importmap.to_json(resolver: self)),
6
6
  javascript_importmap_module_preload_tags(importmap),
7
- (javascript_importmap_shim_nonce_configuration_tag if shim),
8
- (javascript_importmap_shim_tag if shim),
9
7
  javascript_import_module_tag(entry_point)
10
- ].compact, "\n"
8
+ ], "\n"
11
9
  end
12
10
 
13
11
  # Generate an inline importmap tag using the passed `importmap_json` JSON string.
@@ -17,25 +15,10 @@ module Importmap::ImportmapTagsHelper
17
15
  type: "importmap", "data-turbo-track": "reload", nonce: request&.content_security_policy_nonce
18
16
  end
19
17
 
20
- # Configure es-modules-shim with nonce support if the application is using a content security policy.
21
- def javascript_importmap_shim_nonce_configuration_tag
22
- if request&.content_security_policy
23
- tag.script({ nonce: request.content_security_policy_nonce }.to_json.html_safe,
24
- type: "esms-options", nonce: request.content_security_policy_nonce)
25
- end
26
- end
27
-
28
- # Include the es-modules-shim needed to make importmaps work in browsers without native support (like Firefox + Safari).
29
- def javascript_importmap_shim_tag(minimized: true)
30
- javascript_include_tag minimized ? "es-module-shims.min.js" : "es-module-shims.js",
31
- async: true, "data-turbo-track": "reload", nonce: request&.content_security_policy_nonce
32
- end
33
-
34
18
  # Import a named JavaScript module(s) using a script-module tag.
35
19
  def javascript_import_module_tag(*module_names)
36
20
  imports = Array(module_names).collect { |m| %(import "#{m}") }.join("\n")
37
- tag.script imports.html_safe,
38
- type: "module", nonce: request&.content_security_policy_nonce
21
+ tag.script imports.html_safe, type: "module", nonce: request&.content_security_policy_nonce
39
22
  end
40
23
 
41
24
  # Link tags for preloading all modules marked as preload: true in the `importmap`
@@ -12,18 +12,12 @@ class Importmap::Commands < Thor
12
12
  desc "pin [*PACKAGES]", "Pin new packages"
13
13
  option :env, type: :string, aliases: :e, default: "production"
14
14
  option :from, type: :string, aliases: :f, default: "jspm"
15
- option :download, type: :boolean, aliases: :d, default: false
16
15
  def pin(*packages)
17
16
  if imports = packager.import(*packages, env: options[:env], from: options[:from])
18
17
  imports.each do |package, url|
19
- if options[:download]
20
- puts %(Pinning "#{package}" to #{packager.vendor_path}/#{package}.js via download from #{url})
21
- packager.download(package, url)
22
- pin = packager.vendored_pin_for(package, url)
23
- else
24
- puts %(Pinning "#{package}" to #{url})
25
- pin = packager.pin_for(package, url)
26
- end
18
+ puts %(Pinning "#{package}" to #{packager.vendor_path}/#{package}.js via download from #{url})
19
+ packager.download(package, url)
20
+ pin = packager.vendored_pin_for(package, url)
27
21
 
28
22
  if packager.packaged?(package)
29
23
  gsub_file("config/importmap.rb", /^pin "#{package}".*$/, pin, verbose: false)
@@ -39,17 +33,11 @@ class Importmap::Commands < Thor
39
33
  desc "unpin [*PACKAGES]", "Unpin existing packages"
40
34
  option :env, type: :string, aliases: :e, default: "production"
41
35
  option :from, type: :string, aliases: :f, default: "jspm"
42
- option :download, type: :boolean, aliases: :d, default: false
43
36
  def unpin(*packages)
44
37
  if imports = packager.import(*packages, env: options[:env], from: options[:from])
45
38
  imports.each do |package, url|
46
39
  if packager.packaged?(package)
47
- if options[:download]
48
- puts %(Unpinning and removing "#{package}")
49
- else
50
- puts %(Unpinning "#{package}")
51
- end
52
-
40
+ puts %(Unpinning and removing "#{package}")
53
41
  packager.remove(package)
54
42
  end
55
43
  end
@@ -87,9 +75,7 @@ class Importmap::Commands < Thor
87
75
 
88
76
  desc "outdated", "Check for outdated packages"
89
77
  def outdated
90
- outdated_packages = npm.outdated_packages
91
-
92
- if outdated_packages.any?
78
+ if (outdated_packages = npm.outdated_packages).any?
93
79
  table = [["Package", "Current", "Latest"]]
94
80
  outdated_packages.each { |p| table << [p.name, p.current_version, p.latest_version || p.error] }
95
81
 
@@ -103,6 +89,15 @@ class Importmap::Commands < Thor
103
89
  end
104
90
  end
105
91
 
92
+ desc "update", "Update outdated package pins"
93
+ def update
94
+ if (outdated_packages = npm.outdated_packages).any?
95
+ pin outdated_packages.map(&:name)
96
+ else
97
+ puts "No outdated packages found"
98
+ end
99
+ end
100
+
106
101
  desc "packages", "Print out packages with version numbers"
107
102
  def packages
108
103
  puts npm.packages_with_versions.map { |x| x.join(' ') }
@@ -133,14 +128,13 @@ class Importmap::Commands < Thor
133
128
  row.each_with_index.map{ |iterand, index| [lengths[index] || 0, iterand.to_s.length].max }
134
129
  end
135
130
 
136
- puts head = "+" + (column_sizes.map { |s| "-" * (s + 2) }.join('+')) + '+'
131
+ divider = "|" + (column_sizes.map { |s| "-" * (s + 2) }.join('|')) + '|'
137
132
  array.each_with_index do |row, row_number|
138
133
  row = row.fill(nil, row.size..(column_sizes.size - 1))
139
134
  row = row.each_with_index.map { |v, i| v.to_s + " " * (column_sizes[i] - v.to_s.length) }
140
135
  puts "| " + row.join(" | ") + " |"
141
- puts head if row_number == 0
136
+ puts divider if row_number == 0
142
137
  end
143
- puts head
144
138
  end
145
139
  end
146
140
 
@@ -43,7 +43,6 @@ module Importmap
43
43
 
44
44
  initializer "importmap.assets" do |app|
45
45
  if app.config.respond_to?(:assets)
46
- app.config.assets.precompile += %w( es-module-shims.js es-module-shims.min.js es-module-shims.js.map )
47
46
  app.config.assets.paths << Rails.root.join("app/javascript")
48
47
  app.config.assets.paths << Rails.root.join("vendor/javascript")
49
48
  end
data/lib/importmap/map.rb CHANGED
@@ -25,12 +25,12 @@ class Importmap::Map
25
25
  self
26
26
  end
27
27
 
28
- def pin(name, to: nil, preload: false)
28
+ def pin(name, to: nil, preload: true)
29
29
  clear_cache
30
30
  @packages[name] = MappedFile.new(name: name, path: to || "#{name}.js", preload: preload)
31
31
  end
32
32
 
33
- def pin_all_from(dir, under: nil, to: nil, preload: false)
33
+ def pin_all_from(dir, under: nil, to: nil, preload: true)
34
34
  clear_cache
35
35
  @directories[dir] = MappedDir.new(dir: dir, under: under, path: to, preload: preload)
36
36
  end
@@ -145,11 +145,11 @@ class Importmap::Map
145
145
  end
146
146
 
147
147
  def module_path_from(filename, mapping)
148
- [ mapping.path || mapping.under, filename.to_s ].compact.join("/")
148
+ [ mapping.path || mapping.under, filename.to_s ].compact.reject(&:empty?).join("/")
149
149
  end
150
150
 
151
151
  def find_javascript_files_in_tree(path)
152
- Dir[path.join("**/*.js{,m}")].collect { |file| Pathname.new(file) }.select(&:file?)
152
+ Dir[path.join("**/*.js{,m}")].sort.collect { |file| Pathname.new(file) }.select(&:file?)
153
153
  end
154
154
 
155
155
  def absolute_root_of(path)
data/lib/importmap/npm.rb CHANGED
@@ -48,8 +48,8 @@ class Importmap::Npm
48
48
  # We cannot use the name after "pin" because some dependencies are loaded from inside packages
49
49
  # Eg. pin "buffer", to: "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.19/nodelibs/browser/buffer.js"
50
50
 
51
- importmap.scan(/^pin .*(?<=npm:|npm\/|skypack\.dev\/|unpkg\.com\/)(.*)(?=@\d+\.\d+\.\d+)@(\d+\.\d+\.\d+(?:[^\/\s"]*)).*$/) |
52
- importmap.scan(/^pin "([^"]*)".* #.*@(\d+\.\d+\.\d+(?:[^\s]*)).*$/)
51
+ importmap.scan(/^pin .*(?<=npm:|npm\/|skypack\.dev\/|unpkg\.com\/)(.*)(?=@\d+\.\d+\.\d+)@(\d+\.\d+\.\d+(?:[^\/\s["']]*)).*$/) |
52
+ importmap.scan(/^pin ["']([^["']]*)["'].* #.*@(\d+\.\d+\.\d+(?:[^\s]*)).*$/)
53
53
  end
54
54
 
55
55
  private
@@ -1,3 +1,6 @@
1
+ require "active_support"
2
+ require "active_support/core_ext/module/delegation"
3
+
1
4
  class Importmap::Reloader
2
5
  delegate :execute_if_updated, :execute, :updated?, to: :updater
3
6
 
@@ -1,3 +1,3 @@
1
1
  module Importmap
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -3,4 +3,4 @@ end
3
3
 
4
4
  require "importmap/version"
5
5
  require "importmap/reloader"
6
- require "importmap/engine"
6
+ require "importmap/engine" if defined?(Rails::Railtie)
@@ -1,3 +1,3 @@
1
1
  # Pin npm packages by running ./bin/importmap
2
2
 
3
- pin "application", preload: true
3
+ pin "application"
@@ -1,6 +1,6 @@
1
1
  namespace :importmap do
2
2
  desc "Setup Importmap for the app"
3
3
  task :install do
4
- system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
4
+ system RbConfig.ruby, "./bin/rails", "app:template", "LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
5
5
  end
6
6
  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: 1.2.0
4
+ version: 2.0.1
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: 2023-06-18 00:00:00.000000000 Z
11
+ date: 2024-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 6.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 6.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 6.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: actionpack
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -47,9 +61,6 @@ files:
47
61
  - MIT-LICENSE
48
62
  - README.md
49
63
  - Rakefile
50
- - app/assets/javascripts/es-module-shims.js
51
- - app/assets/javascripts/es-module-shims.js.map
52
- - app/assets/javascripts/es-module-shims.min.js
53
64
  - app/helpers/importmap/importmap_tags_helper.rb
54
65
  - lib/importmap-rails.rb
55
66
  - lib/importmap/commands.rb
@@ -62,7 +73,6 @@ files:
62
73
  - lib/install/bin/importmap
63
74
  - lib/install/config/importmap.rb
64
75
  - lib/install/install.rb
65
- - lib/shim.js
66
76
  - lib/tasks/importmap_tasks.rake
67
77
  homepage: https://github.com/rails/importmap-rails
68
78
  licenses:
@@ -85,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
95
  - !ruby/object:Gem::Version
86
96
  version: '0'
87
97
  requirements: []
88
- rubygems_version: 3.4.10
98
+ rubygems_version: 3.4.14
89
99
  signing_key:
90
100
  specification_version: 4
91
101
  summary: Use ESM with importmap to manage modern JavaScript in Rails without transpiling