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
@@ -1,79 +0,0 @@
|
|
1
|
-
const file = require('../file')
|
2
|
-
|
3
|
-
jest.mock("../../config", () => {
|
4
|
-
const original = jest.requireActual("../../config");
|
5
|
-
return {
|
6
|
-
...original,
|
7
|
-
includePaths: [...original.includePaths, 'app/assets']
|
8
|
-
};
|
9
|
-
});
|
10
|
-
|
11
|
-
describe('file', () => {
|
12
|
-
test('test expected file types', () => {
|
13
|
-
const types = [
|
14
|
-
'.bmp',
|
15
|
-
'.gif',
|
16
|
-
'.jpg',
|
17
|
-
'.jpeg',
|
18
|
-
'.png',
|
19
|
-
'.tiff',
|
20
|
-
'.ico',
|
21
|
-
'.avif',
|
22
|
-
'.webp',
|
23
|
-
'.eot',
|
24
|
-
'.otf',
|
25
|
-
'.ttf',
|
26
|
-
'.woff',
|
27
|
-
'.woff2',
|
28
|
-
'.svg',
|
29
|
-
]
|
30
|
-
types.forEach(type => expect(file.test.test(type)).toBe(true))
|
31
|
-
})
|
32
|
-
|
33
|
-
test('exclude expected file types', () => {
|
34
|
-
const types = [
|
35
|
-
'.js',
|
36
|
-
'.mjs',
|
37
|
-
'.jsx',
|
38
|
-
'.ts',
|
39
|
-
'.tsx',
|
40
|
-
]
|
41
|
-
types.forEach(type => expect(file.exclude.test(type)).toBe(true))
|
42
|
-
})
|
43
|
-
|
44
|
-
test('correct generated output path is returned for top level files', () => {
|
45
|
-
const pathData = {
|
46
|
-
filename: 'app/javascript/image.svg',
|
47
|
-
};
|
48
|
-
expect(file.generator.filename(pathData)).toEqual(
|
49
|
-
'static/[name]-[hash][ext][query]'
|
50
|
-
);
|
51
|
-
});
|
52
|
-
|
53
|
-
test('correct generated output path is returned for nested files', () => {
|
54
|
-
const pathData = {
|
55
|
-
filename: 'app/javascript/images/image.svg',
|
56
|
-
};
|
57
|
-
expect(file.generator.filename(pathData)).toEqual(
|
58
|
-
'static/images/[name]-[hash][ext][query]'
|
59
|
-
);
|
60
|
-
})
|
61
|
-
|
62
|
-
test('correct generated output path is returned for deeply nested files', () => {
|
63
|
-
const pathData = {
|
64
|
-
filename: 'app/javascript/images/nested/deeply/image.svg',
|
65
|
-
};
|
66
|
-
expect(file.generator.filename(pathData)).toEqual(
|
67
|
-
'static/images/nested/deeply/[name]-[hash][ext][query]'
|
68
|
-
);
|
69
|
-
});
|
70
|
-
|
71
|
-
test('correct generated output path is returned for all include paths', () => {
|
72
|
-
const pathData = {
|
73
|
-
filename: 'app/assets/images/image.svg',
|
74
|
-
};
|
75
|
-
expect(file.generator.filename(pathData)).toEqual(
|
76
|
-
'static/images/[name]-[hash][ext][query]'
|
77
|
-
);
|
78
|
-
});
|
79
|
-
})
|
@@ -1,18 +0,0 @@
|
|
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
|
-
})
|
@@ -1,63 +0,0 @@
|
|
1
|
-
const {
|
2
|
-
app_javascript,
|
3
|
-
node_modules,
|
4
|
-
node_modules_included,
|
5
|
-
createTestCompiler,
|
6
|
-
createTrackLoader,
|
7
|
-
} = require("./__utils__/webpack");
|
8
|
-
const swcConfig = require("../swc");
|
9
|
-
|
10
|
-
jest.mock("../../config", () => {
|
11
|
-
const original = jest.requireActual("../../config");
|
12
|
-
return {
|
13
|
-
...original,
|
14
|
-
webpack_loader: "swc",
|
15
|
-
includePaths: [...original.includePaths, "node_modules/included"],
|
16
|
-
};
|
17
|
-
});
|
18
|
-
|
19
|
-
const createWebpackConfig = (file, use) => {
|
20
|
-
return {
|
21
|
-
entry: { file },
|
22
|
-
module: {
|
23
|
-
rules: [
|
24
|
-
{
|
25
|
-
...swcConfig,
|
26
|
-
use,
|
27
|
-
},
|
28
|
-
],
|
29
|
-
},
|
30
|
-
output: {
|
31
|
-
path: "/",
|
32
|
-
filename: "scripts-bundled.js",
|
33
|
-
},
|
34
|
-
};
|
35
|
-
};
|
36
|
-
|
37
|
-
describe("swc", () => {
|
38
|
-
test("process files in source_path", async () => {
|
39
|
-
const normalPath = `${app_javascript}/a.js`;
|
40
|
-
const [tracked, loader] = createTrackLoader();
|
41
|
-
const compiler = createTestCompiler(
|
42
|
-
createWebpackConfig(normalPath, loader)
|
43
|
-
);
|
44
|
-
await compiler.run();
|
45
|
-
expect(tracked[normalPath]).toBeTruthy();
|
46
|
-
});
|
47
|
-
|
48
|
-
test("exclude node_modules", async () => {
|
49
|
-
const ignored = `${node_modules}/a.js`;
|
50
|
-
const [tracked, loader] = createTrackLoader();
|
51
|
-
const compiler = createTestCompiler(createWebpackConfig(ignored, loader));
|
52
|
-
await compiler.run();
|
53
|
-
expect(tracked[ignored]).toBeUndefined();
|
54
|
-
});
|
55
|
-
|
56
|
-
test("explicitly included node_modules should be transpiled", async () => {
|
57
|
-
const included = `${node_modules_included}/a.js`;
|
58
|
-
const [tracked, loader] = createTrackLoader();
|
59
|
-
const compiler = createTestCompiler(createWebpackConfig(included, loader));
|
60
|
-
await compiler.run();
|
61
|
-
expect(tracked[included]).toBeTruthy();
|
62
|
-
});
|
63
|
-
});
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Command" do
|
4
|
-
before do
|
5
|
-
allow(Webpacker.logger).to receive(:info)
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#compile" do
|
9
|
-
it "returns success status when stale" do
|
10
|
-
expect(Webpacker.compiler).to receive(:stale?).and_return(true)
|
11
|
-
expect(Webpacker.compiler).to receive(:run_webpack).and_return(true)
|
12
|
-
|
13
|
-
expect(Webpacker.commands.compile).to be true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns success status when fresh" do
|
17
|
-
expect(Webpacker.compiler).to receive(:stale?).and_return(false)
|
18
|
-
|
19
|
-
expect(Webpacker.commands.compile).to be true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns failure status when stale" do
|
23
|
-
expect(Webpacker.compiler).to receive(:stale?).and_return(true)
|
24
|
-
expect(Webpacker.compiler).to receive(:run_webpack).and_return(false)
|
25
|
-
|
26
|
-
expect(Webpacker.commands.compile).to be false
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#clean" do
|
31
|
-
let(:now) { Time.parse("2021-01-01 12:34:56 UTC") }
|
32
|
-
let(:prev_files) do
|
33
|
-
# Test assets to be kept and deleted, path and mtime
|
34
|
-
{
|
35
|
-
# recent versions to be kept with Webpacker.commands.clean(count = 2)
|
36
|
-
"js/application-deadbeef.js" => now - 4000,
|
37
|
-
"js/common-deadbeee.js" => now - 4002,
|
38
|
-
"css/common-deadbeed.css" => now - 4004,
|
39
|
-
"media/images/logo-deadbeeb.css" => now - 4006,
|
40
|
-
"js/application-1eadbeef.js" => now - 8000,
|
41
|
-
"js/common-1eadbeee.js" => now - 8002,
|
42
|
-
"css/common-1eadbeed.css" => now - 8004,
|
43
|
-
"media/images/logo-1eadbeeb.css" => now - 8006,
|
44
|
-
# new files to be kept with Webpacker.commands.clean(age = 3600)
|
45
|
-
"js/brandnew-0001.js" => now,
|
46
|
-
"js/brandnew-0002.js" => now - 10,
|
47
|
-
"js/brandnew-0003.js" => now - 20,
|
48
|
-
"js/brandnew-0004.js" => now - 40,
|
49
|
-
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
50
|
-
end
|
51
|
-
|
52
|
-
let(:expired_files) do
|
53
|
-
{
|
54
|
-
# old files that are outside count = 2 or age = 3600 and to be deleted
|
55
|
-
"js/application-0eadbeef.js" => now - 9000,
|
56
|
-
"js/common-0eadbeee.js" => now - 9002,
|
57
|
-
"css/common-0eadbeed.css" => now - 9004,
|
58
|
-
"js/brandnew-0005.js" => now - 3640,
|
59
|
-
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
60
|
-
end
|
61
|
-
|
62
|
-
let(:all_files) { prev_files.merge(expired_files) }
|
63
|
-
|
64
|
-
let(:file_delete_mock) { double("File Delete") }
|
65
|
-
let(:file_mtime_stub) { Proc.new { |longpath| all_files[longpath] } }
|
66
|
-
let(:file_delete_stub) { Proc.new { |longpath| file_delete_mock.delete(longpath) } }
|
67
|
-
|
68
|
-
before :context do
|
69
|
-
@dir_glob_stub = Proc.new { |arg|
|
70
|
-
case arg
|
71
|
-
when "#{Webpacker.config.public_output_path}/**/*"
|
72
|
-
all_files.keys
|
73
|
-
else
|
74
|
-
[]
|
75
|
-
end
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
|
-
it "works with nested hashes and without any compiled files" do
|
80
|
-
allow(File).to receive(:delete).and_return(true)
|
81
|
-
expect(Webpacker.commands.clean).to be true
|
82
|
-
end
|
83
|
-
|
84
|
-
it "deletes only and only expired versioned files if no parameter passed" do
|
85
|
-
all_files.keys.each do |longpath|
|
86
|
-
allow(file_delete_mock).to receive(:delete).with(longpath)
|
87
|
-
end
|
88
|
-
|
89
|
-
with_time_dir_and_files_stub do
|
90
|
-
expect(Webpacker.commands.clean).to be true
|
91
|
-
|
92
|
-
# Verify that only and only expired files are deleted
|
93
|
-
all_files.keys.each do |longpath|
|
94
|
-
if expired_files.has_key? longpath
|
95
|
-
expect(file_delete_mock).to have_received(:delete).with(longpath)
|
96
|
-
else
|
97
|
-
expect(file_delete_mock).to_not have_received(:delete).with(longpath)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
|
105
|
-
def with_time_dir_and_files_stub(&proc)
|
106
|
-
allow(Time).to receive(:now).and_return(now)
|
107
|
-
allow(Dir).to receive(:glob) { |arg| @dir_glob_stub.call(arg) }
|
108
|
-
allow(File).to receive(:directory?).and_return(false)
|
109
|
-
allow(File).to receive(:file?).and_return(true)
|
110
|
-
allow(File).to receive(:mtime) { |arg| file_mtime_stub.call(arg) }
|
111
|
-
allow(File).to receive(:delete) { |arg| file_delete_stub.call(arg) }
|
112
|
-
|
113
|
-
yield proc
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Webpacker::Compiler" do
|
4
|
-
it "accepts custom environment variables" do
|
5
|
-
expect(Webpacker.compiler.send(:webpack_env)["FOO"]).to be nil
|
6
|
-
|
7
|
-
Webpacker.compiler.env["FOO"] = "BAR"
|
8
|
-
expect(Webpacker.compiler.send(:webpack_env)["FOO"]).to eq "BAR"
|
9
|
-
ensure
|
10
|
-
Webpacker.compiler.env = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
it "returns true when fresh" do
|
14
|
-
mocked_strategy = double("Strategy")
|
15
|
-
expect(mocked_strategy).to receive(:stale?).and_return(false)
|
16
|
-
|
17
|
-
expect(Webpacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
18
|
-
|
19
|
-
expect(Webpacker.compiler.compile).to be true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns true and calls after_compile_hook on successful compile" do
|
23
|
-
mocked_strategy = spy("Strategy")
|
24
|
-
expect(mocked_strategy).to receive(:stale?).and_return(true)
|
25
|
-
|
26
|
-
allow(Webpacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
27
|
-
|
28
|
-
status = OpenStruct.new(success?: true)
|
29
|
-
allow(Open3).to receive(:capture3).and_return([:stderr, :stdout, status])
|
30
|
-
|
31
|
-
expect(Webpacker.compiler.compile).to be true
|
32
|
-
expect(mocked_strategy).to have_received(:after_compile_hook)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns false and calls after_compile_hook on failed compile" do
|
36
|
-
mocked_strategy = spy("Strategy")
|
37
|
-
allow(mocked_strategy).to receive(:stale?).and_return(true)
|
38
|
-
allow(mocked_strategy).to receive(:after_compile_hook)
|
39
|
-
|
40
|
-
allow(Webpacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
41
|
-
|
42
|
-
status = OpenStruct.new(success?: false)
|
43
|
-
allow(Open3).to receive(:capture3).and_return([:stderr, :stdout, status])
|
44
|
-
|
45
|
-
expect(Webpacker.compiler.compile).to be false
|
46
|
-
expect(mocked_strategy).to have_received(:after_compile_hook)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "accepts external env variables" do
|
50
|
-
expect(Webpacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to be nil
|
51
|
-
expect(Webpacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to be nil
|
52
|
-
|
53
|
-
ENV["WEBPACKER_ASSET_HOST"] = "foo.bar"
|
54
|
-
ENV["WEBPACKER_RELATIVE_URL_ROOT"] = "/baz"
|
55
|
-
|
56
|
-
expect(Webpacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq "foo.bar"
|
57
|
-
expect(Webpacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to eq "/baz"
|
58
|
-
end
|
59
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Webpacker::CompilerStrategy" do
|
4
|
-
describe "#from_config" do
|
5
|
-
it "returns an instance of MtimeStrategy when compiler_strategy is set to mtime" do
|
6
|
-
allow(Webpacker.config).to receive(:compiler_strategy).and_return("mtime")
|
7
|
-
|
8
|
-
expect(Webpacker::CompilerStrategy.from_config).to be_an_instance_of(Webpacker::MtimeStrategy)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "returns an instance of DigestStrategy when compiler_strategy is set to digest" do
|
12
|
-
allow(Webpacker.config).to receive(:compiler_strategy).and_return("digest")
|
13
|
-
|
14
|
-
expect(Webpacker::CompilerStrategy.from_config).to be_an_instance_of(Webpacker::DigestStrategy)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "raise an exception for unknown compiler_strategy in the config file" do
|
18
|
-
expected_error_message = "Unknown strategy 'other'. Available options are 'mtime' and 'digest'."
|
19
|
-
allow(Webpacker.config).to receive(:compiler_strategy).and_return("other")
|
20
|
-
|
21
|
-
expect { Webpacker::CompilerStrategy.from_config }.to raise_error(expected_error_message)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,294 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Webpacker::Configuration" do
|
4
|
-
ROOT_PATH = Pathname.new(File.expand_path("webpacker_test_app", __dir__))
|
5
|
-
|
6
|
-
context "with standard webpacker.yml" do
|
7
|
-
let(:config) do
|
8
|
-
Webpacker::Configuration.new(
|
9
|
-
root_path: ROOT_PATH,
|
10
|
-
config_path: Pathname.new(File.expand_path("./webpacker_test_app/config/webpacker.yml", __dir__)),
|
11
|
-
env: "production"
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "#source_path returns correct path" do
|
16
|
-
source_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs").to_s
|
17
|
-
|
18
|
-
expect(config.source_path.to_s).to eq source_path
|
19
|
-
end
|
20
|
-
|
21
|
-
it "#source_entry_path returns correct path" do
|
22
|
-
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs", "entrypoints").to_s
|
23
|
-
|
24
|
-
expect(config.source_entry_path.to_s).to eq source_entry_path
|
25
|
-
end
|
26
|
-
|
27
|
-
it "#public_root_path returns correct path" do
|
28
|
-
public_root_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public").to_s
|
29
|
-
|
30
|
-
expect(config.public_path.to_s).to eq public_root_path
|
31
|
-
end
|
32
|
-
|
33
|
-
it "#public_output_path returns correct path" do
|
34
|
-
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs").to_s
|
35
|
-
|
36
|
-
expect(config.public_output_path.to_s).to eq public_output_path
|
37
|
-
end
|
38
|
-
|
39
|
-
it "#public_manifest_path returns correct path" do
|
40
|
-
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s
|
41
|
-
|
42
|
-
expect(config.public_manifest_path.to_s).to eq public_manifest_path
|
43
|
-
end
|
44
|
-
|
45
|
-
it "#manifest_path returns correct path" do
|
46
|
-
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s
|
47
|
-
|
48
|
-
expect(config.manifest_path.to_s).to eq manifest_path
|
49
|
-
end
|
50
|
-
|
51
|
-
it "#cache_path returns correct path" do
|
52
|
-
cache_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/tmp/webpacker").to_s
|
53
|
-
|
54
|
-
expect(config.cache_path.to_s).to eq cache_path
|
55
|
-
end
|
56
|
-
|
57
|
-
it "#additional_paths returns correct path" do
|
58
|
-
expect(config.additional_paths).to eq ["app/assets", "/etc/yarn", "some.config.js", "app/elm"]
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#cache_manifest?" do
|
62
|
-
it "returns true in production environment" do
|
63
|
-
expect(config.cache_manifest?).to be true
|
64
|
-
end
|
65
|
-
|
66
|
-
it "returns false in development environment" do
|
67
|
-
with_rails_env("development") do
|
68
|
-
expect(Webpacker.config.cache_manifest?).to be false
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it "returns false in test environment" do
|
73
|
-
with_rails_env("test") do
|
74
|
-
expect(Webpacker.config.cache_manifest?).to be false
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#compile?" do
|
80
|
-
it "returns false in production environment" do
|
81
|
-
expect(config.compile?).to be false
|
82
|
-
end
|
83
|
-
|
84
|
-
it "returns true in development environment" do
|
85
|
-
with_rails_env("development") do
|
86
|
-
expect(Webpacker.config.compile?).to be true
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
it "returns true in test environment" do
|
91
|
-
with_rails_env("test") do
|
92
|
-
expect(Webpacker.config.compile?).to be true
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "#nested_entries?" do
|
98
|
-
it "returns false in production environment" do
|
99
|
-
expect(config.nested_entries?).to be false
|
100
|
-
end
|
101
|
-
|
102
|
-
it "returns false in development environment" do
|
103
|
-
with_rails_env("development") do
|
104
|
-
expect(Webpacker.config.nested_entries?).to be false
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
it "returns false in test environment" do
|
109
|
-
with_rails_env("test") do
|
110
|
-
expect(Webpacker.config.nested_entries?).to be false
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "#ensure_consistent_versioning?" do
|
116
|
-
it "returns false in production environment" do
|
117
|
-
expect(config.ensure_consistent_versioning?).to be false
|
118
|
-
end
|
119
|
-
|
120
|
-
it "returns true in development environment" do
|
121
|
-
with_rails_env("development") do
|
122
|
-
expect(Webpacker.config.ensure_consistent_versioning?).to be true
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
it "returns false in test environment" do
|
127
|
-
with_rails_env("test") do
|
128
|
-
expect(Webpacker.config.ensure_consistent_versioning?).to be false
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "#webpacker_precompile?" do
|
134
|
-
before :each do
|
135
|
-
ENV.delete("SHAKAPACKER_PRECOMPILE")
|
136
|
-
ENV.delete("WEBPACKER_PRECOMPILE")
|
137
|
-
end
|
138
|
-
|
139
|
-
subject { config.webpacker_precompile? }
|
140
|
-
|
141
|
-
it "returns true when WEBPACKER_PRECOMPILE is unset" do
|
142
|
-
is_expected.to be true
|
143
|
-
end
|
144
|
-
|
145
|
-
it "returns false when WEBPACKER_PRECOMPILE sets to no" do
|
146
|
-
ENV["WEBPACKER_PRECOMPILE"] = "no"
|
147
|
-
is_expected.to be false
|
148
|
-
end
|
149
|
-
|
150
|
-
it "returns true when WEBPACKER_PRECOMPILE sets to yes" do
|
151
|
-
ENV["WEBPACKER_PRECOMPILE"] = "yes"
|
152
|
-
is_expected.to be true
|
153
|
-
end
|
154
|
-
|
155
|
-
it "returns false when WEBPACKER_PRECOMPILE sets to false" do
|
156
|
-
ENV["WEBPACKER_PRECOMPILE"] = "false"
|
157
|
-
is_expected.to be false
|
158
|
-
end
|
159
|
-
|
160
|
-
it "returns true when WEBPACKER_PRECOMPILE sets to true" do
|
161
|
-
ENV["WEBPACKER_PRECOMPILE"] = "true"
|
162
|
-
is_expected.to be true
|
163
|
-
end
|
164
|
-
|
165
|
-
it "returns false when WEBPACKER_PRECOMPILE sets to n" do
|
166
|
-
ENV["WEBPACKER_PRECOMPILE"] = "n"
|
167
|
-
is_expected.to be false
|
168
|
-
end
|
169
|
-
|
170
|
-
it "returns true when WEBPACKER_PRECOMPILE sets to y" do
|
171
|
-
ENV["WEBPACKER_PRECOMPILE"] = "y"
|
172
|
-
is_expected.to be true
|
173
|
-
end
|
174
|
-
|
175
|
-
it "returns false when WEBPACKER_PRECOMPILE sets to f" do
|
176
|
-
ENV["WEBPACKER_PRECOMPILE"] = "f"
|
177
|
-
is_expected.to be false
|
178
|
-
end
|
179
|
-
|
180
|
-
it "returns true when WEBPACKER_PRECOMPILE sets to t" do
|
181
|
-
ENV["WEBPACKER_PRECOMPILE"] = "t"
|
182
|
-
is_expected.to be true
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context "with webpacker config file containing public_output_path entry" do
|
188
|
-
config = Webpacker::Configuration.new(
|
189
|
-
root_path: ROOT_PATH,
|
190
|
-
config_path: Pathname.new(File.expand_path("./webpacker_test_app/config/webpacker_public_root.yml", __dir__)),
|
191
|
-
env: "production"
|
192
|
-
)
|
193
|
-
|
194
|
-
it "#public_output_path returns correct path" do
|
195
|
-
expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
|
196
|
-
|
197
|
-
expect(config.public_output_path.to_s).to eq expected_public_output_path
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context "with webpacker config file containing manifest_path entry" do
|
202
|
-
config = Webpacker::Configuration.new(
|
203
|
-
root_path: ROOT_PATH,
|
204
|
-
config_path: Pathname.new(File.expand_path("./webpacker_test_app/config/webpacker_manifest_path.yml", __dir__)),
|
205
|
-
env: "production"
|
206
|
-
)
|
207
|
-
|
208
|
-
it "#manifest_path returns correct expected value" do
|
209
|
-
expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/app/packs", "manifest.json").to_s
|
210
|
-
|
211
|
-
expect(config.manifest_path.to_s).to eq expected_manifest_path
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context "with webpacker_precompile entry set to false" do
|
216
|
-
describe "#webpacker_precompile?" do
|
217
|
-
before :each do
|
218
|
-
ENV.delete("SHAKAPACKER_PRECOMPILE")
|
219
|
-
ENV.delete("WEBPACKER_PRECOMPILE")
|
220
|
-
end
|
221
|
-
|
222
|
-
let(:config) {
|
223
|
-
Webpacker::Configuration.new(
|
224
|
-
root_path: ROOT_PATH,
|
225
|
-
config_path: Pathname.new(File.expand_path("./webpacker_test_app/config/webpacker_no_precompile.yml", __dir__)),
|
226
|
-
env: "production"
|
227
|
-
)
|
228
|
-
}
|
229
|
-
|
230
|
-
subject { config.webpacker_precompile? }
|
231
|
-
|
232
|
-
it "returns false with unset WEBPACKER_PRECOMPILE" do
|
233
|
-
expect(subject).to be false
|
234
|
-
end
|
235
|
-
|
236
|
-
it "returns true with WEBPACKER_PRECOMPILE set to true" do
|
237
|
-
ENV["WEBPACKER_PRECOMPILE"] = "true"
|
238
|
-
expect(subject).to be true
|
239
|
-
end
|
240
|
-
|
241
|
-
it "returns false with WEBPACKER_PRECOMPILE set to nil" do
|
242
|
-
ENV["SHAKAPACKER_PRECOMPILE"] = nil
|
243
|
-
expect(subject).to be false
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
context "with webpacker config file containing invalid path" do
|
249
|
-
config = Webpacker::Configuration.new(
|
250
|
-
root_path: ROOT_PATH,
|
251
|
-
config_path: Pathname.new(File.expand_path("./webpacker_test_app/config/invalid_path.yml", __dir__)),
|
252
|
-
env: "default"
|
253
|
-
)
|
254
|
-
|
255
|
-
it "#webpacker_precompile? returns false" do
|
256
|
-
expect(config.webpacker_precompile?).to be false
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
context "with webpacker config file with defaults fallback" do
|
261
|
-
let(:config) do
|
262
|
-
Webpacker::Configuration.new(
|
263
|
-
root_path: ROOT_PATH,
|
264
|
-
config_path: Pathname.new(File.expand_path("./webpacker_test_app/config/webpacker_defaults_fallback.yml", __dir__)),
|
265
|
-
env: "default"
|
266
|
-
)
|
267
|
-
end
|
268
|
-
|
269
|
-
it "#cache_manifest? falls back to 'default' config from bundled file" do
|
270
|
-
expect(config.cache_manifest?).to be false
|
271
|
-
end
|
272
|
-
|
273
|
-
it "#webpacker_precompile? uses 'default' config from custom file" do
|
274
|
-
expect(config.webpacker_precompile?).to be false
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
context "falls back to bundled production config for custom environments" do
|
279
|
-
let(:config) do
|
280
|
-
Webpacker::Configuration.new(
|
281
|
-
root_path: ROOT_PATH,
|
282
|
-
config_path: Pathname.new(File.expand_path("./webpacker_test_app/config/webpacker_defaults_fallback.yml", __dir__)),
|
283
|
-
env: "staging"
|
284
|
-
)
|
285
|
-
end
|
286
|
-
|
287
|
-
it "#cache_manifest? fall back to 'production' config from bundled file" do
|
288
|
-
expect(config.cache_manifest?).to be true
|
289
|
-
end
|
290
|
-
it "#webpacker_precompile? use 'staging' config from custom file" do
|
291
|
-
expect(config.webpacker_precompile?).to be false
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|