@nestjs/cli 9.4.2 → 10.0.0-next.1

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 (44) hide show
  1. package/.circleci/config.yml +2 -2
  2. package/actions/build.action.d.ts +4 -7
  3. package/actions/build.action.js +43 -21
  4. package/actions/new.action.js +1 -2
  5. package/commands/build.command.js +23 -1
  6. package/commands/start.command.js +23 -1
  7. package/lib/compiler/base-compiler.d.ts +9 -0
  8. package/lib/compiler/base-compiler.js +26 -0
  9. package/lib/compiler/compiler.d.ts +4 -4
  10. package/lib/compiler/compiler.js +6 -7
  11. package/lib/compiler/defaults/swc-defaults.d.ts +31 -0
  12. package/lib/compiler/defaults/swc-defaults.js +47 -0
  13. package/lib/compiler/defaults/webpack-defaults.d.ts +1 -1
  14. package/lib/compiler/helpers/get-value-or-default.d.ts +1 -1
  15. package/lib/compiler/helpers/is-compilable-extension.d.ts +1 -0
  16. package/lib/compiler/helpers/is-compilable-extension.js +9 -0
  17. package/lib/compiler/hooks/tsconfig-paths.hook.js +2 -9
  18. package/lib/compiler/interfaces/readonly-visitor.interface.d.ts +9 -0
  19. package/lib/compiler/interfaces/readonly-visitor.interface.js +2 -0
  20. package/lib/compiler/plugins/plugin-metadata-generator.d.ts +15 -0
  21. package/lib/compiler/plugins/plugin-metadata-generator.js +39 -0
  22. package/lib/compiler/plugins/plugin-metadata-printer.d.ts +5 -0
  23. package/lib/compiler/plugins/plugin-metadata-printer.js +30 -0
  24. package/lib/compiler/plugins/plugins-loader.d.ts +30 -0
  25. package/lib/compiler/plugins/plugins-loader.js +66 -0
  26. package/lib/compiler/swc/constants.d.ts +9 -0
  27. package/lib/compiler/swc/constants.js +14 -0
  28. package/lib/compiler/swc/forked-type-checker.d.ts +1 -0
  29. package/lib/compiler/swc/forked-type-checker.js +72 -0
  30. package/lib/compiler/swc/swc-compiler.d.ts +20 -0
  31. package/lib/compiler/swc/swc-compiler.js +171 -0
  32. package/lib/compiler/swc/type-checker-host.d.ts +13 -0
  33. package/lib/compiler/swc/type-checker-host.js +85 -0
  34. package/lib/compiler/watch-compiler.d.ts +9 -5
  35. package/lib/compiler/watch-compiler.js +23 -15
  36. package/lib/compiler/webpack-compiler.d.ts +13 -5
  37. package/lib/compiler/webpack-compiler.js +30 -30
  38. package/lib/configuration/configuration.d.ts +1 -0
  39. package/lib/configuration/defaults.js +1 -0
  40. package/lib/package-managers/package-manager.factory.js +17 -19
  41. package/lib/readers/file-system.reader.js +3 -24
  42. package/package.json +22 -13
  43. package/lib/compiler/plugins-loader.d.ts +0 -21
  44. package/lib/compiler/plugins-loader.js +0 -54
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginsLoader = void 0;
4
+ const path_1 = require("path");
5
+ const ui_1 = require("../../ui");
6
+ const PLUGIN_ENTRY_FILENAME = 'plugin';
7
+ class PluginsLoader {
8
+ load(plugins = [], extras = {}) {
9
+ const pluginNames = plugins.map((entry) => typeof entry === 'object'
10
+ ? entry.name
11
+ : entry);
12
+ const pluginRefs = this.resolvePluginReferences(pluginNames);
13
+ const multiCompilerPlugins = {
14
+ afterHooks: [],
15
+ afterDeclarationsHooks: [],
16
+ beforeHooks: [],
17
+ readonlyVisitors: [],
18
+ };
19
+ pluginRefs.forEach((plugin, index) => {
20
+ if (!plugin.before && !plugin.after && !plugin.afterDeclarations) {
21
+ throw new Error(ui_1.CLI_ERRORS.WRONG_PLUGIN(pluginNames[index]));
22
+ }
23
+ const options = typeof plugins[index] === 'object'
24
+ ? plugins[index].options || {}
25
+ : {};
26
+ if (plugin.before) {
27
+ multiCompilerPlugins.beforeHooks.push(plugin.before.bind(plugin.before, options));
28
+ }
29
+ if (plugin.after) {
30
+ multiCompilerPlugins.afterHooks.push(plugin.after.bind(plugin.after, options));
31
+ }
32
+ if (plugin.afterDeclarations) {
33
+ multiCompilerPlugins.afterDeclarationsHooks.push(plugin.afterDeclarations.bind(plugin.afterDeclarations, options));
34
+ }
35
+ if (plugin.ReadonlyVisitor) {
36
+ const instance = new plugin.ReadonlyVisitor(Object.assign(Object.assign(Object.assign({}, options), extras), { readonly: true }));
37
+ instance.key = pluginNames[index];
38
+ multiCompilerPlugins.readonlyVisitors.push(instance);
39
+ }
40
+ });
41
+ return multiCompilerPlugins;
42
+ }
43
+ resolvePluginReferences(pluginNames) {
44
+ const nodeModulePaths = [
45
+ (0, path_1.join)(process.cwd(), 'node_modules'),
46
+ ...module.paths,
47
+ ];
48
+ return pluginNames.map((item) => {
49
+ try {
50
+ try {
51
+ const binaryPath = require.resolve((0, path_1.join)(item, PLUGIN_ENTRY_FILENAME), {
52
+ paths: nodeModulePaths,
53
+ });
54
+ return require(binaryPath);
55
+ }
56
+ catch (_a) { }
57
+ const binaryPath = require.resolve(item, { paths: nodeModulePaths });
58
+ return require(binaryPath);
59
+ }
60
+ catch (e) {
61
+ throw new Error(`"${item}" plugin is not installed.`);
62
+ }
63
+ });
64
+ }
65
+ }
66
+ exports.PluginsLoader = PluginsLoader;
@@ -0,0 +1,9 @@
1
+ export declare const TSC_NO_ERRORS_MESSAGE = "Found 0 errors. Watching for file changes.";
2
+ export declare const TSC_COMPILATION_STARTED_MESSAGE = "Starting compilation in watch mode...";
3
+ export declare const SWC_LOG_PREFIX: string;
4
+ export declare const TSC_LOG_PREFIX: string;
5
+ export declare const TSC_LOG_ERROR_PREFIX: string;
6
+ export declare const TSC_LOG_SUCCESS_PREFIX: string;
7
+ export declare const INITIALIZING_TYPE_CHECKER: string;
8
+ export declare const FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED: string;
9
+ export declare const FOUND_NO_ISSUES_GENERATING_METADATA: string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FOUND_NO_ISSUES_GENERATING_METADATA = exports.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED = exports.INITIALIZING_TYPE_CHECKER = exports.TSC_LOG_SUCCESS_PREFIX = exports.TSC_LOG_ERROR_PREFIX = exports.TSC_LOG_PREFIX = exports.SWC_LOG_PREFIX = exports.TSC_COMPILATION_STARTED_MESSAGE = exports.TSC_NO_ERRORS_MESSAGE = void 0;
4
+ const chalk = require("chalk");
5
+ exports.TSC_NO_ERRORS_MESSAGE = 'Found 0 errors. Watching for file changes.';
6
+ exports.TSC_COMPILATION_STARTED_MESSAGE = 'Starting compilation in watch mode...';
7
+ exports.SWC_LOG_PREFIX = chalk.cyan('> ') + chalk.bgCyan.bold(' SWC ');
8
+ exports.TSC_LOG_PREFIX = chalk.cyan('> ') + chalk.bgCyan.bold(' TSC ');
9
+ exports.TSC_LOG_ERROR_PREFIX = chalk.red('> ') + chalk.bgRed.bold(' TSC ');
10
+ exports.TSC_LOG_SUCCESS_PREFIX = chalk.green('> ') + chalk.bgGreen.bold(' TSC ');
11
+ exports.INITIALIZING_TYPE_CHECKER = chalk.bgCyan.bold(' TSC ') + chalk.cyan(' Initializing type checker...');
12
+ exports.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED = exports.TSC_LOG_SUCCESS_PREFIX + chalk.green(' Found 0 issues.');
13
+ exports.FOUND_NO_ISSUES_GENERATING_METADATA = exports.TSC_LOG_SUCCESS_PREFIX +
14
+ chalk.green(' Found 0 issues. Generating metadata...');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,72 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const ui_1 = require("../../ui");
13
+ const base_compiler_1 = require("../base-compiler");
14
+ const plugin_metadata_generator_1 = require("../plugins/plugin-metadata-generator");
15
+ const plugins_loader_1 = require("../plugins/plugins-loader");
16
+ const constants_1 = require("./constants");
17
+ const type_checker_host_1 = require("./type-checker-host");
18
+ const [tsConfigPath, appName, sourceRoot, plugins] = process.argv.slice(2);
19
+ class ForkedTypeChecker extends base_compiler_1.BaseCompiler {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.pluginMetadataGenerator = new plugin_metadata_generator_1.PluginMetadataGenerator();
23
+ this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
24
+ }
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
+ });
51
+ }
52
+ }
53
+ const pluginsLoader = new plugins_loader_1.PluginsLoader();
54
+ const forkedTypeChecker = new ForkedTypeChecker(pluginsLoader);
55
+ const applicationName = appName === 'undefined' ? '' : appName;
56
+ const options = {
57
+ sourceRoot,
58
+ };
59
+ if (applicationName) {
60
+ options.projects = {};
61
+ options.projects[applicationName] = {
62
+ compilerOptions: {
63
+ plugins: JSON.parse(plugins),
64
+ },
65
+ };
66
+ }
67
+ else {
68
+ options.compilerOptions = {
69
+ plugins: JSON.parse(plugins),
70
+ };
71
+ }
72
+ forkedTypeChecker.run(options, tsConfigPath, applicationName, { watch: true, typeCheck: true });
@@ -0,0 +1,20 @@
1
+ import { Configuration } from '../../configuration';
2
+ import { BaseCompiler } from '../base-compiler';
3
+ import { PluginsLoader } from '../plugins/plugins-loader';
4
+ export type SwcCompilerExtras = {
5
+ watch: boolean;
6
+ typeCheck: boolean;
7
+ };
8
+ export declare class SwcCompiler extends BaseCompiler {
9
+ private readonly pluginMetadataGenerator;
10
+ private readonly typeCheckerHost;
11
+ constructor(pluginsLoader: PluginsLoader);
12
+ run(configuration: Required<Configuration>, tsConfigPath: string, appName: string, extras: SwcCompilerExtras, onSuccess?: () => void): Promise<void>;
13
+ private runTypeChecker;
14
+ private runSwc;
15
+ private loadSwcCliBinary;
16
+ private getSwcRcFileContentIfExists;
17
+ private deepMerge;
18
+ private debounce;
19
+ private watchFilesInOutDir;
20
+ }
@@ -0,0 +1,171 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SwcCompiler = void 0;
13
+ const chalk = require("chalk");
14
+ const child_process_1 = require("child_process");
15
+ const chokidar = require("chokidar");
16
+ const fs_1 = require("fs");
17
+ const path_1 = require("path");
18
+ const ui_1 = require("../../ui");
19
+ const base_compiler_1 = require("../base-compiler");
20
+ const swc_defaults_1 = require("../defaults/swc-defaults");
21
+ const plugin_metadata_generator_1 = require("../plugins/plugin-metadata-generator");
22
+ const constants_1 = require("./constants");
23
+ const type_checker_host_1 = require("./type-checker-host");
24
+ class SwcCompiler extends base_compiler_1.BaseCompiler {
25
+ constructor(pluginsLoader) {
26
+ super(pluginsLoader);
27
+ this.pluginMetadataGenerator = new plugin_metadata_generator_1.PluginMetadataGenerator();
28
+ this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
29
+ }
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
+ }
44
+ }
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();
51
+ }
52
+ });
53
+ }
54
+ runTypeChecker(configuration, tsConfigPath, appName, extras) {
55
+ var _a, _b;
56
+ if (extras.watch) {
57
+ const args = [
58
+ tsConfigPath,
59
+ appName,
60
+ (_a = configuration.sourceRoot) !== null && _a !== void 0 ? _a : 'src',
61
+ JSON.stringify((_b = configuration.compilerOptions.plugins) !== null && _b !== void 0 ? _b : []),
62
+ ];
63
+ (0, child_process_1.fork)((0, path_1.join)(__dirname, 'forked-type-checker.js'), args, {
64
+ cwd: process.cwd(),
65
+ });
66
+ }
67
+ else {
68
+ const { readonlyVisitors } = this.loadPlugins(configuration, tsConfigPath, appName);
69
+ const outputDir = this.getPathToSource(configuration, tsConfigPath, appName);
70
+ let fulfilled = false;
71
+ return new Promise((resolve, reject) => {
72
+ try {
73
+ this.typeCheckerHost.run(tsConfigPath, {
74
+ watch: extras.watch,
75
+ onSuccess: (program) => {
76
+ if (!fulfilled) {
77
+ fulfilled = true;
78
+ resolve();
79
+ }
80
+ if (readonlyVisitors.length > 0) {
81
+ process.nextTick(() => console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA));
82
+ this.pluginMetadataGenerator.generate({
83
+ outputDir,
84
+ visitors: readonlyVisitors,
85
+ tsProgramRef: program,
86
+ });
87
+ }
88
+ else {
89
+ process.nextTick(() => console.log(constants_1.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED));
90
+ }
91
+ },
92
+ });
93
+ }
94
+ catch (err) {
95
+ if (!fulfilled) {
96
+ fulfilled = true;
97
+ reject(err);
98
+ }
99
+ }
100
+ });
101
+ }
102
+ }
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 }) }));
110
+ });
111
+ }
112
+ loadSwcCliBinary() {
113
+ try {
114
+ return require('@swc/cli/lib/swc/dir');
115
+ }
116
+ catch (err) {
117
+ console.error(ui_1.ERROR_PREFIX +
118
+ ' Failed to load "@swc/cli" package. Please, install it by running "npm i -D @swc/cli"');
119
+ throw err;
120
+ }
121
+ }
122
+ getSwcRcFileContentIfExists() {
123
+ try {
124
+ return JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(process.cwd(), '.swcrc'), 'utf8'));
125
+ }
126
+ catch (err) {
127
+ return {};
128
+ }
129
+ }
130
+ deepMerge(target, source) {
131
+ if (typeof target !== 'object' ||
132
+ target === null ||
133
+ typeof source !== 'object' ||
134
+ source === null) {
135
+ return source;
136
+ }
137
+ const merged = Object.assign({}, target);
138
+ for (const key in source) {
139
+ if (source.hasOwnProperty(key)) {
140
+ if (key in target) {
141
+ merged[key] = this.deepMerge(target[key], source[key]);
142
+ }
143
+ else {
144
+ merged[key] = source[key];
145
+ }
146
+ }
147
+ }
148
+ return merged;
149
+ }
150
+ debounce(callback, wait) {
151
+ let timeout;
152
+ return () => {
153
+ clearTimeout(timeout);
154
+ timeout = setTimeout(callback, wait);
155
+ };
156
+ }
157
+ watchFilesInOutDir(options, onChange) {
158
+ const outDir = (0, path_1.join)(process.cwd(), options.cliOptions.outDir, '**/*.js');
159
+ const watcher = chokidar.watch(outDir, {
160
+ ignoreInitial: true,
161
+ awaitWriteFinish: {
162
+ stabilityThreshold: 50,
163
+ pollInterval: 10,
164
+ },
165
+ });
166
+ for (const type of ['add', 'change']) {
167
+ watcher.on(type, () => __awaiter(this, void 0, void 0, function* () { return onChange(); }));
168
+ }
169
+ }
170
+ }
171
+ exports.SwcCompiler = SwcCompiler;
@@ -0,0 +1,13 @@
1
+ import * as ts from 'typescript';
2
+ export interface TypeCheckerHostRunOptions {
3
+ watch?: boolean;
4
+ onSuccess?: (program: ts.Program) => void;
5
+ }
6
+ export declare class TypeCheckerHost {
7
+ private readonly typescriptLoader;
8
+ private readonly tsConfigProvider;
9
+ run(tsconfigPath: string | undefined, options: TypeCheckerHostRunOptions): void;
10
+ private runInWatchMode;
11
+ private runOnce;
12
+ private createWatchCompilerHost;
13
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeCheckerHost = void 0;
4
+ const chalk = require("chalk");
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
+ }
15
+ run(tsconfigPath, options) {
16
+ if (!tsconfigPath) {
17
+ throw new Error('"tsconfigPath" is required when "tsProgramRef" is not provided.');
18
+ }
19
+ const tsBinary = this.typescriptLoader.load();
20
+ const spinner = ora({
21
+ text: constants_1.INITIALIZING_TYPE_CHECKER,
22
+ });
23
+ if (options.watch) {
24
+ console.log();
25
+ spinner.start();
26
+ this.runInWatchMode(tsconfigPath, tsBinary, options);
27
+ spinner.succeed();
28
+ return;
29
+ }
30
+ spinner.start();
31
+ this.runOnce(tsconfigPath, tsBinary, options);
32
+ spinner.succeed();
33
+ }
34
+ runInWatchMode(tsconfigPath, tsBinary, options) {
35
+ const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(tsconfigPath);
36
+ let builderProgram = undefined;
37
+ const reportWatchStatusCallback = (diagnostic) => {
38
+ var _a, _b;
39
+ if (diagnostic.messageText !== constants_1.TSC_NO_ERRORS_MESSAGE) {
40
+ if ((_a = diagnostic.messageText) === null || _a === void 0 ? void 0 : _a.includes('Found')) {
41
+ console.log(constants_1.TSC_LOG_ERROR_PREFIX, chalk.red(diagnostic.messageText));
42
+ }
43
+ return;
44
+ }
45
+ if (!builderProgram) {
46
+ return;
47
+ }
48
+ const tsProgram = builderProgram.getProgram().getProgram();
49
+ (_b = options.onSuccess) === null || _b === void 0 ? void 0 : _b.call(options, tsProgram);
50
+ };
51
+ const host = this.createWatchCompilerHost(tsBinary, tsconfigPath, tsOptions, reportWatchStatusCallback);
52
+ builderProgram = tsBinary.createWatchProgram(host);
53
+ }
54
+ runOnce(tsconfigPath, tsBinary, options) {
55
+ var _a, _b;
56
+ const { options: tsOptions, fileNames, projectReferences, } = this.tsConfigProvider.getByConfigFilename(tsconfigPath);
57
+ const createProgram = (_a = tsBinary.createIncrementalProgram) !== null && _a !== void 0 ? _a : tsBinary.createProgram;
58
+ const program = createProgram.call(ts, {
59
+ rootNames: fileNames,
60
+ projectReferences,
61
+ options: tsOptions,
62
+ });
63
+ const programRef = program.getProgram
64
+ ? program.getProgram()
65
+ : program;
66
+ const diagnostics = tsBinary.getPreEmitDiagnostics(programRef);
67
+ if (diagnostics.length > 0) {
68
+ const formatDiagnosticsHost = {
69
+ getCanonicalFileName: (path) => path,
70
+ getCurrentDirectory: tsBinary.sys.getCurrentDirectory,
71
+ getNewLine: () => tsBinary.sys.newLine,
72
+ };
73
+ console.log();
74
+ console.log(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost));
75
+ process.exit(1);
76
+ }
77
+ (_b = options.onSuccess) === null || _b === void 0 ? void 0 : _b.call(options, programRef);
78
+ }
79
+ createWatchCompilerHost(tsBinary, tsConfigPath, options, reportWatchStatusCallback) {
80
+ const origDiagnosticReporter = tsBinary.createDiagnosticReporter(tsBinary.sys, true);
81
+ const tsOptions = Object.assign(Object.assign({}, options), { preserveWatchOutput: true, noEmit: true });
82
+ return tsBinary.createWatchCompilerHost(tsConfigPath, tsOptions, tsBinary.sys, undefined, origDiagnosticReporter, reportWatchStatusCallback);
83
+ }
84
+ }
85
+ exports.TypeCheckerHost = TypeCheckerHost;
@@ -1,14 +1,18 @@
1
- import * as ts from 'typescript';
2
1
  import { Configuration } from '../configuration';
2
+ import { BaseCompiler } from './base-compiler';
3
3
  import { TsConfigProvider } from './helpers/tsconfig-provider';
4
- import { PluginsLoader } from './plugins-loader';
4
+ import { PluginsLoader } from './plugins/plugins-loader';
5
5
  import { TypeScriptBinaryLoader } from './typescript-loader';
6
- export declare class WatchCompiler {
7
- private readonly pluginsLoader;
6
+ type TypescriptWatchCompilerExtras = {
7
+ preserveWatchOutput: boolean;
8
+ };
9
+ export declare class WatchCompiler extends BaseCompiler<TypescriptWatchCompilerExtras> {
8
10
  private readonly tsConfigProvider;
9
11
  private readonly typescriptLoader;
10
12
  constructor(pluginsLoader: PluginsLoader, tsConfigProvider: TsConfigProvider, typescriptLoader: TypeScriptBinaryLoader);
11
- run(configuration: Required<Configuration>, configFilename: string, appName: string, tsCompilerOptions: ts.CompilerOptions, onSuccess?: () => void): void;
13
+ run(configuration: Required<Configuration>, tsConfigPath: string, appName: string, extras: TypescriptWatchCompilerExtras, onSuccess?: () => void): void;
14
+ private overrideCreateProgramFn;
12
15
  private createDiagnosticReporter;
13
16
  private createWatchStatusChanged;
14
17
  }
18
+ export {};
@@ -2,33 +2,46 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WatchCompiler = void 0;
4
4
  const errors_1 = require("../ui/errors");
5
+ const base_compiler_1 = require("./base-compiler");
5
6
  const get_value_or_default_1 = require("./helpers/get-value-or-default");
6
7
  const manual_restart_1 = require("./helpers/manual-restart");
7
8
  const tsconfig_paths_hook_1 = require("./hooks/tsconfig-paths.hook");
8
- class WatchCompiler {
9
+ class WatchCompiler extends base_compiler_1.BaseCompiler {
9
10
  constructor(pluginsLoader, tsConfigProvider, typescriptLoader) {
10
- this.pluginsLoader = pluginsLoader;
11
+ super(pluginsLoader);
11
12
  this.tsConfigProvider = tsConfigProvider;
12
13
  this.typescriptLoader = typescriptLoader;
13
14
  }
14
- run(configuration, configFilename, appName, tsCompilerOptions, onSuccess) {
15
+ run(configuration, tsConfigPath, appName, extras, onSuccess) {
15
16
  const tsBin = this.typescriptLoader.load();
16
- const configPath = tsBin.findConfigFile(process.cwd(), tsBin.sys.fileExists, configFilename);
17
+ const configPath = tsBin.findConfigFile(process.cwd(), tsBin.sys.fileExists, tsConfigPath);
17
18
  if (!configPath) {
18
- throw new Error(errors_1.CLI_ERRORS.MISSING_TYPESCRIPT(configFilename));
19
+ throw new Error(errors_1.CLI_ERRORS.MISSING_TYPESCRIPT(tsConfigPath));
19
20
  }
20
- const { options, projectReferences } = this.tsConfigProvider.getByConfigFilename(configFilename);
21
+ const { options, projectReferences } = this.tsConfigProvider.getByConfigFilename(tsConfigPath);
21
22
  const createProgram = tsBin.createEmitAndSemanticDiagnosticsBuilderProgram;
22
23
  const origDiagnosticReporter = tsBin.createDiagnosticReporter(tsBin.sys, true);
23
24
  const origWatchStatusReporter = tsBin.createWatchStatusReporter(tsBin.sys, true);
24
- const host = tsBin.createWatchCompilerHost(configPath, Object.assign(Object.assign({}, options), tsCompilerOptions), tsBin.sys, createProgram, this.createDiagnosticReporter(origDiagnosticReporter), this.createWatchStatusChanged(origWatchStatusReporter, onSuccess));
25
- const pluginsConfig = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.plugins', appName);
26
- const plugins = this.pluginsLoader.load(pluginsConfig);
25
+ const host = tsBin.createWatchCompilerHost(configPath, Object.assign(Object.assign({}, options), { preserveWatchOutput: extras.preserveWatchOutput }), tsBin.sys, createProgram, this.createDiagnosticReporter(origDiagnosticReporter), this.createWatchStatusChanged(origWatchStatusReporter, onSuccess));
26
+ const manualRestart = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.manualRestart', appName);
27
+ const plugins = this.loadPlugins(configuration, tsConfigPath, appName);
28
+ this.overrideCreateProgramFn(host, manualRestart, projectReferences, plugins);
29
+ const watchProgram = tsBin.createWatchProgram(host);
30
+ if (manualRestart) {
31
+ (0, manual_restart_1.listenForManualRestart)(() => {
32
+ watchProgram.close();
33
+ this.run(configuration, tsConfigPath, appName, extras, onSuccess);
34
+ });
35
+ }
36
+ }
37
+ overrideCreateProgramFn(host, manualRestart, projectReferences, plugins) {
27
38
  const origCreateProgram = host.createProgram;
28
39
  host.createProgram = (rootNames, options,
29
40
  // tslint:disable-next-line:no-shadowed-variable
30
41
  host, oldProgram) => {
31
- (0, manual_restart_1.displayManualRestartTip)();
42
+ if (manualRestart) {
43
+ (0, manual_restart_1.displayManualRestartTip)();
44
+ }
32
45
  const tsconfigPathsPlugin = options
33
46
  ? (0, tsconfig_paths_hook_1.tsconfigPathsBeforeHookFactory)(options)
34
47
  : null;
@@ -50,11 +63,6 @@ class WatchCompiler {
50
63
  };
51
64
  return program;
52
65
  };
53
- const watchProgram = tsBin.createWatchProgram(host);
54
- (0, manual_restart_1.listenForManualRestart)(() => {
55
- watchProgram.close();
56
- this.run(configuration, configFilename, appName, tsCompilerOptions, onSuccess);
57
- });
58
66
  }
59
67
  createDiagnosticReporter(diagnosticReporter) {
60
68
  return function (diagnostic, ...args) {
@@ -1,13 +1,21 @@
1
+ import { Input } from '../../commands';
1
2
  import { Configuration } from '../configuration';
2
3
  import { AssetsManager } from './assets-manager';
3
- import { PluginsLoader } from './plugins-loader';
4
- import { Input } from '../../commands';
4
+ import { BaseCompiler } from './base-compiler';
5
+ import { PluginsLoader } from './plugins/plugins-loader';
5
6
  import webpack = require('webpack');
6
7
  type WebpackConfigFactory = (config: webpack.Configuration, webpackRef: typeof webpack) => webpack.Configuration;
7
8
  type WebpackConfigFactoryOrConfig = WebpackConfigFactory | webpack.Configuration;
8
- export declare class WebpackCompiler {
9
- private readonly pluginsLoader;
9
+ type WebpackCompilerExtras = {
10
+ inputs: Input[];
11
+ assetsManager: AssetsManager;
12
+ webpackConfigFactoryOrConfig: WebpackConfigFactoryOrConfig | WebpackConfigFactoryOrConfig[];
13
+ debug?: boolean;
14
+ watchMode?: boolean;
15
+ };
16
+ export declare class WebpackCompiler extends BaseCompiler<WebpackCompilerExtras> {
10
17
  constructor(pluginsLoader: PluginsLoader);
11
- run(configuration: Required<Configuration>, options: Input[], webpackConfigFactoryOrConfig: WebpackConfigFactoryOrConfig | WebpackConfigFactoryOrConfig[], tsConfigPath: string, appName: string, isDebugEnabled: boolean | undefined, watchMode: boolean | undefined, assetsManager: AssetsManager, onSuccess?: () => void): void;
18
+ run(configuration: Required<Configuration>, tsConfigPath: string, appName: string, extras: WebpackCompilerExtras, onSuccess?: () => void): void;
19
+ private createAfterCallback;
12
20
  }
13
21
  export {};