diff --git a/graph/ui-project-details/src/lib/show-all-options/show-all-options.tsx b/graph/ui-project-details/src/lib/show-all-options/show-all-options.tsx
index 403b9bc91a7e44..6b629497212a5b 100644
--- a/graph/ui-project-details/src/lib/show-all-options/show-all-options.tsx
+++ b/graph/ui-project-details/src/lib/show-all-options/show-all-options.tsx
@@ -1,7 +1,8 @@
-import { Fragment, useState } from 'react';
+import { Fragment, useMemo, useState } from 'react';
import { PlayIcon, XMarkIcon } from '@heroicons/react/24/outline';
import { Transition } from '@headlessui/react';
import { getExternalApiService, useEnvironmentConfig } from '@nx/graph/shared';
+/* eslint-disable @nx/enforce-module-boundaries */
// nx-ignore-next-line
import type { TargetConfiguration } from '@nx/devkit';
import { TerminalOutput } from '@nx/nx-dev/ui-fence';
@@ -14,21 +15,12 @@ interface ShowAllOptionsProps {
targetConfiguration: TargetConfiguration;
}
-const projectJsonViteHelpText = `{
- "targets": {
- "serve": {
- "options": {
- "open": "true",
- "port": 5000
- }
- },
- "test": {
- "options": {
- "args": ["run"]
- }
- }
- }
-}`;
+const fallbackHelpExample = {
+ options: {
+ silent: true,
+ },
+ args: ['foo'],
+};
export function ShowAllOptions({
projectName,
@@ -36,11 +28,17 @@ export function ShowAllOptions({
targetConfiguration,
}: ShowAllOptionsProps) {
const environment = useEnvironmentConfig()?.environment;
- const [result, setResult] = useState(null);
+ const [result, setResult] = useState<{
+ text: string;
+ success: boolean;
+ } | null>(null);
const [isPending, setPending] = useState(false);
const externalApiService = getExternalApiService();
- const helpCommand = targetConfiguration.metadata?.help?.command;
+ const helpData = targetConfiguration.metadata?.help;
+ const helpCommand = helpData?.command;
+ const helpExampleOptions = helpData?.example?.options;
+ const helpExampleArgs = helpData?.example?.args;
const runHelpCommand =
environment === 'nx-console'
@@ -56,7 +54,7 @@ export function ShowAllOptions({
}
: async () => {
setPending(true);
- const { result } = await fetch(
+ const result = await fetch(
`/help?project=${encodeURIComponent(
projectName
)}&target=${encodeURIComponent(targetName)}`
@@ -65,18 +63,24 @@ export function ShowAllOptions({
setPending(false);
};
- const openProjectConfig =
- environment === 'nx-console'
- ? () => {
- externalApiService.postEvent({
- type: 'open-project-config',
- payload: {
- projectName,
- targetName,
- },
- });
- }
- : null;
+ const helpExampleTest = useMemo(() => {
+ const targetExampleJson =
+ helpExampleOptions || helpExampleArgs
+ ? {
+ options: helpExampleOptions,
+ args: helpExampleArgs,
+ }
+ : fallbackHelpExample;
+ return JSON.stringify(
+ {
+ targets: {
+ [targetName]: targetExampleJson,
+ },
+ },
+ null,
+ 2
+ );
+ }, [helpExampleOptions, helpExampleArgs]);
return (
helpCommand && (
@@ -98,24 +102,30 @@ export function ShowAllOptions({
(
- For example, when using @nx/vite/plugin
, the
- following are options and args passed to serve
{' '}
- and test
targets, which are then passed to the{' '}
- vite
and{' '}
- vitest
CLI
- respectively.
+ For example, you can use the following configuration for the{' '}
+ {targetName}
target in the{' '}
+ project.json
file for{' '}
+ {projectName} .
- {projectJsonViteHelpText}
+ {helpExampleTest}
-
- This configuration means serve
runs{' '}
-
- vite --port=5000 --open
-
- , and test
runs{' '}
- vitest run
.
-
+ {helpExampleOptions && (
+
+ The options
are CLI options prefixed by{' '}
+ --
, such as ls --color=never
,
+ where you would use {'"color": "never"'}
to
+ set it in the target configuration.
+
+ )}
+ {helpExampleArgs && (
+
+ The args
are CLI positional arguments, such
+ as ls somedir
, where you would use{' '}
+ {'"args": ["somedir"]'}
to set it in the
+ target configuration.
+
+ )}
) as any
}
@@ -161,21 +171,15 @@ export function ShowAllOptions({
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1"
>
- {result}
+
+ {result?.text}
+
}
/>
- {openProjectConfig && (
-
-
- Edit in project.json
-
-
- )}
>
)
);
diff --git a/nx-dev/ui-fence/src/lib/fences/terminal-output.tsx b/nx-dev/ui-fence/src/lib/fences/terminal-output.tsx
index 6391069afbbc68..d001690788d42e 100644
--- a/nx-dev/ui-fence/src/lib/fences/terminal-output.tsx
+++ b/nx-dev/ui-fence/src/lib/fences/terminal-output.tsx
@@ -32,7 +32,7 @@ export function TerminalOutput({
{line}
{actionElement ? (
- {actionElement}
+ {actionElement}
) : null}
);
diff --git a/packages/cypress/src/plugins/plugin.spec.ts b/packages/cypress/src/plugins/plugin.spec.ts
index fc811af05478be..3cbbd4168a8bb5 100644
--- a/packages/cypress/src/plugins/plugin.spec.ts
+++ b/packages/cypress/src/plugins/plugin.spec.ts
@@ -101,6 +101,15 @@ describe('@nx/cypress/plugin', () => {
],
"metadata": {
"description": "Runs Cypress Tests",
+ "example": {
+ "command": "npx cypress run --help",
+ "example": {
+ "args": [
+ "--dev",
+ "--headed",
+ ],
+ },
+ },
"technologies": [
"cypress",
],
@@ -117,6 +126,15 @@ describe('@nx/cypress/plugin', () => {
"command": "cypress open",
"metadata": {
"description": "Opens Cypress",
+ "example": {
+ "command": "npx cypress open --help",
+ "example": {
+ "args": [
+ "--dev",
+ "--e2e",
+ ],
+ },
+ },
"technologies": [
"cypress",
],
@@ -179,6 +197,15 @@ describe('@nx/cypress/plugin', () => {
],
"metadata": {
"description": "Runs Cypress Component Tests",
+ "example": {
+ "command": "npx cypress run --help",
+ "example": {
+ "args": [
+ "--dev",
+ "--headed",
+ ],
+ },
+ },
"technologies": [
"cypress",
],
@@ -195,6 +222,15 @@ describe('@nx/cypress/plugin', () => {
"command": "cypress open",
"metadata": {
"description": "Opens Cypress",
+ "example": {
+ "command": "npx cypress open --help",
+ "example": {
+ "args": [
+ "--dev",
+ "--e2e",
+ ],
+ },
+ },
"technologies": [
"cypress",
],
@@ -273,6 +309,15 @@ describe('@nx/cypress/plugin', () => {
],
"metadata": {
"description": "Runs Cypress Tests",
+ "example": {
+ "command": "npx cypress run --help",
+ "example": {
+ "args": [
+ "--dev",
+ "--headed",
+ ],
+ },
+ },
"technologies": [
"cypress",
],
@@ -306,6 +351,15 @@ describe('@nx/cypress/plugin', () => {
],
"metadata": {
"description": "Runs Cypress Tests in CI",
+ "example": {
+ "command": "npx cypress run --help",
+ "example": {
+ "args": [
+ "--dev",
+ "--headed",
+ ],
+ },
+ },
"technologies": [
"cypress",
],
@@ -329,6 +383,15 @@ describe('@nx/cypress/plugin', () => {
],
"metadata": {
"description": "Runs Cypress Tests in src/test.cy.ts in CI",
+ "example": {
+ "command": "npx cypress run --help",
+ "example": {
+ "args": [
+ "--dev",
+ "--headed",
+ ],
+ },
+ },
"technologies": [
"cypress",
],
@@ -345,6 +408,15 @@ describe('@nx/cypress/plugin', () => {
"command": "cypress open",
"metadata": {
"description": "Opens Cypress",
+ "example": {
+ "command": "npx cypress open --help",
+ "example": {
+ "args": [
+ "--dev",
+ "--e2e",
+ ],
+ },
+ },
"technologies": [
"cypress",
],
diff --git a/packages/cypress/src/plugins/plugin.ts b/packages/cypress/src/plugins/plugin.ts
index 45c0582fa6d940..2d21b2b17d18e3 100644
--- a/packages/cypress/src/plugins/plugin.ts
+++ b/packages/cypress/src/plugins/plugin.ts
@@ -4,6 +4,7 @@ import {
createNodesFromFiles,
CreateNodesV2,
detectPackageManager,
+ getPackageManagerCommand,
joinPathFragments,
logger,
normalizePath,
@@ -183,6 +184,7 @@ async function buildCypressTargets(
options: CypressPluginOptions,
context: CreateNodesContext
): Promise {
+ const pmc = getPackageManagerCommand();
const cypressConfig = await loadConfigFile(
join(context.workspaceRoot, configFilePath)
);
@@ -211,6 +213,12 @@ async function buildCypressTargets(
metadata: {
technologies: ['cypress'],
description: 'Runs Cypress Tests',
+ example: {
+ command: `${pmc.exec} cypress run --help`,
+ example: {
+ args: ['--dev', '--headed'],
+ },
+ },
},
};
@@ -270,6 +278,12 @@ async function buildCypressTargets(
metadata: {
technologies: ['cypress'],
description: `Runs Cypress Tests in ${relativeSpecFilePath} in CI`,
+ example: {
+ command: `${pmc.exec} cypress run --help`,
+ example: {
+ args: ['--dev', '--headed'],
+ },
+ },
},
};
dependsOn.push({
@@ -288,6 +302,12 @@ async function buildCypressTargets(
metadata: {
technologies: ['cypress'],
description: 'Runs Cypress Tests in CI',
+ example: {
+ command: `${pmc.exec} cypress run --help`,
+ example: {
+ args: ['--dev', '--headed'],
+ },
+ },
},
};
ciTargetGroup.push(options.ciTargetName);
@@ -305,6 +325,12 @@ async function buildCypressTargets(
metadata: {
technologies: ['cypress'],
description: 'Runs Cypress Component Tests',
+ example: {
+ command: `${pmc.exec} cypress run --help`,
+ example: {
+ args: ['--dev', '--headed'],
+ },
+ },
},
};
}
@@ -315,6 +341,12 @@ async function buildCypressTargets(
metadata: {
technologies: ['cypress'],
description: 'Opens Cypress',
+ example: {
+ command: `${pmc.exec} cypress open --help`,
+ example: {
+ args: ['--dev', '--e2e'],
+ },
+ },
},
};
diff --git a/packages/eslint/src/plugins/plugin.spec.ts b/packages/eslint/src/plugins/plugin.spec.ts
index fd04f0899eef5b..eea28f229cfb61 100644
--- a/packages/eslint/src/plugins/plugin.spec.ts
+++ b/packages/eslint/src/plugins/plugin.spec.ts
@@ -114,6 +114,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": ".",
},
@@ -155,6 +169,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": ".",
},
@@ -227,6 +255,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": "apps/my-app",
},
@@ -268,6 +310,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": "apps/my-app",
},
@@ -381,6 +437,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": "apps/my-app",
},
@@ -406,6 +476,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": "libs/my-lib",
},
@@ -491,6 +575,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": "apps/my-app",
},
@@ -517,6 +615,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": "libs/my-lib",
},
@@ -560,6 +672,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": "apps/myapp",
},
@@ -608,6 +734,20 @@ describe('@nx/eslint/plugin', () => {
],
},
],
+ "metadata": {
+ "description": "Runs ESLint on project",
+ "help": {
+ "command": "npx eslint --help",
+ "example": {
+ "options": {
+ "max-warnings": 0,
+ },
+ },
+ },
+ "technologies": [
+ "eslint",
+ ],
+ },
"options": {
"cwd": "apps/myapp/nested/mylib",
},
diff --git a/packages/eslint/src/plugins/plugin.ts b/packages/eslint/src/plugins/plugin.ts
index af8dbf3dc2c7e5..d186af6cf9e0a2 100644
--- a/packages/eslint/src/plugins/plugin.ts
+++ b/packages/eslint/src/plugins/plugin.ts
@@ -2,13 +2,13 @@ import {
CreateNodes,
CreateNodesContext,
CreateNodesContextV2,
+ createNodesFromFiles,
CreateNodesResult,
CreateNodesV2,
- TargetConfiguration,
- createNodesFromFiles,
getPackageManagerCommand,
logger,
readJsonFile,
+ TargetConfiguration,
writeJsonFile,
} from '@nx/devkit';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
@@ -20,9 +20,9 @@ import { combineGlobPatterns } from 'nx/src/utils/globs';
import { globWithWorkspaceContext } from 'nx/src/utils/workspace-context';
import { gte } from 'semver';
import {
- ESLINT_CONFIG_FILENAMES,
baseEsLintConfigFile,
baseEsLintFlatConfigFile,
+ ESLINT_CONFIG_FILENAMES,
isFlatConfig,
} from '../utils/config-file';
import { resolveESLintClass } from '../utils/resolve-eslint-class';
@@ -487,6 +487,11 @@ function buildEslintTargets(
description: 'Runs ESLint on project',
help: {
command: `${pmc.exec} eslint --help`,
+ example: {
+ options: {
+ 'max-warnings': 0,
+ },
+ },
},
},
};
diff --git a/packages/jest/src/plugins/__snapshots__/plugin.spec.ts.snap b/packages/jest/src/plugins/__snapshots__/plugin.spec.ts.snap
new file mode 100644
index 00000000000000..31745e4220588d
--- /dev/null
+++ b/packages/jest/src/plugins/__snapshots__/plugin.spec.ts.snap
@@ -0,0 +1,157 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`@nx/jest/plugin should add package as externalDependencies to the inputs when specified as preset and containing a jest-preset.cjs file 1`] = `
+[
+ [
+ "proj/jest.config.js",
+ {
+ "projects": {
+ "proj": {
+ "metadata": undefined,
+ "root": "proj",
+ "targets": {
+ "test": {
+ "cache": true,
+ "command": "jest",
+ "inputs": [
+ "default",
+ "^production",
+ {
+ "externalDependencies": [
+ "jest",
+ "some-package",
+ ],
+ },
+ ],
+ "metadata": {
+ "description": "Run Jest Tests",
+ "help": {
+ "command": "npx jest --help",
+ "example": {
+ "options": {
+ "coverage": true,
+ },
+ },
+ },
+ "technologies": [
+ "jest",
+ ],
+ },
+ "options": {
+ "cwd": "proj",
+ },
+ "outputs": [
+ "{workspaceRoot}/coverage",
+ ],
+ },
+ },
+ },
+ },
+ },
+ ],
+]
+`;
+
+exports[`@nx/jest/plugin should add package as externalDependencies to the inputs when specified as preset and containing a jest-preset.js file 1`] = `
+[
+ [
+ "proj/jest.config.js",
+ {
+ "projects": {
+ "proj": {
+ "metadata": undefined,
+ "root": "proj",
+ "targets": {
+ "test": {
+ "cache": true,
+ "command": "jest",
+ "inputs": [
+ "default",
+ "^production",
+ {
+ "externalDependencies": [
+ "jest",
+ "some-package",
+ ],
+ },
+ ],
+ "metadata": {
+ "description": "Run Jest Tests",
+ "help": {
+ "command": "npx jest --help",
+ "example": {
+ "options": {
+ "coverage": true,
+ },
+ },
+ },
+ "technologies": [
+ "jest",
+ ],
+ },
+ "options": {
+ "cwd": "proj",
+ },
+ "outputs": [
+ "{workspaceRoot}/coverage",
+ ],
+ },
+ },
+ },
+ },
+ },
+ ],
+]
+`;
+
+exports[`@nx/jest/plugin should add package as externalDependencies to the inputs when specified as preset and containing a jest-preset.json file 1`] = `
+[
+ [
+ "proj/jest.config.js",
+ {
+ "projects": {
+ "proj": {
+ "metadata": undefined,
+ "root": "proj",
+ "targets": {
+ "test": {
+ "cache": true,
+ "command": "jest",
+ "inputs": [
+ "default",
+ "^production",
+ {
+ "externalDependencies": [
+ "jest",
+ "some-package",
+ ],
+ },
+ ],
+ "metadata": {
+ "description": "Run Jest Tests",
+ "help": {
+ "command": "npx jest --help",
+ "example": {
+ "options": {
+ "coverage": true,
+ },
+ },
+ },
+ "technologies": [
+ "jest",
+ ],
+ },
+ "options": {
+ "cwd": "proj",
+ },
+ "outputs": [
+ "{workspaceRoot}/coverage",
+ ],
+ },
+ },
+ },
+ },
+ },
+ ],
+]
+`;
diff --git a/packages/jest/src/plugins/plugin.spec.ts b/packages/jest/src/plugins/plugin.spec.ts
index c2d606953c1006..726f179e12cb47 100644
--- a/packages/jest/src/plugins/plugin.spec.ts
+++ b/packages/jest/src/plugins/plugin.spec.ts
@@ -82,6 +82,14 @@ describe('@nx/jest/plugin', () => {
],
"metadata": {
"description": "Run Jest Tests",
+ "help": {
+ "command": "npx jest --help",
+ "example": {
+ "options": {
+ "coverage": true,
+ },
+ },
+ },
"technologies": [
"jest",
],
@@ -151,6 +159,14 @@ describe('@nx/jest/plugin', () => {
],
"metadata": {
"description": "Run Jest Tests",
+ "help": {
+ "command": "npx jest --help",
+ "example": {
+ "options": {
+ "coverage": true,
+ },
+ },
+ },
"technologies": [
"jest",
],
@@ -179,6 +195,14 @@ describe('@nx/jest/plugin', () => {
],
"metadata": {
"description": "Run Jest Tests in CI",
+ "help": {
+ "command": "npx jest --help",
+ "example": {
+ "options": {
+ "coverage": true,
+ },
+ },
+ },
"technologies": [
"jest",
],
@@ -201,6 +225,14 @@ describe('@nx/jest/plugin', () => {
],
"metadata": {
"description": "Run Jest Tests in src/unit.spec.ts",
+ "help": {
+ "command": "npx jest --help",
+ "example": {
+ "options": {
+ "coverage": true,
+ },
+ },
+ },
"technologies": [
"jest",
],
@@ -259,6 +291,14 @@ describe('@nx/jest/plugin', () => {
],
"metadata": {
"description": "Run Jest Tests",
+ "help": {
+ "command": "npx jest --help",
+ "example": {
+ "options": {
+ "coverage": true,
+ },
+ },
+ },
"technologies": [
"jest",
],
@@ -303,49 +343,7 @@ describe('@nx/jest/plugin', () => {
context
);
- expect(results).toMatchInlineSnapshot(`
- [
- [
- "proj/jest.config.js",
- {
- "projects": {
- "proj": {
- "metadata": undefined,
- "root": "proj",
- "targets": {
- "test": {
- "cache": true,
- "command": "jest",
- "inputs": [
- "default",
- "^production",
- {
- "externalDependencies": [
- "jest",
- "some-package",
- ],
- },
- ],
- "metadata": {
- "description": "Run Jest Tests",
- "technologies": [
- "jest",
- ],
- },
- "options": {
- "cwd": "proj",
- },
- "outputs": [
- "{workspaceRoot}/coverage",
- ],
- },
- },
- },
- },
- },
- ],
- ]
- `);
+ expect(results).toMatchSnapshot();
}
);
});
diff --git a/packages/jest/src/plugins/plugin.ts b/packages/jest/src/plugins/plugin.ts
index 72a4d18719daef..f5205864938443 100644
--- a/packages/jest/src/plugins/plugin.ts
+++ b/packages/jest/src/plugins/plugin.ts
@@ -11,7 +11,7 @@ import {
ProjectConfiguration,
readJsonFile,
TargetConfiguration,
- writeJsonFile
+ writeJsonFile,
} from '@nx/devkit';
import { dirname, isAbsolute, join, relative, resolve } from 'path';
@@ -21,7 +21,10 @@ import { readConfig, replaceRootDirInPath } from 'jest-config';
import jestResolve from 'jest-resolve';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
-import { clearRequireCache, loadConfigFile } from '@nx/devkit/src/utils/config-utils';
+import {
+ clearRequireCache,
+ loadConfigFile,
+} from '@nx/devkit/src/utils/config-utils';
import { getGlobPatternsFromPackageManagerWorkspaces } from 'nx/src/plugins/package-json-workspaces';
import { combineGlobPatterns } from 'nx/src/utils/globs';
import { minimatch } from 'minimatch';
@@ -185,6 +188,11 @@ async function buildJestTargets(
description: 'Run Jest Tests',
help: {
command: `${pmc.exec} jest --help`,
+ example: {
+ options: {
+ coverage: true,
+ },
+ },
},
},
});
@@ -241,6 +249,11 @@ async function buildJestTargets(
description: 'Run Jest Tests in CI',
help: {
command: `${pmc.exec} jest --help`,
+ example: {
+ options: {
+ coverage: true,
+ },
+ },
},
},
};
@@ -265,6 +278,11 @@ async function buildJestTargets(
description: `Run Jest Tests in ${relativePath}`,
help: {
command: `${pmc.exec} jest --help`,
+ example: {
+ options: {
+ coverage: true,
+ },
+ },
},
},
};
diff --git a/packages/nx/src/command-line/graph/graph.ts b/packages/nx/src/command-line/graph/graph.ts
index 36611b19e7af30..76d61a1c75dcfe 100644
--- a/packages/nx/src/command-line/graph/graph.ts
+++ b/packages/nx/src/command-line/graph/graph.ts
@@ -582,11 +582,6 @@ async function startServer(
return;
}
- if (sanitizePath === 'help.json') {
- res.end(JSON.stringify({ response: '' }));
- return;
- }
-
if (sanitizePath === 'task-inputs.json') {
performance.mark('task input generation:start');
@@ -628,12 +623,12 @@ async function startServer(
const target = parsedUrl.searchParams.get('target');
try {
- const result = getHelpResultFromTarget(project, target);
+ const text = getHelpTextFromTarget(project, target);
res.writeHead(200, { 'Content-Type': 'application/javascript' });
- res.end(JSON.stringify({ result }));
+ res.end(JSON.stringify({ text, success: true }));
} catch (err) {
- res.writeHead(400, { 'Content-Type': 'application/javascript' });
- res.end(JSON.stringify({ error: err.message }));
+ res.writeHead(200, { 'Content-Type': 'application/javascript' });
+ res.end(JSON.stringify({ text: err.message, success: false }));
}
return;
}
@@ -1184,7 +1179,7 @@ async function createJsonOutput(
return response;
}
-function getHelpResultFromTarget(
+function getHelpTextFromTarget(
projectName: string,
targetName: string
): string {
diff --git a/packages/nx/src/config/workspace-json-project-json.ts b/packages/nx/src/config/workspace-json-project-json.ts
index 4f77e6a1df24fd..1c75d8287540f4 100644
--- a/packages/nx/src/config/workspace-json-project-json.ts
+++ b/packages/nx/src/config/workspace-json-project-json.ts
@@ -126,10 +126,15 @@ export interface ProjectMetadata {
export interface TargetMetadata {
[k: string]: any;
+
description?: string;
technologies?: string[];
help?: {
command: string;
+ example: {
+ options?: Record;
+ args?: string[];
+ };
};
}
diff --git a/packages/playwright/src/plugins/plugin.spec.ts b/packages/playwright/src/plugins/plugin.spec.ts
index a431927a7b79ac..8a1aa360684022 100644
--- a/packages/playwright/src/plugins/plugin.spec.ts
+++ b/packages/playwright/src/plugins/plugin.spec.ts
@@ -73,6 +73,14 @@ describe('@nx/playwright/plugin', () => {
],
"metadata": {
"description": "Runs Playwright Tests",
+ "help": {
+ "command": "npx playwright test --help",
+ "example": {
+ "options": {
+ "workers": 1,
+ },
+ },
+ },
"technologies": [
"playwright",
],
@@ -99,6 +107,14 @@ describe('@nx/playwright/plugin', () => {
],
"metadata": {
"description": "Runs Playwright Tests in CI",
+ "help": {
+ "command": "npx playwright test --help",
+ "example": {
+ "options": {
+ "workers": 1,
+ },
+ },
+ },
"technologies": [
"playwright",
],
@@ -162,6 +178,14 @@ describe('@nx/playwright/plugin', () => {
],
"metadata": {
"description": "Runs Playwright Tests",
+ "help": {
+ "command": "npx playwright test --help",
+ "example": {
+ "options": {
+ "workers": 1,
+ },
+ },
+ },
"technologies": [
"playwright",
],
@@ -191,6 +215,14 @@ describe('@nx/playwright/plugin', () => {
],
"metadata": {
"description": "Runs Playwright Tests in CI",
+ "help": {
+ "command": "npx playwright test --help",
+ "example": {
+ "options": {
+ "workers": 1,
+ },
+ },
+ },
"technologies": [
"playwright",
],
@@ -273,6 +305,14 @@ describe('@nx/playwright/plugin', () => {
],
"metadata": {
"description": "Runs Playwright Tests in CI",
+ "help": {
+ "command": "npx playwright test --help",
+ "example": {
+ "options": {
+ "workers": 1,
+ },
+ },
+ },
"technologies": [
"playwright",
],
@@ -297,6 +337,14 @@ describe('@nx/playwright/plugin', () => {
],
"metadata": {
"description": "Runs Playwright Tests in tests/run-me.spec.ts in CI",
+ "help": {
+ "command": "npx playwright test --help",
+ "example": {
+ "options": {
+ "workers": 1,
+ },
+ },
+ },
"technologies": [
"playwright",
],
@@ -324,6 +372,14 @@ describe('@nx/playwright/plugin', () => {
],
"metadata": {
"description": "Runs Playwright Tests in tests/run-me-2.spec.ts in CI",
+ "help": {
+ "command": "npx playwright test --help",
+ "example": {
+ "options": {
+ "workers": 1,
+ },
+ },
+ },
"technologies": [
"playwright",
],
diff --git a/packages/playwright/src/plugins/plugin.ts b/packages/playwright/src/plugins/plugin.ts
index e7366751f0e3da..3a71c34dff6c73 100644
--- a/packages/playwright/src/plugins/plugin.ts
+++ b/packages/playwright/src/plugins/plugin.ts
@@ -167,6 +167,11 @@ async function buildPlaywrightTargets(
description: 'Runs Playwright Tests',
help: {
command: `${pmc.exec} playwright test --help`,
+ example: {
+ options: {
+ workers: 1,
+ },
+ },
},
},
};
@@ -223,6 +228,11 @@ async function buildPlaywrightTargets(
description: `Runs Playwright Tests in ${relativeSpecFilePath} in CI`,
help: {
command: `${pmc.exec} playwright test --help`,
+ example: {
+ options: {
+ workers: 1,
+ },
+ },
},
},
};
@@ -252,6 +262,11 @@ async function buildPlaywrightTargets(
description: 'Runs Playwright Tests in CI',
help: {
command: `${pmc.exec} playwright test --help`,
+ example: {
+ options: {
+ workers: 1,
+ },
+ },
},
},
};
diff --git a/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap b/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap
index 44cf90108c62d1..5a4b9f8ebe6e64 100644
--- a/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap
+++ b/packages/vite/src/plugins/__snapshots__/plugin-vitest.spec.ts.snap
@@ -25,6 +25,21 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = `
"env": "CI",
},
],
+ "metadata": {
+ "description": "Run Vite tests",
+ "help": {
+ "command": "npx vitest --help",
+ "example": {
+ "options": {
+ "bail": 1,
+ "coverage": true,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": ".",
},
diff --git a/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap b/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap
index f1c1fb7307b6c9..a46944aba01a8d 100644
--- a/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap
+++ b/packages/vite/src/plugins/__snapshots__/plugin-with-test.spec.ts.snap
@@ -25,6 +25,21 @@ exports[`@nx/vite/plugin with test node root project should create nodes - with
"env": "CI",
},
],
+ "metadata": {
+ "description": "Run Vite tests",
+ "help": {
+ "command": "npx vitest --help",
+ "example": {
+ "options": {
+ "bail": 1,
+ "coverage": true,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": ".",
},
diff --git a/packages/vite/src/plugins/__snapshots__/plugin.spec.ts.snap b/packages/vite/src/plugins/__snapshots__/plugin.spec.ts.snap
index 1c292204a3a281..1b75426da5b237 100644
--- a/packages/vite/src/plugins/__snapshots__/plugin.spec.ts.snap
+++ b/packages/vite/src/plugins/__snapshots__/plugin.spec.ts.snap
@@ -26,6 +26,21 @@ exports[`@nx/vite/plugin Library mode should exclude serve and preview targets w
],
},
],
+ "metadata": {
+ "description": "Run Vite build",
+ "help": {
+ "command": "npx vite build --help",
+ "example": {
+ "options": {
+ "manifest": "manifest.json",
+ "sourcemap": true,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": "my-lib",
},
@@ -67,6 +82,21 @@ exports[`@nx/vite/plugin not root project should create nodes 1`] = `
],
},
],
+ "metadata": {
+ "description": "Run Vite build",
+ "help": {
+ "command": "npx vite build --help",
+ "example": {
+ "options": {
+ "manifest": "manifest.json",
+ "sourcemap": true,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": "my-app",
},
@@ -76,12 +106,40 @@ exports[`@nx/vite/plugin not root project should create nodes 1`] = `
},
"my-serve": {
"command": "vite serve",
+ "metadata": {
+ "description": "Starts Vite dev server",
+ "help": {
+ "command": "npx vite --help",
+ "example": {
+ "options": {
+ "port": 3000,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": "my-app",
},
},
"preview-site": {
"command": "vite preview",
+ "metadata": {
+ "description": "Locally preview Vite production build",
+ "help": {
+ "command": "npx vite preview --help",
+ "example": {
+ "options": {
+ "port": 3000,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": "my-app",
},
@@ -127,6 +185,21 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = `
],
},
],
+ "metadata": {
+ "description": "Run Vite build",
+ "help": {
+ "command": "npx vite build --help",
+ "example": {
+ "options": {
+ "manifest": "manifest.json",
+ "sourcemap": true,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": ".",
},
@@ -136,12 +209,40 @@ exports[`@nx/vite/plugin root project should create nodes 1`] = `
},
"preview": {
"command": "vite preview",
+ "metadata": {
+ "description": "Locally preview Vite production build",
+ "help": {
+ "command": "npx vite preview --help",
+ "example": {
+ "options": {
+ "port": 3000,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": ".",
},
},
"serve": {
"command": "vite serve",
+ "metadata": {
+ "description": "Starts Vite dev server",
+ "help": {
+ "command": "npx vite --help",
+ "example": {
+ "options": {
+ "port": 3000,
+ },
+ },
+ },
+ "technologies": [
+ "vite",
+ ],
+ },
"options": {
"cwd": ".",
},
diff --git a/packages/vite/src/plugins/plugin.ts b/packages/vite/src/plugins/plugin.ts
index 5d07ecdf8119d1..15b114668717ea 100644
--- a/packages/vite/src/plugins/plugin.ts
+++ b/packages/vite/src/plugins/plugin.ts
@@ -235,7 +235,15 @@ async function buildTarget(
metadata: {
technologies: ['vite'],
description: `Run Vite build`,
- help: { command: `${pmc.exec} vite build --help` },
+ help: {
+ command: `${pmc.exec} vite build --help`,
+ example: {
+ options: {
+ sourcemap: true,
+ manifest: 'manifest.json',
+ },
+ },
+ },
},
};
}
@@ -249,8 +257,15 @@ function serveTarget(projectRoot: string) {
},
metadata: {
technologies: ['vite'],
- description: `Start Vite dev server`,
- help: { command: `${pmc.exec} vite --help` },
+ description: `Starts Vite dev server`,
+ help: {
+ command: `${pmc.exec} vite --help`,
+ example: {
+ options: {
+ port: 3000,
+ },
+ },
+ },
},
};
@@ -267,7 +282,14 @@ function previewTarget(projectRoot: string) {
metadata: {
technologies: ['vite'],
description: `Locally preview Vite production build`,
- help: { command: `${pmc.exec} vite preview --help` },
+ help: {
+ command: `${pmc.exec} vite preview --help`,
+ example: {
+ options: {
+ port: 3000,
+ },
+ },
+ },
},
};
@@ -299,7 +321,15 @@ async function testTarget(
metadata: {
technologies: ['vite'],
description: `Run Vite tests`,
- help: { command: `${pmc.exec} vitest --help` },
+ help: {
+ command: `${pmc.exec} vitest --help`,
+ example: {
+ options: {
+ bail: 1,
+ coverage: true,
+ },
+ },
+ },
},
};
}
diff --git a/packages/webpack/src/plugins/__snapshots__/plugin.spec.ts.snap b/packages/webpack/src/plugins/__snapshots__/plugin.spec.ts.snap
index 0915efc9ae0d55..a61d76d9e5f9c5 100644
--- a/packages/webpack/src/plugins/__snapshots__/plugin.spec.ts.snap
+++ b/packages/webpack/src/plugins/__snapshots__/plugin.spec.ts.snap
@@ -25,6 +25,23 @@ exports[`@nx/webpack/plugin should create nodes 1`] = `
],
},
],
+ "metadata": {
+ "description": "Runs Webpack build",
+ "help": {
+ "command": "npx webpack-cli build --help",
+ "example": {
+ "args": [
+ "--profile",
+ ],
+ "options": {
+ "json": "stats.json",
+ },
+ },
+ },
+ "technologies": [
+ "webpack",
+ ],
+ },
"options": {
"args": [
"--node-env=production",
@@ -37,6 +54,23 @@ exports[`@nx/webpack/plugin should create nodes 1`] = `
},
"my-serve": {
"command": "webpack-cli serve",
+ "metadata": {
+ "description": "Starts Webpack dev server",
+ "help": {
+ "command": "npx webpack-cli serve --help",
+ "example": {
+ "options": {
+ "args": [
+ "--client-progress",
+ "--history-api-fallback ",
+ ],
+ },
+ },
+ },
+ "technologies": [
+ "webpack",
+ ],
+ },
"options": {
"args": [
"--node-env=development",
@@ -46,6 +80,23 @@ exports[`@nx/webpack/plugin should create nodes 1`] = `
},
"preview-site": {
"command": "webpack-cli serve",
+ "metadata": {
+ "description": "Starts Webpack dev server in production mode",
+ "help": {
+ "command": "npx webpack-cli serve --help",
+ "example": {
+ "options": {
+ "args": [
+ "--client-progress",
+ "--history-api-fallback ",
+ ],
+ },
+ },
+ },
+ "technologies": [
+ "webpack",
+ ],
+ },
"options": {
"args": [
"--node-env=production",
diff --git a/packages/webpack/src/plugins/plugin.ts b/packages/webpack/src/plugins/plugin.ts
index 8924b727d73a93..67862e34777dd9 100644
--- a/packages/webpack/src/plugins/plugin.ts
+++ b/packages/webpack/src/plugins/plugin.ts
@@ -6,6 +6,7 @@ import {
CreateNodesResult,
CreateNodesV2,
detectPackageManager,
+ getPackageManagerCommand,
logger,
ProjectConfiguration,
readJsonFile,
@@ -137,6 +138,7 @@ async function createWebpackTargets(
options: Required,
context: CreateNodesContext
): Promise {
+ const pmc = getPackageManagerCommand();
const namedInputs = getNamedInputs(projectRoot, context);
const webpackConfig = resolveUserDefinedWebpackConfig(
@@ -176,6 +178,19 @@ async function createWebpackTargets(
},
],
outputs: [outputPath],
+ metadata: {
+ technologies: ['webpack'],
+ description: 'Runs Webpack build',
+ help: {
+ command: `${pmc.exec} webpack-cli build --help`,
+ example: {
+ options: {
+ json: 'stats.json',
+ },
+ args: ['--profile'],
+ },
+ },
+ },
};
targets[options.serveTargetName] = {
@@ -184,6 +199,18 @@ async function createWebpackTargets(
cwd: projectRoot,
args: ['--node-env=development'],
},
+ metadata: {
+ technologies: ['webpack'],
+ description: 'Starts Webpack dev server',
+ help: {
+ command: `${pmc.exec} webpack-cli serve --help`,
+ example: {
+ options: {
+ args: ['--client-progress', '--history-api-fallback '],
+ },
+ },
+ },
+ },
};
targets[options.previewTargetName] = {
@@ -192,6 +219,18 @@ async function createWebpackTargets(
cwd: projectRoot,
args: ['--node-env=production'],
},
+ metadata: {
+ technologies: ['webpack'],
+ description: 'Starts Webpack dev server in production mode',
+ help: {
+ command: `${pmc.exec} webpack-cli serve --help`,
+ example: {
+ options: {
+ args: ['--client-progress', '--history-api-fallback '],
+ },
+ },
+ },
+ },
};
targets[options.serveStaticTargetName] = {