@nx/node 21.2.0-beta.3 → 21.2.0-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/node",
3
- "version": "21.2.0-beta.3",
3
+ "version": "21.2.0-beta.5",
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,10 +32,10 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "tslib": "^2.3.0",
35
- "@nx/devkit": "21.2.0-beta.3",
36
- "@nx/jest": "21.2.0-beta.3",
37
- "@nx/js": "21.2.0-beta.3",
38
- "@nx/eslint": "21.2.0-beta.3",
35
+ "@nx/devkit": "21.2.0-beta.5",
36
+ "@nx/jest": "21.2.0-beta.5",
37
+ "@nx/js": "21.2.0-beta.5",
38
+ "@nx/eslint": "21.2.0-beta.5",
39
39
  "tcp-port-used": "^1.0.2",
40
40
  "kill-port": "^1.6.1"
41
41
  },
@@ -1,13 +1,5 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
- export interface NormalizedSchema extends Omit<Schema, 'useTsSolution'> {
4
- appProjectRoot: string;
5
- parsedTags: string[];
6
- outputPath: string;
7
- importPath: string;
8
- isUsingTsSolutionConfig: boolean;
9
- }
10
- export declare function addLintingToApplication(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
11
3
  export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
12
4
  export declare function applicationGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
13
5
  export default applicationGenerator;
@@ -1,297 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addLintingToApplication = addLintingToApplication;
4
3
  exports.applicationGenerator = applicationGenerator;
5
4
  exports.applicationGeneratorInternal = applicationGeneratorInternal;
6
5
  const devkit_1 = require("@nx/devkit");
7
- const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
8
6
  const jest_1 = require("@nx/jest");
9
7
  const js_1 = require("@nx/js");
10
- const versions_1 = require("@nx/js/src/utils/versions");
11
- const eslint_1 = require("@nx/eslint");
12
- const path_1 = require("path");
13
- const versions_2 = require("../../utils/versions");
8
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
9
+ const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
10
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
11
+ const versions_1 = require("../../utils/versions");
14
12
  const e2e_project_1 = require("../e2e-project/e2e-project");
15
13
  const init_1 = require("../init/init");
16
14
  const setup_docker_1 = require("../setup-docker/setup-docker");
17
- const has_webpack_plugin_1 = require("../../utils/has-webpack-plugin");
18
- const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
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");
22
- function getWebpackBuildConfig(project, options) {
23
- return {
24
- executor: `@nx/webpack:webpack`,
25
- outputs: ['{options.outputPath}'],
26
- defaultConfiguration: 'production',
27
- options: {
28
- target: 'node',
29
- compiler: 'tsc',
30
- outputPath: options.outputPath,
31
- main: (0, devkit_1.joinPathFragments)(project.sourceRoot, 'main' + (options.js ? '.js' : '.ts')),
32
- tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
33
- assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
34
- webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
35
- generatePackageJson: options.isUsingTsSolutionConfig ? undefined : true,
36
- },
37
- configurations: {
38
- development: {
39
- outputHashing: 'none',
40
- },
41
- production: {
42
- ...(options.docker && { generateLockfile: true }),
43
- },
44
- },
45
- };
46
- }
47
- function getEsBuildConfig(project, options) {
48
- return {
49
- executor: '@nx/esbuild:esbuild',
50
- outputs: ['{options.outputPath}'],
51
- defaultConfiguration: 'production',
52
- options: {
53
- platform: 'node',
54
- outputPath: options.outputPath,
55
- // Use CJS for Node apps for widest compatibility.
56
- format: ['cjs'],
57
- bundle: false,
58
- main: (0, devkit_1.joinPathFragments)(project.sourceRoot, 'main' + (options.js ? '.js' : '.ts')),
59
- tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
60
- assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
61
- generatePackageJson: options.isUsingTsSolutionConfig ? undefined : true,
62
- esbuildOptions: {
63
- sourcemap: true,
64
- // Generate CJS files as .js so imports can be './foo' rather than './foo.cjs'.
65
- outExtension: { '.js': '.js' },
66
- },
67
- },
68
- configurations: {
69
- development: {},
70
- production: {
71
- ...(options.docker && { generateLockfile: true }),
72
- esbuildOptions: {
73
- sourcemap: false,
74
- // Generate CJS files as .js so imports can be './foo' rather than './foo.cjs'.
75
- outExtension: { '.js': '.js' },
76
- },
77
- },
78
- },
79
- };
80
- }
81
- function getServeConfig(options) {
82
- return {
83
- continuous: true,
84
- executor: '@nx/js:node',
85
- defaultConfiguration: 'development',
86
- // Run build, which includes dependency on "^build" by default, so the first run
87
- // won't error out due to missing build artifacts.
88
- dependsOn: ['build'],
89
- options: {
90
- buildTarget: `${options.name}:build`,
91
- // Even though `false` is the default, set this option so users know it
92
- // exists if they want to always run dependencies during each rebuild.
93
- runBuildTargetDependencies: false,
94
- },
95
- configurations: {
96
- development: {
97
- buildTarget: `${options.name}:build:development`,
98
- },
99
- production: {
100
- buildTarget: `${options.name}:build:production`,
101
- },
102
- },
103
- };
104
- }
105
- function getNestWebpackBuildConfig() {
106
- return {
107
- executor: 'nx:run-commands',
108
- options: {
109
- command: 'webpack-cli build',
110
- args: ['node-env=production'],
111
- },
112
- configurations: {
113
- development: {
114
- args: ['node-env=development'],
115
- },
116
- },
117
- };
118
- }
119
- function addProject(tree, options) {
120
- const project = {
121
- root: options.appProjectRoot,
122
- sourceRoot: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src'),
123
- projectType: 'application',
124
- targets: {},
125
- tags: options.parsedTags,
126
- };
127
- if (options.bundler === 'esbuild') {
128
- (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, '@nx/esbuild:esbuild');
129
- project.targets.build = getEsBuildConfig(project, options);
130
- }
131
- else if (options.bundler === 'webpack') {
132
- if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(tree) && options.addPlugin === false) {
133
- (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, `@nx/webpack:webpack`);
134
- project.targets.build = getWebpackBuildConfig(project, options);
135
- }
136
- else if (options.isNest) {
137
- // If we are using Nest that has the webpack plugin we need to override the
138
- // build target so that node-env can be set to production or development so the serve target can be run in development mode
139
- project.targets.build = getNestWebpackBuildConfig();
140
- }
141
- }
142
- project.targets.serve = getServeConfig(options);
143
- const packageJson = {
144
- name: options.importPath,
145
- version: '0.0.1',
146
- private: true,
147
- };
148
- if (!options.useProjectJson) {
149
- packageJson.nx = {
150
- name: options.name !== options.importPath ? options.name : undefined,
151
- targets: project.targets,
152
- tags: project.tags?.length ? project.tags : undefined,
153
- };
154
- }
155
- else {
156
- (0, devkit_1.addProjectConfiguration)(tree, options.name, project, options.standaloneConfig);
157
- }
158
- if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
159
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
160
- }
161
- }
162
- function addAppFiles(tree, options) {
163
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/common'), options.appProjectRoot, {
164
- ...options,
165
- tmpl: '',
166
- name: options.name,
167
- root: options.appProjectRoot,
168
- offset: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
169
- rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
170
- webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree) && options.addPlugin !== false
171
- ? {
172
- outputPath: options.isUsingTsSolutionConfig
173
- ? 'dist'
174
- : (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.appProjectRoot), 'dist', options.rootProject ? options.name : options.appProjectRoot),
175
- main: './src/main' + (options.js ? '.js' : '.ts'),
176
- tsConfig: './tsconfig.app.json',
177
- assets: ['./src/assets'],
178
- }
179
- : null,
180
- });
181
- if (options.bundler !== 'webpack') {
182
- tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'));
183
- }
184
- if (options.framework && options.framework !== 'none') {
185
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, `./files/${options.framework}`), options.appProjectRoot, {
186
- ...options,
187
- tmpl: '',
188
- name: options.name,
189
- root: options.appProjectRoot,
190
- offset: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
191
- rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
192
- });
193
- }
194
- if (options.js) {
195
- (0, devkit_1.toJS)(tree);
196
- }
197
- }
198
- function addProxy(tree, options) {
199
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.frontendProject);
200
- if (projectConfig.targets &&
201
- ['serve', 'dev'].find((t) => !!projectConfig.targets[t])) {
202
- const targetName = ['serve', 'dev'].find((t) => !!projectConfig.targets[t]);
203
- projectConfig.targets[targetName].dependsOn = [
204
- ...(projectConfig.targets[targetName].dependsOn ?? []),
205
- `${options.name}:serve`,
206
- ];
207
- const pathToProxyFile = `${projectConfig.root}/proxy.conf.json`;
208
- projectConfig.targets[targetName].options = {
209
- ...projectConfig.targets[targetName].options,
210
- proxyConfig: pathToProxyFile,
211
- };
212
- if (!tree.exists(pathToProxyFile)) {
213
- tree.write(pathToProxyFile, JSON.stringify({
214
- '/api': {
215
- target: `http://localhost:${options.port}`,
216
- secure: false,
217
- },
218
- }, null, 2));
219
- }
220
- else {
221
- //add new entry to existing config
222
- const proxyFileContent = tree.read(pathToProxyFile).toString();
223
- const proxyModified = {
224
- ...JSON.parse(proxyFileContent),
225
- [`/${options.name}-api`]: {
226
- target: `http://localhost:${options.port}`,
227
- secure: false,
228
- },
229
- };
230
- tree.write(pathToProxyFile, JSON.stringify(proxyModified, null, 2));
231
- }
232
- (0, devkit_1.updateProjectConfiguration)(tree, options.frontendProject, projectConfig);
233
- }
234
- else {
235
- devkit_1.logger.warn(`Skip updating proxy for frontend project "${options.frontendProject}" since "serve" target is not found in project.json. For more information, see: https://nx.dev/recipes/node/application-proxies.`);
236
- }
237
- }
238
- async function addLintingToApplication(tree, options) {
239
- const lintTask = await (0, eslint_1.lintProjectGenerator)(tree, {
240
- linter: options.linter,
241
- project: options.name,
242
- tsConfigPaths: [
243
- (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
244
- ],
245
- unitTestRunner: options.unitTestRunner,
246
- skipFormat: true,
247
- setParserOptionsProject: options.setParserOptionsProject,
248
- rootProject: options.rootProject,
249
- addPlugin: options.addPlugin,
250
- });
251
- return lintTask;
252
- }
253
- function addProjectDependencies(tree, options) {
254
- const bundlers = {
255
- webpack: {
256
- '@nx/webpack': versions_2.nxVersion,
257
- },
258
- esbuild: {
259
- '@nx/esbuild': versions_2.nxVersion,
260
- esbuild: versions_1.esbuildVersion,
261
- },
262
- };
263
- const frameworkDependencies = {
264
- express: {
265
- express: versions_2.expressVersion,
266
- },
267
- koa: {
268
- koa: versions_2.koaVersion,
269
- },
270
- fastify: {
271
- fastify: versions_2.fastifyVersion,
272
- 'fastify-plugin': versions_2.fastifyPluginVersion,
273
- '@fastify/autoload': versions_2.fastifyAutoloadVersion,
274
- '@fastify/sensible': versions_2.fastifySensibleVersion,
275
- },
276
- };
277
- const frameworkDevDependencies = {
278
- express: {
279
- '@types/express': versions_2.expressTypingsVersion,
280
- },
281
- koa: {
282
- '@types/koa': versions_2.koaTypingsVersion,
283
- },
284
- fastify: {},
285
- };
286
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {
287
- ...frameworkDependencies[options.framework],
288
- tslib: versions_2.tslibVersion,
289
- }, {
290
- ...frameworkDevDependencies[options.framework],
291
- ...bundlers[options.bundler],
292
- '@types/node': versions_2.typesNodeVersion,
293
- });
294
- }
15
+ const lib_1 = require("./lib");
295
16
  function updateTsConfigOptions(tree, options) {
296
17
  if (options.isUsingTsSolutionConfig) {
297
18
  return;
@@ -336,10 +57,10 @@ async function applicationGeneratorInternal(tree, schema) {
336
57
  addTsPlugin: schema.useTsSolution,
337
58
  });
338
59
  tasks.push(jsInitTask);
339
- const options = await normalizeOptions(tree, schema);
60
+ const options = await (0, lib_1.normalizeOptions)(tree, schema);
340
61
  if (options.framework === 'nest') {
341
62
  // nx-ignore-next-line
342
- const { applicationGenerator } = (0, devkit_1.ensurePackage)('@nx/nest', versions_2.nxVersion);
63
+ const { applicationGenerator } = (0, devkit_1.ensurePackage)('@nx/nest', versions_1.nxVersion);
343
64
  const nestTasks = await applicationGenerator(tree, {
344
65
  ...options,
345
66
  skipFormat: true,
@@ -365,10 +86,10 @@ async function applicationGeneratorInternal(tree, schema) {
365
86
  skipFormat: true,
366
87
  });
367
88
  tasks.push(initTask);
368
- const installTask = addProjectDependencies(tree, options);
89
+ const installTask = (0, lib_1.addProjectDependencies)(tree, options);
369
90
  tasks.push(installTask);
370
91
  if (options.bundler === 'webpack') {
371
- const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_2.nxVersion);
92
+ const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
372
93
  const webpackInitTask = await webpackInitGenerator(tree, {
373
94
  skipPackageJson: options.skipPackageJson,
374
95
  skipFormat: true,
@@ -382,8 +103,8 @@ async function applicationGeneratorInternal(tree, schema) {
382
103
  }));
383
104
  }
384
105
  }
385
- addAppFiles(tree, options);
386
- addProject(tree, options);
106
+ (0, lib_1.addAppFiles)(tree, options);
107
+ (0, lib_1.addProject)(tree, options);
387
108
  // If we are using the new TS solution
388
109
  // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
389
110
  if (options.isUsingTsSolutionConfig) {
@@ -391,7 +112,7 @@ async function applicationGeneratorInternal(tree, schema) {
391
112
  }
392
113
  updateTsConfigOptions(tree, options);
393
114
  if (options.linter === 'eslint') {
394
- const lintTask = await addLintingToApplication(tree, options);
115
+ const lintTask = await (0, lib_1.addLintingToApplication)(tree, options);
395
116
  tasks.push(lintTask);
396
117
  }
397
118
  if (options.unitTestRunner === 'jest') {
@@ -435,7 +156,7 @@ async function applicationGeneratorInternal(tree, schema) {
435
156
  (0, devkit_1.updateTsConfigsToJs)(tree, { projectRoot: options.appProjectRoot });
436
157
  }
437
158
  if (options.frontendProject) {
438
- addProxy(tree, options);
159
+ (0, lib_1.addProxy)(tree, options);
439
160
  }
440
161
  if (options.docker) {
441
162
  const dockerTask = await (0, setup_docker_1.setupDockerGenerator)(tree, {
@@ -462,47 +183,4 @@ async function applicationGeneratorInternal(tree, schema) {
462
183
  });
463
184
  return (0, devkit_1.runTasksInSerial)(...tasks);
464
185
  }
465
- async function normalizeOptions(host, options) {
466
- await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
467
- const { projectName, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
468
- name: options.name,
469
- projectType: 'application',
470
- directory: options.directory,
471
- rootProject: options.rootProject,
472
- });
473
- options.rootProject = appProjectRoot === '.';
474
- options.bundler = options.bundler ?? 'esbuild';
475
- options.e2eTestRunner = options.e2eTestRunner ?? 'jest';
476
- const parsedTags = options.tags
477
- ? options.tags.split(',').map((s) => s.trim())
478
- : [];
479
- const nxJson = (0, devkit_1.readNxJson)(host);
480
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
481
- nxJson.useInferencePlugins !== false;
482
- const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
483
- const swcJest = options.swcJest ?? isUsingTsSolutionConfig;
484
- const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath;
485
- const useProjectJson = options.useProjectJson ?? !isUsingTsSolutionConfig;
486
- return {
487
- addPlugin,
488
- ...options,
489
- name: appProjectName,
490
- frontendProject: options.frontendProject
491
- ? (0, devkit_1.names)(options.frontendProject).fileName
492
- : undefined,
493
- appProjectRoot,
494
- importPath,
495
- parsedTags,
496
- linter: options.linter ?? 'eslint',
497
- unitTestRunner: options.unitTestRunner ?? 'jest',
498
- rootProject: options.rootProject ?? false,
499
- port: options.port ?? 3000,
500
- outputPath: isUsingTsSolutionConfig
501
- ? (0, devkit_1.joinPathFragments)(appProjectRoot, 'dist')
502
- : (0, devkit_1.joinPathFragments)('dist', options.rootProject ? appProjectName : appProjectRoot),
503
- isUsingTsSolutionConfig,
504
- swcJest,
505
- useProjectJson,
506
- };
507
- }
508
186
  exports.default = applicationGenerator;
@@ -0,0 +1,3 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from './normalized-schema';
3
+ export declare function addProjectDependencies(tree: Tree, options: NormalizedSchema): GeneratorCallback;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addProjectDependencies = addProjectDependencies;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("@nx/js/src/utils/versions");
6
+ const versions_2 = require("../../../utils/versions");
7
+ function addProjectDependencies(tree, options) {
8
+ const bundlers = {
9
+ webpack: {
10
+ '@nx/webpack': versions_2.nxVersion,
11
+ },
12
+ esbuild: {
13
+ '@nx/esbuild': versions_2.nxVersion,
14
+ esbuild: versions_1.esbuildVersion,
15
+ },
16
+ };
17
+ const frameworkDependencies = {
18
+ express: {
19
+ express: versions_2.expressVersion,
20
+ },
21
+ koa: {
22
+ koa: versions_2.koaVersion,
23
+ },
24
+ fastify: {
25
+ fastify: versions_2.fastifyVersion,
26
+ 'fastify-plugin': versions_2.fastifyPluginVersion,
27
+ '@fastify/autoload': versions_2.fastifyAutoloadVersion,
28
+ '@fastify/sensible': versions_2.fastifySensibleVersion,
29
+ },
30
+ };
31
+ const frameworkDevDependencies = {
32
+ express: {
33
+ '@types/express': versions_2.expressTypingsVersion,
34
+ },
35
+ koa: {
36
+ '@types/koa': versions_2.koaTypingsVersion,
37
+ },
38
+ fastify: {},
39
+ };
40
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {
41
+ ...frameworkDependencies[options.framework],
42
+ tslib: versions_2.tslibVersion,
43
+ }, {
44
+ ...frameworkDevDependencies[options.framework],
45
+ ...bundlers[options.bundler],
46
+ '@types/node': versions_2.typesNodeVersion,
47
+ });
48
+ }
@@ -0,0 +1,3 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from './normalized-schema';
3
+ export declare function addLintingToApplication(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addLintingToApplication = addLintingToApplication;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const eslint_1 = require("@nx/eslint");
6
+ async function addLintingToApplication(tree, options) {
7
+ const lintTask = await (0, eslint_1.lintProjectGenerator)(tree, {
8
+ linter: options.linter,
9
+ project: options.name,
10
+ tsConfigPaths: [
11
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
12
+ ],
13
+ unitTestRunner: options.unitTestRunner,
14
+ skipFormat: true,
15
+ setParserOptionsProject: options.setParserOptionsProject,
16
+ rootProject: options.rootProject,
17
+ addPlugin: options.addPlugin,
18
+ });
19
+ return lintTask;
20
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from './normalized-schema';
3
+ export declare function addProxy(tree: Tree, options: NormalizedSchema): void;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addProxy = addProxy;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function addProxy(tree, options) {
6
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.frontendProject);
7
+ if (projectConfig.targets &&
8
+ ['serve', 'dev'].find((t) => !!projectConfig.targets[t])) {
9
+ const targetName = ['serve', 'dev'].find((t) => !!projectConfig.targets[t]);
10
+ projectConfig.targets[targetName].dependsOn = [
11
+ ...(projectConfig.targets[targetName].dependsOn ?? []),
12
+ `${options.name}:serve`,
13
+ ];
14
+ const pathToProxyFile = `${projectConfig.root}/proxy.conf.json`;
15
+ projectConfig.targets[targetName].options = {
16
+ ...projectConfig.targets[targetName].options,
17
+ proxyConfig: pathToProxyFile,
18
+ };
19
+ if (!tree.exists(pathToProxyFile)) {
20
+ tree.write(pathToProxyFile, JSON.stringify({
21
+ '/api': {
22
+ target: `http://localhost:${options.port}`,
23
+ secure: false,
24
+ },
25
+ }, null, 2));
26
+ }
27
+ else {
28
+ //add new entry to existing config
29
+ const proxyFileContent = tree.read(pathToProxyFile).toString();
30
+ const proxyModified = {
31
+ ...JSON.parse(proxyFileContent),
32
+ [`/${options.name}-api`]: {
33
+ target: `http://localhost:${options.port}`,
34
+ secure: false,
35
+ },
36
+ };
37
+ tree.write(pathToProxyFile, JSON.stringify(proxyModified, null, 2));
38
+ }
39
+ (0, devkit_1.updateProjectConfiguration)(tree, options.frontendProject, projectConfig);
40
+ }
41
+ else {
42
+ devkit_1.logger.warn(`Skip updating proxy for frontend project "${options.frontendProject}" since "serve" target is not found in project.json. For more information, see: https://nx.dev/recipes/node/application-proxies.`);
43
+ }
44
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from './normalized-schema';
3
+ export declare function addAppFiles(tree: Tree, options: NormalizedSchema): void;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAppFiles = addAppFiles;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
6
+ const path_1 = require("path");
7
+ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
8
+ function addAppFiles(tree, options) {
9
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, '../files/common'), options.appProjectRoot, {
10
+ ...options,
11
+ tmpl: '',
12
+ name: options.name,
13
+ root: options.appProjectRoot,
14
+ offset: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
15
+ rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
16
+ webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree) && options.addPlugin !== false
17
+ ? {
18
+ outputPath: options.isUsingTsSolutionConfig
19
+ ? 'dist'
20
+ : (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.appProjectRoot), 'dist', options.rootProject ? options.name : options.appProjectRoot),
21
+ main: './src/main' + (options.js ? '.js' : '.ts'),
22
+ tsConfig: './tsconfig.app.json',
23
+ assets: ['./src/assets'],
24
+ }
25
+ : null,
26
+ });
27
+ if (options.bundler !== 'webpack') {
28
+ tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'));
29
+ }
30
+ if (options.framework && options.framework !== 'none') {
31
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, `../files/${options.framework}`), options.appProjectRoot, {
32
+ ...options,
33
+ tmpl: '',
34
+ name: options.name,
35
+ root: options.appProjectRoot,
36
+ offset: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
37
+ rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
38
+ });
39
+ }
40
+ if (options.js) {
41
+ (0, devkit_1.toJS)(tree);
42
+ }
43
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from './normalized-schema';
3
+ export declare function addProject(tree: Tree, options: NormalizedSchema): void;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addProject = addProject;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
6
+ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
7
+ const create_targets_1 = require("./create-targets");
8
+ function addProject(tree, options) {
9
+ const project = {
10
+ root: options.appProjectRoot,
11
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src'),
12
+ projectType: 'application',
13
+ targets: {},
14
+ tags: options.parsedTags,
15
+ };
16
+ if (options.bundler === 'esbuild') {
17
+ (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, '@nx/esbuild:esbuild');
18
+ project.targets.build = (0, create_targets_1.getEsBuildConfig)(project, options);
19
+ }
20
+ else if (options.bundler === 'webpack') {
21
+ if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(tree) && options.addPlugin === false) {
22
+ (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, `@nx/webpack:webpack`);
23
+ project.targets.build = (0, create_targets_1.getWebpackBuildConfig)(project, options);
24
+ }
25
+ else if (options.isNest) {
26
+ // If we are using Nest that has the webpack plugin we need to override the
27
+ // build target so that node-env can be set to production or development so the serve target can be run in development mode
28
+ project.targets.build = (0, create_targets_1.getNestWebpackBuildConfig)();
29
+ }
30
+ }
31
+ project.targets.serve = (0, create_targets_1.getServeConfig)(options);
32
+ const packageJson = {
33
+ name: options.importPath,
34
+ version: '0.0.1',
35
+ private: true,
36
+ };
37
+ if (!options.useProjectJson) {
38
+ packageJson.nx = {
39
+ name: options.name !== options.importPath ? options.name : undefined,
40
+ targets: project.targets,
41
+ tags: project.tags?.length ? project.tags : undefined,
42
+ };
43
+ }
44
+ else {
45
+ (0, devkit_1.addProjectConfiguration)(tree, options.name, project, options.standaloneConfig);
46
+ }
47
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
48
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
49
+ }
50
+ }
@@ -0,0 +1,6 @@
1
+ import { ProjectConfiguration, TargetConfiguration } from '@nx/devkit';
2
+ import { NormalizedSchema } from './normalized-schema';
3
+ export declare function getWebpackBuildConfig(project: ProjectConfiguration, options: NormalizedSchema): TargetConfiguration;
4
+ export declare function getEsBuildConfig(project: ProjectConfiguration, options: NormalizedSchema): TargetConfiguration;
5
+ export declare function getServeConfig(options: NormalizedSchema): TargetConfiguration;
6
+ export declare function getNestWebpackBuildConfig(): TargetConfiguration;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWebpackBuildConfig = getWebpackBuildConfig;
4
+ exports.getEsBuildConfig = getEsBuildConfig;
5
+ exports.getServeConfig = getServeConfig;
6
+ exports.getNestWebpackBuildConfig = getNestWebpackBuildConfig;
7
+ const devkit_1 = require("@nx/devkit");
8
+ function getWebpackBuildConfig(project, options) {
9
+ return {
10
+ executor: `@nx/webpack:webpack`,
11
+ outputs: ['{options.outputPath}'],
12
+ defaultConfiguration: 'production',
13
+ options: {
14
+ target: 'node',
15
+ compiler: 'tsc',
16
+ outputPath: options.outputPath,
17
+ main: (0, devkit_1.joinPathFragments)(project.sourceRoot, 'main' + (options.js ? '.js' : '.ts')),
18
+ tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
19
+ assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
20
+ webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
21
+ generatePackageJson: options.isUsingTsSolutionConfig ? undefined : true,
22
+ },
23
+ configurations: {
24
+ development: {
25
+ outputHashing: 'none',
26
+ },
27
+ production: {
28
+ ...(options.docker && { generateLockfile: true }),
29
+ },
30
+ },
31
+ };
32
+ }
33
+ function getEsBuildConfig(project, options) {
34
+ return {
35
+ executor: '@nx/esbuild:esbuild',
36
+ outputs: ['{options.outputPath}'],
37
+ defaultConfiguration: 'production',
38
+ options: {
39
+ platform: 'node',
40
+ outputPath: options.outputPath,
41
+ // Use CJS for Node apps for widest compatibility.
42
+ format: ['cjs'],
43
+ bundle: false,
44
+ main: (0, devkit_1.joinPathFragments)(project.sourceRoot, 'main' + (options.js ? '.js' : '.ts')),
45
+ tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
46
+ assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
47
+ generatePackageJson: options.isUsingTsSolutionConfig ? undefined : true,
48
+ esbuildOptions: {
49
+ sourcemap: true,
50
+ // Generate CJS files as .js so imports can be './foo' rather than './foo.cjs'.
51
+ outExtension: { '.js': '.js' },
52
+ },
53
+ },
54
+ configurations: {
55
+ development: {},
56
+ production: {
57
+ ...(options.docker && { generateLockfile: true }),
58
+ esbuildOptions: {
59
+ sourcemap: false,
60
+ // Generate CJS files as .js so imports can be './foo' rather than './foo.cjs'.
61
+ outExtension: { '.js': '.js' },
62
+ },
63
+ },
64
+ },
65
+ };
66
+ }
67
+ function getServeConfig(options) {
68
+ return {
69
+ continuous: true,
70
+ executor: '@nx/js:node',
71
+ defaultConfiguration: 'development',
72
+ // Run build, which includes dependency on "^build" by default, so the first run
73
+ // won't error out due to missing build artifacts.
74
+ dependsOn: ['build'],
75
+ options: {
76
+ buildTarget: `${options.name}:build`,
77
+ // Even though `false` is the default, set this option so users know it
78
+ // exists if they want to always run dependencies during each rebuild.
79
+ runBuildTargetDependencies: false,
80
+ },
81
+ configurations: {
82
+ development: {
83
+ buildTarget: `${options.name}:build:development`,
84
+ },
85
+ production: {
86
+ buildTarget: `${options.name}:build:production`,
87
+ },
88
+ },
89
+ };
90
+ }
91
+ function getNestWebpackBuildConfig() {
92
+ return {
93
+ executor: 'nx:run-commands',
94
+ options: {
95
+ command: 'webpack-cli build',
96
+ args: ['node-env=production'],
97
+ },
98
+ configurations: {
99
+ development: {
100
+ args: ['node-env=development'],
101
+ },
102
+ },
103
+ };
104
+ }
@@ -0,0 +1,8 @@
1
+ export * from './normalized-schema';
2
+ export * from './normalize-options';
3
+ export * from './create-targets';
4
+ export * from './create-project';
5
+ export * from './create-files';
6
+ export * from './add-dependencies';
7
+ export * from './add-linting';
8
+ export * from './add-proxy';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./normalized-schema"), exports);
5
+ tslib_1.__exportStar(require("./normalize-options"), exports);
6
+ tslib_1.__exportStar(require("./create-targets"), exports);
7
+ tslib_1.__exportStar(require("./create-project"), exports);
8
+ tslib_1.__exportStar(require("./create-files"), exports);
9
+ tslib_1.__exportStar(require("./add-dependencies"), exports);
10
+ tslib_1.__exportStar(require("./add-linting"), exports);
11
+ tslib_1.__exportStar(require("./add-proxy"), exports);
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { Schema } from '../schema';
3
+ import { NormalizedSchema } from './normalized-schema';
4
+ export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = normalizeOptions;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
+ async function normalizeOptions(host, options) {
8
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
9
+ const { projectName, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
+ name: options.name,
11
+ projectType: 'application',
12
+ directory: options.directory,
13
+ rootProject: options.rootProject,
14
+ });
15
+ options.rootProject = appProjectRoot === '.';
16
+ options.bundler = options.bundler ?? 'esbuild';
17
+ options.e2eTestRunner = options.e2eTestRunner ?? 'jest';
18
+ const parsedTags = options.tags
19
+ ? options.tags.split(',').map((s) => s.trim())
20
+ : [];
21
+ const nxJson = (0, devkit_1.readNxJson)(host);
22
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
23
+ nxJson.useInferencePlugins !== false;
24
+ const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
25
+ const swcJest = options.swcJest ?? isUsingTsSolutionConfig;
26
+ const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath;
27
+ const useProjectJson = options.useProjectJson ?? !isUsingTsSolutionConfig;
28
+ return {
29
+ addPlugin,
30
+ ...options,
31
+ name: appProjectName,
32
+ frontendProject: options.frontendProject
33
+ ? (0, devkit_1.names)(options.frontendProject).fileName
34
+ : undefined,
35
+ appProjectRoot,
36
+ importPath,
37
+ parsedTags,
38
+ linter: options.linter ?? 'eslint',
39
+ unitTestRunner: options.unitTestRunner ?? 'jest',
40
+ rootProject: options.rootProject ?? false,
41
+ port: options.port ?? 3000,
42
+ outputPath: isUsingTsSolutionConfig
43
+ ? (0, devkit_1.joinPathFragments)(appProjectRoot, 'dist')
44
+ : (0, devkit_1.joinPathFragments)('dist', options.rootProject ? appProjectName : appProjectRoot),
45
+ isUsingTsSolutionConfig,
46
+ swcJest,
47
+ useProjectJson,
48
+ };
49
+ }
@@ -0,0 +1,8 @@
1
+ import { Schema } from '../schema';
2
+ export interface NormalizedSchema extends Omit<Schema, 'useTsSolution'> {
3
+ appProjectRoot: string;
4
+ parsedTags: string[];
5
+ outputPath: string;
6
+ importPath: string;
7
+ isUsingTsSolutionConfig: boolean;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });