@infly/libs 2.2.8 → 2.2.10

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.
@@ -36,6 +36,7 @@ const {
36
36
  pullSingleDirFromBranch
37
37
  } = require("../../script/git-automation");
38
38
  const { resolveSiblingAppDeps } = require("../build-utils/deps");
39
+ const { findOuterWorkspaceRoot, resolveGitWorktreeRoot } = require("../../script/git-automation/git-utils");
39
40
 
40
41
  const scriptEvent = process.env.npm_lifecycle_event;
41
42
  const isBuilZipScript = process.env.npm_lifecycle_event;
@@ -46,6 +47,11 @@ const npmPackageConfigKey = "infly";
46
47
  const currentBranch = getCurrentBranch();
47
48
 
48
49
  const projectRoot = process.cwd();
50
+ // 构建配置可以位于主仓中的子目录(例如合并后的 level/)。配置、产物仍以
51
+ // projectRoot 为基准,只有 Git 检查与分支更新定位到实际工作树根目录。
52
+ const projectGitRoot = resolveGitWorktreeRoot(projectRoot);
53
+ const isEmbeddedProject = projectGitRoot !== projectRoot;
54
+ const workspaceRoot = isEmbeddedProject ? findOuterWorkspaceRoot(projectGitRoot) : "";
49
55
 
50
56
  // 依赖包的配置
51
57
  const originConfigPath = currentProjectFileResolve("template-version-config.json"); // 模板项目文件
@@ -813,14 +819,17 @@ async function beforeBuild() {
813
819
  return;
814
820
  }
815
821
 
816
- const currentProjectStatus = checkSingleDirGitStatus(projectRoot, projectName);
822
+ const sourceRepoName = isEmbeddedProject ? path.basename(projectGitRoot) : projectName;
823
+ const currentProjectStatus = checkSingleDirGitStatus(projectGitRoot, sourceRepoName);
817
824
 
818
825
  if (currentProjectStatus.hasUncommitted) {
819
826
  console.log(global.logColor.error, `\n❌ 当前项目存在未提交的更改,请先提交或暂存后再继续构建`);
820
827
  process.exit(1);
821
828
  }
822
829
 
823
- const currentProjectUpdateResult = pullSingleDirFromBranch(projectRoot, projectName, targetBranch);
830
+ const currentProjectUpdateResult = pullSingleDirFromBranch(
831
+ projectGitRoot, sourceRepoName, targetBranch, isEmbeddedProject ? projectName : ""
832
+ );
824
833
 
825
834
  if (!currentProjectUpdateResult.success) {
826
835
  console.log(global.logColor.error, `\n❌ 当前项目切换到 ${targetBranch} 分支失败,请检查`);
@@ -839,7 +848,7 @@ async function beforeBuild() {
839
848
  }
840
849
 
841
850
  if (process.env.INFLY_SKIP_PACKAGES_UPDATE !== "1") {
842
- await checkAndUpdatePackages(undefined, "master");
851
+ await checkAndUpdatePackages(undefined, "master", isEmbeddedProject ? projectName : "", workspaceRoot);
843
852
  }
844
853
 
845
854
  // 5. 检查并更新兄弟 app 依赖(通过 build config 中的 alias 推断,无需硬编码 app 名称)
@@ -66,7 +66,9 @@ async function selectOptions(message, choices, dependencies = {}) {
66
66
  name: "selections",
67
67
  message,
68
68
  indicator: { on: "[√]", off: "[ ]" },
69
- hint: "↑/↓ 移动,空格勾选/取消,回车确认,Ctrl+C 退出(至少选择一项)",
69
+ // Enquirer 不会正确清除 Git Bash 中发生自动换行的提示行,提示过长时
70
+ // 每次移动光标都会残留一帧。保持简短,最少选择一项由 min 校验提示。
71
+ hint: "空格选择,回车确认",
70
72
  stdin,
71
73
  stdout,
72
74
  min: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infly/libs",
3
- "version": "2.2.8",
3
+ "version": "2.2.10",
4
4
  "description": "不受前端框架限制的独立工具库",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -64,6 +64,7 @@
64
64
  "dotenv": "16.6.1",
65
65
  "enquirer": "^2.4.1",
66
66
  "path-browserify": "^1.0.1",
67
+ "sass": "^1.69.5",
67
68
  "serve-static": "^1.15.0",
68
69
  "yaml": "^2.3.4"
69
70
  },
@@ -45,7 +45,7 @@ function findGitRepo(cwd) {
45
45
  }
46
46
  }
47
47
 
48
- function getGitCommonDir(cwd) {
48
+ function getGitCommonDir(cwd) {
49
49
  const repo = findGitRepo(cwd);
50
50
 
51
51
  if (repo) {
@@ -58,10 +58,26 @@ function getGitCommonDir(cwd) {
58
58
  } catch {
59
59
  return path.resolve(cwd || process.cwd());
60
60
  }
61
- }
62
-
63
- module.exports = {
64
- gitOutput,
65
- findGitRepo,
66
- getGitCommonDir
67
- };
61
+ }
62
+
63
+ function resolveGitWorktreeRoot(cwd) {
64
+ const resolvedCwd = path.resolve(cwd || process.cwd());
65
+ return findGitRepo(resolvedCwd)?.root || resolvedCwd;
66
+ }
67
+
68
+ function findOuterWorkspaceRoot(projectGitRoot) {
69
+ const outerRoot = findGitRepo(path.dirname(projectGitRoot))?.root;
70
+ if (!outerRoot || !fs.existsSync(path.join(outerRoot, ".gitmodules")) ||
71
+ !fs.existsSync(path.join(outerRoot, "pnpm-workspace.yaml"))) {
72
+ return "";
73
+ }
74
+ return outerRoot;
75
+ }
76
+
77
+ module.exports = {
78
+ gitOutput,
79
+ findGitRepo,
80
+ getGitCommonDir,
81
+ resolveGitWorktreeRoot,
82
+ findOuterWorkspaceRoot
83
+ };
@@ -549,7 +549,10 @@ function hasGitModules(packagesDir) {
549
549
  }
550
550
 
551
551
  function checkAndUpdateRootPackages(packagesDir, targetBranch = "master") {
552
- const rootDir = path.resolve(packagesDir, "..");
552
+ return checkAndUpdateRootRepository(path.resolve(packagesDir, ".."), targetBranch);
553
+ }
554
+
555
+ function checkAndUpdateRootRepository(rootDir, targetBranch = "master") {
553
556
  const gitPath = path.join(rootDir, ".git");
554
557
 
555
558
  if (!fs.existsSync(gitPath)) {
@@ -595,7 +598,7 @@ function checkAndUpdateRootPackages(packagesDir, targetBranch = "master") {
595
598
  function findPackagesDir(currentDir) {
596
599
  let searchDir = currentDir || process.cwd();
597
600
 
598
- // 向上查找 packages 目录,最多查找 3 层
601
+ // 旧版 packages/* 独立仓库模式保留近层目录查找。
599
602
  for (let i = 0; i < 3; i++) {
600
603
  const packagesPath = path.resolve(searchDir, "packages");
601
604
  if (fs.existsSync(packagesPath)) {
@@ -662,7 +665,7 @@ function checkSingleDirGitStatus(dirPath, dirName) {
662
665
  * @param {string} dirName - 目录名称(用于日志显示)
663
666
  * @param {string} targetBranch - 目标分支名
664
667
  */
665
- function pullSingleDirFromBranch(dirPath, dirName, targetBranch = "master") {
668
+ function pullSingleDirFromBranch(dirPath, dirName, targetBranch = "master", buildProjectName = "") {
666
669
  const fs = require("fs");
667
670
 
668
671
  if (!fs.existsSync(dirPath)) {
@@ -699,7 +702,8 @@ function pullSingleDirFromBranch(dirPath, dirName, targetBranch = "master") {
699
702
  stdio: "pipe"
700
703
  });
701
704
 
702
- console.log(global.logColor.success, `✅ \x1b[34m${dirName}\x1b[32m[${targetBranch}]: 更新到最新代码`);
705
+ const buildProjectText = buildProjectName ? `(构建项目:${buildProjectName})` : "";
706
+ console.log(global.logColor.success, `✅ \x1b[34m${dirName}\x1b[32m[${targetBranch}]: 更新到最新代码${buildProjectText}`);
703
707
  return { success: true };
704
708
  } catch (error) {
705
709
  console.error(global.logColor.error, `❌ ${dirName}: 操作失败 - ${error.message}`);
@@ -712,13 +716,20 @@ function pullSingleDirFromBranch(dirPath, dirName, targetBranch = "master") {
712
716
  * @param {string} packagesDir - packages 目录的绝对路径
713
717
  * @param {string} targetBranch - 目标分支名,默认为 'master'
714
718
  */
715
- async function checkAndUpdatePackages(outPackagesDir, targetBranch = "master") {
719
+ async function checkAndUpdatePackages(outPackagesDir, targetBranch = "master", buildProjectName = "", rootDir = "") {
716
720
  try {
721
+ if (rootDir) {
722
+ return checkAndUpdateRootRepository(rootDir, targetBranch);
723
+ }
724
+
717
725
  const packagesDir = outPackagesDir || findPackagesDir();
718
726
 
719
727
  // 检查 packages 目录是否存在
720
728
  if (!packagesDir) {
721
- console.log(global.logColor.warning, `⚠️ packages 目录不存在,跳过检查`);
729
+ const warning = buildProjectName
730
+ ? `⚠️ 内嵌项目 ${buildProjectName} 的构建目录未解析到 packages,跳过本次公共包源码更新`
731
+ : `⚠️ packages 目录不存在,跳过检查`;
732
+ console.log(global.logColor.warning, warning);
722
733
  return;
723
734
  }
724
735