sewing_kit 0.127.0 → 0.130.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -3
- data/lib/generators/sewing_kit/install_generator.rb +39 -20
- data/lib/generators/sewing_kit/templates/{package.json → package.json.erb} +1 -1
- data/lib/generators/sewing_kit/templates/sewing-kit.config.ts.erb +47 -0
- data/lib/generators/sewing_kit/templates/tsconfig.json.erb +11 -0
- data/lib/sewing_kit/version.rb +1 -1
- data/lib/sewing_kit/webpack/compiler.rb +1 -1
- data/lib/sewing_kit/webpack/dev.rb +4 -3
- data/lib/sewing_kit/webpack/helper.rb +2 -9
- data/lib/sewing_kit/webpack/manifest/development.rb +5 -3
- data/lib/sewing_kit/webpack/manifest/production.rb +1 -1
- data/lib/sewing_kit/webpack/manifest.rb +2 -2
- data/lib/tasks/sewing_kit.rake +9 -1
- metadata +24 -9
- data/lib/generators/sewing_kit/templates/sewing-kit.config.ts +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fdcc87f6ded6c59b84ea7be01819dc8ffa127cff77907535db27a3b1129b734
|
4
|
+
data.tar.gz: e8ed84b2243a54ce366f86529911695c6fb94339f2315b3289052b5a1d5ed392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962c94d0fbceadae0b190b957b832e5f92a0994a3e47f15671bfe98ff460e076eabaa4556c82929cf5e04df660aa849bc60decb570090c351456564e1cb80d3c
|
7
|
+
data.tar.gz: 720383ee164b982057f814e599467af8ab387ea1e1bbf8b463f578afaaf427316b23e986f5e38ac83e9eaa9306fa05e3e86217fffae54dc4a00c30aea33aeded
|
data/README.md
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
Zero configuration, high performance front end development at organization scale.
|
4
4
|
|
5
|
-
`sewing_kit`
|
5
|
+
`sewing_kit` can be used in a Rails application instead of [Webpacker](https://github.com/rails/webpacker), allowing to embed bundled/compiled javascript in erb pages.
|
6
|
+
|
7
|
+
For a more complete and modern stack with performance-as-a-feature, consider [quilt_rails](https://github.com/Shopify/quilt/tree/master/gems/quilt_rails).
|
8
|
+
|
9
|
+
For details on configuring and usage of the `sewing-kit` node package, see the [sewing-kit README](/README.md).
|
6
10
|
|
7
11
|
## Quick Start
|
8
12
|
|
@@ -99,13 +103,13 @@ end
|
|
99
103
|
|
100
104
|
For fast tests with consistent results, test front-end components using Jest instead of Rails integration tests.
|
101
105
|
|
102
|
-
Use [`sewing-kit test`](https://github.com/Shopify/sewing-kit/blob/
|
106
|
+
Use [`sewing-kit test`](https://github.com/Shopify/sewing-kit/blob/main/docs/commands/test.md#L3) to run all `.test.tsx` files in the `app/ui` directory. [Jest](https://jestjs.io) is used as a test runner, with customization available via [its sewing-kit plugin](https://github.com/Shopify/sewing-kit/blob/main/docs/plugins/jest.md).
|
103
107
|
|
104
108
|
### Customizing the test environment
|
105
109
|
|
106
110
|
Often you will want to hook up custom polyfills, global mocks, or other logic that needs to run either before the initialization of the test environment, or once for each test suite.
|
107
111
|
|
108
|
-
By default, sewing-kit will look for such test setup files under `/app/ui/tests`. Check out the [documentation](https://github.com/Shopify/sewing-kit/blob/
|
112
|
+
By default, sewing-kit will look for such test setup files under `/app/ui/tests`. Check out the [documentation](https://github.com/Shopify/sewing-kit/blob/main/docs/plugins/jest.md#smart-defaults) for more details.
|
109
113
|
|
110
114
|
### Rails tests
|
111
115
|
|
@@ -3,40 +3,59 @@
|
|
3
3
|
module SewingKit
|
4
4
|
class InstallGenerator < Rails::Generators::Base
|
5
5
|
source_root File.expand_path('templates', __dir__)
|
6
|
+
|
7
|
+
desc "Adds the configuration files for a sewing-kit powered front-end."
|
8
|
+
|
6
9
|
class_option :skip_yarn, type: :boolean, default: false
|
10
|
+
class_option :javascript_path, type: :string, default: 'app/ui'
|
7
11
|
|
8
|
-
|
12
|
+
# We don't specify a default here because we want to fallback dynamically
|
13
|
+
class_option :uses_dev, type: :boolean
|
9
14
|
|
10
|
-
def initialize(args, *
|
11
|
-
|
12
|
-
super(args, *options)
|
13
|
-
end
|
15
|
+
def initialize(args, *opts)
|
16
|
+
super(args, *opts)
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
@application_name = Project.app_name
|
19
|
+
@javascript_path = options[:javascript_path]
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
if Project.uses_webpacker?
|
22
|
+
warn("
|
23
|
+
WARNING: We've detected you currently have webpacker config at config/webpacker.yml.
|
24
|
+
You may experience conflicts between sewing-kit and webpacker's behaviour as build tools.
|
25
|
+
If your app was made with `rails new`, try rerunning it with `--skip-webpack-install --skip-javascript`
|
26
|
+
")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_config_files
|
31
|
+
say("Creating JS tooling config files")
|
32
|
+
copy_file("editorconfig", ".editorconfig")
|
33
|
+
copy_file("eslintignore", ".eslintignore")
|
34
|
+
copy_file("prettierignore", ".prettierignore")
|
35
|
+
template("package.json.erb", "package.json")
|
36
|
+
template("tsconfig.json.erb", "tsconfig.json")
|
37
|
+
template("sewing-kit.config.ts.erb", "config/sewing-kit.config.ts")
|
20
38
|
end
|
21
39
|
|
22
40
|
def install_js_dependencies
|
23
41
|
return if options.skip_yarn?
|
24
|
-
|
25
|
-
say "Installing react and types dependencies"
|
42
|
+
say("Installing javascript dependencies")
|
26
43
|
system("yarn add @shopify/sewing-kit")
|
44
|
+
system("yarn add typescript")
|
27
45
|
end
|
28
46
|
|
29
|
-
|
30
|
-
|
47
|
+
class Project
|
48
|
+
def self.app_name
|
49
|
+
Rails.application.class.module_parent.to_s.underscore
|
50
|
+
end
|
31
51
|
|
32
|
-
|
33
|
-
|
34
|
-
|
52
|
+
def self.uses_dev?
|
53
|
+
File.exist?('dev.yml')
|
54
|
+
end
|
35
55
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
copy_file("prettierignore", ".prettierignore")
|
56
|
+
def self.uses_webpacker?
|
57
|
+
File.exist?('config/webpacker.yml')
|
58
|
+
end
|
40
59
|
end
|
41
60
|
end
|
42
61
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/* eslint-env node */
|
2
|
+
import {resolve} from 'path';
|
3
|
+
|
4
|
+
import {Plugins, Env} from '@shopify/sewing-kit';
|
5
|
+
|
6
|
+
const ROOT_PATH = resolve(__dirname, '..');
|
7
|
+
|
8
|
+
export default function sewingKitConfig(plugins: Plugins, env: Env) {
|
9
|
+
return {
|
10
|
+
name: '<%= @application_name %>',
|
11
|
+
plugins: [
|
12
|
+
plugins.paths({
|
13
|
+
// Determines where the root directory for front-end code is
|
14
|
+
app: resolve(ROOT_PATH, '<%= @javascript_path %>'),
|
15
|
+
// Determines where test setup should go for front-end code
|
16
|
+
tests: resolve(ROOT_PATH, '<%= @javascript_path %>', 'tests'),
|
17
|
+
}),
|
18
|
+
|
19
|
+
<% unless @uses_dev %>
|
20
|
+
// Sets up the app to get its assets from the default webpack endpoint in development.
|
21
|
+
// You will need to change this to use your actual production cdn to get it working in production.
|
22
|
+
// NOTE: If you are using dev and shopify-cloud gem you can delete this.
|
23
|
+
plugins.cdn(
|
24
|
+
env.isDevelopment ? 'http://localhost:8080/webpack/assets/' : undefined,
|
25
|
+
),
|
26
|
+
<% end %>
|
27
|
+
// Sets up sewing-kit to generate type definitions for GraphQL using the given schema(s)
|
28
|
+
// Uncomment the following if you are using GraphQL and make sure the path points to your generated schema
|
29
|
+
// plugins.graphql({
|
30
|
+
// schema: resolve(__dirname, '..', 'app', 'graphql', 'schema.graphql'),
|
31
|
+
// }),
|
32
|
+
|
33
|
+
// Sets up sass mixins to be automatically imported.
|
34
|
+
// Uncomment if you are using Polaris and want access to the sass mixins in your custom SCSS
|
35
|
+
// plugins.sass({
|
36
|
+
// autoInclude: [
|
37
|
+
// path.join(
|
38
|
+
// __dirname,
|
39
|
+
// 'node_modules/@shopify/polaris/dist/styles/_public-api.scss',
|
40
|
+
// ),
|
41
|
+
// ],
|
42
|
+
// }),
|
43
|
+
|
44
|
+
// configure additional sewing-kit plugins here
|
45
|
+
],
|
46
|
+
};
|
47
|
+
}
|
data/lib/sewing_kit/version.rb
CHANGED
@@ -8,7 +8,7 @@ module SewingKit
|
|
8
8
|
def initialize
|
9
9
|
super(
|
10
10
|
"nodejs is not installed. " \
|
11
|
-
"Try creating a `.
|
11
|
+
"Try creating a `.buildpacks` file in the root of the project with following content:
|
12
12
|
|
13
13
|
https://github.com/heroku/heroku-buildpack-nodejs.git
|
14
14
|
https://github.com/heroku/heroku-buildpack-ruby.git
|
@@ -29,6 +29,7 @@ module SewingKit
|
|
29
29
|
'NODE_ENV' => 'development',
|
30
30
|
'BLUEBIRD_DEBUG' => '0',
|
31
31
|
'BLUEBIRD_LONG_STACK_TRACES' => '0',
|
32
|
+
'FORCE_COLOR' => 'true',
|
32
33
|
},
|
33
34
|
command,
|
34
35
|
chdir: Rails.root.to_s,
|
@@ -39,13 +40,13 @@ module SewingKit
|
|
39
40
|
|
40
41
|
def handle_exit
|
41
42
|
return if $ERROR_INFO.nil?
|
42
|
-
Process.kill
|
43
|
+
Process.kill('SIGTERM', pid)
|
43
44
|
rescue Errno::ESRCH
|
44
45
|
nil
|
45
46
|
end
|
46
47
|
|
47
48
|
def detach
|
48
|
-
Process.detach
|
49
|
+
Process.detach(pid)
|
49
50
|
end
|
50
51
|
|
51
52
|
def command
|
@@ -54,7 +55,7 @@ module SewingKit
|
|
54
55
|
heap_config,
|
55
56
|
sewing_kit_bin,
|
56
57
|
'dev',
|
57
|
-
'--
|
58
|
+
'--log-level',
|
58
59
|
log_level,
|
59
60
|
].compact.concat(options)
|
60
61
|
|
@@ -10,22 +10,19 @@ module SewingKit
|
|
10
10
|
|
11
11
|
Asset = Struct.new(:path, :integrity)
|
12
12
|
|
13
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
14
13
|
def sewing_kit_assets(entrypoint_name, extension: 'js')
|
15
14
|
return '' unless entrypoint_name.present?
|
16
15
|
|
17
16
|
assets = SewingKit::Webpack::Manifest.asset_dependencies(entrypoint_name, request.user_agent)
|
18
17
|
|
19
|
-
raise UnknownAssetError, "#{entrypoint_name} was not found in manifest." if raise_unknown_error?
|
18
|
+
raise UnknownAssetError, "#{entrypoint_name} was not found in manifest." if raise_unknown_error?(assets)
|
20
19
|
return [] unless assets && assets[extension]
|
21
20
|
|
22
21
|
dependencies = assets[extension]
|
23
|
-
dependencies.unshift(dll_asset) if serve_development_assets? && extension == 'js'
|
24
22
|
dependencies.map do |raw_asset|
|
25
23
|
Asset.new(raw_asset['path'], raw_asset['integrity'])
|
26
24
|
end
|
27
25
|
end
|
28
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
29
26
|
|
30
27
|
def sewing_kit_link_tag(*assets)
|
31
28
|
options = assets.extract_options!
|
@@ -56,7 +53,7 @@ module SewingKit
|
|
56
53
|
private
|
57
54
|
|
58
55
|
def create_asset_tag(tag_type, asset, tag_options)
|
59
|
-
raise ArgumentError, "Invalid tag type: #{tag_type}" unless [:script, :link].include?
|
56
|
+
raise ArgumentError, "Invalid tag type: #{tag_type}" unless [:script, :link].include?(tag_type)
|
60
57
|
|
61
58
|
options = tag_options.clone
|
62
59
|
|
@@ -82,10 +79,6 @@ module SewingKit
|
|
82
79
|
def raise_unknown_error?(assets)
|
83
80
|
assets.nil? && serve_development_assets?
|
84
81
|
end
|
85
|
-
|
86
|
-
def dll_asset
|
87
|
-
Asset.new('/webpack/assets/dll/vendor.js')
|
88
|
-
end
|
89
82
|
end
|
90
83
|
end
|
91
84
|
end
|
@@ -43,7 +43,9 @@ module SewingKit
|
|
43
43
|
return normalize_metadata(result)
|
44
44
|
end
|
45
45
|
rescue => e
|
46
|
-
Rails.logger.warn
|
46
|
+
Rails.logger.warn(
|
47
|
+
"[sewing_kit] could not read manifest from #{@metadata_path}; falling back to node. #{e}"
|
48
|
+
)
|
47
49
|
@metadata_path = nil
|
48
50
|
end
|
49
51
|
|
@@ -81,8 +83,8 @@ module SewingKit
|
|
81
83
|
|
82
84
|
class OnlyUseInProductionError < StandardError
|
83
85
|
def initialize
|
84
|
-
super
|
85
|
-
"for deploying assets to a CDN. Do not use it in development."
|
86
|
+
super("The SewingKit::Webpack::Manifest#manifest is intended "\
|
87
|
+
"for deploying assets to a CDN. Do not use it in development.")
|
86
88
|
end
|
87
89
|
end
|
88
90
|
end
|
@@ -24,14 +24,14 @@ module SewingKit
|
|
24
24
|
# Raised if the node-generated manifest cannot be read from the filesystem.
|
25
25
|
class ManifestLoadError < StandardError
|
26
26
|
def initialize(path, cause)
|
27
|
-
super
|
27
|
+
super("Could not load manifest from #{path} (original error #{cause})")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
# Raised if the node-generated manifest returns unparseable JSON.
|
32
32
|
class ManifestParseError < StandardError
|
33
33
|
def initialize(cause)
|
34
|
-
super
|
34
|
+
super("Could not parse manifest JSON (original error #{cause})")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/lib/tasks/sewing_kit.rake
CHANGED
@@ -4,7 +4,7 @@ TEMPLATE_PATH = File.expand_path("../install/template.rb", File.dirname(__FILE__
|
|
4
4
|
namespace :sewing_kit do
|
5
5
|
desc "Install all of Shopify’s modern FED tooling"
|
6
6
|
task :install do
|
7
|
-
exec "
|
7
|
+
exec "bundle exec rails generate sewing_kit:install"
|
8
8
|
end
|
9
9
|
|
10
10
|
desc "Build webpack asset bundles"
|
@@ -29,3 +29,11 @@ if Rake::Task.task_defined?("assets:precompile")
|
|
29
29
|
else
|
30
30
|
Rake::Task.define_task("assets:precompile" => %w(sewing_kit:build))
|
31
31
|
end
|
32
|
+
|
33
|
+
unless Rake::Task.task_defined?('assets:clean')
|
34
|
+
namespace :assets do
|
35
|
+
task :clean do
|
36
|
+
# This empty task is to offer the same interface than sprockets and webpacker
|
37
|
+
end
|
38
|
+
end
|
39
|
+
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.
|
4
|
+
version: 0.130.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:
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.89.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.89.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop-git
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.1.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-shopify
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.0.5
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.0.5
|
97
111
|
description:
|
98
112
|
email:
|
99
113
|
- chris.sauve@shopify.com
|
@@ -106,9 +120,10 @@ files:
|
|
106
120
|
- lib/generators/sewing_kit/install_generator.rb
|
107
121
|
- lib/generators/sewing_kit/templates/editorconfig
|
108
122
|
- lib/generators/sewing_kit/templates/eslintignore
|
109
|
-
- lib/generators/sewing_kit/templates/package.json
|
123
|
+
- lib/generators/sewing_kit/templates/package.json.erb
|
110
124
|
- lib/generators/sewing_kit/templates/prettierignore
|
111
|
-
- lib/generators/sewing_kit/templates/sewing-kit.config.ts
|
125
|
+
- lib/generators/sewing_kit/templates/sewing-kit.config.ts.erb
|
126
|
+
- lib/generators/sewing_kit/templates/tsconfig.json.erb
|
112
127
|
- lib/hacks/user_agent_parser.rb
|
113
128
|
- lib/sewing_kit.rb
|
114
129
|
- lib/sewing_kit/configuration.rb
|
@@ -126,11 +141,11 @@ files:
|
|
126
141
|
- lib/sewing_kit/webpack/server.rb
|
127
142
|
- lib/sewing_kit/webpack/webpack.rb
|
128
143
|
- lib/tasks/sewing_kit.rake
|
129
|
-
homepage: https://github.com/Shopify/sewing-kit/tree/
|
144
|
+
homepage: https://github.com/Shopify/sewing-kit/tree/main/gems/sewing_kit
|
130
145
|
licenses:
|
131
146
|
- MIT
|
132
147
|
metadata:
|
133
|
-
changelog_uri: https://github.com/Shopify/sewing-kit/blob/
|
148
|
+
changelog_uri: https://github.com/Shopify/sewing-kit/blob/main/gems/sewing_kit/CHANGELOG.md
|
134
149
|
allowed_push_host: https://rubygems.org
|
135
150
|
post_install_message:
|
136
151
|
rdoc_options: []
|
@@ -147,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
162
|
- !ruby/object:Gem::Version
|
148
163
|
version: '0'
|
149
164
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
165
|
+
rubygems_version: 3.2.20
|
151
166
|
signing_key:
|
152
167
|
specification_version: 4
|
153
168
|
summary: Shopify's modern front-end tooling, nicely packaged for Rails
|
@@ -1,11 +0,0 @@
|
|
1
|
-
/* eslint-env node */
|
2
|
-
|
3
|
-
import {Plugins, Env} from '@shopify/sewing-kit';
|
4
|
-
|
5
|
-
export default function sewingKitConfig(plugins: Plugins, env: Env) {
|
6
|
-
return {
|
7
|
-
name: '${application_name}',
|
8
|
-
// remove cdn plugin when using dev
|
9
|
-
plugins: [plugins.cdn(env.isDevelopment ? 'http://localhost:8080/webpack/assets/' : undefined)],
|
10
|
-
};
|
11
|
-
}
|