@depup/nestjs__cli 11.0.24-depup.8 → 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 +6 -14
- 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 +6 -38
- 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 +64 -77
|
@@ -1,40 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { cyan } from 'ansis';
|
|
2
|
+
import { fork, spawnSync } from 'child_process';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { stat } from 'fs/promises';
|
|
5
|
+
import { minimatch } from 'minimatch';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { dirname, isAbsolute, join, posix, relative } from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
import { ERROR_PREFIX } from '../../ui/index.js';
|
|
11
|
+
import { treeKillSync } from '../../utils/tree-kill.js';
|
|
12
|
+
import { BaseCompiler } from '../base-compiler.js';
|
|
13
|
+
import { swcDefaultsFactory } from '../defaults/swc-defaults.js';
|
|
14
|
+
import { getValueOrDefault } from '../helpers/get-value-or-default.js';
|
|
15
|
+
import { PluginMetadataGenerator } from '../plugins/plugin-metadata-generator.js';
|
|
16
|
+
import { watchDirectoryRecursively } from '../watchers/recursive-directory-watcher.js';
|
|
17
|
+
import { FOUND_NO_ISSUES_GENERATING_METADATA, FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED, SWC_LOG_PREFIX, } from './constants.js';
|
|
18
|
+
import { TypeCheckerHost } from './type-checker-host.js';
|
|
19
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
20
|
+
const __dirname = dirname(__filename);
|
|
21
|
+
const require = createRequire(import.meta.url);
|
|
22
|
+
export class SwcCompiler extends BaseCompiler {
|
|
23
|
+
pluginMetadataGenerator = new PluginMetadataGenerator();
|
|
24
|
+
typeCheckerHost = new TypeCheckerHost();
|
|
20
25
|
constructor(pluginsLoader) {
|
|
21
26
|
super(pluginsLoader);
|
|
22
|
-
this.pluginMetadataGenerator = new plugin_metadata_generator_1.PluginMetadataGenerator();
|
|
23
|
-
this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
|
|
24
27
|
}
|
|
25
28
|
async run(configuration, tsConfigPath, appName, extras, onSuccess) {
|
|
26
|
-
const swcOptions =
|
|
27
|
-
const swcrcFilePath =
|
|
29
|
+
const swcOptions = swcDefaultsFactory(extras.tsOptions, configuration, extras.tsConfigExclude);
|
|
30
|
+
const swcrcFilePath = getValueOrDefault(configuration, 'compilerOptions.builder.options.swcrcPath', appName);
|
|
28
31
|
if (extras.watch) {
|
|
29
32
|
if (extras.typeCheck) {
|
|
30
33
|
this.runTypeChecker(configuration, tsConfigPath, appName, extras);
|
|
31
34
|
}
|
|
32
35
|
await this.runSwc(swcOptions, extras, swcrcFilePath);
|
|
36
|
+
if (extras.emitDeclarations) {
|
|
37
|
+
this.emitDeclarations(tsConfigPath);
|
|
38
|
+
}
|
|
33
39
|
if (onSuccess) {
|
|
34
40
|
onSuccess();
|
|
35
41
|
const debounceTime = 150;
|
|
36
42
|
const callback = this.debounce(onSuccess, debounceTime);
|
|
37
|
-
this.watchFilesInOutDir(swcOptions, callback);
|
|
43
|
+
void this.watchFilesInOutDir(swcOptions, callback);
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
else {
|
|
@@ -42,12 +48,28 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
42
48
|
await this.runTypeChecker(configuration, tsConfigPath, appName, extras);
|
|
43
49
|
}
|
|
44
50
|
await this.runSwc(swcOptions, extras, swcrcFilePath);
|
|
51
|
+
if (extras.emitDeclarations) {
|
|
52
|
+
this.emitDeclarations(tsConfigPath);
|
|
53
|
+
}
|
|
45
54
|
if (onSuccess) {
|
|
46
55
|
onSuccess();
|
|
47
56
|
}
|
|
48
57
|
await extras.assetsManager?.closeWatchers();
|
|
49
58
|
}
|
|
50
59
|
}
|
|
60
|
+
emitDeclarations(tsConfigPath) {
|
|
61
|
+
process.nextTick(() => console.log(SWC_LOG_PREFIX, cyan('Emitting declaration files...')));
|
|
62
|
+
const tscPath = join(process.cwd(), 'node_modules', '.bin', 'tsc');
|
|
63
|
+
const result = spawnSync(tscPath, ['--emitDeclarationOnly', '-p', tsConfigPath], {
|
|
64
|
+
cwd: process.cwd(),
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
shell: true,
|
|
67
|
+
});
|
|
68
|
+
if (result.status !== 0) {
|
|
69
|
+
console.error(ERROR_PREFIX +
|
|
70
|
+
' Failed to emit declaration files. Please ensure "declaration" is enabled in your tsconfig.');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
51
73
|
runTypeChecker(configuration, tsConfigPath, appName, extras) {
|
|
52
74
|
if (extras.watch) {
|
|
53
75
|
const args = [
|
|
@@ -56,10 +78,10 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
56
78
|
configuration.sourceRoot ?? 'src',
|
|
57
79
|
JSON.stringify(configuration.compilerOptions.plugins ?? []),
|
|
58
80
|
];
|
|
59
|
-
const childProcessRef =
|
|
81
|
+
const childProcessRef = fork(join(__dirname, 'forked-type-checker.js'), args, {
|
|
60
82
|
cwd: process.cwd(),
|
|
61
83
|
});
|
|
62
|
-
process.on('exit', () => childProcessRef &&
|
|
84
|
+
process.on('exit', () => childProcessRef && treeKillSync(childProcessRef.pid));
|
|
63
85
|
}
|
|
64
86
|
else {
|
|
65
87
|
const { readonlyVisitors } = this.loadPlugins(configuration, tsConfigPath, appName);
|
|
@@ -75,7 +97,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
75
97
|
resolve();
|
|
76
98
|
}
|
|
77
99
|
if (readonlyVisitors.length > 0) {
|
|
78
|
-
process.nextTick(() => console.log(
|
|
100
|
+
process.nextTick(() => console.log(FOUND_NO_ISSUES_GENERATING_METADATA));
|
|
79
101
|
this.pluginMetadataGenerator.generate({
|
|
80
102
|
outputDir,
|
|
81
103
|
visitors: readonlyVisitors,
|
|
@@ -83,7 +105,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
83
105
|
});
|
|
84
106
|
}
|
|
85
107
|
else {
|
|
86
|
-
process.nextTick(() => console.log(
|
|
108
|
+
process.nextTick(() => console.log(FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED));
|
|
87
109
|
}
|
|
88
110
|
},
|
|
89
111
|
});
|
|
@@ -98,11 +120,13 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
98
120
|
}
|
|
99
121
|
}
|
|
100
122
|
async runSwc(options, extras, swcrcFilePath) {
|
|
101
|
-
|
|
123
|
+
if (this.shouldLogSwcStatus(extras)) {
|
|
124
|
+
process.nextTick(() => console.log(SWC_LOG_PREFIX, cyan('Running...')));
|
|
125
|
+
}
|
|
102
126
|
const swcCli = this.loadSwcCliBinary();
|
|
103
127
|
const swcRcFile = await this.getSwcRcFileContentIfExists(swcrcFilePath);
|
|
104
128
|
const swcOptions = this.deepMerge(options.swcOptions, swcRcFile);
|
|
105
|
-
if (swcOptions?.jsc?.baseUrl && !
|
|
129
|
+
if (swcOptions?.jsc?.baseUrl && !isAbsolute(swcOptions?.jsc?.baseUrl)) {
|
|
106
130
|
// jsc.baseUrl should be resolved by the caller, if it's passed as an object.
|
|
107
131
|
// https://github.com/swc-project/swc/pull/7827
|
|
108
132
|
const rootDir = process.cwd();
|
|
@@ -120,35 +144,54 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
120
144
|
// This is required since SWC no longer supports auto-compiling of newly added files in watch mode.
|
|
121
145
|
// We need to watch the source directory and trigger SWC compilation manually.
|
|
122
146
|
await this.watchFilesInSrcDir(options, async (file) => {
|
|
123
|
-
// Transpile newly added file
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
147
|
+
// Transpile newly added file (one-shot: inheriting "watch" here would
|
|
148
|
+
// register one more permanent @swc/cli watcher per added file, and each
|
|
149
|
+
// async invocation constructs a Piscina pool that is never destroyed)
|
|
150
|
+
try {
|
|
151
|
+
await swcCli.default({
|
|
152
|
+
...swcCliOpts,
|
|
153
|
+
cliOptions: {
|
|
154
|
+
...swcCliOpts.cliOptions,
|
|
155
|
+
filenames: [file],
|
|
156
|
+
watch: false,
|
|
157
|
+
sync: true,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Outside of watch mode "@swc/cli" rejects when a file fails to
|
|
163
|
+
// compile, after having reported the failure itself. Swallow it so
|
|
164
|
+
// that adding a file that does not compile yet does not tear down
|
|
165
|
+
// the watch process.
|
|
166
|
+
}
|
|
131
167
|
});
|
|
132
168
|
}
|
|
133
169
|
await swcCli.default(swcCliOpts);
|
|
134
170
|
}
|
|
171
|
+
shouldLogSwcStatus(extras) {
|
|
172
|
+
if (extras.silent) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
const npmLogLevel = process.env.npm_config_loglevel?.toLowerCase();
|
|
176
|
+
return npmLogLevel !== 'silent';
|
|
177
|
+
}
|
|
135
178
|
loadSwcCliBinary() {
|
|
136
179
|
try {
|
|
137
180
|
return require('@swc/cli/lib/swc/dir');
|
|
138
181
|
}
|
|
139
|
-
catch
|
|
140
|
-
console.error(
|
|
182
|
+
catch {
|
|
183
|
+
console.error(ERROR_PREFIX +
|
|
141
184
|
' Failed to load "@swc/cli" and/or "@swc/core" required packages. Please, make sure to install them as development dependencies.');
|
|
142
185
|
process.exit(1);
|
|
143
186
|
}
|
|
144
187
|
}
|
|
145
188
|
getSwcRcFileContentIfExists(swcrcFilePath) {
|
|
146
189
|
try {
|
|
147
|
-
return JSON.parse(
|
|
190
|
+
return JSON.parse(readFileSync(join(process.cwd(), swcrcFilePath ?? '.swcrc'), 'utf8'));
|
|
148
191
|
}
|
|
149
|
-
catch
|
|
192
|
+
catch {
|
|
150
193
|
if (swcrcFilePath !== undefined) {
|
|
151
|
-
console.error(
|
|
194
|
+
console.error(ERROR_PREFIX +
|
|
152
195
|
` Failed to load "${swcrcFilePath}". Please, check if the file exists and is valid JSON.`);
|
|
153
196
|
process.exit(1);
|
|
154
197
|
}
|
|
@@ -170,7 +213,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
170
213
|
}
|
|
171
214
|
const merged = { ...target };
|
|
172
215
|
for (const key in source) {
|
|
173
|
-
if (
|
|
216
|
+
if (Object.hasOwn(source, key)) {
|
|
174
217
|
if (key in target) {
|
|
175
218
|
merged[key] = this.deepMerge(target[key], source[key]);
|
|
176
219
|
}
|
|
@@ -190,7 +233,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
190
233
|
}
|
|
191
234
|
async watchFilesInSrcDir(options, onFileAdded) {
|
|
192
235
|
const srcDir = options.cliOptions?.filenames?.[0];
|
|
193
|
-
const isDirectory = await
|
|
236
|
+
const isDirectory = await stat(srcDir)
|
|
194
237
|
.then((stats) => stats.isDirectory())
|
|
195
238
|
.catch(() => false);
|
|
196
239
|
if (!srcDir || !isDirectory) {
|
|
@@ -199,35 +242,38 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
199
242
|
return;
|
|
200
243
|
}
|
|
201
244
|
const extensions = options.cliOptions?.extensions ?? ['.ts'];
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
245
|
+
await watchDirectoryRecursively(srcDir, {
|
|
246
|
+
extensions,
|
|
247
|
+
onAdd: async (file) => {
|
|
248
|
+
if (this.isIgnoredBySwc(file, options.cliOptions?.ignore)) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
await onFileAdded(file);
|
|
209
252
|
},
|
|
210
253
|
});
|
|
211
|
-
watcher.on('add', async (file) => onFileAdded(file));
|
|
212
254
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
stabilityThreshold: 50,
|
|
223
|
-
pollInterval: 10,
|
|
224
|
-
},
|
|
255
|
+
isIgnoredBySwc(file, ignore = [], cwd = process.cwd()) {
|
|
256
|
+
if (!ignore.length) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
const relativeFile = isAbsolute(file) ? relative(cwd, file) : file;
|
|
260
|
+
const normalizedFile = this.normalizeSwcIgnorePath(relativeFile);
|
|
261
|
+
return ignore.some((pattern) => {
|
|
262
|
+
const normalizedPattern = this.normalizeSwcIgnorePath(pattern);
|
|
263
|
+
return [normalizedPattern, posix.join(normalizedPattern, '**')].some((pattern) => minimatch(normalizedFile, pattern));
|
|
225
264
|
});
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
265
|
+
}
|
|
266
|
+
normalizeSwcIgnorePath(value) {
|
|
267
|
+
return posix.normalize(value.replace(/\\/g, '/'));
|
|
268
|
+
}
|
|
269
|
+
async watchFilesInOutDir(options, onChange) {
|
|
270
|
+
const dir = isAbsolute(options.cliOptions.outDir)
|
|
271
|
+
? options.cliOptions.outDir
|
|
272
|
+
: join(process.cwd(), options.cliOptions.outDir);
|
|
273
|
+
await watchDirectoryRecursively(dir, {
|
|
274
|
+
extensions: ['.js', '.mjs'],
|
|
275
|
+
onAdd: onChange,
|
|
276
|
+
onChange: onChange,
|
|
230
277
|
});
|
|
231
278
|
}
|
|
232
279
|
}
|
|
233
|
-
exports.SwcCompiler = SwcCompiler;
|
|
@@ -1,43 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class TypeCheckerHost {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.typescriptLoader = new typescript_loader_1.TypeScriptBinaryLoader();
|
|
13
|
-
this.tsConfigProvider = new tsconfig_provider_1.TsConfigProvider(this.typescriptLoader);
|
|
14
|
-
}
|
|
1
|
+
import { red } from 'ansis';
|
|
2
|
+
import ora from 'ora';
|
|
3
|
+
import * as ts from 'typescript';
|
|
4
|
+
import { TsConfigProvider } from '../helpers/tsconfig-provider.js';
|
|
5
|
+
import { TypeScriptBinaryLoader } from '../typescript-loader.js';
|
|
6
|
+
import { INITIALIZING_TYPE_CHECKER, TSC_LOG_ERROR_PREFIX, TSC_NO_ERRORS_MESSAGE, } from './constants.js';
|
|
7
|
+
export class TypeCheckerHost {
|
|
8
|
+
typescriptLoader = new TypeScriptBinaryLoader();
|
|
9
|
+
tsConfigProvider = new TsConfigProvider(this.typescriptLoader);
|
|
15
10
|
run(tsconfigPath, options) {
|
|
16
11
|
if (!tsconfigPath) {
|
|
17
12
|
throw new Error('"tsconfigPath" is required when "tsProgramRef" is not provided.');
|
|
18
13
|
}
|
|
19
14
|
const tsBinary = this.typescriptLoader.load();
|
|
20
15
|
const spinner = ora({
|
|
21
|
-
text:
|
|
16
|
+
text: INITIALIZING_TYPE_CHECKER,
|
|
22
17
|
});
|
|
23
18
|
if (options.watch) {
|
|
24
19
|
console.log();
|
|
25
20
|
spinner.start();
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
try {
|
|
22
|
+
this.runInWatchMode(tsconfigPath, tsBinary, options);
|
|
23
|
+
spinner.succeed();
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
spinner.fail();
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
30
31
|
spinner.start();
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
try {
|
|
33
|
+
this.runOnce(tsconfigPath, tsBinary, options);
|
|
34
|
+
spinner.succeed();
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
spinner.fail();
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
runInWatchMode(tsconfigPath, tsBinary, options) {
|
|
35
42
|
const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(tsconfigPath);
|
|
36
43
|
let builderProgram = undefined;
|
|
37
44
|
const reportWatchStatusCallback = (diagnostic) => {
|
|
38
|
-
if (diagnostic.messageText !==
|
|
45
|
+
if (diagnostic.messageText !== TSC_NO_ERRORS_MESSAGE) {
|
|
39
46
|
if (diagnostic.messageText?.includes('Found')) {
|
|
40
|
-
console.
|
|
47
|
+
console.error(TSC_LOG_ERROR_PREFIX, red(diagnostic.messageText.toString()));
|
|
41
48
|
}
|
|
42
49
|
return;
|
|
43
50
|
}
|
|
@@ -71,9 +78,10 @@ class TypeCheckerHost {
|
|
|
71
78
|
getCurrentDirectory: tsBinary.sys.getCurrentDirectory,
|
|
72
79
|
getNewLine: () => tsBinary.sys.newLine,
|
|
73
80
|
};
|
|
81
|
+
const formattedDiagnostics = tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost);
|
|
74
82
|
console.log();
|
|
75
|
-
console.log(
|
|
76
|
-
|
|
83
|
+
console.log(formattedDiagnostics);
|
|
84
|
+
throw new Error(`Found ${diagnostics.length} type error(s) during compilation.`);
|
|
77
85
|
}
|
|
78
86
|
options.onTypeCheck?.(programRef);
|
|
79
87
|
}
|
|
@@ -87,4 +95,3 @@ class TypeCheckerHost {
|
|
|
87
95
|
return tsBinary.createWatchCompilerHost(tsConfigPath, tsOptions, tsBinary.sys, undefined, origDiagnosticReporter, reportWatchStatusCallback);
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
|
-
exports.TypeCheckerHost = TypeCheckerHost;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { CLI_ERRORS } from '../ui/index.js';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
export class TypeScriptBinaryLoader {
|
|
5
|
+
tsBinary;
|
|
6
6
|
load() {
|
|
7
7
|
if (this.tsBinary) {
|
|
8
8
|
return this.tsBinary;
|
|
@@ -12,7 +12,6 @@ class TypeScriptBinaryLoader {
|
|
|
12
12
|
const tsBinaryPath = require.resolve('typescript', {
|
|
13
13
|
paths: [process.cwd(), ...this.getModulePaths()],
|
|
14
14
|
});
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16
15
|
tsBinary = require(tsBinaryPath);
|
|
17
16
|
}
|
|
18
17
|
catch {
|
|
@@ -24,11 +23,11 @@ class TypeScriptBinaryLoader {
|
|
|
24
23
|
}
|
|
25
24
|
assertProgrammaticApiIsSupported(tsBinary) {
|
|
26
25
|
if (typeof tsBinary.getParsedCommandLineOfConfigFile !== 'function') {
|
|
27
|
-
throw new Error(
|
|
26
|
+
throw new Error(CLI_ERRORS.UNSUPPORTED_TYPESCRIPT_VERSION(tsBinary.version));
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
getModulePaths() {
|
|
31
|
-
const modulePaths =
|
|
30
|
+
const modulePaths = require.resolve.paths('typescript') ?? [];
|
|
32
31
|
const packageDeps = modulePaths.slice(0, 3);
|
|
33
32
|
return [
|
|
34
33
|
...packageDeps.reverse(),
|
|
@@ -36,4 +35,3 @@ class TypeScriptBinaryLoader {
|
|
|
36
35
|
];
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
exports.TypeScriptBinaryLoader = TypeScriptBinaryLoader;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Configuration } from '../configuration';
|
|
2
|
-
import { BaseCompiler } from './base-compiler';
|
|
3
|
-
import { TsConfigProvider } from './helpers/tsconfig-provider';
|
|
4
|
-
import { PluginsLoader } from './plugins/plugins-loader';
|
|
5
|
-
import { TypeScriptBinaryLoader } from './typescript-loader';
|
|
1
|
+
import { Configuration } from '../configuration/index.js';
|
|
2
|
+
import { BaseCompiler } from './base-compiler.js';
|
|
3
|
+
import { TsConfigProvider } from './helpers/tsconfig-provider.js';
|
|
4
|
+
import { PluginsLoader } from './plugins/plugins-loader.js';
|
|
5
|
+
import { TypeScriptBinaryLoader } from './typescript-loader.js';
|
|
6
6
|
type TypescriptWatchCompilerExtras = {
|
|
7
7
|
/**
|
|
8
8
|
* If `undefined`, the value of 'preserveWatchOutput' option from tsconfig
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class WatchCompiler extends base_compiler_1.BaseCompiler {
|
|
1
|
+
import { CLI_ERRORS } from '../ui/errors.js';
|
|
2
|
+
import { BaseCompiler } from './base-compiler.js';
|
|
3
|
+
import { getValueOrDefault } from './helpers/get-value-or-default.js';
|
|
4
|
+
import { displayManualRestartTip, listenForManualRestart, } from './helpers/manual-restart.js';
|
|
5
|
+
import { tsconfigPathsBeforeHookFactory } from './hooks/tsconfig-paths.hook.js';
|
|
6
|
+
export class WatchCompiler extends BaseCompiler {
|
|
7
|
+
tsConfigProvider;
|
|
8
|
+
typescriptLoader;
|
|
10
9
|
constructor(pluginsLoader, tsConfigProvider, typescriptLoader) {
|
|
11
10
|
super(pluginsLoader);
|
|
12
11
|
this.tsConfigProvider = tsConfigProvider;
|
|
@@ -16,7 +15,7 @@ class WatchCompiler extends base_compiler_1.BaseCompiler {
|
|
|
16
15
|
const tsBin = this.typescriptLoader.load();
|
|
17
16
|
const configPath = tsBin.findConfigFile(process.cwd(), tsBin.sys.fileExists, tsConfigPath);
|
|
18
17
|
if (!configPath) {
|
|
19
|
-
throw new Error(
|
|
18
|
+
throw new Error(CLI_ERRORS.MISSING_TYPESCRIPT(tsConfigPath));
|
|
20
19
|
}
|
|
21
20
|
const { options, projectReferences } = this.tsConfigProvider.getByConfigFilename(tsConfigPath);
|
|
22
21
|
const createProgram = tsBin.createEmitAndSemanticDiagnosticsBuilderProgram;
|
|
@@ -26,12 +25,12 @@ class WatchCompiler extends base_compiler_1.BaseCompiler {
|
|
|
26
25
|
...options,
|
|
27
26
|
preserveWatchOutput: extras.preserveWatchOutput ?? options.preserveWatchOutput,
|
|
28
27
|
}, tsBin.sys, createProgram, this.createDiagnosticReporter(origDiagnosticReporter), this.createWatchStatusChanged(origWatchStatusReporter, onSuccess));
|
|
29
|
-
const manualRestart =
|
|
28
|
+
const manualRestart = getValueOrDefault(configuration, 'compilerOptions.manualRestart', appName);
|
|
30
29
|
const plugins = this.loadPlugins(configuration, tsConfigPath, appName);
|
|
31
30
|
this.overrideCreateProgramFn(host, manualRestart, projectReferences, plugins);
|
|
32
31
|
const watchProgram = tsBin.createWatchProgram(host);
|
|
33
32
|
if (manualRestart) {
|
|
34
|
-
|
|
33
|
+
listenForManualRestart(() => {
|
|
35
34
|
watchProgram.close();
|
|
36
35
|
this.run(configuration, tsConfigPath, appName, extras, onSuccess);
|
|
37
36
|
});
|
|
@@ -41,10 +40,10 @@ class WatchCompiler extends base_compiler_1.BaseCompiler {
|
|
|
41
40
|
const origCreateProgram = host.createProgram;
|
|
42
41
|
host.createProgram = (rootNames, options, host, oldProgram) => {
|
|
43
42
|
if (manualRestart) {
|
|
44
|
-
|
|
43
|
+
displayManualRestartTip();
|
|
45
44
|
}
|
|
46
45
|
const tsconfigPathsPlugin = options
|
|
47
|
-
?
|
|
46
|
+
? tsconfigPathsBeforeHookFactory(options)
|
|
48
47
|
: null;
|
|
49
48
|
const program = origCreateProgram(rootNames, options, host, oldProgram, undefined, projectReferences);
|
|
50
49
|
const origProgramEmit = program.emit;
|
|
@@ -85,4 +84,3 @@ class WatchCompiler extends base_compiler_1.BaseCompiler {
|
|
|
85
84
|
};
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
|
-
exports.WatchCompiler = WatchCompiler;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface RecursiveDirectoryWatcherOptions {
|
|
2
|
+
/**
|
|
3
|
+
* File suffixes to report events for, e.g. `['.ts']`. Matched with
|
|
4
|
+
* `String#endsWith`, so both `ts` and `.ts` are accepted.
|
|
5
|
+
*/
|
|
6
|
+
extensions: string[];
|
|
7
|
+
/**
|
|
8
|
+
* Called with the path of a file that appeared after the initial scan.
|
|
9
|
+
*/
|
|
10
|
+
onAdd?: (file: string) => unknown;
|
|
11
|
+
/**
|
|
12
|
+
* Called with the path of a file that was modified after the initial scan.
|
|
13
|
+
*/
|
|
14
|
+
onChange?: (file: string) => unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Equivalent of chokidar's "awaitWriteFinish": an event is only reported
|
|
17
|
+
* once the file size stopped changing for that many milliseconds.
|
|
18
|
+
*/
|
|
19
|
+
stabilityThreshold?: number;
|
|
20
|
+
pollInterval?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface RecursiveDirectoryWatcher {
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function supportsNativeRecursiveWatch(platform?: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Watches a directory tree for added and changed files.
|
|
28
|
+
*
|
|
29
|
+
* On macOS chokidar (since v4, which dropped the bundled `fsevents` backend)
|
|
30
|
+
* falls back to `fs.watch` per file, and libuv only uses FSEvents for
|
|
31
|
+
* directories - so every watched file permanently costs a file descriptor and
|
|
32
|
+
* a medium-sized project quickly hits `EMFILE`. A single recursive `fs.watch`
|
|
33
|
+
* over the directory costs one handle for the whole tree instead.
|
|
34
|
+
*
|
|
35
|
+
* See https://github.com/nestjs/nest-cli/issues/3512
|
|
36
|
+
*/
|
|
37
|
+
export declare function watchDirectoryRecursively(dir: string, options: RecursiveDirectoryWatcherOptions): Promise<RecursiveDirectoryWatcher>;
|