Skip to content

Commit 6649869

Browse files
AgentEnderFrozenPandaz
authored andcommitted
fix(core): show project --web shouldn't error (#23251)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 5542350)
1 parent 534b24b commit 6649869

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed

docs/generated/cli/show.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ Type: `boolean`
205205

206206
Show help
207207

208+
##### open
209+
210+
Type: `boolean`
211+
212+
Set to false to prevent the browser from opening when using --web
213+
208214
##### projectName
209215

210216
Type: `string`

docs/generated/packages/nx/documents/show.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ Type: `boolean`
205205

206206
Show help
207207

208+
##### open
209+
210+
Type: `boolean`
211+
212+
Set to false to prevent the browser from opening when using --web
213+
208214
##### projectName
209215

210216
Type: `string`

e2e/nx/src/misc.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import {
66
getPackageManagerCommand,
77
getPublishedVersion,
88
isNotWindows,
9+
killProcessAndPorts,
910
newProject,
1011
readFile,
1112
readJson,
1213
removeFile,
1314
runCLI,
1415
runCLIAsync,
1516
runCommand,
17+
runCommandUntil,
1618
tmpProjPath,
1719
uniq,
1820
updateFile,
@@ -73,6 +75,33 @@ describe('Nx Commands', () => {
7375
expect(project.targets.build).toBeDefined();
7476
expect(project.targets.lint).toBeDefined();
7577
});
78+
79+
it('should open project details view', async () => {
80+
const app = uniq('myapp');
81+
runCLI(`generate @nx/web:app ${app}`);
82+
let url: string;
83+
let port: number;
84+
const child_process = await runCommandUntil(
85+
`show project ${app} --web --open=false`,
86+
(output) => {
87+
console.log(output);
88+
// output should contain 'Project graph started at http://127.0.0.1:{port}'
89+
if (output.includes('Project graph started at http://')) {
90+
const match = /https?:\/\/[\d.]+:(?<port>\d+)/.exec(output);
91+
if (match) {
92+
port = parseInt(match.groups.port);
93+
url = match[0];
94+
return true;
95+
}
96+
}
97+
return false;
98+
}
99+
);
100+
// Check that url is alive
101+
const response = await fetch(url);
102+
expect(response.status).toEqual(200);
103+
await killProcessAndPorts(child_process.pid, port);
104+
}, 700000);
76105
});
77106

78107
describe('report and list', () => {

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
"prepare": "is-ci || husky install",
2121
"echo": "echo 123458",
2222
"preinstall": "node ./scripts/preinstall.js",
23-
"test": "nx test",
24-
"e2e": "nx e2e",
25-
"build-project": "nx build"
23+
"test": "nx run-many -t test",
24+
"e2e": "nx run-many -t e2e --projects ./e2e/*"
2625
},
2726
"devDependencies": {
2827
"@actions/core": "^1.10.0",

packages/nx/src/command-line/show/command-object.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export type ShowProjectsOptions = NxShowArgs & {
2929
export type ShowProjectOptions = NxShowArgs & {
3030
projectName: string;
3131
web?: boolean;
32-
verbose: boolean;
32+
open?: boolean;
33+
verbose?: boolean;
3334
};
3435

3536
export const yargsShowCommand: CommandModule<
@@ -138,7 +139,7 @@ const showProjectCommand: CommandModule<NxShowArgs, ShowProjectOptions> = {
138139
command: 'project <projectName>',
139140
describe: 'Shows resolved project configuration for a given project.',
140141
builder: (yargs) =>
141-
yargs
142+
withVerbose(yargs)
142143
.positional('projectName', {
143144
type: 'string',
144145
alias: 'p',
@@ -149,13 +150,18 @@ const showProjectCommand: CommandModule<NxShowArgs, ShowProjectOptions> = {
149150
type: 'boolean',
150151
description: 'Show project details in the browser',
151152
})
152-
.option('verbose', {
153+
.option('open', {
153154
type: 'boolean',
154155
description:
155-
'Prints additional information about the commands (e.g., stack traces)',
156+
'Set to false to prevent the browser from opening when using --web',
157+
implies: 'web',
158+
})
159+
.check((argv) => {
160+
if (argv.web) {
161+
argv.json = false;
162+
}
163+
return true;
156164
})
157-
.conflicts('json', 'web')
158-
.conflicts('web', 'json')
159165
.example(
160166
'$0 show project my-app',
161167
'View project information for my-app in JSON format'

packages/nx/src/command-line/show/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function showProjectHandler(
2020
view: 'project-details',
2121
focus: node.name,
2222
watch: true,
23-
open: true,
23+
open: args.open ?? true,
2424
},
2525
[]
2626
);

0 commit comments

Comments
 (0)