@nx/node 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-a7b74d2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -4
- package/migrations.json +24 -38
- package/package.json +9 -8
- package/src/generators/application/application.d.ts +3 -1
- package/src/generators/application/application.js +102 -27
- package/src/generators/application/files/common/tsconfig.app.json +0 -1
- package/src/generators/application/files/common/webpack.config.js__tmpl__ +4 -4
- package/src/generators/application/schema.d.ts +5 -5
- package/src/generators/application/schema.json +27 -30
- package/src/generators/e2e-project/e2e-project.js +112 -32
- package/src/generators/e2e-project/files/cli/jest.config.ts__tmpl__ +17 -4
- package/src/generators/e2e-project/files/server/common/jest.config.ts__tmpl__ +17 -4
- package/src/generators/e2e-project/files/server/common/src/support/global-setup.ts__tmpl__ +6 -0
- package/src/generators/e2e-project/files/server/common/src/support/global-teardown.ts__tmpl__ +3 -0
- package/src/generators/e2e-project/files/server/common/src/support/test-setup.ts__tmpl__ +0 -1
- package/src/generators/e2e-project/files/ts-solution/tsconfig.json__tmpl__ +14 -0
- package/src/generators/e2e-project/schema.d.ts +1 -3
- package/src/generators/e2e-project/schema.json +4 -5
- package/src/generators/library/files/ts-solution/tsconfig.lib.json +15 -0
- package/src/generators/library/library.d.ts +1 -0
- package/src/generators/library/library.js +78 -43
- package/src/generators/library/schema.d.ts +3 -5
- package/src/generators/library/schema.json +21 -24
- package/src/utils/kill-port.d.ts +7 -0
- package/src/utils/kill-port.js +36 -0
- package/src/utils/versions.d.ts +6 -6
- package/src/utils/versions.js +6 -6
- package/src/utils/wait-for-port-open.d.ts +24 -0
- package/src/utils/wait-for-port-open.js +47 -0
- package/utils.d.ts +2 -0
- package/utils.js +7 -0
- package/src/generators/e2e-project/files/cli/tsconfig.spec.json__tmpl__ +0 -12
- package/src/generators/e2e-project/files/server/common/tsconfig.json__tmpl__ +0 -13
- package/src/generators/library/files/lib/package.json__tmpl__ +0 -4
- package/src/migrations/update-16-0-0/update-webpack-executor.d.ts +0 -2
- package/src/migrations/update-16-0-0/update-webpack-executor.js +0 -17
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-3-1/update-webpack-executor.d.ts +0 -2
- package/src/migrations/update-16-3-1/update-webpack-executor.js +0 -17
- package/src/migrations/update-16-4-0/replace-node-executor.d.ts +0 -2
- package/src/migrations/update-16-4-0/replace-node-executor.js +0 -14
- /package/src/generators/e2e-project/files/{cli → non-ts-solution}/tsconfig.json__tmpl__ +0 -0
- /package/src/generators/e2e-project/files/{server/common → non-ts-solution}/tsconfig.spec.json__tmpl__ +0 -0
- /package/src/generators/library/files/{lib → non-ts-solution}/tsconfig.lib.json +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p style="text-align: center;">
|
|
2
2
|
<picture>
|
|
3
3
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
|
|
4
|
-
<img alt="Nx - Smart
|
|
4
|
+
<img alt="Nx - Smart Repos · Fast Builds" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
|
|
5
5
|
</picture>
|
|
6
6
|
</p>
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://circleci.com/gh/nrwl/nx)
|
|
11
11
|
[]()
|
|
12
|
-
[](https://www.npmjs.com/package/nx)
|
|
13
13
|
[]()
|
|
14
14
|
[](http://commitizen.github.io/cz-cli/)
|
|
15
15
|
[](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
<hr>
|
|
22
22
|
|
|
23
|
-
# Nx: Smart
|
|
23
|
+
# Nx: Smart Repos · Fast Builds
|
|
24
24
|
|
|
25
25
|
Nx is a build system, optimized for monorepos, with plugins for popular frameworks and tools and advanced CI capabilities including caching and distribution.
|
|
26
26
|
|
|
@@ -62,5 +62,5 @@ npx nx@latest init
|
|
|
62
62
|
- [Blog Posts About Nx](https://nx.dev/blog)
|
|
63
63
|
|
|
64
64
|
<p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
|
|
65
|
-
width="100%" alt="Nx - Smart
|
|
65
|
+
width="100%" alt="Nx - Smart Repos · Fast Builds"></a></p>
|
|
66
66
|
|
package/migrations.json
CHANGED
|
@@ -1,45 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
3
|
-
"update-16-0-0-add-nx-packages": {
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"version": "16.0.0-beta.1",
|
|
6
|
-
"description": "Replace @nrwl/node with @nx/node",
|
|
7
|
-
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
8
|
-
},
|
|
9
|
-
"update-16-0-0-update-executor": {
|
|
10
|
-
"cli": "nx",
|
|
11
|
-
"version": "16.0.0-beta.5",
|
|
12
|
-
"description": "Replace @nrwl/node:webpack with @nx/node:webpack",
|
|
13
|
-
"implementation": "./src/migrations/update-16-0-0/update-webpack-executor"
|
|
14
|
-
},
|
|
15
|
-
"update-16-3-1-update-executor": {
|
|
16
|
-
"cli": "nx",
|
|
17
|
-
"version": "16.3.1-beta.0",
|
|
18
|
-
"description": "Replace @nrwl/node:webpack and @nx/node:webpack with @nx/webpack:webpack for all project targets",
|
|
19
|
-
"implementation": "./src/migrations/update-16-3-1/update-webpack-executor"
|
|
20
|
-
},
|
|
21
|
-
"update-16-4-0-replace-node-executor": {
|
|
22
|
-
"cli": "nx",
|
|
23
|
-
"version": "16.4.0-beta.8",
|
|
24
|
-
"description": "Replace @nx/node:node with @nx/js:node for all project targets",
|
|
25
|
-
"implementation": "./src/migrations/update-16-4-0/replace-node-executor"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
2
|
+
"generators": {},
|
|
28
3
|
"packageJsonUpdates": {
|
|
29
|
-
"
|
|
30
|
-
"version": "
|
|
4
|
+
"20.4.0": {
|
|
5
|
+
"version": "20.4.0-beta.3",
|
|
31
6
|
"packages": {
|
|
32
|
-
"
|
|
33
|
-
"version": "
|
|
7
|
+
"fastify": {
|
|
8
|
+
"version": "~5.2.1",
|
|
34
9
|
"alwaysAddToPackageJson": false
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
10
|
+
},
|
|
11
|
+
"fastify-plugin": {
|
|
12
|
+
"version": "~5.0.1",
|
|
13
|
+
"alwaysAddToPackageJson": false
|
|
14
|
+
},
|
|
15
|
+
"@fastify/autoload": {
|
|
16
|
+
"version": "~6.0.3",
|
|
17
|
+
"alwaysAddToPackageJson": false
|
|
18
|
+
},
|
|
19
|
+
"@fastify/sensible": {
|
|
20
|
+
"version": "~6.0.2",
|
|
21
|
+
"alwaysAddToPackageJson": false
|
|
22
|
+
},
|
|
23
|
+
"express": {
|
|
24
|
+
"version": "^4.21.2",
|
|
25
|
+
"alwaysAddToPackageJson": false
|
|
26
|
+
},
|
|
27
|
+
"@types/express": {
|
|
28
|
+
"version": "^4.17.21",
|
|
43
29
|
"alwaysAddToPackageJson": false
|
|
44
30
|
}
|
|
45
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/node",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-31313-a7b74d2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Node Plugin for Nx contains generators to manage Node applications within an Nx workspace.",
|
|
6
6
|
"repository": {
|
|
@@ -32,15 +32,16 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"tslib": "^2.3.0",
|
|
35
|
-
"@nx/devkit": "0.0.0-pr-
|
|
36
|
-
"@nx/jest": "0.0.0-pr-
|
|
37
|
-
"@nx/js": "0.0.0-pr-
|
|
38
|
-
"@nx/eslint": "0.0.0-pr-
|
|
39
|
-
"
|
|
35
|
+
"@nx/devkit": "0.0.0-pr-31313-a7b74d2",
|
|
36
|
+
"@nx/jest": "0.0.0-pr-31313-a7b74d2",
|
|
37
|
+
"@nx/js": "0.0.0-pr-31313-a7b74d2",
|
|
38
|
+
"@nx/eslint": "0.0.0-pr-31313-a7b74d2",
|
|
39
|
+
"tcp-port-used": "^1.0.2",
|
|
40
|
+
"kill-port": "^1.6.1"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public"
|
|
43
44
|
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
45
|
+
"types": "./index.d.ts",
|
|
46
|
+
"type": "commonjs"
|
|
46
47
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
2
|
import { Schema } from './schema';
|
|
3
|
-
export interface NormalizedSchema extends Schema {
|
|
3
|
+
export interface NormalizedSchema extends Omit<Schema, 'useTsSolution'> {
|
|
4
4
|
appProjectRoot: string;
|
|
5
5
|
parsedTags: string[];
|
|
6
6
|
outputPath: string;
|
|
7
|
+
importPath: string;
|
|
8
|
+
isUsingTsSolutionConfig: boolean;
|
|
7
9
|
}
|
|
8
10
|
export declare function addLintingToApplication(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
|
|
9
11
|
export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
@@ -17,6 +17,8 @@ const setup_docker_1 = require("../setup-docker/setup-docker");
|
|
|
17
17
|
const has_webpack_plugin_1 = require("../../utils/has-webpack-plugin");
|
|
18
18
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
19
19
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
20
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
21
|
+
const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
|
|
20
22
|
function getWebpackBuildConfig(project, options) {
|
|
21
23
|
return {
|
|
22
24
|
executor: `@nx/webpack:webpack`,
|
|
@@ -30,7 +32,7 @@ function getWebpackBuildConfig(project, options) {
|
|
|
30
32
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
31
33
|
assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
|
|
32
34
|
webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
|
|
33
|
-
generatePackageJson: true,
|
|
35
|
+
generatePackageJson: options.isUsingTsSolutionConfig ? undefined : true,
|
|
34
36
|
},
|
|
35
37
|
configurations: {
|
|
36
38
|
development: {},
|
|
@@ -54,7 +56,7 @@ function getEsBuildConfig(project, options) {
|
|
|
54
56
|
main: (0, devkit_1.joinPathFragments)(project.sourceRoot, 'main' + (options.js ? '.js' : '.ts')),
|
|
55
57
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
56
58
|
assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
|
|
57
|
-
generatePackageJson: true,
|
|
59
|
+
generatePackageJson: options.isUsingTsSolutionConfig ? undefined : true,
|
|
58
60
|
esbuildOptions: {
|
|
59
61
|
sourcemap: true,
|
|
60
62
|
// Generate CJS files as .js so imports can be './foo' rather than './foo.cjs'.
|
|
@@ -76,6 +78,7 @@ function getEsBuildConfig(project, options) {
|
|
|
76
78
|
}
|
|
77
79
|
function getServeConfig(options) {
|
|
78
80
|
return {
|
|
81
|
+
continuous: true,
|
|
79
82
|
executor: '@nx/js:node',
|
|
80
83
|
defaultConfiguration: 'development',
|
|
81
84
|
// Run build, which includes dependency on "^build" by default, so the first run
|
|
@@ -97,6 +100,20 @@ function getServeConfig(options) {
|
|
|
97
100
|
},
|
|
98
101
|
};
|
|
99
102
|
}
|
|
103
|
+
function getNestWebpackBuildConfig() {
|
|
104
|
+
return {
|
|
105
|
+
executor: 'nx:run-commands',
|
|
106
|
+
options: {
|
|
107
|
+
command: 'webpack-cli build',
|
|
108
|
+
args: ['node-env=production'],
|
|
109
|
+
},
|
|
110
|
+
configurations: {
|
|
111
|
+
development: {
|
|
112
|
+
args: ['node-env=development'],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
100
117
|
function addProject(tree, options) {
|
|
101
118
|
const project = {
|
|
102
119
|
root: options.appProjectRoot,
|
|
@@ -114,12 +131,33 @@ function addProject(tree, options) {
|
|
|
114
131
|
(0, target_defaults_utils_1.addBuildTargetDefaults)(tree, `@nx/webpack:webpack`);
|
|
115
132
|
project.targets.build = getWebpackBuildConfig(project, options);
|
|
116
133
|
}
|
|
134
|
+
else if (options.isNest) {
|
|
135
|
+
// If we are using Nest that has the webpack plugin we need to override the
|
|
136
|
+
// build target so that node-env can be set to production or development so the serve target can be run in development mode
|
|
137
|
+
project.targets.build = getNestWebpackBuildConfig();
|
|
138
|
+
}
|
|
117
139
|
}
|
|
118
140
|
project.targets.serve = getServeConfig(options);
|
|
119
|
-
|
|
141
|
+
const packageJson = {
|
|
142
|
+
name: options.importPath,
|
|
143
|
+
version: '0.0.1',
|
|
144
|
+
private: true,
|
|
145
|
+
};
|
|
146
|
+
if (!options.useProjectJson) {
|
|
147
|
+
packageJson.nx = {
|
|
148
|
+
name: options.name !== options.importPath ? options.name : undefined,
|
|
149
|
+
targets: project.targets,
|
|
150
|
+
tags: project.tags?.length ? project.tags : undefined,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
(0, devkit_1.addProjectConfiguration)(tree, options.name, project, options.standaloneConfig);
|
|
155
|
+
}
|
|
156
|
+
if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
|
|
157
|
+
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
|
|
158
|
+
}
|
|
120
159
|
}
|
|
121
160
|
function addAppFiles(tree, options) {
|
|
122
|
-
const sourceRoot = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src');
|
|
123
161
|
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/common'), options.appProjectRoot, {
|
|
124
162
|
...options,
|
|
125
163
|
tmpl: '',
|
|
@@ -129,7 +167,9 @@ function addAppFiles(tree, options) {
|
|
|
129
167
|
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
|
|
130
168
|
webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)
|
|
131
169
|
? {
|
|
132
|
-
outputPath: options.
|
|
170
|
+
outputPath: options.isUsingTsSolutionConfig
|
|
171
|
+
? 'dist'
|
|
172
|
+
: (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.appProjectRoot), 'dist', options.rootProject ? options.name : options.appProjectRoot),
|
|
133
173
|
main: './src/main' + (options.js ? '.js' : '.ts'),
|
|
134
174
|
tsConfig: './tsconfig.app.json',
|
|
135
175
|
assets: ['./src/assets'],
|
|
@@ -152,16 +192,19 @@ function addAppFiles(tree, options) {
|
|
|
152
192
|
if (options.js) {
|
|
153
193
|
(0, devkit_1.toJS)(tree);
|
|
154
194
|
}
|
|
155
|
-
if (options.pascalCaseFiles) {
|
|
156
|
-
devkit_1.logger.warn('NOTE: --pascalCaseFiles is a noop');
|
|
157
|
-
}
|
|
158
195
|
}
|
|
159
196
|
function addProxy(tree, options) {
|
|
160
197
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.frontendProject);
|
|
161
|
-
if (projectConfig.targets &&
|
|
198
|
+
if (projectConfig.targets &&
|
|
199
|
+
['serve', 'dev'].find((t) => !!projectConfig.targets[t])) {
|
|
200
|
+
const targetName = ['serve', 'dev'].find((t) => !!projectConfig.targets[t]);
|
|
201
|
+
projectConfig.targets[targetName].dependsOn = [
|
|
202
|
+
...(projectConfig.targets[targetName].dependsOn ?? []),
|
|
203
|
+
`${options.name}:serve`,
|
|
204
|
+
];
|
|
162
205
|
const pathToProxyFile = `${projectConfig.root}/proxy.conf.json`;
|
|
163
|
-
projectConfig.targets.
|
|
164
|
-
...projectConfig.targets.
|
|
206
|
+
projectConfig.targets[targetName].options = {
|
|
207
|
+
...projectConfig.targets[targetName].options,
|
|
165
208
|
proxyConfig: pathToProxyFile,
|
|
166
209
|
};
|
|
167
210
|
if (!tree.exists(pathToProxyFile)) {
|
|
@@ -248,6 +291,9 @@ function addProjectDependencies(tree, options) {
|
|
|
248
291
|
});
|
|
249
292
|
}
|
|
250
293
|
function updateTsConfigOptions(tree, options) {
|
|
294
|
+
if (options.isUsingTsSolutionConfig) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
251
297
|
(0, devkit_1.updateJson)(tree, `${options.appProjectRoot}/tsconfig.json`, (json) => {
|
|
252
298
|
if (options.rootProject) {
|
|
253
299
|
return {
|
|
@@ -275,13 +321,20 @@ function updateTsConfigOptions(tree, options) {
|
|
|
275
321
|
async function applicationGenerator(tree, schema) {
|
|
276
322
|
return await applicationGeneratorInternal(tree, {
|
|
277
323
|
addPlugin: false,
|
|
278
|
-
|
|
324
|
+
useProjectJson: true,
|
|
279
325
|
...schema,
|
|
280
326
|
});
|
|
281
327
|
}
|
|
282
328
|
async function applicationGeneratorInternal(tree, schema) {
|
|
283
|
-
const options = await normalizeOptions(tree, schema);
|
|
284
329
|
const tasks = [];
|
|
330
|
+
const jsInitTask = await (0, js_1.initGenerator)(tree, {
|
|
331
|
+
...schema,
|
|
332
|
+
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
333
|
+
skipFormat: true,
|
|
334
|
+
addTsPlugin: schema.useTsSolution,
|
|
335
|
+
});
|
|
336
|
+
tasks.push(jsInitTask);
|
|
337
|
+
const options = await normalizeOptions(tree, schema);
|
|
285
338
|
if (options.framework === 'nest') {
|
|
286
339
|
// nx-ignore-next-line
|
|
287
340
|
const { applicationGenerator } = (0, devkit_1.ensurePackage)('@nx/nest', versions_2.nxVersion);
|
|
@@ -305,12 +358,6 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
|
305
358
|
},
|
|
306
359
|
]);
|
|
307
360
|
}
|
|
308
|
-
const jsInitTask = await (0, js_1.initGenerator)(tree, {
|
|
309
|
-
...schema,
|
|
310
|
-
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
311
|
-
skipFormat: true,
|
|
312
|
-
});
|
|
313
|
-
tasks.push(jsInitTask);
|
|
314
361
|
const initTask = await (0, init_1.initGenerator)(tree, {
|
|
315
362
|
...schema,
|
|
316
363
|
skipFormat: true,
|
|
@@ -335,8 +382,13 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
|
335
382
|
}
|
|
336
383
|
addAppFiles(tree, options);
|
|
337
384
|
addProject(tree, options);
|
|
385
|
+
// If we are using the new TS solution
|
|
386
|
+
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
|
387
|
+
if (options.isUsingTsSolutionConfig) {
|
|
388
|
+
await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
|
|
389
|
+
}
|
|
338
390
|
updateTsConfigOptions(tree, options);
|
|
339
|
-
if (options.linter ===
|
|
391
|
+
if (options.linter === 'eslint') {
|
|
340
392
|
const lintTask = await addLintingToApplication(tree, options);
|
|
341
393
|
tasks.push(lintTask);
|
|
342
394
|
}
|
|
@@ -352,6 +404,13 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
|
352
404
|
skipFormat: true,
|
|
353
405
|
});
|
|
354
406
|
tasks.push(jestTask);
|
|
407
|
+
// There are no tests by default, so set `--passWithNoTests` to avoid test failure on new project.
|
|
408
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.name);
|
|
409
|
+
projectConfig.targets ??= {};
|
|
410
|
+
projectConfig.targets.test = {
|
|
411
|
+
options: { passWithNoTests: true },
|
|
412
|
+
};
|
|
413
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.name, projectConfig);
|
|
355
414
|
}
|
|
356
415
|
else {
|
|
357
416
|
// No need for default spec file if unit testing is not setup.
|
|
@@ -363,7 +422,6 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
|
363
422
|
projectType: options.framework === 'none' ? 'cli' : 'server',
|
|
364
423
|
name: options.rootProject ? 'e2e' : `${options.name}-e2e`,
|
|
365
424
|
directory: options.rootProject ? 'e2e' : `${options.appProjectRoot}-e2e`,
|
|
366
|
-
projectNameAndRootFormat: 'as-provided',
|
|
367
425
|
project: options.name,
|
|
368
426
|
port: options.port,
|
|
369
427
|
isNest: options.isNest,
|
|
@@ -385,6 +443,15 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
|
385
443
|
});
|
|
386
444
|
tasks.push(dockerTask);
|
|
387
445
|
}
|
|
446
|
+
if (options.isUsingTsSolutionConfig) {
|
|
447
|
+
(0, ts_solution_setup_1.updateTsconfigFiles)(tree, options.appProjectRoot, 'tsconfig.app.json', {
|
|
448
|
+
module: 'nodenext',
|
|
449
|
+
moduleResolution: 'nodenext',
|
|
450
|
+
}, options.linter === 'eslint'
|
|
451
|
+
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
|
452
|
+
: undefined);
|
|
453
|
+
}
|
|
454
|
+
(0, sort_fields_1.sortPackageJsonFields)(tree, options.appProjectRoot);
|
|
388
455
|
if (!options.skipFormat) {
|
|
389
456
|
await (0, devkit_1.formatFiles)(tree);
|
|
390
457
|
}
|
|
@@ -394,16 +461,14 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
|
394
461
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
395
462
|
}
|
|
396
463
|
async function normalizeOptions(host, options) {
|
|
397
|
-
|
|
464
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
|
|
465
|
+
const { projectName, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
398
466
|
name: options.name,
|
|
399
467
|
projectType: 'application',
|
|
400
468
|
directory: options.directory,
|
|
401
|
-
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
402
469
|
rootProject: options.rootProject,
|
|
403
|
-
callingGenerator: '@nx/node:application',
|
|
404
470
|
});
|
|
405
471
|
options.rootProject = appProjectRoot === '.';
|
|
406
|
-
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
407
472
|
options.bundler = options.bundler ?? 'esbuild';
|
|
408
473
|
options.e2eTestRunner = options.e2eTestRunner ?? 'jest';
|
|
409
474
|
const parsedTags = options.tags
|
|
@@ -412,6 +477,10 @@ async function normalizeOptions(host, options) {
|
|
|
412
477
|
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
413
478
|
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
414
479
|
nxJson.useInferencePlugins !== false;
|
|
480
|
+
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
481
|
+
const swcJest = options.swcJest ?? isUsingTsSolutionConfig;
|
|
482
|
+
const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath;
|
|
483
|
+
const useProjectJson = options.useProjectJson ?? !isUsingTsSolutionConfig;
|
|
415
484
|
return {
|
|
416
485
|
addPlugin,
|
|
417
486
|
...options,
|
|
@@ -420,12 +489,18 @@ async function normalizeOptions(host, options) {
|
|
|
420
489
|
? (0, devkit_1.names)(options.frontendProject).fileName
|
|
421
490
|
: undefined,
|
|
422
491
|
appProjectRoot,
|
|
492
|
+
importPath,
|
|
423
493
|
parsedTags,
|
|
424
|
-
linter: options.linter ??
|
|
494
|
+
linter: options.linter ?? 'eslint',
|
|
425
495
|
unitTestRunner: options.unitTestRunner ?? 'jest',
|
|
426
496
|
rootProject: options.rootProject ?? false,
|
|
427
497
|
port: options.port ?? 3000,
|
|
428
|
-
outputPath:
|
|
498
|
+
outputPath: isUsingTsSolutionConfig
|
|
499
|
+
? (0, devkit_1.joinPathFragments)(appProjectRoot, 'dist')
|
|
500
|
+
: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? appProjectName : appProjectRoot),
|
|
501
|
+
isUsingTsSolutionConfig,
|
|
502
|
+
swcJest,
|
|
503
|
+
useProjectJson,
|
|
429
504
|
};
|
|
430
505
|
}
|
|
431
506
|
exports.default = applicationGenerator;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<% if (webpackPluginOptions) { %>
|
|
1
|
+
<%_ if (webpackPluginOptions) { _%>
|
|
2
2
|
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
|
|
3
3
|
const { join } = require('path');
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
6
|
output: {
|
|
7
|
-
path: join(__dirname, '<%=
|
|
7
|
+
path: join(__dirname, '<%= webpackPluginOptions.outputPath %>'),
|
|
8
8
|
},
|
|
9
9
|
plugins: [
|
|
10
10
|
new NxAppWebpackPlugin({
|
|
@@ -19,7 +19,7 @@ module.exports = {
|
|
|
19
19
|
})
|
|
20
20
|
],
|
|
21
21
|
};
|
|
22
|
-
<% } else { %>
|
|
22
|
+
<%_ } else { _%>
|
|
23
23
|
const { composePlugins, withNx} = require('@nx/webpack');
|
|
24
24
|
|
|
25
25
|
// Nx plugins for webpack.
|
|
@@ -33,4 +33,4 @@ module.exports = composePlugins(
|
|
|
33
33
|
return config;
|
|
34
34
|
}
|
|
35
35
|
);
|
|
36
|
-
<% } %>
|
|
36
|
+
<%_ } _%>
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
1
|
import type { Linter, LinterType } from '@nx/eslint';
|
|
3
2
|
|
|
4
3
|
export interface Schema {
|
|
5
|
-
|
|
4
|
+
directory: string;
|
|
5
|
+
name?: string;
|
|
6
6
|
skipFormat?: boolean;
|
|
7
7
|
skipPackageJson?: boolean;
|
|
8
|
-
directory?: string;
|
|
9
|
-
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
10
8
|
unitTestRunner?: 'jest' | 'none';
|
|
11
9
|
e2eTestRunner?: 'jest' | 'none';
|
|
12
10
|
linter?: Linter | LinterType;
|
|
11
|
+
formatter?: 'none' | 'prettier';
|
|
13
12
|
tags?: string;
|
|
14
13
|
frontendProject?: string;
|
|
15
14
|
swcJest?: boolean;
|
|
16
15
|
/** @deprecated use `swcJest` instead */
|
|
17
16
|
babelJest?: boolean;
|
|
18
17
|
js?: boolean;
|
|
19
|
-
pascalCaseFiles?: boolean;
|
|
20
18
|
setParserOptionsProject?: boolean;
|
|
21
19
|
standaloneConfig?: boolean;
|
|
22
20
|
bundler?: 'esbuild' | 'webpack';
|
|
@@ -26,6 +24,8 @@ export interface Schema {
|
|
|
26
24
|
docker?: boolean;
|
|
27
25
|
isNest?: boolean;
|
|
28
26
|
addPlugin?: boolean;
|
|
27
|
+
useTsSolution?: boolean;
|
|
28
|
+
useProjectJson?: boolean;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'nest' | 'none';
|
|
@@ -6,27 +6,21 @@
|
|
|
6
6
|
"description": "Nx Application Options Schema.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"properties": {
|
|
9
|
-
"
|
|
10
|
-
"description": "The
|
|
9
|
+
"directory": {
|
|
10
|
+
"description": "The directory of the new application.",
|
|
11
11
|
"type": "string",
|
|
12
12
|
"$default": {
|
|
13
13
|
"$source": "argv",
|
|
14
14
|
"index": 0
|
|
15
15
|
},
|
|
16
|
-
"x-prompt": "
|
|
17
|
-
"x-priority": "important",
|
|
18
|
-
"pattern": "^[a-zA-Z][^:]*$"
|
|
16
|
+
"x-prompt": "Which directory do you want to create the application in?"
|
|
19
17
|
},
|
|
20
|
-
"
|
|
21
|
-
"description": "The
|
|
18
|
+
"name": {
|
|
19
|
+
"description": "The name of the application.",
|
|
22
20
|
"type": "string",
|
|
21
|
+
"pattern": "^[a-zA-Z][^:]*$",
|
|
23
22
|
"x-priority": "important"
|
|
24
23
|
},
|
|
25
|
-
"projectNameAndRootFormat": {
|
|
26
|
-
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
|
|
27
|
-
"type": "string",
|
|
28
|
-
"enum": ["as-provided", "derived"]
|
|
29
|
-
},
|
|
30
24
|
"skipFormat": {
|
|
31
25
|
"description": "Skip formatting files",
|
|
32
26
|
"type": "boolean",
|
|
@@ -42,14 +36,26 @@
|
|
|
42
36
|
"linter": {
|
|
43
37
|
"description": "The tool to use for running lint checks.",
|
|
44
38
|
"type": "string",
|
|
45
|
-
"enum": ["eslint"],
|
|
46
|
-
"default": "
|
|
39
|
+
"enum": ["eslint", "none"],
|
|
40
|
+
"default": "none",
|
|
41
|
+
"x-prompt": "Which linter would you like to use?",
|
|
42
|
+
"x-priority": "important"
|
|
47
43
|
},
|
|
48
44
|
"unitTestRunner": {
|
|
49
45
|
"type": "string",
|
|
50
46
|
"enum": ["jest", "none"],
|
|
51
47
|
"description": "Test runner to use for unit tests.",
|
|
52
|
-
"default": "
|
|
48
|
+
"default": "none",
|
|
49
|
+
"x-priority": "important",
|
|
50
|
+
"x-prompt": "Which unit test runner would you like to use?"
|
|
51
|
+
},
|
|
52
|
+
"e2eTestRunner": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"enum": ["jest", "none"],
|
|
55
|
+
"description": "Test runner to use for end-to-end tests",
|
|
56
|
+
"default": "none",
|
|
57
|
+
"x-priority": "important",
|
|
58
|
+
"x-prompt": "Which end-to-end test runner would you like to use?"
|
|
53
59
|
},
|
|
54
60
|
"tags": {
|
|
55
61
|
"type": "string",
|
|
@@ -63,8 +69,7 @@
|
|
|
63
69
|
},
|
|
64
70
|
"swcJest": {
|
|
65
71
|
"type": "boolean",
|
|
66
|
-
"description": "Use `@swc/jest` instead `ts-jest` for faster test compilation."
|
|
67
|
-
"default": false
|
|
72
|
+
"description": "Use `@swc/jest` instead `ts-jest` for faster test compilation."
|
|
68
73
|
},
|
|
69
74
|
"babelJest": {
|
|
70
75
|
"type": "boolean",
|
|
@@ -72,12 +77,6 @@
|
|
|
72
77
|
"default": false,
|
|
73
78
|
"x-deprecated": "Use --swcJest instead for faster compilation"
|
|
74
79
|
},
|
|
75
|
-
"pascalCaseFiles": {
|
|
76
|
-
"type": "boolean",
|
|
77
|
-
"description": "Use pascal case file names.",
|
|
78
|
-
"alias": "P",
|
|
79
|
-
"default": false
|
|
80
|
-
},
|
|
81
80
|
"js": {
|
|
82
81
|
"type": "boolean",
|
|
83
82
|
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
@@ -121,16 +120,14 @@
|
|
|
121
120
|
"hidden": true,
|
|
122
121
|
"x-priority": "internal"
|
|
123
122
|
},
|
|
124
|
-
"e2eTestRunner": {
|
|
125
|
-
"type": "string",
|
|
126
|
-
"enum": ["jest", "none"],
|
|
127
|
-
"description": "Test runner to use for end to end (e2e) tests",
|
|
128
|
-
"default": "jest"
|
|
129
|
-
},
|
|
130
123
|
"docker": {
|
|
131
124
|
"type": "boolean",
|
|
132
125
|
"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."
|
|
133
130
|
}
|
|
134
131
|
},
|
|
135
|
-
"required": ["
|
|
132
|
+
"required": ["directory"]
|
|
136
133
|
}
|