shakapacker 7.0.3 → 7.1.0
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 +4 -4
- data/.github/workflows/dummy.yml +3 -1
- data/.github/workflows/generator.yml +3 -1
- data/.github/workflows/jest.yml +4 -2
- data/.github/workflows/js-lint.yml +4 -2
- data/.github/workflows/rubocop.yml +3 -1
- data/.github/workflows/ruby-backward-compatibility.yml +3 -1
- data/.github/workflows/ruby.yml +4 -2
- data/CHANGELOG.md +7 -0
- data/README.md +29 -20
- data/docs/troubleshooting.md +4 -8
- data/docs/using_esbuild_loader.md +2 -4
- data/lib/install/template.rb +2 -2
- data/lib/shakapacker/deprecation_helper.rb +1 -1
- data/lib/shakapacker/dev_server_runner.rb +2 -1
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +35 -2
- data/lib/shakapacker/webpack_runner.rb +4 -3
- data/package/__tests__/index.js +24 -0
- data/package/index.d.ts +1 -1
- data/package/index.js +8 -2
- data/package.json +1 -1
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +5 -3
- data/spec/backward_compatibility_specs/configuration_spec.rb +12 -4
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +17 -16
- data/spec/backward_compatibility_specs/dev_server_spec.rb +1 -1
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +2 -0
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +2 -1
- data/spec/backward_compatibility_specs/helper_spec.rb +20 -20
- data/spec/backward_compatibility_specs/instance_spec.rb +3 -3
- data/spec/backward_compatibility_specs/manifest_spec.rb +12 -12
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +3 -3
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +9 -5
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +14 -18
- data/spec/dummy/config/webpack/commonWebpackConfig.js +1 -1
- data/spec/fixtures/beta_pnpm-lock.v7.yaml +116 -0
- data/spec/fixtures/beta_pnpm-lock.v8.yaml +2537 -0
- data/spec/fixtures/git_url_pnpm-lock.v7.yaml +126 -0
- data/spec/fixtures/git_url_pnpm-lock.v8.yaml +3728 -0
- data/spec/fixtures/github_url_pnpm-lock.v7.yaml +126 -0
- data/spec/fixtures/github_url_pnpm-lock.v8.yaml +3728 -0
- data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +18 -0
- data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +22 -0
- data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +117 -0
- data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +117 -0
- data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +116 -0
- data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +2558 -0
- data/spec/fixtures/without_pnpm-lock.v7.yaml +23 -0
- data/spec/fixtures/without_pnpm-lock.v8.yaml +27 -0
- data/spec/generator_specs/generator_spec.rb +7 -3
- data/spec/shakapacker/compiler_strategy_spec.rb +5 -3
- data/spec/shakapacker/configuration_spec.rb +12 -2
- data/spec/shakapacker/dev_server_runner_spec.rb +22 -16
- data/spec/shakapacker/dev_server_spec.rb +1 -1
- data/spec/shakapacker/digest_strategy_spec.rb +2 -0
- data/spec/shakapacker/engine_rake_tasks_spec.rb +2 -1
- data/spec/shakapacker/helper_spec.rb +20 -20
- data/spec/shakapacker/instance_spec.rb +2 -2
- data/spec/shakapacker/manifest_spec.rb +12 -12
- data/spec/shakapacker/mtime_strategy_spec.rb +3 -3
- data/spec/shakapacker/rake_tasks_spec.rb +5 -2
- data/spec/shakapacker/shakapacker_spec.rb +4 -4
- data/spec/shakapacker/version_checker_spec.rb +468 -121
- data/spec/shakapacker/webpack_runner_spec.rb +14 -18
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b52fbe18d6cc69e790f1432b93a8badee45c64229b7e0b5ad9bf6e7645c1c28c
|
4
|
+
data.tar.gz: 94ba2b7a48537e4b3ece200e2983975b444a340edff45b9af3544b1709375c38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ade899e22f00c9863302d2a9aa7e58549d057b07be50d34d853751cabf59a9d318a637240734854059b352110b20245361ec7d427488166b4e481639b90cb380
|
7
|
+
data.tar.gz: 6364f8d109c008da994d01f7ad553472a90d5392511b796ba7286502d5f3b6969ad225cbd8e3364fb86da6f2dc5b19524631399eebae982b43558444cb886a0e
|
data/.github/workflows/dummy.yml
CHANGED
data/.github/workflows/jest.yml
CHANGED
@@ -13,9 +13,11 @@ jobs:
|
|
13
13
|
runs-on: ${{ matrix.os }}
|
14
14
|
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v4
|
17
|
+
with:
|
18
|
+
persist-credentials: false
|
17
19
|
- name: Use Node.js ${{ matrix.node }}
|
18
|
-
uses: actions/setup-node@
|
20
|
+
uses: actions/setup-node@v3
|
19
21
|
with:
|
20
22
|
node-version: ${{ matrix.node }}
|
21
23
|
cache: yarn
|
@@ -13,9 +13,11 @@ jobs:
|
|
13
13
|
runs-on: ${{ matrix.os }}
|
14
14
|
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v4
|
17
|
+
with:
|
18
|
+
persist-credentials: false
|
17
19
|
- name: Use Node.js ${{ matrix.node }}
|
18
|
-
uses: actions/setup-node@
|
20
|
+
uses: actions/setup-node@v3
|
19
21
|
with:
|
20
22
|
node-version: ${{ matrix.node }}
|
21
23
|
cache: yarn
|
data/.github/workflows/ruby.yml
CHANGED
@@ -29,11 +29,13 @@ jobs:
|
|
29
29
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
30
30
|
|
31
31
|
steps:
|
32
|
-
- uses: actions/checkout@
|
32
|
+
- uses: actions/checkout@v4
|
33
|
+
with:
|
34
|
+
persist-credentials: false
|
33
35
|
- uses: ruby/setup-ruby@v1
|
34
36
|
with:
|
35
37
|
ruby-version: ${{ matrix.ruby }}
|
36
38
|
bundler-cache: true
|
37
39
|
|
38
40
|
- name: Ruby specs
|
39
|
-
run: bundle exec rake run_spec:
|
41
|
+
run: bundle exec rake run_spec:gem
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,13 @@ Changes since last non-beta release.
|
|
9
9
|
|
10
10
|
_Please add entries here for your pull requests that are not yet released._
|
11
11
|
|
12
|
+
### Added
|
13
|
+
- Support passing custom webpack config directly to `generateWebpackConfig` for merging [PR 343](https://github.com/shakacode/shakapacker/pull/343) by [G-Rath](https://github.com/g-rath)
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
- Use `NODE_OPTIONS` to enable Node-specific debugging flags [PR 350](https://github.com/shakacode/shakapacker/pull/350)
|
17
|
+
- Add the boilplate `application.js` into `packs/` [PR 363](https://github.com/shakacode/shakapacker/pull/363)
|
18
|
+
|
12
19
|
## [v7.0.3] - July 7, 2023
|
13
20
|
### Fixed
|
14
21
|
- Fixed commands execution for projects with space in absolute path [PR 322](https://github.com/shakacode/shakapacker/pull/322) by [kukicola](https://github.com/kukicola).
|
data/README.md
CHANGED
@@ -465,26 +465,40 @@ First, you don't _need_ to use Shakapacker's webpack configuration. However, the
|
|
465
465
|
|
466
466
|
1. Your output files go to the right directory
|
467
467
|
2. Your output includes a manifest, via package [`webpack-assets-manifest`](https://github.com/webdeveric/webpack-assets-manifest) that maps output names (your 'packs') to the fingerprinted versions, including bundle-splitting dependencies. That's the main secret sauce of Shakapacker!
|
468
|
+
|
469
|
+
The webpack configuration used by Shakapacker lives in `config/webpack/webpack.config.js`; this makes it easy to customize the configuration beyond what's available in `config/shakapacker.yml` by giving you complete control of the final configuration. By default, this file exports the result of `generateWebpackConfig` which handles generating a webpack configuration based on `config/shakapacker.yml`.
|
468
470
|
|
469
|
-
The
|
471
|
+
The easiest way to modify this config is to pass your desired customizations to `generateWebpackConfig` which will use [webpack-merge](https://github.com/survivejs/webpack-merge) to merge them with the configuration generated from `config/shakapacker.yml`:
|
470
472
|
|
471
473
|
```js
|
472
|
-
//
|
473
|
-
|
474
|
+
// config/webpack/webpack.config.js
|
475
|
+
const { generateWebpackConfig } = require('shakapacker')
|
476
|
+
|
477
|
+
const options = {
|
478
|
+
resolve: {
|
479
|
+
extensions: ['.css', '.ts', '.tsx']
|
480
|
+
}
|
481
|
+
}
|
482
|
+
|
483
|
+
// This results in a new object copied from the mutable global
|
484
|
+
module.exports = generateWebpackConfig(options)
|
485
|
+
```
|
486
|
+
|
487
|
+
The `shakapacker` package also exports the `merge` function from [webpack-merge](https://github.com/survivejs/webpack-merge) to make it easier to do more advanced customizations:
|
488
|
+
|
489
|
+
```js
|
490
|
+
// config/webpack/webpack.config.js
|
474
491
|
const { generateWebpackConfig, merge } = require('shakapacker')
|
475
492
|
|
476
|
-
const
|
493
|
+
const webpackConfig = generateWebpackConfig()
|
477
494
|
|
478
495
|
const options = {
|
479
496
|
resolve: {
|
480
|
-
|
497
|
+
extensions: ['.css', '.ts', '.tsx']
|
481
498
|
}
|
482
499
|
}
|
483
500
|
|
484
|
-
|
485
|
-
// If you want to use this object for client and server rendering configurations,
|
486
|
-
// having a new object is essential.
|
487
|
-
module.exports = merge({}, baseWebpackConfig, options)
|
501
|
+
module.exports = merge(options, webpackConfig)
|
488
502
|
```
|
489
503
|
|
490
504
|
This example is based on [an example project](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/webpack.config.js)
|
@@ -513,12 +527,11 @@ Then `require` this file in your `config/webpack/webpack.config.js`:
|
|
513
527
|
```js
|
514
528
|
// config/webpack/webpack.config.js
|
515
529
|
// use the new NPM package name, `shakapacker`.
|
516
|
-
const { generateWebpackConfig
|
530
|
+
const { generateWebpackConfig } = require('shakapacker')
|
517
531
|
|
518
|
-
const webpackConfig = generateWebpackConfig()
|
519
532
|
const customConfig = require('./custom')
|
520
533
|
|
521
|
-
module.exports =
|
534
|
+
module.exports = generateWebpackConfig(customConfig)
|
522
535
|
```
|
523
536
|
|
524
537
|
If you need access to configs within Shakapacker's configuration, you can import them like so:
|
@@ -616,12 +629,10 @@ Then modify the webpack config to use it as a plugin:
|
|
616
629
|
|
617
630
|
```js
|
618
631
|
// config/webpack/webpack.config.js
|
619
|
-
const { generateWebpackConfig
|
620
|
-
|
621
|
-
const webpackConfig = generateWebpackConfig()
|
632
|
+
const { generateWebpackConfig } = require("shakapacker");
|
622
633
|
const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
623
634
|
|
624
|
-
module.exports =
|
635
|
+
module.exports = generateWebpackConfig({
|
625
636
|
plugins: [new ForkTSCheckerWebpackPlugin()],
|
626
637
|
});
|
627
638
|
```
|
@@ -638,9 +649,7 @@ Optionally, add the `CSS` extension to webpack config for easy resolution.
|
|
638
649
|
|
639
650
|
```js
|
640
651
|
// config/webpack/webpack.config.js
|
641
|
-
const { generateWebpackConfig
|
642
|
-
|
643
|
-
const webpackConfig = generateWebpackConfig()
|
652
|
+
const { generateWebpackConfig } = require('shakapacker')
|
644
653
|
|
645
654
|
const customConfig = {
|
646
655
|
resolve: {
|
@@ -648,7 +657,7 @@ const customConfig = {
|
|
648
657
|
}
|
649
658
|
}
|
650
659
|
|
651
|
-
module.exports =
|
660
|
+
module.exports = generateWebpackConfig(customConfig)
|
652
661
|
```
|
653
662
|
|
654
663
|
To enable `PostCSS`, `Sass` or `Less` support, add `CSS` support first and
|
data/docs/troubleshooting.md
CHANGED
@@ -150,11 +150,9 @@ To silent these warnings, please update `config/webpack/webpack.config.js`:
|
|
150
150
|
```js
|
151
151
|
const webpack = require('webpack')
|
152
152
|
const { resolve } = require('path')
|
153
|
-
const { generateWebpackConfig
|
153
|
+
const { generateWebpackConfig } = require('shakapacker')
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
module.exports = merge(webpackConfig, {
|
155
|
+
module.exports = generateWebpackConfig({
|
158
156
|
plugins: [
|
159
157
|
new webpack.ContextReplacementPlugin(
|
160
158
|
/angular(\\|\/)core(\\|\/)(@angular|esm5)/,
|
@@ -201,11 +199,9 @@ Instead do:
|
|
201
199
|
// config/webpack/webpack.config.js
|
202
200
|
|
203
201
|
const webpack = require('webpack')
|
204
|
-
const { generateWebpackConfig
|
205
|
-
|
206
|
-
const webpackConfig = generateWebpackConfig();
|
202
|
+
const { generateWebpackConfig } = require('shakapacker')
|
207
203
|
|
208
|
-
module.exports =
|
204
|
+
module.exports = generateWebpackConfig({
|
209
205
|
plugins: [
|
210
206
|
new webpack.ProvidePlugin({
|
211
207
|
$: 'jquery',
|
@@ -59,11 +59,9 @@ o do so, you need to modify your webpack configuration and use `ESBuildMinifyPlu
|
|
59
59
|
Example:
|
60
60
|
|
61
61
|
```js
|
62
|
-
const { generateWebpackConfig
|
62
|
+
const { generateWebpackConfig } = require('shakapacker')
|
63
63
|
const { ESBuildMinifyPlugin } = require('esbuild-loader')
|
64
64
|
|
65
|
-
const baseWebpackConfig = generateWebpackConfig()
|
66
|
-
|
67
65
|
const options = {
|
68
66
|
optimization: {
|
69
67
|
minimizer: [
|
@@ -74,7 +72,7 @@ const options = {
|
|
74
72
|
}
|
75
73
|
}
|
76
74
|
|
77
|
-
module.exports =
|
75
|
+
module.exports = generateWebpackConfig(options)
|
78
76
|
```
|
79
77
|
|
80
78
|
For more details, see instructions at https://github.com/shakacode/shakapacker#webpack-configuration and https://github.com/privatenumber/esbuild-loader#js-minification-eg-terser.
|
data/lib/install/template.rb
CHANGED
@@ -14,8 +14,8 @@ if Dir.exist?(Shakapacker.config.source_path)
|
|
14
14
|
say "The packs app source directory already exists"
|
15
15
|
else
|
16
16
|
say "Creating packs app source directory"
|
17
|
-
empty_directory "app/javascript"
|
18
|
-
copy_file "#{__dir__}/application.js", "app/javascript/application.js"
|
17
|
+
empty_directory "app/javascript/packs"
|
18
|
+
copy_file "#{__dir__}/application.js", "app/javascript/packs/application.js"
|
19
19
|
end
|
20
20
|
|
21
21
|
apply "#{__dir__}/binstubs.rb"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "thor"
|
2
2
|
|
3
3
|
module Shakapacker
|
4
|
-
DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/docs/v7_upgrade.md"
|
4
|
+
DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md"
|
5
5
|
DEPRECATION_MESSAGE = <<~MSG
|
6
6
|
DEPRECATION NOTICE:
|
7
7
|
|
@@ -66,6 +66,7 @@ module Shakapacker
|
|
66
66
|
env = Shakapacker::Compiler.env
|
67
67
|
env["SHAKAPACKER_CONFIG"] = @shakapacker_config
|
68
68
|
env["WEBPACK_SERVE"] = "true"
|
69
|
+
env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
|
69
70
|
|
70
71
|
cmd = if node_modules_bin_exist?
|
71
72
|
["#{@node_modules_bin_path}/webpack", "serve"]
|
@@ -83,7 +84,7 @@ module Shakapacker
|
|
83
84
|
end
|
84
85
|
|
85
86
|
if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
|
86
|
-
|
87
|
+
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk --trace-warnings"
|
87
88
|
end
|
88
89
|
|
89
90
|
cmd += ["--config", @webpack_config]
|
data/lib/shakapacker/version.rb
CHANGED
@@ -91,7 +91,7 @@ module Shakapacker
|
|
91
91
|
attr_reader :package_json
|
92
92
|
|
93
93
|
def self.build
|
94
|
-
new(package_json_path, yarn_lock_path, package_lock_path)
|
94
|
+
new(package_json_path, yarn_lock_path, package_lock_path, pnpm_lock_path)
|
95
95
|
end
|
96
96
|
|
97
97
|
def self.package_json_path
|
@@ -106,10 +106,15 @@ module Shakapacker
|
|
106
106
|
Rails.root.join("package-lock.json")
|
107
107
|
end
|
108
108
|
|
109
|
-
def
|
109
|
+
def self.pnpm_lock_path
|
110
|
+
Rails.root.join("pnpm-lock.yaml")
|
111
|
+
end
|
112
|
+
|
113
|
+
def initialize(package_json, yarn_lock, package_lock, pnpm_lock)
|
110
114
|
@package_json = package_json
|
111
115
|
@yarn_lock = yarn_lock
|
112
116
|
@package_lock = package_lock
|
117
|
+
@pnpm_lock = pnpm_lock
|
113
118
|
end
|
114
119
|
|
115
120
|
def raw
|
@@ -170,6 +175,12 @@ module Shakapacker
|
|
170
175
|
return version unless version.nil?
|
171
176
|
end
|
172
177
|
|
178
|
+
if File.exist?(@pnpm_lock)
|
179
|
+
version = from_pnpm_lock
|
180
|
+
|
181
|
+
return version unless version.nil?
|
182
|
+
end
|
183
|
+
|
173
184
|
parsed_package_contents = JSON.parse(package_json_contents)
|
174
185
|
parsed_package_contents.dig("dependencies", "shakapacker").to_s
|
175
186
|
end
|
@@ -210,6 +221,28 @@ module Shakapacker
|
|
210
221
|
|
211
222
|
version
|
212
223
|
end
|
224
|
+
|
225
|
+
def from_pnpm_lock
|
226
|
+
require "yaml"
|
227
|
+
|
228
|
+
content = YAML.load_file(@pnpm_lock)
|
229
|
+
|
230
|
+
content.fetch("packages", {}).each do |key, value|
|
231
|
+
return value["version"] if value["name"] == "shakapacker"
|
232
|
+
|
233
|
+
parts = key.split("/")
|
234
|
+
|
235
|
+
return parts[2] if parts[1] == "shakapacker"
|
236
|
+
next unless parts[1].start_with?("shakapacker@")
|
237
|
+
|
238
|
+
_, version = parts[1].split("@")
|
239
|
+
|
240
|
+
return version[0, version.index("(")] if version.include?("(")
|
241
|
+
return version
|
242
|
+
end
|
243
|
+
|
244
|
+
nil
|
245
|
+
end
|
213
246
|
end
|
214
247
|
end
|
215
248
|
end
|
@@ -19,6 +19,7 @@ module Shakapacker
|
|
19
19
|
def run
|
20
20
|
env = Shakapacker::Compiler.env
|
21
21
|
env["SHAKAPACKER_CONFIG"] = @shakapacker_config
|
22
|
+
env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
|
22
23
|
|
23
24
|
cmd = if node_modules_bin_exist?
|
24
25
|
["#{@node_modules_bin_path}/webpack"]
|
@@ -36,15 +37,15 @@ module Shakapacker
|
|
36
37
|
end
|
37
38
|
|
38
39
|
if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
|
39
|
-
|
40
|
+
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
|
40
41
|
end
|
41
42
|
|
42
43
|
if @argv.delete "--trace-deprecation"
|
43
|
-
|
44
|
+
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --trace-deprecation"
|
44
45
|
end
|
45
46
|
|
46
47
|
if @argv.delete "--no-deprecation"
|
47
|
-
|
48
|
+
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --no-deprecation"
|
48
49
|
end
|
49
50
|
|
50
51
|
# Webpack commands are not compatible with --config option.
|
data/package/__tests__/index.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
const index = require('../index')
|
2
|
+
const { generateWebpackConfig } = require("../index");
|
2
3
|
|
3
4
|
describe('index', () => {
|
4
5
|
test('exports webpack-merge v5 functions', () => {
|
@@ -19,4 +20,27 @@ describe('index', () => {
|
|
19
20
|
expect(webpackConfig2).not.toHaveProperty('newKey')
|
20
21
|
expect(webpackConfig2.output.path).not.toEqual('new value')
|
21
22
|
})
|
23
|
+
|
24
|
+
test('webpackConfig merges extra config', () => {
|
25
|
+
const { generateWebpackConfig } = require('../index')
|
26
|
+
|
27
|
+
const webpackConfig = generateWebpackConfig({
|
28
|
+
newKey: 'new value',
|
29
|
+
output: {
|
30
|
+
path: 'new path'
|
31
|
+
}
|
32
|
+
})
|
33
|
+
|
34
|
+
expect(webpackConfig).toHaveProperty('newKey', 'new value')
|
35
|
+
expect(webpackConfig).toHaveProperty('output.path', 'new path')
|
36
|
+
expect(webpackConfig).toHaveProperty('output.publicPath', '/packs/')
|
37
|
+
})
|
38
|
+
|
39
|
+
test('webpackConfig errors if multiple configs are provided', () => {
|
40
|
+
const { generateWebpackConfig } = require('../index')
|
41
|
+
|
42
|
+
expect(() => generateWebpackConfig({}, {})).toThrow(
|
43
|
+
'use webpack-merge to merge configs before passing them to Shakapacker'
|
44
|
+
)
|
45
|
+
})
|
22
46
|
})
|
data/package/index.d.ts
CHANGED
@@ -34,7 +34,7 @@ declare module 'shakapacker' {
|
|
34
34
|
|
35
35
|
export const config: Config
|
36
36
|
export const devServer: Record<string, unknown>
|
37
|
-
export function generateWebpackConfig(): Configuration
|
37
|
+
export function generateWebpackConfig(extraConfig?: Configuration): Configuration
|
38
38
|
export const globalMutableWebpackConfig: Configuration
|
39
39
|
export const baseConfig: Configuration
|
40
40
|
export const env: Env
|
data/package/index.js
CHANGED
@@ -19,9 +19,15 @@ const globalMutableWebpackConfig = () => {
|
|
19
19
|
return environmentConfig
|
20
20
|
}
|
21
21
|
|
22
|
-
const generateWebpackConfig = () => {
|
22
|
+
const generateWebpackConfig = (extraConfig = {}, ...extraArgs) => {
|
23
|
+
if (extraArgs.length > 0) {
|
24
|
+
throw new Error(
|
25
|
+
'Only one extra config may be passed here - use webpack-merge to merge configs before passing them to Shakapacker'
|
26
|
+
)
|
27
|
+
}
|
28
|
+
|
23
29
|
const environmentConfig = globalMutableWebpackConfig()
|
24
|
-
const immutable = webpackMerge.merge({}, environmentConfig)
|
30
|
+
const immutable = webpackMerge.merge({}, environmentConfig, extraConfig)
|
25
31
|
return immutable
|
26
32
|
}
|
27
33
|
|
data/package.json
CHANGED
@@ -2,17 +2,19 @@ require_relative "spec_helper_initializer"
|
|
2
2
|
|
3
3
|
describe "Webpacker::CompilerStrategy" do
|
4
4
|
describe "#from_config" do
|
5
|
-
it "returns
|
5
|
+
it "returns an instance of MtimeStrategy when compiler_strategy is set to mtime" do
|
6
6
|
allow(Webpacker.config).to receive(:compiler_strategy).and_return("mtime")
|
7
|
+
|
7
8
|
expect(Webpacker::CompilerStrategy.from_config).to be_an_instance_of(Webpacker::MtimeStrategy)
|
8
9
|
end
|
9
10
|
|
10
|
-
it "returns
|
11
|
+
it "returns an instance of DigestStrategy when compiler_strategy is set to digest" do
|
11
12
|
allow(Webpacker.config).to receive(:compiler_strategy).and_return("digest")
|
13
|
+
|
12
14
|
expect(Webpacker::CompilerStrategy.from_config).to be_an_instance_of(Webpacker::DigestStrategy)
|
13
15
|
end
|
14
16
|
|
15
|
-
it "raise exception for unknown compiler_strategy in the config file" do
|
17
|
+
it "raise an exception for unknown compiler_strategy in the config file" do
|
16
18
|
expected_error_message = "Unknown strategy 'other'. Available options are 'mtime' and 'digest'."
|
17
19
|
allow(Webpacker.config).to receive(:compiler_strategy).and_return("other")
|
18
20
|
|
@@ -14,36 +14,43 @@ describe "Webpacker::Configuration" do
|
|
14
14
|
|
15
15
|
it "#source_path returns correct path" do
|
16
16
|
source_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs").to_s
|
17
|
+
|
17
18
|
expect(config.source_path.to_s).to eq source_path
|
18
19
|
end
|
19
20
|
|
20
21
|
it "#source_entry_path returns correct path" do
|
21
22
|
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs", "entrypoints").to_s
|
23
|
+
|
22
24
|
expect(config.source_entry_path.to_s).to eq source_entry_path
|
23
25
|
end
|
24
26
|
|
25
27
|
it "#public_root_path returns correct path" do
|
26
28
|
public_root_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public").to_s
|
29
|
+
|
27
30
|
expect(config.public_path.to_s).to eq public_root_path
|
28
31
|
end
|
29
32
|
|
30
33
|
it "#public_output_path returns correct path" do
|
31
34
|
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs").to_s
|
35
|
+
|
32
36
|
expect(config.public_output_path.to_s).to eq public_output_path
|
33
37
|
end
|
34
38
|
|
35
39
|
it "#public_manifest_path returns correct path" do
|
36
40
|
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s
|
41
|
+
|
37
42
|
expect(config.public_manifest_path.to_s).to eq public_manifest_path
|
38
43
|
end
|
39
44
|
|
40
45
|
it "#manifest_path returns correct path" do
|
41
46
|
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s
|
47
|
+
|
42
48
|
expect(config.manifest_path.to_s).to eq manifest_path
|
43
49
|
end
|
44
50
|
|
45
51
|
it "#cache_path returns correct path" do
|
46
52
|
cache_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/tmp/webpacker").to_s
|
53
|
+
|
47
54
|
expect(config.cache_path.to_s).to eq cache_path
|
48
55
|
end
|
49
56
|
|
@@ -186,6 +193,7 @@ describe "Webpacker::Configuration" do
|
|
186
193
|
|
187
194
|
it "#public_output_path returns correct path" do
|
188
195
|
expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
|
196
|
+
|
189
197
|
expect(config.public_output_path.to_s).to eq expected_public_output_path
|
190
198
|
end
|
191
199
|
end
|
@@ -199,6 +207,7 @@ describe "Webpacker::Configuration" do
|
|
199
207
|
|
200
208
|
it "#manifest_path returns correct expected value" do
|
201
209
|
expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs", "manifest.json").to_s
|
210
|
+
|
202
211
|
expect(config.manifest_path.to_s).to eq expected_manifest_path
|
203
212
|
end
|
204
213
|
end
|
@@ -206,8 +215,8 @@ describe "Webpacker::Configuration" do
|
|
206
215
|
context "with webpacker_precompile entry set to false" do
|
207
216
|
describe "#webpacker_precompile?" do
|
208
217
|
before :each do
|
209
|
-
ENV.delete("WEBPACKER_PRECOMPILE")
|
210
218
|
ENV.delete("SHAKAPACKER_PRECOMPILE")
|
219
|
+
ENV.delete("WEBPACKER_PRECOMPILE")
|
211
220
|
end
|
212
221
|
|
213
222
|
let(:config) {
|
@@ -229,9 +238,8 @@ describe "Webpacker::Configuration" do
|
|
229
238
|
expect(subject).to be true
|
230
239
|
end
|
231
240
|
|
232
|
-
it "returns false with WEBPACKER_PRECOMPILE set to
|
233
|
-
|
234
|
-
ENV.delete("WEBPACKER_PRECOMPILE")
|
241
|
+
it "returns false with WEBPACKER_PRECOMPILE set to nil" do
|
242
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = nil
|
235
243
|
expect(subject).to be false
|
236
244
|
end
|
237
245
|
end
|