@nestjs/cli 10.0.0-next.2 → 10.0.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 (47) hide show
  1. package/.circleci/config.yml +11 -12
  2. package/actions/add.action.js +67 -84
  3. package/actions/build.action.js +44 -59
  4. package/actions/generate.action.js +8 -19
  5. package/actions/info.action.js +31 -50
  6. package/actions/new.action.js +36 -47
  7. package/actions/start.action.js +29 -40
  8. package/bin/nest.js +4 -13
  9. package/commands/add.command.js +3 -12
  10. package/commands/build.command.js +5 -15
  11. package/commands/command.loader.js +8 -19
  12. package/commands/generate.command.js +67 -84
  13. package/commands/info.command.js +3 -12
  14. package/commands/new.command.js +3 -12
  15. package/commands/start.command.js +5 -15
  16. package/lib/compiler/assets-manager.js +3 -3
  17. package/lib/compiler/hooks/tsconfig-paths.hook.js +2 -2
  18. package/lib/compiler/interfaces/readonly-visitor.interface.d.ts +1 -1
  19. package/lib/compiler/plugins/plugin-metadata-generator.d.ts +40 -0
  20. package/lib/compiler/plugins/plugin-metadata-generator.js +40 -4
  21. package/lib/compiler/plugins/plugin-metadata-printer.d.ts +4 -1
  22. package/lib/compiler/plugins/plugin-metadata-printer.js +6 -6
  23. package/lib/compiler/plugins/plugins-loader.js +6 -2
  24. package/lib/compiler/swc/forked-type-checker.js +26 -35
  25. package/lib/compiler/swc/swc-compiler.js +36 -43
  26. package/lib/compiler/swc/type-checker-host.d.ts +2 -1
  27. package/lib/compiler/swc/type-checker-host.js +12 -7
  28. package/lib/compiler/typescript-loader.js +1 -1
  29. package/lib/compiler/watch-compiler.js +4 -1
  30. package/lib/compiler/webpack-compiler.js +12 -5
  31. package/lib/compiler/workspace-utils.js +6 -17
  32. package/lib/configuration/nest-configuration.loader.js +27 -28
  33. package/lib/dependency-managers/nest.dependency-manager.js +21 -34
  34. package/lib/package-managers/abstract.package-manager.js +124 -165
  35. package/lib/package-managers/package-manager.factory.js +15 -26
  36. package/lib/package-managers/package-manager.js +1 -1
  37. package/lib/readers/file-system.reader.js +10 -21
  38. package/lib/runners/abstract.runner.js +19 -30
  39. package/lib/runners/runner.js +1 -1
  40. package/lib/runners/schematic.runner.js +1 -1
  41. package/lib/schematics/abstract.collection.js +4 -15
  42. package/lib/schematics/collection.js +1 -1
  43. package/lib/schematics/custom.collection.js +1 -2
  44. package/lib/schematics/nest.collection.js +3 -17
  45. package/lib/utils/load-configuration.js +3 -14
  46. package/lib/utils/project-utils.js +6 -17
  47. package/package.json +18 -18
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.NewCommand = void 0;
13
4
  const schematics_1 = require("../lib/schematics");
@@ -26,7 +17,7 @@ class NewCommand extends abstract_command_1.AbstractCommand {
26
17
  .option('-l, --language [language]', 'Programming language to be used (TypeScript or JavaScript)', 'TypeScript')
27
18
  .option('-c, --collection [collectionName]', 'Schematics collection to use', schematics_1.Collection.NESTJS)
28
19
  .option('--strict', 'Enables strict mode in TypeScript.', false)
29
- .action((name, command) => __awaiter(this, void 0, void 0, function* () {
20
+ .action(async (name, command) => {
30
21
  const options = [];
31
22
  const availableLanguages = ['js', 'ts', 'javascript', 'typescript'];
32
23
  options.push({ name: 'directory', value: command.directory });
@@ -63,8 +54,8 @@ class NewCommand extends abstract_command_1.AbstractCommand {
63
54
  });
64
55
  const inputs = [];
65
56
  inputs.push({ name: 'name', value: name });
66
- yield this.action.handle(inputs, options);
67
- }));
57
+ await this.action.handle(inputs, options);
58
+ });
68
59
  }
69
60
  }
70
61
  exports.NewCommand = NewCommand;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.StartCommand = void 0;
13
4
  const ui_1 = require("../lib/ui");
@@ -25,15 +16,14 @@ class StartCommand extends abstract_command_1.AbstractCommand {
25
16
  .option('-d, --debug [hostport] ', 'Run in debug mode (with --inspect flag).')
26
17
  .option('--webpack', 'Use webpack for compilation (deprecated option, use --build instead).')
27
18
  .option('--webpackPath [path]', 'Path to webpack configuration.')
28
- .option('--type-check', 'Enable type checking (when SWC is used).', false)
19
+ .option('--type-check', 'Enable type checking (when SWC is used).')
29
20
  .option('--tsc', 'Use tsc for compilation.')
30
21
  .option('--sourceRoot [sourceRoot]', 'Points at the root of the source code for the single project in standard mode structures, or the default project in monorepo mode structures.')
31
22
  .option('--entryFile [entryFile]', "Path to the entry file where this command will work with. Defaults to the one defined at your Nest's CLI config file.")
32
23
  .option('-e, --exec [binary]', 'Binary to run (default: "node").')
33
24
  .option('--preserveWatchOutput', 'Use "preserveWatchOutput" option when tsc watch mode.')
34
25
  .description('Run Nest application.')
35
- .action((app, command) => __awaiter(this, void 0, void 0, function* () {
36
- var _a;
26
+ .action(async (app, command) => {
37
27
  const options = [];
38
28
  options.push({
39
29
  name: 'config',
@@ -78,7 +68,7 @@ class StartCommand extends abstract_command_1.AbstractCommand {
78
68
  }
79
69
  options.push({
80
70
  name: 'builder',
81
- value: (_a = command.builder) !== null && _a !== void 0 ? _a : (isWebpackEnabled ? 'webpack' : 'tsc'),
71
+ value: command.builder,
82
72
  });
83
73
  if (command.typeCheck && command.builder !== 'swc') {
84
74
  console.warn(ui_1.INFO_PREFIX +
@@ -92,12 +82,12 @@ class StartCommand extends abstract_command_1.AbstractCommand {
92
82
  inputs.push({ name: 'app', value: app });
93
83
  const flags = (0, remaining_flags_1.getRemainingFlags)(program);
94
84
  try {
95
- yield this.action.handle(inputs, options, flags);
85
+ await this.action.handle(inputs, options, flags);
96
86
  }
97
87
  catch (err) {
98
88
  process.exit(1);
99
89
  }
100
- }));
90
+ });
101
91
  }
102
92
  }
103
93
  exports.StartCommand = StartCommand;
@@ -67,9 +67,9 @@ class AssetsManager {
67
67
  // prettier-ignore
68
68
  const watcher = chokidar
69
69
  .watch(item.glob, { ignored: item.exclude })
70
- .on('add', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'change' })))
71
- .on('change', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'change' })))
72
- .on('unlink', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'unlink' })));
70
+ .on('add', (path) => this.actionOnFile({ ...option, path, action: 'change' }))
71
+ .on('change', (path) => this.actionOnFile({ ...option, path, action: 'change' }))
72
+ .on('unlink', (path) => this.actionOnFile({ ...option, path, action: 'unlink' }));
73
73
  this.watchers.push(watcher);
74
74
  }
75
75
  }
@@ -37,7 +37,7 @@ function tsconfigPathsBeforeHookFactory(compilerOptions) {
37
37
  return updatedNode;
38
38
  }
39
39
  }
40
- catch (_a) {
40
+ catch {
41
41
  return node;
42
42
  }
43
43
  }
@@ -71,7 +71,7 @@ function getNotAliasedPath(sf, matcher, text) {
71
71
  return text;
72
72
  }
73
73
  }
74
- catch (_a) { }
74
+ catch { }
75
75
  const resolvedPath = path_1.posix.relative((0, path_1.dirname)(sf.fileName), result) || './';
76
76
  return resolvedPath[0] === '.' ? resolvedPath : './' + resolvedPath;
77
77
  }
@@ -5,5 +5,5 @@ export type DeepPluginMeta = ts.ObjectLiteralExpression | {
5
5
  export interface ReadonlyVisitor {
6
6
  key: string;
7
7
  visit(program: ts.Program, sf: ts.SourceFile): void;
8
- collect(): Array<[ts.CallExpression, DeepPluginMeta]>;
8
+ collect(): Record<string, Array<[ts.CallExpression, DeepPluginMeta]>>;
9
9
  }
@@ -1,16 +1,56 @@
1
1
  import * as ts from 'typescript';
2
2
  import { ReadonlyVisitor } from '../interfaces/readonly-visitor.interface';
3
3
  export interface PluginMetadataGenerateOptions {
4
+ /**
5
+ * The visitors to use to generate the metadata.
6
+ */
4
7
  visitors: ReadonlyVisitor[];
8
+ /**
9
+ * The output directory to write the metadata to.
10
+ */
5
11
  outputDir: string;
12
+ /**
13
+ * Whether to watch the project for changes.
14
+ */
6
15
  watch?: boolean;
16
+ /**
17
+ * The path to the tsconfig file.
18
+ * Relative to the current working directory (process.cwd()).
19
+ */
7
20
  tsconfigPath?: string;
21
+ /**
22
+ * The filename to write the metadata to.
23
+ */
8
24
  filename?: string;
25
+ /**
26
+ * A reference to an existing ts.Program instance.
27
+ */
9
28
  tsProgramRef?: ts.Program;
29
+ /**
30
+ * Whether to print diagnostics to the console.
31
+ * @default true
32
+ */
33
+ printDiagnostics?: boolean;
10
34
  }
35
+ /**
36
+ * Generates plugins metadata by traversing the AST of the project.
37
+ * @example
38
+ * ```ts
39
+ * const generator = new PluginMetadataGenerator();
40
+ * generator.generate({
41
+ * visitors: [
42
+ * new ReadonlyVisitor({ introspectComments: true, pathToSource: __dirname }),
43
+ * ],
44
+ * outputDir: __dirname,
45
+ * watch: true,
46
+ * tsconfigPath: 'tsconfig.build.json',
47
+ * });
48
+ * ```
49
+ */
11
50
  export declare class PluginMetadataGenerator {
12
51
  private readonly pluginMetadataPrinter;
13
52
  private readonly typeCheckerHost;
53
+ private readonly typescriptLoader;
14
54
  generate(options: PluginMetadataGenerateOptions): void;
15
55
  private traverseAndPrintMetadata;
16
56
  }
@@ -1,26 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PluginMetadataGenerator = void 0;
4
+ const constants_1 = require("../swc/constants");
4
5
  const type_checker_host_1 = require("../swc/type-checker-host");
6
+ const typescript_loader_1 = require("../typescript-loader");
5
7
  const plugin_metadata_printer_1 = require("./plugin-metadata-printer");
8
+ /**
9
+ * Generates plugins metadata by traversing the AST of the project.
10
+ * @example
11
+ * ```ts
12
+ * const generator = new PluginMetadataGenerator();
13
+ * generator.generate({
14
+ * visitors: [
15
+ * new ReadonlyVisitor({ introspectComments: true, pathToSource: __dirname }),
16
+ * ],
17
+ * outputDir: __dirname,
18
+ * watch: true,
19
+ * tsconfigPath: 'tsconfig.build.json',
20
+ * });
21
+ * ```
22
+ */
6
23
  class PluginMetadataGenerator {
7
24
  constructor() {
8
25
  this.pluginMetadataPrinter = new plugin_metadata_printer_1.PluginMetadataPrinter();
9
26
  this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
27
+ this.typescriptLoader = new typescript_loader_1.TypeScriptBinaryLoader();
10
28
  }
11
29
  generate(options) {
12
- const { tsconfigPath, visitors, tsProgramRef, outputDir, watch, filename } = options;
30
+ const { tsconfigPath, visitors, tsProgramRef, outputDir, watch, filename, printDiagnostics = true, } = options;
13
31
  if (visitors.length === 0) {
14
32
  return;
15
33
  }
16
34
  if (tsProgramRef) {
17
35
  return this.traverseAndPrintMetadata(tsProgramRef, visitors, outputDir, filename);
18
36
  }
37
+ const onTypeCheckOrProgramInit = (program) => {
38
+ this.traverseAndPrintMetadata(program, visitors, outputDir, filename);
39
+ if (printDiagnostics) {
40
+ const tsBinary = this.typescriptLoader.load();
41
+ const diagnostics = tsBinary.getPreEmitDiagnostics(program);
42
+ if (diagnostics.length > 0) {
43
+ const formatDiagnosticsHost = {
44
+ getCanonicalFileName: (path) => path,
45
+ getCurrentDirectory: tsBinary.sys.getCurrentDirectory,
46
+ getNewLine: () => tsBinary.sys.newLine,
47
+ };
48
+ console.log();
49
+ console.log(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost));
50
+ }
51
+ else {
52
+ console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA);
53
+ }
54
+ }
55
+ };
19
56
  this.typeCheckerHost.run(tsconfigPath, {
20
57
  watch,
21
- onSuccess: (program) => {
22
- this.traverseAndPrintMetadata(program, visitors, outputDir, filename);
23
- },
58
+ onTypeCheck: onTypeCheckOrProgramInit,
59
+ onProgramInit: onTypeCheckOrProgramInit,
24
60
  });
25
61
  }
26
62
  traverseAndPrintMetadata(programRef, visitors, outputDir, filename) {
@@ -4,7 +4,10 @@ export interface PluginMetadataPrintOptions {
4
4
  outputDir: string;
5
5
  filename?: string;
6
6
  }
7
+ /**
8
+ * Prints the metadata to a file.
9
+ */
7
10
  export declare class PluginMetadataPrinter {
8
- print(metadata: Record<string, Array<[ts.CallExpression, DeepPluginMeta]>>, options: PluginMetadataPrintOptions): void;
11
+ print(metadata: Record<string, Record<string, Array<[ts.CallExpression, DeepPluginMeta]>>>, options: PluginMetadataPrintOptions): void;
9
12
  private recursivelyCreatePropertyAssignment;
10
13
  }
@@ -5,22 +5,22 @@ const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const ts = require("typescript");
7
7
  const SERIALIZED_METADATA_FILENAME = 'metadata.ts';
8
+ /**
9
+ * Prints the metadata to a file.
10
+ */
8
11
  class PluginMetadataPrinter {
9
12
  print(metadata, options) {
10
- var _a;
11
13
  const objectLiteralExpr = ts.factory.createObjectLiteralExpression(Object.keys(metadata).map((key) => this.recursivelyCreatePropertyAssignment(key, metadata[key])));
12
- const metadataCacheVariableStatement = ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
13
- ts.factory.createVariableDeclaration(ts.factory.createIdentifier('metadataCache'), undefined, undefined, objectLiteralExpr),
14
- ], ts.NodeFlags.Const));
14
+ const exportAssignment = ts.factory.createExportAssignment(undefined, undefined, objectLiteralExpr);
15
15
  const printer = ts.createPrinter({
16
16
  newLine: ts.NewLineKind.LineFeed,
17
17
  });
18
18
  const resultFile = ts.createSourceFile('file.ts', '', ts.ScriptTarget.Latest,
19
19
  /*setParentNodes*/ false, ts.ScriptKind.TS);
20
- const filename = (0, path_1.join)(options.outputDir, (_a = options.filename) !== null && _a !== void 0 ? _a : SERIALIZED_METADATA_FILENAME);
20
+ const filename = (0, path_1.join)(options.outputDir, options.filename ?? SERIALIZED_METADATA_FILENAME);
21
21
  const eslintPrefix = `/* eslint-disable */\n`;
22
22
  (0, fs_1.writeFileSync)(filename, eslintPrefix +
23
- printer.printNode(ts.EmitHint.Unspecified, metadataCacheVariableStatement, resultFile));
23
+ printer.printNode(ts.EmitHint.Unspecified, exportAssignment, resultFile));
24
24
  }
25
25
  recursivelyCreatePropertyAssignment(identifier, meta) {
26
26
  if (Array.isArray(meta)) {
@@ -33,7 +33,11 @@ class PluginsLoader {
33
33
  multiCompilerPlugins.afterDeclarationsHooks.push(plugin.afterDeclarations.bind(plugin.afterDeclarations, options));
34
34
  }
35
35
  if (plugin.ReadonlyVisitor) {
36
- const instance = new plugin.ReadonlyVisitor(Object.assign(Object.assign(Object.assign({}, options), extras), { readonly: true }));
36
+ const instance = new plugin.ReadonlyVisitor({
37
+ ...options,
38
+ ...extras,
39
+ readonly: true,
40
+ });
37
41
  instance.key = pluginNames[index];
38
42
  multiCompilerPlugins.readonlyVisitors.push(instance);
39
43
  }
@@ -53,7 +57,7 @@ class PluginsLoader {
53
57
  });
54
58
  return require(binaryPath);
55
59
  }
56
- catch (_a) { }
60
+ catch { }
57
61
  const binaryPath = require.resolve(item, { paths: nodeModulePaths });
58
62
  return require(binaryPath);
59
63
  }
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const ui_1 = require("../../ui");
13
4
  const base_compiler_1 = require("../base-compiler");
@@ -22,32 +13,32 @@ class ForkedTypeChecker extends base_compiler_1.BaseCompiler {
22
13
  this.pluginMetadataGenerator = new plugin_metadata_generator_1.PluginMetadataGenerator();
23
14
  this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
24
15
  }
25
- run(configuration, tsConfigPath, appName, extras) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const { readonlyVisitors } = this.loadPlugins(configuration, tsConfigPath, appName);
28
- const outputDir = this.getPathToSource(configuration, tsConfigPath, appName);
29
- try {
30
- this.typeCheckerHost.run(tsConfigPath, {
31
- watch: extras.watch,
32
- onSuccess: (program) => {
33
- if (readonlyVisitors.length > 0) {
34
- console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA);
35
- this.pluginMetadataGenerator.generate({
36
- outputDir,
37
- visitors: readonlyVisitors,
38
- tsProgramRef: program,
39
- });
40
- }
41
- else {
42
- console.log(constants_1.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED);
43
- }
44
- },
45
- });
46
- }
47
- catch (err) {
48
- console.log(ui_1.ERROR_PREFIX, err.message);
49
- }
50
- });
16
+ async run(configuration, tsConfigPath, appName, extras) {
17
+ const { readonlyVisitors } = this.loadPlugins(configuration, tsConfigPath, appName);
18
+ const outputDir = this.getPathToSource(configuration, tsConfigPath, appName);
19
+ try {
20
+ const onTypeCheckOrProgramInit = (program) => {
21
+ if (readonlyVisitors.length > 0) {
22
+ console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA);
23
+ this.pluginMetadataGenerator.generate({
24
+ outputDir,
25
+ visitors: readonlyVisitors,
26
+ tsProgramRef: program,
27
+ });
28
+ }
29
+ else {
30
+ console.log(constants_1.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED);
31
+ }
32
+ };
33
+ this.typeCheckerHost.run(tsConfigPath, {
34
+ watch: extras.watch,
35
+ onTypeCheck: onTypeCheckOrProgramInit,
36
+ onProgramInit: onTypeCheckOrProgramInit,
37
+ });
38
+ }
39
+ catch (err) {
40
+ console.log(ui_1.ERROR_PREFIX, err.message);
41
+ }
51
42
  }
52
43
  }
53
44
  const pluginsLoader = new plugins_loader_1.PluginsLoader();
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.SwcCompiler = void 0;
13
4
  const chalk = require("chalk");
@@ -27,38 +18,35 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
27
18
  this.pluginMetadataGenerator = new plugin_metadata_generator_1.PluginMetadataGenerator();
28
19
  this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
29
20
  }
30
- run(configuration, tsConfigPath, appName, extras, onSuccess) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const swcOptions = (0, swc_defaults_1.swcDefaultsFactory)();
33
- if (extras.watch) {
34
- if (extras.typeCheck) {
35
- this.runTypeChecker(configuration, tsConfigPath, appName, extras);
36
- }
37
- yield this.runSwc(swcOptions, extras);
38
- if (onSuccess) {
39
- onSuccess();
40
- const debounceTime = 150;
41
- const callback = this.debounce(onSuccess, debounceTime);
42
- this.watchFilesInOutDir(swcOptions, callback);
43
- }
21
+ async run(configuration, tsConfigPath, appName, extras, onSuccess) {
22
+ const swcOptions = (0, swc_defaults_1.swcDefaultsFactory)();
23
+ if (extras.watch) {
24
+ if (extras.typeCheck) {
25
+ this.runTypeChecker(configuration, tsConfigPath, appName, extras);
44
26
  }
45
- else {
46
- if (extras.typeCheck) {
47
- yield this.runTypeChecker(configuration, tsConfigPath, appName, extras);
48
- }
49
- yield this.runSwc(swcOptions, extras);
50
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
27
+ await this.runSwc(swcOptions, extras);
28
+ if (onSuccess) {
29
+ onSuccess();
30
+ const debounceTime = 150;
31
+ const callback = this.debounce(onSuccess, debounceTime);
32
+ this.watchFilesInOutDir(swcOptions, callback);
51
33
  }
52
- });
34
+ }
35
+ else {
36
+ if (extras.typeCheck) {
37
+ await this.runTypeChecker(configuration, tsConfigPath, appName, extras);
38
+ }
39
+ await this.runSwc(swcOptions, extras);
40
+ onSuccess?.();
41
+ }
53
42
  }
54
43
  runTypeChecker(configuration, tsConfigPath, appName, extras) {
55
- var _a, _b;
56
44
  if (extras.watch) {
57
45
  const args = [
58
46
  tsConfigPath,
59
47
  appName,
60
- (_a = configuration.sourceRoot) !== null && _a !== void 0 ? _a : 'src',
61
- JSON.stringify((_b = configuration.compilerOptions.plugins) !== null && _b !== void 0 ? _b : []),
48
+ configuration.sourceRoot ?? 'src',
49
+ JSON.stringify(configuration.compilerOptions.plugins ?? []),
62
50
  ];
63
51
  (0, child_process_1.fork)((0, path_1.join)(__dirname, 'forked-type-checker.js'), args, {
64
52
  cwd: process.cwd(),
@@ -72,7 +60,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
72
60
  try {
73
61
  this.typeCheckerHost.run(tsConfigPath, {
74
62
  watch: extras.watch,
75
- onSuccess: (program) => {
63
+ onTypeCheck: (program) => {
76
64
  if (!fulfilled) {
77
65
  fulfilled = true;
78
66
  resolve();
@@ -100,13 +88,18 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
100
88
  });
101
89
  }
102
90
  }
103
- runSwc(options, extras) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- process.nextTick(() => console.log(constants_1.SWC_LOG_PREFIX, chalk.cyan('Running...')));
106
- const swcCli = this.loadSwcCliBinary();
107
- const swcRcFile = yield this.getSwcRcFileContentIfExists();
108
- const swcOptions = this.deepMerge(options.swcOptions, swcRcFile);
109
- yield swcCli.default(Object.assign(Object.assign({}, options), { swcOptions, cliOptions: Object.assign(Object.assign({}, options.cliOptions), { watch: extras.watch }) }));
91
+ async runSwc(options, extras) {
92
+ process.nextTick(() => console.log(constants_1.SWC_LOG_PREFIX, chalk.cyan('Running...')));
93
+ const swcCli = this.loadSwcCliBinary();
94
+ const swcRcFile = await this.getSwcRcFileContentIfExists();
95
+ const swcOptions = this.deepMerge(options.swcOptions, swcRcFile);
96
+ await swcCli.default({
97
+ ...options,
98
+ swcOptions,
99
+ cliOptions: {
100
+ ...options.cliOptions,
101
+ watch: extras.watch,
102
+ },
110
103
  });
111
104
  }
112
105
  loadSwcCliBinary() {
@@ -134,7 +127,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
134
127
  source === null) {
135
128
  return source;
136
129
  }
137
- const merged = Object.assign({}, target);
130
+ const merged = { ...target };
138
131
  for (const key in source) {
139
132
  if (source.hasOwnProperty(key)) {
140
133
  if (key in target) {
@@ -164,7 +157,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
164
157
  },
165
158
  });
166
159
  for (const type of ['add', 'change']) {
167
- watcher.on(type, () => __awaiter(this, void 0, void 0, function* () { return onChange(); }));
160
+ watcher.on(type, async () => onChange());
168
161
  }
169
162
  }
170
163
  }
@@ -1,7 +1,8 @@
1
1
  import * as ts from 'typescript';
2
2
  export interface TypeCheckerHostRunOptions {
3
3
  watch?: boolean;
4
- onSuccess?: (program: ts.Program) => void;
4
+ onTypeCheck?: (program: ts.Program) => void;
5
+ onProgramInit?: (program: ts.Program) => void;
5
6
  }
6
7
  export declare class TypeCheckerHost {
7
8
  private readonly typescriptLoader;
@@ -35,9 +35,8 @@ class TypeCheckerHost {
35
35
  const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(tsconfigPath);
36
36
  let builderProgram = undefined;
37
37
  const reportWatchStatusCallback = (diagnostic) => {
38
- var _a, _b;
39
38
  if (diagnostic.messageText !== constants_1.TSC_NO_ERRORS_MESSAGE) {
40
- if ((_a = diagnostic.messageText) === null || _a === void 0 ? void 0 : _a.includes('Found')) {
39
+ if (diagnostic.messageText?.includes('Found')) {
41
40
  console.log(constants_1.TSC_LOG_ERROR_PREFIX, chalk.red(diagnostic.messageText));
42
41
  }
43
42
  return;
@@ -46,15 +45,17 @@ class TypeCheckerHost {
46
45
  return;
47
46
  }
48
47
  const tsProgram = builderProgram.getProgram().getProgram();
49
- (_b = options.onSuccess) === null || _b === void 0 ? void 0 : _b.call(options, tsProgram);
48
+ options.onTypeCheck?.(tsProgram);
50
49
  };
51
50
  const host = this.createWatchCompilerHost(tsBinary, tsconfigPath, tsOptions, reportWatchStatusCallback);
52
51
  builderProgram = tsBinary.createWatchProgram(host);
52
+ process.nextTick(() => {
53
+ options.onProgramInit?.(builderProgram.getProgram().getProgram());
54
+ });
53
55
  }
54
56
  runOnce(tsconfigPath, tsBinary, options) {
55
- var _a, _b;
56
57
  const { options: tsOptions, fileNames, projectReferences, } = this.tsConfigProvider.getByConfigFilename(tsconfigPath);
57
- const createProgram = (_a = tsBinary.createIncrementalProgram) !== null && _a !== void 0 ? _a : tsBinary.createProgram;
58
+ const createProgram = tsBinary.createIncrementalProgram ?? tsBinary.createProgram;
58
59
  const program = createProgram.call(ts, {
59
60
  rootNames: fileNames,
60
61
  projectReferences,
@@ -74,11 +75,15 @@ class TypeCheckerHost {
74
75
  console.log(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost));
75
76
  process.exit(1);
76
77
  }
77
- (_b = options.onSuccess) === null || _b === void 0 ? void 0 : _b.call(options, programRef);
78
+ options.onTypeCheck?.(programRef);
78
79
  }
79
80
  createWatchCompilerHost(tsBinary, tsConfigPath, options, reportWatchStatusCallback) {
80
81
  const origDiagnosticReporter = tsBinary.createDiagnosticReporter(tsBinary.sys, true);
81
- const tsOptions = Object.assign(Object.assign({}, options), { preserveWatchOutput: true, noEmit: true });
82
+ const tsOptions = {
83
+ ...options,
84
+ preserveWatchOutput: true,
85
+ noEmit: true,
86
+ };
82
87
  return tsBinary.createWatchCompilerHost(tsConfigPath, tsOptions, tsBinary.sys, undefined, origDiagnosticReporter, reportWatchStatusCallback);
83
88
  }
84
89
  }
@@ -15,7 +15,7 @@ class TypeScriptBinaryLoader {
15
15
  this.tsBinary = tsBinary;
16
16
  return tsBinary;
17
17
  }
18
- catch (_a) {
18
+ catch {
19
19
  throw new Error('TypeScript could not be found! Please, install "typescript" package.');
20
20
  }
21
21
  }
@@ -22,7 +22,10 @@ class WatchCompiler extends base_compiler_1.BaseCompiler {
22
22
  const createProgram = tsBin.createEmitAndSemanticDiagnosticsBuilderProgram;
23
23
  const origDiagnosticReporter = tsBin.createDiagnosticReporter(tsBin.sys, true);
24
24
  const origWatchStatusReporter = tsBin.createWatchStatusReporter(tsBin.sys, true);
25
- const host = tsBin.createWatchCompilerHost(configPath, Object.assign(Object.assign({}, options), { preserveWatchOutput: extras.preserveWatchOutput }), tsBin.sys, createProgram, this.createDiagnosticReporter(origDiagnosticReporter), this.createWatchStatusChanged(origWatchStatusReporter, onSuccess));
25
+ const host = tsBin.createWatchCompilerHost(configPath, {
26
+ ...options,
27
+ preserveWatchOutput: extras.preserveWatchOutput,
28
+ }, tsBin.sys, createProgram, this.createDiagnosticReporter(origDiagnosticReporter), this.createWatchStatusChanged(origWatchStatusReporter, onSuccess));
26
29
  const manualRestart = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.manualRestart', appName);
27
30
  const plugins = this.loadPlugins(configuration, tsConfigPath, appName);
28
31
  this.overrideCreateProgramFn(host, manualRestart, projectReferences, plugins);