Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web): ensure file server works on windows #9449

Merged
merged 1 commit into from Mar 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/web/src/executors/file-server/file-server.impl.ts
Expand Up @@ -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'];
Expand Down Expand Up @@ -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`);
}
Expand Down Expand Up @@ -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 {}
Expand All @@ -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',
Expand Down