@nestjs/cli 10.0.0-next.3 → 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.
- package/.circleci/config.yml +11 -12
- package/actions/add.action.js +67 -84
- package/actions/build.action.js +44 -59
- package/actions/generate.action.js +8 -19
- package/actions/info.action.js +31 -50
- package/actions/new.action.js +36 -47
- package/actions/start.action.js +29 -40
- package/bin/nest.js +4 -13
- package/commands/add.command.js +3 -12
- package/commands/build.command.js +3 -12
- package/commands/command.loader.js +8 -19
- package/commands/generate.command.js +67 -84
- package/commands/info.command.js +3 -12
- package/commands/new.command.js +3 -12
- package/commands/start.command.js +3 -12
- package/lib/compiler/assets-manager.js +3 -3
- package/lib/compiler/hooks/tsconfig-paths.hook.js +2 -2
- package/lib/compiler/plugins/plugin-metadata-generator.d.ts +40 -0
- package/lib/compiler/plugins/plugin-metadata-generator.js +40 -4
- package/lib/compiler/plugins/plugin-metadata-printer.d.ts +3 -0
- package/lib/compiler/plugins/plugin-metadata-printer.js +6 -6
- package/lib/compiler/plugins/plugins-loader.js +6 -2
- package/lib/compiler/swc/forked-type-checker.js +26 -37
- package/lib/compiler/swc/swc-compiler.js +35 -42
- package/lib/compiler/swc/type-checker-host.js +12 -9
- package/lib/compiler/typescript-loader.js +1 -1
- package/lib/compiler/watch-compiler.js +4 -1
- package/lib/compiler/webpack-compiler.js +12 -5
- package/lib/compiler/workspace-utils.js +6 -17
- package/lib/configuration/nest-configuration.loader.js +27 -28
- package/lib/dependency-managers/nest.dependency-manager.js +21 -34
- package/lib/package-managers/abstract.package-manager.js +124 -165
- package/lib/package-managers/package-manager.factory.js +15 -26
- package/lib/package-managers/package-manager.js +1 -1
- package/lib/readers/file-system.reader.js +10 -21
- package/lib/runners/abstract.runner.js +19 -30
- package/lib/runners/runner.js +1 -1
- package/lib/runners/schematic.runner.js +1 -1
- package/lib/schematics/abstract.collection.js +4 -15
- package/lib/schematics/collection.js +1 -1
- package/lib/schematics/custom.collection.js +1 -2
- package/lib/schematics/nest.collection.js +3 -17
- package/lib/utils/load-configuration.js +3 -14
- package/lib/utils/project-utils.js +6 -17
- package/package.json +18 -18
package/commands/new.command.js
CHANGED
|
@@ -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) =>
|
|
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
|
-
|
|
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");
|
|
@@ -32,7 +23,7 @@ class StartCommand extends abstract_command_1.AbstractCommand {
|
|
|
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) =>
|
|
26
|
+
.action(async (app, command) => {
|
|
36
27
|
const options = [];
|
|
37
28
|
options.push({
|
|
38
29
|
name: 'config',
|
|
@@ -91,12 +82,12 @@ class StartCommand extends abstract_command_1.AbstractCommand {
|
|
|
91
82
|
inputs.push({ name: 'app', value: app });
|
|
92
83
|
const flags = (0, remaining_flags_1.getRemainingFlags)(program);
|
|
93
84
|
try {
|
|
94
|
-
|
|
85
|
+
await this.action.handle(inputs, options, flags);
|
|
95
86
|
}
|
|
96
87
|
catch (err) {
|
|
97
88
|
process.exit(1);
|
|
98
89
|
}
|
|
99
|
-
})
|
|
90
|
+
});
|
|
100
91
|
}
|
|
101
92
|
}
|
|
102
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(
|
|
71
|
-
.on('change', (path) => this.actionOnFile(
|
|
72
|
-
.on('unlink', (path) => this.actionOnFile(
|
|
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
|
|
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
|
|
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
|
}
|
|
@@ -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
|
-
onTypeCheck:
|
|
22
|
-
|
|
23
|
-
},
|
|
58
|
+
onTypeCheck: onTypeCheckOrProgramInit,
|
|
59
|
+
onProgramInit: onTypeCheckOrProgramInit,
|
|
24
60
|
});
|
|
25
61
|
}
|
|
26
62
|
traverseAndPrintMetadata(programRef, visitors, outputDir, filename) {
|
|
@@ -4,6 +4,9 @@ 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
11
|
print(metadata: Record<string, Record<string, Array<[ts.CallExpression, DeepPluginMeta]>>>, options: PluginMetadataPrintOptions): void;
|
|
9
12
|
private recursivelyCreatePropertyAssignment;
|
|
@@ -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
|
|
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,
|
|
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,
|
|
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(
|
|
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
|
|
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,34 +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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
});
|
|
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
|
+
}
|
|
53
42
|
}
|
|
54
43
|
}
|
|
55
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
|
-
|
|
32
|
-
|
|
33
|
-
if (extras.
|
|
34
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
61
|
-
JSON.stringify(
|
|
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(),
|
|
@@ -100,13 +88,18 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
|
|
|
100
88
|
});
|
|
101
89
|
}
|
|
102
90
|
}
|
|
103
|
-
runSwc(options, extras) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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 =
|
|
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, () =>
|
|
160
|
+
watcher.on(type, async () => onChange());
|
|
168
161
|
}
|
|
169
162
|
}
|
|
170
163
|
}
|
|
@@ -32,13 +32,11 @@ class TypeCheckerHost {
|
|
|
32
32
|
spinner.succeed();
|
|
33
33
|
}
|
|
34
34
|
runInWatchMode(tsconfigPath, tsBinary, options) {
|
|
35
|
-
var _a;
|
|
36
35
|
const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(tsconfigPath);
|
|
37
36
|
let builderProgram = undefined;
|
|
38
37
|
const reportWatchStatusCallback = (diagnostic) => {
|
|
39
|
-
var _a, _b;
|
|
40
38
|
if (diagnostic.messageText !== constants_1.TSC_NO_ERRORS_MESSAGE) {
|
|
41
|
-
if (
|
|
39
|
+
if (diagnostic.messageText?.includes('Found')) {
|
|
42
40
|
console.log(constants_1.TSC_LOG_ERROR_PREFIX, chalk.red(diagnostic.messageText));
|
|
43
41
|
}
|
|
44
42
|
return;
|
|
@@ -47,16 +45,17 @@ class TypeCheckerHost {
|
|
|
47
45
|
return;
|
|
48
46
|
}
|
|
49
47
|
const tsProgram = builderProgram.getProgram().getProgram();
|
|
50
|
-
|
|
48
|
+
options.onTypeCheck?.(tsProgram);
|
|
51
49
|
};
|
|
52
50
|
const host = this.createWatchCompilerHost(tsBinary, tsconfigPath, tsOptions, reportWatchStatusCallback);
|
|
53
51
|
builderProgram = tsBinary.createWatchProgram(host);
|
|
54
|
-
(
|
|
52
|
+
process.nextTick(() => {
|
|
53
|
+
options.onProgramInit?.(builderProgram.getProgram().getProgram());
|
|
54
|
+
});
|
|
55
55
|
}
|
|
56
56
|
runOnce(tsconfigPath, tsBinary, options) {
|
|
57
|
-
var _a, _b;
|
|
58
57
|
const { options: tsOptions, fileNames, projectReferences, } = this.tsConfigProvider.getByConfigFilename(tsconfigPath);
|
|
59
|
-
const createProgram =
|
|
58
|
+
const createProgram = tsBinary.createIncrementalProgram ?? tsBinary.createProgram;
|
|
60
59
|
const program = createProgram.call(ts, {
|
|
61
60
|
rootNames: fileNames,
|
|
62
61
|
projectReferences,
|
|
@@ -76,11 +75,15 @@ class TypeCheckerHost {
|
|
|
76
75
|
console.log(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost));
|
|
77
76
|
process.exit(1);
|
|
78
77
|
}
|
|
79
|
-
|
|
78
|
+
options.onTypeCheck?.(programRef);
|
|
80
79
|
}
|
|
81
80
|
createWatchCompilerHost(tsBinary, tsConfigPath, options, reportWatchStatusCallback) {
|
|
82
81
|
const origDiagnosticReporter = tsBinary.createDiagnosticReporter(tsBinary.sys, true);
|
|
83
|
-
const tsOptions =
|
|
82
|
+
const tsOptions = {
|
|
83
|
+
...options,
|
|
84
|
+
preserveWatchOutput: true,
|
|
85
|
+
noEmit: true,
|
|
86
|
+
};
|
|
84
87
|
return tsBinary.createWatchCompilerHost(tsConfigPath, tsOptions, tsBinary.sys, undefined, origDiagnosticReporter, reportWatchStatusCallback);
|
|
85
88
|
}
|
|
86
89
|
}
|
|
@@ -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,
|
|
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);
|
|
@@ -13,7 +13,6 @@ class WebpackCompiler extends base_compiler_1.BaseCompiler {
|
|
|
13
13
|
super(pluginsLoader);
|
|
14
14
|
}
|
|
15
15
|
run(configuration, tsConfigPath, appName, extras, onSuccess) {
|
|
16
|
-
var _a, _b;
|
|
17
16
|
const cwd = process.cwd();
|
|
18
17
|
const configPath = (0, path_1.join)(cwd, tsConfigPath);
|
|
19
18
|
if (!(0, fs_1.existsSync)(configPath)) {
|
|
@@ -23,7 +22,7 @@ class WebpackCompiler extends base_compiler_1.BaseCompiler {
|
|
|
23
22
|
const pathToSource = this.getPathToSource(configuration, tsConfigPath, appName);
|
|
24
23
|
const entryFile = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'entryFile', appName, 'entryFile', extras.inputs);
|
|
25
24
|
const entryFileRoot = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'root', appName) || '';
|
|
26
|
-
const defaultOptions = (0, webpack_defaults_1.webpackDefaultsFactory)(pathToSource, entryFileRoot, entryFile,
|
|
25
|
+
const defaultOptions = (0, webpack_defaults_1.webpackDefaultsFactory)(pathToSource, entryFileRoot, entryFile, extras.debug ?? false, tsConfigPath, plugins);
|
|
27
26
|
let compiler;
|
|
28
27
|
let watchOptions;
|
|
29
28
|
let watch;
|
|
@@ -32,7 +31,11 @@ class WebpackCompiler extends base_compiler_1.BaseCompiler {
|
|
|
32
31
|
const unwrappedConfig = typeof configOrFactory !== 'function'
|
|
33
32
|
? configOrFactory
|
|
34
33
|
: configOrFactory(defaultOptions, webpack);
|
|
35
|
-
return
|
|
34
|
+
return {
|
|
35
|
+
...defaultOptions,
|
|
36
|
+
mode: extras.watchMode ? 'development' : defaultOptions.mode,
|
|
37
|
+
...unwrappedConfig,
|
|
38
|
+
};
|
|
36
39
|
});
|
|
37
40
|
compiler = webpack(webpackConfigurations);
|
|
38
41
|
watchOptions = webpackConfigurations.map((config) => config.watchOptions || {});
|
|
@@ -42,12 +45,16 @@ class WebpackCompiler extends base_compiler_1.BaseCompiler {
|
|
|
42
45
|
const projectWebpackOptions = typeof extras.webpackConfigFactoryOrConfig !== 'function'
|
|
43
46
|
? extras.webpackConfigFactoryOrConfig
|
|
44
47
|
: extras.webpackConfigFactoryOrConfig(defaultOptions, webpack);
|
|
45
|
-
const webpackConfiguration =
|
|
48
|
+
const webpackConfiguration = {
|
|
49
|
+
...defaultOptions,
|
|
50
|
+
mode: extras.watchMode ? 'development' : defaultOptions.mode,
|
|
51
|
+
...projectWebpackOptions,
|
|
52
|
+
};
|
|
46
53
|
compiler = webpack(webpackConfiguration);
|
|
47
54
|
watchOptions = webpackConfiguration.watchOptions;
|
|
48
55
|
watch = webpackConfiguration.watch;
|
|
49
56
|
}
|
|
50
|
-
const afterCallback = this.createAfterCallback(onSuccess, extras.assetsManager,
|
|
57
|
+
const afterCallback = this.createAfterCallback(onSuccess, extras.assetsManager, extras.watchMode ?? false, watch);
|
|
51
58
|
if (extras.watchMode || watch) {
|
|
52
59
|
compiler.hooks.watchRun.tapAsync('Rebuild info', (params, callback) => {
|
|
53
60
|
console.log(`\n${ui_1.INFO_PREFIX} Webpack is building your sources...\n`);
|
|
@@ -1,26 +1,15 @@
|
|
|
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.WorkspaceUtils = void 0;
|
|
13
4
|
const rimraf_1 = require("rimraf");
|
|
14
5
|
const get_value_or_default_1 = require("./helpers/get-value-or-default");
|
|
15
6
|
class WorkspaceUtils {
|
|
16
|
-
deleteOutDirIfEnabled(configuration, appName, dirPath) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
yield (0, rimraf_1.default)(dirPath);
|
|
23
|
-
});
|
|
7
|
+
async deleteOutDirIfEnabled(configuration, appName, dirPath) {
|
|
8
|
+
const isDeleteEnabled = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.deleteOutDir', appName);
|
|
9
|
+
if (!isDeleteEnabled) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
await (0, rimraf_1.default)(dirPath);
|
|
24
13
|
}
|
|
25
14
|
}
|
|
26
15
|
exports.WorkspaceUtils = WorkspaceUtils;
|