@depup/nestjs__cli 11.0.24-depup.7 → 12.0.0-depup.0
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/README.md +7 -15
- package/actions/abstract.action.d.ts +1 -2
- package/actions/abstract.action.js +1 -5
- package/actions/add.action.d.ts +3 -4
- package/actions/add.action.js +44 -53
- package/actions/build.action.d.ts +18 -11
- package/actions/build.action.js +172 -79
- package/actions/deploy.action.d.ts +6 -0
- package/actions/deploy.action.js +51 -0
- package/actions/generate.action.d.ts +3 -3
- package/actions/generate.action.js +61 -59
- package/actions/index.d.ts +9 -7
- package/actions/index.js +9 -23
- package/actions/info.action.d.ts +18 -28
- package/actions/info.action.js +80 -60
- package/actions/new.action.d.ts +3 -3
- package/actions/new.action.js +108 -104
- package/actions/start.action.d.ts +4 -7
- package/actions/start.action.js +40 -47
- package/actions/upgrade.action.d.ts +6 -0
- package/actions/upgrade.action.js +53 -0
- package/bin/nest.js +11 -10
- package/changes.json +9 -41
- package/commands/abstract.command.d.ts +3 -3
- package/commands/abstract.command.js +2 -5
- package/commands/add.command.d.ts +3 -3
- package/commands/add.command.js +17 -20
- package/commands/build.command.d.ts +3 -3
- package/commands/build.command.js +52 -56
- package/commands/command.input.js +1 -2
- package/commands/command.loader.d.ts +2 -2
- package/commands/command.loader.js +29 -22
- package/commands/context/add.context.d.ts +7 -0
- package/commands/context/add.context.js +1 -0
- package/commands/context/build.context.d.ts +17 -0
- package/commands/context/build.context.js +1 -0
- package/commands/context/deploy.context.d.ts +7 -0
- package/commands/context/deploy.context.js +1 -0
- package/commands/context/generate.context.d.ts +18 -0
- package/commands/context/generate.context.js +1 -0
- package/commands/context/index.d.ts +7 -0
- package/commands/context/index.js +7 -0
- package/commands/context/new.context.d.ts +19 -0
- package/commands/context/new.context.js +1 -0
- package/commands/context/start.context.d.ts +22 -0
- package/commands/context/start.context.js +1 -0
- package/commands/context/upgrade.context.d.ts +11 -0
- package/commands/context/upgrade.context.js +1 -0
- package/commands/deploy.command.d.ts +5 -0
- package/commands/deploy.command.js +22 -0
- package/commands/generate.command.d.ts +3 -3
- package/commands/generate.command.js +35 -66
- package/commands/index.d.ts +3 -2
- package/commands/index.js +3 -18
- package/commands/info.command.d.ts +3 -3
- package/commands/info.command.js +4 -8
- package/commands/new.command.d.ts +3 -3
- package/commands/new.command.js +34 -36
- package/commands/start.command.d.ts +3 -3
- package/commands/start.command.js +48 -73
- package/commands/upgrade.command.d.ts +5 -0
- package/commands/upgrade.command.js +32 -0
- package/lib/compiler/assets-manager.d.ts +20 -8
- package/lib/compiler/assets-manager.js +199 -63
- package/lib/compiler/base-compiler.d.ts +5 -5
- package/lib/compiler/base-compiler.js +10 -13
- package/lib/compiler/compiler.d.ts +6 -6
- package/lib/compiler/compiler.js +7 -9
- package/lib/compiler/defaults/rspack-defaults.d.ts +3 -0
- package/lib/compiler/defaults/rspack-defaults.js +179 -0
- package/lib/compiler/defaults/swc-defaults.d.ts +5 -2
- package/lib/compiler/defaults/swc-defaults.js +22 -6
- package/lib/compiler/defaults/webpack-defaults.d.ts +2 -2
- package/lib/compiler/defaults/webpack-defaults.js +59 -19
- package/lib/compiler/helpers/append-extension.js +3 -6
- package/lib/compiler/helpers/copy-path-resolve.js +2 -5
- package/lib/compiler/helpers/delete-out-dir.d.ts +1 -1
- package/lib/compiler/helpers/delete-out-dir.js +45 -10
- package/lib/compiler/helpers/get-builder.d.ts +9 -7
- package/lib/compiler/helpers/get-builder.js +3 -6
- package/lib/compiler/helpers/get-effective-root-dir.d.ts +16 -0
- package/lib/compiler/helpers/get-effective-root-dir.js +56 -0
- package/lib/compiler/helpers/get-rspack-config-path.d.ts +10 -0
- package/lib/compiler/helpers/get-rspack-config-path.js +19 -0
- package/lib/compiler/helpers/get-tsc-config.path.d.ts +2 -3
- package/lib/compiler/helpers/get-tsc-config.path.js +6 -9
- package/lib/compiler/helpers/get-value-or-default.d.ts +2 -3
- package/lib/compiler/helpers/get-value-or-default.js +3 -8
- package/lib/compiler/helpers/get-webpack-config-path.d.ts +2 -3
- package/lib/compiler/helpers/get-webpack-config-path.js +4 -7
- package/lib/compiler/helpers/glob.d.ts +19 -0
- package/lib/compiler/helpers/glob.js +185 -0
- package/lib/compiler/helpers/manual-restart.js +4 -8
- package/lib/compiler/helpers/path-confinement.d.ts +33 -0
- package/lib/compiler/helpers/path-confinement.js +63 -0
- package/lib/compiler/helpers/tsconfig-provider.d.ts +7 -6
- package/lib/compiler/helpers/tsconfig-provider.js +32 -13
- package/lib/compiler/hooks/tsconfig-paths.hook.js +13 -13
- package/lib/compiler/interfaces/readonly-visitor.interface.js +1 -2
- package/lib/compiler/plugins/plugin-metadata-generator.d.ts +37 -1
- package/lib/compiler/plugins/plugin-metadata-generator.js +113 -13
- package/lib/compiler/plugins/plugin-metadata-printer.d.ts +1 -1
- package/lib/compiler/plugins/plugin-metadata-printer.js +5 -9
- package/lib/compiler/plugins/plugins-loader.d.ts +2 -2
- package/lib/compiler/plugins/plugins-loader.js +12 -12
- package/lib/compiler/rspack-compiler.d.ts +21 -0
- package/lib/compiler/rspack-compiler.js +111 -0
- package/lib/compiler/swc/constants.d.ts +0 -1
- package/lib/compiler/swc/constants.js +9 -13
- package/lib/compiler/swc/forked-type-checker.js +13 -18
- package/lib/compiler/swc/swc-compiler.d.ts +13 -6
- package/lib/compiler/swc/swc-compiler.js +116 -70
- package/lib/compiler/swc/type-checker-host.js +31 -24
- package/lib/compiler/typescript-loader.js +7 -9
- package/lib/compiler/watch-compiler.d.ts +5 -5
- package/lib/compiler/watch-compiler.js +13 -15
- package/lib/compiler/watchers/recursive-directory-watcher.d.ts +37 -0
- package/lib/compiler/watchers/recursive-directory-watcher.js +334 -0
- package/lib/compiler/webpack-compiler.d.ts +6 -7
- package/lib/compiler/webpack-compiler.js +46 -23
- package/lib/configuration/configuration.d.ts +16 -3
- package/lib/configuration/configuration.js +1 -2
- package/lib/configuration/configuration.loader.d.ts +1 -1
- package/lib/configuration/configuration.loader.js +1 -2
- package/lib/configuration/defaults.d.ts +2 -1
- package/lib/configuration/defaults.js +8 -10
- package/lib/configuration/index.d.ts +3 -3
- package/lib/configuration/index.js +3 -19
- package/lib/configuration/nest-configuration.loader.d.ts +3 -3
- package/lib/configuration/nest-configuration.loader.js +28 -29
- package/lib/package-managers/abstract.package-manager.d.ts +4 -4
- package/lib/package-managers/abstract.package-manager.js +21 -32
- package/lib/package-managers/bun.package-manager.d.ts +7 -0
- package/lib/package-managers/bun.package-manager.js +22 -0
- package/lib/package-managers/index.d.ts +9 -8
- package/lib/package-managers/index.js +9 -24
- package/lib/package-managers/npm.package-manager.d.ts +2 -2
- package/lib/package-managers/npm.package-manager.js +6 -10
- package/lib/package-managers/package-manager-commands.js +1 -2
- package/lib/package-managers/package-manager.d.ts +2 -1
- package/lib/package-managers/package-manager.factory.d.ts +2 -2
- package/lib/package-managers/package-manager.factory.js +23 -20
- package/lib/package-managers/package-manager.js +3 -5
- package/lib/package-managers/pnpm.package-manager.d.ts +2 -2
- package/lib/package-managers/pnpm.package-manager.js +6 -10
- package/lib/package-managers/project.dependency.js +1 -2
- package/lib/package-managers/yarn.package-manager.d.ts +2 -2
- package/lib/package-managers/yarn.package-manager.js +6 -10
- package/lib/questions/questions.d.ts +5 -1
- package/lib/questions/questions.js +2 -7
- package/lib/readers/file-system.reader.d.ts +1 -1
- package/lib/readers/file-system.reader.js +6 -9
- package/lib/readers/index.d.ts +2 -2
- package/lib/readers/index.js +2 -18
- package/lib/readers/reader.js +3 -5
- package/lib/runners/abstract.runner.js +40 -21
- package/lib/runners/bun.runner.d.ts +4 -0
- package/lib/runners/bun.runner.js +6 -0
- package/lib/runners/git.runner.d.ts +1 -1
- package/lib/runners/git.runner.js +2 -6
- package/lib/runners/index.d.ts +3 -3
- package/lib/runners/index.js +3 -19
- package/lib/runners/mau.runner.d.ts +8 -0
- package/lib/runners/mau.runner.js +10 -0
- package/lib/runners/npm.runner.d.ts +1 -1
- package/lib/runners/npm.runner.js +2 -6
- package/lib/runners/pnpm.runner.d.ts +1 -1
- package/lib/runners/pnpm.runner.js +2 -6
- package/lib/runners/runner.d.ts +2 -1
- package/lib/runners/runner.factory.d.ts +7 -6
- package/lib/runners/runner.factory.js +18 -20
- package/lib/runners/runner.js +3 -5
- package/lib/runners/schematic.runner.d.ts +1 -1
- package/lib/runners/schematic.runner.js +5 -7
- package/lib/runners/yarn.runner.d.ts +1 -1
- package/lib/runners/yarn.runner.js +2 -6
- package/lib/schematics/abstract.collection.d.ts +3 -3
- package/lib/schematics/abstract.collection.js +3 -5
- package/lib/schematics/collection.factory.d.ts +2 -2
- package/lib/schematics/collection.factory.js +9 -13
- package/lib/schematics/collection.js +2 -5
- package/lib/schematics/custom.collection.d.ts +2 -2
- package/lib/schematics/custom.collection.js +4 -8
- package/lib/schematics/index.d.ts +4 -4
- package/lib/schematics/index.js +4 -20
- package/lib/schematics/nest.collection.d.ts +3 -3
- package/lib/schematics/nest.collection.js +113 -109
- package/lib/schematics/schematic.option.js +10 -9
- package/lib/ui/banner.js +1 -4
- package/lib/ui/emojis.d.ts +17 -17
- package/lib/ui/emojis.js +19 -22
- package/lib/ui/errors.js +1 -4
- package/lib/ui/index.d.ts +5 -5
- package/lib/ui/index.js +5 -21
- package/lib/ui/messages.d.ts +8 -0
- package/lib/ui/messages.js +23 -18
- package/lib/ui/prefixes.js +3 -6
- package/lib/utils/extra-args-warning.js +3 -6
- package/lib/utils/formatting.js +1 -4
- package/lib/utils/get-default-tsconfig-path.js +4 -7
- package/lib/utils/gracefully-exit-on-prompt-error.js +1 -4
- package/lib/utils/is-esm-project.d.ts +5 -0
- package/lib/utils/is-esm-project.js +16 -0
- package/lib/utils/is-interactive.d.ts +8 -0
- package/lib/utils/is-interactive.js +10 -0
- package/lib/utils/is-module-available.js +3 -4
- package/lib/utils/load-configuration.d.ts +1 -1
- package/lib/utils/load-configuration.js +4 -7
- package/lib/utils/local-binaries.d.ts +2 -2
- package/lib/utils/local-binaries.js +8 -11
- package/lib/utils/mau.d.ts +14 -0
- package/lib/utils/mau.js +46 -0
- package/lib/utils/os-info.utils.js +1 -4
- package/lib/utils/project-utils.d.ts +1 -3
- package/lib/utils/project-utils.js +16 -28
- package/lib/utils/remaining-flags.d.ts +2 -2
- package/lib/utils/remaining-flags.js +13 -8
- package/lib/utils/tree-kill.js +7 -10
- package/lib/utils/type-assertions.js +1 -4
- package/package.json +70 -83
package/README.md
CHANGED
|
@@ -13,27 +13,19 @@ npm install @depup/nestjs__cli
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [@nestjs/cli](https://www.npmjs.com/package/@nestjs/cli) @
|
|
17
|
-
| Processed | 2026-08-
|
|
16
|
+
| Original | [@nestjs/cli](https://www.npmjs.com/package/@nestjs/cli) @ 12.0.0 |
|
|
17
|
+
| Processed | 2026-08-27 |
|
|
18
18
|
| Smoke test | failed |
|
|
19
|
-
| Deps updated |
|
|
19
|
+
| Deps updated | 4 |
|
|
20
20
|
|
|
21
21
|
## Dependency Changes
|
|
22
22
|
|
|
23
23
|
| Dependency | From | To |
|
|
24
24
|
|------------|------|-----|
|
|
25
|
-
| @angular-devkit/core |
|
|
26
|
-
| @angular-devkit/schematics |
|
|
27
|
-
| @angular-devkit/schematics-cli |
|
|
28
|
-
|
|
|
29
|
-
| @nestjs/schematics | ^11.0.1 | ^11.1.0 |
|
|
30
|
-
| ansis | 4.2.0 | ^4.3.1 |
|
|
31
|
-
| chokidar | 4.0.3 | ^5.0.0 |
|
|
32
|
-
| commander | 4.1.1 | ^15.0.0 |
|
|
33
|
-
| node-emoji | 1.11.0 | ^2.2.0 |
|
|
34
|
-
| ora | 5.4.1 | ^9.4.1 |
|
|
35
|
-
| typescript | 5.9.3 | ^7.0.2 |
|
|
36
|
-
| webpack | 5.106.2 | ^5.109.2 |
|
|
25
|
+
| @angular-devkit/core | 22.1.5 | ^22.1.6 |
|
|
26
|
+
| @angular-devkit/schematics | 22.1.5 | ^22.1.6 |
|
|
27
|
+
| @angular-devkit/schematics-cli | 22.1.5 | ^22.1.6 |
|
|
28
|
+
| typescript | ~6.0.2 | ^7.0.2 |
|
|
37
29
|
|
|
38
30
|
---
|
|
39
31
|
|
package/actions/add.action.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractAction } from './abstract.action';
|
|
1
|
+
import { AddCommandContext } from '../commands/index.js';
|
|
2
|
+
import { AbstractAction } from './abstract.action.js';
|
|
3
3
|
export declare class AddAction extends AbstractAction {
|
|
4
|
-
handle(
|
|
4
|
+
handle(context: AddCommandContext): Promise<void>;
|
|
5
5
|
private getSourceRoot;
|
|
6
6
|
private installPackage;
|
|
7
7
|
private addLibrary;
|
|
8
|
-
private getLibraryName;
|
|
9
8
|
private getPackageName;
|
|
10
9
|
private getCollectionName;
|
|
11
10
|
private getTagName;
|
package/actions/add.action.js
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const load_configuration_1 = require("../lib/utils/load-configuration");
|
|
10
|
-
const project_utils_1 = require("../lib/utils/project-utils");
|
|
11
|
-
const abstract_action_1 = require("./abstract.action");
|
|
1
|
+
import { red } from 'ansis';
|
|
2
|
+
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default.js';
|
|
3
|
+
import { PackageManagerFactory, } from '../lib/package-managers/index.js';
|
|
4
|
+
import { CollectionFactory, SchematicOption, } from '../lib/schematics/index.js';
|
|
5
|
+
import { MESSAGES } from '../lib/ui/index.js';
|
|
6
|
+
import { loadConfiguration } from '../lib/utils/load-configuration.js';
|
|
7
|
+
import { askForProjectName, moveDefaultProjectToStart, shouldAskForProject, } from '../lib/utils/project-utils.js';
|
|
8
|
+
import { AbstractAction } from './abstract.action.js';
|
|
12
9
|
const schematicName = 'nest-add';
|
|
13
|
-
class AddAction extends
|
|
14
|
-
async handle(
|
|
15
|
-
const libraryName =
|
|
10
|
+
export class AddAction extends AbstractAction {
|
|
11
|
+
async handle(context) {
|
|
12
|
+
const libraryName = context.library;
|
|
16
13
|
const packageName = this.getPackageName(libraryName);
|
|
17
14
|
const collectionName = this.getCollectionName(libraryName, packageName);
|
|
18
15
|
const tagName = this.getTagName(packageName);
|
|
19
|
-
const
|
|
20
|
-
|
|
16
|
+
const packageInstallSuccess = context.skipInstall ||
|
|
17
|
+
(await this.installPackage(collectionName, tagName));
|
|
21
18
|
if (packageInstallSuccess) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
await this.addLibrary(collectionName, options, extraFlags);
|
|
19
|
+
const sourceRoot = await this.getSourceRoot(context.project);
|
|
20
|
+
await this.addLibrary(collectionName, sourceRoot, context.extraFlags);
|
|
25
21
|
}
|
|
26
22
|
else {
|
|
27
|
-
console.error(
|
|
28
|
-
throw new Error(
|
|
23
|
+
console.error(red(MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName)));
|
|
24
|
+
throw new Error(MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName));
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
|
-
async getSourceRoot(
|
|
32
|
-
const configuration = await
|
|
27
|
+
async getSourceRoot(project) {
|
|
28
|
+
const configuration = await loadConfiguration();
|
|
33
29
|
const configurationProjects = configuration.projects;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
let sourceRoot = appName
|
|
37
|
-
? (0, get_value_or_default_1.getValueOrDefault)(configuration, 'sourceRoot', appName)
|
|
30
|
+
let sourceRoot = project
|
|
31
|
+
? getValueOrDefault(configuration, 'sourceRoot', project)
|
|
38
32
|
: configuration.sourceRoot;
|
|
39
|
-
const shouldAsk =
|
|
33
|
+
const shouldAsk = shouldAskForProject(schematicName, configurationProjects, project ?? '');
|
|
40
34
|
if (shouldAsk) {
|
|
41
35
|
const defaultLabel = ' [ Default ]';
|
|
42
36
|
let defaultProjectName = configuration.sourceRoot + defaultLabel;
|
|
@@ -47,52 +41,45 @@ class AddAction extends abstract_action_1.AbstractAction {
|
|
|
47
41
|
break;
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
|
-
const projects =
|
|
51
|
-
const selectedProject = (await
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
sourceRoot = configurationProjects[
|
|
44
|
+
const projects = moveDefaultProjectToStart(configuration, defaultProjectName, defaultLabel);
|
|
45
|
+
const selectedProject = (await askForProjectName(MESSAGES.LIBRARY_PROJECT_SELECTION_QUESTION, projects));
|
|
46
|
+
const projectName = selectedProject.replace(defaultLabel, '');
|
|
47
|
+
if (projectName !== configuration.sourceRoot) {
|
|
48
|
+
sourceRoot = configurationProjects[projectName].sourceRoot;
|
|
55
49
|
}
|
|
56
50
|
}
|
|
57
|
-
return
|
|
51
|
+
return sourceRoot;
|
|
58
52
|
}
|
|
59
53
|
async installPackage(collectionName, tagName) {
|
|
60
|
-
const manager = await
|
|
54
|
+
const manager = await PackageManagerFactory.find();
|
|
61
55
|
tagName = tagName || 'latest';
|
|
62
56
|
let installResult = false;
|
|
63
57
|
try {
|
|
64
58
|
installResult = await manager.addProduction([collectionName], tagName);
|
|
65
59
|
}
|
|
66
60
|
catch (error) {
|
|
67
|
-
if (error
|
|
68
|
-
console.error(
|
|
61
|
+
if (error instanceof Error) {
|
|
62
|
+
console.error(red(error.message));
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
return installResult;
|
|
72
66
|
}
|
|
73
|
-
async addLibrary(collectionName,
|
|
74
|
-
console.info(
|
|
67
|
+
async addLibrary(collectionName, sourceRoot, extraFlags) {
|
|
68
|
+
console.info(MESSAGES.LIBRARY_INSTALLATION_STARTS);
|
|
75
69
|
const schematicOptions = [];
|
|
76
|
-
schematicOptions.push(new
|
|
70
|
+
schematicOptions.push(new SchematicOption('sourceRoot', sourceRoot));
|
|
77
71
|
const extraFlagsString = extraFlags ? extraFlags.join(' ') : undefined;
|
|
78
72
|
try {
|
|
79
|
-
const collection =
|
|
73
|
+
const collection = CollectionFactory.create(collectionName);
|
|
80
74
|
await collection.execute(schematicName, schematicOptions, extraFlagsString);
|
|
81
75
|
}
|
|
82
76
|
catch (error) {
|
|
83
|
-
if (error
|
|
84
|
-
console.error(
|
|
85
|
-
return Promise.reject();
|
|
77
|
+
if (error instanceof Error) {
|
|
78
|
+
console.error(red(error.message));
|
|
86
79
|
}
|
|
80
|
+
throw error;
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
|
-
getLibraryName(inputs) {
|
|
90
|
-
const libraryInput = inputs.find((input) => input.name === 'library');
|
|
91
|
-
if (!libraryInput) {
|
|
92
|
-
throw new Error('No library found in command input');
|
|
93
|
-
}
|
|
94
|
-
return libraryInput.value;
|
|
95
|
-
}
|
|
96
83
|
getPackageName(library) {
|
|
97
84
|
return library.startsWith('@')
|
|
98
85
|
? library.split('/', 2).join('/')
|
|
@@ -105,9 +92,13 @@ class AddAction extends abstract_action_1.AbstractAction {
|
|
|
105
92
|
library.slice(packageName.length));
|
|
106
93
|
}
|
|
107
94
|
getTagName(packageName) {
|
|
108
|
-
|
|
95
|
+
// For scoped packages like "@scope/pkg@1.0.0", split('@', 3) yields
|
|
96
|
+
// ["", "scope/pkg", "1.0.0"]. For "@scope/pkg" with no version,
|
|
97
|
+
// the tag slot is undefined. Fall back to an empty string so the
|
|
98
|
+
// return type stays string and installPackage can substitute "latest".
|
|
99
|
+
const tag = packageName.startsWith('@')
|
|
109
100
|
? packageName.split('@', 3)[2]
|
|
110
101
|
: packageName.split('@', 2)[1];
|
|
102
|
+
return tag ?? '';
|
|
111
103
|
}
|
|
112
104
|
}
|
|
113
|
-
exports.AddAction = AddAction;
|
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { AbstractAction } from './abstract.action';
|
|
1
|
+
import { AssetsManager } from '../lib/compiler/assets-manager.js';
|
|
2
|
+
import { TsConfigProvider } from '../lib/compiler/helpers/tsconfig-provider.js';
|
|
3
|
+
import { PluginsLoader } from '../lib/compiler/plugins/plugins-loader.js';
|
|
4
|
+
import { TypeScriptBinaryLoader } from '../lib/compiler/typescript-loader.js';
|
|
5
|
+
import { ConfigurationLoader } from '../lib/configuration/index.js';
|
|
6
|
+
import { FileSystemReader } from '../lib/readers/index.js';
|
|
7
|
+
import { AbstractAction } from './abstract.action.js';
|
|
9
8
|
export declare class BuildAction extends AbstractAction {
|
|
10
9
|
protected readonly pluginsLoader: PluginsLoader;
|
|
11
10
|
protected readonly tsLoader: TypeScriptBinaryLoader;
|
|
12
11
|
protected readonly tsConfigProvider: TsConfigProvider;
|
|
13
12
|
protected readonly fileSystemReader: FileSystemReader;
|
|
14
13
|
protected readonly loader: ConfigurationLoader;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Each app build owns its assets manager: `closeWatchers()` closes every
|
|
16
|
+
* watcher it holds, so a manager shared across a `--parallel` run would let
|
|
17
|
+
* the first app to finish tear down the watchers of apps still building.
|
|
18
|
+
*/
|
|
19
|
+
protected createAssetsManager(): AssetsManager;
|
|
20
|
+
handle(context: any): Promise<void>;
|
|
21
|
+
runBuild(apps: (string | undefined)[], options: Record<string, any>, watchMode: boolean, watchAssetsMode: boolean, isDebugEnabled?: boolean, onSuccess?: () => void): Promise<void>;
|
|
18
22
|
private runSwc;
|
|
19
23
|
private runWebpack;
|
|
20
24
|
private runTsc;
|
|
21
25
|
private getWebpackConfigFactoryByPath;
|
|
26
|
+
private runRspack;
|
|
27
|
+
private getRspackConfigFactoryByPath;
|
|
28
|
+
private warnOnIgnoredLibraryAssets;
|
|
22
29
|
}
|
package/actions/build.action.js
CHANGED
|
@@ -1,145 +1,238 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { red } from 'ansis';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { AssetsManager } from '../lib/compiler/assets-manager.js';
|
|
5
|
+
import { deleteOutDirIfEnabled } from '../lib/compiler/helpers/delete-out-dir.js';
|
|
6
|
+
import { getBuilder } from '../lib/compiler/helpers/get-builder.js';
|
|
7
|
+
import { getEffectiveRootDir } from '../lib/compiler/helpers/get-effective-root-dir.js';
|
|
8
|
+
import { getRspackConfigPath } from '../lib/compiler/helpers/get-rspack-config-path.js';
|
|
9
|
+
import { getTscConfigPath } from '../lib/compiler/helpers/get-tsc-config.path.js';
|
|
10
|
+
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default.js';
|
|
11
|
+
import { getWebpackConfigPath } from '../lib/compiler/helpers/get-webpack-config-path.js';
|
|
12
|
+
import { TsConfigProvider, } from '../lib/compiler/helpers/tsconfig-provider.js';
|
|
13
|
+
import { PluginsLoader } from '../lib/compiler/plugins/plugins-loader.js';
|
|
14
|
+
import { TypeScriptBinaryLoader } from '../lib/compiler/typescript-loader.js';
|
|
15
|
+
import { NestConfigurationLoader, } from '../lib/configuration/index.js';
|
|
16
|
+
import { defaultOutDir, defaultRspackConfigFilename, defaultWebpackConfigFilename, } from '../lib/configuration/defaults.js';
|
|
17
|
+
import { FileSystemReader } from '../lib/readers/index.js';
|
|
18
|
+
import { ERROR_PREFIX, INFO_PREFIX } from '../lib/ui/index.js';
|
|
19
|
+
import { isModuleAvailable } from '../lib/utils/is-module-available.js';
|
|
20
|
+
import { AbstractAction } from './abstract.action.js';
|
|
21
|
+
const require = createRequire(import.meta.url);
|
|
22
|
+
export class BuildAction extends AbstractAction {
|
|
23
|
+
pluginsLoader = new PluginsLoader();
|
|
24
|
+
tsLoader = new TypeScriptBinaryLoader();
|
|
25
|
+
tsConfigProvider = new TsConfigProvider(this.tsLoader);
|
|
26
|
+
fileSystemReader = new FileSystemReader(process.cwd());
|
|
27
|
+
loader = new NestConfigurationLoader(this.fileSystemReader);
|
|
28
|
+
/**
|
|
29
|
+
* Each app build owns its assets manager: `closeWatchers()` closes every
|
|
30
|
+
* watcher it holds, so a manager shared across a `--parallel` run would let
|
|
31
|
+
* the first app to finish tear down the watchers of apps still building.
|
|
32
|
+
*/
|
|
33
|
+
createAssetsManager() {
|
|
34
|
+
return new AssetsManager();
|
|
30
35
|
}
|
|
31
|
-
async handle(
|
|
36
|
+
async handle(context) {
|
|
37
|
+
const { apps, watch, watchAssets } = context;
|
|
32
38
|
try {
|
|
33
|
-
|
|
34
|
-
const watchMode = !!(watchModeOption && watchModeOption.value);
|
|
35
|
-
const watchAssetsModeOption = commandOptions.find((option) => option.name === 'watchAssets');
|
|
36
|
-
const watchAssetsMode = !!(watchAssetsModeOption && watchAssetsModeOption.value);
|
|
37
|
-
await this.runBuild(commandInputs, commandOptions, watchMode, watchAssetsMode);
|
|
39
|
+
await this.runBuild(apps, context, watch, watchAssets);
|
|
38
40
|
}
|
|
39
41
|
catch (err) {
|
|
40
42
|
if (err instanceof Error) {
|
|
41
|
-
console.
|
|
43
|
+
console.error(`\n${ERROR_PREFIX} ${err.message}\n`);
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
|
-
console.error(`\n${
|
|
46
|
+
console.error(`\n${red(err)}\n`);
|
|
45
47
|
}
|
|
46
48
|
process.exit(1);
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
|
-
async runBuild(
|
|
50
|
-
const configFileName =
|
|
51
|
+
async runBuild(apps, options, watchMode, watchAssetsMode, isDebugEnabled = false, onSuccess) {
|
|
52
|
+
const configFileName = options.config;
|
|
51
53
|
const configuration = await this.loader.load(configFileName);
|
|
52
|
-
const buildAll = commandOptions.find((opt) => opt.name === 'all')?.value;
|
|
53
54
|
let appNames;
|
|
54
|
-
if (
|
|
55
|
-
// If the "all" flag is set, we need to build all projects in a monorepo.
|
|
55
|
+
if (options.all) {
|
|
56
56
|
appNames = [];
|
|
57
57
|
if (configuration.projects) {
|
|
58
58
|
appNames.push(...Object.keys(configuration.projects));
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
appNames =
|
|
63
|
-
.filter((input) => input.name === 'app')
|
|
64
|
-
.map((input) => input.value);
|
|
62
|
+
appNames = apps;
|
|
65
63
|
}
|
|
66
64
|
if (appNames.length === 0) {
|
|
67
|
-
// If there are no projects, use "undefined" to build the default project.
|
|
68
65
|
appNames.push(undefined);
|
|
69
66
|
}
|
|
70
|
-
|
|
71
|
-
const pathToTsconfig =
|
|
72
|
-
const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
const appBuildContexts = appNames.map((appName) => {
|
|
68
|
+
const pathToTsconfig = getTscConfigPath(configuration, options, appName);
|
|
69
|
+
const { exclude, options: tsOptions, fileNames: tsFileNames, } = this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
|
|
70
|
+
return {
|
|
71
|
+
appName,
|
|
72
|
+
pathToTsconfig,
|
|
73
|
+
tsOptions,
|
|
74
|
+
exclude,
|
|
75
|
+
outDir: tsOptions.outDir || defaultOutDir,
|
|
76
|
+
tsRootDir: getEffectiveRootDir(tsOptions.rootDir, tsFileNames),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
// Every output directory is cleaned before any app starts emitting.
|
|
80
|
+
// Cleaning inside the per-app build deletes output another app already
|
|
81
|
+
// wrote whenever projects share an outDir (the default monorepo layout):
|
|
82
|
+
// a race under `--parallel`, and deterministic clobbering under `--all`.
|
|
83
|
+
for (const { appName, outDir, tsOptions } of appBuildContexts) {
|
|
84
|
+
await deleteOutDirIfEnabled(configuration, appName, outDir, tsOptions);
|
|
85
|
+
}
|
|
86
|
+
this.warnOnIgnoredLibraryAssets(configuration, appNames);
|
|
87
|
+
const buildApp = async ({ appName, pathToTsconfig, tsOptions, exclude, outDir, tsRootDir, }) => {
|
|
88
|
+
const assetsManager = this.createAssetsManager();
|
|
89
|
+
const isWebpackEnabled = getValueOrDefault(configuration, 'compilerOptions.webpack', appName, 'webpack', options);
|
|
75
90
|
const builder = isWebpackEnabled
|
|
76
91
|
? { type: 'webpack' }
|
|
77
|
-
:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const typeCheck = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', commandOptions);
|
|
92
|
+
: getBuilder(configuration, options, appName);
|
|
93
|
+
assetsManager.copyAssets(configuration, appName, outDir, watchAssetsMode, onSuccess, tsRootDir);
|
|
94
|
+
const typeCheck = getValueOrDefault(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', options);
|
|
81
95
|
if (typeCheck && builder.type !== 'swc') {
|
|
82
|
-
console.warn(
|
|
96
|
+
console.warn(INFO_PREFIX +
|
|
83
97
|
` "typeCheck" will not have any effect when "builder" is not "swc".`);
|
|
84
98
|
}
|
|
99
|
+
const emitDeclarations = getValueOrDefault(configuration, 'compilerOptions.emitDeclarations', appName, 'emitDeclarations', options);
|
|
100
|
+
if (emitDeclarations && builder.type !== 'swc') {
|
|
101
|
+
console.warn(INFO_PREFIX +
|
|
102
|
+
` "emitDeclarations" will not have any effect when "builder" is not "swc".`);
|
|
103
|
+
}
|
|
85
104
|
switch (builder.type) {
|
|
86
105
|
case 'tsc':
|
|
87
|
-
await this.runTsc(watchMode,
|
|
106
|
+
await this.runTsc(watchMode, options, configuration, pathToTsconfig, appName, onSuccess, assetsManager);
|
|
88
107
|
break;
|
|
89
108
|
case 'webpack':
|
|
90
|
-
await this.runWebpack(configuration, appName,
|
|
109
|
+
await this.runWebpack(configuration, appName, options, pathToTsconfig, isDebugEnabled, watchMode, onSuccess, assetsManager);
|
|
110
|
+
break;
|
|
111
|
+
case 'rspack':
|
|
112
|
+
await this.runRspack(configuration, appName, options, pathToTsconfig, tsOptions, isDebugEnabled, watchMode, onSuccess, assetsManager);
|
|
91
113
|
break;
|
|
92
114
|
case 'swc':
|
|
93
|
-
await this.runSwc(configuration, appName, pathToTsconfig, watchMode,
|
|
115
|
+
await this.runSwc(configuration, appName, pathToTsconfig, watchMode, options, tsOptions, exclude, emitDeclarations, onSuccess, assetsManager);
|
|
94
116
|
break;
|
|
95
117
|
}
|
|
118
|
+
};
|
|
119
|
+
const parallel = options.parallel;
|
|
120
|
+
if (parallel && appBuildContexts.length > 1) {
|
|
121
|
+
// Coerce to a positive integer; fall back to unlimited for any
|
|
122
|
+
// non-positive or non-finite value to guard against an infinite loop
|
|
123
|
+
// when `i += concurrency` would never advance.
|
|
124
|
+
const requested = typeof parallel === 'number' ? parallel : appBuildContexts.length;
|
|
125
|
+
const concurrency = Number.isFinite(requested) && requested >= 1
|
|
126
|
+
? Math.floor(requested)
|
|
127
|
+
: appBuildContexts.length;
|
|
128
|
+
for (let i = 0; i < appBuildContexts.length; i += concurrency) {
|
|
129
|
+
const chunk = appBuildContexts.slice(i, i + concurrency);
|
|
130
|
+
await Promise.all(chunk.map((context) => buildApp(context)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
for (const context of appBuildContexts) {
|
|
135
|
+
await buildApp(context);
|
|
136
|
+
}
|
|
96
137
|
}
|
|
97
138
|
}
|
|
98
|
-
async runSwc(configuration, appName, pathToTsconfig, watchMode, options, tsOptions, onSuccess) {
|
|
99
|
-
const { SwcCompiler } = await
|
|
139
|
+
async runSwc(configuration, appName, pathToTsconfig, watchMode, options, tsOptions, tsConfigExclude, emitDeclarations, onSuccess, assetsManager) {
|
|
140
|
+
const { SwcCompiler } = await import('../lib/compiler/swc/swc-compiler.js');
|
|
100
141
|
const swc = new SwcCompiler(this.pluginsLoader);
|
|
142
|
+
const isSilent = !!options.silent;
|
|
101
143
|
await swc.run(configuration, pathToTsconfig, appName, {
|
|
102
144
|
watch: watchMode,
|
|
103
|
-
typeCheck:
|
|
145
|
+
typeCheck: getValueOrDefault(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', options),
|
|
146
|
+
emitDeclarations,
|
|
104
147
|
tsOptions,
|
|
105
|
-
|
|
148
|
+
tsConfigExclude,
|
|
149
|
+
assetsManager,
|
|
150
|
+
silent: isSilent,
|
|
106
151
|
}, onSuccess);
|
|
107
152
|
}
|
|
108
|
-
async runWebpack(configuration, appName,
|
|
109
|
-
const { WebpackCompiler } = await
|
|
153
|
+
async runWebpack(configuration, appName, options, pathToTsconfig, debug, watchMode, onSuccess, assetsManager) {
|
|
154
|
+
const { WebpackCompiler } = await import('../lib/compiler/webpack-compiler.js');
|
|
110
155
|
const webpackCompiler = new WebpackCompiler(this.pluginsLoader);
|
|
111
|
-
const webpackPath =
|
|
112
|
-
|
|
113
|
-
const webpackConfigFactoryOrConfig = this.getWebpackConfigFactoryByPath(webpackPath,
|
|
156
|
+
const webpackPath = getWebpackConfigPath(configuration, options, appName) ??
|
|
157
|
+
defaultWebpackConfigFilename;
|
|
158
|
+
const webpackConfigFactoryOrConfig = this.getWebpackConfigFactoryByPath(webpackPath, defaultWebpackConfigFilename);
|
|
114
159
|
return webpackCompiler.run(configuration, pathToTsconfig, appName, {
|
|
115
|
-
|
|
160
|
+
options,
|
|
116
161
|
webpackConfigFactoryOrConfig,
|
|
117
162
|
debug,
|
|
118
163
|
watchMode,
|
|
119
|
-
assetsManager
|
|
164
|
+
assetsManager,
|
|
120
165
|
}, onSuccess);
|
|
121
166
|
}
|
|
122
|
-
async runTsc(watchMode, options, configuration, pathToTsconfig, appName, onSuccess) {
|
|
167
|
+
async runTsc(watchMode, options, configuration, pathToTsconfig, appName, onSuccess, assetsManager) {
|
|
123
168
|
if (watchMode) {
|
|
124
|
-
const { WatchCompiler } = await
|
|
169
|
+
const { WatchCompiler } = await import('../lib/compiler/watch-compiler.js');
|
|
125
170
|
const watchCompiler = new WatchCompiler(this.pluginsLoader, this.tsConfigProvider, this.tsLoader);
|
|
126
|
-
const isPreserveWatchOutputEnabled = options.
|
|
171
|
+
const isPreserveWatchOutputEnabled = !!options.preserveWatchOutput;
|
|
127
172
|
watchCompiler.run(configuration, pathToTsconfig, appName, { preserveWatchOutput: isPreserveWatchOutputEnabled }, onSuccess);
|
|
128
173
|
}
|
|
129
174
|
else {
|
|
130
|
-
const { Compiler } = await
|
|
175
|
+
const { Compiler } = await import('../lib/compiler/compiler.js');
|
|
131
176
|
const compiler = new Compiler(this.pluginsLoader, this.tsConfigProvider, this.tsLoader);
|
|
132
177
|
compiler.run(configuration, pathToTsconfig, appName, undefined, onSuccess);
|
|
133
|
-
await
|
|
178
|
+
await assetsManager.closeWatchers();
|
|
134
179
|
}
|
|
135
180
|
}
|
|
136
181
|
getWebpackConfigFactoryByPath(webpackPath, defaultPath) {
|
|
137
|
-
const pathToWebpackFile =
|
|
138
|
-
const isWebpackFileAvailable =
|
|
182
|
+
const pathToWebpackFile = join(process.cwd(), webpackPath);
|
|
183
|
+
const isWebpackFileAvailable = isModuleAvailable(pathToWebpackFile);
|
|
139
184
|
if (!isWebpackFileAvailable && webpackPath === defaultPath) {
|
|
140
|
-
return (
|
|
185
|
+
return (_config) => ({});
|
|
141
186
|
}
|
|
142
187
|
return require(pathToWebpackFile);
|
|
143
188
|
}
|
|
189
|
+
async runRspack(configuration, appName, options, pathToTsconfig, tsOptions, debug, watchMode, onSuccess, assetsManager) {
|
|
190
|
+
const { RspackCompiler } = await import('../lib/compiler/rspack-compiler.js');
|
|
191
|
+
const rspackCompiler = new RspackCompiler(this.pluginsLoader);
|
|
192
|
+
const rspackPath = getRspackConfigPath(configuration, options, appName) ??
|
|
193
|
+
defaultRspackConfigFilename;
|
|
194
|
+
const rspackConfigFactoryOrConfig = this.getRspackConfigFactoryByPath(rspackPath, defaultRspackConfigFilename);
|
|
195
|
+
return rspackCompiler.run(configuration, pathToTsconfig, appName, {
|
|
196
|
+
options,
|
|
197
|
+
rspackConfigFactoryOrConfig,
|
|
198
|
+
debug,
|
|
199
|
+
watchMode,
|
|
200
|
+
tsOptions,
|
|
201
|
+
assetsManager,
|
|
202
|
+
}, onSuccess);
|
|
203
|
+
}
|
|
204
|
+
getRspackConfigFactoryByPath(rspackPath, defaultPath) {
|
|
205
|
+
const pathToRspackFile = join(process.cwd(), rspackPath);
|
|
206
|
+
const isRspackFileAvailable = isModuleAvailable(pathToRspackFile);
|
|
207
|
+
if (!isRspackFileAvailable && rspackPath === defaultPath) {
|
|
208
|
+
return (_config) => ({});
|
|
209
|
+
}
|
|
210
|
+
return require(pathToRspackFile);
|
|
211
|
+
}
|
|
212
|
+
warnOnIgnoredLibraryAssets(configuration, appNames) {
|
|
213
|
+
if (!configuration.projects) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// A library whose assets any of the apps being built opts into via
|
|
217
|
+
// `includeLibraryAssets` *is* copied, so warning about it would be wrong.
|
|
218
|
+
const includedLibraries = new Set();
|
|
219
|
+
for (const appName of appNames) {
|
|
220
|
+
const included = getValueOrDefault(configuration, 'compilerOptions.includeLibraryAssets', appName) || [];
|
|
221
|
+
for (const libraryName of included) {
|
|
222
|
+
includedLibraries.add(libraryName);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
for (const [projectName, project] of Object.entries(configuration.projects)) {
|
|
226
|
+
if (appNames.includes(projectName) ||
|
|
227
|
+
includedLibraries.has(projectName)) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (project.type === 'library' &&
|
|
231
|
+
project.compilerOptions?.assets?.length) {
|
|
232
|
+
console.warn(INFO_PREFIX +
|
|
233
|
+
` Assets configured for library "${projectName}" will not be copied during application build.` +
|
|
234
|
+
` Add it to "compilerOptions.includeLibraryAssets" or build the library separately.`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
144
238
|
}
|
|
145
|
-
exports.BuildAction = BuildAction;
|