Skip to content

Commit cbf80c1

Browse files
authored
feat(misc): add useProjectJson flag to project generators (#30319)
Add a `useProjectJson` option to project generators to allow users to opt in/out of generating the Nx configuration in a `project.json` file. ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes #
1 parent 432a645 commit cbf80c1

File tree

143 files changed

+2027
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+2027
-604
lines changed

docs/generated/packages/detox/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
"type": "boolean",
5959
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
6060
"default": false
61+
},
62+
"useProjectJson": {
63+
"type": "boolean",
64+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
6165
}
6266
},
6367
"required": ["e2eDirectory", "appProject", "framework"],

docs/generated/packages/expo/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
"type": "boolean",
8787
"description": "Do not add dependencies to `package.json`.",
8888
"default": false
89+
},
90+
"useProjectJson": {
91+
"type": "boolean",
92+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
8993
}
9094
},
9195
"required": ["directory"],

docs/generated/packages/expo/generators/library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
"type": "boolean",
9090
"description": "Do not add dependencies to `package.json`.",
9191
"default": false
92+
},
93+
"useProjectJson": {
94+
"type": "boolean",
95+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
9296
}
9397
},
9498
"required": ["directory"],

docs/generated/packages/express/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
"type": "boolean",
7474
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
7575
"default": false
76+
},
77+
"useProjectJson": {
78+
"type": "boolean",
79+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
7680
}
7781
},
7882
"required": ["directory"],

docs/generated/packages/nest/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
"type": "boolean",
7979
"description": "Adds strictNullChecks, noImplicitAny, strictBindCallApply, forceConsistentCasingInFileNames and noFallthroughCasesInSwitch to tsconfig.",
8080
"default": false
81+
},
82+
"useProjectJson": {
83+
"type": "boolean",
84+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
8185
}
8286
},
8387
"additionalProperties": false,

docs/generated/packages/nest/generators/library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@
133133
"description": "Don't include the directory in the name of the module of the library.",
134134
"type": "boolean",
135135
"default": false
136+
},
137+
"useProjectJson": {
138+
"type": "boolean",
139+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
136140
}
137141
},
138142
"additionalProperties": false,

docs/generated/packages/next/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@
138138
"default": false,
139139
"hidden": true,
140140
"x-priority": "internal"
141+
},
142+
"useProjectJson": {
143+
"type": "boolean",
144+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
141145
}
142146
},
143147
"required": ["directory"],

docs/generated/packages/next/generators/library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@
152152
"default": false,
153153
"description": "Do not add dependencies to `package.json`.",
154154
"x-priority": "internal"
155+
},
156+
"useProjectJson": {
157+
"type": "boolean",
158+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
155159
}
156160
},
157161
"required": ["directory"],

docs/generated/packages/node/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
"docker": {
124124
"type": "boolean",
125125
"description": "Add a docker build target"
126+
},
127+
"useProjectJson": {
128+
"type": "boolean",
129+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
126130
}
127131
},
128132
"required": ["directory"],

docs/generated/packages/node/generators/library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
"type": "boolean",
124124
"description": "Whether or not to configure the ESLint `parserOptions.project`. We do not do this by default for lint performance reasons.",
125125
"default": false
126+
},
127+
"useProjectJson": {
128+
"type": "boolean",
129+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
126130
}
127131
},
128132
"required": ["directory"],

docs/generated/packages/nuxt/generators/application.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "application",
3-
"factory": "./src/generators/application/application",
3+
"factory": "./src/generators/application/application#applicationGeneratorInternal",
44
"schema": {
55
"$schema": "https://json-schema.org/schema",
66
"cli": "nx",
@@ -100,6 +100,10 @@
100100
"type": "boolean",
101101
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
102102
"default": false
103+
},
104+
"useProjectJson": {
105+
"type": "boolean",
106+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
103107
}
104108
},
105109
"required": ["directory"],
@@ -108,7 +112,7 @@
108112
},
109113
"aliases": ["app"],
110114
"description": "Create a Nuxt application.",
111-
"implementation": "/packages/nuxt/src/generators/application/application.ts",
115+
"implementation": "/packages/nuxt/src/generators/application/application#applicationGeneratorInternal.ts",
112116
"hidden": false,
113117
"path": "/packages/nuxt/src/generators/application/schema.json",
114118
"type": "generator"

docs/generated/packages/react-native/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
"x-prompt": "Which bundler do you want to use to build the application?",
9696
"default": "vite",
9797
"x-priority": "important"
98+
},
99+
"useProjectJson": {
100+
"type": "boolean",
101+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
98102
}
99103
},
100104
"required": ["directory"],

docs/generated/packages/react-native/generators/library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@
9393
"type": "boolean",
9494
"default": false,
9595
"x-priority": "internal"
96+
},
97+
"useProjectJson": {
98+
"type": "boolean",
99+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
96100
}
97101
},
98102
"required": ["directory"],

docs/generated/packages/react/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@
181181
"description": "Generate a React app with a minimal setup, no separate test files.",
182182
"type": "boolean",
183183
"default": false
184+
},
185+
"useProjectJson": {
186+
"type": "boolean",
187+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
184188
}
185189
},
186190
"required": ["directory"],

docs/generated/packages/react/generators/library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@
184184
"description": "Don't include the directory in the name of the module of the library.",
185185
"type": "boolean",
186186
"default": false
187+
},
188+
"useProjectJson": {
189+
"type": "boolean",
190+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
187191
}
188192
},
189193
"required": ["directory"],

docs/generated/packages/remix/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
"type": "boolean",
5858
"x-priority": "internal",
5959
"default": false
60+
},
61+
"useProjectJson": {
62+
"type": "boolean",
63+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
6064
}
6165
},
6266
"required": ["directory"],

docs/generated/packages/remix/generators/library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
"default": false,
8282
"description": "Generate a buildable library that uses rollup to bundle.",
8383
"x-deprecated": "Use the `bundler` option for greater control (none, vite, rollup)."
84+
},
85+
"useProjectJson": {
86+
"type": "boolean",
87+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
8488
}
8589
},
8690
"required": ["directory"],

docs/generated/packages/vue/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@
133133
"type": "boolean",
134134
"default": false,
135135
"hidden": true
136+
},
137+
"useProjectJson": {
138+
"type": "boolean",
139+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
136140
}
137141
},
138142
"required": ["directory"],

docs/generated/packages/vue/generators/library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@
125125
"description": "Create a Vue library with a minimal setup, no separate test files.",
126126
"type": "boolean",
127127
"default": false
128+
},
129+
"useProjectJson": {
130+
"type": "boolean",
131+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
128132
}
129133
},
130134
"required": ["directory"],

docs/generated/packages/web/generators/application.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
"type": "boolean",
102102
"description": "Creates an application with strict mode and strict type checking.",
103103
"default": true
104+
},
105+
"useProjectJson": {
106+
"type": "boolean",
107+
"description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
104108
}
105109
},
106110
"required": ["directory"],

packages/detox/src/generators/application/application.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ describe('detox application generator', () => {
531531
linter: Linter.None,
532532
framework: 'react-native',
533533
addPlugin: true,
534+
useProjectJson: false,
534535
});
535536

536537
expect(tree.read('tsconfig.json', 'utf-8')).toMatchInlineSnapshot(`
@@ -592,6 +593,7 @@ describe('detox application generator', () => {
592593
framework: 'react-native',
593594
addPlugin: true,
594595
skipFormat: true,
596+
useProjectJson: false,
595597
});
596598

597599
expect(tree.exists('apps/my-app-e2e/test-setup.ts')).toBeTruthy();
@@ -672,6 +674,7 @@ describe('detox application generator', () => {
672674
framework: 'react-native',
673675
addPlugin: true,
674676
skipFormat: true,
677+
useProjectJson: false,
675678
});
676679

677680
const packageJson = readJson(tree, 'apps/my-app-e2e/package.json');
@@ -687,5 +690,38 @@ describe('detox application generator', () => {
687690
]
688691
`);
689692
});
693+
694+
it('should generate project.json if useProjectJson is true', async () => {
695+
writeJson(tree, 'apps/my-app/package.json', { name: 'my-app' });
696+
697+
await detoxApplicationGenerator(tree, {
698+
e2eDirectory: 'apps/my-app-e2e',
699+
appProject: 'my-app',
700+
e2eName: 'my-app-e2e',
701+
linter: Linter.None,
702+
framework: 'react-native',
703+
addPlugin: true,
704+
skipFormat: true,
705+
useProjectJson: true,
706+
});
707+
708+
expect(tree.exists('apps/my-app-e2e/project.json')).toBeTruthy();
709+
expect(readProjectConfiguration(tree, 'my-app-e2e'))
710+
.toMatchInlineSnapshot(`
711+
{
712+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
713+
"implicitDependencies": [
714+
"my-app",
715+
],
716+
"name": "my-app-e2e",
717+
"projectType": "application",
718+
"root": "apps/my-app-e2e",
719+
"sourceRoot": "apps/my-app-e2e/src",
720+
"tags": [],
721+
"targets": {},
722+
}
723+
`);
724+
expect(readJson(tree, 'apps/my-app-e2e/package.json').nx).toBeUndefined();
725+
});
690726
});
691727
});

packages/detox/src/generators/application/application.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { sortPackageJsonFields } from '@nx/js/src/utils/package-json/sort-fields
1818
export async function detoxApplicationGenerator(host: Tree, schema: Schema) {
1919
return await detoxApplicationGeneratorInternal(host, {
2020
addPlugin: false,
21+
useProjectJson: true,
2122
...schema,
2223
});
2324
}

packages/detox/src/generators/application/lib/add-project.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('Add Project', () => {
4141
appRoot: 'apps/my-app',
4242
linter: Linter.EsLint,
4343
framework: 'react-native',
44+
useProjectJson: true,
4445
});
4546
});
4647

@@ -91,6 +92,7 @@ describe('Add Project', () => {
9192
appRoot: 'apps/my-dir/my-app',
9293
linter: Linter.EsLint,
9394
framework: 'react-native',
95+
useProjectJson: true,
9496
});
9597
});
9698

packages/detox/src/generators/application/lib/add-project.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
reactNativeTestTarget,
1414
} from './get-targets';
1515
import { NormalizedSchema } from './normalize-options';
16-
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
16+
import type { PackageJson } from 'nx/src/utils/package-json';
1717

1818
export function addProject(host: Tree, options: NormalizedSchema) {
1919
const nxJson = readNxJson(host);
@@ -23,20 +23,21 @@ export function addProject(host: Tree, options: NormalizedSchema) {
2323
: p.plugin === '@nx/detox/plugin'
2424
);
2525

26-
if (isUsingTsSolutionSetup(host)) {
27-
writeJson(host, joinPathFragments(options.e2eProjectRoot, 'package.json'), {
28-
name: options.importPath,
29-
version: '0.0.1',
30-
private: true,
31-
nx: {
32-
name:
33-
options.e2eProjectName !== options.importPath
34-
? options.e2eProjectName
35-
: undefined,
36-
targets: hasPlugin ? undefined : getTargets(options),
37-
implicitDependencies: [options.appProject],
38-
},
39-
});
26+
const packageJson: PackageJson = {
27+
name: options.importPath,
28+
version: '0.0.1',
29+
private: true,
30+
};
31+
32+
if (!options.useProjectJson) {
33+
packageJson.nx = {
34+
name:
35+
options.e2eProjectName !== options.importPath
36+
? options.e2eProjectName
37+
: undefined,
38+
targets: hasPlugin ? undefined : getTargets(options),
39+
implicitDependencies: [options.appProject],
40+
};
4041
} else {
4142
addProjectConfiguration(host, options.e2eProjectName, {
4243
root: options.e2eProjectRoot,
@@ -47,6 +48,14 @@ export function addProject(host: Tree, options: NormalizedSchema) {
4748
implicitDependencies: [options.appProject],
4849
});
4950
}
51+
52+
if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
53+
writeJson(
54+
host,
55+
joinPathFragments(options.e2eProjectRoot, 'package.json'),
56+
packageJson
57+
);
58+
}
5059
}
5160

5261
function getTargets(options: NormalizedSchema) {

0 commit comments

Comments
 (0)