@depup/nestjs__cli 11.0.24-depup.7 → 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 +7 -15
- 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 +9 -41
- 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 +70 -83
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import * as chokidar from 'chokidar';
|
|
2
|
+
import { watch as watchFs } from 'fs';
|
|
3
|
+
import { readdir, stat } from 'fs/promises';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
const DEFAULT_STABILITY_THRESHOLD = 50;
|
|
6
|
+
const DEFAULT_POLL_INTERVAL = 10;
|
|
7
|
+
const RESCAN_DEBOUNCE = 100;
|
|
8
|
+
/**
|
|
9
|
+
* A recursive "fs.watch" only starts delivering once its underlying stream is
|
|
10
|
+
* running, which happens some time after "fs.watch" returns - measurably later
|
|
11
|
+
* on a loaded machine. Anything written in that window produces no event at
|
|
12
|
+
* all, so the tree is diffed a few times while the stream warms up; without
|
|
13
|
+
* this a file added moments after the watch started is never compiled.
|
|
14
|
+
*/
|
|
15
|
+
const CATCH_UP_SCAN_DELAYS = [100, 500, 1_500];
|
|
16
|
+
const REARM_INTERVAL = 500;
|
|
17
|
+
const DIRECTORY_EXISTENCE_CHECK_INTERVAL = 1_000;
|
|
18
|
+
/**
|
|
19
|
+
* Platforms on which libuv implements `fs.watch(dir, { recursive: true })`
|
|
20
|
+
* natively (FSEvents on macOS, ReadDirectoryChangesW on Windows), so that a
|
|
21
|
+
* whole tree costs a single handle. Everywhere else Node either emulates it in
|
|
22
|
+
* JavaScript (Linux, only since v20.13) or does not support it at all, so
|
|
23
|
+
* chokidar - which is already O(directories) there - stays in charge.
|
|
24
|
+
*/
|
|
25
|
+
const NATIVE_RECURSIVE_WATCH_PLATFORMS = new Set([
|
|
26
|
+
'darwin',
|
|
27
|
+
'win32',
|
|
28
|
+
]);
|
|
29
|
+
export function supportsNativeRecursiveWatch(platform = process.platform) {
|
|
30
|
+
return NATIVE_RECURSIVE_WATCH_PLATFORMS.has(platform);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Watches a directory tree for added and changed files.
|
|
34
|
+
*
|
|
35
|
+
* On macOS chokidar (since v4, which dropped the bundled `fsevents` backend)
|
|
36
|
+
* falls back to `fs.watch` per file, and libuv only uses FSEvents for
|
|
37
|
+
* directories - so every watched file permanently costs a file descriptor and
|
|
38
|
+
* a medium-sized project quickly hits `EMFILE`. A single recursive `fs.watch`
|
|
39
|
+
* over the directory costs one handle for the whole tree instead.
|
|
40
|
+
*
|
|
41
|
+
* See https://github.com/nestjs/nest-cli/issues/3512
|
|
42
|
+
*/
|
|
43
|
+
export async function watchDirectoryRecursively(dir, options) {
|
|
44
|
+
if (supportsNativeRecursiveWatch()) {
|
|
45
|
+
return new NativeRecursiveDirectoryWatcher(dir, options).start();
|
|
46
|
+
}
|
|
47
|
+
return createChokidarWatcher(dir, options);
|
|
48
|
+
}
|
|
49
|
+
async function createChokidarWatcher(dir, options) {
|
|
50
|
+
const watcher = chokidar.watch(dir, {
|
|
51
|
+
ignored: (file, stats) => (stats?.isFile() &&
|
|
52
|
+
!matchesExtension(file, options.extensions)),
|
|
53
|
+
ignoreInitial: true,
|
|
54
|
+
awaitWriteFinish: {
|
|
55
|
+
stabilityThreshold: options.stabilityThreshold ?? DEFAULT_STABILITY_THRESHOLD,
|
|
56
|
+
pollInterval: options.pollInterval ?? DEFAULT_POLL_INTERVAL,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
// Chokidar swallows everything it encounters during its initial scan (that
|
|
60
|
+
// is what "ignoreInitial" means), so the watch is only truly active once
|
|
61
|
+
// "ready" has fired. Resolving before that would silently drop every file
|
|
62
|
+
// written in between - the caller has no other signal to wait on.
|
|
63
|
+
await new Promise((resolve) => {
|
|
64
|
+
// Chokidar rethrows an "error" that has no listener; scanning a tree that
|
|
65
|
+
// is being rewritten underneath is not fatal, so it must not take the
|
|
66
|
+
// process down either.
|
|
67
|
+
watcher.on('error', () => resolve());
|
|
68
|
+
watcher.once('ready', () => resolve());
|
|
69
|
+
});
|
|
70
|
+
if (options.onAdd) {
|
|
71
|
+
watcher.on('add', (file) => void options.onAdd(file));
|
|
72
|
+
}
|
|
73
|
+
if (options.onChange) {
|
|
74
|
+
watcher.on('change', (file) => void options.onChange(file));
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
close: () => watcher.close(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function matchesExtension(file, extensions) {
|
|
81
|
+
return extensions.some((extension) => file.endsWith(extension));
|
|
82
|
+
}
|
|
83
|
+
class NativeRecursiveDirectoryWatcher {
|
|
84
|
+
dir;
|
|
85
|
+
options;
|
|
86
|
+
/** Known files mapped to the modification time we last reported. */
|
|
87
|
+
known = new Map();
|
|
88
|
+
pending = new Map();
|
|
89
|
+
stabilityThreshold;
|
|
90
|
+
pollInterval;
|
|
91
|
+
watcher;
|
|
92
|
+
existenceTimer;
|
|
93
|
+
rearmTimer;
|
|
94
|
+
rescanTimer;
|
|
95
|
+
catchUpTimers = new Set();
|
|
96
|
+
closed = false;
|
|
97
|
+
constructor(dir, options) {
|
|
98
|
+
this.dir = dir;
|
|
99
|
+
this.options = options;
|
|
100
|
+
this.stabilityThreshold =
|
|
101
|
+
options.stabilityThreshold ?? DEFAULT_STABILITY_THRESHOLD;
|
|
102
|
+
this.pollInterval = options.pollInterval ?? DEFAULT_POLL_INTERVAL;
|
|
103
|
+
}
|
|
104
|
+
async start() {
|
|
105
|
+
// Snapshot before arming the watcher so that the files that already exist
|
|
106
|
+
// are not reported, mirroring chokidar's "ignoreInitial".
|
|
107
|
+
await this.scan(false);
|
|
108
|
+
this.arm();
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
async close() {
|
|
112
|
+
this.closed = true;
|
|
113
|
+
clearTimeout(this.rearmTimer);
|
|
114
|
+
clearTimeout(this.rescanTimer);
|
|
115
|
+
this.clearCatchUpScans();
|
|
116
|
+
for (const { timer } of this.pending.values()) {
|
|
117
|
+
clearTimeout(timer);
|
|
118
|
+
}
|
|
119
|
+
this.pending.clear();
|
|
120
|
+
this.disposeWatcher();
|
|
121
|
+
}
|
|
122
|
+
arm() {
|
|
123
|
+
if (this.closed) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
this.watcher = watchFs(this.dir, { recursive: true }, (_, filename) => this.handleEvent(filename));
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// The directory does not exist (yet) - "outDir" is only created by the
|
|
131
|
+
// first successful build - or the platform refused the recursive watch.
|
|
132
|
+
this.scheduleRearm();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// A watcher whose directory is removed stops emitting instead of failing,
|
|
136
|
+
// so its liveness is checked separately.
|
|
137
|
+
this.watcher.on('error', () => this.rearm());
|
|
138
|
+
this.existenceTimer = setInterval(() => {
|
|
139
|
+
void stat(this.dir)
|
|
140
|
+
.then((stats) => {
|
|
141
|
+
if (!stats.isDirectory()) {
|
|
142
|
+
this.rearm();
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
.catch(() => this.rearm());
|
|
146
|
+
}, DIRECTORY_EXISTENCE_CHECK_INTERVAL);
|
|
147
|
+
this.existenceTimer.unref?.();
|
|
148
|
+
this.scheduleCatchUpScans();
|
|
149
|
+
}
|
|
150
|
+
scheduleCatchUpScans() {
|
|
151
|
+
for (const delay of CATCH_UP_SCAN_DELAYS) {
|
|
152
|
+
const timer = setTimeout(() => {
|
|
153
|
+
this.catchUpTimers.delete(timer);
|
|
154
|
+
void this.scan(true);
|
|
155
|
+
}, delay);
|
|
156
|
+
timer.unref?.();
|
|
157
|
+
this.catchUpTimers.add(timer);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
clearCatchUpScans() {
|
|
161
|
+
for (const timer of this.catchUpTimers) {
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
}
|
|
164
|
+
this.catchUpTimers.clear();
|
|
165
|
+
}
|
|
166
|
+
handleEvent(filename) {
|
|
167
|
+
if (this.closed) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!filename) {
|
|
171
|
+
// macOS coalesces some events and reports no filename at all; fall back
|
|
172
|
+
// to diffing the tree.
|
|
173
|
+
this.scheduleRescan();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const file = join(this.dir, filename.toString());
|
|
177
|
+
if (!matchesExtension(file, this.options.extensions)) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.settle(file);
|
|
181
|
+
}
|
|
182
|
+
scheduleRescan() {
|
|
183
|
+
if (this.closed || this.rescanTimer) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
this.rescanTimer = setTimeout(() => {
|
|
187
|
+
this.rescanTimer = undefined;
|
|
188
|
+
void this.scan(true);
|
|
189
|
+
}, RESCAN_DEBOUNCE);
|
|
190
|
+
this.rescanTimer.unref?.();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Walks the tree and, when `emit` is set, reports the files that were added
|
|
194
|
+
* or modified since the last walk. Reading the tree does not hold any handle.
|
|
195
|
+
*/
|
|
196
|
+
async scan(emit) {
|
|
197
|
+
let entries;
|
|
198
|
+
try {
|
|
199
|
+
entries = await readdir(this.dir, {
|
|
200
|
+
recursive: true,
|
|
201
|
+
withFileTypes: true,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// Directory is gone; everything it held counts as removed.
|
|
206
|
+
this.known.clear();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (this.closed) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const seen = new Set();
|
|
213
|
+
for (const entry of entries) {
|
|
214
|
+
if (!entry.isFile()) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const file = join(entry.parentPath ?? entry.path, entry.name);
|
|
218
|
+
if (!matchesExtension(file, this.options.extensions)) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
seen.add(file);
|
|
222
|
+
const mtimeMs = await stat(file)
|
|
223
|
+
.then((stats) => stats.mtimeMs)
|
|
224
|
+
.catch(() => undefined);
|
|
225
|
+
if (mtimeMs === undefined) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (!emit) {
|
|
229
|
+
this.known.set(file, mtimeMs);
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (this.known.get(file) !== mtimeMs) {
|
|
233
|
+
this.settle(file);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
for (const file of this.known.keys()) {
|
|
237
|
+
if (!seen.has(file)) {
|
|
238
|
+
this.known.delete(file);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Delays reporting until the file stopped growing, so that a half-written
|
|
244
|
+
* file is never handed over to the compiler.
|
|
245
|
+
*/
|
|
246
|
+
settle(file) {
|
|
247
|
+
const pending = this.pending.get(file);
|
|
248
|
+
if (pending) {
|
|
249
|
+
clearTimeout(pending.timer);
|
|
250
|
+
}
|
|
251
|
+
const state = {
|
|
252
|
+
size: -1,
|
|
253
|
+
stableSince: Date.now(),
|
|
254
|
+
timer: undefined,
|
|
255
|
+
};
|
|
256
|
+
state.timer = setTimeout(() => void this.poll(file), this.pollInterval);
|
|
257
|
+
this.pending.set(file, state);
|
|
258
|
+
}
|
|
259
|
+
async poll(file) {
|
|
260
|
+
const state = this.pending.get(file);
|
|
261
|
+
if (this.closed || !state) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const stats = await stat(file).catch(() => undefined);
|
|
265
|
+
if (this.closed) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (!stats) {
|
|
269
|
+
// Removed (or renamed away) before it settled.
|
|
270
|
+
this.pending.delete(file);
|
|
271
|
+
this.known.delete(file);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const now = Date.now();
|
|
275
|
+
if (stats.size !== state.size) {
|
|
276
|
+
state.size = stats.size;
|
|
277
|
+
state.stableSince = now;
|
|
278
|
+
}
|
|
279
|
+
if (now - state.stableSince >= this.stabilityThreshold) {
|
|
280
|
+
this.pending.delete(file);
|
|
281
|
+
this.emit(file, stats.mtimeMs);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
state.timer = setTimeout(() => void this.poll(file), this.pollInterval);
|
|
285
|
+
}
|
|
286
|
+
emit(file, mtimeMs) {
|
|
287
|
+
const isKnown = this.known.has(file);
|
|
288
|
+
this.known.set(file, mtimeMs);
|
|
289
|
+
if (isKnown) {
|
|
290
|
+
void this.options.onChange?.(file);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
void this.options.onAdd?.(file);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
rearm() {
|
|
297
|
+
if (this.closed) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
this.disposeWatcher();
|
|
301
|
+
this.known.clear();
|
|
302
|
+
this.scheduleRearm();
|
|
303
|
+
}
|
|
304
|
+
scheduleRearm() {
|
|
305
|
+
if (this.closed || this.rearmTimer) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
this.rearmTimer = setTimeout(() => {
|
|
309
|
+
this.rearmTimer = undefined;
|
|
310
|
+
if (this.closed) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
void stat(this.dir)
|
|
314
|
+
.then(async (stats) => {
|
|
315
|
+
if (!stats.isDirectory()) {
|
|
316
|
+
this.scheduleRearm();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
this.arm();
|
|
320
|
+
// The tree may have been (re)populated while unwatched.
|
|
321
|
+
await this.scan(true);
|
|
322
|
+
})
|
|
323
|
+
.catch(() => this.scheduleRearm());
|
|
324
|
+
}, REARM_INTERVAL);
|
|
325
|
+
this.rearmTimer.unref?.();
|
|
326
|
+
}
|
|
327
|
+
disposeWatcher() {
|
|
328
|
+
this.clearCatchUpScans();
|
|
329
|
+
clearInterval(this.existenceTimer);
|
|
330
|
+
this.existenceTimer = undefined;
|
|
331
|
+
this.watcher?.close();
|
|
332
|
+
this.watcher = undefined;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import webpack = require('webpack');
|
|
1
|
+
import { Configuration } from '../configuration/index.js';
|
|
2
|
+
import { AssetsManager } from './assets-manager.js';
|
|
3
|
+
import { BaseCompiler } from './base-compiler.js';
|
|
4
|
+
import { PluginsLoader } from './plugins/plugins-loader.js';
|
|
5
|
+
import type webpack from 'webpack';
|
|
7
6
|
type WebpackConfigFactory = (config: webpack.Configuration, webpackRef: typeof webpack) => webpack.Configuration;
|
|
8
7
|
type WebpackConfigFactoryOrConfig = WebpackConfigFactory | webpack.Configuration;
|
|
9
8
|
type WebpackCompilerExtras = {
|
|
10
|
-
|
|
9
|
+
options: Record<string, any>;
|
|
11
10
|
assetsManager: AssetsManager;
|
|
12
11
|
webpackConfigFactoryOrConfig: WebpackConfigFactoryOrConfig | WebpackConfigFactoryOrConfig[];
|
|
13
12
|
debug?: boolean;
|
|
@@ -1,28 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { ERROR_PREFIX, INFO_PREFIX } from '../ui/index.js';
|
|
5
|
+
import { isEsmProject } from '../utils/is-esm-project.js';
|
|
6
|
+
import { BaseCompiler } from './base-compiler.js';
|
|
7
|
+
import { webpackDefaultsFactory } from './defaults/webpack-defaults.js';
|
|
8
|
+
import { getValueOrDefault } from './helpers/get-value-or-default.js';
|
|
9
|
+
const WEBPACK_DEPRECATION_MSG = 'The webpack compiler is deprecated and will be removed in a future major version. ' +
|
|
10
|
+
'Please migrate to rspack (--builder rspack). ' +
|
|
11
|
+
'See https://docs.nestjs.com/cli/usages#build for details.';
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
function loadWebpack() {
|
|
14
|
+
try {
|
|
15
|
+
return require('webpack');
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw new Error('webpack is not installed. To use the webpack compiler, install the required packages:\n\n' +
|
|
19
|
+
' npm install --save-dev webpack webpack-node-externals tsconfig-paths-webpack-plugin ts-loader\n');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class WebpackCompiler extends BaseCompiler {
|
|
12
23
|
constructor(pluginsLoader) {
|
|
13
24
|
super(pluginsLoader);
|
|
14
25
|
}
|
|
15
26
|
run(configuration, tsConfigPath, appName, extras, onSuccess) {
|
|
16
27
|
const cwd = process.cwd();
|
|
17
|
-
const configPath =
|
|
18
|
-
if (!
|
|
28
|
+
const configPath = join(cwd, tsConfigPath);
|
|
29
|
+
if (!existsSync(configPath)) {
|
|
19
30
|
throw new Error(`Could not find TypeScript configuration file "${tsConfigPath}".`);
|
|
20
31
|
}
|
|
21
32
|
const plugins = this.loadPlugins(configuration, tsConfigPath, appName);
|
|
22
33
|
const pathToSource = this.getPathToSource(configuration, tsConfigPath, appName);
|
|
23
|
-
const entryFile =
|
|
24
|
-
const entryFileRoot =
|
|
25
|
-
|
|
34
|
+
const entryFile = getValueOrDefault(configuration, 'entryFile', appName, 'entryFile', extras.options);
|
|
35
|
+
const entryFileRoot = getValueOrDefault(configuration, 'root', appName) || '';
|
|
36
|
+
if (isEsmProject()) {
|
|
37
|
+
throw new Error('The webpack compiler does not support ESM projects ("type": "module" in package.json). ' +
|
|
38
|
+
'Please use rspack instead by setting "builder": "rspack" in your nest-cli.json compilerOptions, ' +
|
|
39
|
+
'or use --builder rspack on the command line.');
|
|
40
|
+
}
|
|
41
|
+
console.warn(`\n${INFO_PREFIX} ${WEBPACK_DEPRECATION_MSG}\n`);
|
|
42
|
+
const defaultOptions = webpackDefaultsFactory(pathToSource, entryFileRoot, entryFile, extras.debug ?? false, tsConfigPath, plugins);
|
|
43
|
+
const wp = loadWebpack();
|
|
26
44
|
let compiler;
|
|
27
45
|
let watchOptions;
|
|
28
46
|
let watch;
|
|
@@ -30,34 +48,34 @@ class WebpackCompiler extends base_compiler_1.BaseCompiler {
|
|
|
30
48
|
const webpackConfigurations = extras.webpackConfigFactoryOrConfig.map((configOrFactory) => {
|
|
31
49
|
const unwrappedConfig = typeof configOrFactory !== 'function'
|
|
32
50
|
? configOrFactory
|
|
33
|
-
: configOrFactory(defaultOptions,
|
|
51
|
+
: configOrFactory(defaultOptions, wp);
|
|
34
52
|
return {
|
|
35
53
|
...defaultOptions,
|
|
36
54
|
mode: extras.watchMode ? 'development' : defaultOptions.mode,
|
|
37
55
|
...unwrappedConfig,
|
|
38
56
|
};
|
|
39
57
|
});
|
|
40
|
-
compiler =
|
|
58
|
+
compiler = wp(webpackConfigurations);
|
|
41
59
|
watchOptions = webpackConfigurations.map((config) => config.watchOptions || {});
|
|
42
60
|
watch = webpackConfigurations.some((config) => config.watch);
|
|
43
61
|
}
|
|
44
62
|
else {
|
|
45
63
|
const projectWebpackOptions = typeof extras.webpackConfigFactoryOrConfig !== 'function'
|
|
46
64
|
? extras.webpackConfigFactoryOrConfig
|
|
47
|
-
: extras.webpackConfigFactoryOrConfig(defaultOptions,
|
|
65
|
+
: extras.webpackConfigFactoryOrConfig(defaultOptions, wp);
|
|
48
66
|
const webpackConfiguration = {
|
|
49
67
|
...defaultOptions,
|
|
50
68
|
mode: extras.watchMode ? 'development' : defaultOptions.mode,
|
|
51
69
|
...projectWebpackOptions,
|
|
52
70
|
};
|
|
53
|
-
compiler =
|
|
71
|
+
compiler = wp(webpackConfiguration);
|
|
54
72
|
watchOptions = webpackConfiguration.watchOptions;
|
|
55
73
|
watch = webpackConfiguration.watch;
|
|
56
74
|
}
|
|
57
75
|
const afterCallback = this.createAfterCallback(onSuccess, extras.assetsManager, extras.watchMode ?? false, watch);
|
|
58
76
|
if (extras.watchMode || watch) {
|
|
59
77
|
compiler.hooks.watchRun.tapAsync('Rebuild info', (params, callback) => {
|
|
60
|
-
console.log(`\n${
|
|
78
|
+
console.log(`\n${INFO_PREFIX} Webpack is building your sources...\n`);
|
|
61
79
|
callback();
|
|
62
80
|
});
|
|
63
81
|
compiler.watch(watchOptions || {}, afterCallback);
|
|
@@ -82,7 +100,13 @@ class WebpackCompiler extends base_compiler_1.BaseCompiler {
|
|
|
82
100
|
});
|
|
83
101
|
if (!err && !stats.hasErrors()) {
|
|
84
102
|
if (!onSuccess) {
|
|
85
|
-
|
|
103
|
+
// webpack ignores whatever this callback returns, so the close is
|
|
104
|
+
// handled here rather than awaited — but its rejection still has to
|
|
105
|
+
// be caught or it terminates the CLI after a successful compile.
|
|
106
|
+
assetsManager.closeWatchers().catch((error) => {
|
|
107
|
+
console.error(`${ERROR_PREFIX} Failed to close asset watchers. ` +
|
|
108
|
+
`${error instanceof Error ? error.message : String(error)}`);
|
|
109
|
+
});
|
|
86
110
|
}
|
|
87
111
|
else {
|
|
88
112
|
onSuccess();
|
|
@@ -96,4 +120,3 @@ class WebpackCompiler extends base_compiler_1.BaseCompiler {
|
|
|
96
120
|
};
|
|
97
121
|
}
|
|
98
122
|
}
|
|
99
|
-
exports.WebpackCompiler = WebpackCompiler;
|
|
@@ -13,6 +13,7 @@ export interface ActionOnFile {
|
|
|
13
13
|
path: string;
|
|
14
14
|
sourceRoot: string;
|
|
15
15
|
watchAssetsMode: boolean;
|
|
16
|
+
confinePathsToProject: boolean;
|
|
16
17
|
}
|
|
17
18
|
export interface SwcBuilderOptions {
|
|
18
19
|
swcrcPath?: string;
|
|
@@ -27,13 +28,19 @@ export interface SwcBuilderOptions {
|
|
|
27
28
|
export interface WebpackBuilderOptions {
|
|
28
29
|
configPath?: string;
|
|
29
30
|
}
|
|
31
|
+
export interface RspackBuilderOptions {
|
|
32
|
+
configPath?: string;
|
|
33
|
+
}
|
|
30
34
|
export interface TscBuilderOptions {
|
|
31
35
|
configPath?: string;
|
|
32
36
|
}
|
|
33
|
-
export type BuilderVariant = 'tsc' | 'swc' | 'webpack';
|
|
37
|
+
export type BuilderVariant = 'tsc' | 'swc' | 'webpack' | 'rspack';
|
|
34
38
|
export type Builder = BuilderVariant | {
|
|
35
39
|
type: 'webpack';
|
|
36
40
|
options?: WebpackBuilderOptions;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'rspack';
|
|
43
|
+
options?: RspackBuilderOptions;
|
|
37
44
|
} | {
|
|
38
45
|
type: 'swc';
|
|
39
46
|
options?: SwcBuilderOptions;
|
|
@@ -54,12 +61,19 @@ export interface CompilerOptions {
|
|
|
54
61
|
plugins?: string[] | PluginOptions[];
|
|
55
62
|
assets?: Asset[];
|
|
56
63
|
deleteOutDir?: boolean;
|
|
64
|
+
allowOutsidePaths?: boolean;
|
|
57
65
|
manualRestart?: boolean;
|
|
58
66
|
builder?: Builder;
|
|
67
|
+
emitDeclarations?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* List of library project names whose assets should also be copied
|
|
70
|
+
* when building this application.
|
|
71
|
+
*/
|
|
72
|
+
includeLibraryAssets?: string[];
|
|
59
73
|
}
|
|
60
74
|
export interface PluginOptions {
|
|
61
75
|
name: string;
|
|
62
|
-
options: Record<string, any
|
|
76
|
+
options: Record<string, any>;
|
|
63
77
|
}
|
|
64
78
|
export interface GenerateOptions {
|
|
65
79
|
spec?: boolean | Record<string, boolean>;
|
|
@@ -76,7 +90,6 @@ export interface ProjectConfiguration {
|
|
|
76
90
|
compilerOptions?: CompilerOptions;
|
|
77
91
|
}
|
|
78
92
|
export interface Configuration {
|
|
79
|
-
[key: string]: any;
|
|
80
93
|
language?: string;
|
|
81
94
|
collection?: string;
|
|
82
95
|
sourceRoot?: string;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Configuration } from './configuration';
|
|
1
|
+
import { Configuration } from './configuration.js';
|
|
2
2
|
export declare const defaultConfiguration: Required<Configuration>;
|
|
3
3
|
export declare const defaultTsconfigFilename: string;
|
|
4
4
|
export declare const defaultWebpackConfigFilename = "webpack.config.js";
|
|
5
|
+
export declare const defaultRspackConfigFilename = "rspack.config.js";
|
|
5
6
|
export declare const defaultOutDir = "dist";
|
|
6
7
|
export declare const defaultGitIgnore = "# compiled output\n/dist\n/node_modules\n/build\n\n# Logs\nlogs\n*.log\nnpm-debug.log*\npnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\nlerna-debug.log*\n\n# OS\n.DS_Store\n\n# Tests\n/coverage\n/.nyc_output\n\n# IDEs and editors\n/.idea\n.project\n.classpath\n.c9/\n*.launch\n.settings/\n*.sublime-workspace\n\n# IDE - VSCode\n.vscode/*\n!.vscode/settings.json\n!.vscode/tasks.json\n!.vscode/launch.json\n!.vscode/extensions.json\n\n# dotenv environment variable files\n.env\n.env.development.local\n.env.test.local\n.env.production.local\n.env.local\n\n# temp directory\n.temp\n.tmp\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Diagnostic reports (https://nodejs.org/api/report.html)\nreport.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json\n";
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.defaultGitIgnore = exports.defaultOutDir = exports.defaultWebpackConfigFilename = exports.defaultTsconfigFilename = exports.defaultConfiguration = void 0;
|
|
4
|
-
const get_default_tsconfig_path_1 = require("../utils/get-default-tsconfig-path");
|
|
5
|
-
exports.defaultConfiguration = {
|
|
1
|
+
import { getDefaultTsconfigPath } from '../utils/get-default-tsconfig-path.js';
|
|
2
|
+
export const defaultConfiguration = {
|
|
6
3
|
language: 'ts',
|
|
7
4
|
sourceRoot: 'src',
|
|
8
5
|
collection: '@nestjs/schematics',
|
|
@@ -14,7 +11,7 @@ exports.defaultConfiguration = {
|
|
|
14
11
|
builder: {
|
|
15
12
|
type: 'tsc',
|
|
16
13
|
options: {
|
|
17
|
-
configPath:
|
|
14
|
+
configPath: getDefaultTsconfigPath(),
|
|
18
15
|
},
|
|
19
16
|
},
|
|
20
17
|
webpack: false,
|
|
@@ -24,10 +21,11 @@ exports.defaultConfiguration = {
|
|
|
24
21
|
},
|
|
25
22
|
generateOptions: {},
|
|
26
23
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
export const defaultTsconfigFilename = getDefaultTsconfigPath();
|
|
25
|
+
export const defaultWebpackConfigFilename = 'webpack.config.js';
|
|
26
|
+
export const defaultRspackConfigFilename = 'rspack.config.js';
|
|
27
|
+
export const defaultOutDir = 'dist';
|
|
28
|
+
export const defaultGitIgnore = `# compiled output
|
|
31
29
|
/dist
|
|
32
30
|
/node_modules
|
|
33
31
|
/build
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './configuration.loader';
|
|
2
|
-
export * from './nest-configuration.loader';
|
|
3
|
-
export * from './configuration';
|
|
1
|
+
export * from './configuration.loader.js';
|
|
2
|
+
export * from './nest-configuration.loader.js';
|
|
3
|
+
export * from './configuration.js';
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./configuration.loader"), exports);
|
|
18
|
-
__exportStar(require("./nest-configuration.loader"), exports);
|
|
19
|
-
__exportStar(require("./configuration"), exports);
|
|
1
|
+
export * from './configuration.loader.js';
|
|
2
|
+
export * from './nest-configuration.loader.js';
|
|
3
|
+
export * from './configuration.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Reader } from '../readers';
|
|
2
|
-
import { Configuration } from './configuration';
|
|
3
|
-
import { ConfigurationLoader } from './configuration.loader';
|
|
1
|
+
import { Reader } from '../readers/index.js';
|
|
2
|
+
import { Configuration } from './configuration.js';
|
|
3
|
+
import { ConfigurationLoader } from './configuration.loader.js';
|
|
4
4
|
export declare class NestConfigurationLoader implements ConfigurationLoader {
|
|
5
5
|
private readonly reader;
|
|
6
6
|
constructor(reader: Reader);
|