@intra-mart/accel 2.0.0 → 3.0.0-rc.202611260721
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 +10 -4
- package/assets/githooks/.githooks/pre-commit/pre-commit_en +71 -32
- package/assets/githooks/.githooks/pre-commit/pre-commit_ja +67 -33
- package/assets/githooks/.githooks/pre-commit/pre-commit_zh_CN +66 -32
- package/assets/runtime/ensure.mjs +27 -16
- package/dist/asset/deployer.d.ts +0 -2
- package/dist/asset/deployer.js +1 -6
- package/dist/asset/installer.d.ts +18 -2
- package/dist/asset/installer.js +94 -17
- package/dist/commands/attach-existing-files.d.ts +7 -0
- package/dist/commands/attach-existing-files.js +47 -1
- package/dist/commands/attach.d.ts +3 -1
- package/dist/commands/attach.js +21 -5
- package/dist/commands/deploy.d.ts +5 -1
- package/dist/commands/deploy.js +10 -3
- package/dist/commands/detach.d.ts +3 -1
- package/dist/commands/detach.js +16 -4
- package/dist/commands/init.d.ts +3 -1
- package/dist/commands/init.js +9 -4
- package/dist/commands/login.d.ts +8 -0
- package/dist/commands/login.js +13 -1
- package/dist/commands/mobile/attach.js +2 -3
- package/dist/commands/mobile/init.js +5 -2
- package/dist/commands/mobile/shared.d.ts +1 -1
- package/dist/commands/mobile/shared.js +5 -2
- package/dist/commands/switch.d.ts +2 -0
- package/dist/commands/switch.js +2 -2
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +1 -1
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/git/config-file.d.ts +10 -2
- package/dist/git/config-file.js +177 -94
- package/dist/git/config-scopes.d.ts +17 -0
- package/dist/git/config-scopes.js +33 -0
- package/dist/git/index-file.js +23 -4
- package/dist/git/read-capped.d.ts +1 -0
- package/dist/git/read-capped.js +6 -3
- package/dist/git/repo-discovery.d.ts +26 -0
- package/dist/git/repo-discovery.js +213 -0
- package/dist/git/untracked.d.ts +1 -0
- package/dist/git/untracked.js +23 -1
- package/dist/git/worktree-status.js +26 -21
- package/dist/i18n/en.js +72 -6
- package/dist/i18n/ja.js +72 -6
- package/dist/i18n/zh_CN.js +72 -6
- package/dist/interactive/credentials-prompts.d.ts +4 -1
- package/dist/interactive/credentials-prompts.js +2 -1
- package/dist/interactive/hook-confirm.d.ts +2 -0
- package/dist/interactive/hook-confirm.js +16 -0
- package/dist/lib.d.ts +1 -0
- package/dist/utils/command-exists.d.ts +5 -0
- package/dist/utils/command-exists.js +7 -6
- package/dist/utils/external-command.d.ts +0 -1
- package/dist/utils/external-command.js +1 -29
- package/dist/utils/githooks-remove.d.ts +27 -0
- package/dist/utils/githooks-remove.js +196 -0
- package/dist/utils/githooks-state.d.ts +80 -0
- package/dist/utils/githooks-state.js +364 -0
- package/dist/utils/githooks-sync.d.ts +11 -2
- package/dist/utils/githooks-sync.js +360 -68
- package/dist/utils/managed-marker.d.ts +1 -0
- package/dist/utils/managed-marker.js +1 -0
- package/dist/utils/mcp-generate.d.ts +5 -1
- package/dist/utils/mcp-generate.js +13 -4
- package/dist/utils/output-tail.d.ts +11 -0
- package/dist/utils/output-tail.js +29 -0
- package/dist/utils/runtime-ensure.js +10 -4
- package/package.json +1 -1
- package/dist/git/repo-layout.d.ts +0 -5
- package/dist/git/repo-layout.js +0 -44
package/dist/i18n/zh_CN.js
CHANGED
|
@@ -38,12 +38,72 @@ export const messages = {
|
|
|
38
38
|
"warning.fileExists": "文件已存在,跳过: {path}",
|
|
39
39
|
"warning.pathRejected.project": "部署路径指向项目之外,已排除该资材: {path}",
|
|
40
40
|
"warning.pathRejected.assetRepo": "来源路径指向资源仓库之外,已排除该资材: {path}",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
41
|
+
"gitHooks.placed": "已部署 pre-commit 钩子:{path}",
|
|
42
|
+
"gitHooks.integrationScriptKept": "已保留用于集成的 {path}。如果没有其他 pre-commit 钩子执行它,可以将其删除。",
|
|
43
|
+
"gitHooks.confirmParentRepo": "此项目位于 git 仓库({repositoryRoot})的子文件夹中。是否在 {path} 部署检查整个仓库所有提交的 pre-commit 钩子?",
|
|
44
|
+
"gitHooks.reason.foreignHook": "由于 {path} 已有不由 CLI 管理的 pre-commit 钩子,未部署 pre-commit 钩子。",
|
|
45
|
+
"gitHooks.reason.hooksPathSet": "由于 git 的 core.hooksPath 已设置为 \"{value}\",未部署 pre-commit 钩子。",
|
|
46
|
+
"gitHooks.reason.parentRepoDeclined": "未部署 pre-commit 钩子。下次保存连接信息时将再次确认。",
|
|
47
|
+
"gitHooks.reason.parentRepoNoConfirm": "由于项目位于 git 仓库({repositoryRoot})的子文件夹中,且未经确认,因此未部署 pre-commit 钩子。如需部署,请运行 accel login --allow-parent-repo-hook。",
|
|
48
|
+
"gitHooks.reason.unverified": "由于无法确认 {path} 的引用目标,未部署 pre-commit 钩子(如果移动过 worktree,可使用 git worktree repair 修复引用)。",
|
|
49
|
+
"gitHooks.reason.hooksDirUnsupported": "由于 {path} 不是普通目录,未部署 pre-commit 钩子。",
|
|
50
|
+
"gitHooks.reason.writeFailed": "无法在 {path} 部署 pre-commit 钩子:{message}",
|
|
51
|
+
"gitHooks.guidance.runScript": "如需启用 API 密钥检查,请从 pre-commit 钩子中执行 {script}(例如:bash {script} || exit 1)。",
|
|
52
|
+
"gitHooks.guidance.copyOrRun": "如需手动部署,请将 {source} 复制到 {hookPath} 并赋予执行权限。如果已有 pre-commit 钩子,请改为从该钩子中执行(例如:bash {script} || exit 1)。",
|
|
53
|
+
"gitHooks.guidance.noScript": "也无法部署用于集成的脚本({dir} 中存在不由 CLI 管理的文件,或不是普通目录)。",
|
|
54
|
+
"gitHooks.guidance.scriptWriteFailed": "也无法将用于集成的脚本写入 {path}:{message}",
|
|
55
|
+
"gitHooks.updateFailed": "无法将 {path} 更新为最新内容:{message}(仍保留之前的内容)",
|
|
56
|
+
"gitHooks.migrated": "已将旧方式的 pre-commit 钩子设置(core.hooksPath=.githooks)迁移到新方式。",
|
|
57
|
+
"gitHooks.migrated.removedDir": "- 已删除 .githooks/。请提交此删除。",
|
|
58
|
+
"gitHooks.migrated.reenabled": "- 此前被该设置停用的 .git/hooks/ 中的钩子已恢复执行:{hooks}",
|
|
59
|
+
"gitHooks.migrated.teamNotice": "- 在仍使用旧方式的其他环境中(例如其他人的 clone 或另一台电脑),拉取 .githooks/ 的删除后,在该环境中运行 accel login 之前不会执行 API 密钥检查(pre-commit 钩子)。",
|
|
60
|
+
"gitHooks.migrated.removeCall": "- 如果其他 pre-commit 钩子执行了 {path},请一并删除该调用。",
|
|
61
|
+
"gitHooks.migrated.checkDisabled": "- accel CLI 的 API 密钥检查(.githooks/pre-commit)因本次变更已不再执行。请按照随后显示的警告中的步骤启用。",
|
|
62
|
+
"gitHooks.migrationStopped": "已中止旧方式的 pre-commit 钩子设置(core.hooksPath=.githooks)的迁移:{message}。",
|
|
63
|
+
"gitHooks.migrationStopped.unprotected": "由于 core.hooksPath 仍指向 .githooks,目前不会执行 API 密钥检查。",
|
|
64
|
+
"gitHooks.hooksPathRemains": "尝试删除后,本地配置中仍保留 core.hooksPath",
|
|
65
|
+
"gitHooks.legacySettingRemoved": "已移除旧方式的 pre-commit 钩子设置(core.hooksPath=.githooks)。",
|
|
66
|
+
"gitHooks.migrationStopped.active": "旧方式的钩子仍在运行。",
|
|
67
|
+
"gitHooks.migrationStopped.retry": "下次保存连接信息时将再次迁移。",
|
|
68
|
+
"gitHooks.configNotEditable.symlink": "{path} 是符号链接,CLI 不会修改它(修改会改变链接目标文件)",
|
|
69
|
+
"gitHooks.configNotEditable.notRegularFile": "{path} 不是普通文件,CLI 不会修改它",
|
|
70
|
+
"gitHooks.configNotEditable.tooLarge": "{path} 过大(超过 1MB),CLI 不会修改它",
|
|
71
|
+
"gitHooks.configNotEditable.unreadable": "无法读取 {path},CLI 无法修改它",
|
|
72
|
+
"gitHooks.configNotEditable.invalidEncoding": "{path} 包含非 UTF-8 编码的字符(如用户名),CLI 不会修改它(修改会损坏这些字符)",
|
|
73
|
+
"gitHooks.configNotEditable.keyOnHeaderLine": "{path} 中有类似 [core] hooksPath = … 这样合并为一行的写法,CLI 无法修改",
|
|
74
|
+
"gitHooks.manualUnset.introPlaced": "运行以下命令,从本仓库的设置({config})中删除 core.hooksPath 后,git 将运行默认的 .git/hooks/ 中的钩子,已部署的 {hookPath} 将生效:",
|
|
75
|
+
"gitHooks.manualUnset.intro": "运行以下命令,从本仓库的设置({config})中删除 core.hooksPath 后,git 将运行默认的 .git/hooks/ 中的钩子:",
|
|
76
|
+
"gitHooks.manualUnset.introOtherHooksPath": "运行以下命令,从本仓库的设置({config})中删除 core.hooksPath 后,git 将运行全局设置(如 ~/.gitconfig)中 core.hooksPath 所指向的 \"{hooksPath}\" 中的钩子:",
|
|
77
|
+
"gitHooks.manualUnset.introWorktreeHooksPath": "运行以下命令,可从本仓库的设置({config})中删除 core.hooksPath。在此 worktree 中,删除后 git 仍会运行 worktree 专用设置(config.worktree)中 core.hooksPath 所指向的 \"{hooksPath}\" 中的钩子:",
|
|
78
|
+
"gitHooks.manualUnset.reenabled": "- 以下钩子将恢复执行:{hooks}",
|
|
79
|
+
"gitHooks.manualUnset.worktrees": "- 此命令会影响本仓库的所有 worktree。",
|
|
80
|
+
"gitHooks.manualUnset.thenLogin": "- 删除 core.hooksPath 后运行 accel login,它会部署 pre-commit 钩子,或显示无法部署的原因和处理方法。",
|
|
81
|
+
"gitHooks.manualUnset.undo": "- 此命令不会更改其他仓库和全局设置。如需还原,请运行:",
|
|
82
|
+
"gitHooks.manualUnset.noCommand": "请从本仓库的设置({config})中删除 core.hooksPath。由于仓库路径中包含对 shell 有特殊含义的字符,因此不显示命令。",
|
|
83
|
+
"gitHooks.manualUnset.symlinkPlaced": "从链接目标文件({target})中删除 core.hooksPath 后,已部署的 {hookPath} 将生效。如果链接目标文件与其他仓库共享,它们的设置也会改变。",
|
|
84
|
+
"gitHooks.manualUnset.symlink": "请从链接目标文件({target})中删除 core.hooksPath,然后运行 accel login。如果链接目标文件与其他仓库共享,它们的设置也会改变。",
|
|
85
|
+
"gitHooks.manualUnset.keepDir": "- 删除 core.hooksPath 后,.githooks/ 将不再被使用。CLI 不会删除 .githooks/;如果删除它,请提交此删除。",
|
|
86
|
+
"gitHooks.detach.legacyKeepDir": "- 已保留 .githooks/。删除 core.hooksPath 后,请将 .githooks/ 也一并删除。",
|
|
87
|
+
"gitHooks.detach.legacyManual": "请从本仓库的设置({config})中删除 core.hooksPath。",
|
|
88
|
+
"gitHooks.detach.legacySymlink": "请从链接目标文件({target})中删除 core.hooksPath。如果链接目标文件与其他仓库共享,它们的设置也会改变。",
|
|
89
|
+
"gitHooks.unexpectedError": "处理 pre-commit 钩子时发生错误:{message}",
|
|
90
|
+
"gitHooks.detach.legacyFailed": "无法移除旧方式的 pre-commit 钩子设置(core.hooksPath=.githooks):{message}。",
|
|
91
|
+
"gitHooks.detach.confirmList": "还将删除以下 pre-commit 钩子文件:",
|
|
92
|
+
"gitHooks.detach.confirmLegacy": "还将移除旧方式的 pre-commit 钩子设置(core.hooksPath=.githooks)。",
|
|
93
|
+
"gitHooks.detach.removed": "已删除 pre-commit 钩子:{path}",
|
|
94
|
+
"gitHooks.detach.integrationRemoved": "已删除用于集成的 pre-commit 脚本:{path}",
|
|
95
|
+
"gitHooks.detach.sharedNotice": "同一仓库中使用 accel 的其他项目,在下次运行 accel login 之前不会执行 API 密钥检查(pre-commit 钩子)。",
|
|
96
|
+
"gitHooks.detach.removeCall": "如果其他 pre-commit 钩子执行了 {path},请一并删除该调用。",
|
|
97
|
+
"gitHooks.detach.legacyRemoved": "已移除旧方式的 pre-commit 钩子设置(core.hooksPath=.githooks),并删除了 .githooks/。",
|
|
98
|
+
"gitHooks.detach.reenabled": "此前被该设置停用的 .git/hooks/ 中的钩子已恢复执行:{hooks}",
|
|
45
99
|
"warning.ensureScriptUserFile": "由于 {path} 不是由 CLI 管理的文件,已跳过 skill 依赖安装脚本的部署。如需启用自动安装,请删除或移走该文件后重新执行命令。",
|
|
46
100
|
"warning.ensureLaunchFailed": "无法启动 {command}。请确认运行环境(Node.js 或 Bun)后手动执行。",
|
|
101
|
+
"warning.installBuild.failed": "{command} 执行失败({status})。输出的末尾:\n{output}",
|
|
102
|
+
"warning.installBuild.failedNoOutput": "{command} 执行失败({status})。",
|
|
103
|
+
"warning.installBuild.exitCode": "退出代码 {code}",
|
|
104
|
+
"warning.installBuild.signal": "信号 {signal}",
|
|
105
|
+
"warning.installBuild.buildNotRun": "由于 install 失败,未执行 {command}。",
|
|
106
|
+
"warning.installBuild.commandNotFound": "由于未找到 {command},未执行 install / build。请安装 {command} 后,在项目中执行以下命令:\n {installCommand} && {buildCommand}",
|
|
47
107
|
"attach.skipSummary": "{count}个文件已存在,已跳过。",
|
|
48
108
|
"attach.overwritePrompt": "{path} 已存在。要覆盖吗?",
|
|
49
109
|
"attach.overwritePrompt.yes": "Yes (覆盖此文件)",
|
|
@@ -52,6 +112,11 @@ export const messages = {
|
|
|
52
112
|
"attach.overwritePrompt.skipAll": "Skip-all (跳过所有剩余文件)",
|
|
53
113
|
"attach.overwritten": "已覆盖: {path}",
|
|
54
114
|
"attach.overwriteSummary": "已覆盖 {count} 个文件。",
|
|
115
|
+
"attach.installStopped": "由于跳过了已有文件,未执行 install / build。请确认跳过的文件后,执行以下命令:\n {installCommand} && {buildCommand}",
|
|
116
|
+
"attach.lockfileHint": "package.json 与锁文件({lockfile})中只有一个被跳过,两者可能不一致。请确认 package.json 后,执行 {updateCommand}(而不是 {installCommand})来更新锁文件。",
|
|
117
|
+
"attach.pomCreated": "已新建 pom.xml。其中不包含现有项目的依赖(jar、对其他项目的引用、目录中没有的 intra-mart 模块)。请检查 pom.xml 中的依赖。",
|
|
118
|
+
"attach.pomOverwritten": "已用资源的内容覆盖 pom.xml。原 pom.xml 中的依赖未被保留。请与原内容对比,添加所需的依赖。",
|
|
119
|
+
"attach.updateHint": "已跳过 {count} 个已有文件。如需与资源的内容进行比较,请运行 accel update(与资源内容不同的文件会写入双方的内容,并以冲突标记分隔)。如果使用 git 等进行版本管理,请先提交 attach 的结果。",
|
|
55
120
|
"detach.confirm": "从此项目解除Accel CLI。确定吗?",
|
|
56
121
|
"detach.deleted": "已删除: {path}",
|
|
57
122
|
"detach.skipped": "已跳过: {path} (检测到修改)",
|
|
@@ -112,7 +177,7 @@ export const messages = {
|
|
|
112
177
|
"switch.upToDate": "没有变更。",
|
|
113
178
|
"switch.complete": "switch已完成。更新{updated}个、添加{added}个、删除{deleted}个文件。",
|
|
114
179
|
"switch.skippedSummary": "已跳过{count}个已编辑的文件。切换未应用于这些文件:",
|
|
115
|
-
"switch.installFailedHint": "
|
|
180
|
+
"switch.installFailedHint": "上述失败可能是因为以下跳过的已编辑文件与新配置不匹配:",
|
|
116
181
|
"cache.info.dir": "缓存目录: {path}",
|
|
117
182
|
"cache.info.overridden": "(已被环境变量 ACCEL_CACHE_DIR 覆盖)",
|
|
118
183
|
"cache.info.total": "总大小: {size}",
|
|
@@ -231,7 +296,7 @@ export const messages = {
|
|
|
231
296
|
"login.intro": "Accel CLI - login",
|
|
232
297
|
"login.complete": "连接信息已保存。",
|
|
233
298
|
"mcp.generated": "已生成或更新 MCP 配置: {path}",
|
|
234
|
-
"mcp.hint.loginRequired": "执行 accel login
|
|
299
|
+
"mcp.hint.loginRequired": "执行 accel login 后,将添加用于连接 iAP 的 MCP 服务器配置。",
|
|
235
300
|
"mcp.detach.removed": "已从 MCP 配置中移除 CLI 管理的条目: {path}({count} 项)",
|
|
236
301
|
"mcp.warning.unknownOutput": "输出路径不在生成范围内,已跳过 MCP 配置模板: {path}",
|
|
237
302
|
"mcp.warning.fragmentParse": "无法读取或解析 MCP 配置模板,已跳过: {path}",
|
|
@@ -341,6 +406,7 @@ export const messages = {
|
|
|
341
406
|
"progress.createExpo": "正在运行 create-expo...",
|
|
342
407
|
"progress.expoSkills": "正在安装 Expo 官方 skills...",
|
|
343
408
|
"error.externalRunnerNotFound": "未找到 {command}。请安装后重新运行。",
|
|
409
|
+
"error.createExpoNpmNotFound": "未找到 npm。无论通过 --package-manager 选择哪种包管理器,运行 create-expo 都需要 npm。请安装 npm(随 Node.js 附带)后重新运行。",
|
|
344
410
|
"hint.packageManagerOption": "也可以使用 --package-manager 指定其他包管理器(例如 --package-manager npm)。",
|
|
345
411
|
"error.createExpoFailed": "create-expo 运行失败:{command}\n如果已创建 {dir},请检查其内容,删除后重新运行。\n{output}",
|
|
346
412
|
"warning.createExpoInstallIncomplete": "依赖安装可能未完成。请在项目中运行 {command}。",
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { AccelCredentials } from "../core/types.js";
|
|
2
|
-
|
|
2
|
+
import type { ConfirmHookPlacement } from "../utils/githooks-sync.js";
|
|
3
|
+
export declare const ensureCredentials: (projectDir: string, locale: string, seed?: Partial<AccelCredentials>, opts?: {
|
|
4
|
+
confirmHookPlacement?: ConfirmHookPlacement;
|
|
5
|
+
}) => Promise<AccelCredentials>;
|
|
3
6
|
export declare const resolveCredentialsOrThrow: (projectDir: string, locale: string, seed: Partial<AccelCredentials>) => Promise<AccelCredentials>;
|
|
4
7
|
export declare const repromptCredentials: (current: AccelCredentials, locale: string, seed?: Partial<AccelCredentials>) => Promise<AccelCredentials>;
|
|
@@ -7,7 +7,7 @@ import { withHint } from "./format.js";
|
|
|
7
7
|
const requiredValidator = (locale) => (value) => !value || value.trim().length === 0
|
|
8
8
|
? getMessage("credentials.error.required", locale)
|
|
9
9
|
: undefined;
|
|
10
|
-
export const ensureCredentials = async (projectDir, locale, seed = {}) => {
|
|
10
|
+
export const ensureCredentials = async (projectDir, locale, seed = {}, opts = {}) => {
|
|
11
11
|
const existing = await readCredentials(projectDir);
|
|
12
12
|
let endpoint = seed.endpoint ?? existing.endpoint;
|
|
13
13
|
let apiKey = seed.apiKey ?? existing.apiKey;
|
|
@@ -40,6 +40,7 @@ export const ensureCredentials = async (projectDir, locale, seed = {}) => {
|
|
|
40
40
|
await persistCredentialsAndGenerateMcp(projectDir, creds, {
|
|
41
41
|
info: (msg) => p.log.info(msg),
|
|
42
42
|
warn: (msg) => p.log.warning(msg),
|
|
43
|
+
confirmHookPlacement: opts.confirmHookPlacement,
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
return creds;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as p from "@clack/prompts";
|
|
2
|
+
import { createCancelledError } from "../core/errors.js";
|
|
3
|
+
import { getMessage } from "../i18n/index.js";
|
|
4
|
+
import { sanitizeDisplayText } from "../utils/sanitize-text.js";
|
|
5
|
+
export const createClackHookConfirm = (locale) => async (target) => {
|
|
6
|
+
const res = await p.confirm({
|
|
7
|
+
message: getMessage("gitHooks.confirmParentRepo", locale, {
|
|
8
|
+
repositoryRoot: sanitizeDisplayText(target.repositoryRoot),
|
|
9
|
+
path: sanitizeDisplayText(target.hookPath),
|
|
10
|
+
}),
|
|
11
|
+
initialValue: true,
|
|
12
|
+
});
|
|
13
|
+
if (p.isCancel(res))
|
|
14
|
+
throw createCancelledError();
|
|
15
|
+
return res === true;
|
|
16
|
+
};
|
package/dist/lib.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export { validateNonInteractive, validateCliValues, validateCatalogValues, colle
|
|
|
25
25
|
export { resolveJugglingProject, type JugglingResolved, } from "./juggling/resolve.js";
|
|
26
26
|
export { readCredentials, normalizeEndpoint, resolveCredentialInputs, } from "./utils/credentials.js";
|
|
27
27
|
export { persistCredentialsAndGenerateMcp } from "./utils/mcp-generate.js";
|
|
28
|
+
export type { ConfirmHookPlacement, HookPlacementTarget, } from "./utils/githooks-sync.js";
|
|
28
29
|
export { createApiClient, type ApiClient } from "./deploy/api-client.js";
|
|
29
30
|
export { verifyCredentialsLoop, type VerifyDeps } from "./interactive/credential-auth.js";
|
|
30
31
|
export { getReleases, findReleaseById, findReleaseBySemver, resolveAccelplatformVersion, resolveLabel, findModuleByCatalogId, toModuleContextItems, toFeatureContextItems, type Release, type ModuleEntry, type FunctionEntry, type Labels, } from "./core/catalog.js";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
|
-
export const
|
|
2
|
+
export const probeCommand = (cmd, opts = {}) => {
|
|
3
|
+
const whichCmd = process.platform === "win32" ? "where" : "which";
|
|
3
4
|
try {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return true;
|
|
5
|
+
execSync(`${whichCmd} ${cmd}`, { stdio: "pipe", env: opts.env, cwd: opts.cwd });
|
|
6
|
+
return "found";
|
|
7
7
|
}
|
|
8
|
-
catch {
|
|
9
|
-
return
|
|
8
|
+
catch (err) {
|
|
9
|
+
return err.status === 1 ? "missing" : "unknown";
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
+
export const commandExists = (cmd) => probeCommand(cmd) === "found";
|
|
@@ -46,7 +46,6 @@ export type ExternalCommandRunnerOptions = {
|
|
|
46
46
|
};
|
|
47
47
|
export declare const createExternalCommandRunner: (options?: ExternalCommandRunnerOptions) => RunExternalCommand;
|
|
48
48
|
export declare const runExternalCommand: RunExternalCommand;
|
|
49
|
-
export declare const formatOutputTail: (outputTail: readonly string[]) => string;
|
|
50
49
|
export declare const formatCommandLine: (req: Pick<ExternalCommandRequest, "command" | "args">) => string;
|
|
51
50
|
export declare const buildCreateExpoRequest: (opts: {
|
|
52
51
|
createExpo: MobileMeta["createExpo"];
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { execFileSync, spawn } from "node:child_process";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { commandExists as defaultCommandExists } from "./command-exists.js";
|
|
4
|
-
import {
|
|
4
|
+
import { createLineTail, OUTPUT_TAIL_LINES } from "./output-tail.js";
|
|
5
5
|
import { packageRunnerFor } from "../core/constants.js";
|
|
6
|
-
const OUTPUT_TAIL_LINES = 200;
|
|
7
|
-
const MAX_LINE_LENGTH = 4096;
|
|
8
6
|
const WITHHELD_ENV_KEYS = ["ACCEL_API_KEY", "ACCEL_ENDPOINT"];
|
|
9
7
|
export const buildChildEnv = (base, extra) => {
|
|
10
8
|
const env = { ...base };
|
|
@@ -14,7 +12,6 @@ export const buildChildEnv = (base, extra) => {
|
|
|
14
12
|
}
|
|
15
13
|
return { ...env, NoDefaultCurrentDirectoryInExePath: "1", ...extra };
|
|
16
14
|
};
|
|
17
|
-
const FAILURE_TAIL_LINES = 20;
|
|
18
15
|
const SAFE_TOKEN_PATTERN = /^[A-Za-z0-9@._~/:=-]+$/;
|
|
19
16
|
export const buildSpawnSpec = (req, platform) => {
|
|
20
17
|
if (platform !== "win32") {
|
|
@@ -27,30 +24,6 @@ export const buildSpawnSpec = (req, platform) => {
|
|
|
27
24
|
}
|
|
28
25
|
return { file: tokens.join(" "), args: [], shell: true };
|
|
29
26
|
};
|
|
30
|
-
const createLineTail = (limit) => {
|
|
31
|
-
const lines = [];
|
|
32
|
-
const push = (line) => {
|
|
33
|
-
lines.push(line);
|
|
34
|
-
if (lines.length > limit)
|
|
35
|
-
lines.shift();
|
|
36
|
-
};
|
|
37
|
-
const createSink = () => {
|
|
38
|
-
let partial = "";
|
|
39
|
-
return {
|
|
40
|
-
write: (chunk) => {
|
|
41
|
-
const parts = (partial + chunk).split(/\r\n|\n/);
|
|
42
|
-
partial = (parts.pop() ?? "").slice(-MAX_LINE_LENGTH);
|
|
43
|
-
parts.forEach((line) => push(line.slice(-MAX_LINE_LENGTH)));
|
|
44
|
-
},
|
|
45
|
-
flush: () => {
|
|
46
|
-
if (partial !== "")
|
|
47
|
-
push(partial);
|
|
48
|
-
partial = "";
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
return { createSink, lines: () => [...lines] };
|
|
53
|
-
};
|
|
54
27
|
const INTERRUPT_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
55
28
|
const TASKKILL_TIMEOUT_MS = 5000;
|
|
56
29
|
const WINDOWS_ROOT_PATTERN = /^[A-Za-z]:\\/;
|
|
@@ -172,7 +145,6 @@ export const createExternalCommandRunner = (options = {}) => async (req) => {
|
|
|
172
145
|
});
|
|
173
146
|
};
|
|
174
147
|
export const runExternalCommand = createExternalCommandRunner();
|
|
175
|
-
export const formatOutputTail = (outputTail) => sanitizeDisplayBlock(outputTail.slice(-FAILURE_TAIL_LINES).join("\n"));
|
|
176
148
|
export const formatCommandLine = (req) => [req.command, ...req.args].join(" ");
|
|
177
149
|
const runnerEnv = (packageManager) => {
|
|
178
150
|
const { userAgent } = packageRunnerFor(packageManager);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RemainingHooksPath } from "./githooks-state.js";
|
|
2
|
+
export type CliPlacedHooks = {
|
|
3
|
+
hookFiles: string[];
|
|
4
|
+
sharedHook?: string;
|
|
5
|
+
activeLegacyScript?: string;
|
|
6
|
+
integrationScripts: string[];
|
|
7
|
+
integrationAttributes?: string;
|
|
8
|
+
legacy?: {
|
|
9
|
+
configPath: string;
|
|
10
|
+
dir: string;
|
|
11
|
+
files: string[];
|
|
12
|
+
hooksDir: string;
|
|
13
|
+
remaining: RemainingHooksPath;
|
|
14
|
+
};
|
|
15
|
+
shared: boolean;
|
|
16
|
+
worktreesExist: boolean;
|
|
17
|
+
displayRoot: string;
|
|
18
|
+
error?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const findCliPlacedHooks: (projectDirInput: string) => Promise<CliPlacedHooks>;
|
|
21
|
+
export type RemoveHooksSink = {
|
|
22
|
+
success: (msg: string) => void;
|
|
23
|
+
info: (msg: string) => void;
|
|
24
|
+
warn: (msg: string) => void;
|
|
25
|
+
};
|
|
26
|
+
export declare const removeCliPlacedHooks: (found: CliPlacedHooks, sink: RemoveHooksSink, locale: string) => Promise<void>;
|
|
27
|
+
export declare const removeCliPlacedHooksBestEffort: (found: CliPlacedHooks, logger: RemoveHooksSink, locale: string, impl?: typeof removeCliPlacedHooks) => Promise<void>;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { readdir, realpath } from "node:fs/promises";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { discoverRepository } from "../git/repo-discovery.js";
|
|
4
|
+
import { getMessage } from "../i18n/index.js";
|
|
5
|
+
import { classifyDir, classifyFile, classifyLegacy, containsOnlyManagedFiles, displayRelative, hasLinkedWorktrees, hasRemainingHooksPath, integrationPaths, listActiveHooks, manualUnsetGuidance, readHooksPathDefinitions, remainingHooksPaths, removeDirIfEmpty, removeIfManaged, removeManagedFiles, toUnsetFailure, unsetFailureText, unsetLocalHooksPath, } from "./githooks-state.js";
|
|
6
|
+
import { sanitizeDisplayText } from "./sanitize-text.js";
|
|
7
|
+
const errorMessage = (err) => err instanceof Error ? err.message : String(err);
|
|
8
|
+
const emptyHooks = (projectDir) => ({
|
|
9
|
+
hookFiles: [],
|
|
10
|
+
integrationScripts: [],
|
|
11
|
+
shared: false,
|
|
12
|
+
worktreesExist: false,
|
|
13
|
+
displayRoot: projectDir,
|
|
14
|
+
});
|
|
15
|
+
export const findCliPlacedHooks = async (projectDirInput) => {
|
|
16
|
+
const env = process.env;
|
|
17
|
+
const projectDir = await realpath(projectDirInput).catch(() => resolve(projectDirInput));
|
|
18
|
+
const found = emptyHooks(projectDir);
|
|
19
|
+
try {
|
|
20
|
+
const discovery = await discoverRepository(projectDir, { env });
|
|
21
|
+
const integration = integrationPaths(projectDir);
|
|
22
|
+
if (discovery.kind === "found") {
|
|
23
|
+
const layout = discovery.layout;
|
|
24
|
+
found.displayRoot = layout.worktreeRoot;
|
|
25
|
+
const hooksDir = join(layout.commonDir, "hooks");
|
|
26
|
+
if ((await classifyDir(hooksDir)) === "directory") {
|
|
27
|
+
const hookPath = join(hooksDir, "pre-commit");
|
|
28
|
+
if ((await classifyFile(hookPath)) === "managed") {
|
|
29
|
+
found.sharedHook = hookPath;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
found.worktreesExist =
|
|
33
|
+
layout.linkedWorktree || (await hasLinkedWorktrees(layout.commonDir));
|
|
34
|
+
found.shared = found.worktreesExist || layout.projectRel !== "";
|
|
35
|
+
const definitions = await readHooksPathDefinitions(layout, env);
|
|
36
|
+
const legacy = await classifyLegacy(layout, definitions);
|
|
37
|
+
if (legacy.kind === "migratable") {
|
|
38
|
+
const names = (await classifyDir(legacy.dir)) === "directory"
|
|
39
|
+
? await readdir(legacy.dir).catch(() => [])
|
|
40
|
+
: [];
|
|
41
|
+
found.legacy = {
|
|
42
|
+
configPath: join(layout.commonDir, "config"),
|
|
43
|
+
dir: legacy.dir,
|
|
44
|
+
files: names.map((name) => join(legacy.dir, name)),
|
|
45
|
+
hooksDir,
|
|
46
|
+
remaining: remainingHooksPaths(definitions),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
else if (legacy.kind === "protected" && layout.projectRel === "") {
|
|
50
|
+
found.activeLegacyScript = legacy.scriptPath;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (discovery.kind === "unverified") {
|
|
54
|
+
found.displayRoot = discovery.worktreeRoot;
|
|
55
|
+
}
|
|
56
|
+
if (found.legacy === undefined &&
|
|
57
|
+
(await classifyDir(integration.dir)) === "directory") {
|
|
58
|
+
for (const path of [integration.primary, integration.alt]) {
|
|
59
|
+
if (path === found.activeLegacyScript)
|
|
60
|
+
continue;
|
|
61
|
+
if ((await classifyFile(path)) === "managed") {
|
|
62
|
+
found.integrationScripts.push(path);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if ((await classifyFile(integration.attributes)) === "managed" &&
|
|
66
|
+
(await containsOnlyManagedFiles(integration.dir))) {
|
|
67
|
+
found.integrationAttributes = integration.attributes;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
found.hookFiles = [
|
|
71
|
+
...(found.sharedHook !== undefined ? [found.sharedHook] : []),
|
|
72
|
+
...(found.activeLegacyScript !== undefined
|
|
73
|
+
? [found.activeLegacyScript]
|
|
74
|
+
: []),
|
|
75
|
+
...found.integrationScripts,
|
|
76
|
+
...(found.integrationAttributes !== undefined
|
|
77
|
+
? [found.integrationAttributes]
|
|
78
|
+
: []),
|
|
79
|
+
...(found.legacy?.files ?? []),
|
|
80
|
+
];
|
|
81
|
+
return found;
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
return { ...emptyHooks(projectDir), error: errorMessage(err) };
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export const removeCliPlacedHooks = async (found, sink, locale) => {
|
|
88
|
+
const message = (key, params) => getMessage(key, locale, params);
|
|
89
|
+
const shown = (path) => sanitizeDisplayText(path);
|
|
90
|
+
const failed = (err) => {
|
|
91
|
+
sink.warn(message("gitHooks.unexpectedError", { message: shown(errorMessage(err)) }));
|
|
92
|
+
};
|
|
93
|
+
const remove = async (path) => {
|
|
94
|
+
try {
|
|
95
|
+
return await removeIfManaged(path);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
failed(err);
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
let sharedNoticeShown = false;
|
|
103
|
+
const showSharedNotice = () => {
|
|
104
|
+
if (sharedNoticeShown)
|
|
105
|
+
return;
|
|
106
|
+
sharedNoticeShown = true;
|
|
107
|
+
sink.info(message("gitHooks.detach.sharedNotice"));
|
|
108
|
+
};
|
|
109
|
+
if (found.sharedHook !== undefined && (await remove(found.sharedHook))) {
|
|
110
|
+
sink.success(message("gitHooks.detach.removed", { path: shown(found.sharedHook) }));
|
|
111
|
+
if (found.shared)
|
|
112
|
+
showSharedNotice();
|
|
113
|
+
}
|
|
114
|
+
if (found.activeLegacyScript !== undefined &&
|
|
115
|
+
(await remove(found.activeLegacyScript))) {
|
|
116
|
+
sink.success(message("gitHooks.detach.removed", { path: shown(found.activeLegacyScript) }));
|
|
117
|
+
}
|
|
118
|
+
for (const script of found.integrationScripts) {
|
|
119
|
+
if (!(await remove(script)))
|
|
120
|
+
continue;
|
|
121
|
+
sink.success(message("gitHooks.detach.integrationRemoved", { path: shown(script) }));
|
|
122
|
+
sink.info(message("gitHooks.detach.removeCall", {
|
|
123
|
+
path: shown(displayRelative(found.displayRoot, script)),
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
if (found.integrationAttributes !== undefined) {
|
|
127
|
+
await remove(found.integrationAttributes);
|
|
128
|
+
}
|
|
129
|
+
if (found.legacy !== undefined) {
|
|
130
|
+
const legacy = found.legacy;
|
|
131
|
+
const reenabled = hasRemainingHooksPath(legacy.remaining)
|
|
132
|
+
? []
|
|
133
|
+
: await listActiveHooks(legacy.hooksDir);
|
|
134
|
+
const legacyFailed = async (failure) => {
|
|
135
|
+
const guidance = await manualUnsetGuidance({
|
|
136
|
+
mode: "detach",
|
|
137
|
+
locale,
|
|
138
|
+
failure,
|
|
139
|
+
repoRoot: found.displayRoot,
|
|
140
|
+
configPath: legacy.configPath,
|
|
141
|
+
legacyDirHasFiles: legacy.files.length > 0,
|
|
142
|
+
remaining: legacy.remaining,
|
|
143
|
+
reenabled,
|
|
144
|
+
worktreesExist: found.worktreesExist,
|
|
145
|
+
});
|
|
146
|
+
sink.warn([
|
|
147
|
+
message("gitHooks.detach.legacyFailed", {
|
|
148
|
+
message: unsetFailureText(failure, locale, found.displayRoot),
|
|
149
|
+
}),
|
|
150
|
+
...(guidance === "retry" ? [] : guidance),
|
|
151
|
+
].join("\n"));
|
|
152
|
+
};
|
|
153
|
+
let unset;
|
|
154
|
+
try {
|
|
155
|
+
unset = await unsetLocalHooksPath(legacy.configPath);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
await legacyFailed(toUnsetFailure(err));
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (!unset) {
|
|
162
|
+
await legacyFailed({ kind: "remains" });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
await removeManagedFiles(legacy.files, failed);
|
|
166
|
+
const removedDir = await removeDirIfEmpty(legacy.dir);
|
|
167
|
+
sink.success(message(removedDir ? "gitHooks.detach.legacyRemoved" : "gitHooks.legacySettingRemoved"));
|
|
168
|
+
if (reenabled.length > 0) {
|
|
169
|
+
sink.info(message("gitHooks.detach.reenabled", { hooks: reenabled.join(", ") }));
|
|
170
|
+
}
|
|
171
|
+
if (found.worktreesExist)
|
|
172
|
+
showSharedNotice();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const integrationFile = found.integrationScripts[0] ?? found.integrationAttributes;
|
|
176
|
+
if (integrationFile !== undefined) {
|
|
177
|
+
await removeDirIfEmpty(dirname(integrationFile));
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
export const removeCliPlacedHooksBestEffort = async (found, logger, locale, impl = removeCliPlacedHooks) => {
|
|
181
|
+
if (found.error !== undefined) {
|
|
182
|
+
logger.warn(getMessage("gitHooks.unexpectedError", locale, {
|
|
183
|
+
message: sanitizeDisplayText(found.error),
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
if (found.hookFiles.length === 0 && found.legacy === undefined)
|
|
187
|
+
return;
|
|
188
|
+
try {
|
|
189
|
+
await impl(found, logger, locale);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
logger.warn(getMessage("gitHooks.unexpectedError", locale, {
|
|
193
|
+
message: sanitizeDisplayText(errorMessage(err)),
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type ConfigNotEditableReason } from "../git/config-file.js";
|
|
2
|
+
import { type ScopedConfigValue } from "../git/config-scopes.js";
|
|
3
|
+
import { type RepoLayout } from "../git/repo-discovery.js";
|
|
4
|
+
export declare const INTEGRATION_DIR = ".githooks";
|
|
5
|
+
export declare const INTEGRATION_SCRIPT = "pre-commit";
|
|
6
|
+
export declare const INTEGRATION_SCRIPT_ALT = "accel-pre-commit";
|
|
7
|
+
export declare const INTEGRATION_ATTRIBUTES = ".gitattributes";
|
|
8
|
+
export declare const integrationPaths: (projectDir: string) => {
|
|
9
|
+
dir: string;
|
|
10
|
+
primary: string;
|
|
11
|
+
alt: string;
|
|
12
|
+
attributes: string;
|
|
13
|
+
};
|
|
14
|
+
export type FileState = "absent" | "managed" | "foreign";
|
|
15
|
+
export declare const classifyFile: (path: string) => Promise<FileState>;
|
|
16
|
+
export type DirState = "absent" | "directory" | "other";
|
|
17
|
+
export declare const classifyDir: (path: string) => Promise<DirState>;
|
|
18
|
+
export type HookAssets = {
|
|
19
|
+
script: string;
|
|
20
|
+
gitattributes: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const loadHookAssets: (locale: string) => Promise<HookAssets>;
|
|
23
|
+
export declare const writeFileAtomic: (path: string, content: string, mode?: number) => Promise<boolean>;
|
|
24
|
+
export declare const removeIfManaged: (path: string) => Promise<boolean>;
|
|
25
|
+
export declare const removeManagedFiles: (paths: readonly string[], onError: (err: unknown) => void) => Promise<void>;
|
|
26
|
+
export declare const removeDirIfEmpty: (dir: string) => Promise<boolean>;
|
|
27
|
+
export declare const unsetLocalHooksPath: (configPath: string) => Promise<boolean>;
|
|
28
|
+
export type UnsetFailure = {
|
|
29
|
+
kind: "notEditable";
|
|
30
|
+
reason: ConfigNotEditableReason;
|
|
31
|
+
configPath: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "remains";
|
|
34
|
+
} | {
|
|
35
|
+
kind: "other";
|
|
36
|
+
message: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const toUnsetFailure: (err: unknown) => UnsetFailure;
|
|
39
|
+
export declare const unsetFailureText: (failure: UnsetFailure, locale: string, displayRoot: string) => string;
|
|
40
|
+
export declare const isShellSafePath: (path: string) => boolean;
|
|
41
|
+
export type RemainingHooksPath = {
|
|
42
|
+
user?: string;
|
|
43
|
+
worktree?: string;
|
|
44
|
+
};
|
|
45
|
+
export declare const remainingHooksPaths: (definitions: readonly ScopedConfigValue[]) => RemainingHooksPath;
|
|
46
|
+
export declare const hasRemainingHooksPath: (remaining: RemainingHooksPath) => boolean;
|
|
47
|
+
export type ManualUnsetGuidanceOptions = {
|
|
48
|
+
mode: "migration" | "detach";
|
|
49
|
+
locale: string;
|
|
50
|
+
failure: UnsetFailure;
|
|
51
|
+
repoRoot: string;
|
|
52
|
+
configPath: string;
|
|
53
|
+
placedHookPath?: string;
|
|
54
|
+
legacyCheckActive?: boolean;
|
|
55
|
+
legacyDirHasFiles: boolean;
|
|
56
|
+
legacyScriptExists?: boolean;
|
|
57
|
+
remaining: RemainingHooksPath;
|
|
58
|
+
reenabled: string[];
|
|
59
|
+
worktreesExist: boolean;
|
|
60
|
+
};
|
|
61
|
+
export declare const manualUnsetGuidance: (opts: ManualUnsetGuidanceOptions) => Promise<string[] | "retry">;
|
|
62
|
+
export declare const readHooksPathDefinitions: (layout: RepoLayout, env: NodeJS.ProcessEnv) => Promise<ScopedConfigValue[]>;
|
|
63
|
+
export declare const resolveHooksPathDir: (value: string, worktreeRoot: string, env: NodeJS.ProcessEnv) => string;
|
|
64
|
+
export declare const displayRelative: (base: string, path: string) => string;
|
|
65
|
+
export declare const hasLinkedWorktrees: (commonDir: string) => Promise<boolean>;
|
|
66
|
+
export declare const containsOnlyManagedFiles: (dir: string) => Promise<boolean>;
|
|
67
|
+
export type LegacyState = {
|
|
68
|
+
kind: "none";
|
|
69
|
+
} | {
|
|
70
|
+
kind: "migratable";
|
|
71
|
+
dir: string;
|
|
72
|
+
} | {
|
|
73
|
+
kind: "protected";
|
|
74
|
+
scriptPath: string;
|
|
75
|
+
} | {
|
|
76
|
+
kind: "set";
|
|
77
|
+
};
|
|
78
|
+
export declare const classifyLegacy: (layout: RepoLayout, definitions: ScopedConfigValue[]) => Promise<LegacyState>;
|
|
79
|
+
export declare const isRunnableManagedHook: (path: string) => Promise<boolean>;
|
|
80
|
+
export declare const listActiveHooks: (hooksDir: string) => Promise<string[]>;
|