Skip to content

Commit 66e95a9

Browse files
justin808claude
andcommitted
fix: Remove 'use strict' directives and fix formatting in compiled JS
- Remove unnecessary 'use strict' directives from TypeScript-compiled files - Fix prettier/eslint formatting issues in generated JavaScript - Ensures CI linting passes for all environment files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent c9be2a2 commit 66e95a9

5 files changed

Lines changed: 227 additions & 205 deletions

File tree

package/environments/base.js

Lines changed: 104 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,114 @@
1-
"use strict";
21
/* eslint global-require: 0 */
32
/* eslint import/no-dynamic-require: 0 */
4-
const { basename, dirname, join, relative, resolve } = require("path");
5-
const { existsSync, readdirSync } = require("fs");
6-
const extname = require("path-complete-extname");
7-
const config = require("../config");
8-
const { isProduction } = require("../env");
9-
const pluginsPath = resolve(__dirname, "..", "plugins", `${config.assets_bundler}.js`);
10-
const { getPlugins } = require(pluginsPath);
11-
const rulesPath = resolve(__dirname, "..", "rules", `${config.assets_bundler}.js`);
12-
const rules = require(rulesPath);
3+
const { basename, dirname, join, relative, resolve } = require("path")
4+
const { existsSync, readdirSync } = require("fs")
5+
const extname = require("path-complete-extname")
6+
const config = require("../config")
7+
const { isProduction } = require("../env")
8+
const pluginsPath = resolve(
9+
__dirname,
10+
"..",
11+
"plugins",
12+
`${config.assets_bundler}.js`
13+
)
14+
const { getPlugins } = require(pluginsPath)
15+
const rulesPath = resolve(
16+
__dirname,
17+
"..",
18+
"rules",
19+
`${config.assets_bundler}.js`
20+
)
21+
const rules = require(rulesPath)
1322
// Don't use contentHash except for production for performance
1423
// https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
15-
const hash = isProduction || config.useContentHash ? "-[contenthash]" : "";
24+
const hash = isProduction || config.useContentHash ? "-[contenthash]" : ""
1625
const getFilesInDirectory = (dir, includeNested) => {
17-
if (!existsSync(dir)) {
18-
return [];
26+
if (!existsSync(dir)) {
27+
return []
28+
}
29+
return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
30+
const filePath = join(dir, dirent.name)
31+
if (dirent.isDirectory() && includeNested) {
32+
return getFilesInDirectory(filePath, includeNested)
1933
}
20-
return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
21-
const filePath = join(dir, dirent.name);
22-
if (dirent.isDirectory() && includeNested) {
23-
return getFilesInDirectory(filePath, includeNested);
24-
}
25-
if (dirent.isFile()) {
26-
return filePath;
27-
}
28-
return [];
29-
});
30-
};
34+
if (dirent.isFile()) {
35+
return filePath
36+
}
37+
return []
38+
})
39+
}
3140
const getEntryObject = () => {
32-
const entries = {};
33-
const rootPath = join(config.source_path, config.source_entry_path);
34-
if (config.source_entry_path === "/" && config.nested_entries) {
35-
throw new Error(`Invalid Shakapacker configuration detected!\n\n` +
36-
`You have set source_entry_path to '/' with nested_entries enabled.\n` +
37-
`This would create webpack entry points for EVERY file in your source directory,\n` +
38-
`which would severely impact build performance.\n\n` +
39-
`To fix this issue, either:\n` +
40-
`1. Set 'nested_entries: false' in your shakapacker.yml\n` +
41-
`2. Change 'source_entry_path' to a specific subdirectory (e.g., 'packs')\n` +
42-
`3. Or use both options for better organization of your entry points`);
41+
const entries = {}
42+
const rootPath = join(config.source_path, config.source_entry_path)
43+
if (config.source_entry_path === "/" && config.nested_entries) {
44+
throw new Error(
45+
`Invalid Shakapacker configuration detected!\n\n` +
46+
`You have set source_entry_path to '/' with nested_entries enabled.\n` +
47+
`This would create webpack entry points for EVERY file in your source directory,\n` +
48+
`which would severely impact build performance.\n\n` +
49+
`To fix this issue, either:\n` +
50+
`1. Set 'nested_entries: false' in your shakapacker.yml\n` +
51+
`2. Change 'source_entry_path' to a specific subdirectory (e.g., 'packs')\n` +
52+
`3. Or use both options for better organization of your entry points`
53+
)
54+
}
55+
getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
56+
const namespace = relative(join(rootPath), dirname(path))
57+
const name = join(namespace, basename(path, extname(path)))
58+
const assetPath = resolve(path)
59+
// Allows for multiple filetypes per entry (https://webpack.js.org/guides/entry-advanced/)
60+
// Transforms the config object value to an array with all values under the same name
61+
const previousPaths = entries[name]
62+
if (previousPaths) {
63+
const pathArray = Array.isArray(previousPaths)
64+
? previousPaths
65+
: [previousPaths]
66+
pathArray.push(assetPath)
67+
entries[name] = pathArray
68+
} else {
69+
entries[name] = assetPath
4370
}
44-
getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
45-
const namespace = relative(join(rootPath), dirname(path));
46-
const name = join(namespace, basename(path, extname(path)));
47-
const assetPath = resolve(path);
48-
// Allows for multiple filetypes per entry (https://webpack.js.org/guides/entry-advanced/)
49-
// Transforms the config object value to an array with all values under the same name
50-
const previousPaths = entries[name];
51-
if (previousPaths) {
52-
const pathArray = Array.isArray(previousPaths)
53-
? previousPaths
54-
: [previousPaths];
55-
pathArray.push(assetPath);
56-
entries[name] = pathArray;
57-
}
58-
else {
59-
entries[name] = assetPath;
60-
}
61-
});
62-
return entries;
63-
};
71+
})
72+
return entries
73+
}
6474
const getModulePaths = () => {
65-
const result = [resolve(config.source_path)];
66-
if (config.additional_paths) {
67-
config.additional_paths.forEach((path) => result.push(resolve(path)));
68-
}
69-
result.push("node_modules");
70-
return result;
71-
};
75+
const result = [resolve(config.source_path)]
76+
if (config.additional_paths) {
77+
config.additional_paths.forEach((path) => result.push(resolve(path)))
78+
}
79+
result.push("node_modules")
80+
return result
81+
}
7282
const baseConfig = {
73-
mode: "production",
74-
output: {
75-
filename: `js/[name]${hash}.js`,
76-
chunkFilename: `js/[name]${hash}.chunk.js`,
77-
// https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
78-
hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
79-
path: config.outputPath,
80-
publicPath: config.publicPath,
81-
// This is required for SRI to work.
82-
crossOriginLoading: config.integrity && config.integrity.enabled
83-
? config.integrity.cross_origin
84-
: false
85-
},
86-
entry: getEntryObject(),
87-
resolve: {
88-
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
89-
modules: getModulePaths()
90-
},
91-
plugins: getPlugins(),
92-
resolveLoader: {
93-
modules: ["node_modules"]
94-
},
95-
optimization: {
96-
splitChunks: { chunks: "all" },
97-
runtimeChunk: "single"
98-
},
99-
module: {
100-
rules
101-
}
102-
};
103-
module.exports = baseConfig;
83+
mode: "production",
84+
output: {
85+
filename: `js/[name]${hash}.js`,
86+
chunkFilename: `js/[name]${hash}.chunk.js`,
87+
// https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
88+
hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
89+
path: config.outputPath,
90+
publicPath: config.publicPath,
91+
// This is required for SRI to work.
92+
crossOriginLoading:
93+
config.integrity && config.integrity.enabled
94+
? config.integrity.cross_origin
95+
: false
96+
},
97+
entry: getEntryObject(),
98+
resolve: {
99+
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
100+
modules: getModulePaths()
101+
},
102+
plugins: getPlugins(),
103+
resolveLoader: {
104+
modules: ["node_modules"]
105+
},
106+
optimization: {
107+
splitChunks: { chunks: "all" },
108+
runtimeChunk: "single"
109+
},
110+
module: {
111+
rules
112+
}
113+
}
114+
module.exports = baseConfig
Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,75 @@
1-
"use strict";
21
/**
32
* Development environment configuration for webpack and rspack bundlers
43
* @module environments/development
54
*/
6-
Object.defineProperty(exports, "__esModule", { value: true });
7-
const { merge } = require("webpack-merge");
8-
const config = require("../config");
9-
const baseConfig = require("./base");
10-
const webpackDevServerConfig = require("../webpackDevServerConfig");
11-
const { runningWebpackDevServer } = require("../env");
12-
const { moduleExists } = require("../utils/helpers");
5+
Object.defineProperty(exports, "__esModule", { value: true })
6+
const { merge } = require("webpack-merge")
7+
const config = require("../config")
8+
const baseConfig = require("./base")
9+
const webpackDevServerConfig = require("../webpackDevServerConfig")
10+
const { runningWebpackDevServer } = require("../env")
11+
const { moduleExists } = require("../utils/helpers")
1312
/**
1413
* Base development configuration shared between webpack and rspack
1514
*/
1615
const baseDevConfig = {
17-
mode: "development",
18-
devtool: "cheap-module-source-map"
19-
};
16+
mode: "development",
17+
devtool: "cheap-module-source-map"
18+
}
2019
/**
2120
* Generate webpack-specific development configuration
2221
* @returns Webpack configuration with dev server settings
2322
*/
2423
const webpackDevConfig = () => {
25-
const webpackConfig = {
26-
...baseDevConfig,
27-
...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
28-
};
29-
const devServerConfig = webpackDevServerConfig();
30-
if (runningWebpackDevServer &&
31-
devServerConfig.hot &&
32-
moduleExists("@pmmmwh/react-refresh-webpack-plugin")) {
33-
// eslint-disable-next-line global-require
34-
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
35-
webpackConfig.plugins = [
36-
...(webpackConfig.plugins || []),
37-
new ReactRefreshWebpackPlugin()
38-
];
39-
}
40-
return webpackConfig;
41-
};
24+
const webpackConfig = {
25+
...baseDevConfig,
26+
...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
27+
}
28+
const devServerConfig = webpackDevServerConfig()
29+
if (
30+
runningWebpackDevServer &&
31+
devServerConfig.hot &&
32+
moduleExists("@pmmmwh/react-refresh-webpack-plugin")
33+
) {
34+
// eslint-disable-next-line global-require
35+
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin")
36+
webpackConfig.plugins = [
37+
...(webpackConfig.plugins || []),
38+
new ReactRefreshWebpackPlugin()
39+
]
40+
}
41+
return webpackConfig
42+
}
4243
/**
4344
* Generate rspack-specific development configuration
4445
* @returns Rspack configuration with dev server settings
4546
*/
4647
const rspackDevConfig = () => {
47-
const devServerConfig = webpackDevServerConfig();
48-
const rspackConfig = {
49-
...baseDevConfig,
50-
devServer: {
51-
...devServerConfig,
52-
devMiddleware: {
53-
...(devServerConfig.devMiddleware || {}),
54-
writeToDisk: (filePath) => !filePath.includes(".hot-update.")
55-
}
56-
}
57-
};
58-
if (runningWebpackDevServer &&
59-
devServerConfig.hot &&
60-
moduleExists("@rspack/plugin-react-refresh")) {
61-
// eslint-disable-next-line global-require
62-
const ReactRefreshPlugin = require("@rspack/plugin-react-refresh");
63-
rspackConfig.plugins = [
64-
...(rspackConfig.plugins || []),
65-
new ReactRefreshPlugin()
66-
];
48+
const devServerConfig = webpackDevServerConfig()
49+
const rspackConfig = {
50+
...baseDevConfig,
51+
devServer: {
52+
...devServerConfig,
53+
devMiddleware: {
54+
...(devServerConfig.devMiddleware || {}),
55+
writeToDisk: (filePath) => !filePath.includes(".hot-update.")
56+
}
6757
}
68-
return rspackConfig;
69-
};
70-
const bundlerConfig = config.assets_bundler === "rspack" ? rspackDevConfig() : webpackDevConfig();
71-
module.exports = merge(baseConfig, bundlerConfig);
58+
}
59+
if (
60+
runningWebpackDevServer &&
61+
devServerConfig.hot &&
62+
moduleExists("@rspack/plugin-react-refresh")
63+
) {
64+
// eslint-disable-next-line global-require
65+
const ReactRefreshPlugin = require("@rspack/plugin-react-refresh")
66+
rspackConfig.plugins = [
67+
...(rspackConfig.plugins || []),
68+
new ReactRefreshPlugin()
69+
]
70+
}
71+
return rspackConfig
72+
}
73+
const bundlerConfig =
74+
config.assets_bundler === "rspack" ? rspackDevConfig() : webpackDevConfig()
75+
module.exports = merge(baseConfig, bundlerConfig)

0 commit comments

Comments
 (0)