shakapacker 6.2.1 → 6.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +53 -4
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +2 -1
- data/Gemfile.lock +84 -74
- data/README.md +172 -65
- data/docs/react.md +262 -0
- data/docs/sprockets.md +10 -0
- data/docs/v6_upgrade.md +1 -1
- data/lib/install/config/webpacker.yml +14 -0
- data/lib/tasks/webpacker/clean.rake +1 -3
- data/lib/tasks/webpacker/clobber.rake +1 -3
- data/lib/tasks/webpacker/compile.rake +3 -14
- data/lib/tasks/webpacker.rake +0 -1
- data/lib/webpacker/base_strategy.rb +24 -0
- data/lib/webpacker/compiler.rb +4 -67
- data/lib/webpacker/compiler_strategy.rb +20 -0
- data/lib/webpacker/configuration.rb +13 -0
- data/lib/webpacker/digest_strategy.rb +59 -0
- data/lib/webpacker/helper.rb +26 -1
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +2 -2
- data/lib/webpacker/mtime_strategy.rb +40 -0
- data/lib/webpacker/version.rb +1 -1
- data/package/babel/preset.js +0 -1
- data/package/environments/__tests__/base.js +30 -3
- data/package/environments/base.js +8 -1
- data/package/rules/file.js +2 -2
- data/package.json +13 -12
- data/test/compiler_strategy_test.rb +27 -0
- data/test/compiler_test.rb +26 -34
- data/test/configuration_test.rb +24 -4
- data/test/digest_strategy_test.rb +33 -0
- data/test/helper_test.rb +22 -0
- data/test/manifest_test.rb +3 -3
- data/test/mtime_strategy_test.rb +42 -0
- data/test/rake_tasks_test.rb +0 -34
- data/test/test_app/app/packs/entrypoints/generated/something.js +2 -0
- data/test/test_app/config/webpacker.yml +1 -0
- data/test/test_app/config/webpacker_nested_entries.yml +83 -0
- data/test/test_app/config/webpacker_no_precompile.yml +7 -0
- data/yarn.lock +917 -884
- metadata +21 -5
- data/lib/tasks/webpacker/yarn_install.rake +0 -18
- data/lib/tasks/yarn.rake +0 -38
data/lib/webpacker/manifest.rb
CHANGED
@@ -104,12 +104,12 @@ class Webpacker::Manifest
|
|
104
104
|
|
105
105
|
def missing_file_from_manifest_error(bundle_name)
|
106
106
|
<<-MSG
|
107
|
-
|
107
|
+
Shakapacker can't find #{bundle_name} in #{config.manifest_path}. Possible causes:
|
108
108
|
1. You forgot to install node packages (try `yarn install`) or are running an incompatible version of Node
|
109
109
|
2. Your app has code with a non-standard extension (like a `.jsx` file) but the extension is not in the `extensions` config in `config/webpacker.yml`
|
110
110
|
3. You have set compile: false (see `config/webpacker.yml`) for this environment
|
111
111
|
(unless you are using the `bin/webpacker -w` or the `bin/webpacker-dev-server`, in which case maybe you aren't running the dev server in the background?)
|
112
|
-
4. webpack has not yet
|
112
|
+
4. webpack has not yet FINISHED running to reflect updates.
|
113
113
|
5. You have misconfigured Webpacker's `config/webpacker.yml` file.
|
114
114
|
6. Your webpack configuration is not creating a manifest.
|
115
115
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "webpacker/base_strategy"
|
2
|
+
|
3
|
+
module Webpacker
|
4
|
+
class MtimeStrategy < BaseStrategy
|
5
|
+
# Returns true if manifest file mtime is newer than the timestamp of the last modified watched file
|
6
|
+
def fresh?
|
7
|
+
manifest_mtime > latest_modified_timestamp
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns true if manifest file mtime is older than the timestamp of the last modified watched file
|
11
|
+
def stale?
|
12
|
+
!fresh?
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def manifest_mtime
|
18
|
+
config.manifest_path.exist? ? File.mtime(config.manifest_path).to_i : 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def latest_modified_timestamp
|
22
|
+
if Rails.env.development?
|
23
|
+
warn <<~MSG.strip
|
24
|
+
Webpacker::Compiler - Slow setup for development
|
25
|
+
|
26
|
+
Prepare JS assets with either:
|
27
|
+
1. Running `bin/webpacker-dev-server`
|
28
|
+
2. Set `compile` to false in webpacker.yml and run `bin/webpacker -w`
|
29
|
+
MSG
|
30
|
+
end
|
31
|
+
|
32
|
+
root_path = Pathname.new(File.expand_path(config.root_path))
|
33
|
+
expanded_paths = [*default_watched_paths].map do |path|
|
34
|
+
root_path.join(path)
|
35
|
+
end
|
36
|
+
latest_modified = Dir[*expanded_paths].max_by { |f| File.mtime(f) }
|
37
|
+
File.mtime(latest_modified).to_i
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/webpacker/version.rb
CHANGED
data/package/babel/preset.js
CHANGED
@@ -3,15 +3,18 @@
|
|
3
3
|
// environment.js expects to find config/webpacker.yml and resolved modules from
|
4
4
|
// the root of a Rails project
|
5
5
|
|
6
|
-
const { chdirTestApp, chdirCwd } = require('../../utils/helpers')
|
6
|
+
const { chdirTestApp, chdirCwd, resetEnv } = require('../../utils/helpers')
|
7
7
|
|
8
8
|
chdirTestApp()
|
9
9
|
|
10
10
|
const { resolve } = require('path')
|
11
|
-
|
11
|
+
|
12
12
|
const baseConfig = require('../base')
|
13
|
+
const config = require("../../config");
|
13
14
|
|
14
15
|
describe('Base config', () => {
|
16
|
+
beforeEach(() => jest.resetModules() && resetEnv())
|
17
|
+
|
15
18
|
afterAll(chdirCwd)
|
16
19
|
|
17
20
|
describe('config', () => {
|
@@ -21,11 +24,33 @@ describe('Base config', () => {
|
|
21
24
|
)
|
22
25
|
})
|
23
26
|
|
24
|
-
test('should return
|
27
|
+
test('should return only 2 entry points with config.nested_entries == false', () => {
|
28
|
+
expect(config.nested_entries).toEqual(false)
|
29
|
+
|
30
|
+
expect(baseConfig.entry.multi_entry.sort()).toEqual([
|
31
|
+
resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
|
32
|
+
resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
|
33
|
+
])
|
34
|
+
expect(baseConfig.entry['generated/something']).toEqual(undefined)
|
35
|
+
})
|
36
|
+
|
37
|
+
test('should returns top level and nested entry points with config.nested_entries == true', () => {
|
38
|
+
process.env.WEBPACKER_CONFIG = 'config/webpacker_nested_entries.yml'
|
39
|
+
const config = require("../../config");
|
40
|
+
const baseConfig = require('../base')
|
41
|
+
|
42
|
+
expect(config.nested_entries).toEqual(true)
|
43
|
+
|
44
|
+
expect(baseConfig.entry.application).toEqual(
|
45
|
+
resolve('app', 'packs', 'entrypoints', 'application.js')
|
46
|
+
)
|
25
47
|
expect(baseConfig.entry.multi_entry.sort()).toEqual([
|
26
48
|
resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
|
27
49
|
resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
|
28
50
|
])
|
51
|
+
expect(baseConfig.entry['generated/something']).toEqual(
|
52
|
+
resolve('app', 'packs', 'entrypoints', 'generated', 'something.js')
|
53
|
+
)
|
29
54
|
})
|
30
55
|
|
31
56
|
test('should return output', () => {
|
@@ -36,6 +61,8 @@ describe('Base config', () => {
|
|
36
61
|
})
|
37
62
|
|
38
63
|
test('should return default loader rules for each file in config/loaders', () => {
|
64
|
+
const rules = require('../../rules')
|
65
|
+
|
39
66
|
const defaultRules = Object.keys(rules)
|
40
67
|
const configRules = baseConfig.module.rules
|
41
68
|
|
@@ -14,8 +14,15 @@ const { moduleExists } = require('../utils/helpers')
|
|
14
14
|
const getEntryObject = () => {
|
15
15
|
const entries = {}
|
16
16
|
const rootPath = join(config.source_path, config.source_entry_path)
|
17
|
+
if (config.source_entry_path === '/' && config.nested_entries) {
|
18
|
+
throw new Error(
|
19
|
+
"Your webpacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
|
20
|
+
"'true'. Doing this would result in packs for every one of your source files"
|
21
|
+
)
|
22
|
+
}
|
23
|
+
const nesting = config.nested_entries ? '**/' : ''
|
17
24
|
|
18
|
-
globSync(`${rootPath}
|
25
|
+
globSync(`${rootPath}/${nesting}*.*`).forEach((path) => {
|
19
26
|
const namespace = relative(join(rootPath), dirname(path))
|
20
27
|
const name = join(namespace, basename(path, extname(path)))
|
21
28
|
let assetPaths = resolve(path)
|
data/package/rules/file.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const { dirname
|
1
|
+
const { dirname } = require('path')
|
2
2
|
const { source_path: sourcePath } = require('../config')
|
3
3
|
|
4
4
|
module.exports = {
|
@@ -12,7 +12,7 @@ module.exports = {
|
|
12
12
|
.split('/')
|
13
13
|
.slice(1)
|
14
14
|
|
15
|
-
const foldersWithStatic =
|
15
|
+
const foldersWithStatic = ['static', ...folders].join('/')
|
16
16
|
return `${foldersWithStatic}/[name]-[hash][ext][query]`
|
17
17
|
}
|
18
18
|
}
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "shakapacker",
|
3
|
-
"version": "6.
|
3
|
+
"version": "6.4.0",
|
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.
|
20
|
-
"compression-webpack-plugin": "^9.0.0",
|
21
|
-
"terser-webpack-plugin": "^5.
|
22
|
-
"webpack": "^5.
|
15
|
+
"@babel/core": "^7.17.9",
|
16
|
+
"@babel/plugin-transform-runtime": "^7.17.0",
|
17
|
+
"@babel/preset-env": "^7.16.11",
|
18
|
+
"@babel/runtime": "^7.17.9",
|
19
|
+
"babel-loader": "^8.2.4",
|
20
|
+
"compression-webpack-plugin": "^9.0.0 || ^10.0.0",
|
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.9.0",
|
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
|
},
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CompilerStrategyTest < Minitest::Test
|
4
|
+
def test_mtime_strategy_returned
|
5
|
+
Webpacker.config.stub :compiler_strategy, "mtime" do
|
6
|
+
assert_instance_of Webpacker::MtimeStrategy, Webpacker::CompilerStrategy.from_config
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_digest_strategy_returned
|
11
|
+
Webpacker.config.stub :compiler_strategy, "digest" do
|
12
|
+
assert_instance_of Webpacker::DigestStrategy, Webpacker::CompilerStrategy.from_config
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_raise_on_unknown_strategy
|
17
|
+
Webpacker.config.stub :compiler_strategy, "other" do
|
18
|
+
error = assert_raises do
|
19
|
+
Webpacker::CompilerStrategy.from_config
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal \
|
23
|
+
"Unknown strategy 'other'. Available options are 'mtime' and 'digest'.",
|
24
|
+
error.message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
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,43 @@ class CompilerTest < Minitest::Test
|
|
23
9
|
Webpacker.compiler.env = {}
|
24
10
|
end
|
25
11
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
12
|
+
def test_compile_true_when_fresh
|
13
|
+
mock = Minitest::Mock.new
|
14
|
+
mock.expect(:stale?, false)
|
15
|
+
Webpacker.compiler.stub(:strategy, mock) do
|
16
|
+
assert Webpacker.compiler.compile
|
17
|
+
end
|
18
|
+
assert_mock mock
|
29
19
|
end
|
30
20
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
21
|
+
def test_after_compile_hook_called_on_success
|
22
|
+
mock = Minitest::Mock.new
|
23
|
+
mock.expect(:stale?, true)
|
24
|
+
mock.expect(:after_compile_hook, nil)
|
34
25
|
|
35
|
-
def test_freshness_on_compile_success
|
36
26
|
status = OpenStruct.new(success?: true)
|
37
27
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
28
|
+
Webpacker.compiler.stub(:strategy, mock) do
|
29
|
+
Open3.stub :capture3, [:sterr, :stdout, status] do
|
30
|
+
Webpacker.compiler.compile
|
31
|
+
end
|
42
32
|
end
|
33
|
+
assert_mock mock
|
43
34
|
end
|
44
35
|
|
45
|
-
def
|
36
|
+
def test_after_compile_hook_called_on_failure
|
37
|
+
mock = Minitest::Mock.new
|
38
|
+
mock.expect(:stale?, true)
|
39
|
+
mock.expect(:after_compile_hook, nil)
|
40
|
+
|
46
41
|
status = OpenStruct.new(success?: false)
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
Webpacker.compiler.stub(:strategy, mock) do
|
44
|
+
Open3.stub :capture3, [:sterr, :stdout, status] do
|
45
|
+
Webpacker.compiler.compile
|
46
|
+
end
|
52
47
|
end
|
53
|
-
|
54
|
-
|
55
|
-
def test_compilation_digest_path
|
56
|
-
assert_equal Webpacker.compiler.send(:compilation_digest_path).basename.to_s, "last-compilation-digest-#{Webpacker.env}"
|
48
|
+
assert_mock mock
|
57
49
|
end
|
58
50
|
|
59
51
|
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
|
@@ -47,14 +47,14 @@ class ConfigurationTest < Webpacker::Test
|
|
47
47
|
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
|
48
48
|
assert_equal @config.manifest_path.to_s, manifest_path
|
49
49
|
|
50
|
-
@
|
50
|
+
@manifest_config = Webpacker::Configuration.new(
|
51
51
|
root_path: @config.root_path,
|
52
52
|
config_path: Pathname.new(File.expand_path("./test_app/config/webpacker_manifest_path.yml", __dir__)),
|
53
53
|
env: "production"
|
54
54
|
)
|
55
55
|
|
56
56
|
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/packs", "manifest.json").to_s
|
57
|
-
assert_equal @
|
57
|
+
assert_equal @manifest_config.manifest_path.to_s, manifest_path
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_cache_path
|
@@ -100,5 +100,25 @@ class ConfigurationTest < Webpacker::Test
|
|
100
100
|
with_rails_env("test") do
|
101
101
|
refute Webpacker.config.ensure_consistent_versioning?
|
102
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
|
103
123
|
end
|
104
124
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class DigestStrategyTest < Minitest::Test
|
4
|
+
def remove_compilation_digest_path
|
5
|
+
@digest_strategy.send(:compilation_digest_path).tap do |path|
|
6
|
+
path.delete if path.exist?
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@digest_strategy = Webpacker::DigestStrategy.new
|
12
|
+
remove_compilation_digest_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
remove_compilation_digest_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_freshness
|
20
|
+
assert @digest_strategy.stale?
|
21
|
+
assert !@digest_strategy.fresh?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_freshness_after_compilation_hook
|
25
|
+
@digest_strategy.after_compile_hook
|
26
|
+
assert @digest_strategy.fresh?
|
27
|
+
assert !@digest_strategy.stale?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_compilation_digest_path
|
31
|
+
assert_equal @digest_strategy.send(:compilation_digest_path).basename.to_s, "last-compilation-digest-#{Webpacker.env}"
|
32
|
+
end
|
33
|
+
end
|
data/test/helper_test.rb
CHANGED
@@ -115,6 +115,28 @@ class HelperTest < ActionView::TestCase
|
|
115
115
|
javascript_pack_tag("application", "bootstrap", defer: false)
|
116
116
|
end
|
117
117
|
|
118
|
+
def test_javascript_pack_with_append
|
119
|
+
append_javascript_pack_tag("bootstrap", defer: false)
|
120
|
+
assert_equal \
|
121
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
122
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
123
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>\n) +
|
124
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
125
|
+
javascript_pack_tag("application")
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_append_javascript_pack_tag_raises
|
129
|
+
error = assert_raises do
|
130
|
+
javascript_pack_tag("application")
|
131
|
+
append_javascript_pack_tag("bootstrap", defer: false)
|
132
|
+
end
|
133
|
+
|
134
|
+
assert_equal \
|
135
|
+
"You can only call append_javascript_pack_tag before javascript_pack_tag helper. " +
|
136
|
+
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide",
|
137
|
+
error.message
|
138
|
+
end
|
139
|
+
|
118
140
|
def test_javascript_pack_tag_splat
|
119
141
|
assert_equal \
|
120
142
|
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
data/test/manifest_test.rb
CHANGED
@@ -8,7 +8,7 @@ class ManifestTest < Minitest::Test
|
|
8
8
|
Webpacker.manifest.lookup!(asset_file)
|
9
9
|
end
|
10
10
|
|
11
|
-
assert_match "
|
11
|
+
assert_match "Shakapacker can't find #{asset_file} in #{manifest_path}", error.message
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_lookup_with_type_exception!
|
@@ -18,7 +18,7 @@ class ManifestTest < Minitest::Test
|
|
18
18
|
Webpacker.manifest.lookup!(asset_file, type: :javascript)
|
19
19
|
end
|
20
20
|
|
21
|
-
assert_match "
|
21
|
+
assert_match "Shakapacker can't find #{asset_file}.js in #{manifest_path}", error.message
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_lookup_success!
|
@@ -60,7 +60,7 @@ class ManifestTest < Minitest::Test
|
|
60
60
|
Webpacker.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
|
61
61
|
end
|
62
62
|
|
63
|
-
assert_match "
|
63
|
+
assert_match "Shakapacker can't find #{asset_file}.js in #{manifest_path}", error.message
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_lookup_entrypoint
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class MtimeStrategyTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@mtime_strategy = Webpacker::MtimeStrategy.new
|
6
|
+
@manifest_timestamp = Time.parse("2021-01-01 12:34:56 UTC")
|
7
|
+
end
|
8
|
+
|
9
|
+
def with_stubs(latest_timestamp:, manifest_exists: true)
|
10
|
+
@mtime_strategy.stub :latest_modified_timestamp, latest_timestamp do
|
11
|
+
FileTest.stub :exist?, manifest_exists do
|
12
|
+
File.stub :mtime, @manifest_timestamp do
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_freshness_when_manifest_missing
|
20
|
+
latest_timestamp = @manifest_timestamp + 3600
|
21
|
+
|
22
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
|
23
|
+
assert @mtime_strategy.stale?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_freshness_when_manifest_older
|
28
|
+
latest_timestamp = @manifest_timestamp + 3600
|
29
|
+
|
30
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i) do
|
31
|
+
assert @mtime_strategy.stale?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_freshness_when_manifest_newer
|
36
|
+
latest_timestamp = @manifest_timestamp - 3600
|
37
|
+
|
38
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i) do
|
39
|
+
assert @mtime_strategy.fresh?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/test/rake_tasks_test.rb
CHANGED
@@ -30,42 +30,8 @@ class RakeTasksTest < Minitest::Test
|
|
30
30
|
refute_includes output, "Webpacker requires Yarn"
|
31
31
|
end
|
32
32
|
|
33
|
-
def test_rake_webpacker_yarn_install_in_non_production_environments
|
34
|
-
assert_includes test_app_dev_dependencies, "right-pad"
|
35
|
-
|
36
|
-
Webpacker.with_node_env("test") do
|
37
|
-
Dir.chdir(test_app_path) do
|
38
|
-
`bundle exec rake webpacker:yarn_install`
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
assert_includes installed_node_module_names, "right-pad",
|
43
|
-
"Expected dev dependencies to be installed"
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_rake_webpacker_yarn_install_in_production_environment
|
47
|
-
Webpacker.with_node_env("production") do
|
48
|
-
Dir.chdir(test_app_path) do
|
49
|
-
`bundle exec rake webpacker:yarn_install`
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
refute_includes installed_node_module_names, "right-pad",
|
54
|
-
"Expected only production dependencies to be installed"
|
55
|
-
end
|
56
|
-
|
57
33
|
private
|
58
34
|
def test_app_path
|
59
35
|
File.expand_path("test_app", __dir__)
|
60
36
|
end
|
61
|
-
|
62
|
-
def test_app_dev_dependencies
|
63
|
-
package_json = File.expand_path("package.json", test_app_path)
|
64
|
-
JSON.parse(File.read(package_json))["devDependencies"]
|
65
|
-
end
|
66
|
-
|
67
|
-
def installed_node_module_names
|
68
|
-
node_modules_path = File.expand_path("node_modules", test_app_path)
|
69
|
-
Dir.chdir(node_modules_path) { Dir.glob("*") }
|
70
|
-
end
|
71
37
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Note: You must restart bin/webpacker-dev-server for changes to take effect
|
2
|
+
|
3
|
+
default: &default
|
4
|
+
source_path: app/packs
|
5
|
+
source_entry_path: entrypoints
|
6
|
+
nested_entries: true
|
7
|
+
public_root_path: public
|
8
|
+
public_output_path: packs
|
9
|
+
cache_path: tmp/webpacker
|
10
|
+
webpack_compile_output: false
|
11
|
+
webpack_loader: babel
|
12
|
+
|
13
|
+
# Location for manifest.json, defaults to {public_output_path}/manifest.json if unset
|
14
|
+
# manifest_path: public/packs/manifest.json
|
15
|
+
|
16
|
+
# Additional paths webpack should look up modules
|
17
|
+
# ['app/assets', 'engine/foo/app/assets']
|
18
|
+
additional_paths:
|
19
|
+
- app/assets
|
20
|
+
- /etc/yarn
|
21
|
+
- some.config.js
|
22
|
+
- app/elm
|
23
|
+
|
24
|
+
# Reload manifest.json on all requests so we reload latest compiled packs
|
25
|
+
cache_manifest: false
|
26
|
+
|
27
|
+
static_assets_extensions:
|
28
|
+
- .jpg
|
29
|
+
- .jpeg
|
30
|
+
- .png
|
31
|
+
- .gif
|
32
|
+
- .tiff
|
33
|
+
- .ico
|
34
|
+
- .svg
|
35
|
+
|
36
|
+
extensions:
|
37
|
+
- .mjs
|
38
|
+
- .js
|
39
|
+
|
40
|
+
development:
|
41
|
+
<<: *default
|
42
|
+
compile: true
|
43
|
+
ensure_consistent_versioning: true
|
44
|
+
|
45
|
+
# Reference: https://webpack.js.org/configuration/dev-server/
|
46
|
+
dev_server:
|
47
|
+
https: false
|
48
|
+
host: localhost
|
49
|
+
port: 3035
|
50
|
+
public: localhost:3035
|
51
|
+
hmr: false
|
52
|
+
overlay: true
|
53
|
+
disable_host_check: true
|
54
|
+
use_local_ip: false
|
55
|
+
pretty: false
|
56
|
+
|
57
|
+
test:
|
58
|
+
<<: *default
|
59
|
+
compile: true
|
60
|
+
|
61
|
+
# Compile test packs to a separate directory
|
62
|
+
public_output_path: packs-test
|
63
|
+
|
64
|
+
production:
|
65
|
+
<<: *default
|
66
|
+
|
67
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
68
|
+
compile: false
|
69
|
+
|
70
|
+
# Cache manifest.json for performance
|
71
|
+
cache_manifest: true
|
72
|
+
|
73
|
+
staging:
|
74
|
+
<<: *default
|
75
|
+
|
76
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
77
|
+
compile: false
|
78
|
+
|
79
|
+
# Cache manifest.json for performance
|
80
|
+
cache_manifest: true
|
81
|
+
|
82
|
+
# Compile staging packs to a separate directory
|
83
|
+
public_output_path: packs-staging
|