webpacker-remote 0.1.0 → 0.2.0

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: c7c82d3d11b075effbc9efd05042438065ea37b9a46b2ad16298807fa9085706
4
- data.tar.gz: 4e4d31ad15d8f4c9ec935e4dd332a426c7898889575196e42cd8061140799417
3
+ metadata.gz: 635f4710cb86e3d78d8ae1da64807ae12f0bf97e7e3b476fb87a58098c9370f5
4
+ data.tar.gz: 0aa52bce7bfcf825119c82aa1cc215274c929fe3572c8e4e54523555693504ec
5
5
  SHA512:
6
- metadata.gz: 750042b0c9f5132196ad095c4ae340bedaa3d26973c4efe4e45af67c8203ca03f920e2c8a1b16974a5c314d0e03b48f830503503e806d05736db29ac23ce802c
7
- data.tar.gz: ed9d1bb82d933b0d2af2170fc13c517acf996b905fe3a5115d66fcedd37de8a9ac34520efca0bae3e9170fa39c07731d49afdfc772f034875a1a352572860ecf
6
+ metadata.gz: 823dab789035d9160449e109532bac324ee377ed8afd8caea5d4a72395d625cc1826902d2554ac5f7ee8930f3232d759f0276b79e7b703ba033bd62b439fb34e
7
+ data.tar.gz: 799fc8946cdc5a09b83ebe58ec6f7a244041b3e9607a0a33436feb1755fe0a3db7e3ae32ba0c00c2c6029023568e0b960f1ec5d6b75305e108691b321539afea
@@ -9,7 +9,7 @@ jobs:
9
9
  strategy:
10
10
  matrix:
11
11
  ruby: [ '2.7' ]
12
- webpacker: [ '5.2.1' ]
12
+ webpacker: [ '4.3.0', '5.2.1' ]
13
13
  name: Ruby ${{ matrix.ruby }}, Webpacker ${{ matrix.webpacker }}
14
14
  steps:
15
15
  - uses: actions/checkout@v2
@@ -14,7 +14,7 @@ jobs:
14
14
  strategy:
15
15
  matrix:
16
16
  ruby: [ '2.7' ]
17
- webpacker: [ '5.2.1' ]
17
+ webpacker: [ '4.3.0', '5.2.1' ]
18
18
  name: Ruby ${{ matrix.ruby }}, Webpacker ${{ matrix.webpacker }}
19
19
  steps:
20
20
  - uses: actions/checkout@v2
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  .rspec
5
5
  bin
6
6
  coverage/
7
+ *gem
data/README.md CHANGED
@@ -13,13 +13,14 @@
13
13
  - in `config/initializers/remote_webpacker.rb`
14
14
 
15
15
  ```rb
16
- REMOTE_WEBPACKER = Webpacker::Remote.new(uri: 'https://../manifest.json')
16
+ REMOTE_WEBPACKER = Webpacker::Remote.new(root_path: 'https://asset_host/build/', config_path: 'manifest.json')
17
17
  ```
18
18
 
19
19
  - in `app/views/layouts/application.html.erb` (**not** `javascript_pack_tag`)
20
20
 
21
21
  ```rb
22
22
  <%= javascript_packs_with_chunks_tag 'main', webpacker: REMOTE_WEBPACKER %>
23
+ #=> <script src='https://asset_host/build/static/js/main.2e302672.chunk.js'>
23
24
  ```
24
25
 
25
26
  Of course, you can use as many build as you like and do blue-green deployments using gems like `rollout`
@@ -8,6 +8,7 @@ require 'webpacker'
8
8
  class Webpacker::Remote < Webpacker::Instance
9
9
  require 'webpacker/remote/manifest'
10
10
  require 'webpacker/remote/configuration'
11
+ require 'webpacker/remote/helper'
11
12
 
12
13
  VERSION = '0.1.0'
13
14
 
@@ -16,13 +17,20 @@ class Webpacker::Remote < Webpacker::Instance
16
17
  attr_reader :public_manifest_content
17
18
 
18
19
  # fetch early, fail fast
19
- def initialize(uri:, root_path: nil, config_path: nil) # rubocop:disable Lint/UnusedMethodArgument
20
- super(root_path: nil, config_path: nil)
20
+ # rubocop:disable Lint/MissingSuper
21
+ def initialize(root_path: nil, config_path: nil)
22
+ uri = File.join(root_path.to_s, config_path.to_s)
21
23
  @public_manifest_content = JSON.parse(self.class.get_http_response(uri))
22
- @root_path = @config_path = Pathname.new('/non-existing-path-for-ctor-compatibility')
24
+ # deliberately not calling `super` just emulating what's done there
25
+ @config_path = config_path
26
+ @root_path = root_path
23
27
  rescue StandardError => e
24
- raise Error, "#{e.class}: #{e.message}"
28
+ raise Error, <<~MSG
29
+ having {root_path: #{root_path.inspect}, config_path: #{config_path.inspect}}
30
+ #{e.class}: #{e.message}
31
+ MSG
25
32
  end
33
+ # rubocop:enable Lint/MissingSuper
26
34
 
27
35
  def manifest
28
36
  @manifest ||= Webpacker::Remote::Manifest.new(self)
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # better version of https://github.com/rails/webpacker/issues/2054#issuecomment-564173103
4
+ # rewrite all methods by accept direct injection instead of calling `current_webpacker_instance`
5
+ # because we can have same layout with script/link tags from different webpackers
6
+ module Webpacker::Remote::Helper
7
+ METHODS = %i[
8
+ javascript_pack_tag
9
+ javascript_packs_with_chunks_tag
10
+ stylesheet_pack_tag
11
+ stylesheet_packs_with_chunks_tag
12
+ ].freeze
13
+
14
+ METHODS.each do |meth|
15
+ define_method meth do |*names, **options|
16
+ return super(*names, **options) unless options[:webpacker]
17
+
18
+ new_helper = dup
19
+ new_helper.define_singleton_method(:current_webpacker_instance) do
20
+ options[:webpacker]
21
+ end
22
+ new_helper.send(meth, *names, **options.except(:webpacker))
23
+ end
24
+ end
25
+ end
26
+
27
+ unless ENV['SKIP_WEBPACKER_HELPER_OVERRIDE']
28
+ require 'webpacker/helper'
29
+ Webpacker::Helper.prepend Webpacker::Remote::Helper
30
+ end
@@ -6,4 +6,16 @@ class Webpacker::Remote::Manifest < Webpacker::Manifest
6
6
  def load
7
7
  @webpacker.public_manifest_content
8
8
  end
9
+
10
+ def lookup_pack_with_chunks(name, pack_type = {})
11
+ return unless (paths = super)
12
+
13
+ paths.map { |p| File.join(config.root_path.to_s, p) }
14
+ end
15
+
16
+ def lookup(name, pack_type = {})
17
+ return unless (path = super)
18
+
19
+ File.join(config.root_path.to_s, path)
20
+ end
9
21
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'webpacker-remote'
5
- spec.version = '0.1.0'
5
+ spec.version = '0.2.0'
6
6
  spec.authors = ['Vlad Bokov']
7
7
  spec.email = ['vlad@lunatic.cat']
8
8
  spec.license = 'MIT'
@@ -20,9 +20,8 @@ Gem::Specification.new do |spec|
20
20
  end
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_dependency('webpacker', ENV.fetch('WEBPACKER_GEM_VERSION', '~> 5.2'))
23
+ spec.add_dependency('webpacker', ENV.fetch('WEBPACKER_GEM_VERSION', '< 6'))
24
24
 
25
25
  spec.add_development_dependency('rspec', '~> 3.0')
26
- spec.add_development_dependency('rspec-expectations', '~> 3.0')
27
26
  spec.add_development_dependency('simplecov', '~> 0.19')
28
27
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpacker-remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Bokov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-12 00:00:00.000000000 Z
11
+ date: 2021-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webpacker
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.2'
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec-expectations
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: simplecov
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +69,7 @@ files:
83
69
  - Rakefile
84
70
  - lib/webpacker/remote.rb
85
71
  - lib/webpacker/remote/configuration.rb
72
+ - lib/webpacker/remote/helper.rb
86
73
  - lib/webpacker/remote/manifest.rb
87
74
  - webpacker-remote.gemspec
88
75
  homepage: https://github.com/lunatic-cat/webpacker-remote