From a35c249fdc9c79ae6e3b6bb334a87780afac1246 Mon Sep 17 00:00:00 2001 From: Xiaoxing Ye Date: Sun, 30 Jan 2022 01:56:58 +0800 Subject: [PATCH] fix: quote path to prevent space issue (#11733) Co-authored-by: Xiaoxing Ye --- .../playwright-core/src/utils/registry.ts | 2 +- utils/build/build.js | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/playwright-core/src/utils/registry.ts b/packages/playwright-core/src/utils/registry.ts index 928286db45..cc5f9a9f9b 100644 --- a/packages/playwright-core/src/utils/registry.ts +++ b/packages/playwright-core/src/utils/registry.ts @@ -647,7 +647,7 @@ export class Registry { if (code !== 0) throw new Error(`Failed to install ${channel}`); } else { - const { command, args, elevatedPermissions } = await transformCommandsForRoot([`bash ${path.join(BIN_PATH, scriptName)} ${scriptArgs.join('')}`]); + const { command, args, elevatedPermissions } = await transformCommandsForRoot([`bash "${path.join(BIN_PATH, scriptName)}" ${scriptArgs.join('')}`]); if (elevatedPermissions) console.log('Switching to root user to install dependencies...'); // eslint-disable-line no-console const { code } = await spawnAsync(command, args, { cwd, stdio: 'inherit' }); diff --git a/utils/build/build.js b/utils/build/build.js index 78d770d913..22c4cd2602 100644 --- a/utils/build/build.js +++ b/utils/build/build.js @@ -62,13 +62,21 @@ const lintMode = process.argv.slice(2).includes('--lint'); const ROOT = path.join(__dirname, '..', '..'); /** - * @param {string} relative + * @param {string} relative * @returns {string} */ function filePath(relative) { return path.join(ROOT, ...relative.split('/')); } +/** + * @param {string} path + * @returns {string} + */ +function quotePath(path) { + return "\"" + path + "\""; +} + async function runWatch() { function runOnChanges(paths, mustExist = [], nodeFile) { nodeFile = filePath(nodeFile); @@ -108,7 +116,7 @@ async function runWatch() { async function runBuild() { /** - * @param {Step} step + * @param {Step} step */ function runStep(step) { const out = child_process.spawnSync(step.command, step.args, { @@ -143,9 +151,9 @@ async function runBuild() { } /** - * @param {string} file - * @param {string} from - * @param {string} to + * @param {string} file + * @param {string} from + * @param {string} to */ function copyFile(file, from, to) { const destination = path.resolve(filePath(to), path.relative(filePath(from), file)); @@ -172,7 +180,7 @@ const webPackFiles = [ for (const file of webPackFiles) { steps.push({ command: 'npx', - args: ['webpack', '--config', filePath(file), ...(watchMode ? ['--watch', '--stats', 'none'] : [])], + args: ['webpack', '--config', quotePath(filePath(file)), ...(watchMode ? ['--watch', '--stats', 'none'] : [])], shell: true, env: { NODE_ENV: watchMode ? 'development' : 'production' @@ -190,9 +198,9 @@ for (const packageDir of packages) { 'babel', ...(watchMode ? ['-w', '--source-maps'] : []), '--extensions', '.ts', - '--out-dir', path.join(packageDir, 'lib'), + '--out-dir', quotePath(path.join(packageDir, 'lib')), '--ignore', '"packages/playwright-core/src/server/injected/**/*"', - path.join(packageDir, 'src')], + quotePath(path.join(packageDir, 'src'))], shell: true, }); } @@ -263,7 +271,7 @@ if (lintMode) { // Run TypeScript for type chekcing. steps.push({ command: 'npx', - args: ['tsc', ...(watchMode ? ['-w'] : []), '-p', filePath('.')], + args: ['tsc', ...(watchMode ? ['-w'] : []), '-p', quotePath(filePath('.'))], shell: true, }); }