feat(graph): add target group for scripts (#26035)
<!-- 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 --> <img width="1131" alt="Screenshot 2024-05-24 at 3 58 30 PM" src="https://github.com/nrwl/nx/assets/16211801/9aadeac3-ca74-4449-baf6-21d7c97118aa"> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
e0450f7969
commit
ef4035a56a
@ -12,7 +12,7 @@ export const TargetConfigurationGroupHeader = ({
|
|||||||
className = '',
|
className = '',
|
||||||
}: TargetConfigurationGroupHeaderProps) => {
|
}: TargetConfigurationGroupHeaderProps) => {
|
||||||
return (
|
return (
|
||||||
<header className={`px-4 py-2 text-lg ${className}`}>
|
<header className={`px-4 py-2 text-lg capitalize ${className}`}>
|
||||||
{targetGroupName}{' '}
|
{targetGroupName}{' '}
|
||||||
<Pill
|
<Pill
|
||||||
text={
|
text={
|
||||||
|
|||||||
@ -51,20 +51,29 @@ describe('Workspaces', () => {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(projects['packages/my-package']).toEqual({
|
expect(projects['packages/my-package']).toMatchInlineSnapshot(`
|
||||||
name: 'my-package',
|
{
|
||||||
root: 'packages/my-package',
|
"metadata": {
|
||||||
sourceRoot: 'packages/my-package',
|
"targetGroups": {
|
||||||
projectType: 'library',
|
"NPM Scripts": [],
|
||||||
targets: {
|
|
||||||
'nx-release-publish': {
|
|
||||||
configurations: {},
|
|
||||||
dependsOn: ['^nx-release-publish'],
|
|
||||||
executor: '@nx/js:release-publish',
|
|
||||||
options: {},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
"name": "my-package",
|
||||||
|
"projectType": "library",
|
||||||
|
"root": "packages/my-package",
|
||||||
|
"sourceRoot": "packages/my-package",
|
||||||
|
"targets": {
|
||||||
|
"nx-release-publish": {
|
||||||
|
"configurations": {},
|
||||||
|
"dependsOn": [
|
||||||
|
"^nx-release-publish",
|
||||||
|
],
|
||||||
|
"executor": "@nx/js:release-publish",
|
||||||
|
"options": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -41,6 +41,13 @@ describe('nx package.json workspaces plugin', () => {
|
|||||||
{
|
{
|
||||||
"projects": {
|
"projects": {
|
||||||
".": {
|
".": {
|
||||||
|
"metadata": {
|
||||||
|
"targetGroups": {
|
||||||
|
"NPM Scripts": [
|
||||||
|
"echo",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
"name": "root",
|
"name": "root",
|
||||||
"projectType": "library",
|
"projectType": "library",
|
||||||
"root": ".",
|
"root": ".",
|
||||||
@ -73,6 +80,13 @@ describe('nx package.json workspaces plugin', () => {
|
|||||||
{
|
{
|
||||||
"projects": {
|
"projects": {
|
||||||
"packages/lib-a": {
|
"packages/lib-a": {
|
||||||
|
"metadata": {
|
||||||
|
"targetGroups": {
|
||||||
|
"NPM Scripts": [
|
||||||
|
"test",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
"name": "lib-a",
|
"name": "lib-a",
|
||||||
"projectType": "library",
|
"projectType": "library",
|
||||||
"root": "packages/lib-a",
|
"root": "packages/lib-a",
|
||||||
@ -112,6 +126,14 @@ describe('nx package.json workspaces plugin', () => {
|
|||||||
"build",
|
"build",
|
||||||
"test",
|
"test",
|
||||||
],
|
],
|
||||||
|
"metadata": {
|
||||||
|
"targetGroups": {
|
||||||
|
"NPM Scripts": [
|
||||||
|
"build",
|
||||||
|
"test",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
"name": "lib-b",
|
"name": "lib-b",
|
||||||
"projectType": "library",
|
"projectType": "library",
|
||||||
"root": "packages/lib-b",
|
"root": "packages/lib-b",
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { NX_PREFIX } from '../../utils/logger';
|
|||||||
import { output } from '../../utils/output';
|
import { output } from '../../utils/output';
|
||||||
import {
|
import {
|
||||||
PackageJson,
|
PackageJson,
|
||||||
|
getMetadataFromPackageJson,
|
||||||
readTargetsFromPackageJson,
|
readTargetsFromPackageJson,
|
||||||
} from '../../utils/package-json';
|
} from '../../utils/package-json';
|
||||||
import { joinPathFragments } from '../../utils/path';
|
import { joinPathFragments } from '../../utils/path';
|
||||||
@ -101,6 +102,7 @@ export function buildProjectConfigurationFromPackageJson(
|
|||||||
projectType,
|
projectType,
|
||||||
...packageJson.nx,
|
...packageJson.nx,
|
||||||
targets: readTargetsFromPackageJson(packageJson),
|
targets: readTargetsFromPackageJson(packageJson),
|
||||||
|
metadata: getMetadataFromPackageJson(packageJson),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,13 @@ describe('nx project.json plugin', () => {
|
|||||||
{
|
{
|
||||||
"projects": {
|
"projects": {
|
||||||
"lib-a": {
|
"lib-a": {
|
||||||
|
"metadata": {
|
||||||
|
"targetGroups": {
|
||||||
|
"NPM Scripts": [
|
||||||
|
"test",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
"name": "lib-a",
|
"name": "lib-a",
|
||||||
"root": "packages/lib-a",
|
"root": "packages/lib-a",
|
||||||
"targets": {
|
"targets": {
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { readJsonFile } from '../../../utils/fileutils';
|
|||||||
import { ProjectConfiguration } from '../../../config/workspace-json-project-json';
|
import { ProjectConfiguration } from '../../../config/workspace-json-project-json';
|
||||||
import {
|
import {
|
||||||
PackageJson,
|
PackageJson,
|
||||||
|
getMetadataFromPackageJson,
|
||||||
readTargetsFromPackageJson,
|
readTargetsFromPackageJson,
|
||||||
} from '../../../utils/package-json';
|
} from '../../../utils/package-json';
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ function createProjectFromPackageJsonNextToProjectJson(
|
|||||||
name,
|
name,
|
||||||
root,
|
root,
|
||||||
targets: readTargetsFromPackageJson(packageJson),
|
targets: readTargetsFromPackageJson(packageJson),
|
||||||
|
metadata: getMetadataFromPackageJson(packageJson),
|
||||||
} as ProjectConfiguration;
|
} as ProjectConfiguration;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { existsSync } from 'fs';
|
|||||||
import { dirname, join } from 'path';
|
import { dirname, join } from 'path';
|
||||||
import {
|
import {
|
||||||
InputDefinition,
|
InputDefinition,
|
||||||
|
ProjectMetadata,
|
||||||
TargetConfiguration,
|
TargetConfiguration,
|
||||||
} from '../config/workspace-json-project-json';
|
} from '../config/workspace-json-project-json';
|
||||||
import { mergeTargetConfigurations } from '../project-graph/utils/project-configuration-utils';
|
import { mergeTargetConfigurations } from '../project-graph/utils/project-configuration-utils';
|
||||||
@ -138,6 +139,18 @@ export function buildTargetFromScript(
|
|||||||
|
|
||||||
let packageManagerCommand: PackageManagerCommands | undefined;
|
let packageManagerCommand: PackageManagerCommands | undefined;
|
||||||
|
|
||||||
|
export function getMetadataFromPackageJson(
|
||||||
|
packageJson: PackageJson
|
||||||
|
): ProjectMetadata {
|
||||||
|
const { scripts, nx } = packageJson ?? {};
|
||||||
|
const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {});
|
||||||
|
return {
|
||||||
|
targetGroups: {
|
||||||
|
'NPM Scripts': includedScripts,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function readTargetsFromPackageJson(packageJson: PackageJson) {
|
export function readTargetsFromPackageJson(packageJson: PackageJson) {
|
||||||
const { scripts, nx, private: isPrivate } = packageJson ?? {};
|
const { scripts, nx, private: isPrivate } = packageJson ?? {};
|
||||||
const res: Record<string, TargetConfiguration> = {};
|
const res: Record<string, TargetConfiguration> = {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user