@xfe-repo/bff-app 1.5.1 → 1.5.2

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.
@@ -0,0 +1,37 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-O6YSETKJ.mjs";
4
+
5
+ // src/path-resolver.ts
6
+ import fs from "fs";
7
+ import path from "path";
8
+ var INTERNAL_BFF_PACKAGES_DIR = "../../packages/bff";
9
+ var SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
10
+ var IGNORED_PACKAGE_NAME = "bff-app";
11
+ function collectScopedPackageDistPaths(cwd) {
12
+ const scopedPackagesPath = path.resolve(cwd, SCOPE_PACKAGES_DIR);
13
+ if (!fs.existsSync(scopedPackagesPath)) {
14
+ return [];
15
+ }
16
+ return fs.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== IGNORED_PACKAGE_NAME).map((packageName) => path.join(scopedPackagesPath, packageName)).filter((packageLinkPath) => fs.existsSync(packageLinkPath)).map((packageLinkPath) => fs.realpathSync(packageLinkPath)).map((packageRootPath) => path.join(packageRootPath, "dist")).filter((distPath) => fs.existsSync(distPath));
17
+ }
18
+ __name(collectScopedPackageDistPaths, "collectScopedPackageDistPaths");
19
+ function collectInternalPackageDistPaths(cwd) {
20
+ const packagesRootPath = path.resolve(cwd, INTERNAL_BFF_PACKAGES_DIR);
21
+ if (!fs.existsSync(packagesRootPath)) {
22
+ return [];
23
+ }
24
+ return fs.readdirSync(packagesRootPath).filter((packageName) => packageName !== "app").map((packageName) => path.join(packagesRootPath, packageName, "dist")).filter((distPath) => fs.existsSync(distPath));
25
+ }
26
+ __name(collectInternalPackageDistPaths, "collectInternalPackageDistPaths");
27
+ function collectBffPackageDistPaths(cwd) {
28
+ const watchTargets = /* @__PURE__ */ new Set();
29
+ collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
30
+ collectInternalPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
31
+ return Array.from(watchTargets);
32
+ }
33
+ __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
34
+
35
+ export {
36
+ collectBffPackageDistPaths
37
+ };
@@ -0,0 +1,36 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-O6YSETKJ.mjs";
4
+
5
+ // src/watch-manager.ts
6
+ import fs from "fs";
7
+ var JS_OUTPUT_FILE_REGEX = /\.(cjs|mjs|js)$/;
8
+ function shouldRestartOnFileChange(fileName) {
9
+ return JS_OUTPUT_FILE_REGEX.test(fileName);
10
+ }
11
+ __name(shouldRestartOnFileChange, "shouldRestartOnFileChange");
12
+ function createWatcher(watchPath, onChange) {
13
+ if (!fs.existsSync(watchPath)) {
14
+ return null;
15
+ }
16
+ return fs.watch(watchPath, {
17
+ recursive: true
18
+ }, (_eventType, filename) => {
19
+ if (!filename) {
20
+ return;
21
+ }
22
+ if (shouldRestartOnFileChange(filename.toString())) {
23
+ onChange();
24
+ }
25
+ });
26
+ }
27
+ __name(createWatcher, "createWatcher");
28
+ function closeWatchers(watchers) {
29
+ watchers.forEach((watcher) => watcher?.close());
30
+ }
31
+ __name(closeWatchers, "closeWatchers");
32
+
33
+ export {
34
+ createWatcher,
35
+ closeWatchers
36
+ };
@@ -1,5 +1,6 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import {
2
+ __name
3
+ } from "./chunk-O6YSETKJ.mjs";
3
4
 
4
5
  // src/config.ts
5
6
  import fs from "fs";
@@ -46,7 +47,6 @@ var configDeploy = /* @__PURE__ */ __name(() => {
46
47
  }, "configDeploy");
47
48
 
48
49
  export {
49
- __name,
50
50
  loadXfeConfig,
51
51
  configDeploy
52
52
  };
@@ -0,0 +1,129 @@
1
+ import {
2
+ collectBffPackageDistPaths
3
+ } from "./chunk-67SKOZPM.mjs";
4
+ import {
5
+ closeWatchers,
6
+ createWatcher
7
+ } from "./chunk-BAUM5HSG.mjs";
8
+ import {
9
+ __name
10
+ } from "./chunk-O6YSETKJ.mjs";
11
+
12
+ // src/process-manager.ts
13
+ import { execSync, spawn } from "child_process";
14
+ import path from "path";
15
+ var FILE_CHANGE_DEBOUNCE_MS = 300;
16
+ var RESTART_GUARD_MS = 5e3;
17
+ function spawnCommand(command) {
18
+ return spawn(command, {
19
+ stdio: "inherit",
20
+ env: process.env,
21
+ shell: true
22
+ });
23
+ }
24
+ __name(spawnCommand, "spawnCommand");
25
+ function runNestBuild(argsString) {
26
+ execSync(`nest build ${argsString}`, {
27
+ stdio: "inherit",
28
+ env: process.env
29
+ });
30
+ }
31
+ __name(runNestBuild, "runNestBuild");
32
+ function startAppProcess() {
33
+ return spawnCommand("node dist/main.js");
34
+ }
35
+ __name(startAppProcess, "startAppProcess");
36
+ function killProcess(child) {
37
+ if (!child.killed) {
38
+ child.kill("SIGTERM");
39
+ }
40
+ }
41
+ __name(killProcess, "killProcess");
42
+ function runDevCommand(argsString) {
43
+ const cwd = process.cwd();
44
+ runNestBuild(argsString);
45
+ const buildWatcherProcess = spawnCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
46
+ let appProcess = startAppProcess();
47
+ let isClosing = false;
48
+ let isRestarting = false;
49
+ let restartTimer = null;
50
+ const ignoreRestartBefore = Date.now() + RESTART_GUARD_MS;
51
+ const appDistWatcher = createWatcher(path.resolve(cwd, "dist"), scheduleRestart);
52
+ const packageWatchers = collectBffPackageDistPaths(cwd).map((watchPath) => createWatcher(watchPath, scheduleRestart)).filter((watcher) => Boolean(watcher));
53
+ function exitAll(code = 0) {
54
+ isClosing = true;
55
+ if (restartTimer) {
56
+ clearTimeout(restartTimer);
57
+ restartTimer = null;
58
+ }
59
+ closeWatchers([
60
+ appDistWatcher,
61
+ ...packageWatchers
62
+ ]);
63
+ killProcess(appProcess);
64
+ killProcess(buildWatcherProcess);
65
+ process.exit(code);
66
+ }
67
+ __name(exitAll, "exitAll");
68
+ function attachAppExitGuard() {
69
+ appProcess.on("exit", (code) => {
70
+ if (isClosing || isRestarting) {
71
+ return;
72
+ }
73
+ if (code !== 0) {
74
+ console.error(`node dist/main.js \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
75
+ exitAll(code ?? 1);
76
+ }
77
+ });
78
+ }
79
+ __name(attachAppExitGuard, "attachAppExitGuard");
80
+ function restartApp() {
81
+ if (isClosing || isRestarting) {
82
+ return;
83
+ }
84
+ isRestarting = true;
85
+ const startNextApp = /* @__PURE__ */ __name(() => {
86
+ if (isClosing) {
87
+ return;
88
+ }
89
+ appProcess = startAppProcess();
90
+ attachAppExitGuard();
91
+ isRestarting = false;
92
+ }, "startNextApp");
93
+ if (appProcess.killed) {
94
+ startNextApp();
95
+ return;
96
+ }
97
+ appProcess.once("exit", startNextApp);
98
+ killProcess(appProcess);
99
+ }
100
+ __name(restartApp, "restartApp");
101
+ function scheduleRestart() {
102
+ if (Date.now() < ignoreRestartBefore) {
103
+ return;
104
+ }
105
+ if (restartTimer) {
106
+ clearTimeout(restartTimer);
107
+ }
108
+ restartTimer = setTimeout(restartApp, FILE_CHANGE_DEBOUNCE_MS);
109
+ }
110
+ __name(scheduleRestart, "scheduleRestart");
111
+ process.on("SIGINT", () => exitAll(0));
112
+ process.on("SIGTERM", () => exitAll(0));
113
+ buildWatcherProcess.on("exit", (code) => {
114
+ if (isClosing) {
115
+ return;
116
+ }
117
+ if (code !== 0) {
118
+ console.error(`nest build --watch \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
119
+ exitAll(code ?? 1);
120
+ }
121
+ });
122
+ attachAppExitGuard();
123
+ }
124
+ __name(runDevCommand, "runDevCommand");
125
+
126
+ export {
127
+ runNestBuild,
128
+ runDevCommand
129
+ };
@@ -0,0 +1,6 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ export {
5
+ __name
6
+ };
package/dist/cli.js CHANGED
@@ -24,9 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
 
26
26
  // src/cli.ts
27
- var import_child_process = require("child_process");
28
- var import_fs2 = __toESM(require("fs"));
29
- var import_path2 = __toESM(require("path"));
30
27
  var import_minimist = __toESM(require("minimist"));
31
28
 
32
29
  // src/config.ts
@@ -73,185 +70,221 @@ var configDeploy = /* @__PURE__ */ __name(() => {
73
70
  import_fs.default.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
74
71
  }, "configDeploy");
75
72
 
76
- // src/cli.ts
77
- var argv = (0, import_minimist.default)(process.argv.slice(2));
78
- var { _: commands, ...args } = argv;
79
- var [command] = commands;
80
- var env = process.env;
81
- var argsString = Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
82
- var runCommand = /* @__PURE__ */ __name((command2) => {
83
- return (0, import_child_process.spawn)(command2, {
84
- stdio: "inherit",
85
- env,
86
- shell: true
87
- });
88
- }, "runCommand");
89
- var runNodeProcess = /* @__PURE__ */ __name(() => {
90
- return runCommand("node dist/main.js");
91
- }, "runNodeProcess");
92
- var collectBffPackageDistPaths = /* @__PURE__ */ __name(() => {
93
- const distPaths = /* @__PURE__ */ new Set();
94
- const scopedPackagesPath = import_path2.default.resolve(process.cwd(), "node_modules/@xfe-repo");
95
- if (import_fs2.default.existsSync(scopedPackagesPath)) {
96
- const packageDirNames = import_fs2.default.readdirSync(scopedPackagesPath);
97
- packageDirNames.forEach((packageDirName) => {
98
- if (!packageDirName.startsWith("bff-") || packageDirName === "bff-app") {
99
- return;
100
- }
101
- const packageNodeModulesPath = import_path2.default.join(scopedPackagesPath, packageDirName);
102
- if (!import_fs2.default.existsSync(packageNodeModulesPath)) {
103
- return;
104
- }
105
- const packageRootPath = import_fs2.default.realpathSync(packageNodeModulesPath);
106
- const packageDistPath = import_path2.default.join(packageRootPath, "dist");
107
- if (import_fs2.default.existsSync(packageDistPath)) {
108
- distPaths.add(packageDistPath);
109
- }
110
- });
73
+ // src/process-manager.ts
74
+ var import_child_process = require("child_process");
75
+ var import_path3 = __toESM(require("path"));
76
+
77
+ // src/path-resolver.ts
78
+ var import_fs2 = __toESM(require("fs"));
79
+ var import_path2 = __toESM(require("path"));
80
+ var INTERNAL_BFF_PACKAGES_DIR = "../../packages/bff";
81
+ var SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
82
+ var IGNORED_PACKAGE_NAME = "bff-app";
83
+ function collectScopedPackageDistPaths(cwd) {
84
+ const scopedPackagesPath = import_path2.default.resolve(cwd, SCOPE_PACKAGES_DIR);
85
+ if (!import_fs2.default.existsSync(scopedPackagesPath)) {
86
+ return [];
111
87
  }
112
- const bffPackagesPath = import_path2.default.resolve(process.cwd(), "../../packages/bff");
113
- if (import_fs2.default.existsSync(bffPackagesPath)) {
114
- const packageDirs = import_fs2.default.readdirSync(bffPackagesPath);
115
- packageDirs.forEach((packageDirName) => {
116
- if (packageDirName === "app") {
117
- return;
118
- }
119
- const packageDistPath = import_path2.default.join(bffPackagesPath, packageDirName, "dist");
120
- if (import_fs2.default.existsSync(packageDistPath)) {
121
- distPaths.add(packageDistPath);
122
- }
123
- });
88
+ return import_fs2.default.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== IGNORED_PACKAGE_NAME).map((packageName) => import_path2.default.join(scopedPackagesPath, packageName)).filter((packageLinkPath) => import_fs2.default.existsSync(packageLinkPath)).map((packageLinkPath) => import_fs2.default.realpathSync(packageLinkPath)).map((packageRootPath) => import_path2.default.join(packageRootPath, "dist")).filter((distPath) => import_fs2.default.existsSync(distPath));
89
+ }
90
+ __name(collectScopedPackageDistPaths, "collectScopedPackageDistPaths");
91
+ function collectInternalPackageDistPaths(cwd) {
92
+ const packagesRootPath = import_path2.default.resolve(cwd, INTERNAL_BFF_PACKAGES_DIR);
93
+ if (!import_fs2.default.existsSync(packagesRootPath)) {
94
+ return [];
124
95
  }
125
- return Array.from(distPaths);
126
- }, "collectBffPackageDistPaths");
127
- var watchDirectory = /* @__PURE__ */ __name((watchPath, onChange) => {
128
- if (!import_fs2.default.existsSync(watchPath)) {
96
+ return import_fs2.default.readdirSync(packagesRootPath).filter((packageName) => packageName !== "app").map((packageName) => import_path2.default.join(packagesRootPath, packageName, "dist")).filter((distPath) => import_fs2.default.existsSync(distPath));
97
+ }
98
+ __name(collectInternalPackageDistPaths, "collectInternalPackageDistPaths");
99
+ function collectBffPackageDistPaths(cwd) {
100
+ const watchTargets = /* @__PURE__ */ new Set();
101
+ collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
102
+ collectInternalPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
103
+ return Array.from(watchTargets);
104
+ }
105
+ __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
106
+
107
+ // src/watch-manager.ts
108
+ var import_fs3 = __toESM(require("fs"));
109
+ var JS_OUTPUT_FILE_REGEX = /\.(cjs|mjs|js)$/;
110
+ function shouldRestartOnFileChange(fileName) {
111
+ return JS_OUTPUT_FILE_REGEX.test(fileName);
112
+ }
113
+ __name(shouldRestartOnFileChange, "shouldRestartOnFileChange");
114
+ function createWatcher(watchPath, onChange) {
115
+ if (!import_fs3.default.existsSync(watchPath)) {
129
116
  return null;
130
117
  }
131
- return import_fs2.default.watch(watchPath, {
118
+ return import_fs3.default.watch(watchPath, {
132
119
  recursive: true
133
120
  }, (_eventType, filename) => {
134
- if (!filename) return;
135
- const fileName = filename.toString();
136
- if (!fileName.endsWith(".js") && !fileName.endsWith(".mjs") && !fileName.endsWith(".cjs")) {
121
+ if (!filename) {
137
122
  return;
138
123
  }
139
- onChange();
124
+ if (shouldRestartOnFileChange(filename.toString())) {
125
+ onChange();
126
+ }
127
+ });
128
+ }
129
+ __name(createWatcher, "createWatcher");
130
+ function closeWatchers(watchers) {
131
+ watchers.forEach((watcher) => watcher?.close());
132
+ }
133
+ __name(closeWatchers, "closeWatchers");
134
+
135
+ // src/process-manager.ts
136
+ var FILE_CHANGE_DEBOUNCE_MS = 300;
137
+ var RESTART_GUARD_MS = 5e3;
138
+ function spawnCommand(command) {
139
+ return (0, import_child_process.spawn)(command, {
140
+ stdio: "inherit",
141
+ env: process.env,
142
+ shell: true
140
143
  });
141
- }, "watchDirectory");
142
- function devCommand() {
144
+ }
145
+ __name(spawnCommand, "spawnCommand");
146
+ function runNestBuild(argsString) {
143
147
  (0, import_child_process.execSync)(`nest build ${argsString}`, {
144
148
  stdio: "inherit",
145
- env
149
+ env: process.env
146
150
  });
147
- const watchBuildProcess = runCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
148
- let appProcess = runNodeProcess();
151
+ }
152
+ __name(runNestBuild, "runNestBuild");
153
+ function startAppProcess() {
154
+ return spawnCommand("node dist/main.js");
155
+ }
156
+ __name(startAppProcess, "startAppProcess");
157
+ function killProcess(child) {
158
+ if (!child.killed) {
159
+ child.kill("SIGTERM");
160
+ }
161
+ }
162
+ __name(killProcess, "killProcess");
163
+ function runDevCommand(argsString) {
164
+ const cwd = process.cwd();
165
+ runNestBuild(argsString);
166
+ const buildWatcherProcess = spawnCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
167
+ let appProcess = startAppProcess();
149
168
  let isClosing = false;
150
169
  let isRestarting = false;
151
170
  let restartTimer = null;
152
- const ignoreRestartBefore = Date.now() + 5e3;
153
- const restartAppProcess = /* @__PURE__ */ __name(() => {
154
- if (isClosing || isRestarting) return;
171
+ const ignoreRestartBefore = Date.now() + RESTART_GUARD_MS;
172
+ const appDistWatcher = createWatcher(import_path3.default.resolve(cwd, "dist"), scheduleRestart);
173
+ const packageWatchers = collectBffPackageDistPaths(cwd).map((watchPath) => createWatcher(watchPath, scheduleRestart)).filter((watcher) => Boolean(watcher));
174
+ function exitAll(code = 0) {
175
+ isClosing = true;
176
+ if (restartTimer) {
177
+ clearTimeout(restartTimer);
178
+ restartTimer = null;
179
+ }
180
+ closeWatchers([
181
+ appDistWatcher,
182
+ ...packageWatchers
183
+ ]);
184
+ killProcess(appProcess);
185
+ killProcess(buildWatcherProcess);
186
+ process.exit(code);
187
+ }
188
+ __name(exitAll, "exitAll");
189
+ function attachAppExitGuard() {
190
+ appProcess.on("exit", (code) => {
191
+ if (isClosing || isRestarting) {
192
+ return;
193
+ }
194
+ if (code !== 0) {
195
+ console.error(`node dist/main.js \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
196
+ exitAll(code ?? 1);
197
+ }
198
+ });
199
+ }
200
+ __name(attachAppExitGuard, "attachAppExitGuard");
201
+ function restartApp() {
202
+ if (isClosing || isRestarting) {
203
+ return;
204
+ }
155
205
  isRestarting = true;
156
- const startNext = /* @__PURE__ */ __name(() => {
157
- if (isClosing) return;
158
- appProcess = runNodeProcess();
159
- appProcess.on("exit", (code) => {
160
- if (isClosing || isRestarting) return;
161
- if (code !== 0) {
162
- console.error(`node dist/main.js \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
163
- closeWithCode(code ?? 1);
164
- }
165
- });
206
+ const startNextApp = /* @__PURE__ */ __name(() => {
207
+ if (isClosing) {
208
+ return;
209
+ }
210
+ appProcess = startAppProcess();
211
+ attachAppExitGuard();
166
212
  isRestarting = false;
167
- }, "startNext");
213
+ }, "startNextApp");
168
214
  if (appProcess.killed) {
169
- startNext();
215
+ startNextApp();
170
216
  return;
171
217
  }
172
- appProcess.once("exit", () => {
173
- startNext();
174
- });
175
- appProcess.kill("SIGTERM");
176
- }, "restartAppProcess");
177
- const scheduleRestart = /* @__PURE__ */ __name(() => {
218
+ appProcess.once("exit", startNextApp);
219
+ killProcess(appProcess);
220
+ }
221
+ __name(restartApp, "restartApp");
222
+ function scheduleRestart() {
178
223
  if (Date.now() < ignoreRestartBefore) {
179
224
  return;
180
225
  }
181
226
  if (restartTimer) {
182
227
  clearTimeout(restartTimer);
183
228
  }
184
- restartTimer = setTimeout(() => {
185
- restartAppProcess();
186
- }, 300);
187
- }, "scheduleRestart");
188
- const appDistWatcher = watchDirectory(import_path2.default.resolve(process.cwd(), "dist"), scheduleRestart);
189
- const bffPackageDistPaths = collectBffPackageDistPaths();
190
- const packageWatchers = [];
191
- bffPackageDistPaths.forEach((packageDistPath) => {
192
- const watcher = watchDirectory(packageDistPath, scheduleRestart);
193
- if (watcher) {
194
- packageWatchers.push(watcher);
195
- }
196
- });
197
- const allProcesses = [
198
- watchBuildProcess
199
- ];
200
- const closeAllProcesses = /* @__PURE__ */ __name(() => {
201
- isClosing = true;
202
- if (restartTimer) {
203
- clearTimeout(restartTimer);
204
- restartTimer = null;
205
- }
206
- appDistWatcher?.close();
207
- packageWatchers.forEach((watcher) => watcher.close());
208
- if (!appProcess.killed) {
209
- appProcess.kill("SIGTERM");
229
+ restartTimer = setTimeout(restartApp, FILE_CHANGE_DEBOUNCE_MS);
230
+ }
231
+ __name(scheduleRestart, "scheduleRestart");
232
+ process.on("SIGINT", () => exitAll(0));
233
+ process.on("SIGTERM", () => exitAll(0));
234
+ buildWatcherProcess.on("exit", (code) => {
235
+ if (isClosing) {
236
+ return;
210
237
  }
211
- allProcesses.forEach((child) => {
212
- if (!child.killed) {
213
- child.kill("SIGTERM");
214
- }
215
- });
216
- }, "closeAllProcesses");
217
- const closeWithCode = /* @__PURE__ */ __name((code = 0) => {
218
- closeAllProcesses();
219
- process.exit(code);
220
- }, "closeWithCode");
221
- process.on("SIGINT", () => closeWithCode(0));
222
- process.on("SIGTERM", () => closeWithCode(0));
223
- watchBuildProcess.on("exit", (code) => {
224
- if (isClosing) return;
225
238
  if (code !== 0) {
226
239
  console.error(`nest build --watch \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
227
- closeWithCode(code ?? 1);
228
- }
229
- });
230
- appProcess.on("exit", (code) => {
231
- if (isClosing || isRestarting) return;
232
- if (code !== 0) {
233
- console.error(`node dist/main.js \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
234
- closeWithCode(code ?? 1);
240
+ exitAll(code ?? 1);
235
241
  }
236
242
  });
243
+ attachAppExitGuard();
237
244
  }
238
- __name(devCommand, "devCommand");
239
- function main() {
240
- if (command === "dev") {
241
- devCommand();
242
- } else if (command === "build") {
243
- (0, import_child_process.execSync)(`nest build ${argsString}`, {
244
- stdio: "inherit",
245
- env
246
- });
247
- } else if (command === "config") {
248
- configDeploy();
245
+ __name(runDevCommand, "runDevCommand");
246
+
247
+ // src/cli.ts
248
+ function createArgsString(args) {
249
+ return Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
250
+ }
251
+ __name(createArgsString, "createArgsString");
252
+ function parseCliContext() {
253
+ const argv = (0, import_minimist.default)(process.argv.slice(2));
254
+ const { _: commands, ...rawArgs } = argv;
255
+ return {
256
+ command: commands[0],
257
+ argsString: createArgsString(rawArgs)
258
+ };
259
+ }
260
+ __name(parseCliContext, "parseCliContext");
261
+ function runBuild(argsString) {
262
+ runNestBuild(argsString);
263
+ }
264
+ __name(runBuild, "runBuild");
265
+ function runConfig() {
266
+ configDeploy();
267
+ }
268
+ __name(runConfig, "runConfig");
269
+ function runCommandByType(context) {
270
+ if (context.command === "dev") {
271
+ runDevCommand(context.argsString);
272
+ return;
273
+ }
274
+ if (context.command === "build") {
275
+ runBuild(context.argsString);
276
+ return;
277
+ }
278
+ if (context.command === "config") {
279
+ runConfig();
280
+ return;
249
281
  }
282
+ throw new Error(`Unsupported command: ${context.command ?? "undefined"}`);
250
283
  }
251
- __name(main, "main");
284
+ __name(runCommandByType, "runCommandByType");
252
285
  try {
253
- main();
254
- } catch (err) {
255
- console.error("XFE Mini CLI \u6267\u884C\u51FA\u9519:", err);
286
+ runCommandByType(parseCliContext());
287
+ } catch (error) {
288
+ console.error("XFE BFF CLI \u6267\u884C\u51FA\u9519:", error);
256
289
  process.exit(1);
257
290
  }
package/dist/cli.mjs CHANGED
@@ -1,191 +1,58 @@
1
1
  import {
2
- __name,
3
2
  configDeploy
4
- } from "./chunk-7MBWBSGL.mjs";
3
+ } from "./chunk-CUZB5IYH.mjs";
4
+ import {
5
+ runDevCommand,
6
+ runNestBuild
7
+ } from "./chunk-IX37L3FU.mjs";
8
+ import "./chunk-67SKOZPM.mjs";
9
+ import "./chunk-BAUM5HSG.mjs";
10
+ import {
11
+ __name
12
+ } from "./chunk-O6YSETKJ.mjs";
5
13
 
6
14
  // src/cli.ts
7
- import { execSync, spawn } from "child_process";
8
- import fs from "fs";
9
- import path from "path";
10
15
  import minimist from "minimist";
11
- var argv = minimist(process.argv.slice(2));
12
- var { _: commands, ...args } = argv;
13
- var [command] = commands;
14
- var env = process.env;
15
- var argsString = Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
16
- var runCommand = /* @__PURE__ */ __name((command2) => {
17
- return spawn(command2, {
18
- stdio: "inherit",
19
- env,
20
- shell: true
21
- });
22
- }, "runCommand");
23
- var runNodeProcess = /* @__PURE__ */ __name(() => {
24
- return runCommand("node dist/main.js");
25
- }, "runNodeProcess");
26
- var collectBffPackageDistPaths = /* @__PURE__ */ __name(() => {
27
- const distPaths = /* @__PURE__ */ new Set();
28
- const scopedPackagesPath = path.resolve(process.cwd(), "node_modules/@xfe-repo");
29
- if (fs.existsSync(scopedPackagesPath)) {
30
- const packageDirNames = fs.readdirSync(scopedPackagesPath);
31
- packageDirNames.forEach((packageDirName) => {
32
- if (!packageDirName.startsWith("bff-") || packageDirName === "bff-app") {
33
- return;
34
- }
35
- const packageNodeModulesPath = path.join(scopedPackagesPath, packageDirName);
36
- if (!fs.existsSync(packageNodeModulesPath)) {
37
- return;
38
- }
39
- const packageRootPath = fs.realpathSync(packageNodeModulesPath);
40
- const packageDistPath = path.join(packageRootPath, "dist");
41
- if (fs.existsSync(packageDistPath)) {
42
- distPaths.add(packageDistPath);
43
- }
44
- });
45
- }
46
- const bffPackagesPath = path.resolve(process.cwd(), "../../packages/bff");
47
- if (fs.existsSync(bffPackagesPath)) {
48
- const packageDirs = fs.readdirSync(bffPackagesPath);
49
- packageDirs.forEach((packageDirName) => {
50
- if (packageDirName === "app") {
51
- return;
52
- }
53
- const packageDistPath = path.join(bffPackagesPath, packageDirName, "dist");
54
- if (fs.existsSync(packageDistPath)) {
55
- distPaths.add(packageDistPath);
56
- }
57
- });
16
+ function createArgsString(args) {
17
+ return Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
18
+ }
19
+ __name(createArgsString, "createArgsString");
20
+ function parseCliContext() {
21
+ const argv = minimist(process.argv.slice(2));
22
+ const { _: commands, ...rawArgs } = argv;
23
+ return {
24
+ command: commands[0],
25
+ argsString: createArgsString(rawArgs)
26
+ };
27
+ }
28
+ __name(parseCliContext, "parseCliContext");
29
+ function runBuild(argsString) {
30
+ runNestBuild(argsString);
31
+ }
32
+ __name(runBuild, "runBuild");
33
+ function runConfig() {
34
+ configDeploy();
35
+ }
36
+ __name(runConfig, "runConfig");
37
+ function runCommandByType(context) {
38
+ if (context.command === "dev") {
39
+ runDevCommand(context.argsString);
40
+ return;
58
41
  }
59
- return Array.from(distPaths);
60
- }, "collectBffPackageDistPaths");
61
- var watchDirectory = /* @__PURE__ */ __name((watchPath, onChange) => {
62
- if (!fs.existsSync(watchPath)) {
63
- return null;
42
+ if (context.command === "build") {
43
+ runBuild(context.argsString);
44
+ return;
64
45
  }
65
- return fs.watch(watchPath, {
66
- recursive: true
67
- }, (_eventType, filename) => {
68
- if (!filename) return;
69
- const fileName = filename.toString();
70
- if (!fileName.endsWith(".js") && !fileName.endsWith(".mjs") && !fileName.endsWith(".cjs")) {
71
- return;
72
- }
73
- onChange();
74
- });
75
- }, "watchDirectory");
76
- function devCommand() {
77
- execSync(`nest build ${argsString}`, {
78
- stdio: "inherit",
79
- env
80
- });
81
- const watchBuildProcess = runCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
82
- let appProcess = runNodeProcess();
83
- let isClosing = false;
84
- let isRestarting = false;
85
- let restartTimer = null;
86
- const ignoreRestartBefore = Date.now() + 5e3;
87
- const restartAppProcess = /* @__PURE__ */ __name(() => {
88
- if (isClosing || isRestarting) return;
89
- isRestarting = true;
90
- const startNext = /* @__PURE__ */ __name(() => {
91
- if (isClosing) return;
92
- appProcess = runNodeProcess();
93
- appProcess.on("exit", (code) => {
94
- if (isClosing || isRestarting) return;
95
- if (code !== 0) {
96
- console.error(`node dist/main.js \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
97
- closeWithCode(code ?? 1);
98
- }
99
- });
100
- isRestarting = false;
101
- }, "startNext");
102
- if (appProcess.killed) {
103
- startNext();
104
- return;
105
- }
106
- appProcess.once("exit", () => {
107
- startNext();
108
- });
109
- appProcess.kill("SIGTERM");
110
- }, "restartAppProcess");
111
- const scheduleRestart = /* @__PURE__ */ __name(() => {
112
- if (Date.now() < ignoreRestartBefore) {
113
- return;
114
- }
115
- if (restartTimer) {
116
- clearTimeout(restartTimer);
117
- }
118
- restartTimer = setTimeout(() => {
119
- restartAppProcess();
120
- }, 300);
121
- }, "scheduleRestart");
122
- const appDistWatcher = watchDirectory(path.resolve(process.cwd(), "dist"), scheduleRestart);
123
- const bffPackageDistPaths = collectBffPackageDistPaths();
124
- const packageWatchers = [];
125
- bffPackageDistPaths.forEach((packageDistPath) => {
126
- const watcher = watchDirectory(packageDistPath, scheduleRestart);
127
- if (watcher) {
128
- packageWatchers.push(watcher);
129
- }
130
- });
131
- const allProcesses = [
132
- watchBuildProcess
133
- ];
134
- const closeAllProcesses = /* @__PURE__ */ __name(() => {
135
- isClosing = true;
136
- if (restartTimer) {
137
- clearTimeout(restartTimer);
138
- restartTimer = null;
139
- }
140
- appDistWatcher?.close();
141
- packageWatchers.forEach((watcher) => watcher.close());
142
- if (!appProcess.killed) {
143
- appProcess.kill("SIGTERM");
144
- }
145
- allProcesses.forEach((child) => {
146
- if (!child.killed) {
147
- child.kill("SIGTERM");
148
- }
149
- });
150
- }, "closeAllProcesses");
151
- const closeWithCode = /* @__PURE__ */ __name((code = 0) => {
152
- closeAllProcesses();
153
- process.exit(code);
154
- }, "closeWithCode");
155
- process.on("SIGINT", () => closeWithCode(0));
156
- process.on("SIGTERM", () => closeWithCode(0));
157
- watchBuildProcess.on("exit", (code) => {
158
- if (isClosing) return;
159
- if (code !== 0) {
160
- console.error(`nest build --watch \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
161
- closeWithCode(code ?? 1);
162
- }
163
- });
164
- appProcess.on("exit", (code) => {
165
- if (isClosing || isRestarting) return;
166
- if (code !== 0) {
167
- console.error(`node dist/main.js \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
168
- closeWithCode(code ?? 1);
169
- }
170
- });
171
- }
172
- __name(devCommand, "devCommand");
173
- function main() {
174
- if (command === "dev") {
175
- devCommand();
176
- } else if (command === "build") {
177
- execSync(`nest build ${argsString}`, {
178
- stdio: "inherit",
179
- env
180
- });
181
- } else if (command === "config") {
182
- configDeploy();
46
+ if (context.command === "config") {
47
+ runConfig();
48
+ return;
183
49
  }
50
+ throw new Error(`Unsupported command: ${context.command ?? "undefined"}`);
184
51
  }
185
- __name(main, "main");
52
+ __name(runCommandByType, "runCommandByType");
186
53
  try {
187
- main();
188
- } catch (err) {
189
- console.error("XFE Mini CLI \u6267\u884C\u51FA\u9519:", err);
54
+ runCommandByType(parseCliContext());
55
+ } catch (error) {
56
+ console.error("XFE BFF CLI \u6267\u884C\u51FA\u9519:", error);
190
57
  process.exit(1);
191
58
  }
package/dist/config.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  configDeploy,
3
3
  loadXfeConfig
4
- } from "./chunk-7MBWBSGL.mjs";
4
+ } from "./chunk-CUZB5IYH.mjs";
5
+ import "./chunk-O6YSETKJ.mjs";
5
6
  export {
6
7
  configDeploy,
7
8
  loadXfeConfig
@@ -0,0 +1,3 @@
1
+ declare function collectBffPackageDistPaths(cwd: string): string[];
2
+
3
+ export { collectBffPackageDistPaths };
@@ -0,0 +1,3 @@
1
+ declare function collectBffPackageDistPaths(cwd: string): string[];
2
+
3
+ export { collectBffPackageDistPaths };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/path-resolver.ts
32
+ var path_resolver_exports = {};
33
+ __export(path_resolver_exports, {
34
+ collectBffPackageDistPaths: () => collectBffPackageDistPaths
35
+ });
36
+ module.exports = __toCommonJS(path_resolver_exports);
37
+ var import_fs = __toESM(require("fs"));
38
+ var import_path = __toESM(require("path"));
39
+ var INTERNAL_BFF_PACKAGES_DIR = "../../packages/bff";
40
+ var SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
41
+ var IGNORED_PACKAGE_NAME = "bff-app";
42
+ function collectScopedPackageDistPaths(cwd) {
43
+ const scopedPackagesPath = import_path.default.resolve(cwd, SCOPE_PACKAGES_DIR);
44
+ if (!import_fs.default.existsSync(scopedPackagesPath)) {
45
+ return [];
46
+ }
47
+ return import_fs.default.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== IGNORED_PACKAGE_NAME).map((packageName) => import_path.default.join(scopedPackagesPath, packageName)).filter((packageLinkPath) => import_fs.default.existsSync(packageLinkPath)).map((packageLinkPath) => import_fs.default.realpathSync(packageLinkPath)).map((packageRootPath) => import_path.default.join(packageRootPath, "dist")).filter((distPath) => import_fs.default.existsSync(distPath));
48
+ }
49
+ __name(collectScopedPackageDistPaths, "collectScopedPackageDistPaths");
50
+ function collectInternalPackageDistPaths(cwd) {
51
+ const packagesRootPath = import_path.default.resolve(cwd, INTERNAL_BFF_PACKAGES_DIR);
52
+ if (!import_fs.default.existsSync(packagesRootPath)) {
53
+ return [];
54
+ }
55
+ return import_fs.default.readdirSync(packagesRootPath).filter((packageName) => packageName !== "app").map((packageName) => import_path.default.join(packagesRootPath, packageName, "dist")).filter((distPath) => import_fs.default.existsSync(distPath));
56
+ }
57
+ __name(collectInternalPackageDistPaths, "collectInternalPackageDistPaths");
58
+ function collectBffPackageDistPaths(cwd) {
59
+ const watchTargets = /* @__PURE__ */ new Set();
60
+ collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
61
+ collectInternalPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
62
+ return Array.from(watchTargets);
63
+ }
64
+ __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ collectBffPackageDistPaths
68
+ });
@@ -0,0 +1,7 @@
1
+ import {
2
+ collectBffPackageDistPaths
3
+ } from "./chunk-67SKOZPM.mjs";
4
+ import "./chunk-O6YSETKJ.mjs";
5
+ export {
6
+ collectBffPackageDistPaths
7
+ };
@@ -0,0 +1,4 @@
1
+ declare function runNestBuild(argsString: string): void;
2
+ declare function runDevCommand(argsString: string): void;
3
+
4
+ export { runDevCommand, runNestBuild };
@@ -0,0 +1,4 @@
1
+ declare function runNestBuild(argsString: string): void;
2
+ declare function runDevCommand(argsString: string): void;
3
+
4
+ export { runDevCommand, runNestBuild };
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/process-manager.ts
32
+ var process_manager_exports = {};
33
+ __export(process_manager_exports, {
34
+ runDevCommand: () => runDevCommand,
35
+ runNestBuild: () => runNestBuild
36
+ });
37
+ module.exports = __toCommonJS(process_manager_exports);
38
+ var import_child_process = require("child_process");
39
+ var import_path2 = __toESM(require("path"));
40
+
41
+ // src/path-resolver.ts
42
+ var import_fs = __toESM(require("fs"));
43
+ var import_path = __toESM(require("path"));
44
+ var INTERNAL_BFF_PACKAGES_DIR = "../../packages/bff";
45
+ var SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
46
+ var IGNORED_PACKAGE_NAME = "bff-app";
47
+ function collectScopedPackageDistPaths(cwd) {
48
+ const scopedPackagesPath = import_path.default.resolve(cwd, SCOPE_PACKAGES_DIR);
49
+ if (!import_fs.default.existsSync(scopedPackagesPath)) {
50
+ return [];
51
+ }
52
+ return import_fs.default.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== IGNORED_PACKAGE_NAME).map((packageName) => import_path.default.join(scopedPackagesPath, packageName)).filter((packageLinkPath) => import_fs.default.existsSync(packageLinkPath)).map((packageLinkPath) => import_fs.default.realpathSync(packageLinkPath)).map((packageRootPath) => import_path.default.join(packageRootPath, "dist")).filter((distPath) => import_fs.default.existsSync(distPath));
53
+ }
54
+ __name(collectScopedPackageDistPaths, "collectScopedPackageDistPaths");
55
+ function collectInternalPackageDistPaths(cwd) {
56
+ const packagesRootPath = import_path.default.resolve(cwd, INTERNAL_BFF_PACKAGES_DIR);
57
+ if (!import_fs.default.existsSync(packagesRootPath)) {
58
+ return [];
59
+ }
60
+ return import_fs.default.readdirSync(packagesRootPath).filter((packageName) => packageName !== "app").map((packageName) => import_path.default.join(packagesRootPath, packageName, "dist")).filter((distPath) => import_fs.default.existsSync(distPath));
61
+ }
62
+ __name(collectInternalPackageDistPaths, "collectInternalPackageDistPaths");
63
+ function collectBffPackageDistPaths(cwd) {
64
+ const watchTargets = /* @__PURE__ */ new Set();
65
+ collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
66
+ collectInternalPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
67
+ return Array.from(watchTargets);
68
+ }
69
+ __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
70
+
71
+ // src/watch-manager.ts
72
+ var import_fs2 = __toESM(require("fs"));
73
+ var JS_OUTPUT_FILE_REGEX = /\.(cjs|mjs|js)$/;
74
+ function shouldRestartOnFileChange(fileName) {
75
+ return JS_OUTPUT_FILE_REGEX.test(fileName);
76
+ }
77
+ __name(shouldRestartOnFileChange, "shouldRestartOnFileChange");
78
+ function createWatcher(watchPath, onChange) {
79
+ if (!import_fs2.default.existsSync(watchPath)) {
80
+ return null;
81
+ }
82
+ return import_fs2.default.watch(watchPath, {
83
+ recursive: true
84
+ }, (_eventType, filename) => {
85
+ if (!filename) {
86
+ return;
87
+ }
88
+ if (shouldRestartOnFileChange(filename.toString())) {
89
+ onChange();
90
+ }
91
+ });
92
+ }
93
+ __name(createWatcher, "createWatcher");
94
+ function closeWatchers(watchers) {
95
+ watchers.forEach((watcher) => watcher?.close());
96
+ }
97
+ __name(closeWatchers, "closeWatchers");
98
+
99
+ // src/process-manager.ts
100
+ var FILE_CHANGE_DEBOUNCE_MS = 300;
101
+ var RESTART_GUARD_MS = 5e3;
102
+ function spawnCommand(command) {
103
+ return (0, import_child_process.spawn)(command, {
104
+ stdio: "inherit",
105
+ env: process.env,
106
+ shell: true
107
+ });
108
+ }
109
+ __name(spawnCommand, "spawnCommand");
110
+ function runNestBuild(argsString) {
111
+ (0, import_child_process.execSync)(`nest build ${argsString}`, {
112
+ stdio: "inherit",
113
+ env: process.env
114
+ });
115
+ }
116
+ __name(runNestBuild, "runNestBuild");
117
+ function startAppProcess() {
118
+ return spawnCommand("node dist/main.js");
119
+ }
120
+ __name(startAppProcess, "startAppProcess");
121
+ function killProcess(child) {
122
+ if (!child.killed) {
123
+ child.kill("SIGTERM");
124
+ }
125
+ }
126
+ __name(killProcess, "killProcess");
127
+ function runDevCommand(argsString) {
128
+ const cwd = process.cwd();
129
+ runNestBuild(argsString);
130
+ const buildWatcherProcess = spawnCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
131
+ let appProcess = startAppProcess();
132
+ let isClosing = false;
133
+ let isRestarting = false;
134
+ let restartTimer = null;
135
+ const ignoreRestartBefore = Date.now() + RESTART_GUARD_MS;
136
+ const appDistWatcher = createWatcher(import_path2.default.resolve(cwd, "dist"), scheduleRestart);
137
+ const packageWatchers = collectBffPackageDistPaths(cwd).map((watchPath) => createWatcher(watchPath, scheduleRestart)).filter((watcher) => Boolean(watcher));
138
+ function exitAll(code = 0) {
139
+ isClosing = true;
140
+ if (restartTimer) {
141
+ clearTimeout(restartTimer);
142
+ restartTimer = null;
143
+ }
144
+ closeWatchers([
145
+ appDistWatcher,
146
+ ...packageWatchers
147
+ ]);
148
+ killProcess(appProcess);
149
+ killProcess(buildWatcherProcess);
150
+ process.exit(code);
151
+ }
152
+ __name(exitAll, "exitAll");
153
+ function attachAppExitGuard() {
154
+ appProcess.on("exit", (code) => {
155
+ if (isClosing || isRestarting) {
156
+ return;
157
+ }
158
+ if (code !== 0) {
159
+ console.error(`node dist/main.js \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
160
+ exitAll(code ?? 1);
161
+ }
162
+ });
163
+ }
164
+ __name(attachAppExitGuard, "attachAppExitGuard");
165
+ function restartApp() {
166
+ if (isClosing || isRestarting) {
167
+ return;
168
+ }
169
+ isRestarting = true;
170
+ const startNextApp = /* @__PURE__ */ __name(() => {
171
+ if (isClosing) {
172
+ return;
173
+ }
174
+ appProcess = startAppProcess();
175
+ attachAppExitGuard();
176
+ isRestarting = false;
177
+ }, "startNextApp");
178
+ if (appProcess.killed) {
179
+ startNextApp();
180
+ return;
181
+ }
182
+ appProcess.once("exit", startNextApp);
183
+ killProcess(appProcess);
184
+ }
185
+ __name(restartApp, "restartApp");
186
+ function scheduleRestart() {
187
+ if (Date.now() < ignoreRestartBefore) {
188
+ return;
189
+ }
190
+ if (restartTimer) {
191
+ clearTimeout(restartTimer);
192
+ }
193
+ restartTimer = setTimeout(restartApp, FILE_CHANGE_DEBOUNCE_MS);
194
+ }
195
+ __name(scheduleRestart, "scheduleRestart");
196
+ process.on("SIGINT", () => exitAll(0));
197
+ process.on("SIGTERM", () => exitAll(0));
198
+ buildWatcherProcess.on("exit", (code) => {
199
+ if (isClosing) {
200
+ return;
201
+ }
202
+ if (code !== 0) {
203
+ console.error(`nest build --watch \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
204
+ exitAll(code ?? 1);
205
+ }
206
+ });
207
+ attachAppExitGuard();
208
+ }
209
+ __name(runDevCommand, "runDevCommand");
210
+ // Annotate the CommonJS export names for ESM import in node:
211
+ 0 && (module.exports = {
212
+ runDevCommand,
213
+ runNestBuild
214
+ });
@@ -0,0 +1,11 @@
1
+ import {
2
+ runDevCommand,
3
+ runNestBuild
4
+ } from "./chunk-IX37L3FU.mjs";
5
+ import "./chunk-67SKOZPM.mjs";
6
+ import "./chunk-BAUM5HSG.mjs";
7
+ import "./chunk-O6YSETKJ.mjs";
8
+ export {
9
+ runDevCommand,
10
+ runNestBuild
11
+ };
@@ -0,0 +1,6 @@
1
+ import fs from 'fs';
2
+
3
+ declare function createWatcher(watchPath: string, onChange: () => void): fs.FSWatcher | null;
4
+ declare function closeWatchers(watchers: Array<fs.FSWatcher | null>): void;
5
+
6
+ export { closeWatchers, createWatcher };
@@ -0,0 +1,6 @@
1
+ import fs from 'fs';
2
+
3
+ declare function createWatcher(watchPath: string, onChange: () => void): fs.FSWatcher | null;
4
+ declare function closeWatchers(watchers: Array<fs.FSWatcher | null>): void;
5
+
6
+ export { closeWatchers, createWatcher };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/watch-manager.ts
32
+ var watch_manager_exports = {};
33
+ __export(watch_manager_exports, {
34
+ closeWatchers: () => closeWatchers,
35
+ createWatcher: () => createWatcher
36
+ });
37
+ module.exports = __toCommonJS(watch_manager_exports);
38
+ var import_fs = __toESM(require("fs"));
39
+ var JS_OUTPUT_FILE_REGEX = /\.(cjs|mjs|js)$/;
40
+ function shouldRestartOnFileChange(fileName) {
41
+ return JS_OUTPUT_FILE_REGEX.test(fileName);
42
+ }
43
+ __name(shouldRestartOnFileChange, "shouldRestartOnFileChange");
44
+ function createWatcher(watchPath, onChange) {
45
+ if (!import_fs.default.existsSync(watchPath)) {
46
+ return null;
47
+ }
48
+ return import_fs.default.watch(watchPath, {
49
+ recursive: true
50
+ }, (_eventType, filename) => {
51
+ if (!filename) {
52
+ return;
53
+ }
54
+ if (shouldRestartOnFileChange(filename.toString())) {
55
+ onChange();
56
+ }
57
+ });
58
+ }
59
+ __name(createWatcher, "createWatcher");
60
+ function closeWatchers(watchers) {
61
+ watchers.forEach((watcher) => watcher?.close());
62
+ }
63
+ __name(closeWatchers, "closeWatchers");
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ closeWatchers,
67
+ createWatcher
68
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ closeWatchers,
3
+ createWatcher
4
+ } from "./chunk-BAUM5HSG.mjs";
5
+ import "./chunk-O6YSETKJ.mjs";
6
+ export {
7
+ closeWatchers,
8
+ createWatcher
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xfe-repo/bff-app",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "bin": {
5
5
  "xfe-bff": "./bin/index.js"
6
6
  },