@xfe-repo/bff-app 1.5.2 → 1.5.4

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,26 @@
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
+ function collectScopedPackageDistPaths(cwd) {
9
+ const SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
10
+ const scopedPackagesPath = path.resolve(cwd, SCOPE_PACKAGES_DIR);
11
+ if (!fs.existsSync(scopedPackagesPath)) {
12
+ return [];
13
+ }
14
+ return fs.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== "bff-app").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));
15
+ }
16
+ __name(collectScopedPackageDistPaths, "collectScopedPackageDistPaths");
17
+ function collectBffPackageDistPaths(cwd) {
18
+ const watchTargets = /* @__PURE__ */ new Set();
19
+ collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
20
+ return Array.from(watchTargets);
21
+ }
22
+ __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
23
+
24
+ export {
25
+ collectBffPackageDistPaths
26
+ };
@@ -0,0 +1,37 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-PAWJFY3S.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
+ };
37
+ //# sourceMappingURL=chunk-7EO6CNQD.mjs.map
@@ -0,0 +1,135 @@
1
+ import {
2
+ collectBffPackageDistPaths
3
+ } from "./chunk-YR5ZIMNO.mjs";
4
+ import {
5
+ closeWatchers,
6
+ createWatcher
7
+ } from "./chunk-7EO6CNQD.mjs";
8
+ import {
9
+ __name
10
+ } from "./chunk-PAWJFY3S.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(options) {
33
+ const runtimeFlags = [];
34
+ if (options.nodeInspectFlag) {
35
+ runtimeFlags.push("--enable-source-maps", options.nodeInspectFlag);
36
+ }
37
+ const runtimePrefix = runtimeFlags.length > 0 ? `${runtimeFlags.join(" ")} ` : "";
38
+ return spawnCommand(`node ${runtimePrefix}dist/main.js`);
39
+ }
40
+ __name(startAppProcess, "startAppProcess");
41
+ function killProcess(child) {
42
+ if (!child.killed) {
43
+ child.kill("SIGTERM");
44
+ }
45
+ }
46
+ __name(killProcess, "killProcess");
47
+ function runDevCommand(argsString, options = {}) {
48
+ const cwd = process.cwd();
49
+ runNestBuild(argsString);
50
+ const buildWatcherProcess = spawnCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
51
+ let appProcess = startAppProcess(options);
52
+ let isClosing = false;
53
+ let isRestarting = false;
54
+ let restartTimer = null;
55
+ const ignoreRestartBefore = Date.now() + RESTART_GUARD_MS;
56
+ const appDistWatcher = createWatcher(path.resolve(cwd, "dist"), scheduleRestart);
57
+ const packageWatchers = collectBffPackageDistPaths(cwd).map((watchPath) => createWatcher(watchPath, scheduleRestart)).filter((watcher) => Boolean(watcher));
58
+ function exitAll(code = 0) {
59
+ isClosing = true;
60
+ if (restartTimer) {
61
+ clearTimeout(restartTimer);
62
+ restartTimer = null;
63
+ }
64
+ closeWatchers([
65
+ appDistWatcher,
66
+ ...packageWatchers
67
+ ]);
68
+ killProcess(appProcess);
69
+ killProcess(buildWatcherProcess);
70
+ process.exit(code);
71
+ }
72
+ __name(exitAll, "exitAll");
73
+ function attachAppExitGuard() {
74
+ appProcess.on("exit", (code) => {
75
+ if (isClosing || isRestarting) {
76
+ return;
77
+ }
78
+ if (code !== 0) {
79
+ console.error(`node dist/main.js \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
80
+ exitAll(code ?? 1);
81
+ }
82
+ });
83
+ }
84
+ __name(attachAppExitGuard, "attachAppExitGuard");
85
+ function restartApp() {
86
+ if (isClosing || isRestarting) {
87
+ return;
88
+ }
89
+ isRestarting = true;
90
+ const startNextApp = /* @__PURE__ */ __name(() => {
91
+ if (isClosing) {
92
+ return;
93
+ }
94
+ appProcess = startAppProcess(options);
95
+ attachAppExitGuard();
96
+ isRestarting = false;
97
+ }, "startNextApp");
98
+ if (appProcess.killed) {
99
+ startNextApp();
100
+ return;
101
+ }
102
+ appProcess.once("exit", startNextApp);
103
+ killProcess(appProcess);
104
+ }
105
+ __name(restartApp, "restartApp");
106
+ function scheduleRestart() {
107
+ if (Date.now() < ignoreRestartBefore) {
108
+ return;
109
+ }
110
+ if (restartTimer) {
111
+ clearTimeout(restartTimer);
112
+ }
113
+ restartTimer = setTimeout(restartApp, FILE_CHANGE_DEBOUNCE_MS);
114
+ }
115
+ __name(scheduleRestart, "scheduleRestart");
116
+ process.on("SIGINT", () => exitAll(0));
117
+ process.on("SIGTERM", () => exitAll(0));
118
+ buildWatcherProcess.on("exit", (code) => {
119
+ if (isClosing) {
120
+ return;
121
+ }
122
+ if (code !== 0) {
123
+ console.error(`nest build --watch \u9000\u51FA\uFF0Ccode: ${code ?? -1}`);
124
+ exitAll(code ?? 1);
125
+ }
126
+ });
127
+ attachAppExitGuard();
128
+ }
129
+ __name(runDevCommand, "runDevCommand");
130
+
131
+ export {
132
+ runNestBuild,
133
+ runDevCommand
134
+ };
135
+ //# sourceMappingURL=chunk-GK3IPRWV.mjs.map
@@ -0,0 +1,69 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-PAWJFY3S.mjs";
4
+
5
+ // src/tools.ts
6
+ function createArgsString(args) {
7
+ return Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
8
+ }
9
+ __name(createArgsString, "createArgsString");
10
+ function toBoolean(value) {
11
+ if (typeof value === "boolean") {
12
+ return value;
13
+ }
14
+ if (typeof value === "number") {
15
+ return value !== 0;
16
+ }
17
+ if (typeof value === "string") {
18
+ return [
19
+ "1",
20
+ "true",
21
+ "yes",
22
+ "on"
23
+ ].includes(value.trim().toLowerCase());
24
+ }
25
+ return false;
26
+ }
27
+ __name(toBoolean, "toBoolean");
28
+ function toInspectFlag(flagName, value) {
29
+ if (value === void 0 || value === null || value === false) {
30
+ return void 0;
31
+ }
32
+ if (typeof value === "string" && value.trim() !== "") {
33
+ return `--${flagName}=${value.trim()}`;
34
+ }
35
+ if (toBoolean(value) || value === true) {
36
+ return `--${flagName}`;
37
+ }
38
+ return void 0;
39
+ }
40
+ __name(toInspectFlag, "toInspectFlag");
41
+ function parseDevOptions(rawArgs) {
42
+ const inspectBrkFlag = toInspectFlag("inspect-brk", rawArgs["inspect-brk"]);
43
+ if (inspectBrkFlag) {
44
+ return {
45
+ nodeInspectFlag: inspectBrkFlag
46
+ };
47
+ }
48
+ const inspectFlag = toInspectFlag("inspect", rawArgs.inspect);
49
+ if (inspectFlag) {
50
+ return {
51
+ nodeInspectFlag: inspectFlag
52
+ };
53
+ }
54
+ if (toBoolean(rawArgs.debug)) {
55
+ return {
56
+ nodeInspectFlag: "--inspect"
57
+ };
58
+ }
59
+ return {};
60
+ }
61
+ __name(parseDevOptions, "parseDevOptions");
62
+
63
+ export {
64
+ createArgsString,
65
+ toBoolean,
66
+ toInspectFlag,
67
+ parseDevOptions
68
+ };
69
+ //# sourceMappingURL=chunk-I32XDVIW.mjs.map
@@ -0,0 +1,68 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-O6YSETKJ.mjs";
4
+
5
+ // src/tools.ts
6
+ function createArgsString(args) {
7
+ return Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
8
+ }
9
+ __name(createArgsString, "createArgsString");
10
+ function toBoolean(value) {
11
+ if (typeof value === "boolean") {
12
+ return value;
13
+ }
14
+ if (typeof value === "number") {
15
+ return value !== 0;
16
+ }
17
+ if (typeof value === "string") {
18
+ return [
19
+ "1",
20
+ "true",
21
+ "yes",
22
+ "on"
23
+ ].includes(value.trim().toLowerCase());
24
+ }
25
+ return false;
26
+ }
27
+ __name(toBoolean, "toBoolean");
28
+ function toInspectFlag(flagName, value) {
29
+ if (value === void 0 || value === null || value === false) {
30
+ return void 0;
31
+ }
32
+ if (typeof value === "string" && value.trim() !== "") {
33
+ return `--${flagName}=${value.trim()}`;
34
+ }
35
+ if (toBoolean(value) || value === true) {
36
+ return `--${flagName}`;
37
+ }
38
+ return void 0;
39
+ }
40
+ __name(toInspectFlag, "toInspectFlag");
41
+ function parseDevOptions(rawArgs) {
42
+ const inspectBrkFlag = toInspectFlag("inspect-brk", rawArgs["inspect-brk"]);
43
+ if (inspectBrkFlag) {
44
+ return {
45
+ nodeInspectFlag: inspectBrkFlag
46
+ };
47
+ }
48
+ const inspectFlag = toInspectFlag("inspect", rawArgs.inspect);
49
+ if (inspectFlag) {
50
+ return {
51
+ nodeInspectFlag: inspectFlag
52
+ };
53
+ }
54
+ if (toBoolean(rawArgs.debug)) {
55
+ return {
56
+ nodeInspectFlag: "--inspect"
57
+ };
58
+ }
59
+ return {};
60
+ }
61
+ __name(parseDevOptions, "parseDevOptions");
62
+
63
+ export {
64
+ createArgsString,
65
+ toBoolean,
66
+ toInspectFlag,
67
+ parseDevOptions
68
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  collectBffPackageDistPaths
3
- } from "./chunk-67SKOZPM.mjs";
3
+ } from "./chunk-4YNMCK7Y.mjs";
4
4
  import {
5
5
  closeWatchers,
6
6
  createWatcher
@@ -29,8 +29,13 @@ function runNestBuild(argsString) {
29
29
  });
30
30
  }
31
31
  __name(runNestBuild, "runNestBuild");
32
- function startAppProcess() {
33
- return spawnCommand("node dist/main.js");
32
+ function startAppProcess(options) {
33
+ const runtimeFlags = [];
34
+ if (options.nodeInspectFlag) {
35
+ runtimeFlags.push("--enable-source-maps", options.nodeInspectFlag);
36
+ }
37
+ const runtimePrefix = runtimeFlags.length > 0 ? `${runtimeFlags.join(" ")} ` : "";
38
+ return spawnCommand(`node ${runtimePrefix}dist/main.js`);
34
39
  }
35
40
  __name(startAppProcess, "startAppProcess");
36
41
  function killProcess(child) {
@@ -39,11 +44,11 @@ function killProcess(child) {
39
44
  }
40
45
  }
41
46
  __name(killProcess, "killProcess");
42
- function runDevCommand(argsString) {
47
+ function runDevCommand(argsString, options = {}) {
43
48
  const cwd = process.cwd();
44
49
  runNestBuild(argsString);
45
50
  const buildWatcherProcess = spawnCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
46
- let appProcess = startAppProcess();
51
+ let appProcess = startAppProcess(options);
47
52
  let isClosing = false;
48
53
  let isRestarting = false;
49
54
  let restartTimer = null;
@@ -86,7 +91,7 @@ function runDevCommand(argsString) {
86
91
  if (isClosing) {
87
92
  return;
88
93
  }
89
- appProcess = startAppProcess();
94
+ appProcess = startAppProcess(options);
90
95
  attachAppExitGuard();
91
96
  isRestarting = false;
92
97
  }, "startNextApp");
@@ -0,0 +1,53 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-PAWJFY3S.mjs";
4
+
5
+ // src/config.ts
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import yaml from "yaml";
9
+ var loadXfeConfig = /* @__PURE__ */ __name(() => {
10
+ const xfeConfigPath = "./xfe.json";
11
+ if (!fs.existsSync(xfeConfigPath)) {
12
+ throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
13
+ }
14
+ const xfeConfigContent = fs.readFileSync(xfeConfigPath, "utf8");
15
+ return JSON.parse(xfeConfigContent);
16
+ }, "loadXfeConfig");
17
+ var configDeploy = /* @__PURE__ */ __name(() => {
18
+ const xfeConfig = loadXfeConfig();
19
+ if (!xfeConfig?.deploy) return;
20
+ const droneConfigFilePath = path.resolve(__dirname, "../deploy/.drone.yml");
21
+ fs.cpSync(droneConfigFilePath, xfeConfig.deploy.droneConfigPath || "./.drone.yml");
22
+ const valuesYamlFilePath = path.resolve(__dirname, "../deploy/helm/values.yaml");
23
+ const valuesYamlFile = fs.readFileSync(valuesYamlFilePath, "utf8");
24
+ const valuesYaml = yaml.parse(valuesYamlFile);
25
+ if (!valuesYaml.virtualService) valuesYaml.virtualService = {};
26
+ if (!valuesYaml.virtualService.hosts) valuesYaml.virtualService.hosts = {
27
+ test: [],
28
+ stage: [],
29
+ prod: []
30
+ };
31
+ const { virtualServiceEnabled = true, hostsProd = [], hostsStage = [], hostsTest = [], gateways = [
32
+ "common-gateway-eshetang"
33
+ ] } = xfeConfig.deploy;
34
+ const { targetK8s = "saas", targetNamespace = "" } = xfeConfig.deploy;
35
+ valuesYaml.virtualService.enabled = virtualServiceEnabled;
36
+ valuesYaml.virtualService.gateways = gateways;
37
+ valuesYaml.virtualService.hosts.prod = hostsProd;
38
+ valuesYaml.virtualService.hosts.stage = hostsStage;
39
+ valuesYaml.virtualService.hosts.test = hostsTest;
40
+ valuesYaml.targetK8s = targetK8s;
41
+ valuesYaml.namespace = targetNamespace;
42
+ const valuesYamlStr = yaml.stringify(valuesYaml, {
43
+ defaultStringType: "QUOTE_SINGLE",
44
+ defaultKeyType: "PLAIN"
45
+ });
46
+ fs.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
47
+ }, "configDeploy");
48
+
49
+ export {
50
+ loadXfeConfig,
51
+ configDeploy
52
+ };
53
+ //# sourceMappingURL=chunk-NUV437MC.mjs.map
@@ -0,0 +1,7 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ export {
5
+ __name
6
+ };
7
+ //# sourceMappingURL=chunk-PAWJFY3S.mjs.map
@@ -0,0 +1,27 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-PAWJFY3S.mjs";
4
+
5
+ // src/path-resolver.ts
6
+ import fs from "fs";
7
+ import path from "path";
8
+ function collectScopedPackageDistPaths(cwd) {
9
+ const SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
10
+ const scopedPackagesPath = path.resolve(cwd, SCOPE_PACKAGES_DIR);
11
+ if (!fs.existsSync(scopedPackagesPath)) {
12
+ return [];
13
+ }
14
+ return fs.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== "bff-app").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));
15
+ }
16
+ __name(collectScopedPackageDistPaths, "collectScopedPackageDistPaths");
17
+ function collectBffPackageDistPaths(cwd) {
18
+ const watchTargets = /* @__PURE__ */ new Set();
19
+ collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
20
+ return Array.from(watchTargets);
21
+ }
22
+ __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
23
+
24
+ export {
25
+ collectBffPackageDistPaths
26
+ };
27
+ //# sourceMappingURL=chunk-YR5ZIMNO.mjs.map
package/dist/cli.js CHANGED
@@ -77,29 +77,18 @@ var import_path3 = __toESM(require("path"));
77
77
  // src/path-resolver.ts
78
78
  var import_fs2 = __toESM(require("fs"));
79
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
80
  function collectScopedPackageDistPaths(cwd) {
81
+ const SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
84
82
  const scopedPackagesPath = import_path2.default.resolve(cwd, SCOPE_PACKAGES_DIR);
85
83
  if (!import_fs2.default.existsSync(scopedPackagesPath)) {
86
84
  return [];
87
85
  }
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));
86
+ return import_fs2.default.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== "bff-app").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
87
  }
90
88
  __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 [];
95
- }
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
89
  function collectBffPackageDistPaths(cwd) {
100
90
  const watchTargets = /* @__PURE__ */ new Set();
101
91
  collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
102
- collectInternalPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
103
92
  return Array.from(watchTargets);
104
93
  }
105
94
  __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
@@ -150,8 +139,13 @@ function runNestBuild(argsString) {
150
139
  });
151
140
  }
152
141
  __name(runNestBuild, "runNestBuild");
153
- function startAppProcess() {
154
- return spawnCommand("node dist/main.js");
142
+ function startAppProcess(options) {
143
+ const runtimeFlags = [];
144
+ if (options.nodeInspectFlag) {
145
+ runtimeFlags.push("--enable-source-maps", options.nodeInspectFlag);
146
+ }
147
+ const runtimePrefix = runtimeFlags.length > 0 ? `${runtimeFlags.join(" ")} ` : "";
148
+ return spawnCommand(`node ${runtimePrefix}dist/main.js`);
155
149
  }
156
150
  __name(startAppProcess, "startAppProcess");
157
151
  function killProcess(child) {
@@ -160,11 +154,11 @@ function killProcess(child) {
160
154
  }
161
155
  }
162
156
  __name(killProcess, "killProcess");
163
- function runDevCommand(argsString) {
157
+ function runDevCommand(argsString, options = {}) {
164
158
  const cwd = process.cwd();
165
159
  runNestBuild(argsString);
166
160
  const buildWatcherProcess = spawnCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
167
- let appProcess = startAppProcess();
161
+ let appProcess = startAppProcess(options);
168
162
  let isClosing = false;
169
163
  let isRestarting = false;
170
164
  let restartTimer = null;
@@ -207,7 +201,7 @@ function runDevCommand(argsString) {
207
201
  if (isClosing) {
208
202
  return;
209
203
  }
210
- appProcess = startAppProcess();
204
+ appProcess = startAppProcess(options);
211
205
  attachAppExitGuard();
212
206
  isRestarting = false;
213
207
  }, "startNextApp");
@@ -244,17 +238,79 @@ function runDevCommand(argsString) {
244
238
  }
245
239
  __name(runDevCommand, "runDevCommand");
246
240
 
247
- // src/cli.ts
241
+ // src/tools.ts
248
242
  function createArgsString(args) {
249
243
  return Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
250
244
  }
251
245
  __name(createArgsString, "createArgsString");
246
+ function toBoolean(value) {
247
+ if (typeof value === "boolean") {
248
+ return value;
249
+ }
250
+ if (typeof value === "number") {
251
+ return value !== 0;
252
+ }
253
+ if (typeof value === "string") {
254
+ return [
255
+ "1",
256
+ "true",
257
+ "yes",
258
+ "on"
259
+ ].includes(value.trim().toLowerCase());
260
+ }
261
+ return false;
262
+ }
263
+ __name(toBoolean, "toBoolean");
264
+ function toInspectFlag(flagName, value) {
265
+ if (value === void 0 || value === null || value === false) {
266
+ return void 0;
267
+ }
268
+ if (typeof value === "string" && value.trim() !== "") {
269
+ return `--${flagName}=${value.trim()}`;
270
+ }
271
+ if (toBoolean(value) || value === true) {
272
+ return `--${flagName}`;
273
+ }
274
+ return void 0;
275
+ }
276
+ __name(toInspectFlag, "toInspectFlag");
277
+ function parseDevOptions(rawArgs) {
278
+ const inspectBrkFlag = toInspectFlag("inspect-brk", rawArgs["inspect-brk"]);
279
+ if (inspectBrkFlag) {
280
+ return {
281
+ nodeInspectFlag: inspectBrkFlag
282
+ };
283
+ }
284
+ const inspectFlag = toInspectFlag("inspect", rawArgs.inspect);
285
+ if (inspectFlag) {
286
+ return {
287
+ nodeInspectFlag: inspectFlag
288
+ };
289
+ }
290
+ if (toBoolean(rawArgs.debug)) {
291
+ return {
292
+ nodeInspectFlag: "--inspect"
293
+ };
294
+ }
295
+ return {};
296
+ }
297
+ __name(parseDevOptions, "parseDevOptions");
298
+
299
+ // src/cli.ts
252
300
  function parseCliContext() {
253
301
  const argv = (0, import_minimist.default)(process.argv.slice(2));
254
302
  const { _: commands, ...rawArgs } = argv;
303
+ const RUNTIME_ARG_KEYS = /* @__PURE__ */ new Set([
304
+ "debug",
305
+ "inspect",
306
+ "inspect-brk"
307
+ ]);
308
+ const devOptions = parseDevOptions(rawArgs);
309
+ const buildArgs = Object.fromEntries(Object.entries(rawArgs).filter(([key]) => !RUNTIME_ARG_KEYS.has(key)));
255
310
  return {
256
311
  command: commands[0],
257
- argsString: createArgsString(rawArgs)
312
+ argsString: createArgsString(buildArgs),
313
+ devOptions
258
314
  };
259
315
  }
260
316
  __name(parseCliContext, "parseCliContext");
@@ -268,7 +324,7 @@ function runConfig() {
268
324
  __name(runConfig, "runConfig");
269
325
  function runCommandByType(context) {
270
326
  if (context.command === "dev") {
271
- runDevCommand(context.argsString);
327
+ runDevCommand(context.argsString, context.devOptions);
272
328
  return;
273
329
  }
274
330
  if (context.command === "build") {
package/dist/cli.mjs CHANGED
@@ -4,8 +4,12 @@ import {
4
4
  import {
5
5
  runDevCommand,
6
6
  runNestBuild
7
- } from "./chunk-IX37L3FU.mjs";
8
- import "./chunk-67SKOZPM.mjs";
7
+ } from "./chunk-NJP3V6ZT.mjs";
8
+ import "./chunk-4YNMCK7Y.mjs";
9
+ import {
10
+ createArgsString,
11
+ parseDevOptions
12
+ } from "./chunk-MP3KTLGW.mjs";
9
13
  import "./chunk-BAUM5HSG.mjs";
10
14
  import {
11
15
  __name
@@ -13,16 +17,20 @@ import {
13
17
 
14
18
  // src/cli.ts
15
19
  import minimist from "minimist";
16
- function createArgsString(args) {
17
- return Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
18
- }
19
- __name(createArgsString, "createArgsString");
20
20
  function parseCliContext() {
21
21
  const argv = minimist(process.argv.slice(2));
22
22
  const { _: commands, ...rawArgs } = argv;
23
+ const RUNTIME_ARG_KEYS = /* @__PURE__ */ new Set([
24
+ "debug",
25
+ "inspect",
26
+ "inspect-brk"
27
+ ]);
28
+ const devOptions = parseDevOptions(rawArgs);
29
+ const buildArgs = Object.fromEntries(Object.entries(rawArgs).filter(([key]) => !RUNTIME_ARG_KEYS.has(key)));
23
30
  return {
24
31
  command: commands[0],
25
- argsString: createArgsString(rawArgs)
32
+ argsString: createArgsString(buildArgs),
33
+ devOptions
26
34
  };
27
35
  }
28
36
  __name(parseCliContext, "parseCliContext");
@@ -36,7 +44,7 @@ function runConfig() {
36
44
  __name(runConfig, "runConfig");
37
45
  function runCommandByType(context) {
38
46
  if (context.command === "dev") {
39
- runDevCommand(context.argsString);
47
+ runDevCommand(context.argsString, context.devOptions);
40
48
  return;
41
49
  }
42
50
  if (context.command === "build") {
@@ -36,29 +36,18 @@ __export(path_resolver_exports, {
36
36
  module.exports = __toCommonJS(path_resolver_exports);
37
37
  var import_fs = __toESM(require("fs"));
38
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
39
  function collectScopedPackageDistPaths(cwd) {
40
+ const SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
43
41
  const scopedPackagesPath = import_path.default.resolve(cwd, SCOPE_PACKAGES_DIR);
44
42
  if (!import_fs.default.existsSync(scopedPackagesPath)) {
45
43
  return [];
46
44
  }
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));
45
+ return import_fs.default.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== "bff-app").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
46
  }
49
47
  __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
48
  function collectBffPackageDistPaths(cwd) {
59
49
  const watchTargets = /* @__PURE__ */ new Set();
60
50
  collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
61
- collectInternalPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
62
51
  return Array.from(watchTargets);
63
52
  }
64
53
  __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  collectBffPackageDistPaths
3
- } from "./chunk-67SKOZPM.mjs";
3
+ } from "./chunk-4YNMCK7Y.mjs";
4
4
  import "./chunk-O6YSETKJ.mjs";
5
5
  export {
6
6
  collectBffPackageDistPaths
@@ -1,4 +1,7 @@
1
+ import { RunDevOptions } from './tools.mjs';
2
+ import 'minimist';
3
+
1
4
  declare function runNestBuild(argsString: string): void;
2
- declare function runDevCommand(argsString: string): void;
5
+ declare function runDevCommand(argsString: string, options?: RunDevOptions): void;
3
6
 
4
7
  export { runDevCommand, runNestBuild };
@@ -1,4 +1,7 @@
1
+ import { RunDevOptions } from './tools.js';
2
+ import 'minimist';
3
+
1
4
  declare function runNestBuild(argsString: string): void;
2
- declare function runDevCommand(argsString: string): void;
5
+ declare function runDevCommand(argsString: string, options?: RunDevOptions): void;
3
6
 
4
7
  export { runDevCommand, runNestBuild };
@@ -41,29 +41,18 @@ var import_path2 = __toESM(require("path"));
41
41
  // src/path-resolver.ts
42
42
  var import_fs = __toESM(require("fs"));
43
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
44
  function collectScopedPackageDistPaths(cwd) {
45
+ const SCOPE_PACKAGES_DIR = "node_modules/@xfe-repo";
48
46
  const scopedPackagesPath = import_path.default.resolve(cwd, SCOPE_PACKAGES_DIR);
49
47
  if (!import_fs.default.existsSync(scopedPackagesPath)) {
50
48
  return [];
51
49
  }
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));
50
+ return import_fs.default.readdirSync(scopedPackagesPath).filter((packageName) => packageName.startsWith("bff-") && packageName !== "bff-app").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
51
  }
54
52
  __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
53
  function collectBffPackageDistPaths(cwd) {
64
54
  const watchTargets = /* @__PURE__ */ new Set();
65
55
  collectScopedPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
66
- collectInternalPackageDistPaths(cwd).forEach((watchPath) => watchTargets.add(watchPath));
67
56
  return Array.from(watchTargets);
68
57
  }
69
58
  __name(collectBffPackageDistPaths, "collectBffPackageDistPaths");
@@ -114,8 +103,13 @@ function runNestBuild(argsString) {
114
103
  });
115
104
  }
116
105
  __name(runNestBuild, "runNestBuild");
117
- function startAppProcess() {
118
- return spawnCommand("node dist/main.js");
106
+ function startAppProcess(options) {
107
+ const runtimeFlags = [];
108
+ if (options.nodeInspectFlag) {
109
+ runtimeFlags.push("--enable-source-maps", options.nodeInspectFlag);
110
+ }
111
+ const runtimePrefix = runtimeFlags.length > 0 ? `${runtimeFlags.join(" ")} ` : "";
112
+ return spawnCommand(`node ${runtimePrefix}dist/main.js`);
119
113
  }
120
114
  __name(startAppProcess, "startAppProcess");
121
115
  function killProcess(child) {
@@ -124,11 +118,11 @@ function killProcess(child) {
124
118
  }
125
119
  }
126
120
  __name(killProcess, "killProcess");
127
- function runDevCommand(argsString) {
121
+ function runDevCommand(argsString, options = {}) {
128
122
  const cwd = process.cwd();
129
123
  runNestBuild(argsString);
130
124
  const buildWatcherProcess = spawnCommand(`nest build --watch --preserveWatchOutput ${argsString}`);
131
- let appProcess = startAppProcess();
125
+ let appProcess = startAppProcess(options);
132
126
  let isClosing = false;
133
127
  let isRestarting = false;
134
128
  let restartTimer = null;
@@ -171,7 +165,7 @@ function runDevCommand(argsString) {
171
165
  if (isClosing) {
172
166
  return;
173
167
  }
174
- appProcess = startAppProcess();
168
+ appProcess = startAppProcess(options);
175
169
  attachAppExitGuard();
176
170
  isRestarting = false;
177
171
  }, "startNextApp");
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  runDevCommand,
3
3
  runNestBuild
4
- } from "./chunk-IX37L3FU.mjs";
5
- import "./chunk-67SKOZPM.mjs";
4
+ } from "./chunk-NJP3V6ZT.mjs";
5
+ import "./chunk-4YNMCK7Y.mjs";
6
6
  import "./chunk-BAUM5HSG.mjs";
7
7
  import "./chunk-O6YSETKJ.mjs";
8
8
  export {
@@ -0,0 +1,12 @@
1
+ import minimist from 'minimist';
2
+
3
+ type CliArgs = Record<string, string | number | boolean>;
4
+ declare function createArgsString(args: CliArgs): string;
5
+ declare function toBoolean(value: unknown): boolean;
6
+ declare function toInspectFlag(flagName: string, value: unknown): string | undefined;
7
+ interface RunDevOptions {
8
+ nodeInspectFlag?: string;
9
+ }
10
+ declare function parseDevOptions(rawArgs: minimist.ParsedArgs): RunDevOptions;
11
+
12
+ export { type CliArgs, type RunDevOptions, createArgsString, parseDevOptions, toBoolean, toInspectFlag };
@@ -0,0 +1,12 @@
1
+ import minimist from 'minimist';
2
+
3
+ type CliArgs = Record<string, string | number | boolean>;
4
+ declare function createArgsString(args: CliArgs): string;
5
+ declare function toBoolean(value: unknown): boolean;
6
+ declare function toInspectFlag(flagName: string, value: unknown): string | undefined;
7
+ interface RunDevOptions {
8
+ nodeInspectFlag?: string;
9
+ }
10
+ declare function parseDevOptions(rawArgs: minimist.ParsedArgs): RunDevOptions;
11
+
12
+ export { type CliArgs, type RunDevOptions, createArgsString, parseDevOptions, toBoolean, toInspectFlag };
package/dist/tools.js ADDED
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/tools.ts
22
+ var tools_exports = {};
23
+ __export(tools_exports, {
24
+ createArgsString: () => createArgsString,
25
+ parseDevOptions: () => parseDevOptions,
26
+ toBoolean: () => toBoolean,
27
+ toInspectFlag: () => toInspectFlag
28
+ });
29
+ module.exports = __toCommonJS(tools_exports);
30
+ function createArgsString(args) {
31
+ return Object.entries(args).map(([key, value]) => `--${key}=${value}`).join(" ");
32
+ }
33
+ __name(createArgsString, "createArgsString");
34
+ function toBoolean(value) {
35
+ if (typeof value === "boolean") {
36
+ return value;
37
+ }
38
+ if (typeof value === "number") {
39
+ return value !== 0;
40
+ }
41
+ if (typeof value === "string") {
42
+ return [
43
+ "1",
44
+ "true",
45
+ "yes",
46
+ "on"
47
+ ].includes(value.trim().toLowerCase());
48
+ }
49
+ return false;
50
+ }
51
+ __name(toBoolean, "toBoolean");
52
+ function toInspectFlag(flagName, value) {
53
+ if (value === void 0 || value === null || value === false) {
54
+ return void 0;
55
+ }
56
+ if (typeof value === "string" && value.trim() !== "") {
57
+ return `--${flagName}=${value.trim()}`;
58
+ }
59
+ if (toBoolean(value) || value === true) {
60
+ return `--${flagName}`;
61
+ }
62
+ return void 0;
63
+ }
64
+ __name(toInspectFlag, "toInspectFlag");
65
+ function parseDevOptions(rawArgs) {
66
+ const inspectBrkFlag = toInspectFlag("inspect-brk", rawArgs["inspect-brk"]);
67
+ if (inspectBrkFlag) {
68
+ return {
69
+ nodeInspectFlag: inspectBrkFlag
70
+ };
71
+ }
72
+ const inspectFlag = toInspectFlag("inspect", rawArgs.inspect);
73
+ if (inspectFlag) {
74
+ return {
75
+ nodeInspectFlag: inspectFlag
76
+ };
77
+ }
78
+ if (toBoolean(rawArgs.debug)) {
79
+ return {
80
+ nodeInspectFlag: "--inspect"
81
+ };
82
+ }
83
+ return {};
84
+ }
85
+ __name(parseDevOptions, "parseDevOptions");
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ createArgsString,
89
+ parseDevOptions,
90
+ toBoolean,
91
+ toInspectFlag
92
+ });
package/dist/tools.mjs ADDED
@@ -0,0 +1,13 @@
1
+ import {
2
+ createArgsString,
3
+ parseDevOptions,
4
+ toBoolean,
5
+ toInspectFlag
6
+ } from "./chunk-MP3KTLGW.mjs";
7
+ import "./chunk-O6YSETKJ.mjs";
8
+ export {
9
+ createArgsString,
10
+ parseDevOptions,
11
+ toBoolean,
12
+ toInspectFlag
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xfe-repo/bff-app",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "bin": {
5
5
  "xfe-bff": "./bin/index.js"
6
6
  },
@@ -1,37 +0,0 @@
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
- };