@infly/libs 2.6.0 → 2.7.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 CHANGED
@@ -482,3 +482,21 @@ source 构建组件可配置 `monorepoContextFiles: [tooling/install.cjs]`,逐
482
482
  `source.standalone: true` 可显式使用独立源码上下文,即使业务仓位于 monorepo 中也不带根公共包;适用于已有独立安装契约的紧急构建。target 的 `recordConfigurationRevision: true` 则让未注入文件的外部源码组件也记录并复核部署仓提交。两者均为可选布尔值,默认保持原有行为。
483
483
 
484
484
  组件可声明 `health: {timeoutSeconds: 60, addHost: api:127.0.0.1}`,复用运行镜像的 HEALTHCHECK,失败不推送本组任何镜像。普通 check 仍用于语法或文件检查;不要对后端启动真实业务进程作本地镜像探针。
485
+
486
+ 组件可按需声明下列 Docker 构建输入。dry-run 只给出配置计划,实际执行前才从进程环境解析仓库和密钥文件路径。
487
+
488
+ ```yaml
489
+ repositoryEnv: IMAGE_REPOSITORY
490
+ buildSecrets:
491
+ - id: app_env
492
+ fileEnv: APP_ENV_FILE
493
+ defaultFile: .env.app.local
494
+ noCacheFilter: [frontend-build]
495
+ buildTimestampArg: BUILD_TIMESTAMP
496
+ ```
497
+
498
+ - `repositoryEnv` 可替代固定的 `repository`,用于让构建执行者选择镜像仓库。
499
+ - `buildSecrets` 声明 BuildKit 密钥 ID 和保存文件路径的环境变量名。可用 `defaultFile` 声明相对部署仓的本机文件路径,未设置环境变量时使用该文件。密钥文件应放在构建上下文之外,并保持 Git 忽略,由 Dockerfile 使用 `RUN --mount=type=secret` 消费。文件路径和内容均不写入发布记录。
500
+ - `noCacheFilter` 按阶段传给 Buildx。依赖密钥内容改变的编译阶段应列入此处,仍可复用其他构建阶段缓存。
501
+ - `buildTimestampArg` 通过指定的构建参数提供一份 `+08:00` 时间戳。镜像检查可声明 `check.network: none` 进行无网络验证。
502
+ - `--output <路径>` 在成功后写出目标及组件构建结果。推送模式的结果包含已回拉校验的 digest 和 image ID。dry-run 不写文件。
@@ -1,3 +1,4 @@
1
+ const { logTerminal } = require("../../cli/terminal-style");
1
2
  const fs = require("fs");
2
3
  const path = require("path");
3
4
  const net = require("net");
@@ -24,14 +25,6 @@ function getBuildContext() {
24
25
 
25
26
  const buildContext = getBuildContext();
26
27
 
27
- global.logColor = global.logColor || {
28
- success: "\n\x1b[32m%s\x1b[0m",
29
- error: "\n\x1b[31m%s\x1b[0m",
30
- warning: "\n\x1b[33m%s\x1b[0m",
31
- link: "\x1b[34m%s\x1b[0m",
32
- info: "\n\x1b[36m%s\x1b[0m"
33
- };
34
-
35
28
  const DEFAULT_CONFIG = {
36
29
  port: 9001,
37
30
  publicPath: "/",
@@ -69,7 +62,7 @@ async function findAvailablePort(startPort, maxTries = 10) {
69
62
 
70
63
  if (available) {
71
64
  if (i > 0) {
72
- console.log(global.logColor.warning, `⚠️ 端口 ${startPort} 被占用,使用端口 ${port}`);
65
+ logTerminal("warning", `端口 ${startPort} 被占用,使用端口 ${port}`);
73
66
  }
74
67
  return port;
75
68
  }
@@ -114,25 +107,25 @@ async function init(skipBuild = false) {
114
107
  const targetSuffix = buildContext.targetLabel ? ` (${buildContext.targetLabel})` : '';
115
108
 
116
109
  if (buildContext.batchPreview === true || process.env.INFLY_BATCH_PREVIEW === "1") {
117
- console.log(global.logColor.link, `${projectPackage.name || path.basename(projectRoot)}${targetSuffix}: ${previewUrl}`);
110
+ logTerminal("info", `${projectPackage.name || path.basename(projectRoot)}${targetSuffix}: ${previewUrl}`);
118
111
  return;
119
112
  }
120
113
 
121
- console.log(global.logColor.success, `\x1b[42m\x1b[30m DONE \x1b[0m\x1b[32m 项目构建预览,CTRL + C结束:`);
122
- console.log(global.logColor.link, previewUrl);
114
+ logTerminal("success", `项目构建预览已启动,按 Ctrl+C 退出`);
115
+ logTerminal("info", previewUrl);
123
116
  });
124
117
 
125
118
  server.on("error", (error) => {
126
119
  if (error.code === "EADDRINUSE") {
127
- console.log(global.logColor.error, `❌ 端口 ${listenPort} 仍然被占用`);
120
+ logTerminal("error", `端口 ${listenPort} 仍然被占用`);
128
121
  } else {
129
- console.log(global.logColor.error, `❌ 服务器启动失败:${error.message}`);
122
+ logTerminal("error", `服务器启动失败:${error.message}`);
130
123
  }
131
124
  });
132
125
 
133
126
  return server;
134
127
  } catch (error) {
135
- console.log(global.logColor.error, `❌ 预览项目失败:${error.message}`);
128
+ logTerminal("error", `预览项目失败:${error.message}`);
136
129
  throw error;
137
130
  }
138
131
  }
@@ -141,7 +134,7 @@ function buildProject() {
141
134
  try {
142
135
  execSync(`vue-cli-service build ${args}`, { stdio: "inherit" });
143
136
  } catch (err) {
144
- console.error(global.logColor.error, "❌ 构建失败:", err.message);
137
+ logTerminal("error", "构建失败:", err.message);
145
138
  process.exit(1);
146
139
  }
147
140
  }
@@ -1,56 +1,57 @@
1
1
  /**
2
2
  * Webpack require.context 适配器。
3
- * 自动导出目录下所有文件
4
- * @param {Function} requireContext - require.context 返回的函数
5
- * @returns {Object} 导出对象,key 为文件名(不含扩展名),value 为模块内容
6
- *
7
- * @example
8
- * // 在 components/Dialog/index.js 中使用
3
+ * 自动导出目录下所有文件
4
+ * @param {Function} requireContext - require.context 返回的函数
5
+ * @returns {Object} 导出对象,key 为文件名(不含扩展名),value 为模块内容
6
+ *
7
+ * @example
8
+ * // 在 components/Dialog/index.js 中使用
9
9
  * import { autoExportFiles } from '@infly/libs/adapters/webpack/auto-export';
10
- * const components = autoExportFiles(require.context('./', false, /\.vue$/));
11
- * Object.keys(components).forEach(name => {
12
- * module.exports[name] = components[name];
13
- * });
14
- *
15
- * // 或者直接一行
16
- * Object.assign(module.exports, autoExportFiles(require.context('./', false, /\.vue$/)));
17
- */
18
- function autoExportFiles(requireContext) {
19
- if (!requireContext || typeof requireContext !== 'function') {
20
- console.error('autoExportFiles: requireContext 必须是 require.context 返回的函数');
21
- return {};
22
- }
23
-
24
- const exports = {};
25
-
26
- requireContext.keys().forEach(fileName => {
27
- // 跳过 index 文件自身
28
- if (fileName.includes('index')) return;
29
-
30
- const componentConfig = requireContext(fileName);
31
- const componentName = fileName
32
- .replace(/^\.\//, '') // 移除 './'
33
- .replace(/\.\w+$/, ''); // 移除扩展名
34
-
35
- exports[componentName] = componentConfig.default || componentConfig;
36
- });
37
-
38
- return exports;
39
- }
40
-
41
- /**
42
- * 简化版:直接挂载到 module.exports
43
- * @param {Function} requireContext - require.context 返回的函数
44
- * @param {Object} targetExports - 目标导出对象(通常是 module.exports)
45
- *
46
- * @example
47
- * // 在 components/Dialog/index.js 中使用
10
+ * const components = autoExportFiles(require.context('./', false, /\.vue$/));
11
+ * Object.keys(components).forEach(name => {
12
+ * module.exports[name] = components[name];
13
+ * });
14
+ *
15
+ * // 或者直接一行
16
+ * Object.assign(module.exports, autoExportFiles(require.context('./', false, /\.vue$/)));
17
+ */
18
+ const { logTerminal } = require("../../cli/terminal-style");
19
+ function autoExportFiles(requireContext) {
20
+ if (!requireContext || typeof requireContext !== 'function') {
21
+ logTerminal("error", 'autoExportFiles: requireContext 必须是 require.context 返回的函数');
22
+ return {};
23
+ }
24
+
25
+ const exports = {};
26
+
27
+ requireContext.keys().forEach(fileName => {
28
+ // 跳过 index 文件自身
29
+ if (fileName.includes('index')) return;
30
+
31
+ const componentConfig = requireContext(fileName);
32
+ const componentName = fileName
33
+ .replace(/^\.\//, '') // 移除 './'
34
+ .replace(/\.\w+$/, ''); // 移除扩展名
35
+
36
+ exports[componentName] = componentConfig.default || componentConfig;
37
+ });
38
+
39
+ return exports;
40
+ }
41
+
42
+ /**
43
+ * 简化版:直接挂载到 module.exports
44
+ * @param {Function} requireContext - require.context 返回的函数
45
+ * @param {Object} targetExports - 目标导出对象(通常是 module.exports)
46
+ *
47
+ * @example
48
+ * // 在 components/Dialog/index.js 中使用
48
49
  * import { autoExportToModule } from '@infly/libs/adapters/webpack/auto-export';
49
- * autoExportToModule(require.context('./', false, /\.vue$/), module.exports);
50
- */
51
- function autoExportToModule(requireContext, targetExports) {
52
- const files = autoExportFiles(requireContext);
53
- Object.assign(targetExports, files);
54
- }
55
-
56
- export { autoExportFiles, autoExportToModule };
50
+ * autoExportToModule(require.context('./', false, /\.vue$/), module.exports);
51
+ */
52
+ function autoExportToModule(requireContext, targetExports) {
53
+ const files = autoExportFiles(requireContext);
54
+ Object.assign(targetExports, files);
55
+ }
56
+
57
+ export { autoExportFiles, autoExportToModule };
package/bin/cli.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const { logTerminal } = require("../cli/terminal-style");
3
4
  const fs = require("node:fs");
4
5
  const path = require("node:path");
5
6
 
@@ -230,7 +231,7 @@ async function main(argv = process.argv.slice(2)) {
230
231
  if (command && commandMap[command]) {
231
232
  await commandMap[command]();
232
233
  } else {
233
- console.error(`未知命令: ${command || "未提供命令"}`);
234
+ logTerminal("error", `未知命令: ${command || "未提供命令"}`);
234
235
  console.log(`可用命令: ${Object.keys(commandMap).join(", ")}`);
235
236
  process.exitCode = 1;
236
237
  }
@@ -238,7 +239,7 @@ async function main(argv = process.argv.slice(2)) {
238
239
 
239
240
  if (require.main === module) {
240
241
  main().catch((error) => {
241
- console.error("执行失败:", error.message || error);
242
+ logTerminal("error", "执行失败:", error.message || error);
242
243
  process.exitCode = 1;
243
244
  });
244
245
  }
@@ -4,20 +4,13 @@
4
4
  * 工具实现根据配置自动切换分支,构建到配置的对应文件夹路径,并且执行自动提交推送,也可执行自动压缩提交到当前项目
5
5
  */
6
6
 
7
+ const { logTerminal } = require("../../cli/terminal-style");
7
8
  const path = require("path");
8
9
  const fs = require("fs");
9
10
  const readline = require("readline");
10
11
 
11
12
  const { exec } = require("child_process");
12
13
 
13
- global.logColor = {
14
- success: "\n\x1b[32m%s\x1b[0m",
15
- error: "\n\x1b[31m%s\x1b[0m",
16
- warning: "\n\x1b[33m%s\x1b[0m",
17
- link: "\x1b[34m%s\x1b[0m",
18
- info: "\n\x1b[36m%s\x1b[0m"
19
- };
20
-
21
14
  const { zipSync } = require("./zip.js");
22
15
  const { buildList } = require("../../script");
23
16
  const { init: previewInit } = require("../../adapters/vue2/project-preview.js");
@@ -300,7 +293,7 @@ async function init() {
300
293
  await previewInit(true);
301
294
  }
302
295
  } catch (error) {
303
- console.error(global.logColor.error, `❌ 自动构建脚本执行出错, 错误信息:\n${error}`);
296
+ logTerminal("error", `自动构建脚本执行出错, 错误信息:\n${error}`);
304
297
  process.exit(1);
305
298
  }
306
299
  }
@@ -380,23 +373,21 @@ function askUserConfirmation(message, defaultYes = false) {
380
373
  */
381
374
  async function validateConfig(buildConfig, targetBranch = currentBranch) {
382
375
  if (!buildConfig) {
383
- console.error(global.logColor.error, `❌ ZIP压缩已禁用,版本控制文件${versionFileName}配置错误`);
376
+ logTerminal("error", `ZIP压缩已禁用,版本控制文件${versionFileName}配置错误`);
384
377
  process.exit(1);
385
378
  }
386
379
 
387
380
  if (buildConfig?.buildConfigs?.enabled === false) {
388
- console.warn(
389
- global.logColor.error,
390
- `⚠️ ZIP压缩已禁用,版本控制文件${versionFileName}中的 enabled 属性设置为 false`
381
+ logTerminal(
382
+ "warning", `ZIP压缩已禁用,版本控制文件${versionFileName}中的 enabled 属性设置为 false`
391
383
  );
392
384
  process.exit(0);
393
385
  }
394
386
 
395
387
  if (!buildConfig?.buildConfigs?.gitAutoPushReposBranchMap[targetBranch]) {
396
388
  if (![testScript].includes(scriptEvent)) {
397
- console.error(
398
- global.logColor.error,
399
- `❌ 目标分支 ${targetBranch} 非 gitAutoPushReposBranchMap 配置可构建分支,请检查`
389
+ logTerminal(
390
+ "error", `目标分支 ${targetBranch} 非 gitAutoPushReposBranchMap 配置可构建分支,请检查`
400
391
  );
401
392
  process.exit(1);
402
393
  }
@@ -407,18 +398,18 @@ async function validateConfig(buildConfig, targetBranch = currentBranch) {
407
398
  const isStageBuild = buildMode === "stage";
408
399
 
409
400
  if (targetBranch === "master" && !isProdBuild) {
410
- console.error(global.logColor.error, `❌ 目标分支为 master 分支,请使用正式环境构建命令进行构建`);
401
+ logTerminal("error", `目标分支为 master 分支,请使用正式环境构建命令进行构建`);
411
402
  process.exit(1);
412
403
  }
413
404
 
414
405
  if (targetBranch !== "master" && !isStageBuild) {
415
- console.warn(global.logColor.warning, `⚠️ 目标分支为 ${targetBranch} 分支,建议使用测试环境构建命令`);
416
- console.log(global.logColor.info, `推荐命令: npm run infly:build:stage`);
406
+ logTerminal("warning", `目标分支为 ${targetBranch} 分支,建议使用测试环境构建命令`);
407
+ logTerminal("info", `推荐命令: npm run infly:build:stage`);
417
408
 
418
409
  const shouldContinue = await askUserConfirmation("确定要继续当前构建吗?", false);
419
410
 
420
411
  if (!shouldContinue) {
421
- console.log(global.logColor.info, "构建已取消,请使用正确的构建命令");
412
+ logTerminal("info", "构建已取消,请使用正确的构建命令");
422
413
  process.exit(1);
423
414
  }
424
415
  }
@@ -458,14 +449,14 @@ function validateFileExists(checkPath, logKey) {
458
449
  }
459
450
  }[logKey];
460
451
  if (!fs.existsSync(checkPath)) {
461
- console.error(global.logColor.error, `❌ ${error}`);
452
+ logTerminal("error", `${error}`);
462
453
  process.exit(1);
463
454
  }
464
455
  if (success) {
465
- console.log(global.logColor.success, `✅ ${success}`);
456
+ logTerminal("success", `${success}`);
466
457
  }
467
458
  if (link) {
468
- console.log(global.logColor.link, `${link}`);
459
+ logTerminal("info", `${link}`);
469
460
  }
470
461
  }
471
462
 
@@ -552,7 +543,7 @@ function updateVersionList(zipFiles = [], extraParams) {
552
543
  let allVersionExist = true; // 是否所有版本都存在于 version-config.json 中
553
544
  if (zipFiles.length === 0) {
554
545
  if (!isPkg) {
555
- console.warn(global.logColor.warning, "⚠️ 没有 ZIP 文件,跳过版本更新。");
546
+ logTerminal("warning", "没有 ZIP 文件,跳过版本更新。");
556
547
  }
557
548
  } else {
558
549
  zipFiles.forEach((zipFile) => {
@@ -563,15 +554,15 @@ function updateVersionList(zipFiles = [], extraParams) {
563
554
  allVersionExist = false;
564
555
  buildConfig.versionConfig.versionList.unshift(singleVersionInfo);
565
556
  const updateText = isDisableUpdateVersionEnv
566
- ? `✅ 新版本${version}已生成,当前环境跳过写入${versionFileName}`
567
- : `✅ 新版本${version}写入${versionFileName}文件更新成功`;
568
- console.log(global.logColor.success, updateText);
557
+ ? `新版本${version}已生成,当前环境跳过写入${versionFileName}`
558
+ : `新版本${version}写入${versionFileName}文件更新成功`;
559
+ logTerminal("success", updateText);
569
560
  }
570
561
  // 如果是更新,压缩脚本进行打包则删除全部旧文件
571
562
  if (isBuilZipScript && opt === "update") {
572
563
  deleteOldFile.push(fileName);
573
564
  fs.unlinkSync(path.join(projectRoot, fileName));
574
- console.log(global.logColor.success, `✅ 已删除 ZIP 文件: ${fileName}`);
565
+ logTerminal("success", `已删除 ZIP 文件: ${fileName}`);
575
566
  }
576
567
  });
577
568
  }
@@ -598,7 +589,7 @@ function updateVersionList(zipFiles = [], extraParams) {
598
589
 
599
590
  if (allVersionExist) {
600
591
  if (!isPkg) {
601
- console.log(global.logColor.success, `✅ 所有文件版本已存在于${versionFileName}中,无需更新`);
592
+ logTerminal("success", `所有文件版本已存在于${versionFileName}中,无需更新`);
602
593
  }
603
594
  } else if (!isBuilZipScript || opt !== "update") {
604
595
  // 如果是自动压缩的命令,只在完成压缩更新版本后统一输出,更新的时候不输出减少重复信息
@@ -606,7 +597,7 @@ function updateVersionList(zipFiles = [], extraParams) {
606
597
  }
607
598
  // 如果不是自动压缩的命令,在更新版本json文件后退出
608
599
  if (!isBuilZipScript) {
609
- console.warn(global.logColor.warning, "⚠️ 此次仅进行版本号更新,不进行压缩。");
600
+ logTerminal("warning", "此次仅进行版本号更新,不进行压缩。");
610
601
  process.exit(0);
611
602
  }
612
603
  return { deleteOldFile };
@@ -674,13 +665,12 @@ function copyToClipboard(text) {
674
665
  }
675
666
  const child = exec(command, (error) => {
676
667
  if (error) {
677
- console.error(
678
- global.logColor.error,
679
- `❌ 文本复制失败: ${error}\n请确保已安装 xclip 或 xsel(Linux),或手动复制:\n${text}`
668
+ logTerminal(
669
+ "error", `文本复制失败: ${error}\n请确保已安装 xclip 或 xsel(Linux),或手动复制:\n${text}`
680
670
  );
681
671
  reject(error);
682
672
  } else {
683
- console.log(global.logColor.success, `✅ 文本已复制到剪贴板\n${text}`);
673
+ logTerminal("success", `文本已复制到剪贴板\n${text}`);
684
674
  resolve(text);
685
675
  }
686
676
  });
@@ -728,7 +718,7 @@ function scriptInit() {
728
718
  scriptWrite(targetProjectPackageJSON, tempInflyConfig, npmPackageConfigKey);
729
719
 
730
720
  if (isExistTargetProjectVersionConfig) {
731
- console.log(global.logColor.success, `✅ ${versionFileName}配置迁移成功, 可手动删除旧版本控制文件`);
721
+ logTerminal("success", `${versionFileName}配置迁移成功, 可手动删除旧版本控制文件`);
732
722
  }
733
723
  }
734
724
 
@@ -756,7 +746,7 @@ function copyVersionConfigFile() {
756
746
  }
757
747
 
758
748
  if (err) {
759
- console.error(global.logColor.error, `❌ 读取复制文件失败: ${err.message}`);
749
+ logTerminal("error", `读取复制文件失败: ${err.message}`);
760
750
  return;
761
751
  }
762
752
 
@@ -774,17 +764,17 @@ function copyVersionConfigFile() {
774
764
 
775
765
  fs.writeFile(targetProjectVersionConfigPath, tempVersionConfigStr, (err) => {
776
766
  if (err) {
777
- console.error(global.logColor.error, `❌ 读取vue.config.js配置更新失败: ${err.message}`);
767
+ logTerminal("error", `读取vue.config.js配置更新失败: ${err.message}`);
778
768
  } else {
779
- console.log(global.logColor.success, `✅ 读取vue.config.js配置更新成功`);
769
+ logTerminal("success", `读取vue.config.js配置更新成功`);
780
770
  }
781
771
  });
782
772
  });
783
- console.log(global.logColor.success, `✅ 版本JSON文件已成功复制到根目录:${targetProjectVersionConfigPath}`);
773
+ logTerminal("success", `版本JSON文件已成功复制到根目录:${targetProjectVersionConfigPath}`);
784
774
  });
785
775
 
786
776
  writeStream.on("error", (err) => {
787
- console.error(global.logColor.error, `❌ 复制版本JSON文件失败:${err.message}`);
777
+ logTerminal("error", `复制版本JSON文件失败:${err.message}`);
788
778
  });
789
779
  }
790
780
  }
@@ -809,7 +799,7 @@ async function beforeBuild() {
809
799
  const currentProjectStatus = checkSingleDirGitStatus(projectGitRoot, sourceRepoName);
810
800
 
811
801
  if (currentProjectStatus.hasUncommitted) {
812
- console.log(global.logColor.error, `\n❌ 当前项目存在未提交的更改,请先提交或暂存后再继续构建`);
802
+ logTerminal("error", `\n当前项目存在未提交的更改,请先提交或暂存后再继续构建`);
813
803
  process.exit(1);
814
804
  }
815
805
 
@@ -818,7 +808,7 @@ async function beforeBuild() {
818
808
  );
819
809
 
820
810
  if (!currentProjectUpdateResult.success) {
821
- console.log(global.logColor.error, `\n❌ 当前项目切换到 ${targetBranch} 分支失败,请检查`);
811
+ logTerminal("error", `\n当前项目切换到 ${targetBranch} 分支失败,请检查`);
822
812
  process.exit(1);
823
813
  }
824
814
 
@@ -846,14 +836,14 @@ async function beforeBuild() {
846
836
  const siblingStatus = checkSingleDirGitStatus(siblingDir, siblingName);
847
837
 
848
838
  if (siblingStatus.hasUncommitted) {
849
- console.log(global.logColor.error, `\n❌ 兄弟项目 ${siblingName} 存在未提交的更改,请先提交或暂存后再继续构建`);
839
+ logTerminal("error", `\n兄弟项目 ${siblingName} 存在未提交的更改,请先提交或暂存后再继续构建`);
850
840
  process.exit(1);
851
841
  }
852
842
 
853
843
  const siblingUpdateResult = pullSingleDirFromBranch(siblingDir, siblingName, targetBranch);
854
844
 
855
845
  if (!siblingUpdateResult.success) {
856
- console.log(global.logColor.warning, `\n⚠️ 兄弟项目 ${siblingName} 更新失败,但可以继续执行`);
846
+ logTerminal("warning", `\n兄弟项目 ${siblingName} 更新失败,但可以继续执行`);
857
847
  }
858
848
  }
859
849
  }
@@ -1,57 +1,58 @@
1
- const { spawn } = require("child_process");
2
-
3
- function run(command, args, options = {}) {
4
- return new Promise((resolve, reject) => {
5
- const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
6
- // Avoid DEP0190: when shell=true, pass command+args as single string
7
- const [cmd, cmdArgs] = useShell
8
- ? [[command, ...args].join(" "), []]
9
- : [command, args];
10
- const child = spawn(cmd, cmdArgs, {
11
- cwd: options.cwd || process.cwd(),
12
- env: {
13
- ...process.env,
14
- ...(options.env || {})
15
- },
16
- stdio: options.stdio || "inherit",
17
- shell: useShell
18
- });
19
-
20
- child.on("close", (code) => {
21
- if (code === 0) {
22
- resolve();
23
- } else {
24
- reject(new Error(`${command} ${args.join(" ")} failed with exit code ${code}`));
25
- }
26
- });
27
-
28
- child.on("error", reject);
29
- });
30
- }
31
-
32
- function spawnBackground(command, args, options = {}) {
33
- const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
34
- const [cmd, cmdArgs] = useShell
35
- ? [[command, ...args].join(" "), []]
36
- : [command, args];
37
- const child = spawn(cmd, cmdArgs, {
38
- cwd: options.cwd || process.cwd(),
39
- env: {
40
- ...process.env,
41
- ...(options.env || {})
42
- },
43
- stdio: options.stdio || "inherit",
44
- shell: useShell
45
- });
46
-
47
- child.on("error", (error) => {
48
- console.error(error.message);
49
- });
50
-
51
- return child;
52
- }
53
-
54
- module.exports = {
55
- run,
56
- spawnBackground
57
- };
1
+ const { logTerminal } = require("../../cli/terminal-style");
2
+ const { spawn } = require("child_process");
3
+
4
+ function run(command, args, options = {}) {
5
+ return new Promise((resolve, reject) => {
6
+ const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
7
+ // Avoid DEP0190: when shell=true, pass command+args as single string
8
+ const [cmd, cmdArgs] = useShell
9
+ ? [[command, ...args].join(" "), []]
10
+ : [command, args];
11
+ const child = spawn(cmd, cmdArgs, {
12
+ cwd: options.cwd || process.cwd(),
13
+ env: {
14
+ ...process.env,
15
+ ...(options.env || {})
16
+ },
17
+ stdio: options.stdio || "inherit",
18
+ shell: useShell
19
+ });
20
+
21
+ child.on("close", (code) => {
22
+ if (code === 0) {
23
+ resolve();
24
+ } else {
25
+ reject(new Error(`${command} ${args.join(" ")} failed with exit code ${code}`));
26
+ }
27
+ });
28
+
29
+ child.on("error", reject);
30
+ });
31
+ }
32
+
33
+ function spawnBackground(command, args, options = {}) {
34
+ const useShell = options.shell !== undefined ? options.shell : process.platform === "win32";
35
+ const [cmd, cmdArgs] = useShell
36
+ ? [[command, ...args].join(" "), []]
37
+ : [command, args];
38
+ const child = spawn(cmd, cmdArgs, {
39
+ cwd: options.cwd || process.cwd(),
40
+ env: {
41
+ ...process.env,
42
+ ...(options.env || {})
43
+ },
44
+ stdio: options.stdio || "inherit",
45
+ shell: useShell
46
+ });
47
+
48
+ child.on("error", (error) => {
49
+ logTerminal("error", error.message);
50
+ });
51
+
52
+ return child;
53
+ }
54
+
55
+ module.exports = {
56
+ run,
57
+ spawnBackground
58
+ };
@@ -1,20 +1,20 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- /**
5
- * 从项目的 webpack/vite 等构建配置中解析对兄弟 app 的依赖。
6
- *
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ /**
5
+ * 从项目的 webpack/vite 等构建配置中解析对兄弟 app 的依赖。
6
+ *
7
7
  * 规则:如果 vue.config.js / vite.config.* / next.config.* 的 alias 中存在指向 ../ 的路径,
8
- * 则认为当前项目依赖该兄弟 app,构建前需要确保兄弟 app 源码是最新的。
9
- *
10
- * 示例(vue.config.js):
11
- * alias: {
12
- * "@example-admin": projectResolve("../example-admin/src")
13
- * }
14
- *
15
- * @param {string} appDir - 当前 app 目录的绝对路径
16
- * @returns {string[]} 兄弟 app 根目录(含 package.json)的绝对路径列表
17
- */
8
+ * 则认为当前项目依赖该兄弟 app,构建前需要确保兄弟 app 源码是最新的。
9
+ *
10
+ * 示例(vue.config.js):
11
+ * alias: {
12
+ * "@example-admin": projectResolve("../example-admin/src")
13
+ * }
14
+ *
15
+ * @param {string} appDir - 当前 app 目录的绝对路径
16
+ * @returns {string[]} 兄弟 app 根目录(含 package.json)的绝对路径列表
17
+ */
18
18
  function resolveSiblingAppDeps(appDir) {
19
19
  const siblings = [];
20
20
  const configFiles = [
@@ -51,13 +51,13 @@ function resolveSiblingAppDeps(appDir) {
51
51
  addSibling(match[2]);
52
52
  }
53
53
  }
54
-
55
- for (const configFile of configFiles) {
56
- const configPath = path.join(appDir, configFile);
57
- if (!fs.existsSync(configPath)) continue;
58
-
59
- const content = fs.readFileSync(configPath, "utf8");
60
-
54
+
55
+ for (const configFile of configFiles) {
56
+ const configPath = path.join(appDir, configFile);
57
+ if (!fs.existsSync(configPath)) continue;
58
+
59
+ const content = fs.readFileSync(configPath, "utf8");
60
+
61
61
  // 匹配 alias 中指向 ../ 兄弟目录的值,兼容以下写法:
62
62
  // "@foo": projectResolve("../foo/src")
63
63
  // "@foo": resolve("../foo/src")
@@ -77,8 +77,8 @@ function resolveSiblingAppDeps(appDir) {
77
77
 
78
78
  [...objectAliasPatterns, ...arrayAliasPatterns].forEach((pattern) => collectMatches(content, pattern));
79
79
  }
80
-
81
- return siblings;
82
- }
83
-
84
- module.exports = { resolveSiblingAppDeps };
80
+
81
+ return siblings;
82
+ }
83
+
84
+ module.exports = { resolveSiblingAppDeps };