@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.
- package/.circleci/config.yml +2 -2
- package/actions/build.action.d.ts +4 -7
- package/actions/build.action.js +43 -21
- package/actions/new.action.js +1 -2
- package/commands/build.command.js +23 -1
- package/commands/start.command.js +23 -1
- package/lib/compiler/base-compiler.d.ts +9 -0
- package/lib/compiler/base-compiler.js +26 -0
- package/lib/compiler/compiler.d.ts +4 -4
- package/lib/compiler/compiler.js +6 -7
- package/lib/compiler/defaults/swc-defaults.d.ts +31 -0
- package/lib/compiler/defaults/swc-defaults.js +47 -0
- package/lib/compiler/defaults/webpack-defaults.d.ts +1 -1
- package/lib/compiler/helpers/get-value-or-default.d.ts +1 -1
- package/lib/compiler/helpers/is-compilable-extension.d.ts +1 -0
- package/lib/compiler/helpers/is-compilable-extension.js +9 -0
- package/lib/compiler/hooks/tsconfig-paths.hook.js +2 -9
- package/lib/compiler/interfaces/readonly-visitor.interface.d.ts +9 -0
- package/lib/compiler/interfaces/readonly-visitor.interface.js +2 -0
- package/lib/compiler/plugins/plugin-metadata-generator.d.ts +15 -0
- package/lib/compiler/plugins/plugin-metadata-generator.js +39 -0
- package/lib/compiler/plugins/plugin-metadata-printer.d.ts +5 -0
- package/lib/compiler/plugins/plugin-metadata-printer.js +30 -0
- package/lib/compiler/plugins/plugins-loader.d.ts +30 -0
- package/lib/compiler/plugins/plugins-loader.js +66 -0
- package/lib/compiler/swc/constants.d.ts +9 -0
- package/lib/compiler/swc/constants.js +14 -0
- package/lib/compiler/swc/forked-type-checker.d.ts +1 -0
- package/lib/compiler/swc/forked-type-checker.js +72 -0
- package/lib/compiler/swc/swc-compiler.d.ts +20 -0
- package/lib/compiler/swc/swc-compiler.js +171 -0
- package/lib/compiler/swc/type-checker-host.d.ts +13 -0
- package/lib/compiler/swc/type-checker-host.js +85 -0
- package/lib/compiler/watch-compiler.d.ts +9 -5
- package/lib/compiler/watch-compiler.js +23 -15
- package/lib/compiler/webpack-compiler.d.ts +13 -5
- package/lib/compiler/webpack-compiler.js +30 -30
- package/lib/configuration/configuration.d.ts +1 -0
- package/lib/configuration/defaults.js +1 -0
- package/lib/package-managers/package-manager.factory.js +17 -19
- package/lib/readers/file-system.reader.js +3 -24
- package/package.json +22 -13
- package/lib/compiler/plugins-loader.d.ts +0 -21
- package/lib/compiler/plugins-loader.js +0 -54
package/.circleci/config.yml
CHANGED
|
@@ -21,7 +21,7 @@ jobs:
|
|
|
21
21
|
build:
|
|
22
22
|
working_directory: ~/nest
|
|
23
23
|
docker:
|
|
24
|
-
- image: cimg/node:20.
|
|
24
|
+
- image: cimg/node:20.2
|
|
25
25
|
steps:
|
|
26
26
|
- checkout
|
|
27
27
|
- run:
|
|
@@ -43,7 +43,7 @@ jobs:
|
|
|
43
43
|
unit_tests:
|
|
44
44
|
working_directory: ~/nest
|
|
45
45
|
docker:
|
|
46
|
-
- image: cimg/node:20.
|
|
46
|
+
- image: cimg/node:20.2
|
|
47
47
|
steps:
|
|
48
48
|
- checkout
|
|
49
49
|
- *restore-cache
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Input } from '../commands';
|
|
2
2
|
import { AssetsManager } from '../lib/compiler/assets-manager';
|
|
3
|
-
import { Compiler } from '../lib/compiler/compiler';
|
|
4
3
|
import { TsConfigProvider } from '../lib/compiler/helpers/tsconfig-provider';
|
|
5
|
-
import { PluginsLoader } from '../lib/compiler/plugins-loader';
|
|
4
|
+
import { PluginsLoader } from '../lib/compiler/plugins/plugins-loader';
|
|
6
5
|
import { TypeScriptBinaryLoader } from '../lib/compiler/typescript-loader';
|
|
7
|
-
import { WatchCompiler } from '../lib/compiler/watch-compiler';
|
|
8
|
-
import { WebpackCompiler } from '../lib/compiler/webpack-compiler';
|
|
9
6
|
import { WorkspaceUtils } from '../lib/compiler/workspace-utils';
|
|
10
7
|
import { ConfigurationLoader } from '../lib/configuration';
|
|
11
8
|
import { FileSystemReader } from '../lib/readers';
|
|
@@ -14,14 +11,14 @@ export declare class BuildAction extends AbstractAction {
|
|
|
14
11
|
protected readonly pluginsLoader: PluginsLoader;
|
|
15
12
|
protected readonly tsLoader: TypeScriptBinaryLoader;
|
|
16
13
|
protected readonly tsConfigProvider: TsConfigProvider;
|
|
17
|
-
protected readonly compiler: Compiler;
|
|
18
|
-
protected readonly webpackCompiler: WebpackCompiler;
|
|
19
|
-
protected readonly watchCompiler: WatchCompiler;
|
|
20
14
|
protected readonly fileSystemReader: FileSystemReader;
|
|
21
15
|
protected readonly loader: ConfigurationLoader;
|
|
22
16
|
protected readonly assetsManager: AssetsManager;
|
|
23
17
|
protected readonly workspaceUtils: WorkspaceUtils;
|
|
24
18
|
handle(inputs: Input[], options: Input[]): Promise<void>;
|
|
25
19
|
runBuild(inputs: Input[], options: Input[], watchMode: boolean, watchAssetsMode: boolean, isDebugEnabled?: boolean, onSuccess?: () => void): Promise<void>;
|
|
20
|
+
private runSwc;
|
|
21
|
+
private runWebpack;
|
|
22
|
+
private runTsc;
|
|
26
23
|
private getWebpackConfigFactoryByPath;
|
|
27
24
|
}
|
package/actions/build.action.js
CHANGED
|
@@ -16,7 +16,8 @@ const assets_manager_1 = require("../lib/compiler/assets-manager");
|
|
|
16
16
|
const compiler_1 = require("../lib/compiler/compiler");
|
|
17
17
|
const get_value_or_default_1 = require("../lib/compiler/helpers/get-value-or-default");
|
|
18
18
|
const tsconfig_provider_1 = require("../lib/compiler/helpers/tsconfig-provider");
|
|
19
|
-
const plugins_loader_1 = require("../lib/compiler/plugins-loader");
|
|
19
|
+
const plugins_loader_1 = require("../lib/compiler/plugins/plugins-loader");
|
|
20
|
+
const swc_compiler_1 = require("../lib/compiler/swc/swc-compiler");
|
|
20
21
|
const typescript_loader_1 = require("../lib/compiler/typescript-loader");
|
|
21
22
|
const watch_compiler_1 = require("../lib/compiler/watch-compiler");
|
|
22
23
|
const webpack_compiler_1 = require("../lib/compiler/webpack-compiler");
|
|
@@ -32,9 +33,6 @@ class BuildAction extends abstract_action_1.AbstractAction {
|
|
|
32
33
|
this.pluginsLoader = new plugins_loader_1.PluginsLoader();
|
|
33
34
|
this.tsLoader = new typescript_loader_1.TypeScriptBinaryLoader();
|
|
34
35
|
this.tsConfigProvider = new tsconfig_provider_1.TsConfigProvider(this.tsLoader);
|
|
35
|
-
this.compiler = new compiler_1.Compiler(this.pluginsLoader, this.tsConfigProvider, this.tsLoader);
|
|
36
|
-
this.webpackCompiler = new webpack_compiler_1.WebpackCompiler(this.pluginsLoader);
|
|
37
|
-
this.watchCompiler = new watch_compiler_1.WatchCompiler(this.pluginsLoader, this.tsConfigProvider, this.tsLoader);
|
|
38
36
|
this.fileSystemReader = new readers_1.FileSystemReader(process.cwd());
|
|
39
37
|
this.loader = new configuration_1.NestConfigurationLoader(this.fileSystemReader);
|
|
40
38
|
this.assetsManager = new assets_manager_1.AssetsManager();
|
|
@@ -70,28 +68,52 @@ class BuildAction extends abstract_action_1.AbstractAction {
|
|
|
70
68
|
const pathToTsconfig = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.tsConfigPath', appName, 'path', options);
|
|
71
69
|
const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
|
|
72
70
|
const outDir = tsOptions.outDir || defaults_1.defaultOutDir;
|
|
73
|
-
const
|
|
71
|
+
const builder = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.builder', appName, 'builder', options);
|
|
74
72
|
yield this.workspaceUtils.deleteOutDirIfEnabled(configuration, appName, outDir);
|
|
75
73
|
this.assetsManager.copyAssets(configuration, appName, outDir, watchAssetsMode);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const isPreserveWatchOutputEnabled = options.find((option) => option.name === 'preserveWatchOutput' && option.value === true);
|
|
84
|
-
if (isPreserveWatchOutputEnabled) {
|
|
85
|
-
tsCompilerOptions.preserveWatchOutput = true;
|
|
86
|
-
}
|
|
87
|
-
this.watchCompiler.run(configuration, pathToTsconfig, appName, tsCompilerOptions, onSuccess);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.compiler.run(configuration, pathToTsconfig, appName, onSuccess);
|
|
91
|
-
this.assetsManager.closeWatchers();
|
|
74
|
+
switch (builder) {
|
|
75
|
+
case 'tsc':
|
|
76
|
+
return this.runTsc(watchMode, options, configuration, pathToTsconfig, appName, onSuccess);
|
|
77
|
+
case 'webpack':
|
|
78
|
+
return this.runWebpack(configuration, appName, options, pathToTsconfig, isDebugEnabled, watchMode, onSuccess);
|
|
79
|
+
case 'swc':
|
|
80
|
+
return this.runSwc(configuration, appName, pathToTsconfig, watchMode, options, onSuccess);
|
|
92
81
|
}
|
|
93
82
|
});
|
|
94
83
|
}
|
|
84
|
+
runSwc(configuration, appName, pathToTsconfig, watchMode, options, onSuccess) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const swc = new swc_compiler_1.SwcCompiler(this.pluginsLoader);
|
|
87
|
+
yield swc.run(configuration, pathToTsconfig, appName, {
|
|
88
|
+
watch: watchMode,
|
|
89
|
+
typeCheck: (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', options),
|
|
90
|
+
}, onSuccess);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
runWebpack(configuration, appName, inputs, pathToTsconfig, debug, watchMode, onSuccess) {
|
|
94
|
+
const webpackCompiler = new webpack_compiler_1.WebpackCompiler(this.pluginsLoader);
|
|
95
|
+
const webpackPath = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.webpackConfigPath', appName, 'webpackPath', inputs);
|
|
96
|
+
const webpackConfigFactoryOrConfig = this.getWebpackConfigFactoryByPath(webpackPath, configuration.compilerOptions.webpackConfigPath);
|
|
97
|
+
return webpackCompiler.run(configuration, pathToTsconfig, appName, {
|
|
98
|
+
inputs,
|
|
99
|
+
webpackConfigFactoryOrConfig,
|
|
100
|
+
debug,
|
|
101
|
+
watchMode,
|
|
102
|
+
assetsManager: this.assetsManager,
|
|
103
|
+
}, onSuccess);
|
|
104
|
+
}
|
|
105
|
+
runTsc(watchMode, options, configuration, pathToTsconfig, appName, onSuccess) {
|
|
106
|
+
if (watchMode) {
|
|
107
|
+
const watchCompiler = new watch_compiler_1.WatchCompiler(this.pluginsLoader, this.tsConfigProvider, this.tsLoader);
|
|
108
|
+
const isPreserveWatchOutputEnabled = options.find((option) => option.name === 'preserveWatchOutput' && option.value === true);
|
|
109
|
+
watchCompiler.run(configuration, pathToTsconfig, appName, { preserveWatchOutput: !!isPreserveWatchOutputEnabled }, onSuccess);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const compiler = new compiler_1.Compiler(this.pluginsLoader, this.tsConfigProvider, this.tsLoader);
|
|
113
|
+
compiler.run(configuration, pathToTsconfig, appName, undefined, onSuccess);
|
|
114
|
+
this.assetsManager.closeWatchers();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
95
117
|
getWebpackConfigFactoryByPath(webpackPath, defaultPath) {
|
|
96
118
|
const pathToWebpackFile = (0, path_1.join)(process.cwd(), webpackPath);
|
|
97
119
|
try {
|
package/actions/new.action.js
CHANGED
|
@@ -15,7 +15,6 @@ const child_process_1 = require("child_process");
|
|
|
15
15
|
const fs = require("fs");
|
|
16
16
|
const inquirer = require("inquirer");
|
|
17
17
|
const path_1 = require("path");
|
|
18
|
-
const util_1 = require("util");
|
|
19
18
|
const defaults_1 = require("../lib/configuration/defaults");
|
|
20
19
|
const package_managers_1 = require("../lib/package-managers");
|
|
21
20
|
const questions_1 = require("../lib/questions/questions");
|
|
@@ -144,7 +143,7 @@ const createGitIgnoreFile = (dir, content) => {
|
|
|
144
143
|
if (fileExists(filePath)) {
|
|
145
144
|
return;
|
|
146
145
|
}
|
|
147
|
-
return
|
|
146
|
+
return fs.promises.writeFile(filePath, fileContent);
|
|
148
147
|
};
|
|
149
148
|
const printCollective = () => {
|
|
150
149
|
const dim = print('dim');
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.BuildCommand = void 0;
|
|
13
|
+
const ui_1 = require("../lib/ui");
|
|
13
14
|
const abstract_command_1 = require("./abstract.command");
|
|
14
15
|
class BuildCommand extends abstract_command_1.AbstractCommand {
|
|
15
16
|
load(program) {
|
|
@@ -18,12 +19,15 @@ class BuildCommand extends abstract_command_1.AbstractCommand {
|
|
|
18
19
|
.option('-c, --config [path]', 'Path to nest-cli configuration file.')
|
|
19
20
|
.option('-p, --path [path]', 'Path to tsconfig file.')
|
|
20
21
|
.option('-w, --watch', 'Run in watch mode (live-reload).')
|
|
22
|
+
.option('-b, --builder [name]', 'Builder to be used (tsc, webpack, swc).')
|
|
21
23
|
.option('--watchAssets', 'Watch non-ts (e.g., .graphql) files mode.')
|
|
22
|
-
.option('--webpack', 'Use webpack for compilation.')
|
|
24
|
+
.option('--webpack', 'Use webpack for compilation (deprecated option, use --build instead).')
|
|
25
|
+
.option('--type-check', 'Enable type checking (when SWC is used).', false)
|
|
23
26
|
.option('--webpackPath [path]', 'Path to webpack configuration.')
|
|
24
27
|
.option('--tsc', 'Use tsc for compilation.')
|
|
25
28
|
.description('Build Nest application.')
|
|
26
29
|
.action((app, command) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
var _a;
|
|
27
31
|
const options = [];
|
|
28
32
|
options.push({
|
|
29
33
|
name: 'config',
|
|
@@ -41,6 +45,24 @@ class BuildCommand extends abstract_command_1.AbstractCommand {
|
|
|
41
45
|
name: 'webpackPath',
|
|
42
46
|
value: command.webpackPath,
|
|
43
47
|
});
|
|
48
|
+
const availableBuilders = ['tsc', 'webpack', 'swc'];
|
|
49
|
+
if (command.builder && !availableBuilders.includes(command.builder)) {
|
|
50
|
+
console.error(ui_1.ERROR_PREFIX +
|
|
51
|
+
` Invalid builder option: ${command.builder}. Available builders: ${availableBuilders.join(', ')}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
options.push({
|
|
55
|
+
name: 'builder',
|
|
56
|
+
value: (_a = command.builder) !== null && _a !== void 0 ? _a : (isWebpackEnabled ? 'webpack' : 'tsc'),
|
|
57
|
+
});
|
|
58
|
+
if (command.typeCheck && command.builder !== 'swc') {
|
|
59
|
+
console.warn(ui_1.INFO_PREFIX +
|
|
60
|
+
` "typeCheck" will not have any effect when "builder" is not "swc".`);
|
|
61
|
+
}
|
|
62
|
+
options.push({
|
|
63
|
+
name: 'typeCheck',
|
|
64
|
+
value: command.typeCheck,
|
|
65
|
+
});
|
|
44
66
|
const inputs = [];
|
|
45
67
|
inputs.push({ name: 'app', value: app });
|
|
46
68
|
yield this.action.handle(inputs, options);
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.StartCommand = void 0;
|
|
13
|
+
const ui_1 = require("../lib/ui");
|
|
13
14
|
const remaining_flags_1 = require("../lib/utils/remaining-flags");
|
|
14
15
|
const abstract_command_1 = require("./abstract.command");
|
|
15
16
|
class StartCommand extends abstract_command_1.AbstractCommand {
|
|
@@ -19,10 +20,12 @@ class StartCommand extends abstract_command_1.AbstractCommand {
|
|
|
19
20
|
.option('-c, --config [path]', 'Path to nest-cli configuration file.')
|
|
20
21
|
.option('-p, --path [path]', 'Path to tsconfig file.')
|
|
21
22
|
.option('-w, --watch', 'Run in watch mode (live-reload).')
|
|
23
|
+
.option('-b, --builder [name]', 'Builder to be used (tsc, webpack, swc).')
|
|
22
24
|
.option('--watchAssets', 'Watch non-ts (e.g., .graphql) files mode.')
|
|
23
25
|
.option('-d, --debug [hostport] ', 'Run in debug mode (with --inspect flag).')
|
|
24
|
-
.option('--webpack', 'Use webpack for compilation.')
|
|
26
|
+
.option('--webpack', 'Use webpack for compilation (deprecated option, use --build instead).')
|
|
25
27
|
.option('--webpackPath [path]', 'Path to webpack configuration.')
|
|
28
|
+
.option('--type-check', 'Enable type checking (when SWC is used).', false)
|
|
26
29
|
.option('--tsc', 'Use tsc for compilation.')
|
|
27
30
|
.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.')
|
|
28
31
|
.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.")
|
|
@@ -30,6 +33,7 @@ class StartCommand extends abstract_command_1.AbstractCommand {
|
|
|
30
33
|
.option('--preserveWatchOutput', 'Use "preserveWatchOutput" option when tsc watch mode.')
|
|
31
34
|
.description('Run Nest application.')
|
|
32
35
|
.action((app, command) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
var _a;
|
|
33
37
|
const options = [];
|
|
34
38
|
options.push({
|
|
35
39
|
name: 'config',
|
|
@@ -66,6 +70,24 @@ class StartCommand extends abstract_command_1.AbstractCommand {
|
|
|
66
70
|
!!command.watch &&
|
|
67
71
|
!isWebpackEnabled,
|
|
68
72
|
});
|
|
73
|
+
const availableBuilders = ['tsc', 'webpack', 'swc'];
|
|
74
|
+
if (command.builder && !availableBuilders.includes(command.builder)) {
|
|
75
|
+
console.error(ui_1.ERROR_PREFIX +
|
|
76
|
+
` Invalid builder option: ${command.builder}. Available builders: ${availableBuilders.join(', ')}`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
options.push({
|
|
80
|
+
name: 'builder',
|
|
81
|
+
value: (_a = command.builder) !== null && _a !== void 0 ? _a : (isWebpackEnabled ? 'webpack' : 'tsc'),
|
|
82
|
+
});
|
|
83
|
+
if (command.typeCheck && command.builder !== 'swc') {
|
|
84
|
+
console.warn(ui_1.INFO_PREFIX +
|
|
85
|
+
` "typeCheck" will not have any effect when "builder" is not "swc".`);
|
|
86
|
+
}
|
|
87
|
+
options.push({
|
|
88
|
+
name: 'typeCheck',
|
|
89
|
+
value: command.typeCheck,
|
|
90
|
+
});
|
|
69
91
|
const inputs = [];
|
|
70
92
|
inputs.push({ name: 'app', value: app });
|
|
71
93
|
const flags = (0, remaining_flags_1.getRemainingFlags)(program);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Configuration } from '../configuration';
|
|
2
|
+
import { PluginsLoader } from './plugins/plugins-loader';
|
|
3
|
+
export declare abstract class BaseCompiler<T = Record<string, any>> {
|
|
4
|
+
private readonly pluginsLoader;
|
|
5
|
+
constructor(pluginsLoader: PluginsLoader);
|
|
6
|
+
abstract run(configuration: Required<Configuration>, tsConfigPath: string, appName: string | undefined, extras?: T, onSuccess?: () => void): any;
|
|
7
|
+
loadPlugins(configuration: Required<Configuration>, tsConfigPath: string, appName: string | undefined): import("./plugins/plugins-loader").MultiNestCompilerPlugins;
|
|
8
|
+
getPathToSource(configuration: Required<Configuration>, tsConfigPath: string, appName: string | undefined): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseCompiler = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const get_value_or_default_1 = require("./helpers/get-value-or-default");
|
|
6
|
+
class BaseCompiler {
|
|
7
|
+
constructor(pluginsLoader) {
|
|
8
|
+
this.pluginsLoader = pluginsLoader;
|
|
9
|
+
}
|
|
10
|
+
loadPlugins(configuration, tsConfigPath, appName) {
|
|
11
|
+
const pluginsConfig = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.plugins', appName);
|
|
12
|
+
const pathToSource = this.getPathToSource(configuration, tsConfigPath, appName);
|
|
13
|
+
const plugins = this.pluginsLoader.load(pluginsConfig, { pathToSource });
|
|
14
|
+
return plugins;
|
|
15
|
+
}
|
|
16
|
+
getPathToSource(configuration, tsConfigPath, appName) {
|
|
17
|
+
const sourceRoot = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'sourceRoot', appName, 'sourceRoot');
|
|
18
|
+
const cwd = process.cwd();
|
|
19
|
+
const relativeRootPath = (0, path_1.dirname)((0, path_1.relative)(cwd, tsConfigPath));
|
|
20
|
+
const pathToSource = (0, path_1.normalize)(sourceRoot).indexOf((0, path_1.normalize)(relativeRootPath)) >= 0
|
|
21
|
+
? (0, path_1.join)(cwd, sourceRoot)
|
|
22
|
+
: (0, path_1.join)(cwd, relativeRootPath, sourceRoot);
|
|
23
|
+
return pathToSource;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.BaseCompiler = BaseCompiler;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Configuration } from '../configuration';
|
|
2
|
+
import { BaseCompiler } from './base-compiler';
|
|
2
3
|
import { TsConfigProvider } from './helpers/tsconfig-provider';
|
|
3
|
-
import { PluginsLoader } from './plugins-loader';
|
|
4
|
+
import { PluginsLoader } from './plugins/plugins-loader';
|
|
4
5
|
import { TypeScriptBinaryLoader } from './typescript-loader';
|
|
5
|
-
export declare class Compiler {
|
|
6
|
-
private readonly pluginsLoader;
|
|
6
|
+
export declare class Compiler extends BaseCompiler {
|
|
7
7
|
private readonly tsConfigProvider;
|
|
8
8
|
private readonly typescriptLoader;
|
|
9
9
|
constructor(pluginsLoader: PluginsLoader, tsConfigProvider: TsConfigProvider, typescriptLoader: TypeScriptBinaryLoader);
|
|
10
|
-
run(configuration: Required<Configuration>,
|
|
10
|
+
run(configuration: Required<Configuration>, tsConfigPath: string, appName: string, _extras: any, onSuccess?: () => void): void;
|
|
11
11
|
private reportAfterCompilationDiagnostic;
|
|
12
12
|
}
|
package/lib/compiler/compiler.js
CHANGED
|
@@ -2,30 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Compiler = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
-
const
|
|
5
|
+
const base_compiler_1 = require("./base-compiler");
|
|
6
6
|
const tsconfig_paths_hook_1 = require("./hooks/tsconfig-paths.hook");
|
|
7
|
-
class Compiler {
|
|
7
|
+
class Compiler extends base_compiler_1.BaseCompiler {
|
|
8
8
|
constructor(pluginsLoader, tsConfigProvider, typescriptLoader) {
|
|
9
|
-
|
|
9
|
+
super(pluginsLoader);
|
|
10
10
|
this.tsConfigProvider = tsConfigProvider;
|
|
11
11
|
this.typescriptLoader = typescriptLoader;
|
|
12
12
|
}
|
|
13
|
-
run(configuration,
|
|
13
|
+
run(configuration, tsConfigPath, appName, _extras, onSuccess) {
|
|
14
14
|
const tsBinary = this.typescriptLoader.load();
|
|
15
15
|
const formatHost = {
|
|
16
16
|
getCanonicalFileName: (path) => path,
|
|
17
17
|
getCurrentDirectory: tsBinary.sys.getCurrentDirectory,
|
|
18
18
|
getNewLine: () => tsBinary.sys.newLine,
|
|
19
19
|
};
|
|
20
|
-
const { options, fileNames, projectReferences } = this.tsConfigProvider.getByConfigFilename(
|
|
20
|
+
const { options, fileNames, projectReferences } = this.tsConfigProvider.getByConfigFilename(tsConfigPath);
|
|
21
21
|
const createProgram = tsBinary.createIncrementalProgram || tsBinary.createProgram;
|
|
22
22
|
const program = createProgram.call(ts, {
|
|
23
23
|
rootNames: fileNames,
|
|
24
24
|
projectReferences,
|
|
25
25
|
options,
|
|
26
26
|
});
|
|
27
|
-
const
|
|
28
|
-
const plugins = this.pluginsLoader.load(pluginsConfig);
|
|
27
|
+
const plugins = this.loadPlugins(configuration, tsConfigPath, appName);
|
|
29
28
|
const tsconfigPathsPlugin = (0, tsconfig_paths_hook_1.tsconfigPathsBeforeHookFactory)(options);
|
|
30
29
|
const programRef = program.getProgram
|
|
31
30
|
? program.getProgram()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const swcDefaultsFactory: () => {
|
|
2
|
+
swcOptions: {
|
|
3
|
+
jsc: {
|
|
4
|
+
target: string;
|
|
5
|
+
parser: {
|
|
6
|
+
syntax: string;
|
|
7
|
+
decorators: boolean;
|
|
8
|
+
dynamicImport: boolean;
|
|
9
|
+
};
|
|
10
|
+
transform: {
|
|
11
|
+
legacyDecorator: boolean;
|
|
12
|
+
decoratorMetadata: boolean;
|
|
13
|
+
};
|
|
14
|
+
keepClassNames: boolean;
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
};
|
|
17
|
+
minify: boolean;
|
|
18
|
+
swcrc: boolean;
|
|
19
|
+
};
|
|
20
|
+
cliOptions: {
|
|
21
|
+
outDir: string;
|
|
22
|
+
filenames: string[];
|
|
23
|
+
sync: boolean;
|
|
24
|
+
extensions: string[];
|
|
25
|
+
watch: boolean;
|
|
26
|
+
copyFiles: boolean;
|
|
27
|
+
includeDotfiles: boolean;
|
|
28
|
+
deleteDirOnStart: boolean;
|
|
29
|
+
quiet: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.swcDefaultsFactory = void 0;
|
|
4
|
+
const swcDefaultsFactory = () => {
|
|
5
|
+
return {
|
|
6
|
+
swcOptions: {
|
|
7
|
+
jsc: {
|
|
8
|
+
target: 'es2021',
|
|
9
|
+
parser: {
|
|
10
|
+
'syntax': 'typescript',
|
|
11
|
+
'decorators': true,
|
|
12
|
+
'dynamicImport': true,
|
|
13
|
+
},
|
|
14
|
+
transform: {
|
|
15
|
+
'legacyDecorator': true,
|
|
16
|
+
'decoratorMetadata': true,
|
|
17
|
+
},
|
|
18
|
+
keepClassNames: true,
|
|
19
|
+
baseUrl: './',
|
|
20
|
+
},
|
|
21
|
+
minify: false,
|
|
22
|
+
swcrc: true,
|
|
23
|
+
},
|
|
24
|
+
cliOptions: {
|
|
25
|
+
outDir: 'dist',
|
|
26
|
+
filenames: ['src'],
|
|
27
|
+
sync: false,
|
|
28
|
+
extensions: [
|
|
29
|
+
'.js',
|
|
30
|
+
'.jsx',
|
|
31
|
+
'.es6',
|
|
32
|
+
'.es',
|
|
33
|
+
'.mjs',
|
|
34
|
+
'.ts',
|
|
35
|
+
'.tsx',
|
|
36
|
+
'.cts',
|
|
37
|
+
'.mts',
|
|
38
|
+
],
|
|
39
|
+
watch: false,
|
|
40
|
+
copyFiles: false,
|
|
41
|
+
includeDotfiles: false,
|
|
42
|
+
deleteDirOnStart: true,
|
|
43
|
+
quiet: false,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
exports.swcDefaultsFactory = swcDefaultsFactory;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { MultiNestCompilerPlugins } from '../plugins-loader';
|
|
1
|
+
import { MultiNestCompilerPlugins } from '../plugins/plugins-loader';
|
|
2
2
|
import webpack = require('webpack');
|
|
3
3
|
export declare const webpackDefaultsFactory: (sourceRoot: string, relativeSourceRoot: string, entryFilename: string, isDebugEnabled: boolean | undefined, tsConfigFile: string | undefined, plugins: MultiNestCompilerPlugins) => webpack.Configuration;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Input } from '../../../commands';
|
|
2
2
|
import { Configuration } from '../../configuration';
|
|
3
|
-
export declare function getValueOrDefault<T = any>(configuration: Required<Configuration>, propertyPath: string, appName: string, key?: 'path' | 'webpack' | 'webpackPath' | 'entryFile' | 'sourceRoot' | 'exec', options?: Input[], defaultValue?: T): T;
|
|
3
|
+
export declare function getValueOrDefault<T = any>(configuration: Required<Configuration>, propertyPath: string, appName: string | undefined, key?: 'path' | 'webpack' | 'webpackPath' | 'entryFile' | 'sourceRoot' | 'exec' | 'builder' | 'typeCheck', options?: Input[], defaultValue?: T): T;
|
|
4
4
|
export declare function getValueOfPath<T = any>(object: Record<string, any>, propertyPath: string): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isCompilableExtension(filename: string, allowedExtension: string[]): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCompilableExtension = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
function isCompilableExtension(filename, allowedExtension) {
|
|
6
|
+
const ext = (0, path_1.extname)(filename);
|
|
7
|
+
return allowedExtension.includes(ext);
|
|
8
|
+
}
|
|
9
|
+
exports.isCompilableExtension = isCompilableExtension;
|
|
@@ -6,10 +6,7 @@ const path_1 = require("path");
|
|
|
6
6
|
const typescript_loader_1 = require("../typescript-loader");
|
|
7
7
|
const tsPaths = require("tsconfig-paths");
|
|
8
8
|
function tsconfigPathsBeforeHookFactory(compilerOptions) {
|
|
9
|
-
var _a;
|
|
10
9
|
const tsBinary = new typescript_loader_1.TypeScriptBinaryLoader().load();
|
|
11
|
-
const [tsVersionMajor, tsVersionMinor] = (_a = tsBinary.versionMajorMinor) === null || _a === void 0 ? void 0 : _a.split('.').map((x) => +x);
|
|
12
|
-
const isInUpdatedAstContext = tsVersionMinor >= 8 || tsVersionMajor > 4;
|
|
13
10
|
const { paths = {}, baseUrl = './' } = compilerOptions;
|
|
14
11
|
const matcher = tsPaths.createMatchPath(baseUrl, paths, ['main']);
|
|
15
12
|
return (ctx) => {
|
|
@@ -30,16 +27,12 @@ function tsconfigPathsBeforeHookFactory(compilerOptions) {
|
|
|
30
27
|
const moduleSpecifier = tsBinary.factory.createStringLiteral(result);
|
|
31
28
|
moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
32
29
|
if (tsBinary.isImportDeclaration(node)) {
|
|
33
|
-
const updatedNode =
|
|
34
|
-
? tsBinary.factory.updateImportDeclaration(node, node.modifiers, node.importClause, moduleSpecifier, node.assertClause)
|
|
35
|
-
: tsBinary.factory.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
30
|
+
const updatedNode = tsBinary.factory.updateImportDeclaration(node, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
36
31
|
updatedNode.flags = node.flags;
|
|
37
32
|
return updatedNode;
|
|
38
33
|
}
|
|
39
34
|
else {
|
|
40
|
-
const updatedNode =
|
|
41
|
-
? tsBinary.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause)
|
|
42
|
-
: tsBinary.factory.updateExportDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
35
|
+
const updatedNode = tsBinary.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
43
36
|
updatedNode.flags = node.flags;
|
|
44
37
|
return updatedNode;
|
|
45
38
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
export type DeepPluginMeta = ts.ObjectLiteralExpression | {
|
|
3
|
+
[key: string]: DeepPluginMeta;
|
|
4
|
+
};
|
|
5
|
+
export interface ReadonlyVisitor {
|
|
6
|
+
key: string;
|
|
7
|
+
visit(program: ts.Program, sf: ts.SourceFile): void;
|
|
8
|
+
collect(): Record<string, DeepPluginMeta>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { ReadonlyVisitor } from '../interfaces/readonly-visitor.interface';
|
|
3
|
+
export interface PluginMetadataGenerateOptions {
|
|
4
|
+
visitors: ReadonlyVisitor[];
|
|
5
|
+
outputDir: string;
|
|
6
|
+
watch?: boolean;
|
|
7
|
+
tsconfigPath?: string;
|
|
8
|
+
tsProgramRef?: ts.Program;
|
|
9
|
+
}
|
|
10
|
+
export declare class PluginMetadataGenerator {
|
|
11
|
+
private readonly pluginMetadataPrinter;
|
|
12
|
+
private readonly typeCheckerHost;
|
|
13
|
+
generate(options: PluginMetadataGenerateOptions): void;
|
|
14
|
+
private traverseAndPrintMetadata;
|
|
15
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginMetadataGenerator = void 0;
|
|
4
|
+
const type_checker_host_1 = require("../swc/type-checker-host");
|
|
5
|
+
const plugin_metadata_printer_1 = require("./plugin-metadata-printer");
|
|
6
|
+
class PluginMetadataGenerator {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.pluginMetadataPrinter = new plugin_metadata_printer_1.PluginMetadataPrinter();
|
|
9
|
+
this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
|
|
10
|
+
}
|
|
11
|
+
generate(options) {
|
|
12
|
+
const { tsconfigPath, visitors, tsProgramRef, outputDir, watch } = options;
|
|
13
|
+
if (visitors.length === 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (tsProgramRef) {
|
|
17
|
+
return this.traverseAndPrintMetadata(tsProgramRef, visitors, outputDir);
|
|
18
|
+
}
|
|
19
|
+
this.typeCheckerHost.run(tsconfigPath, {
|
|
20
|
+
watch,
|
|
21
|
+
onSuccess: (program) => {
|
|
22
|
+
this.traverseAndPrintMetadata(program, visitors, outputDir);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
traverseAndPrintMetadata(programRef, visitors, outputDir) {
|
|
27
|
+
for (const sourceFile of programRef.getSourceFiles()) {
|
|
28
|
+
if (!sourceFile.isDeclarationFile) {
|
|
29
|
+
visitors.forEach((visitor) => visitor.visit(programRef, sourceFile));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const collectedMetadata = {};
|
|
33
|
+
visitors.forEach((visitor) => {
|
|
34
|
+
collectedMetadata[visitor.key] = visitor.collect();
|
|
35
|
+
});
|
|
36
|
+
this.pluginMetadataPrinter.print(collectedMetadata, outputDir);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.PluginMetadataGenerator = PluginMetadataGenerator;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginMetadataPrinter = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const ts = require("typescript");
|
|
7
|
+
const SERIALIZED_METADATA_FILENAME = 'metadata.ts';
|
|
8
|
+
class PluginMetadataPrinter {
|
|
9
|
+
print(metadata, outputDir) {
|
|
10
|
+
const objectLiteralExpr = ts.factory.createObjectLiteralExpression(Object.keys(metadata).map((key) => this.recursivelyCreatePropertyAssignment(key, metadata[key])));
|
|
11
|
+
const metadataCacheVariableStatement = ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
12
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier('metadataCache'), undefined, undefined, objectLiteralExpr),
|
|
13
|
+
], ts.NodeFlags.Const));
|
|
14
|
+
const printer = ts.createPrinter({
|
|
15
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
16
|
+
});
|
|
17
|
+
const resultFile = ts.createSourceFile('file.ts', '', ts.ScriptTarget.Latest,
|
|
18
|
+
/*setParentNodes*/ false, ts.ScriptKind.TS);
|
|
19
|
+
const filename = (0, path_1.join)(outputDir, SERIALIZED_METADATA_FILENAME);
|
|
20
|
+
const eslintPrefix = `/* eslint-disable */\n`;
|
|
21
|
+
(0, fs_1.writeFileSync)(filename, eslintPrefix +
|
|
22
|
+
printer.printNode(ts.EmitHint.Unspecified, metadataCacheVariableStatement, resultFile));
|
|
23
|
+
}
|
|
24
|
+
recursivelyCreatePropertyAssignment(identifier, meta) {
|
|
25
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(identifier), ts.isObjectLiteralExpression(meta)
|
|
26
|
+
? meta
|
|
27
|
+
: ts.factory.createObjectLiteralExpression(Object.keys(meta).map((key) => this.recursivelyCreatePropertyAssignment(key, meta[key]))));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.PluginMetadataPrinter = PluginMetadataPrinter;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { ReadonlyVisitor } from '../interfaces/readonly-visitor.interface';
|
|
3
|
+
type Transformer = ts.TransformerFactory<any> | ts.CustomTransformerFactory;
|
|
4
|
+
type PluginEntry = string | PluginAndOptions;
|
|
5
|
+
type PluginOptions = Record<string, any>;
|
|
6
|
+
interface PluginAndOptions {
|
|
7
|
+
name: 'string';
|
|
8
|
+
options: PluginOptions;
|
|
9
|
+
}
|
|
10
|
+
export interface NestCompilerPlugin {
|
|
11
|
+
before?: (options?: PluginOptions, program?: ts.Program) => Transformer;
|
|
12
|
+
after?: (options?: PluginOptions, program?: ts.Program) => Transformer;
|
|
13
|
+
afterDeclarations?: (options?: PluginOptions, program?: ts.Program) => Transformer;
|
|
14
|
+
ReadonlyVisitor?: {
|
|
15
|
+
new (options: PluginOptions): ReadonlyVisitor;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface MultiNestCompilerPlugins {
|
|
19
|
+
beforeHooks: Array<(program?: ts.Program) => Transformer>;
|
|
20
|
+
afterHooks: Array<(program?: ts.Program) => Transformer>;
|
|
21
|
+
afterDeclarationsHooks: Array<(program?: ts.Program) => Transformer>;
|
|
22
|
+
readonlyVisitors: Array<ReadonlyVisitor>;
|
|
23
|
+
}
|
|
24
|
+
export declare class PluginsLoader {
|
|
25
|
+
load(plugins?: PluginEntry[], extras?: {
|
|
26
|
+
pathToSource?: string;
|
|
27
|
+
}): MultiNestCompilerPlugins;
|
|
28
|
+
private resolvePluginReferences;
|
|
29
|
+
}
|
|
30
|
+
export {};
|