shakapacker 7.3.0.beta.1 → 8.0.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/.eslintignore +1 -1
- data/.eslintrc.js +29 -8
- data/.github/PULL_REQUEST_TEMPLATE.md +10 -3
- data/.github/workflows/dummy.yml +6 -1
- data/.github/workflows/generator.yml +14 -18
- data/.github/workflows/node.yml +56 -0
- data/.github/workflows/ruby.yml +29 -17
- data/.node-version +1 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +56 -5
- data/README.md +101 -48
- data/Rakefile +1 -7
- data/docs/customizing_babel_config.md +2 -2
- data/docs/deployment.md +13 -6
- data/docs/react.md +7 -13
- data/docs/troubleshooting.md +4 -4
- data/docs/using_esbuild_loader.md +1 -1
- data/docs/using_swc_loader.md +1 -1
- data/docs/v6_upgrade.md +1 -1
- data/docs/v8_upgrade.md +148 -0
- data/gemfiles/Gemfile-rails.7.1.x +12 -0
- data/jest.config.js +4 -0
- data/lib/install/config/shakapacker.yml +2 -2
- data/lib/install/template.rb +36 -30
- data/lib/shakapacker/base_strategy.rb +2 -1
- data/lib/shakapacker/compiler.rb +6 -21
- data/lib/shakapacker/configuration.rb +2 -46
- data/lib/shakapacker/deprecation_helper.rb +0 -78
- data/lib/shakapacker/dev_server.rb +1 -16
- data/lib/shakapacker/dev_server_runner.rb +2 -21
- data/lib/shakapacker/env.rb +1 -1
- data/lib/shakapacker/helper.rb +3 -3
- data/lib/shakapacker/instance.rb +1 -3
- data/lib/shakapacker/manifest.rb +1 -1
- data/lib/shakapacker/railtie.rb +7 -0
- data/lib/shakapacker/runner.rb +4 -18
- data/lib/shakapacker/utils/manager.rb +58 -0
- data/lib/shakapacker/utils/misc.rb +0 -12
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +9 -30
- data/lib/shakapacker/webpack_runner.rb +2 -21
- data/lib/shakapacker.rb +0 -2
- data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
- data/lib/tasks/shakapacker/check_manager.rake +3 -8
- data/lib/tasks/shakapacker/info.rake +6 -15
- data/package/babel/preset.js +15 -15
- data/package/config.js +15 -19
- data/package/dev_server.js +4 -4
- data/package/env.js +19 -17
- data/package/environments/base.js +41 -24
- data/package/environments/development.js +6 -6
- data/package/environments/production.js +16 -16
- data/package/environments/test.js +1 -1
- data/package/esbuild/index.js +6 -6
- data/package/index.d.ts +0 -2
- data/package/index.js +17 -46
- data/package/rules/babel.js +6 -8
- data/package/rules/coffee.js +2 -2
- data/package/rules/css.js +1 -1
- data/package/rules/erb.js +4 -4
- data/package/rules/esbuild.js +5 -7
- data/package/rules/file.js +14 -7
- data/package/rules/index.js +11 -11
- data/package/rules/jscommon.js +8 -5
- data/package/rules/less.js +10 -9
- data/package/rules/raw.js +1 -1
- data/package/rules/sass.js +4 -4
- data/package/rules/stylus.js +12 -7
- data/package/rules/swc.js +5 -7
- data/package/swc/index.js +10 -10
- data/package/utils/configPath.js +3 -18
- data/package/utils/defaultConfigPath.js +1 -1
- data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
- data/package/utils/helpers.js +2 -43
- data/package/utils/inliningCss.js +4 -3
- data/package/utils/snakeToCamelCase.js +5 -0
- data/package/webpackDevServerConfig.js +28 -25
- data/package.json +12 -18
- data/prettier.config.js +4 -0
- data/shakapacker.gemspec +1 -1
- data/spec/dummy/app/javascript/packs/application.js +1 -1
- data/spec/dummy/config/application.rb +3 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
- data/spec/dummy/config/shakapacker.yml +3 -4
- data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
- data/spec/dummy/config/webpack/webpack.config.js +1 -1
- data/spec/dummy/package.json +2 -1
- data/spec/dummy/yarn.lock +2 -3
- data/spec/fixtures/github_url_package-lock.v1.json +1 -1
- data/spec/fixtures/github_url_package-lock.v2.json +2 -2
- data/spec/fixtures/github_url_package.json +1 -1
- data/spec/fixtures/github_url_pnpm-lock.v7.yaml +1 -1
- data/spec/fixtures/github_url_pnpm-lock.v8.yaml +1 -1
- data/spec/fixtures/github_url_yarn.v1.lock +1 -1
- data/spec/fixtures/github_url_yarn.v2.lock +2 -2
- data/spec/generator_specs/e2e_template/template.rb +15 -28
- data/spec/generator_specs/generator_spec.rb +6 -136
- data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
- data/spec/shakapacker/compiler_spec.rb +1 -3
- data/spec/shakapacker/configuration_spec.rb +4 -56
- data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
- data/spec/shakapacker/dev_server_spec.rb +1 -16
- data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
- data/spec/shakapacker/helper_spec.rb +3 -3
- data/spec/shakapacker/instance_spec.rb +1 -3
- data/spec/shakapacker/rake_tasks_spec.rb +2 -14
- data/spec/shakapacker/shakapacker_spec.rb +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
- data/spec/shakapacker/test_app/package.json +2 -1
- data/spec/shakapacker/utils_manager_spec.rb +125 -0
- data/spec/shakapacker/version_checker_spec.rb +5 -5
- data/spec/shakapacker/webpack_runner_spec.rb +19 -28
- data/spec/support/package_json_helpers.rb +7 -4
- data/test/helpers.js +67 -0
- data/test/package/config.test.js +50 -0
- data/test/package/dev_server.test.js +44 -0
- data/test/package/development.test.js +43 -0
- data/test/package/env.test.js +57 -0
- data/test/package/environments/base.test.js +105 -0
- data/test/package/environments/development.test.js +50 -0
- data/test/package/environments/production.test.js +106 -0
- data/test/package/index.test.js +45 -0
- data/test/package/production.test.js +32 -0
- data/test/package/rules/babel.test.js +58 -0
- data/test/package/rules/esbuild.test.js +59 -0
- data/test/package/rules/file.test.js +81 -0
- data/test/package/rules/index.test.js +7 -0
- data/test/package/rules/raw.test.js +12 -0
- data/test/package/rules/swc.test.js +59 -0
- data/test/package/staging.test.js +31 -0
- data/test/package/test.test.js +28 -0
- data/yarn.lock +1278 -421
- metadata +50 -100
- data/.github/workflows/jest.yml +0 -33
- data/.github/workflows/js-lint.yml +0 -33
- data/.github/workflows/rubocop.yml +0 -28
- data/.github/workflows/ruby-backward-compatibility.yml +0 -51
- data/lib/install/package.json +0 -15
- data/lib/tasks/shakapacker/check_yarn.rake +0 -34
- data/lib/tasks/shakapacker/yarn_install.rake +0 -24
- data/lib/tasks/webpacker/binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_node.rake +0 -9
- data/lib/tasks/webpacker/check_yarn.rake +0 -9
- data/lib/tasks/webpacker/clean.rake +0 -9
- data/lib/tasks/webpacker/clobber.rake +0 -11
- data/lib/tasks/webpacker/compile.rake +0 -9
- data/lib/tasks/webpacker/info.rake +0 -9
- data/lib/tasks/webpacker/install.rake +0 -9
- data/lib/tasks/webpacker/verify_config.rake +0 -9
- data/lib/tasks/webpacker/verify_install.rake +0 -9
- data/lib/tasks/webpacker/yarn_install.rake +0 -9
- data/lib/tasks/webpacker.rake +0 -20
- data/lib/webpacker/dev_server_runner.rb +0 -9
- data/lib/webpacker/webpack_runner.rb +0 -9
- data/lib/webpacker.rb +0 -4
- data/package/__tests__/config-bc.js +0 -27
- data/package/__tests__/config.js +0 -46
- data/package/__tests__/dev_server-bc.js +0 -46
- data/package/__tests__/dev_server.js +0 -46
- data/package/__tests__/development-bc.js +0 -66
- data/package/__tests__/development.js +0 -66
- data/package/__tests__/env-bc.js +0 -59
- data/package/__tests__/env.js +0 -59
- data/package/__tests__/index-bc.js +0 -22
- data/package/__tests__/index.js +0 -46
- data/package/__tests__/production-bc.js +0 -51
- data/package/__tests__/production.js +0 -51
- data/package/__tests__/staging-bc.js +0 -53
- data/package/__tests__/staging.js +0 -53
- data/package/__tests__/test-bc.js +0 -43
- data/package/__tests__/test.js +0 -43
- data/package/environments/__tests__/base-bc.js +0 -107
- data/package/environments/__tests__/base.js +0 -107
- data/package/environments/__tests__/development.js +0 -53
- data/package/environments/__tests__/production.js +0 -92
- data/package/rules/__tests__/__utils__/webpack.js +0 -50
- data/package/rules/__tests__/babel.js +0 -63
- data/package/rules/__tests__/esbuild.js +0 -64
- data/package/rules/__tests__/file.js +0 -79
- data/package/rules/__tests__/index.js +0 -7
- data/package/rules/__tests__/raw.js +0 -18
- data/package/rules/__tests__/swc.js +0 -63
- data/package/utils/snakeToCamelCase +0 -7
- data/spec/backward_compatibility_specs/command_spec.rb +0 -116
- data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
- data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
- data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
- data/spec/backward_compatibility_specs/env_spec.rb +0 -23
- data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
- data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
- data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
- data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
- data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
- data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
@@ -2,6 +2,13 @@ require_relative "spec_helper_initializer"
|
|
2
2
|
require "shakapacker/webpack_runner"
|
3
3
|
|
4
4
|
describe "WebpackRunner" do
|
5
|
+
around do |example|
|
6
|
+
within_temp_directory do
|
7
|
+
FileUtils.cp_r(File.expand_path("./test_app", __dir__), Dir.pwd)
|
8
|
+
Dir.chdir("test_app") { example.run }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
5
12
|
before :all do
|
6
13
|
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
7
14
|
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
@@ -12,15 +19,21 @@ describe "WebpackRunner" do
|
|
12
19
|
ENV["RAILS_ENV"] = @original_rails_env
|
13
20
|
end
|
14
21
|
|
15
|
-
let(:test_app_path) {
|
22
|
+
let(:test_app_path) { Dir.pwd }
|
16
23
|
|
17
24
|
NODE_PACKAGE_MANAGERS.each do |fallback_manager|
|
18
25
|
context "when using package_json with #{fallback_manager} as the manager" do
|
19
|
-
|
26
|
+
before do
|
27
|
+
manager_name = fallback_manager.split("_")[0]
|
28
|
+
manager_version = "1.2.3"
|
29
|
+
manager_version = "4.5.6" if fallback_manager == "yarn_berry"
|
20
30
|
|
21
|
-
|
31
|
+
PackageJson.read.merge! { { "packageManager" => "#{manager_name}@#{manager_version}" } }
|
22
32
|
|
23
|
-
|
33
|
+
allow(Shakapacker::Utils::Manager).to receive(:error_unless_package_manager_is_obvious!)
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:package_json) { PackageJson.read(test_app_path) }
|
24
37
|
|
25
38
|
it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do
|
26
39
|
cmd = package_json.manager.native_exec_command("webpack", ["--config", "#{test_app_path}/config/webpack/webpack.config.js"])
|
@@ -44,42 +57,20 @@ describe "WebpackRunner" do
|
|
44
57
|
end
|
45
58
|
end
|
46
59
|
|
47
|
-
context "when not using package_json" do
|
48
|
-
with_use_package_json_gem(enabled: false)
|
49
|
-
|
50
|
-
it "supports running via node_modules" do
|
51
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
52
|
-
|
53
|
-
verify_command(cmd, use_node_modules: true)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "supports running via yarn" do
|
57
|
-
cmd = ["yarn", "webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
58
|
-
|
59
|
-
verify_command(cmd, use_node_modules: false)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "passes on arguments" do
|
63
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--watch"]
|
64
|
-
|
65
|
-
verify_command(cmd, argv: ["--watch"])
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
60
|
private
|
70
61
|
|
71
|
-
def verify_command(cmd,
|
62
|
+
def verify_command(cmd, argv: [])
|
72
63
|
Dir.chdir(test_app_path) do
|
73
64
|
klass = Shakapacker::WebpackRunner
|
74
65
|
instance = klass.new(argv)
|
75
66
|
|
76
67
|
allow(klass).to receive(:new).and_return(instance)
|
77
|
-
allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
|
78
68
|
allow(Kernel).to receive(:exec)
|
79
69
|
|
80
70
|
klass.run(argv)
|
81
71
|
|
82
72
|
expect(Kernel).to have_received(:exec).with(Shakapacker::Compiler.env, *cmd)
|
73
|
+
expect(Shakapacker::Utils::Manager).to have_received(:error_unless_package_manager_is_obvious!)
|
83
74
|
end
|
84
75
|
end
|
85
76
|
end
|
@@ -1,16 +1,19 @@
|
|
1
1
|
NODE_PACKAGE_MANAGERS = ["npm", "yarn_classic", "yarn_berry", "pnpm", "bun"]
|
2
2
|
|
3
|
-
def
|
3
|
+
def with_package_json_fallback_manager(fallback_manager)
|
4
4
|
around do |example|
|
5
|
-
old_use_package_json_gem_value = ENV["SHAKAPACKER_USE_PACKAGE_JSON_GEM"]
|
6
5
|
old_package_json_fallback_manager_value = ENV["PACKAGE_JSON_FALLBACK_MANAGER"]
|
7
6
|
|
8
|
-
ENV["SHAKAPACKER_USE_PACKAGE_JSON_GEM"] = enabled.to_s
|
9
7
|
ENV["PACKAGE_JSON_FALLBACK_MANAGER"] = fallback_manager.to_s
|
10
8
|
|
11
9
|
example.run
|
12
10
|
|
13
|
-
ENV["SHAKAPACKER_USE_PACKAGE_JSON_GEM"] = old_use_package_json_gem_value
|
14
11
|
ENV["PACKAGE_JSON_FALLBACK_MANAGER"] = old_package_json_fallback_manager_value
|
15
12
|
end
|
16
13
|
end
|
14
|
+
|
15
|
+
def within_temp_directory(tmpdir = nil, &block)
|
16
|
+
Dir.mktmpdir("shakapacker-", tmpdir) do |dir|
|
17
|
+
Dir.chdir(dir, &block)
|
18
|
+
end
|
19
|
+
end
|
data/test/helpers.js
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
const webpack = require("webpack")
|
2
|
+
const MemoryFS = require("memory-fs")
|
3
|
+
const thenify = require("thenify")
|
4
|
+
const path = require("path")
|
5
|
+
|
6
|
+
const createTrackLoader = () => {
|
7
|
+
const filesTracked = {}
|
8
|
+
return [
|
9
|
+
filesTracked,
|
10
|
+
(source) => {
|
11
|
+
filesTracked[source.resource] = true
|
12
|
+
return source
|
13
|
+
}
|
14
|
+
]
|
15
|
+
}
|
16
|
+
|
17
|
+
const pathToNodeModules = path.resolve("node_modules")
|
18
|
+
const pathToNodeModulesIncluded = path.resolve("node_modules/included")
|
19
|
+
const pathToAppJavascript = path.resolve("app/javascript")
|
20
|
+
|
21
|
+
const createInMemoryFs = () => {
|
22
|
+
const fs = new MemoryFS()
|
23
|
+
|
24
|
+
fs.mkdirpSync(pathToNodeModules)
|
25
|
+
fs.mkdirpSync(pathToNodeModulesIncluded)
|
26
|
+
fs.mkdirpSync(pathToAppJavascript)
|
27
|
+
|
28
|
+
return fs
|
29
|
+
}
|
30
|
+
|
31
|
+
const createTestCompiler = (config, fs = createInMemoryFs()) => {
|
32
|
+
Object.values(config.entry).forEach((file) => {
|
33
|
+
fs.writeFileSync(file, "console.log(1);")
|
34
|
+
})
|
35
|
+
|
36
|
+
const compiler = webpack(config)
|
37
|
+
compiler.run = thenify(compiler.run)
|
38
|
+
compiler.inputFileSystem = fs
|
39
|
+
compiler.outputFileSystem = fs
|
40
|
+
return compiler
|
41
|
+
}
|
42
|
+
|
43
|
+
const chdirTestApp = () => {
|
44
|
+
try {
|
45
|
+
return process.chdir("spec/shakapacker/test_app")
|
46
|
+
} catch (e) {
|
47
|
+
return null
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
const chdirCwd = () => process.chdir(process.cwd())
|
52
|
+
|
53
|
+
const resetEnv = () => {
|
54
|
+
process.env = {}
|
55
|
+
}
|
56
|
+
|
57
|
+
module.exports = {
|
58
|
+
chdirTestApp,
|
59
|
+
chdirCwd,
|
60
|
+
resetEnv,
|
61
|
+
createTrackLoader,
|
62
|
+
pathToNodeModules,
|
63
|
+
pathToNodeModulesIncluded,
|
64
|
+
pathToAppJavascript,
|
65
|
+
createInMemoryFs,
|
66
|
+
createTestCompiler
|
67
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
const { resolve } = require("path")
|
2
|
+
const { chdirTestApp, resetEnv } = require("../helpers")
|
3
|
+
|
4
|
+
const rootPath = process.cwd()
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe("Config", () => {
|
8
|
+
beforeEach(() => jest.resetModules() && resetEnv())
|
9
|
+
afterAll(() => process.chdir(rootPath))
|
10
|
+
|
11
|
+
test("public path", () => {
|
12
|
+
process.env.RAILS_ENV = "development"
|
13
|
+
const config = require("../../package/config")
|
14
|
+
expect(config.publicPath).toBe("/packs/")
|
15
|
+
})
|
16
|
+
|
17
|
+
test("public path with asset host", () => {
|
18
|
+
process.env.RAILS_ENV = "development"
|
19
|
+
process.env.SHAKAPACKER_ASSET_HOST = "http://foo.com/"
|
20
|
+
const config = require("../../package/config")
|
21
|
+
expect(config.publicPath).toBe("http://foo.com/packs/")
|
22
|
+
})
|
23
|
+
|
24
|
+
test("should return additional paths as listed in app config, with resolved paths", () => {
|
25
|
+
const config = require("../../package/config")
|
26
|
+
|
27
|
+
expect(config.additional_paths).toStrictEqual([
|
28
|
+
"app/assets",
|
29
|
+
"/etc/yarn",
|
30
|
+
"some.config.js",
|
31
|
+
"app/elm"
|
32
|
+
])
|
33
|
+
})
|
34
|
+
|
35
|
+
test("should default manifestPath to the public dir", () => {
|
36
|
+
const config = require("../../package/config")
|
37
|
+
|
38
|
+
expect(config.manifestPath).toStrictEqual(
|
39
|
+
resolve("public/packs/manifest.json")
|
40
|
+
)
|
41
|
+
})
|
42
|
+
|
43
|
+
test("should allow overriding manifestPath", () => {
|
44
|
+
process.env.SHAKAPACKER_CONFIG = "config/shakapacker_manifest_path.yml"
|
45
|
+
const config = require("../../package/config")
|
46
|
+
expect(config.manifestPath).toStrictEqual(
|
47
|
+
resolve("app/javascript/manifest.json")
|
48
|
+
)
|
49
|
+
})
|
50
|
+
})
|
@@ -0,0 +1,44 @@
|
|
1
|
+
const { chdirTestApp } = require("../helpers")
|
2
|
+
|
3
|
+
const rootPath = process.cwd()
|
4
|
+
chdirTestApp()
|
5
|
+
|
6
|
+
describe("DevServer", () => {
|
7
|
+
beforeEach(() => jest.resetModules())
|
8
|
+
afterAll(() => process.chdir(rootPath))
|
9
|
+
|
10
|
+
test("with NODE_ENV and RAILS_ENV set to development", () => {
|
11
|
+
process.env.NODE_ENV = "development"
|
12
|
+
process.env.RAILS_ENV = "development"
|
13
|
+
process.env.SHAKAPACKER_DEV_SERVER_HOST = "0.0.0.0"
|
14
|
+
process.env.SHAKAPACKER_DEV_SERVER_PORT = 5000
|
15
|
+
process.env.SHAKAPACKER_DEV_SERVER_DISABLE_HOST_CHECK = false
|
16
|
+
|
17
|
+
const devServer = require("../../package/dev_server")
|
18
|
+
expect(devServer).toBeDefined()
|
19
|
+
expect(devServer.host).toBe("0.0.0.0")
|
20
|
+
expect(devServer.port).toBe("5000")
|
21
|
+
expect(devServer.disable_host_check).toBe(false)
|
22
|
+
})
|
23
|
+
|
24
|
+
test("with custom env prefix", () => {
|
25
|
+
const config = require("../../package/config")
|
26
|
+
config.dev_server.env_prefix = "TEST_SHAKAPACKER_DEV_SERVER"
|
27
|
+
|
28
|
+
process.env.NODE_ENV = "development"
|
29
|
+
process.env.RAILS_ENV = "development"
|
30
|
+
process.env.TEST_SHAKAPACKER_DEV_SERVER_HOST = "0.0.0.0"
|
31
|
+
process.env.TEST_SHAKAPACKER_DEV_SERVER_PORT = 5000
|
32
|
+
|
33
|
+
const devServer = require("../../package/dev_server")
|
34
|
+
expect(devServer).toBeDefined()
|
35
|
+
expect(devServer.host).toBe("0.0.0.0")
|
36
|
+
expect(devServer.port).toBe("5000")
|
37
|
+
})
|
38
|
+
|
39
|
+
test("with NODE_ENV and RAILS_ENV set to production", () => {
|
40
|
+
process.env.RAILS_ENV = "production"
|
41
|
+
process.env.NODE_ENV = "production"
|
42
|
+
expect(require("../../package/dev_server")).toStrictEqual({})
|
43
|
+
})
|
44
|
+
})
|
@@ -0,0 +1,43 @@
|
|
1
|
+
const { resolve } = require("path")
|
2
|
+
const { chdirTestApp, resetEnv } = require("../helpers")
|
3
|
+
|
4
|
+
const rootPath = process.cwd()
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe("Development environment", () => {
|
8
|
+
beforeEach(() => jest.resetModules() && resetEnv())
|
9
|
+
afterAll(() => process.chdir(rootPath))
|
10
|
+
|
11
|
+
describe("generateWebpackConfig", () => {
|
12
|
+
beforeEach(() => jest.resetModules())
|
13
|
+
|
14
|
+
test("should use development config and environment including devServer if WEBPACK_SERVE", () => {
|
15
|
+
process.env.RAILS_ENV = "development"
|
16
|
+
process.env.NODE_ENV = "development"
|
17
|
+
process.env.WEBPACK_SERVE = "true"
|
18
|
+
const { generateWebpackConfig } = require("../../package/index")
|
19
|
+
|
20
|
+
const webpackConfig = generateWebpackConfig()
|
21
|
+
|
22
|
+
expect(webpackConfig.output.path).toStrictEqual(
|
23
|
+
resolve("public", "packs")
|
24
|
+
)
|
25
|
+
expect(webpackConfig.output.publicPath).toBe("/packs/")
|
26
|
+
})
|
27
|
+
|
28
|
+
test("should use development config and environment if WEBPACK_SERVE", () => {
|
29
|
+
process.env.RAILS_ENV = "development"
|
30
|
+
process.env.NODE_ENV = "development"
|
31
|
+
process.env.WEBPACK_SERVE = undefined
|
32
|
+
const { generateWebpackConfig } = require("../../package/index")
|
33
|
+
|
34
|
+
const webpackConfig = generateWebpackConfig()
|
35
|
+
|
36
|
+
expect(webpackConfig.output.path).toStrictEqual(
|
37
|
+
resolve("public", "packs")
|
38
|
+
)
|
39
|
+
expect(webpackConfig.output.publicPath).toBe("/packs/")
|
40
|
+
expect(webpackConfig.devServer).toBeUndefined()
|
41
|
+
})
|
42
|
+
})
|
43
|
+
})
|
@@ -0,0 +1,57 @@
|
|
1
|
+
const { chdirTestApp } = require("../helpers")
|
2
|
+
|
3
|
+
const rootPath = process.cwd()
|
4
|
+
chdirTestApp()
|
5
|
+
|
6
|
+
describe("Env", () => {
|
7
|
+
beforeEach(() => jest.resetModules())
|
8
|
+
afterAll(() => process.chdir(rootPath))
|
9
|
+
|
10
|
+
test("with NODE_ENV and RAILS_ENV set to development", () => {
|
11
|
+
process.env.RAILS_ENV = "development"
|
12
|
+
process.env.NODE_ENV = "development"
|
13
|
+
expect(require("../../package/env")).toStrictEqual({
|
14
|
+
railsEnv: "development",
|
15
|
+
nodeEnv: "development",
|
16
|
+
isProduction: false,
|
17
|
+
isDevelopment: true,
|
18
|
+
runningWebpackDevServer: false
|
19
|
+
})
|
20
|
+
})
|
21
|
+
|
22
|
+
test("with undefined NODE_ENV and RAILS_ENV set to development", () => {
|
23
|
+
process.env.RAILS_ENV = "development"
|
24
|
+
delete process.env.NODE_ENV
|
25
|
+
expect(require("../../package/env")).toStrictEqual({
|
26
|
+
railsEnv: "development",
|
27
|
+
nodeEnv: "production",
|
28
|
+
isProduction: true,
|
29
|
+
isDevelopment: false,
|
30
|
+
runningWebpackDevServer: false
|
31
|
+
})
|
32
|
+
})
|
33
|
+
|
34
|
+
test("with undefined NODE_ENV and RAILS_ENV", () => {
|
35
|
+
delete process.env.NODE_ENV
|
36
|
+
delete process.env.RAILS_ENV
|
37
|
+
expect(require("../../package/env")).toStrictEqual({
|
38
|
+
railsEnv: "production",
|
39
|
+
nodeEnv: "production",
|
40
|
+
isProduction: true,
|
41
|
+
isDevelopment: false,
|
42
|
+
runningWebpackDevServer: false
|
43
|
+
})
|
44
|
+
})
|
45
|
+
|
46
|
+
test("with a non-standard environment", () => {
|
47
|
+
process.env.RAILS_ENV = "staging"
|
48
|
+
process.env.NODE_ENV = "staging"
|
49
|
+
expect(require("../../package/env")).toStrictEqual({
|
50
|
+
railsEnv: "staging",
|
51
|
+
nodeEnv: "production",
|
52
|
+
isProduction: true,
|
53
|
+
isDevelopment: false,
|
54
|
+
runningWebpackDevServer: false
|
55
|
+
})
|
56
|
+
})
|
57
|
+
})
|
@@ -0,0 +1,105 @@
|
|
1
|
+
// environment.js expects to find config/shakapacker.yml and resolved modules from
|
2
|
+
// the root of a Rails project
|
3
|
+
|
4
|
+
const { resolve } = require("path")
|
5
|
+
const { chdirTestApp, resetEnv } = require("../../helpers")
|
6
|
+
|
7
|
+
const rootPath = process.cwd()
|
8
|
+
chdirTestApp()
|
9
|
+
|
10
|
+
const baseConfig = require("../../../package/environments/base")
|
11
|
+
const config = require("../../../package/config")
|
12
|
+
|
13
|
+
describe("Base config", () => {
|
14
|
+
beforeEach(() => jest.resetModules() && resetEnv())
|
15
|
+
afterAll(() => process.chdir(rootPath))
|
16
|
+
|
17
|
+
describe("config", () => {
|
18
|
+
test("should return entry", () => {
|
19
|
+
expect(baseConfig.entry.application).toStrictEqual(
|
20
|
+
resolve("app", "javascript", "entrypoints", "application.js")
|
21
|
+
)
|
22
|
+
})
|
23
|
+
|
24
|
+
test("should return false for css_extract_ignore_order_warnings when using default config", () => {
|
25
|
+
expect(config.css_extract_ignore_order_warnings).toBe(false)
|
26
|
+
})
|
27
|
+
|
28
|
+
test("should return true for css_extract_ignore_order_warnings when configured", () => {
|
29
|
+
process.env.SHAKAPACKER_CONFIG =
|
30
|
+
"config/shakapacker_css_extract_ignore_order_warnings.yml"
|
31
|
+
const config2 = require("../../../package/config")
|
32
|
+
|
33
|
+
expect(config2.css_extract_ignore_order_warnings).toBe(true)
|
34
|
+
})
|
35
|
+
|
36
|
+
test("should return only 2 entry points with config.nested_entries == false", () => {
|
37
|
+
expect(config.nested_entries).toBe(false)
|
38
|
+
|
39
|
+
expect(baseConfig.entry.multi_entry.sort()).toStrictEqual([
|
40
|
+
resolve("app", "javascript", "entrypoints", "multi_entry.css"),
|
41
|
+
resolve("app", "javascript", "entrypoints", "multi_entry.js")
|
42
|
+
])
|
43
|
+
expect(baseConfig.entry["generated/something"]).toBeUndefined()
|
44
|
+
})
|
45
|
+
|
46
|
+
test("should returns top level and nested entry points with config.nested_entries == true", () => {
|
47
|
+
process.env.SHAKAPACKER_CONFIG = "config/shakapacker_nested_entries.yml"
|
48
|
+
const config2 = require("../../../package/config")
|
49
|
+
const baseConfig2 = require("../../../package/environments/base")
|
50
|
+
|
51
|
+
expect(config2.nested_entries).toBe(true)
|
52
|
+
|
53
|
+
expect(baseConfig2.entry.application).toStrictEqual(
|
54
|
+
resolve("app", "javascript", "entrypoints", "application.js")
|
55
|
+
)
|
56
|
+
expect(baseConfig2.entry.multi_entry.sort()).toStrictEqual([
|
57
|
+
resolve("app", "javascript", "entrypoints", "multi_entry.css"),
|
58
|
+
resolve("app", "javascript", "entrypoints", "multi_entry.js")
|
59
|
+
])
|
60
|
+
expect(baseConfig2.entry["generated/something"]).toStrictEqual(
|
61
|
+
resolve("app", "javascript", "entrypoints", "generated", "something.js")
|
62
|
+
)
|
63
|
+
})
|
64
|
+
|
65
|
+
test("should return output", () => {
|
66
|
+
expect(baseConfig.output.filename).toBe("js/[name]-[contenthash].js")
|
67
|
+
expect(baseConfig.output.chunkFilename).toBe(
|
68
|
+
"js/[name]-[contenthash].chunk.js"
|
69
|
+
)
|
70
|
+
})
|
71
|
+
|
72
|
+
test("should return default loader rules for each file in config/loaders", () => {
|
73
|
+
const rules = require("../../../package/rules")
|
74
|
+
|
75
|
+
const defaultRules = Object.keys(rules)
|
76
|
+
const configRules = baseConfig.module.rules
|
77
|
+
|
78
|
+
expect(defaultRules).toHaveLength(3)
|
79
|
+
expect(configRules).toHaveLength(3)
|
80
|
+
})
|
81
|
+
|
82
|
+
test("should return default plugins", () => {
|
83
|
+
expect(baseConfig.plugins).toHaveLength(2)
|
84
|
+
})
|
85
|
+
|
86
|
+
test("should return default resolveLoader", () => {
|
87
|
+
expect(baseConfig.resolveLoader.modules).toStrictEqual(["node_modules"])
|
88
|
+
})
|
89
|
+
|
90
|
+
test("should return default resolve.modules with additions", () => {
|
91
|
+
expect(baseConfig.resolve.modules).toStrictEqual([
|
92
|
+
resolve("app", "javascript"),
|
93
|
+
resolve("app/assets"),
|
94
|
+
resolve("/etc/yarn"),
|
95
|
+
resolve("some.config.js"),
|
96
|
+
resolve("app/elm"),
|
97
|
+
"node_modules"
|
98
|
+
])
|
99
|
+
})
|
100
|
+
|
101
|
+
test("returns plugins property as Array", () => {
|
102
|
+
expect(baseConfig.plugins).toBeInstanceOf(Array)
|
103
|
+
})
|
104
|
+
})
|
105
|
+
})
|
@@ -0,0 +1,50 @@
|
|
1
|
+
const { chdirTestApp, resetEnv } = require("../../helpers")
|
2
|
+
|
3
|
+
const rootPath = process.cwd()
|
4
|
+
chdirTestApp()
|
5
|
+
|
6
|
+
describe("Development specific config", () => {
|
7
|
+
beforeEach(() => {
|
8
|
+
jest.resetModules()
|
9
|
+
resetEnv()
|
10
|
+
process.env.NODE_ENV = "development"
|
11
|
+
})
|
12
|
+
afterAll(() => process.chdir(rootPath))
|
13
|
+
|
14
|
+
describe("with config.useContentHash = true", () => {
|
15
|
+
test("sets filename to use contentHash", () => {
|
16
|
+
const config = require("../../../package/config")
|
17
|
+
config.useContentHash = true
|
18
|
+
const environmentConfig = require("../../../package/environments/development")
|
19
|
+
|
20
|
+
expect(environmentConfig.output.filename).toBe(
|
21
|
+
"js/[name]-[contenthash].js"
|
22
|
+
)
|
23
|
+
expect(environmentConfig.output.chunkFilename).toBe(
|
24
|
+
"js/[name]-[contenthash].chunk.js"
|
25
|
+
)
|
26
|
+
})
|
27
|
+
})
|
28
|
+
|
29
|
+
describe("with config.useContentHash = false", () => {
|
30
|
+
test("sets filename without using contentHash", () => {
|
31
|
+
const config = require("../../../package/config")
|
32
|
+
config.useContentHash = false
|
33
|
+
const environmentConfig = require("../../../package/environments/development")
|
34
|
+
|
35
|
+
expect(environmentConfig.output.filename).toBe("js/[name].js")
|
36
|
+
expect(environmentConfig.output.chunkFilename).toBe("js/[name].chunk.js")
|
37
|
+
})
|
38
|
+
})
|
39
|
+
|
40
|
+
describe("with unset config.useContentHash", () => {
|
41
|
+
test("sets filename without using contentHash", () => {
|
42
|
+
const config = require("../../../package/config")
|
43
|
+
delete config.useContentHash
|
44
|
+
const environmentConfig = require("../../../package/environments/development")
|
45
|
+
|
46
|
+
expect(environmentConfig.output.filename).toBe("js/[name].js")
|
47
|
+
expect(environmentConfig.output.chunkFilename).toBe("js/[name].chunk.js")
|
48
|
+
})
|
49
|
+
})
|
50
|
+
})
|
@@ -0,0 +1,106 @@
|
|
1
|
+
const { chdirTestApp, resetEnv } = require("../../helpers")
|
2
|
+
|
3
|
+
const rootPath = process.cwd()
|
4
|
+
chdirTestApp()
|
5
|
+
|
6
|
+
describe("Production specific config", () => {
|
7
|
+
beforeEach(() => {
|
8
|
+
jest.resetModules()
|
9
|
+
resetEnv()
|
10
|
+
process.env.NODE_ENV = "production"
|
11
|
+
})
|
12
|
+
afterAll(() => process.chdir(rootPath))
|
13
|
+
|
14
|
+
describe("with config.useContentHash = true", () => {
|
15
|
+
test("sets filename to use contentHash", () => {
|
16
|
+
const config = require("../../../package/config")
|
17
|
+
config.useContentHash = true
|
18
|
+
const environmentConfig = require("../../../package/environments/production")
|
19
|
+
|
20
|
+
expect(environmentConfig.output.filename).toBe(
|
21
|
+
"js/[name]-[contenthash].js"
|
22
|
+
)
|
23
|
+
expect(environmentConfig.output.chunkFilename).toBe(
|
24
|
+
"js/[name]-[contenthash].chunk.js"
|
25
|
+
)
|
26
|
+
})
|
27
|
+
|
28
|
+
test("doesn't shows any warning message", () => {
|
29
|
+
const consoleWarnSpy = jest.spyOn(console, "warn")
|
30
|
+
const config = require("../../../package/config")
|
31
|
+
config.useContentHash = true
|
32
|
+
|
33
|
+
require("../../../package/environments/production")
|
34
|
+
|
35
|
+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
|
36
|
+
expect.stringMatching(
|
37
|
+
/Setting 'useContentHash' to 'false' in the production environment/
|
38
|
+
)
|
39
|
+
)
|
40
|
+
|
41
|
+
consoleWarnSpy.mockRestore()
|
42
|
+
})
|
43
|
+
})
|
44
|
+
|
45
|
+
describe("with config.useContentHash = false", () => {
|
46
|
+
test("sets filename to use contentHash", () => {
|
47
|
+
const config = require("../../../package/config")
|
48
|
+
config.useContentHash = false
|
49
|
+
const environmentConfig = require("../../../package/environments/production")
|
50
|
+
|
51
|
+
expect(environmentConfig.output.filename).toBe(
|
52
|
+
"js/[name]-[contenthash].js"
|
53
|
+
)
|
54
|
+
expect(environmentConfig.output.chunkFilename).toBe(
|
55
|
+
"js/[name]-[contenthash].chunk.js"
|
56
|
+
)
|
57
|
+
})
|
58
|
+
|
59
|
+
test("shows a warning message", () => {
|
60
|
+
const consoleWarnSpy = jest.spyOn(console, "warn")
|
61
|
+
const config = require("../../../package/config")
|
62
|
+
config.useContentHash = false
|
63
|
+
|
64
|
+
require("../../../package/environments/production")
|
65
|
+
|
66
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
67
|
+
expect.stringMatching(
|
68
|
+
/Setting 'useContentHash' to 'false' in the production environment/
|
69
|
+
)
|
70
|
+
)
|
71
|
+
|
72
|
+
consoleWarnSpy.mockRestore()
|
73
|
+
})
|
74
|
+
})
|
75
|
+
|
76
|
+
describe("with unset config.useContentHash", () => {
|
77
|
+
test("sets filename to use contentHash", () => {
|
78
|
+
const config = require("../../../package/config")
|
79
|
+
delete config.useContentHash
|
80
|
+
const environmentConfig = require("../../../package/environments/production")
|
81
|
+
|
82
|
+
expect(environmentConfig.output.filename).toBe(
|
83
|
+
"js/[name]-[contenthash].js"
|
84
|
+
)
|
85
|
+
expect(environmentConfig.output.chunkFilename).toBe(
|
86
|
+
"js/[name]-[contenthash].chunk.js"
|
87
|
+
)
|
88
|
+
})
|
89
|
+
|
90
|
+
test("doesn't shows any warning message", () => {
|
91
|
+
const consoleWarnSpy = jest.spyOn(console, "warn")
|
92
|
+
const config = require("../../../package/config")
|
93
|
+
delete config.useContentHash
|
94
|
+
|
95
|
+
require("../../../package/environments/production")
|
96
|
+
|
97
|
+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
|
98
|
+
expect.stringMatching(
|
99
|
+
/Setting 'useContentHash' to 'false' in the production environment/
|
100
|
+
)
|
101
|
+
)
|
102
|
+
|
103
|
+
consoleWarnSpy.mockRestore()
|
104
|
+
})
|
105
|
+
})
|
106
|
+
})
|
@@ -0,0 +1,45 @@
|
|
1
|
+
const index = require("../../package/index")
|
2
|
+
|
3
|
+
describe("index", () => {
|
4
|
+
test("exports webpack-merge v5 functions", () => {
|
5
|
+
expect(index.merge).toBeInstanceOf(Function)
|
6
|
+
expect(index.mergeWithRules).toBeInstanceOf(Function)
|
7
|
+
expect(index.mergeWithCustomize).toBeInstanceOf(Function)
|
8
|
+
})
|
9
|
+
|
10
|
+
test("webpackConfig returns an immutable object", () => {
|
11
|
+
const { generateWebpackConfig } = require("../../package/index")
|
12
|
+
|
13
|
+
const webpackConfig1 = generateWebpackConfig()
|
14
|
+
const webpackConfig2 = generateWebpackConfig()
|
15
|
+
|
16
|
+
webpackConfig1.newKey = "new value"
|
17
|
+
webpackConfig1.output.path = "new path"
|
18
|
+
|
19
|
+
expect(webpackConfig2).not.toHaveProperty("newKey")
|
20
|
+
expect(webpackConfig2.output.path).not.toBe("new value")
|
21
|
+
})
|
22
|
+
|
23
|
+
test("webpackConfig merges extra config", () => {
|
24
|
+
const { generateWebpackConfig } = require("../../package/index")
|
25
|
+
|
26
|
+
const webpackConfig = generateWebpackConfig({
|
27
|
+
newKey: "new value",
|
28
|
+
output: {
|
29
|
+
path: "new path"
|
30
|
+
}
|
31
|
+
})
|
32
|
+
|
33
|
+
expect(webpackConfig).toHaveProperty("newKey", "new value")
|
34
|
+
expect(webpackConfig).toHaveProperty("output.path", "new path")
|
35
|
+
expect(webpackConfig).toHaveProperty("output.publicPath", "/packs/")
|
36
|
+
})
|
37
|
+
|
38
|
+
test("webpackConfig errors if multiple configs are provided", () => {
|
39
|
+
const { generateWebpackConfig } = require("../../package/index")
|
40
|
+
|
41
|
+
expect(() => generateWebpackConfig({}, {})).toThrow(
|
42
|
+
"use webpack-merge to merge configs before passing them to Shakapacker"
|
43
|
+
)
|
44
|
+
})
|
45
|
+
})
|