Skip to content

Commit d46336d

Browse files
committed
Centralize sanitizeInput logic in buildScripts/util/Sanitizer.mjs #7992
1 parent 511eb52 commit d46336d

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

buildScripts/buildAll.mjs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import chalk from 'chalk';
2-
import {spawnSync} from 'child_process';
3-
import {Command} from 'commander/esm.mjs';
4-
import envinfo from 'envinfo';
5-
import fs from 'fs-extra';
6-
import inquirer from 'inquirer';
7-
import os from 'os';
8-
import path from 'path';
1+
import chalk from 'chalk';
2+
import {spawnSync} from 'child_process';
3+
import {Command} from 'commander/esm.mjs';
4+
import envinfo from 'envinfo';
5+
import fs from 'fs-extra';
6+
import inquirer from 'inquirer';
7+
import os from 'os';
8+
import path from 'path';
9+
import {sanitizeInput} from './util/Sanitizer.mjs';
10+
911

1012
const __dirname = path.resolve(),
1113
cwd = process.cwd(),
@@ -18,13 +20,7 @@ const __dirname = path.resolve(),
1820
neoPath = path.resolve(packageJson.name.includes('neo.mjs') ? './' : './node_modules/neo.mjs/'),
1921
webpackPath = path.resolve(neoPath, 'buildScripts/webpack'),
2022
programName = `${packageJson.name} buildAll`,
21-
questions = [],
22-
sanitizeInput = value => {
23-
if (typeof value === 'string') {
24-
return value.replace(/^["']|["']$/g, '').trim();
25-
}
26-
return value;
27-
};
23+
questions = [];
2824

2925
program
3026
.name(programName)

buildScripts/util/Sanitizer.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Sanitizes command line input values by removing surrounding quotes and trimming whitespace.
3+
* This is useful when users wrap their arguments in quotes (e.g. --env "dev").
4+
*
5+
* @param {String|*} value The input value to sanitize
6+
* @returns {String|*} The sanitized value
7+
*/
8+
export const sanitizeInput = value => {
9+
if (typeof value === 'string') {
10+
return value.replace(/^["']|["']$/g, '').trim();
11+
}
12+
return value;
13+
};

0 commit comments

Comments
 (0)