@infly/libs 2.2.5 → 2.2.7
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/adapters/webpack/auto-export.js +52 -52
- package/build/build-dist/index.js +3 -1
- package/build/build-utils/command.js +57 -57
- package/build/build-utils/deps.js +28 -28
- package/build/build-utils/git.js +254 -254
- package/build/build-utils/preview.js +78 -78
- package/build/build-utils/webhook-single.js +136 -136
- package/build/docker/compose-release.js +79 -79
- package/build/docker/docker-build-push.js +96 -4
- package/build/project-files.js +47 -47
- package/core/async/concurrency.js +29 -29
- package/package.json +1 -1
- package/script/git-automation/index.js +68 -7
- package/script/git-automation/submodule-utils.js +16 -16
- package/workspace/config.js +144 -144
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 框架无关的异步并发控制。
|
|
3
|
-
* 异步并发限流器。
|
|
4
|
-
* 对 items 数组中的每一项执行 worker,同时最多运行 concurrency 个 worker。
|
|
5
|
-
*
|
|
6
|
-
* @param {Array} items - 待处理项
|
|
7
|
-
* @param {number} concurrency - 最大并发数
|
|
8
|
-
* @param {Function} worker - 处理函数 (item, index) => Promise
|
|
9
|
-
* @returns {Promise<Array>} 结果数组,索引与 items 一一对应
|
|
10
|
-
*/
|
|
11
|
-
async function runWithConcurrency(items, concurrency, worker) {
|
|
12
|
-
if (!Number.isInteger(concurrency) || concurrency < 1) {
|
|
13
|
-
throw new TypeError("concurrency must be a positive integer");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const results = new Array(items.length);
|
|
17
|
-
let nextIndex = 0;
|
|
18
|
-
const runWorker = async () => {
|
|
19
|
-
while (nextIndex < items.length) {
|
|
20
|
-
const index = nextIndex;
|
|
21
|
-
nextIndex += 1;
|
|
22
|
-
results[index] = await worker(items[index], index);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const workerCount = Math.min(concurrency, items.length);
|
|
27
|
-
await Promise.all(Array.from({ length: workerCount }, runWorker));
|
|
28
|
-
return results;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = { runWithConcurrency };
|
|
3
|
+
* 异步并发限流器。
|
|
4
|
+
* 对 items 数组中的每一项执行 worker,同时最多运行 concurrency 个 worker。
|
|
5
|
+
*
|
|
6
|
+
* @param {Array} items - 待处理项
|
|
7
|
+
* @param {number} concurrency - 最大并发数
|
|
8
|
+
* @param {Function} worker - 处理函数 (item, index) => Promise
|
|
9
|
+
* @returns {Promise<Array>} 结果数组,索引与 items 一一对应
|
|
10
|
+
*/
|
|
11
|
+
async function runWithConcurrency(items, concurrency, worker) {
|
|
12
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) {
|
|
13
|
+
throw new TypeError("concurrency must be a positive integer");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const results = new Array(items.length);
|
|
17
|
+
let nextIndex = 0;
|
|
18
|
+
const runWorker = async () => {
|
|
19
|
+
while (nextIndex < items.length) {
|
|
20
|
+
const index = nextIndex;
|
|
21
|
+
nextIndex += 1;
|
|
22
|
+
results[index] = await worker(items[index], index);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const workerCount = Math.min(concurrency, items.length);
|
|
27
|
+
await Promise.all(Array.from({ length: workerCount }, runWorker));
|
|
28
|
+
return results;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { runWithConcurrency };
|
package/package.json
CHANGED
|
@@ -18,15 +18,17 @@ function getCurrentBranch() {
|
|
|
18
18
|
* 获取 Git 提交信息
|
|
19
19
|
* @returns {Object} 包含提交信息的对象,如果获取失败则返回空对象
|
|
20
20
|
*/
|
|
21
|
-
function getLatestCommitInfo() {
|
|
21
|
+
function getLatestCommitInfo(cwd = process.cwd()) {
|
|
22
22
|
// 定义 Git 命令
|
|
23
23
|
const commands = {
|
|
24
|
-
|
|
24
|
+
// 构建元数据必须全部对应源码 HEAD。跳过 merge commit 会导致 fullHash 指向
|
|
25
|
+
// 当前合并提交,而文案、作者却回退到更早的版本构建提交。
|
|
26
|
+
commitMsg: "git log -1 --pretty=%B",
|
|
25
27
|
branch: "git rev-parse --abbrev-ref HEAD",
|
|
26
28
|
fullHash: "git rev-parse HEAD",
|
|
27
|
-
author: "git log -1 --
|
|
28
|
-
email: "git log -1 --
|
|
29
|
-
date: "git log -1 --
|
|
29
|
+
author: "git log -1 --pretty=%an",
|
|
30
|
+
email: "git log -1 --pretty=%ae",
|
|
31
|
+
date: "git log -1 --pretty=%cd --date=iso"
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
// 结果对象
|
|
@@ -34,12 +36,12 @@ function getLatestCommitInfo() {
|
|
|
34
36
|
|
|
35
37
|
try {
|
|
36
38
|
// 检查当前目录是否是 Git 仓库
|
|
37
|
-
execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
|
|
39
|
+
execSync("git rev-parse --is-inside-work-tree", { cwd, stdio: "ignore" });
|
|
38
40
|
|
|
39
41
|
// 遍历命令并执行
|
|
40
42
|
for (const [key, command] of Object.entries(commands)) {
|
|
41
43
|
try {
|
|
42
|
-
commitInfo[key] = execSync(`${command}`, { encoding: "utf-8" }).trim();
|
|
44
|
+
commitInfo[key] = execSync(`${command}`, { cwd, encoding: "utf-8" }).trim();
|
|
43
45
|
} catch (cmdError) {
|
|
44
46
|
console.warn(global.logColor.warning, `⚠️️ 获取 Git 信息失败(${key}):${cmdError.message}`);
|
|
45
47
|
commitInfo[key] = ""; // 失败时设置为空字符串
|
|
@@ -56,6 +58,64 @@ function getLatestCommitInfo() {
|
|
|
56
58
|
return commitInfo;
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
function createCommitTextMatcher(template = "") {
|
|
62
|
+
if (!template) return null;
|
|
63
|
+
|
|
64
|
+
const escapedParts = template
|
|
65
|
+
.split("{version}")
|
|
66
|
+
.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
67
|
+
return new RegExp(`^${escapedParts.join(".+?")}$`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 获取上一次自动版本提交之后的业务提交摘要。
|
|
72
|
+
* Merge 提交只描述 Git 操作,不作为企业微信中的更新内容。
|
|
73
|
+
* @param {String} gitAutoCommitText 自动版本提交模板
|
|
74
|
+
* @param {String} cwd Git 仓库目录
|
|
75
|
+
* @param {Number} limit 最多展示的提交数
|
|
76
|
+
* @returns {String} 构建更新摘要;无法识别版本基线时返回空字符串
|
|
77
|
+
*/
|
|
78
|
+
function getBuildUpdateText(gitAutoCommitText, cwd = process.cwd(), limit = 10) {
|
|
79
|
+
const matcher = createCommitTextMatcher(gitAutoCommitText);
|
|
80
|
+
if (!matcher) return "";
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const history = execSync("git log --format=%H%x1f%s", { cwd, encoding: "utf-8" })
|
|
84
|
+
.trim()
|
|
85
|
+
.split(/\r?\n/)
|
|
86
|
+
.filter(Boolean)
|
|
87
|
+
.map((line) => {
|
|
88
|
+
const separatorIndex = line.indexOf("\x1f");
|
|
89
|
+
return {
|
|
90
|
+
hash: line.slice(0, separatorIndex),
|
|
91
|
+
subject: line.slice(separatorIndex + 1)
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
const previousBuild = history.find(({ hash, subject }) => /^[0-9a-f]{40}$/i.test(hash) && matcher.test(subject));
|
|
95
|
+
|
|
96
|
+
if (!previousBuild) return "";
|
|
97
|
+
|
|
98
|
+
const subjects = execSync(`git log --no-merges --format=%s ${previousBuild.hash}..HEAD`, {
|
|
99
|
+
cwd,
|
|
100
|
+
encoding: "utf-8"
|
|
101
|
+
})
|
|
102
|
+
.trim()
|
|
103
|
+
.split(/\r?\n/)
|
|
104
|
+
.filter(Boolean);
|
|
105
|
+
|
|
106
|
+
if (subjects.length === 0) return "无源码提交变更";
|
|
107
|
+
|
|
108
|
+
const visibleSubjects = subjects.slice(0, limit);
|
|
109
|
+
if (subjects.length > limit) {
|
|
110
|
+
visibleSubjects.push(`...另 ${subjects.length - limit} 条提交`);
|
|
111
|
+
}
|
|
112
|
+
return visibleSubjects.map((subject) => `- ${subject}`).join("\n");
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.warn(global.logColor.warning, `⚠️️ 获取构建更新摘要失败:${error.message}`);
|
|
115
|
+
return "";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
59
119
|
/**
|
|
60
120
|
* 获取指定文件的最后一次提交信息
|
|
61
121
|
* @param {String} filePath - 文件路径
|
|
@@ -703,6 +763,7 @@ async function checkAndUpdatePackages(outPackagesDir, targetBranch = "master") {
|
|
|
703
763
|
module.exports = {
|
|
704
764
|
getCurrentBranch,
|
|
705
765
|
getLatestCommitInfo,
|
|
766
|
+
getBuildUpdateText,
|
|
706
767
|
getLastCommitByFile,
|
|
707
768
|
checkGitStatus,
|
|
708
769
|
autoGitProcess,
|
|
@@ -3,20 +3,20 @@ const fs = require("fs");
|
|
|
3
3
|
function normalizeRelativePath(value) {
|
|
4
4
|
return String(value).replace(/\\/g, "/");
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 从 .gitmodules 中解析所有子模块路径
|
|
9
|
-
*/
|
|
10
|
-
function parseGitmodulesPaths(rootDir) {
|
|
11
|
-
const p = require("path").join(rootDir, ".gitmodules");
|
|
12
|
-
if (!fs.existsSync(p)) return [];
|
|
13
|
-
const content = fs.readFileSync(p, "utf8");
|
|
14
|
-
const paths = [];
|
|
15
|
-
content.split(/\[submodule/).forEach((block) => {
|
|
16
|
-
const m = block.match(/path\s*=\s*(.+)/);
|
|
17
|
-
if (m) paths.push(m[1].trim());
|
|
18
|
-
});
|
|
19
|
-
return paths;
|
|
20
|
-
}
|
|
21
|
-
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 从 .gitmodules 中解析所有子模块路径
|
|
9
|
+
*/
|
|
10
|
+
function parseGitmodulesPaths(rootDir) {
|
|
11
|
+
const p = require("path").join(rootDir, ".gitmodules");
|
|
12
|
+
if (!fs.existsSync(p)) return [];
|
|
13
|
+
const content = fs.readFileSync(p, "utf8");
|
|
14
|
+
const paths = [];
|
|
15
|
+
content.split(/\[submodule/).forEach((block) => {
|
|
16
|
+
const m = block.match(/path\s*=\s*(.+)/);
|
|
17
|
+
if (m) paths.push(m[1].trim());
|
|
18
|
+
});
|
|
19
|
+
return paths;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
22
|
module.exports = { normalizeRelativePath, parseGitmodulesPaths };
|
package/workspace/config.js
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
1
|
// workspace 配置读取与模式展开。
|
|
2
2
|
const fs = require("fs");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const YAML = require("yaml");
|
|
5
|
-
|
|
6
|
-
function readJson(filePath) {
|
|
7
|
-
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function readWorkspaceList(content, sectionName) {
|
|
11
|
-
let workspaceConfig;
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
workspaceConfig = YAML.parse(content);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
throw new Error(`无法解析 pnpm-workspace.yaml: ${error.message}`, { cause: error });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (workspaceConfig == null) {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (typeof workspaceConfig !== "object" || Array.isArray(workspaceConfig)) {
|
|
24
|
-
throw new TypeError("pnpm-workspace.yaml 的根节点必须是对象");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const patterns = workspaceConfig[sectionName];
|
|
28
|
-
|
|
29
|
-
if (patterns == null) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
!Array.isArray(patterns)
|
|
35
|
-
|| patterns.some((pattern) => typeof pattern !== "string" || pattern.trim().length === 0)
|
|
36
|
-
) {
|
|
37
|
-
throw new TypeError(`pnpm-workspace.yaml 的 ${sectionName} 必须是非空字符串数组`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return patterns;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function readWorkspaceSection(workspaceFile, sectionName) {
|
|
44
|
-
return readWorkspaceList(fs.readFileSync(workspaceFile, "utf8"), sectionName);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function readWorkspaceSectionWithFallback(workspaceFile, sectionName, fallbackSectionName) {
|
|
48
|
-
const patterns = readWorkspaceSection(workspaceFile, sectionName);
|
|
49
|
-
|
|
50
|
-
if (patterns.length > 0) {
|
|
51
|
-
return patterns;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return readWorkspaceSection(workspaceFile, fallbackSectionName);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function expandWorkspacePattern(rootDir, pattern) {
|
|
58
|
-
const normalizedPattern = pattern.replace(/\\/g, "/");
|
|
59
|
-
|
|
60
|
-
if (!normalizedPattern.includes("*")) {
|
|
61
|
-
return [path.join(rootDir, normalizedPattern)];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const starIndex = normalizedPattern.indexOf("*");
|
|
65
|
-
const basePart = normalizedPattern.slice(0, starIndex);
|
|
66
|
-
const suffixPart = normalizedPattern.slice(starIndex + 1);
|
|
67
|
-
const baseDir = path.join(rootDir, basePart);
|
|
68
|
-
|
|
69
|
-
if (!fs.existsSync(baseDir)) {
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const suffixIsNamePattern = suffixPart && !suffixPart.startsWith("/");
|
|
74
|
-
|
|
75
|
-
return fs
|
|
76
|
-
.readdirSync(baseDir, { withFileTypes: true })
|
|
77
|
-
.filter((entry) => entry.isDirectory())
|
|
78
|
-
.filter((entry) => !suffixIsNamePattern || entry.name.endsWith(suffixPart))
|
|
79
|
-
.map((entry) => (suffixIsNamePattern
|
|
80
|
-
? path.join(baseDir, entry.name)
|
|
81
|
-
: path.join(baseDir, entry.name, suffixPart)))
|
|
82
|
-
.filter((packageDir) => fs.existsSync(path.join(packageDir, "package.json")));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function getWorkspacePackages(rootDir, workspaceFile, sectionName, fallbackSectionName, scriptName) {
|
|
86
|
-
const patterns = fallbackSectionName
|
|
87
|
-
? readWorkspaceSectionWithFallback(workspaceFile, sectionName, fallbackSectionName)
|
|
88
|
-
: readWorkspaceSection(workspaceFile, sectionName);
|
|
89
|
-
const included = new Set();
|
|
90
|
-
patterns.forEach((pattern) => {
|
|
91
|
-
const excluded = pattern.startsWith("!");
|
|
92
|
-
const resolvedPattern = excluded ? pattern.slice(1) : pattern;
|
|
93
|
-
expandWorkspacePattern(rootDir, resolvedPattern).forEach((packageDir) => {
|
|
94
|
-
const resolvedDir = path.resolve(packageDir);
|
|
95
|
-
if (excluded) included.delete(resolvedDir);
|
|
96
|
-
else included.add(resolvedDir);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
const packageDirs = [...included];
|
|
100
|
-
const seen = new Set();
|
|
101
|
-
|
|
102
|
-
return packageDirs
|
|
103
|
-
.map((packageDir) => {
|
|
104
|
-
const packageJsonPath = path.join(packageDir, "package.json");
|
|
105
|
-
|
|
106
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const packageJson = readJson(packageJsonPath);
|
|
111
|
-
const scripts = packageJson.scripts || {};
|
|
112
|
-
|
|
113
|
-
if (!packageJson.name || seen.has(packageJson.name) || (scriptName && !scripts[scriptName])) {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
seen.add(packageJson.name);
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
name: packageJson.name,
|
|
121
|
-
dir: path.relative(rootDir, packageDir),
|
|
122
|
-
packageJson,
|
|
123
|
-
};
|
|
124
|
-
})
|
|
125
|
-
.filter(Boolean);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function toTurboFilter(value) {
|
|
129
|
-
const normalized = value.replace(/\\/g, "/");
|
|
130
|
-
|
|
131
|
-
if (normalized.includes("/") && !normalized.startsWith("./") && !normalized.startsWith("../")) {
|
|
132
|
-
return `./${normalized}`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return normalized;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
module.exports = {
|
|
139
|
-
expandWorkspacePattern,
|
|
140
|
-
getWorkspacePackages,
|
|
141
|
-
readJson,
|
|
142
|
-
readWorkspaceList,
|
|
143
|
-
readWorkspaceSection,
|
|
144
|
-
readWorkspaceSectionWithFallback,
|
|
145
|
-
toTurboFilter,
|
|
146
|
-
};
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const YAML = require("yaml");
|
|
5
|
+
|
|
6
|
+
function readJson(filePath) {
|
|
7
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function readWorkspaceList(content, sectionName) {
|
|
11
|
+
let workspaceConfig;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
workspaceConfig = YAML.parse(content);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
throw new Error(`无法解析 pnpm-workspace.yaml: ${error.message}`, { cause: error });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (workspaceConfig == null) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof workspaceConfig !== "object" || Array.isArray(workspaceConfig)) {
|
|
24
|
+
throw new TypeError("pnpm-workspace.yaml 的根节点必须是对象");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const patterns = workspaceConfig[sectionName];
|
|
28
|
+
|
|
29
|
+
if (patterns == null) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
!Array.isArray(patterns)
|
|
35
|
+
|| patterns.some((pattern) => typeof pattern !== "string" || pattern.trim().length === 0)
|
|
36
|
+
) {
|
|
37
|
+
throw new TypeError(`pnpm-workspace.yaml 的 ${sectionName} 必须是非空字符串数组`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return patterns;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readWorkspaceSection(workspaceFile, sectionName) {
|
|
44
|
+
return readWorkspaceList(fs.readFileSync(workspaceFile, "utf8"), sectionName);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readWorkspaceSectionWithFallback(workspaceFile, sectionName, fallbackSectionName) {
|
|
48
|
+
const patterns = readWorkspaceSection(workspaceFile, sectionName);
|
|
49
|
+
|
|
50
|
+
if (patterns.length > 0) {
|
|
51
|
+
return patterns;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return readWorkspaceSection(workspaceFile, fallbackSectionName);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function expandWorkspacePattern(rootDir, pattern) {
|
|
58
|
+
const normalizedPattern = pattern.replace(/\\/g, "/");
|
|
59
|
+
|
|
60
|
+
if (!normalizedPattern.includes("*")) {
|
|
61
|
+
return [path.join(rootDir, normalizedPattern)];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const starIndex = normalizedPattern.indexOf("*");
|
|
65
|
+
const basePart = normalizedPattern.slice(0, starIndex);
|
|
66
|
+
const suffixPart = normalizedPattern.slice(starIndex + 1);
|
|
67
|
+
const baseDir = path.join(rootDir, basePart);
|
|
68
|
+
|
|
69
|
+
if (!fs.existsSync(baseDir)) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const suffixIsNamePattern = suffixPart && !suffixPart.startsWith("/");
|
|
74
|
+
|
|
75
|
+
return fs
|
|
76
|
+
.readdirSync(baseDir, { withFileTypes: true })
|
|
77
|
+
.filter((entry) => entry.isDirectory())
|
|
78
|
+
.filter((entry) => !suffixIsNamePattern || entry.name.endsWith(suffixPart))
|
|
79
|
+
.map((entry) => (suffixIsNamePattern
|
|
80
|
+
? path.join(baseDir, entry.name)
|
|
81
|
+
: path.join(baseDir, entry.name, suffixPart)))
|
|
82
|
+
.filter((packageDir) => fs.existsSync(path.join(packageDir, "package.json")));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function getWorkspacePackages(rootDir, workspaceFile, sectionName, fallbackSectionName, scriptName) {
|
|
86
|
+
const patterns = fallbackSectionName
|
|
87
|
+
? readWorkspaceSectionWithFallback(workspaceFile, sectionName, fallbackSectionName)
|
|
88
|
+
: readWorkspaceSection(workspaceFile, sectionName);
|
|
89
|
+
const included = new Set();
|
|
90
|
+
patterns.forEach((pattern) => {
|
|
91
|
+
const excluded = pattern.startsWith("!");
|
|
92
|
+
const resolvedPattern = excluded ? pattern.slice(1) : pattern;
|
|
93
|
+
expandWorkspacePattern(rootDir, resolvedPattern).forEach((packageDir) => {
|
|
94
|
+
const resolvedDir = path.resolve(packageDir);
|
|
95
|
+
if (excluded) included.delete(resolvedDir);
|
|
96
|
+
else included.add(resolvedDir);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
const packageDirs = [...included];
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
|
|
102
|
+
return packageDirs
|
|
103
|
+
.map((packageDir) => {
|
|
104
|
+
const packageJsonPath = path.join(packageDir, "package.json");
|
|
105
|
+
|
|
106
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const packageJson = readJson(packageJsonPath);
|
|
111
|
+
const scripts = packageJson.scripts || {};
|
|
112
|
+
|
|
113
|
+
if (!packageJson.name || seen.has(packageJson.name) || (scriptName && !scripts[scriptName])) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
seen.add(packageJson.name);
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
name: packageJson.name,
|
|
121
|
+
dir: path.relative(rootDir, packageDir),
|
|
122
|
+
packageJson,
|
|
123
|
+
};
|
|
124
|
+
})
|
|
125
|
+
.filter(Boolean);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function toTurboFilter(value) {
|
|
129
|
+
const normalized = value.replace(/\\/g, "/");
|
|
130
|
+
|
|
131
|
+
if (normalized.includes("/") && !normalized.startsWith("./") && !normalized.startsWith("../")) {
|
|
132
|
+
return `./${normalized}`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return normalized;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = {
|
|
139
|
+
expandWorkspacePattern,
|
|
140
|
+
getWorkspacePackages,
|
|
141
|
+
readJson,
|
|
142
|
+
readWorkspaceList,
|
|
143
|
+
readWorkspaceSection,
|
|
144
|
+
readWorkspaceSectionWithFallback,
|
|
145
|
+
toTurboFilter,
|
|
146
|
+
};
|