From 41914d29614ddf5a59c7c223e5575ee910b8343e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Tue, 22 Mar 2022 22:39:42 +0100 Subject: [PATCH] fix(web): ensure file server works on windows (#9449) --- .../src/executors/file-server/file-server.impl.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/web/src/executors/file-server/file-server.impl.ts b/packages/web/src/executors/file-server/file-server.impl.ts index 493b705589fe5..c30ccf5b79148 100644 --- a/packages/web/src/executors/file-server/file-server.impl.ts +++ b/packages/web/src/executors/file-server/file-server.impl.ts @@ -5,6 +5,10 @@ import { readFileSync } from 'fs'; import { Schema } from './schema'; import { watch } from 'chokidar'; import { workspaceLayout } from '@nrwl/workspace/src/core/file-utils'; +import { platform } from 'os'; + +// platform specific command name +const pmCmd = platform() === 'win32' ? `npx.cmd` : 'npx'; function getHttpServerArgs(options: Schema) { const args = ['-c-1']; @@ -36,7 +40,7 @@ function getHttpServerArgs(options: Schema) { } function getBuildTargetCommand(options: Schema) { - const cmd = ['npx', 'nx', 'run', options.buildTarget]; + const cmd = ['nx', 'run', options.buildTarget]; if (options.withDeps) { cmd.push(`--with-deps`); } @@ -115,8 +119,8 @@ export default async function* fileServerExecutor( if (!running) { running = true; try { - const [cmd, ...args] = getBuildTargetCommand(options); - execFileSync(cmd, args, { + const args = getBuildTargetCommand(options); + execFileSync(pmCmd, args, { stdio: [0, 1, 2], }); } catch {} @@ -132,7 +136,7 @@ export default async function* fileServerExecutor( const outputPath = getBuildTargetOutputPath(options, context); const args = getHttpServerArgs(options); - const serve = execFile('npx', ['http-server', outputPath, ...args], { + const serve = execFile(pmCmd, ['http-server', outputPath, ...args], { cwd: context.root, env: { FORCE_COLOR: 'true',