@infly/libs 2.2.3 → 2.2.5
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
|
@@ -133,6 +133,8 @@ infly-libs release:docker --local --health-check --health-timeout=60
|
|
|
133
133
|
|
|
134
134
|
`checks` 中的名称必须对应应用已有的 pnpm script;任一检查、覆盖率文件验证、Sonar Quality Gate 或镜像健康门禁失败,命令都会退出且不会推送镜像。`sonar` 默认为 `true`;设为 `false` 时由 CI 单独负责扫描和 Quality Gate。本地启用 Sonar 时必须通过当前进程环境或应用根目录下被 Git 忽略的 `.env.production.local` 提供 `SONAR_TOKEN`,并确保 `sonar-scanner` CLI 可执行;当前进程环境变量的优先级更高。`release:docker` 会拒绝含未提交文件的应用工作树,固定使用完整 40 位应用 commit 作为镜像标签及 OCI revision/version;普通 `build:docker` 未显式传版本时同样使用完整 commit。应用差异保留在应用配置,通用编排由 `infly-libs` 维护。
|
|
135
135
|
|
|
136
|
+
`infly-libs beforeBuild` 要求应用通过 `infly.buildConfigs.gitAutoPushReposBranchMap` 声明可构建分支;当前应用、可选产物仓、历史独立 packages 仓以及 monorepo 根仓更新均只允许 fast-forward,分支发生分叉时立即停止,不自动创建 merge commit。只需要更新应用和根仓源码的项目应显式设置 `gitAuto: false` 与 `gitAutoPushRepos: false`,避免进入产物自动提交或产物仓分支处理。兄弟应用依赖会从 `vue.config.js`、`vite.config.js/mjs/ts` 和 `next.config.js/mjs/ts` 的相对路径 alias 中静态识别,不执行配置文件;识别到的兄弟仓同样要求工作树干净并以 fast-forward-only 更新。
|
|
137
|
+
|
|
136
138
|
受控紧急构建可使用 `--emergency` 跳过 `checks`、覆盖率文件校验和 Sonar,但必须提供 8~200 个字符且无控制字符的 `--emergency-reason`,并同时启用 `--standalone --commit-only --health-check`。紧急模式仍执行工作树干净检查、commit/revision 解析、镜像构建、健康检查和推送;缺少任一保护参数会在调用 Docker 前失败。
|
|
137
139
|
|
|
138
140
|
## HTTP 环境保护配置
|
|
@@ -825,13 +825,16 @@ async function beforeBuild() {
|
|
|
825
825
|
process.exit(1);
|
|
826
826
|
}
|
|
827
827
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
828
|
+
// 当前项目已经在上方完成更新;只有显式启用产物仓时才处理产物仓分支。
|
|
829
|
+
if (gitAutoPushRepos) {
|
|
830
|
+
await autoBranchProcess({
|
|
831
|
+
gitAutoPushRepos,
|
|
832
|
+
gitAutoPushReposBranchMap,
|
|
833
|
+
currentBranch: targetBranch,
|
|
834
|
+
targetProjectOutputDir,
|
|
835
|
+
validateConfig: () => {}
|
|
836
|
+
});
|
|
837
|
+
}
|
|
835
838
|
|
|
836
839
|
if (process.env.INFLY_SKIP_PACKAGES_UPDATE !== "1") {
|
|
837
840
|
await checkAndUpdatePackages(undefined, "master");
|
|
@@ -4,7 +4,7 @@ const path = require("path");
|
|
|
4
4
|
/**
|
|
5
5
|
* 从项目的 webpack/vite 等构建配置中解析对兄弟 app 的依赖。
|
|
6
6
|
*
|
|
7
|
-
* 规则:如果 vue.config.js / next.config.* 的 alias 中存在指向 ../ 的路径,
|
|
7
|
+
* 规则:如果 vue.config.js / vite.config.* / next.config.* 的 alias 中存在指向 ../ 的路径,
|
|
8
8
|
* 则认为当前项目依赖该兄弟 app,构建前需要确保兄弟 app 源码是最新的。
|
|
9
9
|
*
|
|
10
10
|
* 示例(vue.config.js):
|
|
@@ -15,14 +15,42 @@ const path = require("path");
|
|
|
15
15
|
* @param {string} appDir - 当前 app 目录的绝对路径
|
|
16
16
|
* @returns {string[]} 兄弟 app 根目录(含 package.json)的绝对路径列表
|
|
17
17
|
*/
|
|
18
|
-
function resolveSiblingAppDeps(appDir) {
|
|
19
|
-
const siblings = [];
|
|
20
|
-
const configFiles = [
|
|
21
|
-
"vue.config.js",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
18
|
+
function resolveSiblingAppDeps(appDir) {
|
|
19
|
+
const siblings = [];
|
|
20
|
+
const configFiles = [
|
|
21
|
+
"vue.config.js",
|
|
22
|
+
"vite.config.js",
|
|
23
|
+
"vite.config.mjs",
|
|
24
|
+
"vite.config.ts",
|
|
25
|
+
"next.config.js",
|
|
26
|
+
"next.config.mjs",
|
|
27
|
+
"next.config.ts"
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
function addSibling(relativePath) {
|
|
31
|
+
const resolved = path.resolve(appDir, relativePath);
|
|
32
|
+
|
|
33
|
+
// 向上查找含 package.json 的目录,即 app 根目录
|
|
34
|
+
let current = resolved;
|
|
35
|
+
for (let i = 0; i < 5; i++) {
|
|
36
|
+
if (fs.existsSync(path.join(current, "package.json"))) {
|
|
37
|
+
if (current !== appDir && !siblings.includes(current)) {
|
|
38
|
+
siblings.push(current);
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
const parent = path.dirname(current);
|
|
43
|
+
if (parent === current) break;
|
|
44
|
+
current = parent;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function collectMatches(content, pattern) {
|
|
49
|
+
let match;
|
|
50
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
51
|
+
addSibling(match[2]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
26
54
|
|
|
27
55
|
for (const configFile of configFiles) {
|
|
28
56
|
const configPath = path.join(appDir, configFile);
|
|
@@ -30,32 +58,25 @@ function resolveSiblingAppDeps(appDir) {
|
|
|
30
58
|
|
|
31
59
|
const content = fs.readFileSync(configPath, "utf8");
|
|
32
60
|
|
|
33
|
-
// 匹配 alias 中指向 ../ 兄弟目录的值,兼容以下写法:
|
|
34
|
-
// "@foo": projectResolve("../foo/src")
|
|
35
|
-
// "@foo": resolve("../foo/src")
|
|
36
|
-
// "@foo": path.resolve(__dirname, "../foo/src")
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
const parent = path.dirname(current);
|
|
54
|
-
if (parent === current) break;
|
|
55
|
-
current = parent;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
61
|
+
// 匹配 alias 中指向 ../ 兄弟目录的值,兼容以下写法:
|
|
62
|
+
// "@foo": projectResolve("../foo/src")
|
|
63
|
+
// "@foo": resolve("../foo/src")
|
|
64
|
+
// "@foo": path.resolve(__dirname, "../foo/src")
|
|
65
|
+
// "@foo": fileURLToPath(new URL("../foo/src", import.meta.url))
|
|
66
|
+
// { find: "@foo", replacement: path.resolve(appRoot, "../foo/src") }
|
|
67
|
+
const objectAliasPatterns = [
|
|
68
|
+
/["'](@[^"']+)["']\s*:\s*(?:projectResolve|resolve)\s*\(\s*["'](\.\.\/[^"']+)["']/g,
|
|
69
|
+
/["'](@[^"']+)["']\s*:\s*path\.resolve\s*\(\s*(?:__dirname|appRoot|rootDir|projectRoot)\s*,\s*["'](\.\.\/[^"']+)["']/g,
|
|
70
|
+
/["'](@[^"']+)["']\s*:\s*fileURLToPath\s*\(\s*new\s+URL\s*\(\s*["'](\.\.\/[^"']+)["']\s*,\s*import\.meta\.url/g
|
|
71
|
+
];
|
|
72
|
+
const arrayAliasPatterns = [
|
|
73
|
+
/\bfind\s*:\s*["'](@[^"']+)["']\s*,\s*\breplacement\s*:\s*(?:projectResolve|resolve)\s*\(\s*["'](\.\.\/[^"']+)["']/g,
|
|
74
|
+
/\bfind\s*:\s*["'](@[^"']+)["']\s*,\s*\breplacement\s*:\s*path\.resolve\s*\(\s*(?:__dirname|appRoot|rootDir|projectRoot)\s*,\s*["'](\.\.\/[^"']+)["']/g,
|
|
75
|
+
/\bfind\s*:\s*["'](@[^"']+)["']\s*,\s*\breplacement\s*:\s*fileURLToPath\s*\(\s*new\s+URL\s*\(\s*["'](\.\.\/[^"']+)["']\s*,\s*import\.meta\.url/g
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
[...objectAliasPatterns, ...arrayAliasPatterns].forEach((pattern) => collectMatches(content, pattern));
|
|
79
|
+
}
|
|
59
80
|
|
|
60
81
|
return siblings;
|
|
61
82
|
}
|
|
@@ -274,6 +274,10 @@ async function runTargetRelease(options = {}, dependencies = {}) {
|
|
|
274
274
|
if (!/^[a-f0-9]{40}$/.test(commit) || commit !== git("rev-parse", `${expectedRef}^{commit}`).toLowerCase()) {
|
|
275
275
|
throw new Error(`${item.name} HEAD 与 ${expectedRef} 不一致,请先核对并 fetch 对应仓库`);
|
|
276
276
|
}
|
|
277
|
+
if (item.source) {
|
|
278
|
+
const sourceLabel = item.name === "backend" ? "后端" : (item.label || item.name);
|
|
279
|
+
log(`\x1b[0;32m✓ ${sourceLabel}构建分支:${item.source.branch}\x1b[0m`);
|
|
280
|
+
}
|
|
277
281
|
let context = inside(sourceDir, item.context || ".");
|
|
278
282
|
let dockerfile = inside(sourceDir, item.dockerfile || "Dockerfile");
|
|
279
283
|
for (const file of item.requiredFiles || []) {
|
package/package.json
CHANGED
|
@@ -326,7 +326,7 @@ async function autoBranchProcess(config) {
|
|
|
326
326
|
const tempBranch = gitAutoPushRepos ? gitAutoPushReposBranchMap[currentBranch] : currentBranch;
|
|
327
327
|
const targetProjectOutputDirCmd = gitAutoPushRepos ? ` -C ${targetProjectOutputDir}` : "";
|
|
328
328
|
const checkoutCmd = `git${targetProjectOutputDirCmd} checkout ${tempBranch}`;
|
|
329
|
-
const pullCmd = `git${targetProjectOutputDirCmd} pull origin ${tempBranch}`;
|
|
329
|
+
const pullCmd = `git${targetProjectOutputDirCmd} pull --ff-only origin ${tempBranch}`;
|
|
330
330
|
const fileList = checkGitStatus(undefined, undefined, {
|
|
331
331
|
onlyCheckStatus: true,
|
|
332
332
|
targetProjectOutputDir,
|
|
@@ -459,7 +459,7 @@ async function pullPackagesFromMaster(packagesDir, targetBranch = "master") {
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
// 拉取最新代码
|
|
462
|
-
await execAsync(`git pull origin ${targetBranch}`, { cwd: modulePath });
|
|
462
|
+
await execAsync(`git pull --ff-only origin ${targetBranch}`, { cwd: modulePath });
|
|
463
463
|
|
|
464
464
|
console.log(global.logColor.success, `✅ \x1b[34m${module}\x1b[32m[${targetBranch}]: 更新到最新代码`);
|
|
465
465
|
return { module, success: true };
|
|
@@ -634,7 +634,7 @@ function pullSingleDirFromBranch(dirPath, dirName, targetBranch = "master") {
|
|
|
634
634
|
|
|
635
635
|
// 拉取最新代码
|
|
636
636
|
// console.log(global.logColor.info, ` ${dirName}: 拉取 ${targetBranch} 最新代码...`);
|
|
637
|
-
execSync(`git pull origin ${targetBranch}`, {
|
|
637
|
+
execSync(`git pull --ff-only origin ${targetBranch}`, {
|
|
638
638
|
cwd: dirPath,
|
|
639
639
|
stdio: "pipe"
|
|
640
640
|
});
|