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
data/package/esbuild/index.js
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const { resolve } = require(
|
5
|
-
const { existsSync } = require(
|
6
|
-
const { merge } = require(
|
4
|
+
const { resolve } = require("path")
|
5
|
+
const { existsSync } = require("fs")
|
6
|
+
const { merge } = require("webpack-merge")
|
7
7
|
|
8
8
|
const getLoaderExtension = (filename) => {
|
9
9
|
const matchData = filename.match(/\.([jt]sx?)?(\.erb)?$/)
|
10
10
|
|
11
11
|
if (!matchData) {
|
12
|
-
return
|
12
|
+
return "js"
|
13
13
|
}
|
14
14
|
|
15
15
|
return matchData[1]
|
16
16
|
}
|
17
17
|
|
18
18
|
const getCustomConfig = () => {
|
19
|
-
const path = resolve(
|
19
|
+
const path = resolve("config", "esbuild.config.js")
|
20
20
|
if (existsSync(path)) {
|
21
21
|
return require(path)
|
22
22
|
}
|
@@ -26,7 +26,7 @@ const getCustomConfig = () => {
|
|
26
26
|
const getEsbuildLoaderConfig = (filenameToProcess) => {
|
27
27
|
const customConfig = getCustomConfig()
|
28
28
|
const defaultConfig = {
|
29
|
-
loader: require.resolve(
|
29
|
+
loader: require.resolve("esbuild-loader"),
|
30
30
|
options: {
|
31
31
|
loader: getLoaderExtension(filenameToProcess)
|
32
32
|
}
|
data/package/index.d.ts
CHANGED
@@ -22,7 +22,6 @@ declare module 'shakapacker' {
|
|
22
22
|
publicPath: string
|
23
23
|
publicPathWithoutCDN: string
|
24
24
|
manifestPath: string
|
25
|
-
includePaths: string[]
|
26
25
|
}
|
27
26
|
|
28
27
|
export interface Env {
|
@@ -36,7 +35,6 @@ declare module 'shakapacker' {
|
|
36
35
|
export const config: Config
|
37
36
|
export const devServer: Record<string, unknown>
|
38
37
|
export function generateWebpackConfig(extraConfig?: Configuration): Configuration
|
39
|
-
export const globalMutableWebpackConfig: Configuration
|
40
38
|
export const baseConfig: Configuration
|
41
39
|
export const env: Env
|
42
40
|
export const rules: Record<string, unknown>
|
data/package/index.js
CHANGED
@@ -1,41 +1,35 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const webpackMerge = require(
|
5
|
-
const { resolve } = require(
|
6
|
-
const { existsSync } = require(
|
7
|
-
const baseConfig = require(
|
8
|
-
const rules = require(
|
9
|
-
const config = require(
|
10
|
-
const devServer = require(
|
11
|
-
const env = require(
|
12
|
-
const { moduleExists, canProcess } = require(
|
13
|
-
const inliningCss = require(
|
14
|
-
|
15
|
-
const globalMutableWebpackConfig = () => {
|
16
|
-
const { nodeEnv } = env
|
17
|
-
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
18
|
-
const environmentConfig = existsSync(path) ? require(path) : baseConfig
|
19
|
-
return environmentConfig
|
20
|
-
}
|
4
|
+
const webpackMerge = require("webpack-merge")
|
5
|
+
const { resolve } = require("path")
|
6
|
+
const { existsSync } = require("fs")
|
7
|
+
const baseConfig = require("./environments/base")
|
8
|
+
const rules = require("./rules")
|
9
|
+
const config = require("./config")
|
10
|
+
const devServer = require("./dev_server")
|
11
|
+
const env = require("./env")
|
12
|
+
const { moduleExists, canProcess } = require("./utils/helpers")
|
13
|
+
const inliningCss = require("./utils/inliningCss")
|
21
14
|
|
22
15
|
const generateWebpackConfig = (extraConfig = {}, ...extraArgs) => {
|
23
16
|
if (extraArgs.length > 0) {
|
24
17
|
throw new Error(
|
25
|
-
|
18
|
+
"Only one extra config may be passed here - use webpack-merge to merge configs before passing them to Shakapacker"
|
26
19
|
)
|
27
20
|
}
|
28
21
|
|
29
|
-
const
|
30
|
-
const
|
31
|
-
|
22
|
+
const { nodeEnv } = env
|
23
|
+
const path = resolve(__dirname, "environments", `${nodeEnv}.js`)
|
24
|
+
const environmentConfig = existsSync(path) ? require(path) : baseConfig
|
25
|
+
|
26
|
+
return webpackMerge.merge({}, environmentConfig, extraConfig)
|
32
27
|
}
|
33
28
|
|
34
|
-
|
29
|
+
module.exports = {
|
35
30
|
config, // shakapacker.yml
|
36
31
|
devServer,
|
37
32
|
generateWebpackConfig,
|
38
|
-
globalMutableWebpackConfig: globalMutableWebpackConfig(),
|
39
33
|
baseConfig,
|
40
34
|
env,
|
41
35
|
rules,
|
@@ -44,26 +38,3 @@ const shakapackerObject = {
|
|
44
38
|
inliningCss,
|
45
39
|
...webpackMerge
|
46
40
|
}
|
47
|
-
|
48
|
-
// For backward compatibility
|
49
|
-
const shakapackerProxyHandler = {
|
50
|
-
get(target, prop) {
|
51
|
-
if (prop === 'webpackConfig') {
|
52
|
-
// eslint-disable-next-line no-console
|
53
|
-
console.warn(`⚠️
|
54
|
-
DEPRECATION NOTICE:
|
55
|
-
The 'webpackConfig' is deprecated and will be removed in a future version.
|
56
|
-
Please use 'globalMutableWebpackConfig' instead, or use
|
57
|
-
'generateWebpackConfig()' to avoid unwanted config mutation across the app.
|
58
|
-
|
59
|
-
For more information, see version 7 upgrade documentation at:
|
60
|
-
https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md
|
61
|
-
`)
|
62
|
-
return globalMutableWebpackConfig()
|
63
|
-
}
|
64
|
-
|
65
|
-
return target[prop]
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
module.exports = new Proxy(shakapackerObject, shakapackerProxyHandler)
|
data/package/rules/babel.js
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
const { loaderMatches } = require(
|
2
|
-
const {
|
3
|
-
|
4
|
-
|
5
|
-
const { isProduction } = require('../env')
|
6
|
-
const jscommon = require('./jscommon')
|
1
|
+
const { loaderMatches } = require("../utils/helpers")
|
2
|
+
const { webpack_loader: webpackLoader } = require("../config")
|
3
|
+
const { isProduction } = require("../env")
|
4
|
+
const jscommon = require("./jscommon")
|
7
5
|
|
8
|
-
module.exports = loaderMatches(webpackLoader,
|
6
|
+
module.exports = loaderMatches(webpackLoader, "babel", () => ({
|
9
7
|
test: /\.(js|jsx|mjs|ts|tsx|coffee)?(\.erb)?$/,
|
10
8
|
...jscommon,
|
11
9
|
use: [
|
12
10
|
{
|
13
|
-
loader: require.resolve(
|
11
|
+
loader: require.resolve("babel-loader"),
|
14
12
|
options: {
|
15
13
|
cacheDirectory: true,
|
16
14
|
cacheCompression: isProduction,
|
data/package/rules/coffee.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
const { canProcess } = require(
|
1
|
+
const { canProcess } = require("../utils/helpers")
|
2
2
|
|
3
|
-
module.exports = canProcess(
|
3
|
+
module.exports = canProcess("coffee-loader", (resolvedPath) => ({
|
4
4
|
test: /\.coffee(\.erb)?$/,
|
5
5
|
use: [{ loader: resolvedPath }]
|
6
6
|
}))
|
data/package/rules/css.js
CHANGED
data/package/rules/erb.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
const { canProcess } = require(
|
1
|
+
const { canProcess } = require("../utils/helpers")
|
2
2
|
|
3
|
-
const runner = /^win/.test(process.platform) ?
|
3
|
+
const runner = /^win/.test(process.platform) ? "ruby " : ""
|
4
4
|
|
5
|
-
module.exports = canProcess(
|
5
|
+
module.exports = canProcess("rails-erb-loader", (resolvedPath) => ({
|
6
6
|
test: /\.erb$/,
|
7
|
-
enforce:
|
7
|
+
enforce: "pre",
|
8
8
|
exclude: /node_modules/,
|
9
9
|
use: [
|
10
10
|
{
|
data/package/rules/esbuild.js
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
const { loaderMatches } = require(
|
2
|
-
const { getEsbuildLoaderConfig } = require(
|
3
|
-
const {
|
4
|
-
|
5
|
-
} = require('../config')
|
6
|
-
const jscommon = require('./jscommon')
|
1
|
+
const { loaderMatches } = require("../utils/helpers")
|
2
|
+
const { getEsbuildLoaderConfig } = require("../esbuild")
|
3
|
+
const { webpack_loader: webpackLoader } = require("../config")
|
4
|
+
const jscommon = require("./jscommon")
|
7
5
|
|
8
|
-
module.exports = loaderMatches(webpackLoader,
|
6
|
+
module.exports = loaderMatches(webpackLoader, "esbuild", () => ({
|
9
7
|
test: /\.(ts|tsx|js|jsx|mjs|coffee)?(\.erb)?$/,
|
10
8
|
...jscommon,
|
11
9
|
use: ({ resource }) => getEsbuildLoaderConfig(resource)
|
data/package/rules/file.js
CHANGED
@@ -1,21 +1,28 @@
|
|
1
|
-
const { dirname } = require(
|
2
|
-
const {
|
1
|
+
const { dirname } = require("path")
|
2
|
+
const {
|
3
|
+
additional_paths: additionalPaths,
|
4
|
+
source_path: sourcePath
|
5
|
+
} = require("../config")
|
3
6
|
|
4
7
|
module.exports = {
|
5
8
|
test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg)$/,
|
6
9
|
exclude: /\.(js|mjs|jsx|ts|tsx)$/,
|
7
|
-
type:
|
10
|
+
type: "asset/resource",
|
8
11
|
generator: {
|
9
12
|
filename: (pathData) => {
|
10
13
|
const path = dirname(pathData.filename)
|
11
|
-
const
|
14
|
+
const stripPaths = [...additionalPaths, sourcePath]
|
15
|
+
|
16
|
+
const selectedStripPath = stripPaths.find((includePath) =>
|
17
|
+
path.startsWith(includePath)
|
18
|
+
)
|
12
19
|
|
13
20
|
const folders = path
|
14
|
-
.replace(`${
|
15
|
-
.split(
|
21
|
+
.replace(`${selectedStripPath}`, "")
|
22
|
+
.split("/")
|
16
23
|
.filter(Boolean)
|
17
24
|
|
18
|
-
const foldersWithStatic = [
|
25
|
+
const foldersWithStatic = ["static", ...folders].join("/")
|
19
26
|
return `${foldersWithStatic}/[name]-[hash][ext][query]`
|
20
27
|
}
|
21
28
|
}
|
data/package/rules/index.js
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
4
|
const rules = {
|
5
|
-
raw: require(
|
6
|
-
file: require(
|
7
|
-
css: require(
|
8
|
-
sass: require(
|
9
|
-
babel: require(
|
10
|
-
swc: require(
|
11
|
-
esbuild: require(
|
12
|
-
erb: require(
|
13
|
-
coffee: require(
|
14
|
-
less: require(
|
15
|
-
stylus: require(
|
5
|
+
raw: require("./raw"),
|
6
|
+
file: require("./file"),
|
7
|
+
css: require("./css"),
|
8
|
+
sass: require("./sass"),
|
9
|
+
babel: require("./babel"),
|
10
|
+
swc: require("./swc"),
|
11
|
+
esbuild: require("./esbuild"),
|
12
|
+
erb: require("./erb"),
|
13
|
+
coffee: require("./coffee"),
|
14
|
+
less: require("./less"),
|
15
|
+
stylus: require("./stylus")
|
16
16
|
}
|
17
17
|
|
18
18
|
module.exports = Object.keys(rules)
|
data/package/rules/jscommon.js
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
const { resolve } = require(
|
2
|
-
const { realpathSync } = require(
|
3
|
-
const {
|
1
|
+
const { resolve } = require("path")
|
2
|
+
const { realpathSync } = require("fs")
|
3
|
+
const {
|
4
|
+
source_path: sourcePath,
|
5
|
+
additional_paths: additionalPaths
|
6
|
+
} = require("../config")
|
4
7
|
|
5
|
-
const inclusions =
|
8
|
+
const inclusions = [sourcePath, ...additionalPaths].map((p) => {
|
6
9
|
try {
|
7
10
|
return realpathSync(p)
|
8
11
|
} catch (e) {
|
@@ -15,7 +18,7 @@ module.exports = {
|
|
15
18
|
exclude: [
|
16
19
|
{
|
17
20
|
// exclude all node_modules from running through babel-loader
|
18
|
-
and: [resolve(
|
21
|
+
and: [resolve("node_modules")],
|
19
22
|
// Do not exclude inclusions, as otherwise these won't be transpiled
|
20
23
|
not: [...inclusions]
|
21
24
|
}
|
data/package/rules/less.js
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
const path = require(
|
2
|
-
const { canProcess } = require(
|
3
|
-
const getStyleRule = require(
|
4
|
-
const { includePaths } = require('../config')
|
1
|
+
const path = require("path")
|
2
|
+
const { canProcess } = require("../utils/helpers")
|
3
|
+
const getStyleRule = require("../utils/getStyleRule")
|
5
4
|
|
6
|
-
|
5
|
+
const {
|
6
|
+
additional_paths: paths,
|
7
|
+
source_path: sourcePath
|
8
|
+
} = require("../config")
|
9
|
+
|
10
|
+
module.exports = canProcess("less-loader", (resolvedPath) =>
|
7
11
|
getStyleRule(/\.(less)(\.erb)?$/i, [
|
8
12
|
{
|
9
13
|
loader: resolvedPath,
|
10
14
|
options: {
|
11
15
|
lessOptions: {
|
12
|
-
paths: [
|
13
|
-
path.resolve(__dirname, 'node_modules'),
|
14
|
-
...includePaths
|
15
|
-
]
|
16
|
+
paths: [path.resolve(__dirname, "node_modules"), sourcePath, ...paths]
|
16
17
|
},
|
17
18
|
sourceMap: true
|
18
19
|
}
|
data/package/rules/raw.js
CHANGED
data/package/rules/sass.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
|
3
|
-
const getStyleRule = require(
|
4
|
-
const { canProcess } = require(
|
5
|
-
const { additional_paths: includePaths } = require(
|
3
|
+
const getStyleRule = require("../utils/getStyleRule")
|
4
|
+
const { canProcess } = require("../utils/helpers")
|
5
|
+
const { additional_paths: includePaths } = require("../config")
|
6
6
|
|
7
|
-
module.exports = canProcess(
|
7
|
+
module.exports = canProcess("sass-loader", (resolvedPath) =>
|
8
8
|
getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
|
9
9
|
{
|
10
10
|
loader: resolvedPath,
|
data/package/rules/stylus.js
CHANGED
@@ -1,17 +1,22 @@
|
|
1
|
-
const path = require(
|
2
|
-
const { canProcess } = require(
|
3
|
-
const getStyleRule = require(
|
4
|
-
const { includePaths } = require('../config')
|
1
|
+
const path = require("path")
|
2
|
+
const { canProcess } = require("../utils/helpers")
|
3
|
+
const getStyleRule = require("../utils/getStyleRule")
|
5
4
|
|
6
|
-
|
5
|
+
const {
|
6
|
+
additional_paths: paths,
|
7
|
+
source_path: sourcePath
|
8
|
+
} = require("../config")
|
9
|
+
|
10
|
+
module.exports = canProcess("stylus-loader", (resolvedPath) =>
|
7
11
|
getStyleRule(/\.(styl(us)?)(\.erb)?$/i, [
|
8
12
|
{
|
9
13
|
loader: resolvedPath,
|
10
14
|
options: {
|
11
15
|
stylusOptions: {
|
12
16
|
include: [
|
13
|
-
path.resolve(__dirname,
|
14
|
-
|
17
|
+
path.resolve(__dirname, "node_modules"),
|
18
|
+
sourcePath,
|
19
|
+
...paths
|
15
20
|
]
|
16
21
|
},
|
17
22
|
sourceMap: true
|
data/package/rules/swc.js
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
const { loaderMatches } = require(
|
2
|
-
const { getSwcLoaderConfig } = require(
|
3
|
-
const {
|
4
|
-
|
5
|
-
} = require('../config')
|
6
|
-
const jscommon = require('./jscommon')
|
1
|
+
const { loaderMatches } = require("../utils/helpers")
|
2
|
+
const { getSwcLoaderConfig } = require("../swc")
|
3
|
+
const { webpack_loader: webpackLoader } = require("../config")
|
4
|
+
const jscommon = require("./jscommon")
|
7
5
|
|
8
|
-
module.exports = loaderMatches(webpackLoader,
|
6
|
+
module.exports = loaderMatches(webpackLoader, "swc", () => ({
|
9
7
|
test: /\.(ts|tsx|js|jsx|mjs|coffee)?(\.erb)?$/,
|
10
8
|
...jscommon,
|
11
9
|
use: ({ resource }) => getSwcLoaderConfig(resource)
|
data/package/swc/index.js
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const { resolve } = require(
|
5
|
-
const { existsSync } = require(
|
6
|
-
const { merge } = require(
|
4
|
+
const { resolve } = require("path")
|
5
|
+
const { existsSync } = require("fs")
|
6
|
+
const { merge } = require("webpack-merge")
|
7
7
|
|
8
8
|
const isJsxFile = (filename) => !!filename.match(/\.(jsx|tsx)?(\.erb)?$/)
|
9
9
|
|
10
10
|
const isTypescriptFile = (filename) => !!filename.match(/\.(ts|tsx)?(\.erb)?$/)
|
11
11
|
|
12
12
|
const getCustomConfig = () => {
|
13
|
-
const path = resolve(
|
13
|
+
const path = resolve("config", "swc.config.js")
|
14
14
|
if (existsSync(path)) {
|
15
15
|
return require(path)
|
16
16
|
}
|
@@ -20,15 +20,15 @@ const getCustomConfig = () => {
|
|
20
20
|
const getSwcLoaderConfig = (filenameToProcess) => {
|
21
21
|
const customConfig = getCustomConfig()
|
22
22
|
const defaultConfig = {
|
23
|
-
loader: require.resolve(
|
23
|
+
loader: require.resolve("swc-loader"),
|
24
24
|
options: {
|
25
25
|
jsc: {
|
26
26
|
parser: {
|
27
27
|
dynamicImport: true,
|
28
28
|
syntax: isTypescriptFile(filenameToProcess)
|
29
|
-
?
|
30
|
-
:
|
31
|
-
[isTypescriptFile(filenameToProcess) ?
|
29
|
+
? "typescript"
|
30
|
+
: "ecmascript",
|
31
|
+
[isTypescriptFile(filenameToProcess) ? "tsx" : "jsx"]:
|
32
32
|
isJsxFile(filenameToProcess)
|
33
33
|
},
|
34
34
|
loose: true
|
@@ -36,8 +36,8 @@ const getSwcLoaderConfig = (filenameToProcess) => {
|
|
36
36
|
sourceMaps: true,
|
37
37
|
env: {
|
38
38
|
coreJs: 3,
|
39
|
-
exclude: [
|
40
|
-
mode:
|
39
|
+
exclude: ["transform-typeof-symbol"],
|
40
|
+
mode: "entry"
|
41
41
|
}
|
42
42
|
}
|
43
43
|
}
|
data/package/utils/configPath.js
CHANGED
@@ -1,19 +1,4 @@
|
|
1
|
-
const
|
2
|
-
const { resolve } = require('path')
|
3
|
-
const { setShakapackerEnvVariablesForBackwardCompatibility } = require('./helpers')
|
1
|
+
const { resolve } = require("path")
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
// For backward compatibility
|
8
|
-
const resolveToPhysicalFilePath = () => {
|
9
|
-
const shakapackerConfigPath = resolve('config', 'shakapacker.yml')
|
10
|
-
const webpackerConfigPath = resolve('config', 'webpacker.yml')
|
11
|
-
|
12
|
-
if (fs.existsSync(shakapackerConfigPath)) return shakapackerConfigPath
|
13
|
-
if (fs.existsSync(webpackerConfigPath)) return webpackerConfigPath
|
14
|
-
|
15
|
-
// If neither of files exist, try to resolve to shakapacker.yml to get more relevant error
|
16
|
-
return shakapackerConfigPath
|
17
|
-
}
|
18
|
-
|
19
|
-
module.exports = process.env.SHAKAPACKER_CONFIG || resolveToPhysicalFilePath()
|
3
|
+
module.exports =
|
4
|
+
process.env.SHAKAPACKER_CONFIG || resolve("config", "shakapacker.yml")
|
@@ -1,2 +1,2 @@
|
|
1
|
-
const path = require.resolve(
|
1
|
+
const path = require.resolve("../../lib/install/config/shakapacker.yml")
|
2
2
|
module.exports = path
|
@@ -1,11 +1,11 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
|
-
const { canProcess, moduleExists } = require(
|
3
|
-
const inliningCss = require(
|
2
|
+
const { canProcess, moduleExists } = require("./helpers")
|
3
|
+
const inliningCss = require("./inliningCss")
|
4
4
|
|
5
5
|
const getStyleRule = (test, preprocessors = []) => {
|
6
|
-
if (moduleExists(
|
6
|
+
if (moduleExists("css-loader")) {
|
7
7
|
const tryPostcss = () =>
|
8
|
-
canProcess(
|
8
|
+
canProcess("postcss-loader", (loaderPath) => ({
|
9
9
|
loader: loaderPath,
|
10
10
|
options: { sourceMap: true }
|
11
11
|
}))
|
@@ -13,9 +13,9 @@ const getStyleRule = (test, preprocessors = []) => {
|
|
13
13
|
// style-loader is required when using css modules with HMR on the webpack-dev-server
|
14
14
|
|
15
15
|
const use = [
|
16
|
-
inliningCss ?
|
16
|
+
inliningCss ? "style-loader" : require("mini-css-extract-plugin").loader,
|
17
17
|
{
|
18
|
-
loader: require.resolve(
|
18
|
+
loader: require.resolve("css-loader"),
|
19
19
|
options: {
|
20
20
|
sourceMap: true,
|
21
21
|
importLoaders: 2,
|
data/package/utils/helpers.js
CHANGED
@@ -1,35 +1,12 @@
|
|
1
|
-
const isArray = (value) => Array.isArray(value)
|
2
1
|
const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
|
3
|
-
const chdirTestApp = () => {
|
4
|
-
try {
|
5
|
-
return process.chdir('spec/shakapacker/test_app')
|
6
|
-
} catch (e) {
|
7
|
-
return null
|
8
|
-
}
|
9
|
-
}
|
10
2
|
|
11
|
-
|
12
|
-
const chdirWebpackerTestApp = () => {
|
13
|
-
try {
|
14
|
-
return process.chdir('spec/backward_compatibility_specs/webpacker_test_app')
|
15
|
-
} catch (e) {
|
16
|
-
return null
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
const chdirCwd = () => process.chdir(process.cwd())
|
21
|
-
|
22
|
-
const resetEnv = () => {
|
23
|
-
process.env = {}
|
24
|
-
}
|
25
|
-
|
26
|
-
const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
|
3
|
+
const ensureTrailingSlash = (path) => (path.endsWith("/") ? path : `${path}/`)
|
27
4
|
|
28
5
|
const resolvedPath = (packageName) => {
|
29
6
|
try {
|
30
7
|
return require.resolve(packageName)
|
31
8
|
} catch (e) {
|
32
|
-
if (e.code !==
|
9
|
+
if (e.code !== "MODULE_NOT_FOUND") {
|
33
10
|
throw e
|
34
11
|
}
|
35
12
|
return null
|
@@ -64,28 +41,10 @@ const loaderMatches = (configLoader, loaderToCheck, fn) => {
|
|
64
41
|
return fn()
|
65
42
|
}
|
66
43
|
|
67
|
-
// For backward compatibility
|
68
|
-
// Set SHAKAPACKER_XYZ only if SHAKAPACKER_XYZ is not defined but WEBPACKER_XYZ is.
|
69
|
-
const setShakapackerEnvVariablesForBackwardCompatibility = () => {
|
70
|
-
const webpackerEnvVariables = Object.entries(process.env).filter((key) => /^WEBPACKER_/.test(key))
|
71
|
-
webpackerEnvVariables.forEach(([webpackerEnvKey, webpackerEnvValue]) => {
|
72
|
-
const shakapackerKey = webpackerEnvKey.replace(/^WEBPACKER/, 'SHAKAPACKER')
|
73
|
-
if (!process.env[shakapackerKey]) {
|
74
|
-
process.env[shakapackerKey] = webpackerEnvValue
|
75
|
-
}
|
76
|
-
})
|
77
|
-
}
|
78
|
-
|
79
44
|
module.exports = {
|
80
|
-
chdirTestApp,
|
81
|
-
chdirWebpackerTestApp,
|
82
|
-
setShakapackerEnvVariablesForBackwardCompatibility,
|
83
|
-
chdirCwd,
|
84
|
-
isArray,
|
85
45
|
isBoolean,
|
86
46
|
ensureTrailingSlash,
|
87
47
|
canProcess,
|
88
48
|
moduleExists,
|
89
|
-
resetEnv,
|
90
49
|
loaderMatches
|
91
50
|
}
|
@@ -1,7 +1,8 @@
|
|
1
|
-
const { runningWebpackDevServer } = require(
|
2
|
-
const devServer = require(
|
1
|
+
const { runningWebpackDevServer } = require("../env")
|
2
|
+
const devServer = require("../dev_server")
|
3
3
|
|
4
4
|
// This logic is tied to lib/shakapacker/instance.rb
|
5
|
-
const inliningCss =
|
5
|
+
const inliningCss =
|
6
|
+
runningWebpackDevServer && devServer.hmr && devServer.inline_css !== false
|
6
7
|
|
7
8
|
module.exports = inliningCss
|