sewing_kit 0.32.0.pre.beta.pre.4 → 0.91.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: '008f81a3e9adde12cbfe60d59ae86b0645bfd3b41547d82cef8f0cae15ab481c'
4
- data.tar.gz: e890677d3c76735ce57ce27017288f034e127697033b59649a6e06f89534d9ad
3
+ metadata.gz: 3f6d423df01ea72b33c61ce184e02adec82b1e10b5e490b0be2b125270357982
4
+ data.tar.gz: 54493dde6260a14b4a4bd364541c166a4521c588b8a3ae2191cfe60b12e89b63
5
5
  SHA512:
6
- metadata.gz: 3b1c692d5f1bbdd61cfcd18a523421b3943b482f767bbd29773f9afbc5e787a027dd6a313e21fb861fa2f40258a2ffe39020f5b61b187109156d7de56406c6e4
7
- data.tar.gz: b8d2382294d12cedbfb891c266b3e09262b2bb36d8523f5c1bec1e65528ba9b94fa6ef795e347617635c7e76d191d131aa02ca0467efae27ee9b87fafa8b429e
6
+ metadata.gz: a426f2fdf3447168389f235512c268832e0c841f216cbcb8f5b8e65c8815deb8d696bab5b702d5c35b6cbbcf686fb4a1182694b99660fb0525a81a84dd92611b
7
+ data.tar.gz: ddaf36cd7851bce4d400e78af172c5f66ecb7404fea9e47c424f405e9feda62f1792b2bc4acba372257dd3300c3b81a7d566a04e6b4101a7003c1c0be5d8c9f2
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
- # sewing_kit [![Build status](https://badge.buildkite.com/e7cdc87e61b9fe80e91e8686b6bfba53ca26a36366eb811a50.svg)](https://buildkite.com/shopify/sewing-kit-1)
1
+ # sewing_kit [![Build status](https://badge.buildkite.com/e7cdc87e61b9fe80e91e8686b6bfba53ca26a36366eb811a50.svg)](https://buildkite.com/shopify/sewing-kit-gem-ci)
2
2
 
3
3
  Zero configuration, high performance front end development at organization scale.
4
4
 
5
- This document focuses on Rails integration. For details of `sewing-kit`'s configuration and usage, see the [sewing-kit documentation](https://github.com/Shopify/sewing-kit#sewing-kit).
5
+ This document focuses on Rails integration. For details of `sewing-kit`'s configuration and usage, see the [sewing-kit documentation](/README.md).
6
6
 
7
7
  ## Quick Start
8
+
8
9
  Create a Rails project using `dev init` then:
9
10
 
10
11
  ### Install Sewing Kits
12
+
11
13
  ```sh
12
14
  # Add Ruby/Node dependencies
13
15
  bundle add sewing_kit
@@ -21,9 +23,11 @@ dev up
21
23
  ```
22
24
 
23
25
  ### Add JavaScript
24
- sewing_kit looks for JavaScript in `app/ui/index.js`. The code in `index.js` (and any imported JS/CSS) will be built into a `main` bundle.
26
+
27
+ sewing_kit looks for JavaScript in `app/ui/index.js`. The code in `index.js` (and any imported JS/CSS) will be built into a `main` bundle.
25
28
 
26
29
  ### Link to JS/CSS with `erb` Helpers
30
+
27
31
  The `main` bundle is imported into `erb` files using Rails helpers:
28
32
 
29
33
  ```erb
@@ -34,6 +38,7 @@ The `main` bundle is imported into `erb` files using Rails helpers:
34
38
  **Note:** CSS `<link>` tags appear only in production; in development, CSS is embedded within the `main.js` bundle.
35
39
 
36
40
  ## Minimal Project Layout
41
+
37
42
  ```
38
43
  ├── Gemfile (must contain "gem 'sewing_kit")
39
44
  ├── package.json (must specify '@shopify/sewing-kit' as a 'devDependency')
@@ -47,7 +52,9 @@ The `main` bundle is imported into `erb` files using Rails helpers:
47
52
  ```
48
53
 
49
54
  ## Rails, Polaris, and React Layout
50
- A typical Polaris app will use React to render views and components. The following layout shows best practice locations for:
55
+
56
+ A typical Polaris app will use React to render views and components. The following layout shows best practice locations for:
57
+
51
58
  - Global SCSS settings
52
59
  - App sections (roughly analogous to Rails routes)
53
60
  - Components
@@ -82,29 +89,36 @@ A typical Polaris app will use React to render views and components. The follow
82
89
  ```
83
90
 
84
91
  ## Which version of sewing-kit can I use?
85
- Assume that the sewing_kit gem's latest minor version requires _at least_ the same minor version of the sewing-kit package.
92
+
93
+ Assume that the sewing*kit gem's latest minor version requires \_at least* the same minor version of the sewing-kit package.
86
94
 
87
95
  If sewing-kit makes a breaking change, this gem's minor version will be bumped to match the required sewing-kit version.
88
96
 
89
97
  ## Transitioning from sprockets-commoner
98
+
90
99
  It is currently not recommended to use `sprockets-commoner` and `sewing_kit` in the same project.
91
100
  Minimally, it is required that the project does not have its own `babel-*` libraries that `sewing-kit` currently has as [dependencies](https://github.com/Shopify/sewing-kit/blob/master/package.json#L97~L102).
92
101
 
93
102
  ## React Boilerplate
94
- * Create a React app in `app/ui/App.js` ([example](https://github.com/Shopify/rails_sewing_kit_example/blob/master/app/ui/App.jsx))
95
- * In an `erb` view, add a placeholder for React content ([example](https://github.com/Shopify/rails_sewing_kit_example/blob/master/app/views/home/index.html.erb#L4))
96
- * In `index.js`, render a React component into the placeholder element ([example](https://github.com/Shopify/rails_sewing_kit_example/blob/master/app/ui/index.js))
97
- * Use `sewing_kit_script_tag`/`sewing_kit_link_tag` helpers to link erb/js ([example](https://github.com/Shopify/rails_sewing_kit_example/blob/master/app/views/layouts/application.html.erb#L8))
103
+
104
+ - Create a React app in `app/ui/App.js` ([example](https://github.com/Shopify/rails_sewing_kit_example/blob/master/app/ui/App.jsx))
105
+ - In an `erb` view, add a placeholder for React content ([example](https://github.com/Shopify/rails_sewing_kit_example/blob/master/app/views/home/index.html.erb#L4))
106
+ - In `index.js`, render a React component into the placeholder element ([example](https://github.com/Shopify/rails_sewing_kit_example/blob/master/app/ui/index.js))
107
+ - Use `sewing_kit_script_tag`/`sewing_kit_link_tag` helpers to link erb/js ([example](https://github.com/Shopify/rails_sewing_kit_example/blob/master/app/views/layouts/application.html.erb#L8))
98
108
 
99
109
  ## FAQ
110
+
100
111
  ### How can I fix production builds that are failing due to missing devDependencies?
101
- By moving everything into `package.json#dependencies`. This is necessary because Rails 5.2 prunes `devDependencies` during asset compilation.
112
+
113
+ By moving everything into `package.json#dependencies`. This is necessary because Rails 5.2 prunes `devDependencies` during asset compilation.
102
114
 
103
115
  ### How can I test a production verison of my changes?
104
- Ideally, by deploying to a `staging` environment. If that is not possible, a production-like local development experience is available via:
116
+
117
+ Ideally, by deploying to a `staging` environment. If that is not possible, a production-like local development experience is available via:
118
+
105
119
  ```sh
106
120
  NODE_ENV=production bundle exec rake assets:precompile
107
121
  NODE_ENV=production SK_SIMULATE_PRODUCTION=1 dev run
108
122
  ```
109
123
 
110
- Note that code changes will not be automatically recompiled in this state. After verifying production behaviour, run `bundle exec rake assets:clobber` to get back to development mode.
124
+ Note that code changes will not be automatically recompiled in this state. After verifying production behaviour, run `bundle exec rake assets:clobber` to get back to development mode.
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SewingKit
3
- VERSION = "0.32.0-beta-4"
3
+ VERSION = "0.91.0"
4
4
  end
@@ -17,7 +17,7 @@ module SewingKit
17
17
  def sewing_kit_assets(entrypoint_name, extension: 'js')
18
18
  return '' unless entrypoint_name.present?
19
19
 
20
- assets = SewingKit::Webpack::Manifest.asset_dependencies(entrypoint_name)
20
+ assets = SewingKit::Webpack::Manifest.asset_dependencies(entrypoint_name, request.user_agent)
21
21
 
22
22
  raise UnknownAssetError, "#{entrypoint_name} was not found in manifest." if raise_unknown_error? assets
23
23
  return [] unless assets && assets[extension]
@@ -43,16 +43,10 @@ module SewingKit
43
43
  end
44
44
  end
45
45
 
46
- class LegacyManifestError < StandardError
47
- def initialize(manifest)
48
- super "manifest must contain 'entrypoints' key (found: #{manifest})"
49
- end
50
- end
51
-
52
46
  class << self
53
47
  # :nodoc:
54
- def asset_dependencies(entrypoint_name)
55
- instance.asset_dependencies(entrypoint_name)
48
+ def asset_dependencies(entrypoint_name, user_agent)
49
+ instance.asset_dependencies(entrypoint_name, user_agent)
56
50
  end
57
51
 
58
52
  def clear_cache!
@@ -9,22 +9,30 @@ module SewingKit
9
9
  @metadata = nil
10
10
  end
11
11
 
12
- # :nodoc:
13
- def asset_dependencies(entrypoint_name)
14
- current_metadata = metadata
15
- if current_metadata.key?('development')
16
- current_metadata['development']['hangTight']
17
- else
18
- current_metadata['entrypoints'][entrypoint_name]
19
- end
20
- end
21
-
22
12
  def clear_cache!
23
13
  @metadata = nil
24
14
  end
25
15
 
26
16
  def manifest
27
- metadata['assets']
17
+ current_metadata = metadata
18
+
19
+ if current_metadata.is_a?(Array)
20
+ all_assets = current_metadata.flat_map do |data|
21
+ data['assets']['all'].values
22
+ end
23
+
24
+ # sewing-kit asset manifests return a numerically indexed hash, not a true array,
25
+ # so we need to change it back to a hash for compatibility
26
+ asset_hash = all_assets.each_with_index
27
+ .collect { |asset, index| [index, asset] }
28
+ .to_h
29
+
30
+ {
31
+ "all" => asset_hash,
32
+ }
33
+ else
34
+ current_metadata['assets']
35
+ end
28
36
  end
29
37
 
30
38
  def self.load_metadata_from_node
@@ -10,28 +10,44 @@ module SewingKit
10
10
  @metadata_path = nil
11
11
  end
12
12
 
13
+ def asset_dependencies(entrypoint_name, _target)
14
+ current_metadata = metadata
15
+ if current_metadata.key?('development')
16
+ current_metadata['development']['hangTight']
17
+ else
18
+ current_metadata['entrypoints'][entrypoint_name]
19
+ end
20
+ end
21
+
13
22
  def clear_cache!
14
23
  super
15
24
  @metadata_path = nil
16
25
  end
17
26
 
27
+ def manifest
28
+ raise OnlyUseInProductionError
29
+ end
30
+
18
31
  def metadata
19
32
  load_metadata
20
33
  end
21
34
 
22
35
  def load_metadata
23
36
  begin
24
- return load_metadata_from_fs(@metadata_path) if @metadata_path
37
+ if @metadata_path
38
+ result = load_metadata_from_fs(@metadata_path)
39
+ return normalize_metadata(result)
40
+ end
25
41
  rescue => e
26
42
  Rails.logger.warn "[sewing_kit] could not read manifest from #{@metadata_path}; falling back to node. #{e}"
27
43
  @metadata_path = nil
28
44
  end
29
45
 
30
46
  result = SewingKit::Webpack::Manifest::Base.load_metadata_from_node
31
- raise LegacyManifestError, result unless result['entrypoints'] || result['development']
32
47
 
33
- @metadata_path = result && result['path']
34
- result
48
+ metadata = normalize_metadata(result)
49
+ @metadata_path = metadata && metadata['path']
50
+ metadata
35
51
  end
36
52
 
37
53
  def load_metadata_from_fs(path)
@@ -50,10 +66,25 @@ module SewingKit
50
66
 
51
67
  protected
52
68
 
69
+ def normalize_metadata(maybe_array_metadata)
70
+ if maybe_array_metadata.is_a?(Array)
71
+ maybe_array_metadata.last
72
+ else
73
+ maybe_array_metadata
74
+ end
75
+ end
76
+
53
77
  def mode
54
78
  'development'
55
79
  end
56
80
  end
81
+
82
+ class OnlyUseInProductionError < StandardError
83
+ def initialize
84
+ super "The SewingKit::Webpack::Manifest#manifest is intended "\
85
+ "for deploying assets to a CDN. Do not use it in development."
86
+ end
87
+ end
57
88
  end
58
89
  end
59
90
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'sewing_kit/webpack/manifest/base'
3
+ require 'browserslist_useragent'
3
4
 
4
5
  module SewingKit
5
6
  module Webpack
@@ -9,14 +10,33 @@ module SewingKit
9
10
  @metadata_path = nil
10
11
 
11
12
  # :nodoc:
12
- def asset_dependencies(entrypoint_name)
13
- metadata['entrypoints'][entrypoint_name]
13
+ def asset_dependencies(entrypoint_name, user_agent)
14
+ metadata_for(user_agent)['entrypoints'][entrypoint_name]
14
15
  end
15
16
 
16
17
  def metadata
17
- manifest = SewingKit::CachedProductionManifest
18
- raise LegacyManifestError, manifest unless manifest['entrypoints']
19
- manifest
18
+ SewingKit::CachedProductionManifest
19
+ end
20
+
21
+ private
22
+
23
+ def metadata_for(user_agent)
24
+ if metadata.is_a?(Array)
25
+ find_matching_metadata(metadata, user_agent)
26
+ else
27
+ metadata
28
+ end
29
+ end
30
+
31
+ def find_matching_metadata(consolidated_metadata, user_agent)
32
+ found = consolidated_metadata.find do |metadata|
33
+ return nil if metadata["resolvedBrowsers"].nil?
34
+ matcher = BrowserslistUseragent::Match.new(metadata["resolvedBrowsers"], user_agent)
35
+
36
+ matcher.browser? && matcher.version?(allow_higher: true)
37
+ end
38
+
39
+ found || consolidated_metadata.last
20
40
  end
21
41
  end
22
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sewing_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0.pre.beta.pre.4
4
+ version: 0.91.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Sauve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-26 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: browserslist_useragent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rails
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -117,9 +131,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
131
  version: 2.0.0
118
132
  required_rubygems_version: !ruby/object:Gem::Requirement
119
133
  requirements:
120
- - - ">"
134
+ - - ">="
121
135
  - !ruby/object:Gem::Version
122
- version: 1.3.1
136
+ version: '0'
123
137
  requirements: []
124
138
  rubyforge_project:
125
139
  rubygems_version: 2.7.6