@nx/node 20.3.0-canary.20241212-0d1c960 → 20.3.0-canary.20241213-0d6667d
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 +5 -5
- package/src/generators/application/application.d.ts +1 -0
- package/src/generators/application/application.js +45 -13
- package/src/generators/application/schema.d.ts +2 -0
- package/src/generators/application/schema.json +15 -9
- package/src/generators/e2e-project/e2e-project.js +74 -14
- package/src/generators/e2e-project/files/cli/jest.config.ts__tmpl__ +1 -1
- package/src/generators/e2e-project/files/server/common/jest.config.ts__tmpl__ +1 -1
- package/src/generators/e2e-project/files/ts-solution/tsconfig.json__tmpl__ +16 -0
- package/src/generators/init/init.js +0 -2
- 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 +48 -28
- package/src/generators/library/schema.json +8 -4
- 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/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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/node",
|
3
|
-
"version": "20.3.0-canary.
|
3
|
+
"version": "20.3.0-canary.20241213-0d6667d",
|
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": "20.3.0-canary.
|
36
|
-
"@nx/jest": "20.3.0-canary.
|
37
|
-
"@nx/js": "20.3.0-canary.
|
38
|
-
"@nx/eslint": "20.3.0-canary.
|
35
|
+
"@nx/devkit": "20.3.0-canary.20241213-0d6667d",
|
36
|
+
"@nx/jest": "20.3.0-canary.20241213-0d6667d",
|
37
|
+
"@nx/js": "20.3.0-canary.20241213-0d6667d",
|
38
|
+
"@nx/eslint": "20.3.0-canary.20241213-0d6667d"
|
39
39
|
},
|
40
40
|
"publishConfig": {
|
41
41
|
"access": "public"
|
@@ -4,6 +4,7 @@ export interface NormalizedSchema extends Schema {
|
|
4
4
|
appProjectRoot: string;
|
5
5
|
parsedTags: string[];
|
6
6
|
outputPath: string;
|
7
|
+
isUsingTsSolutionConfig: boolean;
|
7
8
|
}
|
8
9
|
export declare function addLintingToApplication(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
|
9
10
|
export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addLintingToApplication = addLintingToApplication;
|
4
4
|
exports.applicationGenerator = applicationGenerator;
|
5
5
|
exports.applicationGeneratorInternal = applicationGeneratorInternal;
|
6
|
+
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
6
7
|
const devkit_1 = require("@nx/devkit");
|
7
8
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
8
9
|
const jest_1 = require("@nx/jest");
|
9
10
|
const js_1 = require("@nx/js");
|
10
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
11
11
|
const versions_1 = require("@nx/js/src/utils/versions");
|
12
12
|
const eslint_1 = require("@nx/eslint");
|
13
13
|
const path_1 = require("path");
|
@@ -18,6 +18,7 @@ const setup_docker_1 = require("../setup-docker/setup-docker");
|
|
18
18
|
const has_webpack_plugin_1 = require("../../utils/has-webpack-plugin");
|
19
19
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
20
20
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
21
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
21
22
|
function getWebpackBuildConfig(project, options) {
|
22
23
|
return {
|
23
24
|
executor: `@nx/webpack:webpack`,
|
@@ -31,7 +32,7 @@ function getWebpackBuildConfig(project, options) {
|
|
31
32
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
32
33
|
assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
|
33
34
|
webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
|
34
|
-
generatePackageJson: true,
|
35
|
+
generatePackageJson: options.isUsingTsSolutionConfig ? undefined : true,
|
35
36
|
},
|
36
37
|
configurations: {
|
37
38
|
development: {},
|
@@ -55,7 +56,7 @@ function getEsBuildConfig(project, options) {
|
|
55
56
|
main: (0, devkit_1.joinPathFragments)(project.sourceRoot, 'main' + (options.js ? '.js' : '.ts')),
|
56
57
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
57
58
|
assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
|
58
|
-
generatePackageJson: true,
|
59
|
+
generatePackageJson: options.isUsingTsSolutionConfig ? undefined : true,
|
59
60
|
esbuildOptions: {
|
60
61
|
sourcemap: true,
|
61
62
|
// Generate CJS files as .js so imports can be './foo' rather than './foo.cjs'.
|
@@ -136,10 +137,25 @@ function addProject(tree, options) {
|
|
136
137
|
}
|
137
138
|
}
|
138
139
|
project.targets.serve = getServeConfig(options);
|
139
|
-
|
140
|
+
if (options.isUsingTsSolutionConfig) {
|
141
|
+
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
|
142
|
+
name: (0, get_import_path_1.getImportPath)(tree, options.name),
|
143
|
+
version: '0.0.1',
|
144
|
+
private: true,
|
145
|
+
nx: {
|
146
|
+
name: options.name,
|
147
|
+
projectType: 'application',
|
148
|
+
sourceRoot: project.sourceRoot,
|
149
|
+
targets: project.targets,
|
150
|
+
tags: project.tags?.length ? project.tags : undefined,
|
151
|
+
},
|
152
|
+
});
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
(0, devkit_1.addProjectConfiguration)(tree, options.name, project, options.standaloneConfig);
|
156
|
+
}
|
140
157
|
}
|
141
158
|
function addAppFiles(tree, options) {
|
142
|
-
const sourceRoot = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src');
|
143
159
|
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/common'), options.appProjectRoot, {
|
144
160
|
...options,
|
145
161
|
tmpl: '',
|
@@ -296,9 +312,15 @@ async function applicationGenerator(tree, schema) {
|
|
296
312
|
});
|
297
313
|
}
|
298
314
|
async function applicationGeneratorInternal(tree, schema) {
|
299
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'node', 'application');
|
300
|
-
const options = await normalizeOptions(tree, schema);
|
301
315
|
const tasks = [];
|
316
|
+
const jsInitTask = await (0, js_1.initGenerator)(tree, {
|
317
|
+
...schema,
|
318
|
+
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
319
|
+
skipFormat: true,
|
320
|
+
addTsPlugin: schema.useTsSolution,
|
321
|
+
});
|
322
|
+
tasks.push(jsInitTask);
|
323
|
+
const options = await normalizeOptions(tree, schema);
|
302
324
|
if (options.framework === 'nest') {
|
303
325
|
// nx-ignore-next-line
|
304
326
|
const { applicationGenerator } = (0, devkit_1.ensurePackage)('@nx/nest', versions_2.nxVersion);
|
@@ -322,12 +344,6 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
322
344
|
},
|
323
345
|
]);
|
324
346
|
}
|
325
|
-
const jsInitTask = await (0, js_1.initGenerator)(tree, {
|
326
|
-
...schema,
|
327
|
-
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
328
|
-
skipFormat: true,
|
329
|
-
});
|
330
|
-
tasks.push(jsInitTask);
|
331
347
|
const initTask = await (0, init_1.initGenerator)(tree, {
|
332
348
|
...schema,
|
333
349
|
skipFormat: true,
|
@@ -369,6 +385,13 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
369
385
|
skipFormat: true,
|
370
386
|
});
|
371
387
|
tasks.push(jestTask);
|
388
|
+
// There are no tests by default, so set `--passWithNoTests` to avoid test failure on new project.
|
389
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.name);
|
390
|
+
projectConfig.targets ??= {};
|
391
|
+
projectConfig.targets.test = {
|
392
|
+
options: { passWithNoTests: true },
|
393
|
+
};
|
394
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.name, projectConfig);
|
372
395
|
}
|
373
396
|
else {
|
374
397
|
// No need for default spec file if unit testing is not setup.
|
@@ -404,6 +427,14 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
404
427
|
if (!options.skipFormat) {
|
405
428
|
await (0, devkit_1.formatFiles)(tree);
|
406
429
|
}
|
430
|
+
if (options.isUsingTsSolutionConfig) {
|
431
|
+
(0, ts_solution_setup_1.updateTsconfigFiles)(tree, options.appProjectRoot, 'tsconfig.app.json', {
|
432
|
+
module: 'nodenext',
|
433
|
+
moduleResolution: 'nodenext',
|
434
|
+
}, options.linter === 'eslint'
|
435
|
+
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
436
|
+
: undefined);
|
437
|
+
}
|
407
438
|
tasks.push(() => {
|
408
439
|
(0, log_show_project_command_1.logShowProjectCommand)(options.name);
|
409
440
|
});
|
@@ -440,6 +471,7 @@ async function normalizeOptions(host, options) {
|
|
440
471
|
rootProject: options.rootProject ?? false,
|
441
472
|
port: options.port ?? 3000,
|
442
473
|
outputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : appProjectRoot),
|
474
|
+
isUsingTsSolutionConfig: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
|
443
475
|
};
|
444
476
|
}
|
445
477
|
exports.default = applicationGenerator;
|
@@ -8,6 +8,7 @@ export interface Schema {
|
|
8
8
|
unitTestRunner?: 'jest' | 'none';
|
9
9
|
e2eTestRunner?: 'jest' | 'none';
|
10
10
|
linter?: Linter | LinterType;
|
11
|
+
formatter?: 'none' | 'prettier';
|
11
12
|
tags?: string;
|
12
13
|
frontendProject?: string;
|
13
14
|
swcJest?: boolean;
|
@@ -23,6 +24,7 @@ export interface Schema {
|
|
23
24
|
docker?: boolean;
|
24
25
|
isNest?: boolean;
|
25
26
|
addPlugin?: boolean;
|
27
|
+
useTsSolution?: boolean;
|
26
28
|
}
|
27
29
|
|
28
30
|
export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'nest' | 'none';
|
@@ -36,14 +36,26 @@
|
|
36
36
|
"linter": {
|
37
37
|
"description": "The tool to use for running lint checks.",
|
38
38
|
"type": "string",
|
39
|
-
"enum": ["eslint"],
|
40
|
-
"default": "
|
39
|
+
"enum": ["eslint", "none"],
|
40
|
+
"default": "none",
|
41
|
+
"x-prompt": "Which linter would you like to use?",
|
42
|
+
"x-priority": "important"
|
41
43
|
},
|
42
44
|
"unitTestRunner": {
|
43
45
|
"type": "string",
|
44
46
|
"enum": ["jest", "none"],
|
45
47
|
"description": "Test runner to use for unit tests.",
|
46
|
-
"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?"
|
47
59
|
},
|
48
60
|
"tags": {
|
49
61
|
"type": "string",
|
@@ -109,12 +121,6 @@
|
|
109
121
|
"hidden": true,
|
110
122
|
"x-priority": "internal"
|
111
123
|
},
|
112
|
-
"e2eTestRunner": {
|
113
|
-
"type": "string",
|
114
|
-
"enum": ["jest", "none"],
|
115
|
-
"description": "Test runner to use for end to end (e2e) tests",
|
116
|
-
"default": "jest"
|
117
|
-
},
|
118
124
|
"docker": {
|
119
125
|
"type": "boolean",
|
120
126
|
"description": "Add a docker build target"
|
@@ -11,6 +11,9 @@ const versions_1 = require("../../utils/versions");
|
|
11
11
|
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
12
12
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
13
13
|
const config_file_1 = require("@nx/jest/src/utils/config/config-file");
|
14
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
15
|
+
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
16
|
+
const posix_1 = require("node:path/posix");
|
14
17
|
async function e2eProjectGenerator(host, options) {
|
15
18
|
return await e2eProjectGeneratorInternal(host, {
|
16
19
|
addPlugin: false,
|
@@ -21,23 +24,49 @@ async function e2eProjectGeneratorInternal(host, _options) {
|
|
21
24
|
const tasks = [];
|
22
25
|
const options = await normalizeOptions(host, _options);
|
23
26
|
const appProject = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
27
|
+
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
24
28
|
// TODO(@ndcunningham): This is broken.. the outputs are wrong.. and this isn't using the jest generator
|
25
|
-
(
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
if (isUsingTsSolutionConfig) {
|
30
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
|
31
|
+
name: (0, get_import_path_1.getImportPath)(host, options.e2eProjectName),
|
32
|
+
version: '0.0.1',
|
33
|
+
private: true,
|
34
|
+
nx: {
|
35
|
+
name: options.e2eProjectName,
|
36
|
+
projectType: 'application',
|
37
|
+
implicitDependencies: [options.project],
|
38
|
+
targets: {
|
39
|
+
e2e: {
|
40
|
+
executor: '@nx/jest:jest',
|
41
|
+
outputs: ['{workspaceRoot}/coverage/{e2eProjectRoot}'],
|
42
|
+
options: {
|
43
|
+
jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
|
44
|
+
passWithNoTests: true,
|
45
|
+
},
|
46
|
+
dependsOn: [`${options.project}:build`],
|
47
|
+
},
|
36
48
|
},
|
37
|
-
dependsOn: [`${options.project}:build`],
|
38
49
|
},
|
39
|
-
}
|
40
|
-
}
|
50
|
+
});
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
(0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
|
54
|
+
root: options.e2eProjectRoot,
|
55
|
+
implicitDependencies: [options.project],
|
56
|
+
projectType: 'application',
|
57
|
+
targets: {
|
58
|
+
e2e: {
|
59
|
+
executor: '@nx/jest:jest',
|
60
|
+
outputs: ['{workspaceRoot}/coverage/{e2eProjectRoot}'],
|
61
|
+
options: {
|
62
|
+
jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
|
63
|
+
passWithNoTests: true,
|
64
|
+
},
|
65
|
+
dependsOn: [`${options.project}:build`],
|
66
|
+
},
|
67
|
+
},
|
68
|
+
});
|
69
|
+
}
|
41
70
|
// TODO(@nicholas): Find a better way to get build target
|
42
71
|
// We remove the 'test' target from the e2e project because it is not needed
|
43
72
|
// The 'e2e' target is the one that should run the tests for the e2e project
|
@@ -64,10 +93,14 @@ async function e2eProjectGeneratorInternal(host, _options) {
|
|
64
93
|
});
|
65
94
|
}
|
66
95
|
const jestPreset = (0, config_file_1.findRootJestPreset)(host) ?? 'jest.preset.js';
|
96
|
+
const tsConfigFile = isUsingTsSolutionConfig
|
97
|
+
? 'tsconfig.json'
|
98
|
+
: 'tsconfig.spec.json';
|
67
99
|
if (options.projectType === 'server') {
|
68
100
|
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/server/common'), options.e2eProjectRoot, {
|
69
101
|
...options,
|
70
102
|
...(0, devkit_1.names)(options.rootProject ? 'server' : options.project),
|
103
|
+
tsConfigFile,
|
71
104
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
|
72
105
|
jestPreset,
|
73
106
|
tmpl: '',
|
@@ -76,6 +109,7 @@ async function e2eProjectGeneratorInternal(host, _options) {
|
|
76
109
|
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/server/nest'), options.e2eProjectRoot, {
|
77
110
|
...options,
|
78
111
|
...(0, devkit_1.names)(options.rootProject ? 'server' : options.project),
|
112
|
+
tsConfigFile,
|
79
113
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
|
80
114
|
tmpl: '',
|
81
115
|
});
|
@@ -87,11 +121,27 @@ async function e2eProjectGeneratorInternal(host, _options) {
|
|
87
121
|
...options,
|
88
122
|
...(0, devkit_1.names)(options.rootProject ? 'cli' : options.project),
|
89
123
|
mainFile,
|
124
|
+
tsConfigFile,
|
90
125
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
|
91
126
|
jestPreset,
|
92
127
|
tmpl: '',
|
93
128
|
});
|
94
129
|
}
|
130
|
+
if (isUsingTsSolutionConfig) {
|
131
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/ts-solution'), options.e2eProjectRoot, {
|
132
|
+
...options,
|
133
|
+
relativeProjectReferencePath: (0, posix_1.relative)(options.e2eProjectRoot, appProject.root),
|
134
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
|
135
|
+
tmpl: '',
|
136
|
+
});
|
137
|
+
}
|
138
|
+
else {
|
139
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/non-ts-solution'), options.e2eProjectRoot, {
|
140
|
+
...options,
|
141
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot),
|
142
|
+
tmpl: '',
|
143
|
+
});
|
144
|
+
}
|
95
145
|
// axios is more than likely used in the application code, so install it as a regular dependency.
|
96
146
|
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, { axios: versions_1.axiosVersion }, {});
|
97
147
|
tasks.push(installTask);
|
@@ -120,6 +170,16 @@ async function e2eProjectGeneratorInternal(host, _options) {
|
|
120
170
|
if (!options.skipFormat) {
|
121
171
|
await (0, devkit_1.formatFiles)(host);
|
122
172
|
}
|
173
|
+
if (isUsingTsSolutionConfig) {
|
174
|
+
(0, devkit_1.updateJson)(host, 'tsconfig.json', (json) => {
|
175
|
+
json.references ??= [];
|
176
|
+
const e2eRef = `./${options.e2eProjectRoot}`;
|
177
|
+
if (!json.references.find((ref) => ref.path === e2eRef)) {
|
178
|
+
json.references.push({ path: e2eRef });
|
179
|
+
}
|
180
|
+
return json;
|
181
|
+
});
|
182
|
+
}
|
123
183
|
tasks.push(() => {
|
124
184
|
(0, log_show_project_command_1.logShowProjectCommand)(options.e2eProjectName);
|
125
185
|
});
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"extends": "<%= offsetFromRoot %>tsconfig.base.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "out-tsc/<%= e2eProjectName %>",
|
5
|
+
"esModuleInterop": true,
|
6
|
+
"noUnusedLocals": false,
|
7
|
+
"noImplicitAny": false
|
8
|
+
},
|
9
|
+
"include": [
|
10
|
+
"jest.config.ts",
|
11
|
+
"src/**/*.ts"
|
12
|
+
],
|
13
|
+
"references": [
|
14
|
+
{ "path": "<%= relativeProjectReferencePath %>" }
|
15
|
+
]
|
16
|
+
}
|
@@ -2,7 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.initGenerator = initGenerator;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
6
5
|
const versions_1 = require("../../utils/versions");
|
7
6
|
function updateDependencies(tree, options) {
|
8
7
|
const tasks = [];
|
@@ -11,7 +10,6 @@ function updateDependencies(tree, options) {
|
|
11
10
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
12
11
|
}
|
13
12
|
async function initGenerator(tree, options) {
|
14
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'node', 'init');
|
15
13
|
let installTask = () => { };
|
16
14
|
if (!options.skipPackageJson) {
|
17
15
|
installTask = updateDependencies(tree, options);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"baseUrl": ".",
|
5
|
+
"rootDir": "src",
|
6
|
+
"module": "nodenext",
|
7
|
+
"moduleResolution": "nodenext",
|
8
|
+
"outDir": "dist",
|
9
|
+
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
10
|
+
"emitDeclarationOnly": false,
|
11
|
+
"types": ["node"]
|
12
|
+
},
|
13
|
+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
|
14
|
+
"include": ["src/**/*.ts"]
|
15
|
+
}
|
@@ -6,6 +6,7 @@ export interface NormalizedSchema extends Schema {
|
|
6
6
|
projectRoot: string;
|
7
7
|
parsedTags: string[];
|
8
8
|
compiler: 'swc' | 'tsc';
|
9
|
+
isUsingTsSolutionConfig: boolean;
|
9
10
|
}
|
10
11
|
export declare function libraryGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
11
12
|
export declare function libraryGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
@@ -7,11 +7,12 @@ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project
|
|
7
7
|
const js_1 = require("@nx/js");
|
8
8
|
const add_swc_config_1 = require("@nx/js/src/utils/swc/add-swc-config");
|
9
9
|
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
10
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
11
10
|
const path_1 = require("path");
|
12
11
|
const versions_1 = require("../../utils/versions");
|
13
12
|
const init_1 = require("../init/init");
|
14
13
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
14
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
15
|
+
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
15
16
|
async function libraryGenerator(tree, schema) {
|
16
17
|
return await libraryGeneratorInternal(tree, {
|
17
18
|
addPlugin: false,
|
@@ -19,33 +20,46 @@ async function libraryGenerator(tree, schema) {
|
|
19
20
|
});
|
20
21
|
}
|
21
22
|
async function libraryGeneratorInternal(tree, schema) {
|
22
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'node', 'library');
|
23
23
|
const options = await normalizeOptions(tree, schema);
|
24
|
-
const tasks = [
|
25
|
-
await (0, init_1.initGenerator)(tree, {
|
26
|
-
...options,
|
27
|
-
skipFormat: true,
|
28
|
-
}),
|
29
|
-
];
|
24
|
+
const tasks = [];
|
30
25
|
if (options.publishable === true && !schema.importPath) {
|
31
26
|
throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
|
32
27
|
}
|
33
|
-
|
34
|
-
|
28
|
+
// Create `package.json` first because @nx/js:lib generator will update it.
|
29
|
+
if (options.isUsingTsSolutionConfig ||
|
30
|
+
options.publishable ||
|
31
|
+
options.buildable) {
|
32
|
+
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), {
|
33
|
+
name: (0, get_import_path_1.getImportPath)(tree, options.name),
|
34
|
+
version: '0.0.1',
|
35
|
+
private: true,
|
36
|
+
files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
tasks.push(await (0, js_1.libraryGenerator)(tree, {
|
40
|
+
...schema,
|
35
41
|
bundler: schema.buildable || schema.publishable ? 'tsc' : 'none',
|
36
42
|
includeBabelRc: schema.babelJest,
|
37
|
-
importPath:
|
43
|
+
importPath: schema.importPath,
|
38
44
|
testEnvironment: 'node',
|
39
45
|
skipFormat: true,
|
40
|
-
setParserOptionsProject:
|
41
|
-
|
42
|
-
|
46
|
+
setParserOptionsProject: schema.setParserOptionsProject,
|
47
|
+
useProjectJson: !options.isUsingTsSolutionConfig,
|
48
|
+
}));
|
49
|
+
tasks.push(await (0, init_1.initGenerator)(tree, {
|
50
|
+
...options,
|
51
|
+
skipFormat: true,
|
52
|
+
}));
|
43
53
|
createFiles(tree, options);
|
44
54
|
if (options.js) {
|
45
55
|
(0, devkit_1.updateTsConfigsToJs)(tree, options);
|
46
56
|
}
|
47
57
|
updateProject(tree, options);
|
48
58
|
tasks.push(ensureDependencies(tree));
|
59
|
+
// Always run install to link packages.
|
60
|
+
if (options.isUsingTsSolutionConfig) {
|
61
|
+
tasks.push(() => (0, devkit_1.installPackagesTask)(tree, true));
|
62
|
+
}
|
49
63
|
if (!schema.skipFormat) {
|
50
64
|
await (0, devkit_1.formatFiles)(tree);
|
51
65
|
}
|
@@ -77,6 +91,7 @@ async function normalizeOptions(tree, options) {
|
|
77
91
|
projectRoot,
|
78
92
|
parsedTags,
|
79
93
|
importPath,
|
94
|
+
isUsingTsSolutionConfig: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree),
|
80
95
|
};
|
81
96
|
}
|
82
97
|
function createFiles(tree, options) {
|
@@ -92,9 +107,6 @@ function createFiles(tree, options) {
|
|
92
107
|
if (options.unitTestRunner === 'none') {
|
93
108
|
tree.delete((0, path_1.join)(options.projectRoot, `./src/lib/${options.fileName}.spec.ts`));
|
94
109
|
}
|
95
|
-
if (!options.publishable && !options.buildable) {
|
96
|
-
tree.delete((0, path_1.join)(options.projectRoot, 'package.json'));
|
97
|
-
}
|
98
110
|
if (options.js) {
|
99
111
|
(0, devkit_1.toJS)(tree);
|
100
112
|
}
|
@@ -107,17 +119,25 @@ function updateProject(tree, options) {
|
|
107
119
|
const rootProject = options.projectRoot === '.' || options.projectRoot === '';
|
108
120
|
project.targets = project.targets || {};
|
109
121
|
(0, target_defaults_utils_1.addBuildTargetDefaults)(tree, `@nx/js:${options.compiler}`);
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
122
|
+
// For TS solution, we want tsc build to be inferred by `@nx/js/typescript` plugin.
|
123
|
+
if (!options.isUsingTsSolutionConfig || options.compiler === 'swc') {
|
124
|
+
project.targets.build = {
|
125
|
+
executor: `@nx/js:${options.compiler}`,
|
126
|
+
outputs: ['{options.outputPath}'],
|
127
|
+
options: {
|
128
|
+
outputPath: options.isUsingTsSolutionConfig
|
129
|
+
? (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist')
|
130
|
+
: (0, devkit_1.joinPathFragments)('dist', rootProject ? options.projectName : options.projectRoot),
|
131
|
+
tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
|
132
|
+
packageJson: `${options.projectRoot}/package.json`,
|
133
|
+
main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
|
134
|
+
assets: options.isUsingTsSolutionConfig
|
135
|
+
? undefined
|
136
|
+
: [`${options.projectRoot}/*.md`],
|
137
|
+
stripLeadingPaths: options.isUsingTsSolutionConfig ? true : undefined,
|
138
|
+
},
|
139
|
+
};
|
140
|
+
}
|
121
141
|
if (options.compiler === 'swc') {
|
122
142
|
(0, add_swc_dependencies_1.addSwcDependencies)(tree);
|
123
143
|
(0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot);
|
@@ -36,14 +36,18 @@
|
|
36
36
|
"linter": {
|
37
37
|
"description": "The tool to use for running lint checks.",
|
38
38
|
"type": "string",
|
39
|
-
"enum": ["eslint"],
|
40
|
-
"default": "
|
39
|
+
"enum": ["eslint", "none"],
|
40
|
+
"default": "none",
|
41
|
+
"x-prompt": "Which linter would you like to use?",
|
42
|
+
"x-priority": "important"
|
41
43
|
},
|
42
44
|
"unitTestRunner": {
|
43
45
|
"type": "string",
|
44
46
|
"enum": ["jest", "none"],
|
45
47
|
"description": "Test runner to use for unit tests.",
|
46
|
-
"default": "
|
48
|
+
"default": "none",
|
49
|
+
"x-prompt": "Which unit test runner would you like to use?",
|
50
|
+
"x-priority": "important"
|
47
51
|
},
|
48
52
|
"tags": {
|
49
53
|
"type": "string",
|
@@ -69,7 +73,7 @@
|
|
69
73
|
},
|
70
74
|
"buildable": {
|
71
75
|
"type": "boolean",
|
72
|
-
"default":
|
76
|
+
"default": true,
|
73
77
|
"description": "Generate a buildable library.",
|
74
78
|
"x-priority": "important"
|
75
79
|
},
|
@@ -1,13 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": "<%= offsetFromRoot %><% if (rootProject) { %>tsconfig.json<% } else { %>tsconfig.base.json<% } %>",
|
3
|
-
"files": [],
|
4
|
-
"include": [],
|
5
|
-
"references": [
|
6
|
-
{
|
7
|
-
"path": "./tsconfig.spec.json"
|
8
|
-
}
|
9
|
-
],
|
10
|
-
"compilerOptions": {
|
11
|
-
"esModuleInterop": true
|
12
|
-
}
|
13
|
-
}
|
File without changes
|
File without changes
|
File without changes
|