@infly/libs 2.2.9 → 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,7 +36,7 @@ const {
|
|
|
36
36
|
pullSingleDirFromBranch
|
|
37
37
|
} = require("../../script/git-automation");
|
|
38
38
|
const { resolveSiblingAppDeps } = require("../build-utils/deps");
|
|
39
|
-
const { resolveGitWorktreeRoot } = require("../../script/git-automation/git-utils");
|
|
39
|
+
const { findOuterWorkspaceRoot, resolveGitWorktreeRoot } = require("../../script/git-automation/git-utils");
|
|
40
40
|
|
|
41
41
|
const scriptEvent = process.env.npm_lifecycle_event;
|
|
42
42
|
const isBuilZipScript = process.env.npm_lifecycle_event;
|
|
@@ -50,6 +50,8 @@ const projectRoot = process.cwd();
|
|
|
50
50
|
// 构建配置可以位于主仓中的子目录(例如合并后的 level/)。配置、产物仍以
|
|
51
51
|
// projectRoot 为基准,只有 Git 检查与分支更新定位到实际工作树根目录。
|
|
52
52
|
const projectGitRoot = resolveGitWorktreeRoot(projectRoot);
|
|
53
|
+
const isEmbeddedProject = projectGitRoot !== projectRoot;
|
|
54
|
+
const workspaceRoot = isEmbeddedProject ? findOuterWorkspaceRoot(projectGitRoot) : "";
|
|
53
55
|
|
|
54
56
|
// 依赖包的配置
|
|
55
57
|
const originConfigPath = currentProjectFileResolve("template-version-config.json"); // 模板项目文件
|
|
@@ -817,14 +819,17 @@ async function beforeBuild() {
|
|
|
817
819
|
return;
|
|
818
820
|
}
|
|
819
821
|
|
|
820
|
-
const
|
|
822
|
+
const sourceRepoName = isEmbeddedProject ? path.basename(projectGitRoot) : projectName;
|
|
823
|
+
const currentProjectStatus = checkSingleDirGitStatus(projectGitRoot, sourceRepoName);
|
|
821
824
|
|
|
822
825
|
if (currentProjectStatus.hasUncommitted) {
|
|
823
826
|
console.log(global.logColor.error, `\n❌ 当前项目存在未提交的更改,请先提交或暂存后再继续构建`);
|
|
824
827
|
process.exit(1);
|
|
825
828
|
}
|
|
826
829
|
|
|
827
|
-
const currentProjectUpdateResult = pullSingleDirFromBranch(
|
|
830
|
+
const currentProjectUpdateResult = pullSingleDirFromBranch(
|
|
831
|
+
projectGitRoot, sourceRepoName, targetBranch, isEmbeddedProject ? projectName : ""
|
|
832
|
+
);
|
|
828
833
|
|
|
829
834
|
if (!currentProjectUpdateResult.success) {
|
|
830
835
|
console.log(global.logColor.error, `\n❌ 当前项目切换到 ${targetBranch} 分支失败,请检查`);
|
|
@@ -843,7 +848,7 @@ async function beforeBuild() {
|
|
|
843
848
|
}
|
|
844
849
|
|
|
845
850
|
if (process.env.INFLY_SKIP_PACKAGES_UPDATE !== "1") {
|
|
846
|
-
await checkAndUpdatePackages(undefined, "master");
|
|
851
|
+
await checkAndUpdatePackages(undefined, "master", isEmbeddedProject ? projectName : "", workspaceRoot);
|
|
847
852
|
}
|
|
848
853
|
|
|
849
854
|
// 5. 检查并更新兄弟 app 依赖(通过 build config 中的 alias 推断,无需硬编码 app 名称)
|
package/package.json
CHANGED
|
@@ -65,9 +65,19 @@ function resolveGitWorktreeRoot(cwd) {
|
|
|
65
65
|
return findGitRepo(resolvedCwd)?.root || resolvedCwd;
|
|
66
66
|
}
|
|
67
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
|
+
|
|
68
77
|
module.exports = {
|
|
69
78
|
gitOutput,
|
|
70
79
|
findGitRepo,
|
|
71
80
|
getGitCommonDir,
|
|
72
|
-
resolveGitWorktreeRoot
|
|
81
|
+
resolveGitWorktreeRoot,
|
|
82
|
+
findOuterWorkspaceRoot
|
|
73
83
|
};
|
|
@@ -549,7 +549,10 @@ function hasGitModules(packagesDir) {
|
|
|
549
549
|
}
|
|
550
550
|
|
|
551
551
|
function checkAndUpdateRootPackages(packagesDir, targetBranch = "master") {
|
|
552
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
729
|
+
const warning = buildProjectName
|
|
730
|
+
? `⚠️ 内嵌项目 ${buildProjectName} 的构建目录未解析到 packages,跳过本次公共包源码更新`
|
|
731
|
+
: `⚠️ packages 目录不存在,跳过检查`;
|
|
732
|
+
console.log(global.logColor.warning, warning);
|
|
722
733
|
return;
|
|
723
734
|
}
|
|
724
735
|
|