@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.
Files changed (220) hide show
  1. package/README.md +6 -14
  2. package/actions/abstract.action.d.ts +1 -2
  3. package/actions/abstract.action.js +1 -5
  4. package/actions/add.action.d.ts +3 -4
  5. package/actions/add.action.js +44 -53
  6. package/actions/build.action.d.ts +18 -11
  7. package/actions/build.action.js +172 -79
  8. package/actions/deploy.action.d.ts +6 -0
  9. package/actions/deploy.action.js +51 -0
  10. package/actions/generate.action.d.ts +3 -3
  11. package/actions/generate.action.js +61 -59
  12. package/actions/index.d.ts +9 -7
  13. package/actions/index.js +9 -23
  14. package/actions/info.action.d.ts +18 -28
  15. package/actions/info.action.js +80 -60
  16. package/actions/new.action.d.ts +3 -3
  17. package/actions/new.action.js +108 -104
  18. package/actions/start.action.d.ts +4 -7
  19. package/actions/start.action.js +40 -47
  20. package/actions/upgrade.action.d.ts +6 -0
  21. package/actions/upgrade.action.js +53 -0
  22. package/bin/nest.js +11 -10
  23. package/changes.json +6 -38
  24. package/commands/abstract.command.d.ts +3 -3
  25. package/commands/abstract.command.js +2 -5
  26. package/commands/add.command.d.ts +3 -3
  27. package/commands/add.command.js +17 -20
  28. package/commands/build.command.d.ts +3 -3
  29. package/commands/build.command.js +52 -56
  30. package/commands/command.input.js +1 -2
  31. package/commands/command.loader.d.ts +2 -2
  32. package/commands/command.loader.js +29 -22
  33. package/commands/context/add.context.d.ts +7 -0
  34. package/commands/context/add.context.js +1 -0
  35. package/commands/context/build.context.d.ts +17 -0
  36. package/commands/context/build.context.js +1 -0
  37. package/commands/context/deploy.context.d.ts +7 -0
  38. package/commands/context/deploy.context.js +1 -0
  39. package/commands/context/generate.context.d.ts +18 -0
  40. package/commands/context/generate.context.js +1 -0
  41. package/commands/context/index.d.ts +7 -0
  42. package/commands/context/index.js +7 -0
  43. package/commands/context/new.context.d.ts +19 -0
  44. package/commands/context/new.context.js +1 -0
  45. package/commands/context/start.context.d.ts +22 -0
  46. package/commands/context/start.context.js +1 -0
  47. package/commands/context/upgrade.context.d.ts +11 -0
  48. package/commands/context/upgrade.context.js +1 -0
  49. package/commands/deploy.command.d.ts +5 -0
  50. package/commands/deploy.command.js +22 -0
  51. package/commands/generate.command.d.ts +3 -3
  52. package/commands/generate.command.js +35 -66
  53. package/commands/index.d.ts +3 -2
  54. package/commands/index.js +3 -18
  55. package/commands/info.command.d.ts +3 -3
  56. package/commands/info.command.js +4 -8
  57. package/commands/new.command.d.ts +3 -3
  58. package/commands/new.command.js +34 -36
  59. package/commands/start.command.d.ts +3 -3
  60. package/commands/start.command.js +48 -73
  61. package/commands/upgrade.command.d.ts +5 -0
  62. package/commands/upgrade.command.js +32 -0
  63. package/lib/compiler/assets-manager.d.ts +20 -8
  64. package/lib/compiler/assets-manager.js +199 -63
  65. package/lib/compiler/base-compiler.d.ts +5 -5
  66. package/lib/compiler/base-compiler.js +10 -13
  67. package/lib/compiler/compiler.d.ts +6 -6
  68. package/lib/compiler/compiler.js +7 -9
  69. package/lib/compiler/defaults/rspack-defaults.d.ts +3 -0
  70. package/lib/compiler/defaults/rspack-defaults.js +179 -0
  71. package/lib/compiler/defaults/swc-defaults.d.ts +5 -2
  72. package/lib/compiler/defaults/swc-defaults.js +22 -6
  73. package/lib/compiler/defaults/webpack-defaults.d.ts +2 -2
  74. package/lib/compiler/defaults/webpack-defaults.js +59 -19
  75. package/lib/compiler/helpers/append-extension.js +3 -6
  76. package/lib/compiler/helpers/copy-path-resolve.js +2 -5
  77. package/lib/compiler/helpers/delete-out-dir.d.ts +1 -1
  78. package/lib/compiler/helpers/delete-out-dir.js +45 -10
  79. package/lib/compiler/helpers/get-builder.d.ts +9 -7
  80. package/lib/compiler/helpers/get-builder.js +3 -6
  81. package/lib/compiler/helpers/get-effective-root-dir.d.ts +16 -0
  82. package/lib/compiler/helpers/get-effective-root-dir.js +56 -0
  83. package/lib/compiler/helpers/get-rspack-config-path.d.ts +10 -0
  84. package/lib/compiler/helpers/get-rspack-config-path.js +19 -0
  85. package/lib/compiler/helpers/get-tsc-config.path.d.ts +2 -3
  86. package/lib/compiler/helpers/get-tsc-config.path.js +6 -9
  87. package/lib/compiler/helpers/get-value-or-default.d.ts +2 -3
  88. package/lib/compiler/helpers/get-value-or-default.js +3 -8
  89. package/lib/compiler/helpers/get-webpack-config-path.d.ts +2 -3
  90. package/lib/compiler/helpers/get-webpack-config-path.js +4 -7
  91. package/lib/compiler/helpers/glob.d.ts +19 -0
  92. package/lib/compiler/helpers/glob.js +185 -0
  93. package/lib/compiler/helpers/manual-restart.js +4 -8
  94. package/lib/compiler/helpers/path-confinement.d.ts +33 -0
  95. package/lib/compiler/helpers/path-confinement.js +63 -0
  96. package/lib/compiler/helpers/tsconfig-provider.d.ts +7 -6
  97. package/lib/compiler/helpers/tsconfig-provider.js +32 -13
  98. package/lib/compiler/hooks/tsconfig-paths.hook.js +13 -13
  99. package/lib/compiler/interfaces/readonly-visitor.interface.js +1 -2
  100. package/lib/compiler/plugins/plugin-metadata-generator.d.ts +37 -1
  101. package/lib/compiler/plugins/plugin-metadata-generator.js +113 -13
  102. package/lib/compiler/plugins/plugin-metadata-printer.d.ts +1 -1
  103. package/lib/compiler/plugins/plugin-metadata-printer.js +5 -9
  104. package/lib/compiler/plugins/plugins-loader.d.ts +2 -2
  105. package/lib/compiler/plugins/plugins-loader.js +12 -12
  106. package/lib/compiler/rspack-compiler.d.ts +21 -0
  107. package/lib/compiler/rspack-compiler.js +111 -0
  108. package/lib/compiler/swc/constants.d.ts +0 -1
  109. package/lib/compiler/swc/constants.js +9 -13
  110. package/lib/compiler/swc/forked-type-checker.js +13 -18
  111. package/lib/compiler/swc/swc-compiler.d.ts +13 -6
  112. package/lib/compiler/swc/swc-compiler.js +116 -70
  113. package/lib/compiler/swc/type-checker-host.js +31 -24
  114. package/lib/compiler/typescript-loader.js +7 -9
  115. package/lib/compiler/watch-compiler.d.ts +5 -5
  116. package/lib/compiler/watch-compiler.js +13 -15
  117. package/lib/compiler/watchers/recursive-directory-watcher.d.ts +37 -0
  118. package/lib/compiler/watchers/recursive-directory-watcher.js +334 -0
  119. package/lib/compiler/webpack-compiler.d.ts +6 -7
  120. package/lib/compiler/webpack-compiler.js +46 -23
  121. package/lib/configuration/configuration.d.ts +16 -3
  122. package/lib/configuration/configuration.js +1 -2
  123. package/lib/configuration/configuration.loader.d.ts +1 -1
  124. package/lib/configuration/configuration.loader.js +1 -2
  125. package/lib/configuration/defaults.d.ts +2 -1
  126. package/lib/configuration/defaults.js +8 -10
  127. package/lib/configuration/index.d.ts +3 -3
  128. package/lib/configuration/index.js +3 -19
  129. package/lib/configuration/nest-configuration.loader.d.ts +3 -3
  130. package/lib/configuration/nest-configuration.loader.js +28 -29
  131. package/lib/package-managers/abstract.package-manager.d.ts +4 -4
  132. package/lib/package-managers/abstract.package-manager.js +21 -32
  133. package/lib/package-managers/bun.package-manager.d.ts +7 -0
  134. package/lib/package-managers/bun.package-manager.js +22 -0
  135. package/lib/package-managers/index.d.ts +9 -8
  136. package/lib/package-managers/index.js +9 -24
  137. package/lib/package-managers/npm.package-manager.d.ts +2 -2
  138. package/lib/package-managers/npm.package-manager.js +6 -10
  139. package/lib/package-managers/package-manager-commands.js +1 -2
  140. package/lib/package-managers/package-manager.d.ts +2 -1
  141. package/lib/package-managers/package-manager.factory.d.ts +2 -2
  142. package/lib/package-managers/package-manager.factory.js +23 -20
  143. package/lib/package-managers/package-manager.js +3 -5
  144. package/lib/package-managers/pnpm.package-manager.d.ts +2 -2
  145. package/lib/package-managers/pnpm.package-manager.js +6 -10
  146. package/lib/package-managers/project.dependency.js +1 -2
  147. package/lib/package-managers/yarn.package-manager.d.ts +2 -2
  148. package/lib/package-managers/yarn.package-manager.js +6 -10
  149. package/lib/questions/questions.d.ts +5 -1
  150. package/lib/questions/questions.js +2 -7
  151. package/lib/readers/file-system.reader.d.ts +1 -1
  152. package/lib/readers/file-system.reader.js +6 -9
  153. package/lib/readers/index.d.ts +2 -2
  154. package/lib/readers/index.js +2 -18
  155. package/lib/readers/reader.js +3 -5
  156. package/lib/runners/abstract.runner.js +40 -21
  157. package/lib/runners/bun.runner.d.ts +4 -0
  158. package/lib/runners/bun.runner.js +6 -0
  159. package/lib/runners/git.runner.d.ts +1 -1
  160. package/lib/runners/git.runner.js +2 -6
  161. package/lib/runners/index.d.ts +3 -3
  162. package/lib/runners/index.js +3 -19
  163. package/lib/runners/mau.runner.d.ts +8 -0
  164. package/lib/runners/mau.runner.js +10 -0
  165. package/lib/runners/npm.runner.d.ts +1 -1
  166. package/lib/runners/npm.runner.js +2 -6
  167. package/lib/runners/pnpm.runner.d.ts +1 -1
  168. package/lib/runners/pnpm.runner.js +2 -6
  169. package/lib/runners/runner.d.ts +2 -1
  170. package/lib/runners/runner.factory.d.ts +7 -6
  171. package/lib/runners/runner.factory.js +18 -20
  172. package/lib/runners/runner.js +3 -5
  173. package/lib/runners/schematic.runner.d.ts +1 -1
  174. package/lib/runners/schematic.runner.js +5 -7
  175. package/lib/runners/yarn.runner.d.ts +1 -1
  176. package/lib/runners/yarn.runner.js +2 -6
  177. package/lib/schematics/abstract.collection.d.ts +3 -3
  178. package/lib/schematics/abstract.collection.js +3 -5
  179. package/lib/schematics/collection.factory.d.ts +2 -2
  180. package/lib/schematics/collection.factory.js +9 -13
  181. package/lib/schematics/collection.js +2 -5
  182. package/lib/schematics/custom.collection.d.ts +2 -2
  183. package/lib/schematics/custom.collection.js +4 -8
  184. package/lib/schematics/index.d.ts +4 -4
  185. package/lib/schematics/index.js +4 -20
  186. package/lib/schematics/nest.collection.d.ts +3 -3
  187. package/lib/schematics/nest.collection.js +113 -109
  188. package/lib/schematics/schematic.option.js +10 -9
  189. package/lib/ui/banner.js +1 -4
  190. package/lib/ui/emojis.d.ts +17 -17
  191. package/lib/ui/emojis.js +19 -22
  192. package/lib/ui/errors.js +1 -4
  193. package/lib/ui/index.d.ts +5 -5
  194. package/lib/ui/index.js +5 -21
  195. package/lib/ui/messages.d.ts +8 -0
  196. package/lib/ui/messages.js +23 -18
  197. package/lib/ui/prefixes.js +3 -6
  198. package/lib/utils/extra-args-warning.js +3 -6
  199. package/lib/utils/formatting.js +1 -4
  200. package/lib/utils/get-default-tsconfig-path.js +4 -7
  201. package/lib/utils/gracefully-exit-on-prompt-error.js +1 -4
  202. package/lib/utils/is-esm-project.d.ts +5 -0
  203. package/lib/utils/is-esm-project.js +16 -0
  204. package/lib/utils/is-interactive.d.ts +8 -0
  205. package/lib/utils/is-interactive.js +10 -0
  206. package/lib/utils/is-module-available.js +3 -4
  207. package/lib/utils/load-configuration.d.ts +1 -1
  208. package/lib/utils/load-configuration.js +4 -7
  209. package/lib/utils/local-binaries.d.ts +2 -2
  210. package/lib/utils/local-binaries.js +8 -11
  211. package/lib/utils/mau.d.ts +14 -0
  212. package/lib/utils/mau.js +46 -0
  213. package/lib/utils/os-info.utils.js +1 -4
  214. package/lib/utils/project-utils.d.ts +1 -3
  215. package/lib/utils/project-utils.js +16 -28
  216. package/lib/utils/remaining-flags.d.ts +2 -2
  217. package/lib/utils/remaining-flags.js +13 -8
  218. package/lib/utils/tree-kill.js +7 -10
  219. package/lib/utils/type-assertions.js +1 -4
  220. package/package.json +64 -77
@@ -1,40 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwcCompiler = void 0;
4
- const ansis_1 = require("ansis");
5
- const child_process_1 = require("child_process");
6
- const chokidar = require("chokidar");
7
- const fs_1 = require("fs");
8
- const promises_1 = require("fs/promises");
9
- const path = require("path");
10
- const path_1 = require("path");
11
- const ui_1 = require("../../ui");
12
- const tree_kill_1 = require("../../utils/tree-kill");
13
- const base_compiler_1 = require("../base-compiler");
14
- const swc_defaults_1 = require("../defaults/swc-defaults");
15
- const get_value_or_default_1 = require("../helpers/get-value-or-default");
16
- const plugin_metadata_generator_1 = require("../plugins/plugin-metadata-generator");
17
- const constants_1 = require("./constants");
18
- const type_checker_host_1 = require("./type-checker-host");
19
- class SwcCompiler extends base_compiler_1.BaseCompiler {
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 = (0, swc_defaults_1.swcDefaultsFactory)(extras.tsOptions, configuration);
27
- const swcrcFilePath = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.builder.options.swcrcPath', appName);
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 = (0, child_process_1.fork)((0, path_1.join)(__dirname, 'forked-type-checker.js'), args, {
81
+ const childProcessRef = fork(join(__dirname, 'forked-type-checker.js'), args, {
60
82
  cwd: process.cwd(),
61
83
  });
62
- process.on('exit', () => childProcessRef && (0, tree_kill_1.treeKillSync)(childProcessRef.pid));
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(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA));
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(constants_1.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED));
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
- process.nextTick(() => console.log(constants_1.SWC_LOG_PREFIX, (0, ansis_1.cyan)('Running...')));
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 && !(0, path_1.isAbsolute)(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
- await swcCli.default({
125
- ...swcCliOpts,
126
- cliOptions: {
127
- ...swcCliOpts.cliOptions,
128
- filenames: [file],
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 (err) {
140
- console.error(ui_1.ERROR_PREFIX +
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((0, fs_1.readFileSync)((0, path_1.join)(process.cwd(), swcrcFilePath ?? '.swcrc'), 'utf8'));
190
+ return JSON.parse(readFileSync(join(process.cwd(), swcrcFilePath ?? '.swcrc'), 'utf8'));
148
191
  }
149
- catch (err) {
192
+ catch {
150
193
  if (swcrcFilePath !== undefined) {
151
- console.error(ui_1.ERROR_PREFIX +
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 (source.hasOwnProperty(key)) {
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 (0, promises_1.stat)(srcDir)
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
- const watcher = chokidar.watch(srcDir, {
203
- ignored: (file, stats) => (stats?.isFile() &&
204
- !extensions.some((ext) => file.endsWith(ext))),
205
- ignoreInitial: true,
206
- awaitWriteFinish: {
207
- stabilityThreshold: 50,
208
- pollInterval: 10,
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
- watchFilesInOutDir(options, onChange) {
214
- const dir = (0, path_1.isAbsolute)(options.cliOptions.outDir)
215
- ? options.cliOptions.outDir
216
- : (0, path_1.join)(process.cwd(), options.cliOptions.outDir);
217
- const watcher = chokidar.watch(dir, {
218
- ignored: (file, stats) => (stats?.isFile() &&
219
- !(file.endsWith('.js') || file.endsWith('.mjs'))),
220
- ignoreInitial: true,
221
- awaitWriteFinish: {
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
- watcher.on('ready', () => {
227
- for (const type of ['add', 'change']) {
228
- watcher.on(type, async () => onChange());
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeCheckerHost = void 0;
4
- const ansis_1 = require("ansis");
5
- const ora = require("ora");
6
- const ts = require("typescript");
7
- const tsconfig_provider_1 = require("../helpers/tsconfig-provider");
8
- const typescript_loader_1 = require("../typescript-loader");
9
- const constants_1 = require("./constants");
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: constants_1.INITIALIZING_TYPE_CHECKER,
16
+ text: INITIALIZING_TYPE_CHECKER,
22
17
  });
23
18
  if (options.watch) {
24
19
  console.log();
25
20
  spinner.start();
26
- this.runInWatchMode(tsconfigPath, tsBinary, options);
27
- spinner.succeed();
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
- this.runOnce(tsconfigPath, tsBinary, options);
32
- spinner.succeed();
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 !== constants_1.TSC_NO_ERRORS_MESSAGE) {
45
+ if (diagnostic.messageText !== TSC_NO_ERRORS_MESSAGE) {
39
46
  if (diagnostic.messageText?.includes('Found')) {
40
- console.log(constants_1.TSC_LOG_ERROR_PREFIX, (0, ansis_1.red)(diagnostic.messageText.toString()));
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(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost));
76
- process.exit(1);
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeScriptBinaryLoader = void 0;
4
- const ui_1 = require("../ui");
5
- class TypeScriptBinaryLoader {
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(ui_1.CLI_ERRORS.UNSUPPORTED_TYPESCRIPT_VERSION(tsBinary.version));
26
+ throw new Error(CLI_ERRORS.UNSUPPORTED_TYPESCRIPT_VERSION(tsBinary.version));
28
27
  }
29
28
  }
30
29
  getModulePaths() {
31
- const modulePaths = module.paths.slice(2, module.paths.length);
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WatchCompiler = void 0;
4
- const errors_1 = require("../ui/errors");
5
- const base_compiler_1 = require("./base-compiler");
6
- const get_value_or_default_1 = require("./helpers/get-value-or-default");
7
- const manual_restart_1 = require("./helpers/manual-restart");
8
- const tsconfig_paths_hook_1 = require("./hooks/tsconfig-paths.hook");
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(errors_1.CLI_ERRORS.MISSING_TYPESCRIPT(tsConfigPath));
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 = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.manualRestart', appName);
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
- (0, manual_restart_1.listenForManualRestart)(() => {
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
- (0, manual_restart_1.displayManualRestartTip)();
43
+ displayManualRestartTip();
45
44
  }
46
45
  const tsconfigPathsPlugin = options
47
- ? (0, tsconfig_paths_hook_1.tsconfigPathsBeforeHookFactory)(options)
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>;