shakapacker 7.3.0.beta.1 → 8.0.0.rc.2
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
@@ -0,0 +1,32 @@
|
|
1
|
+
const { resolve } = require("path")
|
2
|
+
const { chdirTestApp } = require("../helpers")
|
3
|
+
|
4
|
+
const rootPath = process.cwd()
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe("Production environment", () => {
|
8
|
+
afterAll(() => process.chdir(rootPath))
|
9
|
+
|
10
|
+
describe("generateWebpackConfig", () => {
|
11
|
+
beforeEach(() => jest.resetModules())
|
12
|
+
|
13
|
+
test("should use production config and environment", () => {
|
14
|
+
process.env.RAILS_ENV = "production"
|
15
|
+
process.env.NODE_ENV = "production"
|
16
|
+
|
17
|
+
const { generateWebpackConfig } = require("../../package/index")
|
18
|
+
|
19
|
+
const webpackConfig = generateWebpackConfig()
|
20
|
+
|
21
|
+
expect(webpackConfig.output.path).toStrictEqual(
|
22
|
+
resolve("public", "packs")
|
23
|
+
)
|
24
|
+
expect(webpackConfig.output.publicPath).toBe("/packs/")
|
25
|
+
|
26
|
+
expect(webpackConfig).toMatchObject({
|
27
|
+
devtool: "source-map",
|
28
|
+
stats: "normal"
|
29
|
+
})
|
30
|
+
})
|
31
|
+
})
|
32
|
+
})
|
@@ -0,0 +1,58 @@
|
|
1
|
+
const {
|
2
|
+
pathToAppJavascript,
|
3
|
+
pathToNodeModules,
|
4
|
+
pathToNodeModulesIncluded,
|
5
|
+
createTestCompiler,
|
6
|
+
createTrackLoader
|
7
|
+
} = require("../../helpers")
|
8
|
+
const babelConfig = require("../../../package/rules/babel")
|
9
|
+
|
10
|
+
jest.mock("../../../package/config", () => {
|
11
|
+
const original = jest.requireActual("../../../package/config")
|
12
|
+
return {
|
13
|
+
...original,
|
14
|
+
additional_paths: [...original.additional_paths, "node_modules/included"]
|
15
|
+
}
|
16
|
+
})
|
17
|
+
|
18
|
+
const createWebpackConfig = (file, use) => ({
|
19
|
+
entry: { file },
|
20
|
+
module: {
|
21
|
+
rules: [
|
22
|
+
{
|
23
|
+
...babelConfig,
|
24
|
+
use
|
25
|
+
}
|
26
|
+
]
|
27
|
+
},
|
28
|
+
output: {
|
29
|
+
path: "/",
|
30
|
+
filename: "scripts-bundled.js"
|
31
|
+
}
|
32
|
+
})
|
33
|
+
|
34
|
+
describe("babel", () => {
|
35
|
+
test("process source path", async () => {
|
36
|
+
const normalPath = `${pathToAppJavascript}/a.js`
|
37
|
+
const [tracked, loader] = createTrackLoader()
|
38
|
+
const compiler = createTestCompiler(createWebpackConfig(normalPath, loader))
|
39
|
+
await compiler.run()
|
40
|
+
expect(tracked[normalPath]).toBeTruthy()
|
41
|
+
})
|
42
|
+
|
43
|
+
test("exclude node_modules", async () => {
|
44
|
+
const ignored = `${pathToNodeModules}/a.js`
|
45
|
+
const [tracked, loader] = createTrackLoader()
|
46
|
+
const compiler = createTestCompiler(createWebpackConfig(ignored, loader))
|
47
|
+
await compiler.run()
|
48
|
+
expect(tracked[ignored]).toBeUndefined()
|
49
|
+
})
|
50
|
+
|
51
|
+
test("explicitly included node_modules should be transpiled", async () => {
|
52
|
+
const included = `${pathToNodeModulesIncluded}/a.js`
|
53
|
+
const [tracked, loader] = createTrackLoader()
|
54
|
+
const compiler = createTestCompiler(createWebpackConfig(included, loader))
|
55
|
+
await compiler.run()
|
56
|
+
expect(tracked[included]).toBeTruthy()
|
57
|
+
})
|
58
|
+
})
|
@@ -0,0 +1,59 @@
|
|
1
|
+
const {
|
2
|
+
pathToAppJavascript,
|
3
|
+
pathToNodeModules,
|
4
|
+
pathToNodeModulesIncluded,
|
5
|
+
createTestCompiler,
|
6
|
+
createTrackLoader
|
7
|
+
} = require("../../helpers")
|
8
|
+
const esbuildConfig = require("../../../package/rules/esbuild")
|
9
|
+
|
10
|
+
jest.mock("../../../package/config", () => {
|
11
|
+
const original = jest.requireActual("../../../package/config")
|
12
|
+
return {
|
13
|
+
...original,
|
14
|
+
webpack_loader: "esbuild",
|
15
|
+
additional_paths: [...original.additional_paths, "node_modules/included"]
|
16
|
+
}
|
17
|
+
})
|
18
|
+
|
19
|
+
const createWebpackConfig = (file, use) => ({
|
20
|
+
entry: { file },
|
21
|
+
module: {
|
22
|
+
rules: [
|
23
|
+
{
|
24
|
+
...esbuildConfig,
|
25
|
+
use
|
26
|
+
}
|
27
|
+
]
|
28
|
+
},
|
29
|
+
output: {
|
30
|
+
path: "/",
|
31
|
+
filename: "scripts-bundled.js"
|
32
|
+
}
|
33
|
+
})
|
34
|
+
|
35
|
+
describe("swc", () => {
|
36
|
+
test("process source path", async () => {
|
37
|
+
const normalPath = `${pathToAppJavascript}/a.js`
|
38
|
+
const [tracked, loader] = createTrackLoader()
|
39
|
+
const compiler = createTestCompiler(createWebpackConfig(normalPath, loader))
|
40
|
+
await compiler.run()
|
41
|
+
expect(tracked[normalPath]).toBeTruthy()
|
42
|
+
})
|
43
|
+
|
44
|
+
test("exclude node_modules", async () => {
|
45
|
+
const ignored = `${pathToNodeModules}/a.js`
|
46
|
+
const [tracked, loader] = createTrackLoader()
|
47
|
+
const compiler = createTestCompiler(createWebpackConfig(ignored, loader))
|
48
|
+
await compiler.run()
|
49
|
+
expect(tracked[ignored]).toBeUndefined()
|
50
|
+
})
|
51
|
+
|
52
|
+
test("explicitly included node_modules should be transpiled", async () => {
|
53
|
+
const included = `${pathToNodeModulesIncluded}/a.js`
|
54
|
+
const [tracked, loader] = createTrackLoader()
|
55
|
+
const compiler = createTestCompiler(createWebpackConfig(included, loader))
|
56
|
+
await compiler.run()
|
57
|
+
expect(tracked[included]).toBeTruthy()
|
58
|
+
})
|
59
|
+
})
|
@@ -0,0 +1,81 @@
|
|
1
|
+
const file = require("../../../package/rules/file")
|
2
|
+
|
3
|
+
jest.mock("../../../package/config", () => {
|
4
|
+
const original = jest.requireActual("../../../package/config")
|
5
|
+
return {
|
6
|
+
...original,
|
7
|
+
additional_paths: [...original.additional_paths, "app/assets"]
|
8
|
+
}
|
9
|
+
})
|
10
|
+
|
11
|
+
describe("file", () => {
|
12
|
+
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 = [".js", ".mjs", ".jsx", ".ts", ".tsx"]
|
35
|
+
types.forEach((type) => expect(file.exclude.test(type)).toBe(true))
|
36
|
+
})
|
37
|
+
|
38
|
+
test("correct generated output path is returned for top level files", () => {
|
39
|
+
const pathData = {
|
40
|
+
filename: "app/javascript/image.svg"
|
41
|
+
}
|
42
|
+
expect(file.generator.filename(pathData)).toBe(
|
43
|
+
"static/[name]-[hash][ext][query]"
|
44
|
+
)
|
45
|
+
})
|
46
|
+
|
47
|
+
test("correct generated output path is returned for nested files", () => {
|
48
|
+
const pathData = {
|
49
|
+
filename: "app/javascript/images/image.svg"
|
50
|
+
}
|
51
|
+
expect(file.generator.filename(pathData)).toBe(
|
52
|
+
"static/images/[name]-[hash][ext][query]"
|
53
|
+
)
|
54
|
+
})
|
55
|
+
|
56
|
+
test("correct generated output path is returned for deeply nested files", () => {
|
57
|
+
const pathData = {
|
58
|
+
filename: "app/javascript/images/nested/deeply/image.svg"
|
59
|
+
}
|
60
|
+
expect(file.generator.filename(pathData)).toBe(
|
61
|
+
"static/images/nested/deeply/[name]-[hash][ext][query]"
|
62
|
+
)
|
63
|
+
})
|
64
|
+
|
65
|
+
test("correct generated output path is returned for additional_paths", () => {
|
66
|
+
const pathData = {
|
67
|
+
filename: "app/assets/images/image.svg"
|
68
|
+
}
|
69
|
+
|
70
|
+
expect(file.generator.filename(pathData)).toBe(
|
71
|
+
"static/images/[name]-[hash][ext][query]"
|
72
|
+
)
|
73
|
+
|
74
|
+
const pathData2 = {
|
75
|
+
filename: "app/javascript/app/assets/image.svg"
|
76
|
+
}
|
77
|
+
expect(file.generator.filename(pathData2)).toBe(
|
78
|
+
"static/app/assets/[name]-[hash][ext][query]"
|
79
|
+
)
|
80
|
+
})
|
81
|
+
})
|
@@ -0,0 +1,12 @@
|
|
1
|
+
const raw = require("../../../package/rules/raw")
|
2
|
+
|
3
|
+
describe("raw", () => {
|
4
|
+
test("expected file types", () => {
|
5
|
+
expect(raw.test.test(".html")).toBe(true)
|
6
|
+
})
|
7
|
+
|
8
|
+
test("exclude expected file types", () => {
|
9
|
+
const types = [".js", ".mjs", ".jsx", ".ts", ".tsx"]
|
10
|
+
types.forEach((type) => expect(raw.exclude.test(type)).toBe(true))
|
11
|
+
})
|
12
|
+
})
|
@@ -0,0 +1,59 @@
|
|
1
|
+
const {
|
2
|
+
pathToAppJavascript,
|
3
|
+
pathToNodeModules,
|
4
|
+
pathToNodeModulesIncluded,
|
5
|
+
createTestCompiler,
|
6
|
+
createTrackLoader
|
7
|
+
} = require("../../helpers")
|
8
|
+
const swcConfig = require("../../../package/rules/swc")
|
9
|
+
|
10
|
+
jest.mock("../../../package/config", () => {
|
11
|
+
const original = jest.requireActual("../../../package/config")
|
12
|
+
return {
|
13
|
+
...original,
|
14
|
+
webpack_loader: "swc",
|
15
|
+
additional_paths: [...original.additional_paths, "node_modules/included"]
|
16
|
+
}
|
17
|
+
})
|
18
|
+
|
19
|
+
const createWebpackConfig = (file, use) => ({
|
20
|
+
entry: { file },
|
21
|
+
module: {
|
22
|
+
rules: [
|
23
|
+
{
|
24
|
+
...swcConfig,
|
25
|
+
use
|
26
|
+
}
|
27
|
+
]
|
28
|
+
},
|
29
|
+
output: {
|
30
|
+
path: "/",
|
31
|
+
filename: "scripts-bundled.js"
|
32
|
+
}
|
33
|
+
})
|
34
|
+
|
35
|
+
describe("swc", () => {
|
36
|
+
test("process files in source_path", async () => {
|
37
|
+
const normalPath = `${pathToAppJavascript}/a.js`
|
38
|
+
const [tracked, loader] = createTrackLoader()
|
39
|
+
const compiler = createTestCompiler(createWebpackConfig(normalPath, loader))
|
40
|
+
await compiler.run()
|
41
|
+
expect(tracked[normalPath]).toBeTruthy()
|
42
|
+
})
|
43
|
+
|
44
|
+
test("exclude node_modules", async () => {
|
45
|
+
const ignored = `${pathToNodeModules}/a.js`
|
46
|
+
const [tracked, loader] = createTrackLoader()
|
47
|
+
const compiler = createTestCompiler(createWebpackConfig(ignored, loader))
|
48
|
+
await compiler.run()
|
49
|
+
expect(tracked[ignored]).toBeUndefined()
|
50
|
+
})
|
51
|
+
|
52
|
+
test("explicitly included node_modules should be transpiled", async () => {
|
53
|
+
const included = `${pathToNodeModulesIncluded}/a.js`
|
54
|
+
const [tracked, loader] = createTrackLoader()
|
55
|
+
const compiler = createTestCompiler(createWebpackConfig(included, loader))
|
56
|
+
await compiler.run()
|
57
|
+
expect(tracked[included]).toBeTruthy()
|
58
|
+
})
|
59
|
+
})
|
@@ -0,0 +1,31 @@
|
|
1
|
+
const { resolve } = require("path")
|
2
|
+
const { chdirTestApp } = require("../helpers")
|
3
|
+
|
4
|
+
const rootPath = process.cwd()
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe("Custom environment", () => {
|
8
|
+
afterAll(() => process.chdir(rootPath))
|
9
|
+
|
10
|
+
describe("generateWebpackConfig", () => {
|
11
|
+
beforeEach(() => jest.resetModules())
|
12
|
+
|
13
|
+
test("should use staging config and default production environment", () => {
|
14
|
+
process.env.RAILS_ENV = "staging"
|
15
|
+
delete process.env.NODE_ENV
|
16
|
+
|
17
|
+
const { generateWebpackConfig } = require("../../package/index")
|
18
|
+
|
19
|
+
const webpackConfig = generateWebpackConfig()
|
20
|
+
|
21
|
+
expect(webpackConfig.output.path).toStrictEqual(
|
22
|
+
resolve("public", "packs-staging")
|
23
|
+
)
|
24
|
+
expect(webpackConfig.output.publicPath).toBe("/packs-staging/")
|
25
|
+
expect(webpackConfig).toMatchObject({
|
26
|
+
devtool: "source-map",
|
27
|
+
stats: "normal"
|
28
|
+
})
|
29
|
+
})
|
30
|
+
})
|
31
|
+
})
|
@@ -0,0 +1,28 @@
|
|
1
|
+
const { resolve } = require("path")
|
2
|
+
const { chdirTestApp } = require("../helpers")
|
3
|
+
|
4
|
+
const rootPath = process.cwd()
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe("Test environment", () => {
|
8
|
+
afterAll(() => process.chdir(rootPath))
|
9
|
+
|
10
|
+
describe("generateWebpackConfig", () => {
|
11
|
+
beforeEach(() => jest.resetModules())
|
12
|
+
|
13
|
+
test("should use test config and production environment", () => {
|
14
|
+
process.env.RAILS_ENV = "test"
|
15
|
+
process.env.NODE_ENV = "test"
|
16
|
+
|
17
|
+
const { generateWebpackConfig } = require("../../package/index")
|
18
|
+
|
19
|
+
const webpackConfig = generateWebpackConfig()
|
20
|
+
|
21
|
+
expect(webpackConfig.output.path).toStrictEqual(
|
22
|
+
resolve("public", "packs-test")
|
23
|
+
)
|
24
|
+
expect(webpackConfig.output.publicPath).toBe("/packs-test/")
|
25
|
+
expect(webpackConfig.devServer).toBeUndefined()
|
26
|
+
})
|
27
|
+
})
|
28
|
+
})
|