bito-code-review[bot] commented on code in PR #44459:
URL: https://github.com/apache/superset/pull/44459#discussion_r4056642872
##########
superset-frontend/webpack.config.js:
##########
@@ -65,700 +61,709 @@ const ROOT_DIR = path.resolve(__dirname, '..');
// any url prefix.
const MINI_CSS_EXTRACT_PUBLICPATH = './';
-const {
- mode = 'development',
- devserverPort: cliPort,
- devserverHost: cliHost,
- measure = false,
- nameChunks = false,
-} = parsedArgs;
-
-// Precedence: CLI args > env vars > defaults
-const devserverPort = cliPort || process.env.WEBPACK_DEVSERVER_PORT || 9000;
-const devserverHost =
- cliHost || process.env.WEBPACK_DEVSERVER_HOST || '127.0.0.1';
-
-const isDevMode = mode !== 'production';
-const isDevServer = process.argv[1]?.includes('webpack-dev-server') ?? false;
-
-// TypeScript checker memory limit (in MB)
-const TYPESCRIPT_MEMORY_LIMIT = 8192;
-
-const defaultEntryFilename = isDevMode
- ? '[name].[contenthash:8].entry.js'
- : nameChunks
- ? '[name].[chunkhash].entry.js'
- : '[name].[chunkhash].entry.js';
-
-const defaultChunkFilename = isDevMode
- ? '[name].[contenthash:8].chunk.js'
- : nameChunks
- ? '[name].[chunkhash].chunk.js'
- : '[chunkhash].chunk.js';
-
-const output = {
- path: BUILD_DIR,
- publicPath: '/static/assets/',
- filename: pathData =>
- pathData.chunk?.name === 'service-worker'
- ? '../service-worker.js'
- : defaultEntryFilename,
- chunkFilename: pathData =>
- pathData.chunk?.name === 'service-worker'
- ? '../service-worker.js'
- : defaultChunkFilename,
-};
+const generateWebpackConfigWithCustomInputs = (env, args) => {
+ const {
+ devserverPort: cliPort,
+ devserverHost: cliHost,
+ measure = false,
+ nameChunks = false,
+ } = env;
+ const { mode } = args;
+
+ // Precedence: CLI args > env vars > defaults
+ const devserverPort = cliPort || process.env.WEBPACK_DEVSERVER_PORT || 9000;
+ const devserverHost =
+ cliHost || process.env.WEBPACK_DEVSERVER_HOST || '127.0.0.1';
+
+ const isDevMode = mode !== 'production';
+ const isDevServer = process.argv[1]?.includes('webpack-dev-server') ?? false;
+
+ // TypeScript checker memory limit (in MB)
+ const TYPESCRIPT_MEMORY_LIMIT = 8192;
+
+ const defaultEntryFilename = isDevMode
+ ? '[name].[contenthash:8].entry.js'
+ : nameChunks
+ ? '[name].[chunkhash].entry.js'
+ : '[name].[chunkhash].entry.js';
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Redundant identical ternary branch</b></div>
<div id="fix">
In `defaultEntryFilename`, both branches of the `nameChunks ? ... : ...`
ternary return the identical string `'[name].[chunkhash].entry.js'`, so
`nameChunks` is a no-op here. This is dead/redundant logic — likely a
copy-paste from `defaultChunkFilename` (which correctly varies
`[name]`/`[chunkhash]`). Collapse the ternary or fix the non-`nameChunks`
branch to match intent.
</div>
</div>
<small><i>Code Review Run #c5c682</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset-frontend/scripts/build.js:
##########
@@ -26,13 +26,22 @@
import { spawnSync } from 'node:child_process';
import fastGlob from 'fast-glob';
-import yargs from 'yargs';
-import { hideBin } from 'yargs/helpers';
+import { parseArgs } from 'node:util';
process.env.PATH = `./node_modules/.bin:${process.env.PATH}`;
-const { globs } = yargs(hideBin(process.argv)).parse();
-const glob = globs?.length > 1 ? `{${globs.join(',')}}` : globs?.[0] || '*';
+const cliOptions = {
+ globs: {
+ type: 'string',
+ multiple: true,
+ default: ['*'],
+ },
+};
+
+const { values } = parseArgs({ options: cliOptions });
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>CLI arg parse crash</b></div>
<div id="fix">
`parseArgs` defaults to `strict: true`, so any unknown option (e.g.
`--verbose`) or positional arg (e.g. `--globs chart table`) now throws `Unknown
option`/`Unexpected argument` at module scope, crashing the whole build. The
old `yargs` parser tolerated both. Add `strict: false` to preserve prior
behavior.
</div>
</div>
<small><i>Code Review Run #c5c682</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]