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 +4 -4
- data/README.md +33 -96
- data/app/helpers/importmap/importmap_tags_helper.rb +3 -20
- data/lib/importmap/commands.rb +16 -22
- data/lib/importmap/engine.rb +0 -1
- data/lib/importmap/map.rb +4 -4
- data/lib/importmap/npm.rb +2 -2
- data/lib/importmap/reloader.rb +3 -0
- data/lib/importmap/version.rb +1 -1
- data/lib/importmap-rails.rb +1 -1
- data/lib/install/config/importmap.rb +1 -1
- data/lib/tasks/importmap_tasks.rake +1 -1
- metadata +17 -7
- data/app/assets/javascripts/es-module-shims.js +0 -947
- data/app/assets/javascripts/es-module-shims.js.map +0 -1
- data/app/assets/javascripts/es-module-shims.min.js +0 -3
- data/lib/shim.js +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1409421a79c426cb82404b0c910dedb0c5ec2dc733304e5f907f92067cfb208
|
4
|
+
data.tar.gz: 138353eac33ffcbbe8a80ce4a8202485792e4609122409478bc5dc9fa324650d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.
|
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
|
-
|
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
|
-
```
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
-
|
86
|
+
Allows you to:
|
98
87
|
|
99
88
|
```js
|
100
|
-
|
101
|
-
import
|
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
|
-
|
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
|
-
|
98
|
+
Importmap for Rails downloads and vendors your npm package dependencies via JavaScript CDNs that provide pre-compiled distribution versions.
|
149
99
|
|
150
|
-
|
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
|
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
|
117
|
+
If you later wish to remove a downloaded pin:
|
168
118
|
|
169
119
|
```bash
|
170
|
-
./bin/importmap unpin react
|
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
|
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: "
|
187
|
-
pin "md5",
|
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="
|
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",
|
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
|
-
]
|
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`
|
data/lib/importmap/commands.rb
CHANGED
@@ -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
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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
|
-
|
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
|
136
|
+
puts divider if row_number == 0
|
142
137
|
end
|
143
|
-
puts head
|
144
138
|
end
|
145
139
|
end
|
146
140
|
|
data/lib/importmap/engine.rb
CHANGED
@@ -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:
|
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:
|
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
|
data/lib/importmap/reloader.rb
CHANGED
data/lib/importmap/version.rb
CHANGED
data/lib/importmap-rails.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :importmap do
|
2
2
|
desc "Setup Importmap for the app"
|
3
3
|
task :install do
|
4
|
-
system
|
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:
|
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:
|
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.
|
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
|