@depup/nestjs__cli 11.0.16-depup.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/LICENSE +24 -0
- package/README.md +42 -0
- package/actions/abstract.action.d.ts +4 -0
- package/actions/abstract.action.js +6 -0
- package/actions/add.action.d.ts +12 -0
- package/actions/add.action.js +113 -0
- package/actions/build.action.d.ts +22 -0
- package/actions/build.action.js +145 -0
- package/actions/generate.action.d.ts +5 -0
- package/actions/generate.action.js +97 -0
- package/actions/index.d.ts +7 -0
- package/actions/index.js +23 -0
- package/actions/info.action.d.ts +35 -0
- package/actions/info.action.js +181 -0
- package/actions/new.action.d.ts +7 -0
- package/actions/new.action.js +186 -0
- package/actions/start.action.d.ts +10 -0
- package/actions/start.action.js +122 -0
- package/bin/nest.d.ts +2 -0
- package/bin/nest.js +25 -0
- package/changes.json +54 -0
- package/commands/abstract.command.d.ts +7 -0
- package/commands/abstract.command.js +9 -0
- package/commands/add.command.d.ts +5 -0
- package/commands/add.command.js +36 -0
- package/commands/build.command.d.ts +5 -0
- package/commands/build.command.js +74 -0
- package/commands/command.input.d.ts +5 -0
- package/commands/command.input.js +2 -0
- package/commands/command.loader.d.ts +5 -0
- package/commands/command.loader.js +31 -0
- package/commands/generate.command.d.ts +9 -0
- package/commands/generate.command.js +107 -0
- package/commands/index.d.ts +2 -0
- package/commands/index.js +18 -0
- package/commands/info.command.d.ts +5 -0
- package/commands/info.command.js +16 -0
- package/commands/new.command.d.ts +5 -0
- package/commands/new.command.js +61 -0
- package/commands/start.command.d.ts +5 -0
- package/commands/start.command.js +104 -0
- package/lib/compiler/assets-manager.d.ts +15 -0
- package/lib/compiler/assets-manager.js +129 -0
- package/lib/compiler/base-compiler.d.ts +9 -0
- package/lib/compiler/base-compiler.js +26 -0
- package/lib/compiler/compiler.d.ts +12 -0
- package/lib/compiler/compiler.js +61 -0
- package/lib/compiler/defaults/swc-defaults.d.ts +61 -0
- package/lib/compiler/defaults/swc-defaults.js +57 -0
- package/lib/compiler/defaults/webpack-defaults.d.ts +3 -0
- package/lib/compiler/defaults/webpack-defaults.js +104 -0
- package/lib/compiler/helpers/append-extension.d.ts +1 -0
- package/lib/compiler/helpers/append-extension.js +7 -0
- package/lib/compiler/helpers/copy-path-resolve.d.ts +7 -0
- package/lib/compiler/helpers/copy-path-resolve.js +25 -0
- package/lib/compiler/helpers/delete-out-dir.d.ts +2 -0
- package/lib/compiler/helpers/delete-out-dir.js +12 -0
- package/lib/compiler/helpers/get-builder.d.ts +21 -0
- package/lib/compiler/helpers/get-builder.js +19 -0
- package/lib/compiler/helpers/get-tsc-config.path.d.ts +10 -0
- package/lib/compiler/helpers/get-tsc-config.path.js +24 -0
- package/lib/compiler/helpers/get-value-or-default.d.ts +4 -0
- package/lib/compiler/helpers/get-value-or-default.js +66 -0
- package/lib/compiler/helpers/get-webpack-config-path.d.ts +10 -0
- package/lib/compiler/helpers/get-webpack-config-path.js +23 -0
- package/lib/compiler/helpers/manual-restart.d.ts +2 -0
- package/lib/compiler/helpers/manual-restart.js +17 -0
- package/lib/compiler/helpers/tsconfig-provider.d.ts +11 -0
- package/lib/compiler/helpers/tsconfig-provider.js +22 -0
- package/lib/compiler/hooks/tsconfig-paths.hook.d.ts +2 -0
- package/lib/compiler/hooks/tsconfig-paths.hook.js +76 -0
- package/lib/compiler/interfaces/readonly-visitor.interface.d.ts +10 -0
- package/lib/compiler/interfaces/readonly-visitor.interface.js +2 -0
- package/lib/compiler/plugins/plugin-metadata-generator.d.ts +58 -0
- package/lib/compiler/plugins/plugin-metadata-generator.js +84 -0
- package/lib/compiler/plugins/plugin-metadata-printer.d.ts +17 -0
- package/lib/compiler/plugins/plugin-metadata-printer.js +51 -0
- package/lib/compiler/plugins/plugins-loader.d.ts +30 -0
- package/lib/compiler/plugins/plugins-loader.js +70 -0
- package/lib/compiler/swc/constants.d.ts +9 -0
- package/lib/compiler/swc/constants.js +13 -0
- package/lib/compiler/swc/forked-type-checker.d.ts +1 -0
- package/lib/compiler/swc/forked-type-checker.js +63 -0
- package/lib/compiler/swc/swc-compiler.d.ts +25 -0
- package/lib/compiler/swc/swc-compiler.js +231 -0
- package/lib/compiler/swc/type-checker-host.d.ts +14 -0
- package/lib/compiler/swc/type-checker-host.js +90 -0
- package/lib/compiler/typescript-loader.d.ts +6 -0
- package/lib/compiler/typescript-loader.js +31 -0
- package/lib/compiler/watch-compiler.d.ts +22 -0
- package/lib/compiler/watch-compiler.js +89 -0
- package/lib/compiler/webpack-compiler.d.ts +21 -0
- package/lib/compiler/webpack-compiler.js +99 -0
- package/lib/configuration/configuration.d.ts +91 -0
- package/lib/configuration/configuration.js +2 -0
- package/lib/configuration/configuration.loader.d.ts +4 -0
- package/lib/configuration/configuration.loader.js +2 -0
- package/lib/configuration/defaults.d.ts +6 -0
- package/lib/configuration/defaults.js +86 -0
- package/lib/configuration/index.d.ts +3 -0
- package/lib/configuration/index.js +19 -0
- package/lib/configuration/nest-configuration.loader.d.ts +8 -0
- package/lib/configuration/nest-configuration.loader.js +61 -0
- package/lib/package-managers/abstract.package-manager.d.ts +25 -0
- package/lib/package-managers/abstract.package-manager.js +151 -0
- package/lib/package-managers/index.d.ts +8 -0
- package/lib/package-managers/index.js +24 -0
- package/lib/package-managers/npm.package-manager.d.ts +7 -0
- package/lib/package-managers/npm.package-manager.js +26 -0
- package/lib/package-managers/package-manager-commands.d.ts +9 -0
- package/lib/package-managers/package-manager-commands.js +2 -0
- package/lib/package-managers/package-manager.d.ts +5 -0
- package/lib/package-managers/package-manager.factory.d.ts +6 -0
- package/lib/package-managers/package-manager.factory.js +41 -0
- package/lib/package-managers/package-manager.js +9 -0
- package/lib/package-managers/pnpm.package-manager.d.ts +7 -0
- package/lib/package-managers/pnpm.package-manager.js +27 -0
- package/lib/package-managers/project.dependency.d.ts +4 -0
- package/lib/package-managers/project.dependency.js +2 -0
- package/lib/package-managers/yarn.package-manager.d.ts +7 -0
- package/lib/package-managers/yarn.package-manager.js +26 -0
- package/lib/questions/questions.d.ts +9 -0
- package/lib/questions/questions.js +27 -0
- package/lib/readers/file-system.reader.d.ts +8 -0
- package/lib/readers/file-system.reader.js +46 -0
- package/lib/readers/index.d.ts +2 -0
- package/lib/readers/index.js +18 -0
- package/lib/readers/reader.d.ts +10 -0
- package/lib/readers/reader.js +11 -0
- package/lib/runners/abstract.runner.d.ts +11 -0
- package/lib/runners/abstract.runner.js +47 -0
- package/lib/runners/git.runner.d.ts +4 -0
- package/lib/runners/git.runner.js +10 -0
- package/lib/runners/index.d.ts +3 -0
- package/lib/runners/index.js +19 -0
- package/lib/runners/npm.runner.d.ts +4 -0
- package/lib/runners/npm.runner.js +10 -0
- package/lib/runners/pnpm.runner.d.ts +4 -0
- package/lib/runners/pnpm.runner.js +10 -0
- package/lib/runners/runner.d.ts +6 -0
- package/lib/runners/runner.factory.d.ts +8 -0
- package/lib/runners/runner.factory.js +26 -0
- package/lib/runners/runner.js +10 -0
- package/lib/runners/schematic.runner.d.ts +6 -0
- package/lib/runners/schematic.runner.js +21 -0
- package/lib/runners/yarn.runner.d.ts +4 -0
- package/lib/runners/yarn.runner.js +10 -0
- package/lib/schematics/abstract.collection.d.ts +12 -0
- package/lib/schematics/abstract.collection.js +23 -0
- package/lib/schematics/collection.d.ts +3 -0
- package/lib/schematics/collection.factory.d.ts +5 -0
- package/lib/schematics/collection.factory.js +19 -0
- package/lib/schematics/collection.js +7 -0
- package/lib/schematics/custom.collection.d.ts +10 -0
- package/lib/schematics/custom.collection.js +33 -0
- package/lib/schematics/index.d.ts +4 -0
- package/lib/schematics/index.js +20 -0
- package/lib/schematics/nest.collection.d.ts +15 -0
- package/lib/schematics/nest.collection.js +126 -0
- package/lib/schematics/schematic.option.d.ts +8 -0
- package/lib/schematics/schematic.option.js +44 -0
- package/lib/ui/banner.d.ts +1 -0
- package/lib/ui/banner.js +12 -0
- package/lib/ui/emojis.d.ts +19 -0
- package/lib/ui/emojis.js +23 -0
- package/lib/ui/errors.d.ts +4 -0
- package/lib/ui/errors.js +8 -0
- package/lib/ui/index.d.ts +5 -0
- package/lib/ui/index.js +21 -0
- package/lib/ui/messages.d.ts +24 -0
- package/lib/ui/messages.js +32 -0
- package/lib/ui/prefixes.d.ts +2 -0
- package/lib/ui/prefixes.js +6 -0
- package/lib/utils/formatting.d.ts +8 -0
- package/lib/utils/formatting.js +18 -0
- package/lib/utils/get-default-tsconfig-path.d.ts +1 -0
- package/lib/utils/get-default-tsconfig-path.js +12 -0
- package/lib/utils/gracefully-exit-on-prompt-error.d.ts +1 -0
- package/lib/utils/gracefully-exit-on-prompt-error.js +11 -0
- package/lib/utils/is-module-available.d.ts +1 -0
- package/lib/utils/is-module-available.js +12 -0
- package/lib/utils/load-configuration.d.ts +2 -0
- package/lib/utils/load-configuration.js +9 -0
- package/lib/utils/local-binaries.d.ts +3 -0
- package/lib/utils/local-binaries.js +15 -0
- package/lib/utils/os-info.utils.d.ts +1 -0
- package/lib/utils/os-info.utils.js +23 -0
- package/lib/utils/project-utils.d.ts +11 -0
- package/lib/utils/project-utils.js +83 -0
- package/lib/utils/remaining-flags.d.ts +2 -0
- package/lib/utils/remaining-flags.js +36 -0
- package/lib/utils/tree-kill.d.ts +1 -0
- package/lib/utils/tree-kill.js +68 -0
- package/lib/utils/type-assertions.d.ts +1 -0
- package/lib/utils/type-assertions.js +8 -0
- package/package.json +161 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsconfigPathsBeforeHookFactory = tsconfigPathsBeforeHookFactory;
|
|
4
|
+
const os = require("os");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const typescript_loader_1 = require("../typescript-loader");
|
|
7
|
+
const tsPaths = require("tsconfig-paths");
|
|
8
|
+
function tsconfigPathsBeforeHookFactory(compilerOptions) {
|
|
9
|
+
const tsBinary = new typescript_loader_1.TypeScriptBinaryLoader().load();
|
|
10
|
+
const { paths = {}, baseUrl = './' } = compilerOptions;
|
|
11
|
+
const matcher = tsPaths.createMatchPath(baseUrl, paths, ['main']);
|
|
12
|
+
return (ctx) => {
|
|
13
|
+
return (sf) => {
|
|
14
|
+
const visitNode = (node) => {
|
|
15
|
+
if (tsBinary.isImportDeclaration(node) ||
|
|
16
|
+
(tsBinary.isExportDeclaration(node) && node.moduleSpecifier)) {
|
|
17
|
+
try {
|
|
18
|
+
const importPathWithQuotes = node.moduleSpecifier && node.moduleSpecifier.getText();
|
|
19
|
+
if (!importPathWithQuotes) {
|
|
20
|
+
return node;
|
|
21
|
+
}
|
|
22
|
+
const text = importPathWithQuotes.substring(1, importPathWithQuotes.length - 1);
|
|
23
|
+
const result = getNotAliasedPath(sf, matcher, text);
|
|
24
|
+
if (!result) {
|
|
25
|
+
return node;
|
|
26
|
+
}
|
|
27
|
+
const moduleSpecifier = tsBinary.factory.createStringLiteral(result);
|
|
28
|
+
moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
29
|
+
if (tsBinary.isImportDeclaration(node)) {
|
|
30
|
+
const updatedNode = tsBinary.factory.updateImportDeclaration(node, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
31
|
+
updatedNode.flags = node.flags;
|
|
32
|
+
return updatedNode;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const updatedNode = tsBinary.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
36
|
+
updatedNode.flags = node.flags;
|
|
37
|
+
return updatedNode;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return node;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return tsBinary.visitEachChild(node, visitNode, ctx);
|
|
45
|
+
};
|
|
46
|
+
return tsBinary.visitNode(sf, visitNode);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getNotAliasedPath(sf, matcher, text) {
|
|
51
|
+
let result = matcher(text, undefined, undefined, [
|
|
52
|
+
'.ts',
|
|
53
|
+
'.tsx',
|
|
54
|
+
'.js',
|
|
55
|
+
'.jsx',
|
|
56
|
+
]);
|
|
57
|
+
if (!result) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (os.platform() === 'win32') {
|
|
61
|
+
result = result.replace(/\\/g, '/');
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
// Installed packages (node modules) should take precedence over root files with the same name.
|
|
65
|
+
// Ref: https://github.com/nestjs/nest-cli/issues/838
|
|
66
|
+
const packagePath = require.resolve(text, {
|
|
67
|
+
paths: [process.cwd(), ...module.paths],
|
|
68
|
+
});
|
|
69
|
+
if (packagePath) {
|
|
70
|
+
return text;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch { }
|
|
74
|
+
const resolvedPath = path_1.posix.relative((0, path_1.dirname)(sf.fileName), result) || './';
|
|
75
|
+
return resolvedPath[0] === '.' ? resolvedPath : './' + resolvedPath;
|
|
76
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
typeImports: Record<string, string>;
|
|
8
|
+
visit(program: unknown, sf: unknown): unknown;
|
|
9
|
+
collect(): Record<string, Array<unknown>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { ReadonlyVisitor } from '../interfaces/readonly-visitor.interface';
|
|
3
|
+
export interface PluginMetadataGenerateOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The visitors to use to generate the metadata.
|
|
6
|
+
*/
|
|
7
|
+
visitors: ReadonlyVisitor[];
|
|
8
|
+
/**
|
|
9
|
+
* The output directory to write the metadata to.
|
|
10
|
+
*/
|
|
11
|
+
outputDir: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to watch the project for changes.
|
|
14
|
+
*/
|
|
15
|
+
watch?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The path to the tsconfig file.
|
|
18
|
+
* Relative to the current working directory (process.cwd()).
|
|
19
|
+
*/
|
|
20
|
+
tsconfigPath?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The filename to write the metadata to.
|
|
23
|
+
*/
|
|
24
|
+
filename?: string;
|
|
25
|
+
/**
|
|
26
|
+
* A reference to an existing ts.Program instance.
|
|
27
|
+
*/
|
|
28
|
+
tsProgramRef?: ts.Program;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to print diagnostics to the console.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
printDiagnostics?: boolean;
|
|
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
|
+
*/
|
|
50
|
+
export declare class PluginMetadataGenerator {
|
|
51
|
+
private readonly pluginMetadataPrinter;
|
|
52
|
+
private readonly typeCheckerHost;
|
|
53
|
+
private readonly typescriptLoader;
|
|
54
|
+
private readonly tsBinary;
|
|
55
|
+
constructor();
|
|
56
|
+
generate(options: PluginMetadataGenerateOptions): void;
|
|
57
|
+
private traverseAndPrintMetadata;
|
|
58
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginMetadataGenerator = void 0;
|
|
4
|
+
const constants_1 = require("../swc/constants");
|
|
5
|
+
const type_checker_host_1 = require("../swc/type-checker-host");
|
|
6
|
+
const typescript_loader_1 = require("../typescript-loader");
|
|
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
|
+
*/
|
|
23
|
+
class PluginMetadataGenerator {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.pluginMetadataPrinter = new plugin_metadata_printer_1.PluginMetadataPrinter();
|
|
26
|
+
this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
|
|
27
|
+
this.typescriptLoader = new typescript_loader_1.TypeScriptBinaryLoader();
|
|
28
|
+
this.tsBinary = this.typescriptLoader.load();
|
|
29
|
+
}
|
|
30
|
+
generate(options) {
|
|
31
|
+
const { tsconfigPath, visitors, tsProgramRef, outputDir, watch, filename, printDiagnostics = true, } = options;
|
|
32
|
+
if (visitors.length === 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (tsProgramRef) {
|
|
36
|
+
return this.traverseAndPrintMetadata(tsProgramRef, visitors, outputDir, filename);
|
|
37
|
+
}
|
|
38
|
+
const onTypeCheckOrProgramInit = (program) => {
|
|
39
|
+
this.traverseAndPrintMetadata(program, visitors, outputDir, filename);
|
|
40
|
+
if (printDiagnostics) {
|
|
41
|
+
const tsBinary = this.typescriptLoader.load();
|
|
42
|
+
const diagnostics = tsBinary.getPreEmitDiagnostics(program);
|
|
43
|
+
if (diagnostics.length > 0) {
|
|
44
|
+
const formatDiagnosticsHost = {
|
|
45
|
+
getCanonicalFileName: (path) => path,
|
|
46
|
+
getCurrentDirectory: tsBinary.sys.getCurrentDirectory,
|
|
47
|
+
getNewLine: () => tsBinary.sys.newLine,
|
|
48
|
+
};
|
|
49
|
+
console.log();
|
|
50
|
+
console.log(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.typeCheckerHost.run(tsconfigPath, {
|
|
58
|
+
watch,
|
|
59
|
+
onTypeCheck: onTypeCheckOrProgramInit,
|
|
60
|
+
onProgramInit: onTypeCheckOrProgramInit,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
traverseAndPrintMetadata(programRef, visitors, outputDir, filename) {
|
|
64
|
+
for (const sourceFile of programRef.getSourceFiles()) {
|
|
65
|
+
if (!sourceFile.isDeclarationFile) {
|
|
66
|
+
visitors.forEach((visitor) => visitor.visit(programRef, sourceFile));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
let typeImports = {};
|
|
70
|
+
const collectedMetadata = {};
|
|
71
|
+
visitors.forEach((visitor) => {
|
|
72
|
+
collectedMetadata[visitor.key] = visitor.collect();
|
|
73
|
+
typeImports = {
|
|
74
|
+
...typeImports,
|
|
75
|
+
...visitor.typeImports,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
this.pluginMetadataPrinter.print(collectedMetadata, typeImports, {
|
|
79
|
+
outputDir,
|
|
80
|
+
filename,
|
|
81
|
+
}, this.tsBinary);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.PluginMetadataGenerator = PluginMetadataGenerator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { DeepPluginMeta } from '../interfaces/readonly-visitor.interface';
|
|
3
|
+
export interface PluginMetadataPrintOptions {
|
|
4
|
+
outputDir: string;
|
|
5
|
+
filename?: string;
|
|
6
|
+
}
|
|
7
|
+
type ComposedPluginMeta = Record<string, Record<string, Array<[ts.CallExpression, DeepPluginMeta]>>>;
|
|
8
|
+
/**
|
|
9
|
+
* Prints the metadata to a file.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PluginMetadataPrinter {
|
|
12
|
+
print(metadata: ComposedPluginMeta, typeImports: Record<string, string>, options: PluginMetadataPrintOptions, tsBinary: typeof ts): void;
|
|
13
|
+
private recursivelyCreatePropertyAssignment;
|
|
14
|
+
private createTypeImportVariableStatement;
|
|
15
|
+
private createPropertyAssignment;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
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 SERIALIZED_METADATA_FILENAME = 'metadata.ts';
|
|
7
|
+
const TYPE_IMPORT_VARIABLE_NAME = 't';
|
|
8
|
+
/**
|
|
9
|
+
* Prints the metadata to a file.
|
|
10
|
+
*/
|
|
11
|
+
class PluginMetadataPrinter {
|
|
12
|
+
print(metadata, typeImports, options, tsBinary) {
|
|
13
|
+
const objectLiteralExpr = tsBinary.factory.createObjectLiteralExpression(Object.keys(metadata).map((key) => this.recursivelyCreatePropertyAssignment(key, metadata[key], tsBinary)));
|
|
14
|
+
const exportAssignment = tsBinary.factory.createExportAssignment(undefined, undefined, tsBinary.factory.createArrowFunction([tsBinary.factory.createToken(tsBinary.SyntaxKind.AsyncKeyword)], undefined, [], undefined, tsBinary.factory.createToken(tsBinary.SyntaxKind.EqualsGreaterThanToken), tsBinary.factory.createBlock([
|
|
15
|
+
this.createTypeImportVariableStatement(typeImports, tsBinary),
|
|
16
|
+
tsBinary.factory.createReturnStatement(objectLiteralExpr),
|
|
17
|
+
], true)));
|
|
18
|
+
const printer = tsBinary.createPrinter({
|
|
19
|
+
newLine: tsBinary.NewLineKind.LineFeed,
|
|
20
|
+
});
|
|
21
|
+
const resultFile = tsBinary.createSourceFile('file.ts', '', tsBinary.ScriptTarget.Latest,
|
|
22
|
+
/*setParentNodes*/ false, tsBinary.ScriptKind.TS);
|
|
23
|
+
const filename = (0, path_1.join)(options.outputDir, options.filename ?? SERIALIZED_METADATA_FILENAME);
|
|
24
|
+
const eslintPrefix = `/* eslint-disable */\n`;
|
|
25
|
+
(0, fs_1.writeFileSync)(filename, eslintPrefix +
|
|
26
|
+
printer.printNode(tsBinary.EmitHint.Unspecified, exportAssignment, resultFile));
|
|
27
|
+
}
|
|
28
|
+
recursivelyCreatePropertyAssignment(identifier, meta, tsBinary) {
|
|
29
|
+
if (Array.isArray(meta)) {
|
|
30
|
+
return tsBinary.factory.createPropertyAssignment(tsBinary.factory.createStringLiteral(identifier), tsBinary.factory.createArrayLiteralExpression(meta.map(([importExpr, meta]) => tsBinary.factory.createArrayLiteralExpression([
|
|
31
|
+
importExpr,
|
|
32
|
+
tsBinary.factory.createObjectLiteralExpression(Object.keys(meta).map((key) => this.recursivelyCreatePropertyAssignment(key, meta[key], tsBinary))),
|
|
33
|
+
]))));
|
|
34
|
+
}
|
|
35
|
+
return tsBinary.factory.createPropertyAssignment(tsBinary.factory.createStringLiteral(identifier), tsBinary.isObjectLiteralExpression(meta)
|
|
36
|
+
? meta
|
|
37
|
+
: tsBinary.factory.createObjectLiteralExpression(Object.keys(meta).map((key) => this.recursivelyCreatePropertyAssignment(key, meta[key], tsBinary))));
|
|
38
|
+
}
|
|
39
|
+
createTypeImportVariableStatement(typeImports, tsBinary) {
|
|
40
|
+
return tsBinary.factory.createVariableStatement(undefined, tsBinary.factory.createVariableDeclarationList([
|
|
41
|
+
tsBinary.factory.createVariableDeclaration(tsBinary.factory.createIdentifier(TYPE_IMPORT_VARIABLE_NAME), undefined, undefined, tsBinary.factory.createObjectLiteralExpression(Object.keys(typeImports).map((ti) => this.createPropertyAssignment(ti, typeImports[ti], tsBinary)), true)),
|
|
42
|
+
], tsBinary.NodeFlags.Const |
|
|
43
|
+
tsBinary.NodeFlags.AwaitContext |
|
|
44
|
+
tsBinary.NodeFlags.ContextFlags |
|
|
45
|
+
tsBinary.NodeFlags.TypeExcludesFlags));
|
|
46
|
+
}
|
|
47
|
+
createPropertyAssignment(identifier, target, tsBinary) {
|
|
48
|
+
return tsBinary.factory.createPropertyAssignment(tsBinary.factory.createComputedPropertyName(tsBinary.factory.createStringLiteral(identifier)), tsBinary.factory.createIdentifier(target));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
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 {};
|
|
@@ -0,0 +1,70 @@
|
|
|
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({
|
|
37
|
+
...options,
|
|
38
|
+
...extras,
|
|
39
|
+
readonly: true,
|
|
40
|
+
});
|
|
41
|
+
instance.key = pluginNames[index];
|
|
42
|
+
multiCompilerPlugins.readonlyVisitors.push(instance);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return multiCompilerPlugins;
|
|
46
|
+
}
|
|
47
|
+
resolvePluginReferences(pluginNames) {
|
|
48
|
+
const nodeModulePaths = [
|
|
49
|
+
(0, path_1.join)(process.cwd(), 'node_modules'),
|
|
50
|
+
...module.paths,
|
|
51
|
+
];
|
|
52
|
+
return pluginNames.map((item) => {
|
|
53
|
+
try {
|
|
54
|
+
try {
|
|
55
|
+
const binaryPath = require.resolve((0, path_1.join)(item, PLUGIN_ENTRY_FILENAME), {
|
|
56
|
+
paths: nodeModulePaths,
|
|
57
|
+
});
|
|
58
|
+
return require(binaryPath);
|
|
59
|
+
}
|
|
60
|
+
catch { }
|
|
61
|
+
const binaryPath = require.resolve(item, { paths: nodeModulePaths });
|
|
62
|
+
return require(binaryPath);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
throw new Error(`"${item}" plugin is not installed.`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
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,13 @@
|
|
|
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 ansis_1 = require("ansis");
|
|
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 = (0, ansis_1.cyan)('> ') + ansis_1.bgCyan.bold(' SWC ');
|
|
8
|
+
exports.TSC_LOG_PREFIX = (0, ansis_1.cyan)('> ') + ansis_1.bgCyan.bold(' TSC ');
|
|
9
|
+
exports.TSC_LOG_ERROR_PREFIX = (0, ansis_1.red)('> ') + ansis_1.bgRed.bold(' TSC ');
|
|
10
|
+
exports.TSC_LOG_SUCCESS_PREFIX = (0, ansis_1.green)('> ') + ansis_1.bgGreen.bold(' TSC ');
|
|
11
|
+
exports.INITIALIZING_TYPE_CHECKER = ansis_1.bgCyan.bold(' TSC ') + (0, ansis_1.cyan)(' Initializing type checker...');
|
|
12
|
+
exports.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED = exports.TSC_LOG_SUCCESS_PREFIX + (0, ansis_1.green)(' Found 0 issues.');
|
|
13
|
+
exports.FOUND_NO_ISSUES_GENERATING_METADATA = exports.TSC_LOG_SUCCESS_PREFIX + (0, ansis_1.green)(' Found 0 issues. Generating metadata...');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ui_1 = require("../../ui");
|
|
4
|
+
const base_compiler_1 = require("../base-compiler");
|
|
5
|
+
const plugin_metadata_generator_1 = require("../plugins/plugin-metadata-generator");
|
|
6
|
+
const plugins_loader_1 = require("../plugins/plugins-loader");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const type_checker_host_1 = require("./type-checker-host");
|
|
9
|
+
const [tsConfigPath, appName, sourceRoot, plugins] = process.argv.slice(2);
|
|
10
|
+
class ForkedTypeChecker extends base_compiler_1.BaseCompiler {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.pluginMetadataGenerator = new plugin_metadata_generator_1.PluginMetadataGenerator();
|
|
14
|
+
this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
|
|
15
|
+
}
|
|
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
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const pluginsLoader = new plugins_loader_1.PluginsLoader();
|
|
45
|
+
const forkedTypeChecker = new ForkedTypeChecker(pluginsLoader);
|
|
46
|
+
const applicationName = appName === 'undefined' ? '' : appName;
|
|
47
|
+
const options = {
|
|
48
|
+
sourceRoot,
|
|
49
|
+
};
|
|
50
|
+
if (applicationName) {
|
|
51
|
+
options.projects = {};
|
|
52
|
+
options.projects[applicationName] = {
|
|
53
|
+
compilerOptions: {
|
|
54
|
+
plugins: JSON.parse(plugins),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
options.compilerOptions = {
|
|
60
|
+
plugins: JSON.parse(plugins),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
forkedTypeChecker.run(options, tsConfigPath, applicationName, { watch: true, typeCheck: true });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { Configuration } from '../../configuration';
|
|
3
|
+
import { AssetsManager } from '../assets-manager';
|
|
4
|
+
import { BaseCompiler } from '../base-compiler';
|
|
5
|
+
import { PluginsLoader } from '../plugins/plugins-loader';
|
|
6
|
+
export type SwcCompilerExtras = {
|
|
7
|
+
watch: boolean;
|
|
8
|
+
typeCheck: boolean;
|
|
9
|
+
assetsManager: AssetsManager;
|
|
10
|
+
tsOptions: ts.CompilerOptions;
|
|
11
|
+
};
|
|
12
|
+
export declare class SwcCompiler extends BaseCompiler {
|
|
13
|
+
private readonly pluginMetadataGenerator;
|
|
14
|
+
private readonly typeCheckerHost;
|
|
15
|
+
constructor(pluginsLoader: PluginsLoader);
|
|
16
|
+
run(configuration: Required<Configuration>, tsConfigPath: string, appName: string | undefined, extras: SwcCompilerExtras, onSuccess?: () => void): Promise<void>;
|
|
17
|
+
private runTypeChecker;
|
|
18
|
+
private runSwc;
|
|
19
|
+
private loadSwcCliBinary;
|
|
20
|
+
private getSwcRcFileContentIfExists;
|
|
21
|
+
private deepMerge;
|
|
22
|
+
private debounce;
|
|
23
|
+
private watchFilesInSrcDir;
|
|
24
|
+
private watchFilesInOutDir;
|
|
25
|
+
}
|