@depup/nestjs__cli 11.0.24-depup.8 → 12.0.0-depup.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/README.md +6 -14
- package/actions/abstract.action.d.ts +1 -2
- package/actions/abstract.action.js +1 -5
- package/actions/add.action.d.ts +3 -4
- package/actions/add.action.js +44 -53
- package/actions/build.action.d.ts +18 -11
- package/actions/build.action.js +172 -79
- package/actions/deploy.action.d.ts +6 -0
- package/actions/deploy.action.js +51 -0
- package/actions/generate.action.d.ts +3 -3
- package/actions/generate.action.js +61 -59
- package/actions/index.d.ts +9 -7
- package/actions/index.js +9 -23
- package/actions/info.action.d.ts +18 -28
- package/actions/info.action.js +80 -60
- package/actions/new.action.d.ts +3 -3
- package/actions/new.action.js +108 -104
- package/actions/start.action.d.ts +4 -7
- package/actions/start.action.js +40 -47
- package/actions/upgrade.action.d.ts +6 -0
- package/actions/upgrade.action.js +53 -0
- package/bin/nest.js +11 -10
- package/changes.json +6 -38
- package/commands/abstract.command.d.ts +3 -3
- package/commands/abstract.command.js +2 -5
- package/commands/add.command.d.ts +3 -3
- package/commands/add.command.js +17 -20
- package/commands/build.command.d.ts +3 -3
- package/commands/build.command.js +52 -56
- package/commands/command.input.js +1 -2
- package/commands/command.loader.d.ts +2 -2
- package/commands/command.loader.js +29 -22
- package/commands/context/add.context.d.ts +7 -0
- package/commands/context/add.context.js +1 -0
- package/commands/context/build.context.d.ts +17 -0
- package/commands/context/build.context.js +1 -0
- package/commands/context/deploy.context.d.ts +7 -0
- package/commands/context/deploy.context.js +1 -0
- package/commands/context/generate.context.d.ts +18 -0
- package/commands/context/generate.context.js +1 -0
- package/commands/context/index.d.ts +7 -0
- package/commands/context/index.js +7 -0
- package/commands/context/new.context.d.ts +19 -0
- package/commands/context/new.context.js +1 -0
- package/commands/context/start.context.d.ts +22 -0
- package/commands/context/start.context.js +1 -0
- package/commands/context/upgrade.context.d.ts +11 -0
- package/commands/context/upgrade.context.js +1 -0
- package/commands/deploy.command.d.ts +5 -0
- package/commands/deploy.command.js +22 -0
- package/commands/generate.command.d.ts +3 -3
- package/commands/generate.command.js +35 -66
- package/commands/index.d.ts +3 -2
- package/commands/index.js +3 -18
- package/commands/info.command.d.ts +3 -3
- package/commands/info.command.js +4 -8
- package/commands/new.command.d.ts +3 -3
- package/commands/new.command.js +34 -36
- package/commands/start.command.d.ts +3 -3
- package/commands/start.command.js +48 -73
- package/commands/upgrade.command.d.ts +5 -0
- package/commands/upgrade.command.js +32 -0
- package/lib/compiler/assets-manager.d.ts +20 -8
- package/lib/compiler/assets-manager.js +199 -63
- package/lib/compiler/base-compiler.d.ts +5 -5
- package/lib/compiler/base-compiler.js +10 -13
- package/lib/compiler/compiler.d.ts +6 -6
- package/lib/compiler/compiler.js +7 -9
- package/lib/compiler/defaults/rspack-defaults.d.ts +3 -0
- package/lib/compiler/defaults/rspack-defaults.js +179 -0
- package/lib/compiler/defaults/swc-defaults.d.ts +5 -2
- package/lib/compiler/defaults/swc-defaults.js +22 -6
- package/lib/compiler/defaults/webpack-defaults.d.ts +2 -2
- package/lib/compiler/defaults/webpack-defaults.js +59 -19
- package/lib/compiler/helpers/append-extension.js +3 -6
- package/lib/compiler/helpers/copy-path-resolve.js +2 -5
- package/lib/compiler/helpers/delete-out-dir.d.ts +1 -1
- package/lib/compiler/helpers/delete-out-dir.js +45 -10
- package/lib/compiler/helpers/get-builder.d.ts +9 -7
- package/lib/compiler/helpers/get-builder.js +3 -6
- package/lib/compiler/helpers/get-effective-root-dir.d.ts +16 -0
- package/lib/compiler/helpers/get-effective-root-dir.js +56 -0
- package/lib/compiler/helpers/get-rspack-config-path.d.ts +10 -0
- package/lib/compiler/helpers/get-rspack-config-path.js +19 -0
- package/lib/compiler/helpers/get-tsc-config.path.d.ts +2 -3
- package/lib/compiler/helpers/get-tsc-config.path.js +6 -9
- package/lib/compiler/helpers/get-value-or-default.d.ts +2 -3
- package/lib/compiler/helpers/get-value-or-default.js +3 -8
- package/lib/compiler/helpers/get-webpack-config-path.d.ts +2 -3
- package/lib/compiler/helpers/get-webpack-config-path.js +4 -7
- package/lib/compiler/helpers/glob.d.ts +19 -0
- package/lib/compiler/helpers/glob.js +185 -0
- package/lib/compiler/helpers/manual-restart.js +4 -8
- package/lib/compiler/helpers/path-confinement.d.ts +33 -0
- package/lib/compiler/helpers/path-confinement.js +63 -0
- package/lib/compiler/helpers/tsconfig-provider.d.ts +7 -6
- package/lib/compiler/helpers/tsconfig-provider.js +32 -13
- package/lib/compiler/hooks/tsconfig-paths.hook.js +13 -13
- package/lib/compiler/interfaces/readonly-visitor.interface.js +1 -2
- package/lib/compiler/plugins/plugin-metadata-generator.d.ts +37 -1
- package/lib/compiler/plugins/plugin-metadata-generator.js +113 -13
- package/lib/compiler/plugins/plugin-metadata-printer.d.ts +1 -1
- package/lib/compiler/plugins/plugin-metadata-printer.js +5 -9
- package/lib/compiler/plugins/plugins-loader.d.ts +2 -2
- package/lib/compiler/plugins/plugins-loader.js +12 -12
- package/lib/compiler/rspack-compiler.d.ts +21 -0
- package/lib/compiler/rspack-compiler.js +111 -0
- package/lib/compiler/swc/constants.d.ts +0 -1
- package/lib/compiler/swc/constants.js +9 -13
- package/lib/compiler/swc/forked-type-checker.js +13 -18
- package/lib/compiler/swc/swc-compiler.d.ts +13 -6
- package/lib/compiler/swc/swc-compiler.js +116 -70
- package/lib/compiler/swc/type-checker-host.js +31 -24
- package/lib/compiler/typescript-loader.js +7 -9
- package/lib/compiler/watch-compiler.d.ts +5 -5
- package/lib/compiler/watch-compiler.js +13 -15
- package/lib/compiler/watchers/recursive-directory-watcher.d.ts +37 -0
- package/lib/compiler/watchers/recursive-directory-watcher.js +334 -0
- package/lib/compiler/webpack-compiler.d.ts +6 -7
- package/lib/compiler/webpack-compiler.js +46 -23
- package/lib/configuration/configuration.d.ts +16 -3
- package/lib/configuration/configuration.js +1 -2
- package/lib/configuration/configuration.loader.d.ts +1 -1
- package/lib/configuration/configuration.loader.js +1 -2
- package/lib/configuration/defaults.d.ts +2 -1
- package/lib/configuration/defaults.js +8 -10
- package/lib/configuration/index.d.ts +3 -3
- package/lib/configuration/index.js +3 -19
- package/lib/configuration/nest-configuration.loader.d.ts +3 -3
- package/lib/configuration/nest-configuration.loader.js +28 -29
- package/lib/package-managers/abstract.package-manager.d.ts +4 -4
- package/lib/package-managers/abstract.package-manager.js +21 -32
- package/lib/package-managers/bun.package-manager.d.ts +7 -0
- package/lib/package-managers/bun.package-manager.js +22 -0
- package/lib/package-managers/index.d.ts +9 -8
- package/lib/package-managers/index.js +9 -24
- package/lib/package-managers/npm.package-manager.d.ts +2 -2
- package/lib/package-managers/npm.package-manager.js +6 -10
- package/lib/package-managers/package-manager-commands.js +1 -2
- package/lib/package-managers/package-manager.d.ts +2 -1
- package/lib/package-managers/package-manager.factory.d.ts +2 -2
- package/lib/package-managers/package-manager.factory.js +23 -20
- package/lib/package-managers/package-manager.js +3 -5
- package/lib/package-managers/pnpm.package-manager.d.ts +2 -2
- package/lib/package-managers/pnpm.package-manager.js +6 -10
- package/lib/package-managers/project.dependency.js +1 -2
- package/lib/package-managers/yarn.package-manager.d.ts +2 -2
- package/lib/package-managers/yarn.package-manager.js +6 -10
- package/lib/questions/questions.d.ts +5 -1
- package/lib/questions/questions.js +2 -7
- package/lib/readers/file-system.reader.d.ts +1 -1
- package/lib/readers/file-system.reader.js +6 -9
- package/lib/readers/index.d.ts +2 -2
- package/lib/readers/index.js +2 -18
- package/lib/readers/reader.js +3 -5
- package/lib/runners/abstract.runner.js +40 -21
- package/lib/runners/bun.runner.d.ts +4 -0
- package/lib/runners/bun.runner.js +6 -0
- package/lib/runners/git.runner.d.ts +1 -1
- package/lib/runners/git.runner.js +2 -6
- package/lib/runners/index.d.ts +3 -3
- package/lib/runners/index.js +3 -19
- package/lib/runners/mau.runner.d.ts +8 -0
- package/lib/runners/mau.runner.js +10 -0
- package/lib/runners/npm.runner.d.ts +1 -1
- package/lib/runners/npm.runner.js +2 -6
- package/lib/runners/pnpm.runner.d.ts +1 -1
- package/lib/runners/pnpm.runner.js +2 -6
- package/lib/runners/runner.d.ts +2 -1
- package/lib/runners/runner.factory.d.ts +7 -6
- package/lib/runners/runner.factory.js +18 -20
- package/lib/runners/runner.js +3 -5
- package/lib/runners/schematic.runner.d.ts +1 -1
- package/lib/runners/schematic.runner.js +5 -7
- package/lib/runners/yarn.runner.d.ts +1 -1
- package/lib/runners/yarn.runner.js +2 -6
- package/lib/schematics/abstract.collection.d.ts +3 -3
- package/lib/schematics/abstract.collection.js +3 -5
- package/lib/schematics/collection.factory.d.ts +2 -2
- package/lib/schematics/collection.factory.js +9 -13
- package/lib/schematics/collection.js +2 -5
- package/lib/schematics/custom.collection.d.ts +2 -2
- package/lib/schematics/custom.collection.js +4 -8
- package/lib/schematics/index.d.ts +4 -4
- package/lib/schematics/index.js +4 -20
- package/lib/schematics/nest.collection.d.ts +3 -3
- package/lib/schematics/nest.collection.js +113 -109
- package/lib/schematics/schematic.option.js +10 -9
- package/lib/ui/banner.js +1 -4
- package/lib/ui/emojis.d.ts +17 -17
- package/lib/ui/emojis.js +19 -22
- package/lib/ui/errors.js +1 -4
- package/lib/ui/index.d.ts +5 -5
- package/lib/ui/index.js +5 -21
- package/lib/ui/messages.d.ts +8 -0
- package/lib/ui/messages.js +23 -18
- package/lib/ui/prefixes.js +3 -6
- package/lib/utils/extra-args-warning.js +3 -6
- package/lib/utils/formatting.js +1 -4
- package/lib/utils/get-default-tsconfig-path.js +4 -7
- package/lib/utils/gracefully-exit-on-prompt-error.js +1 -4
- package/lib/utils/is-esm-project.d.ts +5 -0
- package/lib/utils/is-esm-project.js +16 -0
- package/lib/utils/is-interactive.d.ts +8 -0
- package/lib/utils/is-interactive.js +10 -0
- package/lib/utils/is-module-available.js +3 -4
- package/lib/utils/load-configuration.d.ts +1 -1
- package/lib/utils/load-configuration.js +4 -7
- package/lib/utils/local-binaries.d.ts +2 -2
- package/lib/utils/local-binaries.js +8 -11
- package/lib/utils/mau.d.ts +14 -0
- package/lib/utils/mau.js +46 -0
- package/lib/utils/os-info.utils.js +1 -4
- package/lib/utils/project-utils.d.ts +1 -3
- package/lib/utils/project-utils.js +16 -28
- package/lib/utils/remaining-flags.d.ts +2 -2
- package/lib/utils/remaining-flags.js +13 -8
- package/lib/utils/tree-kill.js +7 -10
- package/lib/utils/type-assertions.js +1 -4
- package/package.json +64 -77
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.swcDefaultsFactory = void 0;
|
|
4
|
-
const swcDefaultsFactory = (tsOptions, configuration) => {
|
|
1
|
+
export const swcDefaultsFactory = (tsOptions, configuration, tsConfigExclude = []) => {
|
|
5
2
|
const builderOptions = typeof configuration?.compilerOptions?.builder !== 'string'
|
|
6
3
|
? configuration?.compilerOptions?.builder?.options
|
|
7
4
|
: {};
|
|
@@ -37,14 +34,33 @@ const swcDefaultsFactory = (tsOptions, configuration) => {
|
|
|
37
34
|
extensions: ['.js', '.ts'],
|
|
38
35
|
copyFiles: false,
|
|
39
36
|
includeDotfiles: false,
|
|
37
|
+
ignore: tsConfigExclude.length ? tsConfigExclude : undefined,
|
|
40
38
|
quiet: false,
|
|
41
39
|
watch: false,
|
|
42
|
-
stripLeadingPaths:
|
|
40
|
+
stripLeadingPaths: shouldStripLeadingPaths(tsOptions?.rootDir, configuration?.sourceRoot ?? 'src'),
|
|
43
41
|
...builderOptions,
|
|
44
42
|
},
|
|
45
43
|
};
|
|
46
44
|
};
|
|
47
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Mirrors tsc's output layout: tsc flattens the source directory out of the
|
|
47
|
+
* output when its (effective) rootDir is the source root, so swc must strip
|
|
48
|
+
* leading paths in the same cases — no rootDir configured (tsc infers the
|
|
49
|
+
* common source directory), or a rootDir that points at the source root
|
|
50
|
+
* (relative or resolved absolute). A rootDir above the source root (e.g. '.')
|
|
51
|
+
* keeps the source directory in the output, so nothing is stripped.
|
|
52
|
+
*/
|
|
53
|
+
function shouldStripLeadingPaths(rootDir, sourceRoot) {
|
|
54
|
+
if (!rootDir) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
const normalizedRootDir = convertPath(rootDir).replace(/\/+$/, '');
|
|
58
|
+
const normalizedSourceRoot = convertPath(sourceRoot)
|
|
59
|
+
.replace(/^\.\//, '')
|
|
60
|
+
.replace(/\/+$/, '');
|
|
61
|
+
return (normalizedRootDir === normalizedSourceRoot ||
|
|
62
|
+
normalizedRootDir.endsWith(`/${normalizedSourceRoot}`));
|
|
63
|
+
}
|
|
48
64
|
/**
|
|
49
65
|
* Converts Windows specific file paths to posix
|
|
50
66
|
* @param windowsPath
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import type webpack from 'webpack';
|
|
2
|
+
import { MultiNestCompilerPlugins } from '../plugins/plugins-loader.js';
|
|
3
3
|
export declare const webpackDefaultsFactory: (sourceRoot: string, relativeSourceRoot: string, entryFilename: string, isDebugEnabled: boolean | undefined, tsConfigFile: string | undefined, plugins: MultiNestCompilerPlugins) => webpack.Configuration;
|
|
@@ -1,23 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { defaultTsconfigFilename } from '../../configuration/defaults.js';
|
|
5
|
+
import { appendTsExtension } from '../helpers/append-extension.js';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a `require` of an optional webpack dependency so a missing package
|
|
9
|
+
* reports the install command instead of a raw MODULE_NOT_FOUND. Every
|
|
10
|
+
* optional webpack dependency must be loaded through here — they are declared
|
|
11
|
+
* as optional peers, so any unguarded `require` surfaces as a bare crash.
|
|
12
|
+
*/
|
|
13
|
+
function withInstallAdvice(load) {
|
|
14
|
+
try {
|
|
15
|
+
return load();
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
if (e?.code !== 'MODULE_NOT_FOUND' && e?.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
19
|
+
// Only the "package missing" branch is wrapped with install advice.
|
|
20
|
+
// Surfacing unrelated errors as "package not found" would mislead
|
|
21
|
+
// users into reinstalling perfectly valid dependencies.
|
|
22
|
+
throw e;
|
|
23
|
+
}
|
|
24
|
+
// Use a non-greedy match so error messages that contain multiple
|
|
25
|
+
// quoted paths (e.g. ESM "Cannot find package 'foo' imported from
|
|
26
|
+
// '/abs/path.mjs'") still extract the package name rather than the
|
|
27
|
+
// importing file path.
|
|
28
|
+
const pkg = e?.message?.match?.(/Cannot find.*?'([^']+)'/)?.[1] ?? 'webpack';
|
|
29
|
+
throw new Error(`The "${pkg}" package is required when using the webpack compiler but could not be found. ` +
|
|
30
|
+
`Please install it:\n\n npm install --save-dev webpack webpack-node-externals tsconfig-paths-webpack-plugin ts-loader fork-ts-checker-webpack-plugin\n`, { cause: e });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function loadWebpackDeps() {
|
|
34
|
+
return withInstallAdvice(() => {
|
|
35
|
+
const wp = require('webpack');
|
|
36
|
+
const externals = require('webpack-node-externals');
|
|
37
|
+
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
|
|
38
|
+
return { webpack: wp, nodeExternals: externals, TsconfigPathsPlugin };
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function getBaseUrl(tsConfigFile) {
|
|
42
|
+
try {
|
|
43
|
+
const { compilerOptions } = JSON.parse(readFileSync(tsConfigFile, 'utf8'));
|
|
44
|
+
return compilerOptions?.baseUrl ?? '.';
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return '.';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, isDebugEnabled = false, tsConfigFile = defaultTsconfigFilename, plugins) => {
|
|
51
|
+
const { webpack: wp, nodeExternals: externals, TsconfigPathsPlugin, } = loadWebpackDeps();
|
|
11
52
|
const isPluginRegistered = isAnyPluginRegistered(plugins);
|
|
12
53
|
const webpackConfiguration = {
|
|
13
|
-
entry:
|
|
54
|
+
entry: appendTsExtension(join(sourceRoot, entryFilename)),
|
|
14
55
|
devtool: isDebugEnabled ? 'inline-source-map' : false,
|
|
15
56
|
target: 'node',
|
|
16
57
|
output: {
|
|
17
|
-
filename:
|
|
58
|
+
filename: join(relativeSourceRoot, `${entryFilename}.js`).replace(/\\/g, '/'),
|
|
18
59
|
},
|
|
19
60
|
ignoreWarnings: [/^(?!CriticalDependenciesWarning$)/],
|
|
20
|
-
externals: [
|
|
61
|
+
externals: [externals()],
|
|
21
62
|
externalsPresets: { node: true },
|
|
22
63
|
module: {
|
|
23
64
|
rules: [
|
|
@@ -44,8 +85,9 @@ const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, i
|
|
|
44
85
|
resolve: {
|
|
45
86
|
extensions: ['.tsx', '.ts', '.js'],
|
|
46
87
|
plugins: [
|
|
47
|
-
new
|
|
88
|
+
new TsconfigPathsPlugin({
|
|
48
89
|
configFile: tsConfigFile,
|
|
90
|
+
baseUrl: getBaseUrl(tsConfigFile),
|
|
49
91
|
}),
|
|
50
92
|
],
|
|
51
93
|
},
|
|
@@ -58,7 +100,7 @@ const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, i
|
|
|
58
100
|
__dirname: false,
|
|
59
101
|
},
|
|
60
102
|
plugins: [
|
|
61
|
-
new
|
|
103
|
+
new wp.IgnorePlugin({
|
|
62
104
|
checkResource(resource) {
|
|
63
105
|
const lazyImports = [
|
|
64
106
|
'@nestjs/microservices',
|
|
@@ -76,7 +118,7 @@ const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, i
|
|
|
76
118
|
paths: [process.cwd()],
|
|
77
119
|
});
|
|
78
120
|
}
|
|
79
|
-
catch
|
|
121
|
+
catch {
|
|
80
122
|
return true;
|
|
81
123
|
}
|
|
82
124
|
return false;
|
|
@@ -85,8 +127,7 @@ const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, i
|
|
|
85
127
|
],
|
|
86
128
|
};
|
|
87
129
|
if (!isPluginRegistered) {
|
|
88
|
-
|
|
89
|
-
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
130
|
+
const ForkTsCheckerWebpackPlugin = withInstallAdvice(() => require('fork-ts-checker-webpack-plugin'));
|
|
90
131
|
webpackConfiguration.plugins.push(new ForkTsCheckerWebpackPlugin({
|
|
91
132
|
typescript: {
|
|
92
133
|
configFile: tsConfigFile,
|
|
@@ -95,7 +136,6 @@ const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, i
|
|
|
95
136
|
}
|
|
96
137
|
return webpackConfiguration;
|
|
97
138
|
};
|
|
98
|
-
exports.webpackDefaultsFactory = webpackDefaultsFactory;
|
|
99
139
|
function isAnyPluginRegistered(plugins) {
|
|
100
140
|
return ((plugins.afterHooks && plugins.afterHooks.length > 0) ||
|
|
101
141
|
(plugins.beforeHooks && plugins.beforeHooks.length > 0) ||
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
function appendTsExtension(path) {
|
|
6
|
-
return (0, path_1.extname)(path) === '.ts' ? path : path + '.ts';
|
|
1
|
+
import { extname } from 'path';
|
|
2
|
+
export function appendTsExtension(path) {
|
|
3
|
+
return extname(path) === '.ts' ? path : path + '.ts';
|
|
7
4
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.copyPathResolve = copyPathResolve;
|
|
4
|
-
const path = require("path");
|
|
1
|
+
import * as path from 'path';
|
|
5
2
|
/**
|
|
6
3
|
* Helper function for returning a copy destination filename
|
|
7
4
|
*
|
|
8
5
|
* @description used in `assets-manager.ts` (copy from `copyfiles`)
|
|
9
6
|
* @see https://github.com/calvinmetcalf/copyfiles/blob/master/index.js#L22
|
|
10
7
|
*/
|
|
11
|
-
function copyPathResolve(filePath, outDir, up) {
|
|
8
|
+
export function copyPathResolve(filePath, outDir, up) {
|
|
12
9
|
return path.join(outDir, dealWith(filePath, up));
|
|
13
10
|
}
|
|
14
11
|
function dealWith(inPath, up) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import { Configuration } from '../../configuration';
|
|
2
|
+
import { Configuration } from '../../configuration/index.js';
|
|
3
3
|
export declare function deleteOutDirIfEnabled(configuration: Required<Configuration>, appName: string | undefined, dirPath: string, tsOptions?: ts.CompilerOptions): Promise<void>;
|
|
@@ -1,15 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { rm } from 'fs/promises';
|
|
2
|
+
import * as ts from 'typescript';
|
|
3
|
+
import { getValueOrDefault } from './get-value-or-default.js';
|
|
4
|
+
import { areOutsidePathsAllowed, assertPathInsideProject, } from './path-confinement.js';
|
|
5
|
+
/**
|
|
6
|
+
* A recursive delete is not atomic: it walks the tree, and anything created
|
|
7
|
+
* between the "readdir" of a directory and its "rmdir" makes the removal fail
|
|
8
|
+
* with ENOTEMPTY. Concurrent writers into "outDir" are common in monorepos
|
|
9
|
+
* (a sibling "tsc --noEmit --incremental" dropping its buildinfo there, for
|
|
10
|
+
* instance), which turns "deleteOutDir" into a flaky build. Node already
|
|
11
|
+
* treats ENOTEMPTY - along with EBUSY, EMFILE, ENFILE and EPERM, the errors
|
|
12
|
+
* Windows raises for a file another process still holds - as retryable, but
|
|
13
|
+
* only retries when "maxRetries" is set; it defaults to 0.
|
|
14
|
+
*
|
|
15
|
+
* See https://github.com/nestjs/nest-cli/issues/3509
|
|
16
|
+
*/
|
|
17
|
+
const RM_MAX_RETRIES = 3;
|
|
18
|
+
export async function deleteOutDirIfEnabled(configuration, appName, dirPath, tsOptions) {
|
|
19
|
+
const isDeleteEnabled = getValueOrDefault(configuration, 'compilerOptions.deleteOutDir', appName);
|
|
8
20
|
if (!isDeleteEnabled) {
|
|
9
21
|
return;
|
|
10
22
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
const shouldValidate = !areOutsidePathsAllowed(configuration, appName);
|
|
24
|
+
// With "incremental" enabled but no explicit "tsBuildInfoFile", TypeScript
|
|
25
|
+
// derives a default location that can fall outside "outDir" (with "outDir"
|
|
26
|
+
// and "rootDir" both set, "tsconfig.build.tsbuildinfo" lands next to the
|
|
27
|
+
// tsconfig), so the recursive delete below would leave it behind. Reuse the
|
|
28
|
+
// compiler's own resolution to remove the buildinfo wherever it actually is.
|
|
29
|
+
const tsBuildInfoFile = tsOptions &&
|
|
30
|
+
(tsOptions.tsBuildInfoFile ?? ts.getTsBuildInfoEmitOutputFilePath(tsOptions));
|
|
31
|
+
// Both paths are validated before anything is removed, so that a rejected
|
|
32
|
+
// "tsBuildInfoFile" cannot leave a half-deleted output directory behind.
|
|
33
|
+
const outDirToDelete = shouldValidate
|
|
34
|
+
? assertPathInsideProject(dirPath, 'outDir')
|
|
35
|
+
: dirPath;
|
|
36
|
+
const tsBuildInfoFileToDelete = shouldValidate && tsBuildInfoFile
|
|
37
|
+
? assertPathInsideProject(tsBuildInfoFile, 'tsBuildInfoFile')
|
|
38
|
+
: tsBuildInfoFile;
|
|
39
|
+
await rm(outDirToDelete, {
|
|
40
|
+
recursive: true,
|
|
41
|
+
force: true,
|
|
42
|
+
maxRetries: RM_MAX_RETRIES,
|
|
43
|
+
});
|
|
44
|
+
if (tsBuildInfoFileToDelete) {
|
|
45
|
+
await rm(tsBuildInfoFileToDelete, {
|
|
46
|
+
force: true,
|
|
47
|
+
maxRetries: RM_MAX_RETRIES,
|
|
48
|
+
});
|
|
14
49
|
}
|
|
15
50
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Configuration } from '../../configuration';
|
|
1
|
+
import { Configuration } from '../../configuration/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* Returns the builder to use for the given application.
|
|
5
4
|
* @param configuration Configuration object.
|
|
@@ -7,15 +6,18 @@ import { Configuration } from '../../configuration';
|
|
|
7
6
|
* @param appName Application name.
|
|
8
7
|
* @returns The builder to use.
|
|
9
8
|
*/
|
|
10
|
-
export declare function getBuilder(configuration: Required<Configuration>, cmdOptions:
|
|
9
|
+
export declare function getBuilder(configuration: Required<Configuration>, cmdOptions: Record<string, any>, appName: string | undefined): {
|
|
11
10
|
type: "webpack";
|
|
12
|
-
options?: import("../../configuration").WebpackBuilderOptions;
|
|
11
|
+
options?: import("../../configuration/configuration.js").WebpackBuilderOptions;
|
|
12
|
+
} | {
|
|
13
|
+
type: "rspack";
|
|
14
|
+
options?: import("../../configuration/configuration.js").RspackBuilderOptions;
|
|
13
15
|
} | {
|
|
14
16
|
type: "swc";
|
|
15
|
-
options?: import("../../configuration").SwcBuilderOptions;
|
|
17
|
+
options?: import("../../configuration/configuration.js").SwcBuilderOptions;
|
|
16
18
|
} | {
|
|
17
19
|
type: "tsc";
|
|
18
|
-
options?: import("../../configuration").TscBuilderOptions;
|
|
20
|
+
options?: import("../../configuration/configuration.js").TscBuilderOptions;
|
|
19
21
|
} | {
|
|
20
|
-
type: import("../../configuration").BuilderVariant;
|
|
22
|
+
type: import("../../configuration/configuration.js").BuilderVariant;
|
|
21
23
|
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBuilder = getBuilder;
|
|
4
|
-
const get_value_or_default_1 = require("./get-value-or-default");
|
|
1
|
+
import { getValueOrDefault } from './get-value-or-default.js';
|
|
5
2
|
/**
|
|
6
3
|
* Returns the builder to use for the given application.
|
|
7
4
|
* @param configuration Configuration object.
|
|
@@ -9,8 +6,8 @@ const get_value_or_default_1 = require("./get-value-or-default");
|
|
|
9
6
|
* @param appName Application name.
|
|
10
7
|
* @returns The builder to use.
|
|
11
8
|
*/
|
|
12
|
-
function getBuilder(configuration, cmdOptions, appName) {
|
|
13
|
-
const builderValue =
|
|
9
|
+
export function getBuilder(configuration, cmdOptions, appName) {
|
|
10
|
+
const builderValue = getValueOrDefault(configuration, 'compilerOptions.builder', appName, 'builder', cmdOptions, 'tsc');
|
|
14
11
|
return typeof builderValue === 'string'
|
|
15
12
|
? {
|
|
16
13
|
type: builderValue,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the effective TypeScript rootDir for an emit, mirroring how the
|
|
3
|
+
* TypeScript compiler determines it when `rootDir` is not set in tsconfig.
|
|
4
|
+
*
|
|
5
|
+
* When `rootDir` is explicitly configured, its absolute, normalized form is
|
|
6
|
+
* returned. Otherwise the longest common parent directory of the input file
|
|
7
|
+
* list is used (the same heuristic TypeScript applies through
|
|
8
|
+
* `Program#getCommonSourceDirectory`).
|
|
9
|
+
*
|
|
10
|
+
* Returns `undefined` if no rootDir can be determined (e.g. no input files).
|
|
11
|
+
*
|
|
12
|
+
* @param explicitRootDir Value of `compilerOptions.rootDir` from tsconfig, if any.
|
|
13
|
+
* @param fileNames List of TypeScript input files (absolute paths).
|
|
14
|
+
* @param cwd Current working directory used to resolve relative paths.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getEffectiveRootDir(explicitRootDir: string | undefined, fileNames: readonly string[] | undefined, cwd?: string): string | undefined;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { dirname, isAbsolute, normalize, resolve, sep } from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Computes the effective TypeScript rootDir for an emit, mirroring how the
|
|
4
|
+
* TypeScript compiler determines it when `rootDir` is not set in tsconfig.
|
|
5
|
+
*
|
|
6
|
+
* When `rootDir` is explicitly configured, its absolute, normalized form is
|
|
7
|
+
* returned. Otherwise the longest common parent directory of the input file
|
|
8
|
+
* list is used (the same heuristic TypeScript applies through
|
|
9
|
+
* `Program#getCommonSourceDirectory`).
|
|
10
|
+
*
|
|
11
|
+
* Returns `undefined` if no rootDir can be determined (e.g. no input files).
|
|
12
|
+
*
|
|
13
|
+
* @param explicitRootDir Value of `compilerOptions.rootDir` from tsconfig, if any.
|
|
14
|
+
* @param fileNames List of TypeScript input files (absolute paths).
|
|
15
|
+
* @param cwd Current working directory used to resolve relative paths.
|
|
16
|
+
*/
|
|
17
|
+
export function getEffectiveRootDir(explicitRootDir, fileNames, cwd = process.cwd()) {
|
|
18
|
+
if (explicitRootDir) {
|
|
19
|
+
return normalize(isAbsolute(explicitRootDir)
|
|
20
|
+
? explicitRootDir
|
|
21
|
+
: resolve(cwd, explicitRootDir));
|
|
22
|
+
}
|
|
23
|
+
if (!fileNames || fileNames.length === 0) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
// Declaration files are excluded from the common source directory, matching
|
|
27
|
+
// TypeScript: they produce no emit, so a `typings/**/*.d.ts` entry outside
|
|
28
|
+
// `src` must not drag the computed root up to the project root and push
|
|
29
|
+
// every copied asset into a `dist/src` subdirectory.
|
|
30
|
+
const emittedFiles = fileNames.filter((file) => !isDeclarationFileName(file));
|
|
31
|
+
if (emittedFiles.length === 0) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const absolutePaths = emittedFiles.map((file) => normalize(isAbsolute(file) ? file : resolve(cwd, file)));
|
|
35
|
+
let commonDir = dirname(absolutePaths[0]);
|
|
36
|
+
for (let i = 1; i < absolutePaths.length; i++) {
|
|
37
|
+
commonDir = commonParentDir(commonDir, dirname(absolutePaths[i]));
|
|
38
|
+
if (!commonDir) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return commonDir;
|
|
43
|
+
}
|
|
44
|
+
function isDeclarationFileName(fileName) {
|
|
45
|
+
return /\.d\.[cm]?ts$/i.test(fileName);
|
|
46
|
+
}
|
|
47
|
+
function commonParentDir(a, b) {
|
|
48
|
+
const aSegments = a.split(sep);
|
|
49
|
+
const bSegments = b.split(sep);
|
|
50
|
+
const length = Math.min(aSegments.length, bSegments.length);
|
|
51
|
+
let i = 0;
|
|
52
|
+
while (i < length && aSegments[i] === bSegments[i]) {
|
|
53
|
+
i++;
|
|
54
|
+
}
|
|
55
|
+
return aSegments.slice(0, i).join(sep);
|
|
56
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Configuration } from '../../configuration/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the path to the rspack configuration file to use for the given application.
|
|
4
|
+
* CLI option `rspackPath` takes precedence over the configuration file.
|
|
5
|
+
* @param configuration Configuration object.
|
|
6
|
+
* @param cmdOptions Command line options.
|
|
7
|
+
* @param appName Application name.
|
|
8
|
+
* @returns The path to the rspack configuration file to use.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getRspackConfigPath(configuration: Required<Configuration>, cmdOptions: Record<string, any>, appName: string | undefined): string | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getValueOrDefault } from './get-value-or-default.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the path to the rspack configuration file to use for the given application.
|
|
4
|
+
* CLI option `rspackPath` takes precedence over the configuration file.
|
|
5
|
+
* @param configuration Configuration object.
|
|
6
|
+
* @param cmdOptions Command line options.
|
|
7
|
+
* @param appName Application name.
|
|
8
|
+
* @returns The path to the rspack configuration file to use.
|
|
9
|
+
*/
|
|
10
|
+
export function getRspackConfigPath(configuration, cmdOptions, appName) {
|
|
11
|
+
if (cmdOptions?.rspackPath) {
|
|
12
|
+
return cmdOptions.rspackPath;
|
|
13
|
+
}
|
|
14
|
+
const builder = getValueOrDefault(configuration, 'compilerOptions.builder', appName);
|
|
15
|
+
const rspackPath = typeof builder === 'object' && builder?.type === 'rspack'
|
|
16
|
+
? builder.options?.configPath
|
|
17
|
+
: undefined;
|
|
18
|
+
return rspackPath;
|
|
19
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Configuration } from '../../configuration';
|
|
1
|
+
import { Configuration } from '../../configuration/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* Returns the path to the tsc configuration file to use for the given application.
|
|
5
4
|
* @param configuration Configuration object.
|
|
@@ -7,4 +6,4 @@ import { Configuration } from '../../configuration';
|
|
|
7
6
|
* @param appName Application name.
|
|
8
7
|
* @returns The path to the tsc configuration file to use.
|
|
9
8
|
*/
|
|
10
|
-
export declare function getTscConfigPath(configuration: Required<Configuration>, cmdOptions:
|
|
9
|
+
export declare function getTscConfigPath(configuration: Required<Configuration>, cmdOptions: Record<string, any>, appName: string | undefined): string;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getTscConfigPath = getTscConfigPath;
|
|
4
|
-
const get_default_tsconfig_path_1 = require("../../utils/get-default-tsconfig-path");
|
|
5
|
-
const get_value_or_default_1 = require("./get-value-or-default");
|
|
1
|
+
import { getDefaultTsconfigPath } from '../../utils/get-default-tsconfig-path.js';
|
|
2
|
+
import { getValueOrDefault } from './get-value-or-default.js';
|
|
6
3
|
/**
|
|
7
4
|
* Returns the path to the tsc configuration file to use for the given application.
|
|
8
5
|
* @param configuration Configuration object.
|
|
@@ -10,15 +7,15 @@ const get_value_or_default_1 = require("./get-value-or-default");
|
|
|
10
7
|
* @param appName Application name.
|
|
11
8
|
* @returns The path to the tsc configuration file to use.
|
|
12
9
|
*/
|
|
13
|
-
function getTscConfigPath(configuration, cmdOptions, appName) {
|
|
14
|
-
let tsconfigPath =
|
|
10
|
+
export function getTscConfigPath(configuration, cmdOptions, appName) {
|
|
11
|
+
let tsconfigPath = getValueOrDefault(configuration, 'compilerOptions.tsConfigPath', appName, 'path', cmdOptions);
|
|
15
12
|
if (tsconfigPath) {
|
|
16
13
|
return tsconfigPath;
|
|
17
14
|
}
|
|
18
|
-
const builder =
|
|
15
|
+
const builder = getValueOrDefault(configuration, 'compilerOptions.builder', appName);
|
|
19
16
|
tsconfigPath =
|
|
20
17
|
typeof builder === 'object' && builder?.type === 'tsc'
|
|
21
18
|
? builder.options?.configPath
|
|
22
19
|
: undefined;
|
|
23
|
-
return tsconfigPath ??
|
|
20
|
+
return tsconfigPath ?? getDefaultTsconfigPath();
|
|
24
21
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function getValueOrDefault<T = any>(configuration: Required<Configuration>, propertyPath: string, appName: string | undefined, key?: 'path' | 'webpack' | 'webpackPath' | 'entryFile' | 'sourceRoot' | 'exec' | 'builder' | 'typeCheck', options?: Input[], defaultValue?: T): T;
|
|
1
|
+
import { Configuration } from '../../configuration/index.js';
|
|
2
|
+
export declare function getValueOrDefault<T = any>(configuration: Required<Configuration>, propertyPath: string, appName: string | undefined, key?: 'path' | 'webpack' | 'webpackPath' | 'entryFile' | 'sourceRoot' | 'exec' | 'builder' | 'typeCheck' | 'emitDeclarations', options?: Record<string, any>, defaultValue?: T): T;
|
|
4
3
|
export declare function getValueOfPath<T = any>(object: Record<string, any>, propertyPath: string): T;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getValueOrDefault = getValueOrDefault;
|
|
4
|
-
exports.getValueOfPath = getValueOfPath;
|
|
5
|
-
function getValueOrDefault(configuration, propertyPath, appName, key, options = [], defaultValue) {
|
|
6
|
-
const item = options.find((option) => option.name === key);
|
|
7
|
-
const origValue = item && item.value;
|
|
1
|
+
export function getValueOrDefault(configuration, propertyPath, appName, key, options = {}, defaultValue) {
|
|
2
|
+
const origValue = key != null ? options[key] : undefined;
|
|
8
3
|
if (origValue !== undefined && origValue !== null) {
|
|
9
4
|
return origValue;
|
|
10
5
|
}
|
|
@@ -23,7 +18,7 @@ function getValueOrDefault(configuration, propertyPath, appName, key, options =
|
|
|
23
18
|
}
|
|
24
19
|
return value;
|
|
25
20
|
}
|
|
26
|
-
function getValueOfPath(object, propertyPath) {
|
|
21
|
+
export function getValueOfPath(object, propertyPath) {
|
|
27
22
|
const fragments = propertyPath.split('.');
|
|
28
23
|
let propertyValue = object;
|
|
29
24
|
let isConcatInProgress = false;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Configuration } from '../../configuration';
|
|
1
|
+
import { Configuration } from '../../configuration/index.js';
|
|
3
2
|
/**
|
|
4
3
|
* Returns the path to the webpack configuration file to use for the given application.
|
|
5
4
|
* @param configuration Configuration object.
|
|
@@ -7,4 +6,4 @@ import { Configuration } from '../../configuration';
|
|
|
7
6
|
* @param appName Application name.
|
|
8
7
|
* @returns The path to the webpack configuration file to use.
|
|
9
8
|
*/
|
|
10
|
-
export declare function getWebpackConfigPath(configuration: Required<Configuration>, cmdOptions:
|
|
9
|
+
export declare function getWebpackConfigPath(configuration: Required<Configuration>, cmdOptions: Record<string, any>, appName: string | undefined): string | undefined;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWebpackConfigPath = getWebpackConfigPath;
|
|
4
|
-
const get_value_or_default_1 = require("./get-value-or-default");
|
|
1
|
+
import { getValueOrDefault } from './get-value-or-default.js';
|
|
5
2
|
/**
|
|
6
3
|
* Returns the path to the webpack configuration file to use for the given application.
|
|
7
4
|
* @param configuration Configuration object.
|
|
@@ -9,12 +6,12 @@ const get_value_or_default_1 = require("./get-value-or-default");
|
|
|
9
6
|
* @param appName Application name.
|
|
10
7
|
* @returns The path to the webpack configuration file to use.
|
|
11
8
|
*/
|
|
12
|
-
function getWebpackConfigPath(configuration, cmdOptions, appName) {
|
|
13
|
-
let webpackPath =
|
|
9
|
+
export function getWebpackConfigPath(configuration, cmdOptions, appName) {
|
|
10
|
+
let webpackPath = getValueOrDefault(configuration, 'compilerOptions.webpackConfigPath', appName, 'webpackPath', cmdOptions);
|
|
14
11
|
if (webpackPath) {
|
|
15
12
|
return webpackPath;
|
|
16
13
|
}
|
|
17
|
-
const builder =
|
|
14
|
+
const builder = getValueOrDefault(configuration, 'compilerOptions.builder', appName);
|
|
18
15
|
if (typeof builder === 'object' && builder?.type === 'webpack') {
|
|
19
16
|
const webpackConfigPath = builder.options?.configPath;
|
|
20
17
|
if (webpackConfigPath) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface GlobSyncOptions {
|
|
2
|
+
/** A single glob pattern; every path matching it is removed from the result. */
|
|
3
|
+
ignore?: string;
|
|
4
|
+
/** When true, `*` and `**` also match entries whose name starts with a dot. */
|
|
5
|
+
dot?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface GlobEntry {
|
|
8
|
+
/** Absolute path, always `/`-separated regardless of platform. */
|
|
9
|
+
path: string;
|
|
10
|
+
isFile: boolean;
|
|
11
|
+
isDirectory: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Expands `pattern` to every matching path, with the type of each entry.
|
|
15
|
+
* See the file header for the compatibility rules this preserves.
|
|
16
|
+
*/
|
|
17
|
+
export declare function globEntriesSync(pattern: string, options?: GlobSyncOptions): GlobEntry[];
|
|
18
|
+
/** Expands `pattern` to every matching path. */
|
|
19
|
+
export declare function globSync(pattern: string, options?: GlobSyncOptions): string[];
|