shakapacker 7.0.0.rc.1 → 7.0.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: aba276f401a1f78173be61e48f752843e048ccab75e2cea85789e0db511f120b
4
- data.tar.gz: d29b9940a940f999d5ec9be41a75fabf9d7601c44767b28bfca7c0068c537ded
3
+ metadata.gz: 0eef3643fb556af4dc928c1d651fa46cfe5543fc6d5a227d29fcbfd7b3876c3c
4
+ data.tar.gz: 4530e671bb02c0af5bbfc37ba1696fff4e81548c40af6df65a06e2bc2d0a9815
5
5
  SHA512:
6
- metadata.gz: dddcafead06f6db4f256759f7d8f243f5511f7b131d4bbdaae3da6cc3ea160854f82c70fd87ae313f33a14ec3309a6a762b35d24fcbffbd53c22a0eac0920abb
7
- data.tar.gz: 06c7e5ed689286cb05091c00390f3b4ef56bbbec19bb5a30354c8819c503373dd503f8ed9f240c3ca970d07506045a6be0dfc96b4a0f1a9faa5dfc2c3cbcbdc3
6
+ metadata.gz: a7803b77d1d0e9dff88d6cdb25f88c1a89fb4c036153e03d153fe994b216a82a69aaa85d446331945a528443fbd097ac4f49cb64661e66f29b5941a5971315a8
7
+ data.tar.gz: 98aba0b391b59a50932d43cab666604998d66c5bcf548f8ceea06c77919a9196ba5ca2861a204ce3f66cd490d69b64e0e8c0dfb10610b6ba64842049f49d2df4
data/CHANGELOG.md CHANGED
@@ -22,6 +22,7 @@ _Please add entries here for your pull requests that are not yet released._
22
22
  - Set CSS modules mode depending on file type. [PR 261](https://github.com/shakacode/shakapacker/pull/261) by [talyuk](https://github.com/talyuk).
23
23
  - All standard webpack entries with the camelCase format are now supported in `shakapacker.yml` in snake_case format. [PR276](https://github.com/shakacode/shakapacker/pull/276) by [ahangarha](https://github.com/ahangarha).
24
24
  - The `shakapacker:install` rake task now has an option to force overriding files using `FORCE=true` environment variable [PR311](https://github.com/shakacode/shakapacker/pull/311) by [ahangarha](https://github.com/ahangarha).
25
+ - Allow configuration of use of contentHash for specific environment [PR 234](https://github.com/shakacode/shakapacker/pull/234) by [justin808](https://github/justin808).
25
26
 
26
27
  ### Changed
27
28
  - Rename Webpacker to Shakapacker in the entire project including config files, binstubs, environment variables, etc. with a high degree of backward compatibility.
data/README.md CHANGED
@@ -216,6 +216,8 @@ Webpack intelligently includes only necessary files. In this example, the file `
216
216
 
217
217
  `nested_entries` allows you to have webpack entry points nested in subdirectories. This defaults to false so you don't accidentally create entry points for an entire tree of files. In other words, with `nested_entries: false`, you can have your entire `source_path` used for your source (using the `source_entry_path: /`) and you place files at the top level that you want as entry points. `nested_entries: true` allows you to have entries that are in subdirectories. This is useful if you have entries that are generated, so you can have a `generated` subdirectory and easily separate generated files from the rest of your codebase.
218
218
 
219
+ To enable/disable the usage of contentHash in any node environment (specified using the `NODE_ENV` environment variable), add/modify `useContentHash` with a boolean value in `config/shakapacker.yml`. This feature is disabled for all environments except production by default. You may not disable the content hash for a `NODE_ENV` of production as that would break the browser caching of assets. Notice that despite the possibility of enabling this option for the development environment, [it is not recommended](https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling).
220
+
219
221
  #### Setting custom config path
220
222
 
221
223
  You can use the environment variable `SHAKAPACKER_CONFIG` to enforce a particular path to the config file rather than the default `config/shakapacker.yml`.
@@ -1,4 +1,5 @@
1
1
  # Note: You must restart bin/shakapacker-dev-server for changes to take effect
2
+ # This file contains the defaults used by shakapacker.
2
3
 
3
4
  default: &default
4
5
  source_path: app/javascript
@@ -44,6 +45,11 @@ default: &default
44
45
  # Select whether the compiler will use SHA digest ('digest' option) or most most recent modified timestamp ('mtime') to determine freshness
45
46
  compiler_strategy: digest
46
47
 
48
+ # Select whether the compiler will always use a content hash and not just in production
49
+ # Don't use contentHash except for production for performance
50
+ # https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
51
+ useContentHash: false
52
+
47
53
  development:
48
54
  <<: *default
49
55
  compile: true
@@ -105,5 +111,8 @@ production:
105
111
  # Production depends on precompilation of packs prior to booting for performance.
106
112
  compile: false
107
113
 
114
+ # Use content hash for naming assets. Cannot be overridden by for production.
115
+ useContentHash: true
116
+
108
117
  # Cache manifest.json for performance
109
118
  cache_manifest: true
@@ -1,4 +1,4 @@
1
1
  module Shakapacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "7.0.0.rc.1".freeze
3
+ VERSION = "7.0.0".freeze
4
4
  end
@@ -0,0 +1,22 @@
1
+ const index = require('../index')
2
+
3
+ describe('index', () => {
4
+ describe('webpackConfig', () => {
5
+ test('is a global object', () => {
6
+ const { webpackConfig, globalMutableWebpackConfig } = require('../index')
7
+
8
+ expect(webpackConfig).toBe(globalMutableWebpackConfig)
9
+ })
10
+
11
+ test('Shows warning with deprecation message', () => {
12
+ const consoleSpy = jest.spyOn(console, "warn");
13
+
14
+ const { webpackConfig } = require('../index')
15
+
16
+ expect(consoleSpy).toHaveBeenCalledWith(
17
+ expect.stringMatching(/The 'webpackConfig' is deprecated/)
18
+ )
19
+ consoleSpy.mockRestore();
20
+ })
21
+ })
22
+ })
@@ -65,9 +65,9 @@ describe('Base config', () => {
65
65
  })
66
66
 
67
67
  test('should return output', () => {
68
- expect(baseConfig.output.filename).toEqual('js/[name].js')
68
+ expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
69
69
  expect(baseConfig.output.chunkFilename).toEqual(
70
- 'js/[name].chunk.js'
70
+ 'js/[name]-[contenthash].chunk.js'
71
71
  )
72
72
  })
73
73
 
@@ -65,9 +65,9 @@ describe('Base config', () => {
65
65
  })
66
66
 
67
67
  test('should return output', () => {
68
- expect(baseConfig.output.filename).toEqual('js/[name].js')
68
+ expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
69
69
  expect(baseConfig.output.chunkFilename).toEqual(
70
- 'js/[name].chunk.js'
70
+ 'js/[name]-[contenthash].chunk.js'
71
71
  )
72
72
  })
73
73
 
@@ -0,0 +1,53 @@
1
+ /* global test expect, describe, afterAll, beforeEach */
2
+
3
+ const { chdirTestApp, resetEnv } = require('../../utils/helpers')
4
+ const rootPath = process.cwd()
5
+ chdirTestApp()
6
+
7
+ describe('Development specific config', () => {
8
+ beforeEach(() => {
9
+ jest.resetModules()
10
+ resetEnv()
11
+ process.env['NODE_ENV'] = 'development'
12
+ })
13
+ afterAll(() => process.chdir(rootPath))
14
+
15
+ describe('with config.useContentHash = true', () => {
16
+ test('sets filename to use contentHash', () => {
17
+ const config = require("../../config");
18
+ config.useContentHash = true
19
+ const environmnetConfig = require('../development')
20
+
21
+ expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
+ expect(environmnetConfig.output.chunkFilename).toEqual(
23
+ 'js/[name]-[contenthash].chunk.js'
24
+ )
25
+ })
26
+ })
27
+
28
+ describe('with config.useContentHash = false', () => {
29
+ test('sets filename without using contentHash', () => {
30
+ const config = require("../../config");
31
+ config.useContentHash = false
32
+ const environmnetConfig = require('../development')
33
+
34
+ expect(environmnetConfig.output.filename).toEqual('js/[name].js')
35
+ expect(environmnetConfig.output.chunkFilename).toEqual(
36
+ 'js/[name].chunk.js'
37
+ )
38
+ })
39
+ })
40
+
41
+ describe('with unset config.useContentHash', () => {
42
+ test('sets filename without using contentHash', () => {
43
+ const config = require("../../config");
44
+ delete config.useContentHash
45
+ const environmnetConfig = require('../development')
46
+
47
+ expect(environmnetConfig.output.filename).toEqual('js/[name].js')
48
+ expect(environmnetConfig.output.chunkFilename).toEqual(
49
+ 'js/[name].chunk.js'
50
+ )
51
+ })
52
+ })
53
+ })
@@ -0,0 +1,53 @@
1
+ /* global test expect, describe, afterAll, beforeEach */
2
+
3
+ const { chdirTestApp, resetEnv } = require('../../utils/helpers')
4
+ const rootPath = process.cwd()
5
+ chdirTestApp()
6
+
7
+ describe('Production specific config', () => {
8
+ beforeEach(() => {
9
+ jest.resetModules()
10
+ resetEnv()
11
+ process.env['NODE_ENV'] = 'production'
12
+ })
13
+ afterAll(() => process.chdir(rootPath))
14
+
15
+ describe('with config.useContentHash = true', () => {
16
+ test('sets filename to use contentHash', () => {
17
+ const config = require("../../config");
18
+ config.useContentHash = true
19
+ const environmnetConfig = require('../production')
20
+
21
+ expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
+ expect(environmnetConfig.output.chunkFilename).toEqual(
23
+ 'js/[name]-[contenthash].chunk.js'
24
+ )
25
+ })
26
+ })
27
+
28
+ describe('with config.useContentHash = false', () => {
29
+ test('sets filename to use contentHash', () => {
30
+ const config = require("../../config");
31
+ config.useContentHash = false
32
+ const environmnetConfig = require('../production')
33
+
34
+ expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
35
+ expect(environmnetConfig.output.chunkFilename).toEqual(
36
+ 'js/[name]-[contenthash].chunk.js'
37
+ )
38
+ })
39
+ })
40
+
41
+ describe('with unset config.useContentHash', () => {
42
+ test('sets filename to use contentHash', () => {
43
+ const config = require("../../config");
44
+ delete config.useContentHash
45
+ const environmnetConfig = require('../production')
46
+
47
+ expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
48
+ expect(environmnetConfig.output.chunkFilename).toEqual(
49
+ 'js/[name]-[contenthash].chunk.js'
50
+ )
51
+ })
52
+ })
53
+ })
@@ -7,8 +7,8 @@ const { sync: globSync } = require('glob')
7
7
  const WebpackAssetsManifest = require('webpack-assets-manifest')
8
8
  const webpack = require('webpack')
9
9
  const rules = require('../rules')
10
- const { isProduction } = require('../env')
11
10
  const config = require('../config')
11
+ const { isProduction } = require('../env')
12
12
  const { moduleExists } = require('../utils/helpers')
13
13
 
14
14
  const getEntryObject = () => {
@@ -68,7 +68,7 @@ const getPlugins = () => {
68
68
  ]
69
69
 
70
70
  if (moduleExists('css-loader') && moduleExists('mini-css-extract-plugin')) {
71
- const hash = isProduction ? '-[contenthash:8]' : ''
71
+ const hash = isProduction || config.useContentHash ? '-[contenthash:8]' : ''
72
72
  const MiniCssExtractPlugin = require('mini-css-extract-plugin')
73
73
  plugins.push(
74
74
  new MiniCssExtractPlugin({
@@ -87,7 +87,8 @@ const getPlugins = () => {
87
87
 
88
88
  // Don't use contentHash except for production for performance
89
89
  // https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
90
- const hash = isProduction ? '-[contenthash]' : ''
90
+ const hash = isProduction || config.useContentHash ? '-[contenthash]' : ''
91
+
91
92
  module.exports = {
92
93
  mode: 'production',
93
94
  output: {
@@ -6,6 +6,7 @@ const CompressionPlugin = require('compression-webpack-plugin')
6
6
  const TerserPlugin = require('terser-webpack-plugin')
7
7
  const baseConfig = require('./base')
8
8
  const { moduleExists } = require('../utils/helpers')
9
+ const config = require('../config')
9
10
 
10
11
  const getPlugins = () => {
11
12
  const plugins = []
@@ -76,4 +77,12 @@ const productionConfig = {
76
77
  }
77
78
  }
78
79
 
80
+ if (config.useContentHash === true) {
81
+ // eslint-disable-next-line no-console
82
+ console.warn(`⚠️ WARNING
83
+ Setting 'useContentHash' to 'false' in the production environment (specified by NODE_ENV environment variable) is not allowed!
84
+ Content hashes get added to the filenames regardless of setting useContentHash in 'shakapacker.yml' to false.
85
+ `)
86
+ }
87
+
79
88
  module.exports = merge(baseConfig, productionConfig)
data/package/index.js CHANGED
@@ -25,27 +25,11 @@ const generateWebpackConfig = () => {
25
25
  return immutable
26
26
  }
27
27
 
28
- const webpackConfigForBackwardCompatibility = () => {
29
- // eslint-disable-next-line no-console
30
- console.log(`⚠️
31
- DEPRECATION NOTICE:
32
- The 'webpackConfig' is deprecated and will be removed in a future version.
33
- Please use 'globalMutableWebpackConfig' instead, or use
34
- 'generateWebpackConfig()' to avoid unwanted config manipulation across the app.
35
-
36
- For more information, see version 7 upgrade documentation at:
37
- https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md
38
- `)
39
-
40
- return globalMutableWebpackConfig()
41
- }
42
-
43
- module.exports = {
28
+ const shakapackerObject = {
44
29
  config, // shakapacker.yml
45
30
  devServer,
46
31
  generateWebpackConfig,
47
32
  globalMutableWebpackConfig: globalMutableWebpackConfig(),
48
- webpackConfig: webpackConfigForBackwardCompatibility(),
49
33
  baseConfig,
50
34
  env,
51
35
  rules,
@@ -54,3 +38,26 @@ module.exports = {
54
38
  inliningCss,
55
39
  ...webpackMerge
56
40
  }
41
+
42
+ // For backward compatibility
43
+ const shakapackerProxyHandler = {
44
+ get(target, prop) {
45
+ if (prop === 'webpackConfig') {
46
+ // eslint-disable-next-line no-console
47
+ console.warn(`⚠️
48
+ DEPRECATION NOTICE:
49
+ The 'webpackConfig' is deprecated and will be removed in a future version.
50
+ Please use 'globalMutableWebpackConfig' instead, or use
51
+ 'generateWebpackConfig()' to avoid unwanted config mutation across the app.
52
+
53
+ For more information, see version 7 upgrade documentation at:
54
+ https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md
55
+ `)
56
+ return globalMutableWebpackConfig()
57
+ }
58
+
59
+ return target[prop]
60
+ }
61
+ }
62
+
63
+ module.exports = new Proxy(shakapackerObject, shakapackerProxyHandler)
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shakapacker",
3
- "version": "7.0.0-rc.1",
3
+ "version": "7.0.0",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shakapacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.rc.1
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-06-12 00:00:00.000000000 Z
13
+ date: 2023-06-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -230,6 +230,7 @@ files:
230
230
  - package/__tests__/development.js
231
231
  - package/__tests__/env-bc.js
232
232
  - package/__tests__/env.js
233
+ - package/__tests__/index-bc.js
233
234
  - package/__tests__/index.js
234
235
  - package/__tests__/production-bc.js
235
236
  - package/__tests__/production.js
@@ -243,6 +244,8 @@ files:
243
244
  - package/env.js
244
245
  - package/environments/__tests__/base-bc.js
245
246
  - package/environments/__tests__/base.js
247
+ - package/environments/__tests__/development.js
248
+ - package/environments/__tests__/production.js
246
249
  - package/environments/base.js
247
250
  - package/environments/development.js
248
251
  - package/environments/production.js
@@ -525,7 +528,7 @@ homepage: https://github.com/shakacode/shakapacker
525
528
  licenses:
526
529
  - MIT
527
530
  metadata:
528
- source_code_uri: https://github.com/shakacode/shakapacker/tree/v7.0.0-rc.1
531
+ source_code_uri: https://github.com/shakacode/shakapacker/tree/v7.0.0
529
532
  post_install_message:
530
533
  rdoc_options: []
531
534
  require_paths:
@@ -537,9 +540,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
537
540
  version: 2.6.0
538
541
  required_rubygems_version: !ruby/object:Gem::Requirement
539
542
  requirements:
540
- - - ">"
543
+ - - ">="
541
544
  - !ruby/object:Gem::Version
542
- version: 1.3.1
545
+ version: '0'
543
546
  requirements: []
544
547
  rubygems_version: 3.4.12
545
548
  signing_key: