importmap-rails 1.2.1 → 1.2.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: 33dce6ec9c0694844753828ea342c40c03dc7cc07460461b37e0310e995b9238
4
- data.tar.gz: fa91a5de60f67973d7075e58c0f6ac45cf74bc023d96407072c65c616f546472
3
+ metadata.gz: 4aeaabf5f2e5ff22f899b925176126c59d50f0160fc380b2614ba90ef187b077
4
+ data.tar.gz: 7b2a751caf4d3e8a6669fbef2ca9165b5a25681240cb4656e1a24094628e9ff2
5
5
  SHA512:
6
- metadata.gz: 79168173967c286f3ffa36b912cd6a230159f225d1842a0d458b05a54ec8e53ac051cf7fd5903ffab43348b0bfcdf17f17cb1d065de31af6b4b392a5da33e039
7
- data.tar.gz: d8eb7c52ace629023a350c01755f2f3a17a8b835905b019bb51599af9e058e2de213902acb1e3fa5b7d4d31f9a623f075b697b5270f5547de98c087a37096672
6
+ metadata.gz: 1010224d71e6d9e7d9f4a4da395fd025b87a7c765be93917afb5160cc7a6f2aa25829c4cbad98b49ea2d6b813c5770acff76172dd200fa520219f2e44e80bb8b
7
+ data.tar.gz: 54c230bb6c7fefeb91f1b84cba05d826c3883a29dfeba49b4e0cbd68253e68cd16acd59240a3a481bd09e75605b44c6fd7664deae4163b5e26dcd1bcb6de1a80
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,3 @@
1
1
  module Importmap
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
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.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: 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