shakapacker 6.1.1 → 6.3.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.node-version +1 -1
- data/CHANGELOG.md +48 -4
- data/CONTRIBUTING.md +2 -2
- data/Gemfile.lock +1 -1
- data/README.md +60 -26
- data/docs/customizing_babel_config.md +2 -0
- data/docs/deployment.md +2 -2
- data/docs/style_loader_vs_mini_css.md +48 -0
- data/docs/troubleshooting.md +18 -0
- data/docs/using_esbuild_loader.md +1 -1
- data/docs/using_swc_loader.md +2 -2
- data/docs/v6_upgrade.md +72 -74
- data/lib/install/config/webpacker.yml +16 -0
- data/lib/install/template.rb +2 -2
- data/lib/tasks/webpacker/clean.rake +1 -3
- data/lib/tasks/webpacker/clobber.rake +1 -3
- data/lib/tasks/webpacker/compile.rake +1 -4
- data/lib/webpacker/commands.rb +2 -2
- data/lib/webpacker/compiler.rb +12 -30
- data/lib/webpacker/configuration.rb +22 -4
- data/lib/webpacker/dev_server.rb +11 -2
- data/lib/webpacker/helper.rb +26 -8
- data/lib/webpacker/instance.rb +1 -1
- data/lib/webpacker/manifest.rb +4 -4
- data/lib/webpacker/railtie.rb +7 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/version_checker.rb +152 -0
- data/package/__tests__/config.js +11 -0
- data/package/babel/preset.js +0 -1
- data/package/config.js +6 -0
- data/package/environments/base.js +1 -1
- data/package/inliningCss.js +1 -1
- data/package/rules/__tests__/file.js +35 -0
- data/package/rules/__tests__/index.js +11 -0
- data/package/rules/__tests__/raw.js +18 -0
- data/package/rules/file.js +2 -17
- data/package/rules/raw.js +2 -2
- data/package/swc/index.js +3 -3
- data/package.json +12 -11
- data/test/compiler_test.rb +27 -32
- data/test/configuration_test.rb +48 -2
- data/test/fixtures/beta_package.json +13 -0
- data/test/fixtures/git_url_package.json +13 -0
- data/test/fixtures/github_url_package.json +13 -0
- data/test/fixtures/normal_package.json +13 -0
- data/test/fixtures/relative_path_package.json +13 -0
- data/test/fixtures/semver_caret_package.json +13 -0
- data/test/fixtures/semver_tilde_package.json +13 -0
- data/test/fixtures/without_package.json +13 -0
- data/test/helper_test.rb +34 -12
- data/test/manifest_test.rb +3 -3
- data/test/test_app/config/webpacker.yml +4 -0
- data/test/test_app/config/webpacker_manifest_path.yml +80 -0
- data/test/test_app/config/webpacker_no_precompile.yml +7 -0
- data/test/version_checker_test.rb +271 -0
- data/test/webpacker_test.rb +15 -0
- data/yarn.lock +917 -884
- metadata +32 -5
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "webpacker/version"
|
3
|
+
|
4
|
+
module Webpacker
|
5
|
+
class VersionChecker
|
6
|
+
attr_reader :node_package_version
|
7
|
+
|
8
|
+
MAJOR_MINOR_PATCH_VERSION_REGEX = /(\d+)\.(\d+)\.(\d+)/.freeze
|
9
|
+
|
10
|
+
def self.build
|
11
|
+
new(NodePackageVersion.build)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(node_package_version)
|
15
|
+
@node_package_version = node_package_version
|
16
|
+
end
|
17
|
+
|
18
|
+
def raise_if_gem_and_node_package_versions_differ
|
19
|
+
# Skip check if package is not in package.json or listed from relative path, git repo or github URL
|
20
|
+
return if node_package_version.skip_processing?
|
21
|
+
|
22
|
+
node_major_minor_patch = node_package_version.major_minor_patch
|
23
|
+
gem_major_minor_patch = gem_major_minor_patch_version
|
24
|
+
versions_match = node_major_minor_patch[0] == gem_major_minor_patch[0] &&
|
25
|
+
node_major_minor_patch[1] == gem_major_minor_patch[1] &&
|
26
|
+
node_major_minor_patch[2] == gem_major_minor_patch[2]
|
27
|
+
|
28
|
+
uses_wildcard = node_package_version.semver_wildcard?
|
29
|
+
|
30
|
+
if !Webpacker.config.ensure_consistent_versioning? && (uses_wildcard || !versions_match)
|
31
|
+
check_failed = if uses_wildcard
|
32
|
+
"Semver wildcard detected"
|
33
|
+
else
|
34
|
+
"Version mismatch detected"
|
35
|
+
end
|
36
|
+
|
37
|
+
warn <<-MSG.strip_heredoc
|
38
|
+
Webpacker::VersionChecker - #{check_failed}
|
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.
|
41
|
+
|
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
|
+
|
44
|
+
You can enable the version check by setting `ensure_consistent_versioning: true` in your `webpacker.yml` file.
|
45
|
+
|
46
|
+
Checking for gem and npm package versions mismatch or wildcard will be enabled by default in the next major version of shakapacker.
|
47
|
+
MSG
|
48
|
+
|
49
|
+
return
|
50
|
+
end
|
51
|
+
|
52
|
+
raise_differing_versions_warning unless versions_match
|
53
|
+
|
54
|
+
raise_node_semver_version_warning if uses_wildcard
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def common_error_msg
|
60
|
+
<<-MSG.strip_heredoc
|
61
|
+
Detected: #{node_package_version.raw}
|
62
|
+
gem: #{gem_version}
|
63
|
+
Ensure the installed version of the gem is the same as the version of
|
64
|
+
your installed node package. Do not use >= or ~> in your Gemfile for shakapacker.
|
65
|
+
Do not use ^ or ~ in your package.json for shakapacker.
|
66
|
+
Run `yarn add shakapacker --exact` in the directory containing folder node_modules.
|
67
|
+
MSG
|
68
|
+
end
|
69
|
+
|
70
|
+
def raise_differing_versions_warning
|
71
|
+
msg = "**ERROR** Webpacker: Webpacker gem and node package versions do not match\n#{common_error_msg}"
|
72
|
+
raise msg
|
73
|
+
end
|
74
|
+
|
75
|
+
def raise_node_semver_version_warning
|
76
|
+
msg = "**ERROR** Webpacker: Your node package version for shakapacker contains a "\
|
77
|
+
"^ or ~\n#{common_error_msg}"
|
78
|
+
raise msg
|
79
|
+
end
|
80
|
+
|
81
|
+
def gem_version
|
82
|
+
Webpacker::VERSION
|
83
|
+
end
|
84
|
+
|
85
|
+
def gem_major_minor_patch_version
|
86
|
+
match = gem_version.match(MAJOR_MINOR_PATCH_VERSION_REGEX)
|
87
|
+
[match[1], match[2], match[3]]
|
88
|
+
end
|
89
|
+
|
90
|
+
class NodePackageVersion
|
91
|
+
attr_reader :package_json
|
92
|
+
|
93
|
+
def self.build
|
94
|
+
new(package_json_path)
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.package_json_path
|
98
|
+
Rails.root.join("package.json")
|
99
|
+
end
|
100
|
+
|
101
|
+
def initialize(package_json)
|
102
|
+
@package_json = package_json
|
103
|
+
end
|
104
|
+
|
105
|
+
def raw
|
106
|
+
parsed_package_contents = JSON.parse(package_json_contents)
|
107
|
+
parsed_package_contents.dig("dependencies", "shakapacker").to_s
|
108
|
+
end
|
109
|
+
|
110
|
+
def semver_wildcard?
|
111
|
+
raw.match(/[~^]/).present?
|
112
|
+
end
|
113
|
+
|
114
|
+
def skip_processing?
|
115
|
+
!package_specified? || relative_path? || git_url? || github_url?
|
116
|
+
end
|
117
|
+
|
118
|
+
def major_minor_patch
|
119
|
+
return if skip_processing?
|
120
|
+
|
121
|
+
match = raw.match(MAJOR_MINOR_PATCH_VERSION_REGEX)
|
122
|
+
unless match
|
123
|
+
raise "Cannot parse version number '#{raw}' (wildcard versions are not supported)"
|
124
|
+
end
|
125
|
+
|
126
|
+
[match[1], match[2], match[3]]
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def package_specified?
|
132
|
+
raw.present?
|
133
|
+
end
|
134
|
+
|
135
|
+
def relative_path?
|
136
|
+
raw.match(%r{(\.\.|\Afile:///)}).present?
|
137
|
+
end
|
138
|
+
|
139
|
+
def git_url?
|
140
|
+
raw.match(%r{^git}).present?
|
141
|
+
end
|
142
|
+
|
143
|
+
def github_url?
|
144
|
+
raw.match(%r{^([\w-]+\/[\w-]+)}).present?
|
145
|
+
end
|
146
|
+
|
147
|
+
def package_json_contents
|
148
|
+
@package_json_contents ||= File.read(package_json)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
data/package/__tests__/config.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/* global test expect, describe */
|
2
2
|
|
3
3
|
const { chdirCwd, chdirTestApp, resetEnv } = require('../utils/helpers')
|
4
|
+
const { resolve } = require('path')
|
4
5
|
|
5
6
|
chdirTestApp()
|
6
7
|
|
@@ -31,4 +32,14 @@ describe('Config', () => {
|
|
31
32
|
'app/elm'
|
32
33
|
])
|
33
34
|
})
|
35
|
+
|
36
|
+
test('should default manifestPath to the public dir', () => {
|
37
|
+
expect(config.manifestPath).toEqual(resolve('public/packs/manifest.json'))
|
38
|
+
})
|
39
|
+
|
40
|
+
test('should allow overriding manifestPath', () => {
|
41
|
+
process.env.WEBPACKER_CONFIG = 'config/webpacker_manifest_path.yml'
|
42
|
+
const config = require('../config')
|
43
|
+
expect(config.manifestPath).toEqual(resolve('app/packs/manifest.json'))
|
44
|
+
})
|
34
45
|
})
|
data/package/babel/preset.js
CHANGED
data/package/config.js
CHANGED
@@ -29,4 +29,10 @@ const getPublicPath = () => {
|
|
29
29
|
config.publicPath = getPublicPath()
|
30
30
|
config.publicPathWithoutCDN = `/${config.public_output_path}/`
|
31
31
|
|
32
|
+
if (config.manifest_path) {
|
33
|
+
config.manifestPath = resolve(config.manifest_path)
|
34
|
+
} else {
|
35
|
+
config.manifestPath = resolve(config.outputPath, 'manifest.json')
|
36
|
+
}
|
37
|
+
|
32
38
|
module.exports = config
|
data/package/inliningCss.js
CHANGED
@@ -2,6 +2,6 @@ const { runningWebpackDevServer } = require('./env')
|
|
2
2
|
const devServer = require('./dev_server')
|
3
3
|
|
4
4
|
// This logic is tied to lib/webpacker/instance.rb
|
5
|
-
const inliningCss = runningWebpackDevServer && devServer.hmr
|
5
|
+
const inliningCss = runningWebpackDevServer && devServer.hmr && devServer.inline_css !== false
|
6
6
|
|
7
7
|
module.exports = inliningCss
|
@@ -0,0 +1,35 @@
|
|
1
|
+
const file = require('../file')
|
2
|
+
|
3
|
+
describe('file', () => {
|
4
|
+
test('test expected file types', () => {
|
5
|
+
const types = [
|
6
|
+
'.bmp',
|
7
|
+
'.gif',
|
8
|
+
'.jpg',
|
9
|
+
'.jpeg',
|
10
|
+
'.png',
|
11
|
+
'.tiff',
|
12
|
+
'.ico',
|
13
|
+
'.avif',
|
14
|
+
'.webp',
|
15
|
+
'.eot',
|
16
|
+
'.otf',
|
17
|
+
'.ttf',
|
18
|
+
'.woff',
|
19
|
+
'.woff2',
|
20
|
+
'.svg',
|
21
|
+
]
|
22
|
+
types.forEach(type => expect(file.test.test(type)).toBe(true))
|
23
|
+
})
|
24
|
+
|
25
|
+
test('exclude expected file types', () => {
|
26
|
+
const types = [
|
27
|
+
'.js',
|
28
|
+
'.mjs',
|
29
|
+
'.jsx',
|
30
|
+
'.ts',
|
31
|
+
'.tsx',
|
32
|
+
]
|
33
|
+
types.forEach(type => expect(file.exclude.test(type)).toBe(true))
|
34
|
+
})
|
35
|
+
})
|
@@ -0,0 +1,11 @@
|
|
1
|
+
const rules = require('../index')
|
2
|
+
|
3
|
+
describe('index', () => {
|
4
|
+
test('rule tests are regexes', () => {
|
5
|
+
rules.forEach(rule => expect(rule.test instanceof RegExp).toBe(true))
|
6
|
+
})
|
7
|
+
|
8
|
+
test('rule excludes are regexes', () => {
|
9
|
+
rules.forEach(rule => expect(rule.exclude instanceof RegExp).toBe(true))
|
10
|
+
})
|
11
|
+
})
|
@@ -0,0 +1,18 @@
|
|
1
|
+
const raw = require('../raw')
|
2
|
+
|
3
|
+
describe('raw', () => {
|
4
|
+
test('test expected file types', () => {
|
5
|
+
expect(raw.test.test('.html')).toBe(true)
|
6
|
+
})
|
7
|
+
|
8
|
+
test('exclude expected file types', () => {
|
9
|
+
const types = [
|
10
|
+
'.js',
|
11
|
+
'.mjs',
|
12
|
+
'.jsx',
|
13
|
+
'.ts',
|
14
|
+
'.tsx',
|
15
|
+
]
|
16
|
+
types.forEach(type => expect(raw.exclude.test(type)).toBe(true))
|
17
|
+
})
|
18
|
+
})
|
data/package/rules/file.js
CHANGED
@@ -2,23 +2,8 @@ const { dirname, join } = require('path')
|
|
2
2
|
const { source_path: sourcePath } = require('../config')
|
3
3
|
|
4
4
|
module.exports = {
|
5
|
-
test:
|
6
|
-
|
7
|
-
/\.gif$/,
|
8
|
-
/\.jpe?g$/,
|
9
|
-
/\.png$/,
|
10
|
-
/\.tiff$/,
|
11
|
-
/\.ico$/,
|
12
|
-
/\.avif$/,
|
13
|
-
/\.webp$/,
|
14
|
-
/\.eot$/,
|
15
|
-
/\.otf$/,
|
16
|
-
/\.ttf$/,
|
17
|
-
/\.woff$/,
|
18
|
-
/\.woff2$/,
|
19
|
-
/\.svg$/
|
20
|
-
],
|
21
|
-
exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
|
5
|
+
test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg)$/,
|
6
|
+
exclude: /\.(js|mjs|jsx|ts|tsx)$/,
|
22
7
|
type: 'asset/resource',
|
23
8
|
generator: {
|
24
9
|
filename: (pathData) => {
|
data/package/rules/raw.js
CHANGED
data/package/swc/index.js
CHANGED
@@ -30,12 +30,12 @@ const getSwcLoaderConfig = (filenameToProcess) => {
|
|
30
30
|
: 'ecmascript',
|
31
31
|
[isTypescriptFile(filenameToProcess) ? 'tsx' : 'jsx']:
|
32
32
|
isJsxFile(filenameToProcess)
|
33
|
-
}
|
33
|
+
},
|
34
|
+
loose: true
|
34
35
|
},
|
35
36
|
sourceMaps: true,
|
36
37
|
env: {
|
37
|
-
coreJs:
|
38
|
-
loose: true,
|
38
|
+
coreJs: 3,
|
39
39
|
exclude: ['transform-typeof-symbol'],
|
40
40
|
mode: 'entry'
|
41
41
|
}
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "shakapacker",
|
3
|
-
"version": "6.
|
3
|
+
"version": "6.3.0-rc.1",
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
5
|
"main": "package/index.js",
|
6
6
|
"files": [
|
@@ -12,16 +12,17 @@
|
|
12
12
|
"yarn": ">=1 <4"
|
13
13
|
},
|
14
14
|
"peerDependencies": {
|
15
|
-
"@babel/core": "^7.
|
16
|
-
"@babel/plugin-transform-runtime": "^7.
|
17
|
-
"@babel/preset-env": "^7.
|
18
|
-
"@babel/runtime": "^7.
|
19
|
-
"babel-loader": "^8.2.
|
15
|
+
"@babel/core": "^7.17.9",
|
16
|
+
"@babel/plugin-transform-runtime": "^7.17.9",
|
17
|
+
"@babel/preset-env": "^7.16.11",
|
18
|
+
"@babel/runtime": "^7.17.9",
|
19
|
+
"babel-loader": "^8.2.4",
|
20
20
|
"compression-webpack-plugin": "^9.0.0",
|
21
|
-
"terser-webpack-plugin": "^5.
|
22
|
-
"webpack": "^5.
|
21
|
+
"terser-webpack-plugin": "^5.3.1",
|
22
|
+
"webpack": "^5.72.0",
|
23
23
|
"webpack-assets-manifest": "^5.0.6",
|
24
|
-
"webpack-cli": "^4.
|
24
|
+
"webpack-cli": "^4.9.2",
|
25
|
+
"webpack-dev-server": "^4.8.1",
|
25
26
|
"webpack-merge": "^5.8.0"
|
26
27
|
},
|
27
28
|
"dependencies": {
|
@@ -30,7 +31,7 @@
|
|
30
31
|
"path-complete-extname": "^1.0.0"
|
31
32
|
},
|
32
33
|
"devDependencies": {
|
33
|
-
"babel-loader": "^8.2.
|
34
|
+
"babel-loader": "^8.2.4",
|
34
35
|
"compression-webpack-plugin": "^9.0.0",
|
35
36
|
"esbuild-loader": "^2.18.0",
|
36
37
|
"eslint": "^7.32.0",
|
@@ -41,7 +42,7 @@
|
|
41
42
|
"eslint-plugin-react": "^7.26.0",
|
42
43
|
"jest": "^27.2.1",
|
43
44
|
"swc-loader": "^0.1.15",
|
44
|
-
"webpack": "^5.
|
45
|
+
"webpack": "^5.72.0",
|
45
46
|
"webpack-assets-manifest": "^5.0.6",
|
46
47
|
"webpack-merge": "^5.8.0"
|
47
48
|
},
|
data/test/compiler_test.rb
CHANGED
@@ -1,20 +1,6 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class CompilerTest < Minitest::Test
|
4
|
-
def remove_compilation_digest_path
|
5
|
-
Webpacker.compiler.send(:compilation_digest_path).tap do |path|
|
6
|
-
path.delete if path.exist?
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def setup
|
11
|
-
remove_compilation_digest_path
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
remove_compilation_digest_path
|
16
|
-
end
|
17
|
-
|
18
4
|
def test_custom_environment_variables
|
19
5
|
assert_nil Webpacker.compiler.send(:webpack_env)["FOO"]
|
20
6
|
Webpacker.compiler.env["FOO"] = "BAR"
|
@@ -23,37 +9,46 @@ class CompilerTest < Minitest::Test
|
|
23
9
|
Webpacker.compiler.env = {}
|
24
10
|
end
|
25
11
|
|
26
|
-
def
|
27
|
-
|
28
|
-
assert !Webpacker.compiler.fresh?
|
12
|
+
def setup
|
13
|
+
@manifest_timestamp = Time.parse("2021-01-01 12:34:56 UTC")
|
29
14
|
end
|
30
15
|
|
31
|
-
def
|
32
|
-
|
16
|
+
def with_stubs(latest_timestamp:, manifest_exists: true)
|
17
|
+
Webpacker.compiler.stub :latest_modified_timestamp, latest_timestamp do
|
18
|
+
FileTest.stub :exist?, manifest_exists do
|
19
|
+
File.stub :mtime, @manifest_timestamp do
|
20
|
+
yield
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
33
24
|
end
|
34
25
|
|
35
|
-
def
|
36
|
-
|
26
|
+
def test_freshness_when_manifest_missing
|
27
|
+
latest_timestamp = @manifest_timestamp + 3600
|
37
28
|
|
38
|
-
|
39
|
-
|
40
|
-
Webpacker.compiler.compile
|
41
|
-
assert Webpacker.compiler.fresh?
|
29
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
|
30
|
+
assert Webpacker.compiler.stale?
|
42
31
|
end
|
43
32
|
end
|
44
33
|
|
45
|
-
def
|
46
|
-
|
34
|
+
def test_freshness_when_manifest_older
|
35
|
+
latest_timestamp = @manifest_timestamp + 3600
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
|
37
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i) do
|
38
|
+
assert Webpacker.compiler.stale?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_freshness_when_manifest_newer
|
43
|
+
latest_timestamp = @manifest_timestamp - 3600
|
44
|
+
|
45
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i) do
|
51
46
|
assert Webpacker.compiler.fresh?
|
52
47
|
end
|
53
48
|
end
|
54
49
|
|
55
|
-
def
|
56
|
-
|
50
|
+
def test_compile
|
51
|
+
assert !Webpacker.compiler.compile
|
57
52
|
end
|
58
53
|
|
59
54
|
def test_external_env_variables
|
data/test/configuration_test.rb
CHANGED
@@ -28,14 +28,14 @@ class ConfigurationTest < Webpacker::Test
|
|
28
28
|
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
|
29
29
|
assert_equal @config.public_output_path.to_s, public_output_path
|
30
30
|
|
31
|
-
@
|
31
|
+
@public_root_config = Webpacker::Configuration.new(
|
32
32
|
root_path: @config.root_path,
|
33
33
|
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_public_root.yml", __dir__)),
|
34
34
|
env: "production"
|
35
35
|
)
|
36
36
|
|
37
37
|
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
|
38
|
-
assert_equal @
|
38
|
+
assert_equal @public_root_config.public_output_path.to_s, public_output_path
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_public_manifest_path
|
@@ -43,6 +43,20 @@ class ConfigurationTest < Webpacker::Test
|
|
43
43
|
assert_equal @config.public_manifest_path.to_s, public_manifest_path
|
44
44
|
end
|
45
45
|
|
46
|
+
def test_manifest_path
|
47
|
+
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
|
48
|
+
assert_equal @config.manifest_path.to_s, manifest_path
|
49
|
+
|
50
|
+
@manifest_config = Webpacker::Configuration.new(
|
51
|
+
root_path: @config.root_path,
|
52
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_manifest_path.yml", __dir__)),
|
53
|
+
env: "production"
|
54
|
+
)
|
55
|
+
|
56
|
+
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs", "manifest.json").to_s
|
57
|
+
assert_equal @manifest_config.manifest_path.to_s, manifest_path
|
58
|
+
end
|
59
|
+
|
46
60
|
def test_cache_path
|
47
61
|
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/webpacker").to_s
|
48
62
|
assert_equal @config.cache_path.to_s, cache_path
|
@@ -75,4 +89,36 @@ class ConfigurationTest < Webpacker::Test
|
|
75
89
|
assert Webpacker.config.compile?
|
76
90
|
end
|
77
91
|
end
|
92
|
+
|
93
|
+
def test_ensure_consistent_versioning?
|
94
|
+
refute @config.ensure_consistent_versioning?
|
95
|
+
|
96
|
+
with_rails_env("development") do
|
97
|
+
assert Webpacker.config.ensure_consistent_versioning?
|
98
|
+
end
|
99
|
+
|
100
|
+
with_rails_env("test") do
|
101
|
+
refute Webpacker.config.ensure_consistent_versioning?
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_webpacker_precompile
|
105
|
+
assert @config.webpacker_precompile
|
106
|
+
|
107
|
+
ENV["WEBPACKER_PRECOMPILE"] = "false"
|
108
|
+
|
109
|
+
refute Webpacker.config.webpacker_precompile?
|
110
|
+
|
111
|
+
ENV["WEBPACKER_PRECOMPILE"] = "yes"
|
112
|
+
|
113
|
+
assert Webpacker.config.webpacker_precompile?
|
114
|
+
|
115
|
+
@no_precompile_config = Webpacker::Configuration.new(
|
116
|
+
root_path: @config.root_path,
|
117
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_no_precompile.yml", __dir__)),
|
118
|
+
env: "production"
|
119
|
+
)
|
120
|
+
|
121
|
+
refute @no_precompile_config.webpacker_precompile
|
122
|
+
end
|
123
|
+
end
|
78
124
|
end
|