Skip to content

Commit

Permalink
feat(web): support buildTarget that excludes project name (#20508)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Nov 30, 2023
1 parent 1692a54 commit 2d529b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions e2e/web/src/file-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe('file-server', () => {
setMaxWorkers(join('apps', appName, 'project.json'));
updateJson(join('apps', appName, 'project.json'), (config) => {
config.targets['serve'].executor = '@nx/web:file-server';
// Check that buildTarget can exclude project name (e.g. build vs proj:build).
config.targets['serve'].options.buildTarget = 'build';
return config;
});

Expand Down
14 changes: 11 additions & 3 deletions packages/web/src/executors/file-server/file-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ function getHttpServerArgs(options: Schema) {
return args;
}

function getBuildTargetCommand(options: Schema) {
const cmd = ['nx', 'run', options.buildTarget];
function getBuildTargetCommand(options: Schema, context: ExecutorContext) {
const target = parseTargetString(options.buildTarget, context);
const cmd = ['nx', 'run'];

if (target.configuration) {
cmd.push(`${target.project}:${target.target}:${target.configuration}`);
} else {
cmd.push(`${target.project}:${target.target}`);
}

if (options.parallel) {
cmd.push(`--parallel`);
}
Expand Down Expand Up @@ -131,7 +139,7 @@ export default async function* fileServerExecutor(
if (!running) {
running = true;
try {
const args = getBuildTargetCommand(options);
const args = getBuildTargetCommand(options, context);
execFileSync(pmCmd, args, {
stdio: [0, 1, 2],
});
Expand Down

0 comments on commit 2d529b1

Please sign in to comment.