ember-cli-rails-assets 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a14199abf9cfa5f0faf079ea10fbc134cf701d48d016da69f7d43ed64256fbdf
4
- data.tar.gz: b5d351892f33578fcae89ccdb77966393b2682f634dfe5f3d0ee384e42e095b3
3
+ metadata.gz: '09d4079f97e405aafa40b0b3663fdeaed6ae362e55e84839563856169225aed7'
4
+ data.tar.gz: 2f329df8fb400ff28c6ddb7105589a7a76ff7054606e9007d6955d2090848e61
5
5
  SHA512:
6
- metadata.gz: 52c74aa8f6993613dd16c7e762260ce2818654d043ac80b1627392ac2fbd3cdcbcc3231a9b67125f107b1de4b0aab97f52aaa7f6f9f9fa34025a7fb92a160244
7
- data.tar.gz: 4c639e39672b4cbc07281153c20e3a27d68f233e20a0abd3ab2b03ae130c71c807db7a91acbbcb05121d130fb8f4484e9baedfa1d386da0cf5eca171013c70d7
6
+ metadata.gz: 97f6951bc89beb25aa963e554679415758069fdecb817753c8ce2148137669d159e8bc9384e22cd778ea2aebe371d3b57c9b530188700b442a27f7d8fb07586d
7
+ data.tar.gz: 574368c875b462fd04a08613e8fece7ed186e4b95a8918e3429e37251c3385d3993795feb2c58d34c2777058e0b67323151f0ed73a2de3494512fa686ed065fd
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
@@ -1,6 +1,7 @@
1
1
  require "ember_cli/assets/errors"
2
2
  require "ember_cli/assets/lookup"
3
3
  require "ember_cli/assets/paths"
4
+ require "ember_cli/assets/url"
4
5
 
5
6
  module EmberCliRailsAssetsHelper
6
7
  def include_ember_script_tags(name, prepend: "")
@@ -39,7 +40,7 @@ module EmberCliRailsAssetsHelper
39
40
  assets = EmberCli::Assets::Lookup.new(app)
40
41
 
41
42
  assets.stylesheet_assets.
42
- map { |src| [prepend, src].join }.
43
+ map { |src| mount_asset(src, prepend) }.
43
44
  map { |src| %{<link rel="stylesheet" href="#{src}">}.html_safe }.
44
45
  inject(&:+)
45
46
  end
@@ -69,11 +70,21 @@ module EmberCliRailsAssetsHelper
69
70
  assets = EmberCli::Assets::Lookup.new(app)
70
71
 
71
72
  assets.javascript_assets.
72
- map { |src| [prepend, src].join }.
73
+ map { |src| mount_asset(src, prepend) }.
73
74
  map { |src| %{<script src="#{src}"></script>}.html_safe }.
74
75
  inject(&:+)
75
76
  end
76
77
 
78
+ # `prepend` mounts the build's assets onto a path (or another host), so it only applies to the URLs that point into the build.
79
+ # Assets hosted elsewhere (a CDN, a font service) are already absolute.
80
+ def mount_asset(src, prepend)
81
+ if EmberCli::Assets::Url.remote?(src)
82
+ src
83
+ else
84
+ [prepend, src].join
85
+ end
86
+ end
87
+
77
88
  # Vite builds boot from ES modules declared in dist/index.html, so extract
78
89
  # the tags required for startup (including the config meta tag and
79
90
  # stylesheets) and remap root-absolute paths onto the mount point.
File without changes
@@ -1,5 +1,6 @@
1
1
  require 'nokogiri'
2
2
  require "ember_cli/assets/errors"
3
+ require "ember_cli/assets/url"
3
4
 
4
5
  module EmberCli
5
6
  module Assets
@@ -13,25 +14,35 @@ module EmberCli
13
14
  def javascripts
14
15
  assert_asset_map!
15
16
 
16
- Nokogiri::HTML(index_html.read).css('script').map {|s|
17
- filename = File.basename(s['src'])
18
- asset_matching(/#{Regexp.escape(filename)}\z/)
19
- }
17
+ document.css('script').filter_map { |script| asset_for(script['src']) }
20
18
  end
21
19
 
22
20
  def stylesheets
23
21
  assert_asset_map!
24
22
 
25
- Nokogiri::HTML(index_html.read).css('link[rel="stylesheet"]').map {|s|
26
- filename = File.basename(s['href'])
27
- asset_matching(/#{Regexp.escape(filename)}\z/)
28
- }
23
+ document.css('link[rel="stylesheet"]').filter_map { |link| asset_for(link['href']) }
29
24
  end
30
25
 
31
26
  private
32
27
 
33
28
  attr_reader :name, :asset_map, :index_html
34
29
 
30
+ def document
31
+ @document ||= Nokogiri::HTML(index_html.read)
32
+ end
33
+
34
+ # Assets hosted outside the build (a CDN, a font service) have no entry in the asset map, so their URL is emitted untouched.
35
+ # A tag without a URL (an inline `<script>`) references no asset at all.
36
+ def asset_for(url)
37
+ if url.to_s.empty?
38
+ nil
39
+ elsif Url.remote?(url)
40
+ url
41
+ else
42
+ asset_matching(/#{Regexp.escape(File.basename(url))}\z/)
43
+ end
44
+ end
45
+
35
46
  def asset_matching(regex)
36
47
  matching_asset = files.detect { |asset| asset =~ regex }
37
48
 
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ module EmberCli
2
+ module Assets
3
+ # URLs in a built `index.html` either point into the build output or somewhere else entirely (a CDN, a font service).
4
+ # Only the former are resolved against the build and mounted onto the Rails application.
5
+ module Url
6
+ # Matches a URL that resolves outside the build: one carrying a scheme (`https://example.com/app.css`, `data:…`), and a protocol-relative one (`//example.com/app.css`).
7
+ REMOTE = %r{\A(?:[a-zA-Z][a-zA-Z0-9+.\-]*:|//)}
8
+
9
+ def self.remote?(url)
10
+ REMOTE.match?(url.to_s)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module EmberCli
2
2
  module Assets
3
- VERSION = "0.9.0"
3
+ VERSION = "0.9.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ember-cli-rails-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Doyle
@@ -43,6 +43,7 @@ files:
43
43
  - lib/ember_cli/assets/errors.rb
44
44
  - lib/ember_cli/assets/lookup.rb
45
45
  - lib/ember_cli/assets/paths.rb
46
+ - lib/ember_cli/assets/url.rb
46
47
  - lib/ember_cli/assets/version.rb
47
48
  homepage: https://github.com/tricknotes/ember-cli-rails-assets
48
49
  licenses: