importmap-rails 1.2.1 → 1.2.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: 33dce6ec9c0694844753828ea342c40c03dc7cc07460461b37e0310e995b9238
4
- data.tar.gz: fa91a5de60f67973d7075e58c0f6ac45cf74bc023d96407072c65c616f546472
3
+ metadata.gz: 5177fd5e9d3aa36dcb9ad47a2990aea48acafe9b11d5ee9186de7be3567aba46
4
+ data.tar.gz: d3f6c34a20bddb2e13dd5fa1840b9df415a7af920c1f0b8854de47b3158548d0
5
5
  SHA512:
6
- metadata.gz: 79168173967c286f3ffa36b912cd6a230159f225d1842a0d458b05a54ec8e53ac051cf7fd5903ffab43348b0bfcdf17f17cb1d065de31af6b4b392a5da33e039
7
- data.tar.gz: d8eb7c52ace629023a350c01755f2f3a17a8b835905b019bb51599af9e058e2de213902acb1e3fa5b7d4d31f9a623f075b697b5270f5547de98c087a37096672
6
+ metadata.gz: a8320c74f6f8af0515aaf518a0fe6c60f595cc30f0006eb82268eb0097cc141a7dd8353ee7712d7a804bf5bec7a37520047c9deefd61e75624ea343c437a74dc
7
+ data.tar.gz: 683b27fe8a26e146ee381424eb3a4e297e8f87ab87178c746fe029ffcf90cfa66e2a8ca45eb746d5b4685cde7d508ec53ea935f82c94ef02f30e148a0fee6f98
data/README.md CHANGED
@@ -63,6 +63,27 @@ It's in `app/javascript/application.js` you setup your application by importing
63
63
 
64
64
  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
65
 
66
+ ### Local modules
67
+
68
+ 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.
69
+ You can use `pin_all_from` to pick all files in a specific folder, so you don't have to `pin` each module individually.
70
+
71
+ ```rb
72
+ # config/importmap.rb
73
+ pin_all_from 'app/javascript/src`, under: 'src', to: 'src'
74
+ ```
75
+
76
+ 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.
77
+
78
+ Allows you to:
79
+
80
+ ```js
81
+ // app/javascript/application.js
82
+ import { ExampleFunction } from 'src/example_function'
83
+ ```
84
+ Which imports the function from `app/javascript/src/example_function.js`.
85
+
86
+ 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.
66
87
 
67
88
  ## Using npm packages via JavaScript CDNs
68
89
 
data/lib/importmap/map.rb CHANGED
@@ -145,7 +145,7 @@ 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)
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.1"
2
+ VERSION = "1.2.3"
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)
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.1
4
+ version: 1.2.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: 2023-06-18 00:00:00.000000000 Z
11
+ date: 2023-10-27 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