shakapacker 6.5.0 → 6.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +18 -6
- data/Gemfile +1 -10
- data/Gemfile.development_dependencies +13 -0
- data/README.md +9 -35
- data/docs/react.md +10 -1
- data/docs/v6_upgrade.md +7 -19
- data/lib/webpacker/configuration.rb +6 -2
- data/lib/webpacker/env.rb +2 -4
- data/lib/webpacker/helper.rb +6 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/version_checker.rb +72 -9
- data/lib/webpacker.rb +2 -0
- data/package.json +1 -1
- data/test/configuration_test.rb +75 -13
- data/test/env_test.rb +1 -1
- data/test/fixtures/beta_package-lock.v1.json +119 -0
- data/test/fixtures/beta_package-lock.v2.json +6777 -0
- data/test/fixtures/beta_package.json +1 -1
- data/test/fixtures/beta_yarn.v1.lock +106 -0
- data/test/fixtures/beta_yarn.v2.lock +164 -0
- data/test/fixtures/git_url_package-lock.v1.json +118 -0
- data/test/fixtures/git_url_package-lock.v2.json +10263 -0
- data/test/fixtures/git_url_package.json +1 -1
- data/test/fixtures/git_url_yarn.v1.lock +106 -0
- data/test/fixtures/git_url_yarn.v2.lock +165 -0
- data/test/fixtures/github_url_package-lock.v1.json +118 -0
- data/test/fixtures/github_url_package-lock.v2.json +10263 -0
- data/test/fixtures/github_url_package.json +1 -1
- data/test/fixtures/github_url_yarn.v1.lock +105 -0
- data/test/fixtures/github_url_yarn.v2.lock +165 -0
- data/test/fixtures/relative_path_package-lock.v1.json +3468 -0
- data/test/fixtures/relative_path_package-lock.v2.json +105 -0
- data/test/fixtures/relative_path_package.json +1 -1
- data/test/fixtures/relative_path_yarn.v1.lock +104 -0
- data/test/fixtures/relative_path_yarn.v2.lock +165 -0
- data/test/fixtures/semver_caret_package-lock.v1.json +119 -0
- data/test/fixtures/semver_caret_package-lock.v2.json +10264 -0
- data/test/fixtures/semver_caret_yarn.v1.lock +106 -0
- data/test/fixtures/semver_caret_yarn.v2.lock +165 -0
- data/test/fixtures/semver_exact_package-lock.v1.json +119 -0
- data/test/fixtures/semver_exact_package-lock.v2.json +6819 -0
- data/test/fixtures/{normal_package.json → semver_exact_package.json} +0 -0
- data/test/fixtures/semver_exact_yarn.v1.lock +106 -0
- data/test/fixtures/semver_exact_yarn.v2.lock +165 -0
- data/test/fixtures/semver_tilde_package-lock.v1.json +119 -0
- data/test/fixtures/semver_tilde_package-lock.v2.json +6777 -0
- data/test/fixtures/semver_tilde_yarn.v1.lock +106 -0
- data/test/fixtures/semver_tilde_yarn.v2.lock +164 -0
- data/test/fixtures/without_package-lock.v1.json +19 -0
- data/test/fixtures/without_package-lock.v2.json +47 -0
- data/test/fixtures/without_yarn.v1.lock +13 -0
- data/test/fixtures/without_yarn.v2.lock +29 -0
- data/test/test_app/config/webpacker_defaults_fallback.yml +11 -0
- data/test/version_checker_test.rb +575 -20
- metadata +72 -6
- data/Gemfile.lock +0 -193
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9174a8c729f67ee442afd4db423a2c2f5e412ba448283c9d691dea1b565cf7e
|
4
|
+
data.tar.gz: 940e267827d81bf4febd2ab41748efb2d8862ac653e7d234ce5016448cca4026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4553b937730995bf743ba9a3d11941096d0eda4e7cd37d69c9dc0fcb97b9f3d6f7e550e58e5d2106882686ff01c3a2ff0740e6758fd8759fed1221513eff66f2
|
7
|
+
data.tar.gz: 287b01999fcc9e13230a4ea90d2fd36cf9f71775435912283599f6db3630390a3f10e7c0810f92cb21ddb363cb80f3aa7f3f8e719a61afa7fc1c3fef6749e890
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,17 @@ Changes since last non-beta release.
|
|
8
8
|
|
9
9
|
_Please add entries here for your pull requests that are not yet released._
|
10
10
|
|
11
|
+
## [v6.5.1] - August 12, 2022
|
12
|
+
|
13
|
+
### Improved
|
14
|
+
- Resolve exact npm package version from lockfiles for constraint checking. [PR 170](https://github.com/shakacode/shakapacker/pull/170) by [G-Rath](https://github.com/G-Rath).
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- `append_javascript_pack_tag` and `append_stylesheet_pack_tag` helpers return `nil` to prevent rendering the queue into view when using `<%= … %>` ERB syntax. [PR 167](https://github.com/shakacode/shakapacker/pull/167) by [ur5us](https://github.com/ur5us). While `<%=` should not be used, it's OK to return nil in case it's misused.
|
18
|
+
- Fixed non-runnable test due to wrong code nesting. [PR 173](https://github.com/shakacode/shakapacker/pull/173) by [ur5us](https://github.com/ur5us).
|
19
|
+
- Fixed default configurations not working for custom Rails environments [PR 168](https://github.com/shakacode/shakapacker/pull/168) by [ur5us](https://github.com/ur5us).
|
20
|
+
- Added accessor method for `nested_entries` configuration. [PR 176](https://github.com/shakacode/shakapacker/pull/176) by [pulkitkkr](https://github.com/pulkitkkr).
|
21
|
+
|
11
22
|
## [v6.5.0] - July 4, 2022
|
12
23
|
### Added
|
13
24
|
- `append_stylesheet_pack_tag` helper. It helps in configuring stylesheet pack names from the view for a route or partials. It is also required for filesystem-based automated Component Registry API on React on Rails gem. [PR 144](https://github.com/shakacode/shakapacker/pull/144) by [pulkitkkr](https://github.com/pulkitkkr).
|
@@ -28,7 +39,7 @@ _Please add entries here for your pull requests that are not yet released._
|
|
28
39
|
- Fixed [Issue 123: Rails 7.0.3 - Webpacker configuration file not found when running rails webpacker:install (shakapacker v6.3)](https://github.com/shakacode/shakapacker/issues/123) in [PR 136: Don't enhance precompile if no config #136](https://github.com/shakacode/shakapacker/pull/136) by [justin808](https://github.com/justin808).
|
29
40
|
|
30
41
|
### Added
|
31
|
-
- Configuration boolean option `nested_entries` to use nested entries. This was the default prior to v6.0. Because entries maybe generated, it's useful to allow a `generated` subdirectory. [PR 121](https://github.com/shakacode/shakapacker/pull/121) by [justin808](https://github.com/justin808).
|
42
|
+
- Configuration boolean option `nested_entries` to use nested entries. This was the default prior to v6.0. Because entries maybe generated, it's useful to allow a `generated` subdirectory. [PR 121](https://github.com/shakacode/shakapacker/pull/121) by [justin808](https://github.com/justin808).
|
32
43
|
|
33
44
|
### Improved
|
34
45
|
- Allow v10 of `compression-webpack-plugin` as a peer dependency. [PR 117](https://github.com/shakacode/shakapacker/pull/117) by [aried3r](https://github.com/aried3r).
|
@@ -38,7 +49,7 @@ _Please add entries here for your pull requests that are not yet released._
|
|
38
49
|
## [v6.3.0] - May 19, 2022
|
39
50
|
|
40
51
|
### Improved
|
41
|
-
- Add ability to configure usage of either last modified timestamp and digest strategies when checking asset freshness. [PR 112](https://github.com/shakacode/shakapacker/pull/112) by [tomdracz](https://github.com/tomdracz).
|
52
|
+
- Add ability to configure usage of either last modified timestamp and digest strategies when checking asset freshness. [PR 112](https://github.com/shakacode/shakapacker/pull/112) by [tomdracz](https://github.com/tomdracz).
|
42
53
|
|
43
54
|
### Fixed
|
44
55
|
- On Windows CSS urls no longer contain backslashes resulting in 404 errors. [PR 115](https://github.com/shakacode/shakapacker/pull/115) by [daniel-rikowski](https://github.com/daniel-rikowski).
|
@@ -50,10 +61,10 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
|
|
50
61
|
### Changed
|
51
62
|
- Remove Loose mode from the default @babel-preset/env configuration. [PR 107](https://github.com/shakacode/shakapacker/pull/107) by [Jeremy Liberman](https://github.com/MrLeebo).
|
52
63
|
|
53
|
-
Loose mode compiles the bundle down to be compatible with ES5, but saves space by skipping over behaviors that are considered edge cases. Loose mode can affect how your code runs in a variety of ways, but in newer versions of Babel it's better to use [Compiler Assumptions](https://babeljs.io/docs/en/assumptions) to have finer-grained control over which edge cases you're choosing to ignore.
|
64
|
+
Loose mode compiles the bundle down to be compatible with ES5, but saves space by skipping over behaviors that are considered edge cases. Loose mode can affect how your code runs in a variety of ways, but in newer versions of Babel it's better to use [Compiler Assumptions](https://babeljs.io/docs/en/assumptions) to have finer-grained control over which edge cases you're choosing to ignore.
|
54
65
|
|
55
66
|
This change may increase the file size of your bundles, and may change some behavior in your app if your code touches upon one of the edge cases where Loose mode differs from native JavaScript. There are notes in the linked PR about how to turn Loose mode back on if you need to, but consider migrating to Compiler Assumptions when you can. If you have already customized your babel config, this change probably won't affect you.
|
56
|
-
|
67
|
+
|
57
68
|
### Added
|
58
69
|
- Adds `webpacker_precompile` setting to `webpacker.yml` to allow controlling precompile behaviour, similar to existing `ENV["WEBPACKER_PRECOMPILE"]` variable. [PR 102](https://github.com/shakacode/shakapacker/pull/102) by [Judahmeek](https://github.com/Judahmeek).
|
59
70
|
- Adds `append_javascript_pack_tag` helper. Allows for easier usage and coordination of multiple javascript packs. [PR 94](https://github.com/shakacode/shakapacker/pull/94) by [tomdracz](https://github.com/tomdracz).
|
@@ -150,9 +161,10 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
|
|
150
161
|
- CSS extraction enabled by default, except when devServer is configured and running
|
151
162
|
|
152
163
|
## v5.4.3 and prior changes from rails/webpacker
|
153
|
-
See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
|
164
|
+
See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
|
154
165
|
|
155
|
-
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.5.
|
166
|
+
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.5.1...master
|
167
|
+
[v6.5.1]: https://github.com/shakacode/shakapacker/compare/v6.5.0...v6.5.1
|
156
168
|
[v6.5.0]: https://github.com/shakacode/shakapacker/compare/v6.4.1...v6.5.0
|
157
169
|
[v6.4.1]: https://github.com/shakacode/shakapacker/compare/v6.4.0...v6.4.1
|
158
170
|
[v6.4.0]: https://github.com/shakacode/shakapacker/compare/v6.3.0...v6.4.0
|
data/Gemfile
CHANGED
@@ -2,13 +2,4 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
gem "rake", ">= 11.1"
|
7
|
-
gem "rack-proxy", require: false
|
8
|
-
gem "semantic_range", require: false
|
9
|
-
gem "nokogiri", "~> 1.13", ">= 1.13.6"
|
10
|
-
|
11
|
-
group :test do
|
12
|
-
gem "minitest", "~> 5.0"
|
13
|
-
gem "byebug"
|
14
|
-
end
|
5
|
+
eval_gemfile File.expand_path("./Gemfile.development_dependencies", __dir__)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
gem "rails", ">= 6.1.6"
|
4
|
+
gem "rake", ">= 11.1"
|
5
|
+
gem "rack-proxy", ">= 0.7.2"
|
6
|
+
gem "nokogiri", ">= 1.13.6"
|
7
|
+
gem "rails-html-sanitizer", ">= 1.4.3"
|
8
|
+
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "minitest", "~> 5.0"
|
12
|
+
gem "byebug"
|
13
|
+
end
|
data/README.md
CHANGED
@@ -62,13 +62,12 @@ Discussion forum and Slack to discuss debugging and troubleshooting tips. Please
|
|
62
62
|
- [Integrations](#integrations)
|
63
63
|
- [React](#react)
|
64
64
|
- [Typescript](#typescript)
|
65
|
-
- [CoffeeScript](#coffeescript)
|
66
|
-
- [TypeScript](#typescript)
|
67
65
|
- [CSS](#css)
|
68
66
|
- [Postcss](#postcss)
|
69
67
|
- [Sass](#sass)
|
70
68
|
- [Less](#less)
|
71
69
|
- [Stylus](#stylus)
|
70
|
+
- [CoffeeScript](#coffeescript)
|
72
71
|
- [Other frameworks](#other-frameworks)
|
73
72
|
- [Custom Rails environments](#custom-rails-environments)
|
74
73
|
- [Upgrading](#upgrading)
|
@@ -171,7 +170,7 @@ You will need your file system to correspond to the setup of your `webpacker.yml
|
|
171
170
|
|
172
171
|
Suppose you have the following configuration:
|
173
172
|
|
174
|
-
`
|
173
|
+
`webpacker.yml`
|
175
174
|
```yml
|
176
175
|
default: &default
|
177
176
|
source_path: app/javascript
|
@@ -527,34 +526,6 @@ See here for detailed instructions on how to [configure Shakapacker to bundle a
|
|
527
526
|
|
528
527
|
See also [Customizing Babel Config](./docs/customizing_babel_config.md) for an example React configuration.
|
529
528
|
|
530
|
-
#### Typescript
|
531
|
-
...if you are using typescript, update your `tsconfig.json`
|
532
|
-
|
533
|
-
```json
|
534
|
-
{
|
535
|
-
"compilerOptions": {
|
536
|
-
"declaration": false,
|
537
|
-
"emitDecoratorMetadata": true,
|
538
|
-
"experimentalDecorators": true,
|
539
|
-
"lib": ["es6", "dom"],
|
540
|
-
"module": "es6",
|
541
|
-
"moduleResolution": "node",
|
542
|
-
"sourceMap": true,
|
543
|
-
"target": "es5",
|
544
|
-
"jsx": "react",
|
545
|
-
"noEmit": true
|
546
|
-
},
|
547
|
-
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
548
|
-
"compileOnSave": false
|
549
|
-
}
|
550
|
-
```
|
551
|
-
|
552
|
-
#### CoffeeScript
|
553
|
-
|
554
|
-
```bash
|
555
|
-
yarn add coffeescript coffee-loader
|
556
|
-
```
|
557
|
-
|
558
529
|
#### TypeScript
|
559
530
|
|
560
531
|
```bash
|
@@ -578,12 +549,9 @@ Add tsconfig.json
|
|
578
549
|
"lib": ["es6", "dom"],
|
579
550
|
"module": "es6",
|
580
551
|
"moduleResolution": "node",
|
581
|
-
"baseUrl": ".",
|
582
|
-
"paths": {
|
583
|
-
"*": ["node_modules/*", "app/javascript/*"]
|
584
|
-
},
|
585
552
|
"sourceMap": true,
|
586
553
|
"target": "es5",
|
554
|
+
"jsx": "react",
|
587
555
|
"noEmit": true
|
588
556
|
},
|
589
557
|
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
@@ -657,6 +625,12 @@ yarn add less less-loader
|
|
657
625
|
yarn add stylus stylus-loader
|
658
626
|
```
|
659
627
|
|
628
|
+
#### CoffeeScript
|
629
|
+
|
630
|
+
```bash
|
631
|
+
yarn add coffeescript coffee-loader
|
632
|
+
```
|
633
|
+
|
660
634
|
#### Other frameworks
|
661
635
|
|
662
636
|
Please follow webpack integration guide for relevant framework or library,
|
data/docs/react.md
CHANGED
@@ -8,7 +8,16 @@ Before starting, ensure that you have Yarn installed, for example:
|
|
8
8
|
npm i -g yarn
|
9
9
|
```
|
10
10
|
|
11
|
-
##
|
11
|
+
## Easy Setup
|
12
|
+
If you'd like easy integration of React with Ruby on Rails, see [React on Rails](https://github.com/shakacode/react_on_rails).
|
13
|
+
|
14
|
+
The below information applies to a React on Rails app, except that you need to setup some environment variables as follows:
|
15
|
+
|
16
|
+
```
|
17
|
+
EXECJS_RUNTIME=Node
|
18
|
+
```
|
19
|
+
|
20
|
+
## Basic Manual Setup
|
12
21
|
|
13
22
|
Create a new Rails app as per the [installation instructions in the README](https://github.com/shakacode/shakapacker#installation).
|
14
23
|
|
data/docs/v6_upgrade.md
CHANGED
@@ -21,8 +21,10 @@ _If you're on webpacker v5, follow below steps to get to v6.0.0.rc.6 first._
|
|
21
21
|
1. Change the gem name from `webpacker` to `shakapacker` and the NPM package from `@rails/webpacker` to `shakapacker`.
|
22
22
|
1. Install the peer dependencies. Run `yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader compression-webpack-plugin terser-webpack-plugin webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server`. You may have old versions of libraries. Run `yarn install` and check for warnings like `warning " > shakapacker@6.1.1" has incorrect peer dependency "compression-webpack-plugin@^9.0.0"` and `file-loader@1.1.11" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0 || ^4.0.0"`. In other words, warnings like these are **serious** and will cause considerable confusion if not respected.
|
23
23
|
1. Update any scripts that called `bin/webpack` or `bin/webpack-dev-server` to `bin/webpacker` or `bin/webpacker-dev-server`
|
24
|
-
1. Update your webpack config for a single config file, `config/webpack/webpack.config.js`. If you want to use the prior style of having a separate file for each NODE_ENV, you can use this shim for `config/webpack/webpack.config.js`. WARNING, previously, if you did not set `NODE_ENV`, `NODE_ENV` defaulted to `development`. Thus, you might expect `config/webpack/development.js` to run, but you'll instead be using the `config/webpack/
|
25
|
-
|
24
|
+
1. Update your webpack config for a single config file, `config/webpack/webpack.config.js`. If you want to use the prior style of having a separate file for each NODE_ENV, you can use this shim for `config/webpack/webpack.config.js`. WARNING, previously, if you did not set `NODE_ENV`, `NODE_ENV` defaulted to `development`. Thus, you might expect `config/webpack/development.js` to run, but you'll instead be using the the configuration file that corresponds to your `RAILS_ENV`. If your `RAILS_ENV` is `test`, you'd be running `config/webpack/test.js`.
|
25
|
+
|
26
|
+
```js
|
27
|
+
// name this file config/webpack/webpack.config.js
|
26
28
|
const { env, webpackConfig } = require('shakapacker')
|
27
29
|
const { existsSync } = require('fs')
|
28
30
|
const { resolve } = require('path')
|
@@ -45,23 +47,9 @@ _If you're on webpacker v5, follow below steps to get to v6.0.0.rc.6 first._
|
|
45
47
|
## How to upgrade to Webpacker v6.0.0.rc.6 from v5
|
46
48
|
1. Ensure you have a clean working git branch. You will be overwriting all your files and reverting the changes that you don't want.
|
47
49
|
|
48
|
-
1.
|
49
|
-
```yml
|
50
|
-
source_path: app/javascript
|
51
|
-
source_entry_path: packs
|
52
|
-
```
|
53
|
-
consider changing to the v6 default:
|
54
|
-
```yml
|
55
|
-
source_path: app/javascript
|
56
|
-
source_entry_path: /
|
57
|
-
```
|
58
|
-
Then consider moving your `app/javascript/packs/*` (including `application.js`) to `app/javascript/` and updating the configuration file.
|
59
|
-
|
60
|
-
Note, moving your files is optional, as you can stil keep your entries in a separate directory, called something like `packs`, or `entries`. This directory is defined within the source_path.
|
61
|
-
|
62
|
-
1. **Ensure no nested directories in your `source_entry_path`.** Check if you had any entry point files in child directories of your `source_entry_path`. Files for entry points in child directories are not supported by shakacode/shakapacker v6. Move those files to the top level, adjusting any imports in those files.
|
50
|
+
1. **Ensure no nested directories in your `source_entry_path`. or set option `nested_entries: true`** Check if you had any entry point files in child directories of your `source_entry_path`.
|
63
51
|
|
64
|
-
The new v6 configuration
|
52
|
+
The new v6 configuration **defaults** to not allow nesting, so as to allow placing the entry points at in the root directory of JavaScript. You can find this change [here](https://github.com/rails/webpacker/commit/5de0fbc1e16d3db0c93202fb39f5b4d80582c682#diff-7af8667a3e36201db57c02b68dd8651883d7bfc00dc9653661be11cd31feeccdL19).
|
65
53
|
|
66
54
|
1. Upgrade the Webpacker Ruby gem and the NPM package
|
67
55
|
|
@@ -110,7 +98,7 @@ _If you're on webpacker v5, follow below steps to get to v6.0.0.rc.6 first._
|
|
110
98
|
|
111
99
|
1. **Ensure no nested directories in your `source_entry_path`.** Check if you had any entry point files in child directories of your `source_entry_path`. Files for entry points in child directories are not supported by shakacode/shakapacker v6. Move those files to the top level, adjusting any imports in those files.
|
112
100
|
|
113
|
-
The
|
101
|
+
The v6 configuration does not allow nesting, so as to allow placing the entry points at in the root directory of JavaScript. You can find this change [here](https://github.com/rails/webpacker/commit/5de0fbc1e16d3db0c93202fb39f5b4d80582c682#diff-7af8667a3e36201db57c02b68dd8651883d7bfc00dc9653661be11cd31feeccdL19).
|
114
102
|
|
115
103
|
1. Update `webpack-dev-server` to the current version, greater than 4.2, updating `package.json`.
|
116
104
|
|
@@ -23,6 +23,10 @@ class Webpacker::Configuration
|
|
23
23
|
fetch(:compile)
|
24
24
|
end
|
25
25
|
|
26
|
+
def nested_entries?
|
27
|
+
fetch(:nested_entries)
|
28
|
+
end
|
29
|
+
|
26
30
|
def ensure_consistent_versioning?
|
27
31
|
fetch(:ensure_consistent_versioning)
|
28
32
|
end
|
@@ -30,7 +34,7 @@ class Webpacker::Configuration
|
|
30
34
|
def webpacker_precompile?
|
31
35
|
# ENV of false takes precedence
|
32
36
|
return false if %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
|
33
|
-
return true if %w(yes true t).include?(ENV["WEBPACKER_PRECOMPILE"])
|
37
|
+
return true if %w(yes true y t).include?(ENV["WEBPACKER_PRECOMPILE"])
|
34
38
|
|
35
39
|
return false unless config_path.exist?
|
36
40
|
fetch(:webpacker_precompile)
|
@@ -130,7 +134,7 @@ class Webpacker::Configuration
|
|
130
134
|
rescue ArgumentError
|
131
135
|
YAML.load_file(path)
|
132
136
|
end
|
133
|
-
HashWithIndifferentAccess.new(config[env])
|
137
|
+
HashWithIndifferentAccess.new(config[env] || config[Webpacker::DEFAULT_ENV])
|
134
138
|
end
|
135
139
|
end
|
136
140
|
end
|
data/lib/webpacker/env.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
class Webpacker::Env
|
2
|
-
DEFAULT = "production".freeze
|
3
|
-
|
4
2
|
delegate :config_path, :logger, to: :@webpacker
|
5
3
|
|
6
4
|
def self.inquire(webpacker)
|
@@ -13,7 +11,7 @@ class Webpacker::Env
|
|
13
11
|
|
14
12
|
def inquire
|
15
13
|
fallback_env_warning if config_path.exist? && !current
|
16
|
-
current ||
|
14
|
+
current || Webpacker::DEFAULT_ENV.inquiry
|
17
15
|
end
|
18
16
|
|
19
17
|
private
|
@@ -22,7 +20,7 @@ class Webpacker::Env
|
|
22
20
|
end
|
23
21
|
|
24
22
|
def fallback_env_warning
|
25
|
-
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/webpacker.yml, falling back to #{
|
23
|
+
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/webpacker.yml, falling back to #{Webpacker::DEFAULT_ENV} environment"
|
26
24
|
end
|
27
25
|
|
28
26
|
def available_environments
|
data/lib/webpacker/helper.rb
CHANGED
@@ -174,6 +174,9 @@ module Webpacker::Helper
|
|
174
174
|
|
175
175
|
@stylesheet_pack_tag_queue ||= []
|
176
176
|
@stylesheet_pack_tag_queue.concat names
|
177
|
+
|
178
|
+
# prevent rendering Array#to_s representation when used with <%= … %> syntax
|
179
|
+
nil
|
177
180
|
end
|
178
181
|
|
179
182
|
def append_javascript_pack_tag(*names, defer: true)
|
@@ -184,6 +187,9 @@ module Webpacker::Helper
|
|
184
187
|
|
185
188
|
hash_key = defer ? :deferred : :non_deferred
|
186
189
|
javascript_pack_tag_queue[hash_key] |= names
|
190
|
+
|
191
|
+
# prevent rendering Array#to_s representation when used with <%= … %> syntax
|
192
|
+
nil
|
187
193
|
end
|
188
194
|
|
189
195
|
private
|
data/lib/webpacker/version.rb
CHANGED
@@ -29,7 +29,7 @@ module Webpacker
|
|
29
29
|
|
30
30
|
if !Webpacker.config.ensure_consistent_versioning? && (uses_wildcard || !versions_match)
|
31
31
|
check_failed = if uses_wildcard
|
32
|
-
"Semver wildcard detected"
|
32
|
+
"Semver wildcard without a lockfile detected"
|
33
33
|
else
|
34
34
|
"Version mismatch detected"
|
35
35
|
end
|
@@ -37,7 +37,7 @@ module Webpacker
|
|
37
37
|
warn <<-MSG.strip_heredoc
|
38
38
|
Webpacker::VersionChecker - #{check_failed}
|
39
39
|
|
40
|
-
You are currently not checking for consistent versions of shakapacker gem and npm package. A version mismatch or usage of semantic versioning wildcard (~ or ^) has been detected.
|
40
|
+
You are currently not checking for consistent versions of shakapacker gem and npm package. A version mismatch or usage of semantic versioning wildcard (~ or ^) without a lockfile has been detected.
|
41
41
|
|
42
42
|
Version mismatch can lead to incorrect behavior and bugs. You should ensure that both the gem and npm package dependencies are locked to the same version.
|
43
43
|
|
@@ -61,9 +61,9 @@ module Webpacker
|
|
61
61
|
Detected: #{node_package_version.raw}
|
62
62
|
gem: #{gem_version}
|
63
63
|
Ensure the installed version of the gem is the same as the version of
|
64
|
-
your installed node package.
|
65
|
-
Do not use
|
66
|
-
|
64
|
+
your installed node package.
|
65
|
+
Do not use >= or ~> in your Gemfile for shakapacker without a lockfile.
|
66
|
+
Do not use ^ or ~ in your package.json for shakapacker without a lockfile.
|
67
67
|
MSG
|
68
68
|
end
|
69
69
|
|
@@ -91,20 +91,29 @@ module Webpacker
|
|
91
91
|
attr_reader :package_json
|
92
92
|
|
93
93
|
def self.build
|
94
|
-
new(package_json_path)
|
94
|
+
new(package_json_path, yarn_lock_path, package_lock_path)
|
95
95
|
end
|
96
96
|
|
97
97
|
def self.package_json_path
|
98
98
|
Rails.root.join("package.json")
|
99
99
|
end
|
100
100
|
|
101
|
-
def
|
101
|
+
def self.yarn_lock_path
|
102
|
+
Rails.root.join("yarn.lock")
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.package_lock_path
|
106
|
+
Rails.root.join("package-lock.json")
|
107
|
+
end
|
108
|
+
|
109
|
+
def initialize(package_json, yarn_lock, package_lock)
|
102
110
|
@package_json = package_json
|
111
|
+
@yarn_lock = yarn_lock
|
112
|
+
@package_lock = package_lock
|
103
113
|
end
|
104
114
|
|
105
115
|
def raw
|
106
|
-
|
107
|
-
parsed_package_contents.dig("dependencies", "shakapacker").to_s
|
116
|
+
@raw ||= find_version
|
108
117
|
end
|
109
118
|
|
110
119
|
def semver_wildcard?
|
@@ -147,6 +156,60 @@ module Webpacker
|
|
147
156
|
def package_json_contents
|
148
157
|
@package_json_contents ||= File.read(package_json)
|
149
158
|
end
|
159
|
+
|
160
|
+
def find_version
|
161
|
+
if File.exist?(@yarn_lock)
|
162
|
+
version = from_yarn_lock
|
163
|
+
|
164
|
+
return version unless version.nil?
|
165
|
+
end
|
166
|
+
|
167
|
+
if File.exist?(@package_lock)
|
168
|
+
version = from_package_lock
|
169
|
+
|
170
|
+
return version unless version.nil?
|
171
|
+
end
|
172
|
+
|
173
|
+
parsed_package_contents = JSON.parse(package_json_contents)
|
174
|
+
parsed_package_contents.dig("dependencies", "shakapacker").to_s
|
175
|
+
end
|
176
|
+
|
177
|
+
def from_package_lock
|
178
|
+
package_lock_contents = File.read(@package_lock)
|
179
|
+
parsed_lock_contents = JSON.parse(package_lock_contents)
|
180
|
+
|
181
|
+
pkg = parsed_lock_contents.dig("packages", "node_modules/shakapacker")
|
182
|
+
pkg = parsed_lock_contents.dig("dependencies", "shakapacker") if pkg.nil?
|
183
|
+
|
184
|
+
pkg&.fetch("version", nil)
|
185
|
+
end
|
186
|
+
|
187
|
+
def from_yarn_lock
|
188
|
+
found_pkg = false
|
189
|
+
version = nil
|
190
|
+
matcher = /\A"?shakapacker@.+:/
|
191
|
+
|
192
|
+
File.foreach(@yarn_lock, chomp: true) do |line|
|
193
|
+
next if line.start_with?("#")
|
194
|
+
|
195
|
+
# if we've found the start of the packages details and then come across
|
196
|
+
# a line that is not indented we've hit the end of the package details
|
197
|
+
break if found_pkg && !line.start_with?(" ")
|
198
|
+
|
199
|
+
if found_pkg
|
200
|
+
m = line.match(/\A {2}version:? "?(?<package_version>[\w.-]+)"?\z/)
|
201
|
+
|
202
|
+
next unless m
|
203
|
+
|
204
|
+
version = m[:package_version]
|
205
|
+
break
|
206
|
+
end
|
207
|
+
|
208
|
+
found_pkg = true if matcher.match(line)
|
209
|
+
end
|
210
|
+
|
211
|
+
version
|
212
|
+
end
|
150
213
|
end
|
151
214
|
end
|
152
215
|
end
|
data/lib/webpacker.rb
CHANGED
data/package.json
CHANGED
data/test/configuration_test.rb
CHANGED
@@ -90,6 +90,18 @@ class ConfigurationTest < Webpacker::Test
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
+
def test_nested_entries?
|
94
|
+
refute @config.nested_entries?
|
95
|
+
|
96
|
+
with_rails_env("development") do
|
97
|
+
refute Webpacker.config.nested_entries?
|
98
|
+
end
|
99
|
+
|
100
|
+
with_rails_env("test") do
|
101
|
+
refute Webpacker.config.nested_entries?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
93
105
|
def test_ensure_consistent_versioning?
|
94
106
|
refute @config.ensure_consistent_versioning?
|
95
107
|
|
@@ -100,25 +112,75 @@ class ConfigurationTest < Webpacker::Test
|
|
100
112
|
with_rails_env("test") do
|
101
113
|
refute Webpacker.config.ensure_consistent_versioning?
|
102
114
|
end
|
115
|
+
end
|
103
116
|
|
104
|
-
|
105
|
-
|
117
|
+
def test_webpacker_precompile
|
118
|
+
assert @config.webpacker_precompile?
|
106
119
|
|
107
|
-
|
120
|
+
ENV["WEBPACKER_PRECOMPILE"] = "no"
|
121
|
+
refute Webpacker.config.webpacker_precompile?
|
108
122
|
|
109
|
-
|
123
|
+
ENV["WEBPACKER_PRECOMPILE"] = "yes"
|
124
|
+
assert Webpacker.config.webpacker_precompile?
|
110
125
|
|
111
|
-
|
126
|
+
ENV["WEBPACKER_PRECOMPILE"] = "false"
|
127
|
+
refute Webpacker.config.webpacker_precompile?
|
112
128
|
|
113
|
-
|
129
|
+
ENV["WEBPACKER_PRECOMPILE"] = "true"
|
130
|
+
assert Webpacker.config.webpacker_precompile?
|
114
131
|
|
115
|
-
|
116
|
-
|
117
|
-
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_no_precompile.yml", __dir__)),
|
118
|
-
env: "production"
|
119
|
-
)
|
132
|
+
ENV["WEBPACKER_PRECOMPILE"] = "n"
|
133
|
+
refute Webpacker.config.webpacker_precompile?
|
120
134
|
|
121
|
-
|
122
|
-
|
135
|
+
ENV["WEBPACKER_PRECOMPILE"] = "y"
|
136
|
+
assert Webpacker.config.webpacker_precompile?
|
137
|
+
|
138
|
+
ENV["WEBPACKER_PRECOMPILE"] = "f"
|
139
|
+
refute Webpacker.config.webpacker_precompile?
|
140
|
+
|
141
|
+
ENV["WEBPACKER_PRECOMPILE"] = "t"
|
142
|
+
assert Webpacker.config.webpacker_precompile?
|
143
|
+
|
144
|
+
@no_precompile_config = Webpacker::Configuration.new(
|
145
|
+
root_path: @config.root_path,
|
146
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_no_precompile.yml", __dir__)),
|
147
|
+
env: "production"
|
148
|
+
)
|
149
|
+
|
150
|
+
assert @no_precompile_config.webpacker_precompile?
|
151
|
+
|
152
|
+
ENV["WEBPACKER_PRECOMPILE"] = nil
|
153
|
+
|
154
|
+
refute @no_precompile_config.webpacker_precompile?
|
155
|
+
|
156
|
+
@invalid_path_config = Webpacker::Configuration.new(
|
157
|
+
root_path: @config.root_path,
|
158
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/invalid_path.yml", __dir__)),
|
159
|
+
env: "default"
|
160
|
+
)
|
161
|
+
|
162
|
+
refute @invalid_path_config.webpacker_precompile?
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_fall_back_to_bundled_config_with_the_same_name_for_standard_environments
|
166
|
+
@no_default_config = Webpacker::Configuration.new(
|
167
|
+
root_path: @config.root_path,
|
168
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_defaults_fallback.yml", __dir__)),
|
169
|
+
env: "default"
|
170
|
+
)
|
171
|
+
|
172
|
+
refute @no_default_config.cache_manifest? # fall back to "default" config from bundled file
|
173
|
+
refute @no_default_config.webpacker_precompile? # use "default" config from custom file
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_fall_back_to_bundled_production_config_for_custom_environments
|
177
|
+
@no_env_config = Webpacker::Configuration.new(
|
178
|
+
root_path: @config.root_path,
|
179
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_defaults_fallback.yml", __dir__)),
|
180
|
+
env: "staging"
|
181
|
+
)
|
182
|
+
|
183
|
+
assert @no_env_config.cache_manifest? # fall back to "production" config from bundled file
|
184
|
+
refute @no_env_config.webpacker_precompile? # use "staging" config from custom file
|
123
185
|
end
|
124
186
|
end
|