@gadmin2n/cli 0.0.73
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 +62 -0
- package/.claude/settings.local.json +7 -0
- package/.github/ISSUE_TEMPLATE/Bug_report.yml +106 -0
- package/.github/ISSUE_TEMPLATE/Feature_request.yml +52 -0
- package/.github/ISSUE_TEMPLATE/Regression.yml +78 -0
- package/.github/ISSUE_TEMPLATE/config.yml +7 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +41 -0
- package/LICENSE +24 -0
- package/README.md +56 -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 +129 -0
- package/actions/build.action.d.ts +27 -0
- package/actions/build.action.js +108 -0
- package/actions/generate.action.d.ts +5 -0
- package/actions/generate.action.js +95 -0
- package/actions/index.d.ts +8 -0
- package/actions/index.js +24 -0
- package/actions/info.action.d.ts +28 -0
- package/actions/info.action.js +129 -0
- package/actions/new.action.d.ts +7 -0
- package/actions/new.action.js +294 -0
- package/actions/prisma.action.d.ts +5 -0
- package/actions/prisma.action.js +153 -0
- package/actions/start.action.d.ts +9 -0
- package/actions/start.action.js +115 -0
- package/actions/update.action.d.ts +5 -0
- package/actions/update.action.js +26 -0
- package/bin/gadmin.d.ts +2 -0
- package/bin/gadmin.js +25 -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 +43 -0
- package/commands/build.command.d.ts +5 -0
- package/commands/build.command.js +50 -0
- package/commands/command.input.d.ts +25 -0
- package/commands/command.input.js +28 -0
- package/commands/command.loader.d.ts +5 -0
- package/commands/command.loader.js +33 -0
- package/commands/generate.command.d.ts +7 -0
- package/commands/generate.command.js +105 -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 +25 -0
- package/commands/new.command.d.ts +5 -0
- package/commands/new.command.js +52 -0
- package/commands/start.command.d.ts +5 -0
- package/commands/start.command.js +64 -0
- package/commands/update.command.d.ts +5 -0
- package/commands/update.command.js +30 -0
- package/lib/compiler/assets-manager.d.ts +15 -0
- package/lib/compiler/assets-manager.js +103 -0
- package/lib/compiler/compiler.d.ts +12 -0
- package/lib/compiler/compiler.js +60 -0
- package/lib/compiler/defaults/webpack-defaults.d.ts +3 -0
- package/lib/compiler/defaults/webpack-defaults.js +95 -0
- package/lib/compiler/helpers/append-extension.d.ts +1 -0
- package/lib/compiler/helpers/append-extension.js +8 -0
- package/lib/compiler/helpers/copy-path-resolve.d.ts +7 -0
- package/lib/compiler/helpers/copy-path-resolve.js +26 -0
- package/lib/compiler/helpers/get-value-or-default.d.ts +4 -0
- package/lib/compiler/helpers/get-value-or-default.js +67 -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 +70 -0
- package/lib/compiler/plugins-loader.d.ts +21 -0
- package/lib/compiler/plugins-loader.js +54 -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 +14 -0
- package/lib/compiler/watch-compiler.js +70 -0
- package/lib/compiler/webpack-compiler.d.ts +9 -0
- package/lib/compiler/webpack-compiler.js +74 -0
- package/lib/compiler/workspace-utils.d.ts +4 -0
- package/lib/compiler/workspace-utils.js +26 -0
- package/lib/configuration/configuration.d.ts +52 -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 +4 -0
- package/lib/configuration/defaults.js +56 -0
- package/lib/configuration/gadmin-configuration.loader.d.ts +8 -0
- package/lib/configuration/gadmin-configuration.loader.js +39 -0
- package/lib/configuration/index.d.ts +3 -0
- package/lib/configuration/index.js +19 -0
- package/lib/dependency-managers/index.d.ts +1 -0
- package/lib/dependency-managers/index.js +17 -0
- package/lib/dependency-managers/nest.dependency-manager.d.ts +7 -0
- package/lib/dependency-managers/nest.dependency-manager.js +48 -0
- package/lib/package-managers/abstract.package-manager.d.ts +25 -0
- package/lib/package-managers/abstract.package-manager.js +185 -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 +54 -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 +2 -0
- package/lib/questions/questions.js +23 -0
- package/lib/readers/file-system.reader.d.ts +8 -0
- package/lib/readers/file-system.reader.js +61 -0
- package/lib/readers/index.d.ts +2 -0
- package/lib/readers/index.js +18 -0
- package/lib/readers/reader.d.ts +5 -0
- package/lib/readers/reader.js +2 -0
- package/lib/runners/abstract.runner.d.ts +11 -0
- package/lib/runners/abstract.runner.js +55 -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 +10 -0
- package/lib/schematics/abstract.collection.js +34 -0
- package/lib/schematics/collection.d.ts +3 -0
- package/lib/schematics/collection.factory.d.ts +5 -0
- package/lib/schematics/collection.factory.js +18 -0
- package/lib/schematics/collection.js +7 -0
- package/lib/schematics/custom.collection.d.ts +3 -0
- package/lib/schematics/custom.collection.js +7 -0
- package/lib/schematics/gadmin.collection.d.ts +16 -0
- package/lib/schematics/gadmin.collection.js +142 -0
- package/lib/schematics/index.d.ts +4 -0
- package/lib/schematics/index.js +20 -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 +11 -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 +26 -0
- package/lib/ui/messages.js +34 -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 +19 -0
- package/lib/utils/is-error.d.ts +1 -0
- package/lib/utils/is-error.js +11 -0
- package/lib/utils/load-configuration.d.ts +2 -0
- package/lib/utils/load-configuration.js +21 -0
- package/lib/utils/local-binaries.d.ts +3 -0
- package/lib/utils/local-binaries.js +16 -0
- package/lib/utils/project-utils.d.ts +8 -0
- package/lib/utils/project-utils.js +69 -0
- package/lib/utils/remaining-flags.d.ts +2 -0
- package/lib/utils/remaining-flags.js +37 -0
- package/lib/utils/tree-kill.d.ts +1 -0
- package/lib/utils/tree-kill.js +66 -0
- package/package.json +105 -0
- package/test/lib/compiler/hooks/__snapshots__/tsconfig-paths.hook.spec.ts.snap +68 -0
- package/test/lib/compiler/hooks/fixtures/aliased-imports/src/bar.tsx +1 -0
- package/test/lib/compiler/hooks/fixtures/aliased-imports/src/baz.js +1 -0
- package/test/lib/compiler/hooks/fixtures/aliased-imports/src/qux.jsx +1 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssetsManager = void 0;
|
|
4
|
+
const chokidar = require("chokidar");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const shell = require("shelljs");
|
|
7
|
+
const copy_path_resolve_1 = require("./helpers/copy-path-resolve");
|
|
8
|
+
const get_value_or_default_1 = require("./helpers/get-value-or-default");
|
|
9
|
+
class AssetsManager {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.watchAssetsKeyValue = {};
|
|
12
|
+
this.watchers = [];
|
|
13
|
+
this.actionInProgress = false;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Using on `nest build` to close file watch or the build process will not end
|
|
17
|
+
* Interval like process
|
|
18
|
+
* If no action has been taken recently close watchers
|
|
19
|
+
* If action has been taken recently flag and try again
|
|
20
|
+
*/
|
|
21
|
+
closeWatchers() {
|
|
22
|
+
// Consider adjusting this for larger files
|
|
23
|
+
const timeoutMs = 500;
|
|
24
|
+
const closeFn = () => {
|
|
25
|
+
if (this.actionInProgress) {
|
|
26
|
+
this.actionInProgress = false;
|
|
27
|
+
setTimeout(closeFn, timeoutMs);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.watchers.forEach((watcher) => watcher.close());
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
setTimeout(closeFn, timeoutMs);
|
|
34
|
+
}
|
|
35
|
+
copyAssets(configuration, appName, outDir, watchAssetsMode) {
|
|
36
|
+
const assets = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.assets', appName) || [];
|
|
37
|
+
if (assets.length <= 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
let sourceRoot = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'sourceRoot', appName);
|
|
42
|
+
sourceRoot = (0, path_1.join)(process.cwd(), sourceRoot);
|
|
43
|
+
const filesToCopy = assets.map((item) => {
|
|
44
|
+
if (typeof item === 'string') {
|
|
45
|
+
return {
|
|
46
|
+
glob: (0, path_1.join)(sourceRoot, item),
|
|
47
|
+
outDir,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
outDir: item.outDir || outDir,
|
|
52
|
+
glob: (0, path_1.join)(sourceRoot, item.include),
|
|
53
|
+
exclude: item.exclude ? (0, path_1.join)(sourceRoot, item.exclude) : undefined,
|
|
54
|
+
flat: item.flat,
|
|
55
|
+
watchAssets: item.watchAssets,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
const isWatchEnabled = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.watchAssets', appName) || watchAssetsMode;
|
|
59
|
+
for (const item of filesToCopy) {
|
|
60
|
+
const option = {
|
|
61
|
+
action: 'change',
|
|
62
|
+
item,
|
|
63
|
+
path: '',
|
|
64
|
+
sourceRoot,
|
|
65
|
+
watchAssetsMode: isWatchEnabled,
|
|
66
|
+
};
|
|
67
|
+
// prettier-ignore
|
|
68
|
+
const watcher = chokidar
|
|
69
|
+
.watch(item.glob, { ignored: item.exclude })
|
|
70
|
+
.on('add', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'change' })))
|
|
71
|
+
.on('change', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'change' })))
|
|
72
|
+
.on('unlink', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'unlink' })));
|
|
73
|
+
this.watchers.push(watcher);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
throw new Error(`An error occurred during the assets copying process. ${err.message}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
actionOnFile(option) {
|
|
81
|
+
const { action, item, path, sourceRoot, watchAssetsMode } = option;
|
|
82
|
+
const isWatchEnabled = watchAssetsMode || item.watchAssets;
|
|
83
|
+
// Allow to do action for the first time before check watchMode
|
|
84
|
+
if (!isWatchEnabled && this.watchAssetsKeyValue[path]) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Set path value to true for watching the first time
|
|
88
|
+
this.watchAssetsKeyValue[path] = true;
|
|
89
|
+
// Set action to true to avoid watches getting cutoff
|
|
90
|
+
this.actionInProgress = true;
|
|
91
|
+
const dest = (0, copy_path_resolve_1.copyPathResolve)(path, item.outDir, sourceRoot.split(path_1.sep).length);
|
|
92
|
+
// Copy to output dir if file is changed or added
|
|
93
|
+
if (action === 'change') {
|
|
94
|
+
shell.mkdir('-p', (0, path_1.dirname)(dest));
|
|
95
|
+
shell.cp(path, dest);
|
|
96
|
+
}
|
|
97
|
+
else if (action === 'unlink') {
|
|
98
|
+
// Remove from output dir if file is deleted
|
|
99
|
+
shell.rm(dest);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.AssetsManager = AssetsManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Configuration } from '../configuration';
|
|
2
|
+
import { TsConfigProvider } from './helpers/tsconfig-provider';
|
|
3
|
+
import { PluginsLoader } from './plugins-loader';
|
|
4
|
+
import { TypeScriptBinaryLoader } from './typescript-loader';
|
|
5
|
+
export declare class Compiler {
|
|
6
|
+
private readonly pluginsLoader;
|
|
7
|
+
private readonly tsConfigProvider;
|
|
8
|
+
private readonly typescriptLoader;
|
|
9
|
+
constructor(pluginsLoader: PluginsLoader, tsConfigProvider: TsConfigProvider, typescriptLoader: TypeScriptBinaryLoader);
|
|
10
|
+
run(configuration: Required<Configuration>, configFilename: string, appName: string, onSuccess?: () => void): void;
|
|
11
|
+
private reportAfterCompilationDiagnostic;
|
|
12
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Compiler = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
const get_value_or_default_1 = require("./helpers/get-value-or-default");
|
|
6
|
+
const tsconfig_paths_hook_1 = require("./hooks/tsconfig-paths.hook");
|
|
7
|
+
class Compiler {
|
|
8
|
+
constructor(pluginsLoader, tsConfigProvider, typescriptLoader) {
|
|
9
|
+
this.pluginsLoader = pluginsLoader;
|
|
10
|
+
this.tsConfigProvider = tsConfigProvider;
|
|
11
|
+
this.typescriptLoader = typescriptLoader;
|
|
12
|
+
}
|
|
13
|
+
run(configuration, configFilename, appName, onSuccess) {
|
|
14
|
+
const tsBinary = this.typescriptLoader.load();
|
|
15
|
+
const formatHost = {
|
|
16
|
+
getCanonicalFileName: (path) => path,
|
|
17
|
+
getCurrentDirectory: tsBinary.sys.getCurrentDirectory,
|
|
18
|
+
getNewLine: () => tsBinary.sys.newLine,
|
|
19
|
+
};
|
|
20
|
+
const { options, fileNames, projectReferences } = this.tsConfigProvider.getByConfigFilename(configFilename);
|
|
21
|
+
const createProgram = tsBinary.createIncrementalProgram || tsBinary.createProgram;
|
|
22
|
+
const program = createProgram.call(ts, {
|
|
23
|
+
rootNames: fileNames,
|
|
24
|
+
projectReferences,
|
|
25
|
+
options,
|
|
26
|
+
});
|
|
27
|
+
const pluginsConfig = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.plugins', appName);
|
|
28
|
+
const plugins = this.pluginsLoader.load(pluginsConfig);
|
|
29
|
+
const tsconfigPathsPlugin = (0, tsconfig_paths_hook_1.tsconfigPathsBeforeHookFactory)(options);
|
|
30
|
+
const programRef = program.getProgram
|
|
31
|
+
? program.getProgram()
|
|
32
|
+
: program;
|
|
33
|
+
const before = plugins.beforeHooks.map((hook) => hook(programRef));
|
|
34
|
+
const after = plugins.afterHooks.map((hook) => hook(programRef));
|
|
35
|
+
const afterDeclarations = plugins.afterDeclarationsHooks.map((hook) => hook(programRef));
|
|
36
|
+
const emitResult = program.emit(undefined, undefined, undefined, undefined, {
|
|
37
|
+
before: before.concat(tsconfigPathsPlugin),
|
|
38
|
+
after,
|
|
39
|
+
afterDeclarations,
|
|
40
|
+
});
|
|
41
|
+
const errorsCount = this.reportAfterCompilationDiagnostic(program, emitResult, tsBinary, formatHost);
|
|
42
|
+
if (errorsCount) {
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
else if (!errorsCount && onSuccess) {
|
|
46
|
+
onSuccess();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
reportAfterCompilationDiagnostic(program, emitResult, tsBinary, formatHost) {
|
|
50
|
+
const diagnostics = tsBinary
|
|
51
|
+
.getPreEmitDiagnostics(program)
|
|
52
|
+
.concat(emitResult.diagnostics);
|
|
53
|
+
if (diagnostics.length > 0) {
|
|
54
|
+
console.error(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatHost));
|
|
55
|
+
console.info(`Found ${diagnostics.length} error(s).` + tsBinary.sys.newLine);
|
|
56
|
+
}
|
|
57
|
+
return diagnostics.length;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Compiler = Compiler;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MultiNestCompilerPlugins } from '../plugins-loader';
|
|
2
|
+
import webpack = require('webpack');
|
|
3
|
+
export declare const webpackDefaultsFactory: (sourceRoot: string, relativeSourceRoot: string, entryFilename: string, isDebugEnabled: boolean | undefined, tsConfigFile: string | undefined, plugins: MultiNestCompilerPlugins) => webpack.Configuration;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webpackDefaultsFactory = void 0;
|
|
4
|
+
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
|
|
7
|
+
const defaults_1 = require("../../configuration/defaults");
|
|
8
|
+
const append_extension_1 = require("../helpers/append-extension");
|
|
9
|
+
const webpack = require("webpack");
|
|
10
|
+
const nodeExternals = require("webpack-node-externals");
|
|
11
|
+
const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, isDebugEnabled = false, tsConfigFile = defaults_1.defaultConfiguration.compilerOptions.tsConfigPath, plugins) => ({
|
|
12
|
+
entry: (0, append_extension_1.appendTsExtension)((0, path_1.join)(sourceRoot, entryFilename)),
|
|
13
|
+
devtool: isDebugEnabled ? 'inline-source-map' : false,
|
|
14
|
+
target: 'node',
|
|
15
|
+
output: {
|
|
16
|
+
filename: (0, path_1.join)(relativeSourceRoot, `${entryFilename}.js`),
|
|
17
|
+
},
|
|
18
|
+
ignoreWarnings: [/^(?!CriticalDependenciesWarning$)/],
|
|
19
|
+
externals: [nodeExternals()],
|
|
20
|
+
externalsPresets: { node: true },
|
|
21
|
+
module: {
|
|
22
|
+
rules: [
|
|
23
|
+
{
|
|
24
|
+
test: /.tsx?$/,
|
|
25
|
+
use: [
|
|
26
|
+
{
|
|
27
|
+
loader: 'ts-loader',
|
|
28
|
+
options: {
|
|
29
|
+
transpileOnly: !isAnyPluginRegistered(plugins),
|
|
30
|
+
configFile: tsConfigFile,
|
|
31
|
+
getCustomTransformers: (program) => ({
|
|
32
|
+
before: plugins.beforeHooks.map((hook) => hook(program)),
|
|
33
|
+
after: plugins.afterHooks.map((hook) => hook(program)),
|
|
34
|
+
afterDeclarations: plugins.afterDeclarationsHooks.map((hook) => hook(program)),
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
exclude: /node_modules/,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
resolve: {
|
|
44
|
+
extensions: ['.tsx', '.ts', '.js'],
|
|
45
|
+
plugins: [
|
|
46
|
+
new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({
|
|
47
|
+
configFile: tsConfigFile,
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
mode: 'none',
|
|
52
|
+
optimization: {
|
|
53
|
+
nodeEnv: false,
|
|
54
|
+
},
|
|
55
|
+
node: {
|
|
56
|
+
__filename: false,
|
|
57
|
+
__dirname: false,
|
|
58
|
+
},
|
|
59
|
+
plugins: [
|
|
60
|
+
new webpack.IgnorePlugin({
|
|
61
|
+
checkResource(resource) {
|
|
62
|
+
const lazyImports = [
|
|
63
|
+
'@nestjs/microservices',
|
|
64
|
+
'cache-manager',
|
|
65
|
+
'class-validator',
|
|
66
|
+
'class-transformer',
|
|
67
|
+
];
|
|
68
|
+
if (!lazyImports.includes(resource)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
require.resolve(resource, {
|
|
73
|
+
paths: [process.cwd()],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
new ForkTsCheckerWebpackPlugin({
|
|
83
|
+
typescript: {
|
|
84
|
+
configFile: tsConfigFile,
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
exports.webpackDefaultsFactory = webpackDefaultsFactory;
|
|
90
|
+
function isAnyPluginRegistered(plugins) {
|
|
91
|
+
return ((plugins.afterHooks && plugins.afterHooks.length > 0) ||
|
|
92
|
+
(plugins.beforeHooks && plugins.beforeHooks.length > 0) ||
|
|
93
|
+
(plugins.afterDeclarationsHooks &&
|
|
94
|
+
plugins.afterDeclarationsHooks.length > 0));
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function appendTsExtension(path: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.appendTsExtension = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
function appendTsExtension(path) {
|
|
6
|
+
return (0, path_1.extname)(path) === '.ts' ? path : path + '.ts';
|
|
7
|
+
}
|
|
8
|
+
exports.appendTsExtension = appendTsExtension;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function for returning a copy destination filename
|
|
3
|
+
*
|
|
4
|
+
* @description used in `assets-manager.ts` (copy from `copyfiles`)
|
|
5
|
+
* @see https://github.com/calvinmetcalf/copyfiles/blob/master/index.js#L22
|
|
6
|
+
*/
|
|
7
|
+
export declare function copyPathResolve(filePath: string, outDir: string, up: number): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyPathResolve = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
/**
|
|
6
|
+
* Helper function for returning a copy destination filename
|
|
7
|
+
*
|
|
8
|
+
* @description used in `assets-manager.ts` (copy from `copyfiles`)
|
|
9
|
+
* @see https://github.com/calvinmetcalf/copyfiles/blob/master/index.js#L22
|
|
10
|
+
*/
|
|
11
|
+
function copyPathResolve(filePath, outDir, up) {
|
|
12
|
+
return path.join(outDir, dealWith(filePath, up));
|
|
13
|
+
}
|
|
14
|
+
exports.copyPathResolve = copyPathResolve;
|
|
15
|
+
function dealWith(inPath, up) {
|
|
16
|
+
if (!up) {
|
|
17
|
+
return inPath;
|
|
18
|
+
}
|
|
19
|
+
if (depth(inPath) < up) {
|
|
20
|
+
throw new Error('cant go up that far');
|
|
21
|
+
}
|
|
22
|
+
return path.join(...path.normalize(inPath).split(path.sep).slice(up));
|
|
23
|
+
}
|
|
24
|
+
function depth(string) {
|
|
25
|
+
return path.normalize(string).split(path.sep).length - 1;
|
|
26
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Input } from '../../../commands';
|
|
2
|
+
import { Configuration } from '../../configuration';
|
|
3
|
+
export declare function getValueOrDefault<T = any>(configuration: Required<Configuration>, propertyPath: string, appName: string, key?: 'path' | 'webpack' | 'webpackPath', options?: Input[], defaultValue?: T): T;
|
|
4
|
+
export declare function getValueOfPath<T = any>(object: Record<string, any>, propertyPath: string): T;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValueOfPath = exports.getValueOrDefault = void 0;
|
|
4
|
+
function getValueOrDefault(configuration, propertyPath, appName, key, options = [], defaultValue) {
|
|
5
|
+
const item = options.find((option) => option.name === key);
|
|
6
|
+
const origValue = item && item.value;
|
|
7
|
+
if (origValue !== undefined && origValue !== null) {
|
|
8
|
+
return origValue;
|
|
9
|
+
}
|
|
10
|
+
if (configuration.projects && configuration.projects[appName]) {
|
|
11
|
+
// Wrap the application name in double-quotes to prevent splitting it
|
|
12
|
+
// into separate chunks
|
|
13
|
+
appName = appName && !appName.includes('"') ? `"${appName}"` : appName;
|
|
14
|
+
const perAppValue = getValueOfPath(configuration, `projects.${appName}.`.concat(propertyPath));
|
|
15
|
+
if (perAppValue !== undefined) {
|
|
16
|
+
return perAppValue;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let value = getValueOfPath(configuration, propertyPath);
|
|
20
|
+
if (value === undefined) {
|
|
21
|
+
value = defaultValue;
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
exports.getValueOrDefault = getValueOrDefault;
|
|
26
|
+
function getValueOfPath(object, propertyPath) {
|
|
27
|
+
const fragments = propertyPath.split('.');
|
|
28
|
+
let propertyValue = object;
|
|
29
|
+
let isConcatInProgress = false;
|
|
30
|
+
let path = '';
|
|
31
|
+
for (const fragment of fragments) {
|
|
32
|
+
if (!propertyValue) {
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* When path is escaped with "" double quotes,
|
|
37
|
+
* concatenate the property path.
|
|
38
|
+
* Reference: https://github.com/nestjs/nest-cli/issues/947
|
|
39
|
+
*/
|
|
40
|
+
if (fragment.startsWith('"') && fragment.endsWith('"')) {
|
|
41
|
+
path = stripDoubleQuotes(fragment);
|
|
42
|
+
}
|
|
43
|
+
else if (fragment.startsWith('"')) {
|
|
44
|
+
path += stripDoubleQuotes(fragment) + '.';
|
|
45
|
+
isConcatInProgress = true;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
else if (isConcatInProgress && !fragment.endsWith('"')) {
|
|
49
|
+
path += fragment + '.';
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
else if (fragment.endsWith('"')) {
|
|
53
|
+
path += stripDoubleQuotes(fragment);
|
|
54
|
+
isConcatInProgress = false;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
path = fragment;
|
|
58
|
+
}
|
|
59
|
+
propertyValue = propertyValue[path];
|
|
60
|
+
path = '';
|
|
61
|
+
}
|
|
62
|
+
return propertyValue;
|
|
63
|
+
}
|
|
64
|
+
exports.getValueOfPath = getValueOfPath;
|
|
65
|
+
function stripDoubleQuotes(text) {
|
|
66
|
+
return text.replace(/"/g, '');
|
|
67
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { TypeScriptBinaryLoader } from '../typescript-loader';
|
|
3
|
+
export declare class TsConfigProvider {
|
|
4
|
+
private readonly typescriptLoader;
|
|
5
|
+
constructor(typescriptLoader: TypeScriptBinaryLoader);
|
|
6
|
+
getByConfigFilename(configFilename: string): {
|
|
7
|
+
options: ts.CompilerOptions;
|
|
8
|
+
fileNames: string[];
|
|
9
|
+
projectReferences: readonly ts.ProjectReference[] | undefined;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TsConfigProvider = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const ui_1 = require("../../ui");
|
|
7
|
+
class TsConfigProvider {
|
|
8
|
+
constructor(typescriptLoader) {
|
|
9
|
+
this.typescriptLoader = typescriptLoader;
|
|
10
|
+
}
|
|
11
|
+
getByConfigFilename(configFilename) {
|
|
12
|
+
const configPath = (0, path_1.join)(process.cwd(), configFilename);
|
|
13
|
+
if (!(0, fs_1.existsSync)(configPath)) {
|
|
14
|
+
throw new Error(ui_1.CLI_ERRORS.MISSING_TYPESCRIPT(configFilename));
|
|
15
|
+
}
|
|
16
|
+
const tsBinary = this.typescriptLoader.load();
|
|
17
|
+
const parsedCmd = tsBinary.getParsedCommandLineOfConfigFile(configPath, undefined, tsBinary.sys);
|
|
18
|
+
const { options, fileNames, projectReferences } = parsedCmd;
|
|
19
|
+
return { options, fileNames, projectReferences };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.TsConfigProvider = TsConfigProvider;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tsconfigPathsBeforeHookFactory = void 0;
|
|
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 newNode = tsBinary.getMutableClone(node);
|
|
19
|
+
const importPathWithQuotes = node.moduleSpecifier && node.moduleSpecifier.getText();
|
|
20
|
+
if (!importPathWithQuotes) {
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
const text = importPathWithQuotes.substr(1, importPathWithQuotes.length - 2);
|
|
24
|
+
const result = getNotAliasedPath(sf, matcher, text);
|
|
25
|
+
if (!result) {
|
|
26
|
+
return node;
|
|
27
|
+
}
|
|
28
|
+
newNode.moduleSpecifier = tsBinary.createLiteral(result);
|
|
29
|
+
newNode.moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
30
|
+
newNode.flags = node.flags;
|
|
31
|
+
return newNode;
|
|
32
|
+
}
|
|
33
|
+
catch (_a) {
|
|
34
|
+
return node;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return tsBinary.visitEachChild(node, visitNode, ctx);
|
|
38
|
+
};
|
|
39
|
+
return tsBinary.visitNode(sf, visitNode);
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.tsconfigPathsBeforeHookFactory = tsconfigPathsBeforeHookFactory;
|
|
44
|
+
function getNotAliasedPath(sf, matcher, text) {
|
|
45
|
+
let result = matcher(text, undefined, undefined, [
|
|
46
|
+
'.ts',
|
|
47
|
+
'.tsx',
|
|
48
|
+
'.js',
|
|
49
|
+
'.jsx',
|
|
50
|
+
]);
|
|
51
|
+
if (!result) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (os.platform() === 'win32') {
|
|
55
|
+
result = result.replace(/\\/g, '/');
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
// Installed packages (node modules) should take precedence over root files with the same name.
|
|
59
|
+
// Ref: https://github.com/nestjs/nest-cli/issues/838
|
|
60
|
+
const packagePath = require.resolve(text, {
|
|
61
|
+
paths: [process.cwd(), ...module.paths],
|
|
62
|
+
});
|
|
63
|
+
if (packagePath) {
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (_a) { }
|
|
68
|
+
const resolvedPath = path_1.posix.relative((0, path_1.dirname)(sf.fileName), result) || './';
|
|
69
|
+
return resolvedPath[0] === '.' ? resolvedPath : './' + resolvedPath;
|
|
70
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
declare type Transformer = ts.TransformerFactory<any> | ts.CustomTransformerFactory;
|
|
3
|
+
declare type PluginEntry = string | PluginAndOptions;
|
|
4
|
+
interface PluginAndOptions {
|
|
5
|
+
name: 'string';
|
|
6
|
+
options: Record<string, any>;
|
|
7
|
+
}
|
|
8
|
+
export interface NestCompilerPlugin {
|
|
9
|
+
before?: (options?: Record<string, any>, program?: ts.Program) => Transformer;
|
|
10
|
+
after?: (options?: Record<string, any>, program?: ts.Program) => Transformer;
|
|
11
|
+
afterDeclarations?: (options?: Record<string, any>, program?: ts.Program) => Transformer;
|
|
12
|
+
}
|
|
13
|
+
export interface MultiNestCompilerPlugins {
|
|
14
|
+
beforeHooks: Array<(program?: ts.Program) => Transformer>;
|
|
15
|
+
afterHooks: Array<(program?: ts.Program) => Transformer>;
|
|
16
|
+
afterDeclarationsHooks: Array<(program?: ts.Program) => Transformer>;
|
|
17
|
+
}
|
|
18
|
+
export declare class PluginsLoader {
|
|
19
|
+
load(plugins?: PluginEntry[]): MultiNestCompilerPlugins;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginsLoader = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const util_1 = require("util");
|
|
6
|
+
const ui_1 = require("../ui");
|
|
7
|
+
const PLUGIN_ENTRY_FILENAME = 'plugin';
|
|
8
|
+
class PluginsLoader {
|
|
9
|
+
load(plugins = []) {
|
|
10
|
+
const pluginNames = plugins.map((entry) => (0, util_1.isObject)(entry) ? entry.name : entry);
|
|
11
|
+
const nodeModulePaths = [
|
|
12
|
+
(0, path_1.join)(process.cwd(), 'node_modules'),
|
|
13
|
+
...module.paths,
|
|
14
|
+
];
|
|
15
|
+
const pluginRefs = pluginNames.map((item) => {
|
|
16
|
+
try {
|
|
17
|
+
try {
|
|
18
|
+
const binaryPath = require.resolve((0, path_1.join)(item, PLUGIN_ENTRY_FILENAME), {
|
|
19
|
+
paths: nodeModulePaths,
|
|
20
|
+
});
|
|
21
|
+
return require(binaryPath);
|
|
22
|
+
}
|
|
23
|
+
catch (_a) { }
|
|
24
|
+
const binaryPath = require.resolve(item, { paths: nodeModulePaths });
|
|
25
|
+
return require(binaryPath);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
throw new Error(`"${item}" plugin could not be found!`);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const beforeHooks = [];
|
|
32
|
+
const afterHooks = [];
|
|
33
|
+
const afterDeclarationsHooks = [];
|
|
34
|
+
pluginRefs.forEach((plugin, index) => {
|
|
35
|
+
if (!plugin.before && !plugin.after && !plugin.afterDeclarations) {
|
|
36
|
+
throw new Error(ui_1.CLI_ERRORS.WRONG_PLUGIN(pluginNames[index]));
|
|
37
|
+
}
|
|
38
|
+
const options = (0, util_1.isObject)(plugins[index])
|
|
39
|
+
? plugins[index].options || {}
|
|
40
|
+
: {};
|
|
41
|
+
plugin.before &&
|
|
42
|
+
beforeHooks.push(plugin.before.bind(plugin.before, options));
|
|
43
|
+
plugin.after && afterHooks.push(plugin.after.bind(plugin.after, options));
|
|
44
|
+
plugin.afterDeclarations &&
|
|
45
|
+
afterDeclarationsHooks.push(plugin.afterDeclarations.bind(plugin.afterDeclarations, options));
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
beforeHooks,
|
|
49
|
+
afterHooks,
|
|
50
|
+
afterDeclarationsHooks,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.PluginsLoader = PluginsLoader;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeScriptBinaryLoader = void 0;
|
|
4
|
+
class TypeScriptBinaryLoader {
|
|
5
|
+
load() {
|
|
6
|
+
if (this.tsBinary) {
|
|
7
|
+
return this.tsBinary;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const tsBinaryPath = require.resolve('typescript', {
|
|
11
|
+
paths: [process.cwd(), ...this.getModulePaths()],
|
|
12
|
+
});
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
+
const tsBinary = require(tsBinaryPath);
|
|
15
|
+
this.tsBinary = tsBinary;
|
|
16
|
+
return tsBinary;
|
|
17
|
+
}
|
|
18
|
+
catch (_a) {
|
|
19
|
+
throw new Error('TypeScript could not be found! Please, install "typescript" package.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getModulePaths() {
|
|
23
|
+
const modulePaths = module.paths.slice(2, module.paths.length);
|
|
24
|
+
const packageDeps = modulePaths.slice(0, 3);
|
|
25
|
+
return [
|
|
26
|
+
...packageDeps.reverse(),
|
|
27
|
+
...modulePaths.slice(3, modulePaths.length).reverse(),
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.TypeScriptBinaryLoader = TypeScriptBinaryLoader;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { Configuration } from '../configuration';
|
|
3
|
+
import { TsConfigProvider } from './helpers/tsconfig-provider';
|
|
4
|
+
import { PluginsLoader } from './plugins-loader';
|
|
5
|
+
import { TypeScriptBinaryLoader } from './typescript-loader';
|
|
6
|
+
export declare class WatchCompiler {
|
|
7
|
+
private readonly pluginsLoader;
|
|
8
|
+
private readonly tsConfigProvider;
|
|
9
|
+
private readonly typescriptLoader;
|
|
10
|
+
constructor(pluginsLoader: PluginsLoader, tsConfigProvider: TsConfigProvider, typescriptLoader: TypeScriptBinaryLoader);
|
|
11
|
+
run(configuration: Required<Configuration>, configFilename: string, appName: string, tsCompilerOptions: ts.CompilerOptions, onSuccess?: () => void): void;
|
|
12
|
+
private createDiagnosticReporter;
|
|
13
|
+
private createWatchStatusChanged;
|
|
14
|
+
}
|