@intra-mart/accel 3.0.0-dev.202611201537 → 3.0.0-rc.202611261408
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 +1 -1
- package/assets/githooks/.githooks/pre-commit/pre-commit_en +1 -1
- package/assets/githooks/.githooks/pre-commit/pre-commit_ja +1 -1
- package/assets/githooks/.githooks/pre-commit/pre-commit_zh_CN +4 -4
- package/assets/runtime/ensure.mjs +83 -33
- package/dist/asset/deployer.d.ts +7 -0
- package/dist/asset/deployer.js +32 -16
- package/dist/asset/updater.d.ts +15 -1
- package/dist/asset/updater.js +71 -2
- package/dist/commands/attach-existing-files.d.ts +3 -2
- package/dist/commands/attach-existing-files.js +18 -1
- package/dist/commands/attach.d.ts +1 -1
- package/dist/commands/attach.js +10 -6
- package/dist/commands/detach.d.ts +2 -0
- package/dist/commands/detach.js +27 -3
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.js +6 -4
- package/dist/commands/mobile/attach.js +5 -4
- package/dist/commands/mobile/init.js +5 -3
- package/dist/commands/mobile/shared.js +1 -1
- package/dist/commands/preset.js +3 -3
- package/dist/commands/switch.js +17 -9
- package/dist/commands/update.js +27 -10
- package/dist/core/constants.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/i18n/en.js +25 -1
- package/dist/i18n/ja.js +34 -10
- package/dist/i18n/zh_CN.js +129 -105
- package/dist/interactive/credential-auth.js +10 -1
- package/dist/interactive/credentials-prompts.js +14 -6
- package/dist/lib.d.ts +1 -1
- package/dist/utils/credentials.d.ts +3 -1
- package/dist/utils/credentials.js +14 -4
- package/dist/utils/gitignore.d.ts +5 -2
- package/dist/utils/gitignore.js +11 -3
- package/dist/utils/managed-hooks.d.ts +43 -0
- package/dist/utils/managed-hooks.js +140 -0
- package/dist/utils/mcp-generate.d.ts +2 -1
- package/dist/utils/mcp-generate.js +29 -6
- package/dist/utils/path-guard.d.ts +37 -0
- package/dist/utils/path-guard.js +113 -0
- package/dist/utils/preset-io.d.ts +2 -2
- package/dist/utils/preset-io.js +9 -3
- package/dist/utils/runtime-ensure.d.ts +1 -9
- package/dist/utils/runtime-ensure.js +61 -130
- package/dist/utils/settings-io.d.ts +1 -0
- package/dist/utils/settings-io.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ accel init my-project
|
|
|
86
86
|
| `--no-git-init` | git initをスキップ | `false` |
|
|
87
87
|
| `--skip-install` | 依存インストールをスキップ | `false` |
|
|
88
88
|
| `--asset-server-url` | 資材を取得するgitリポジトリのURL(HTTP(S) のみ) | `https://github.com/accelplatform/skills` |
|
|
89
|
-
| `--asset-ref` | 資材リポジトリから取得するブランチ/タグ | `
|
|
89
|
+
| `--asset-ref` | 資材リポジトリから取得するブランチ/タグ | `experiment` |
|
|
90
90
|
|
|
91
91
|
### `accel attach`
|
|
92
92
|
|
|
@@ -300,7 +300,7 @@ if [ "$found" -eq 1 ]; then
|
|
|
300
300
|
hook_path=$0
|
|
301
301
|
case $hook_path in /*|[A-Za-z]:[\\/]*) ;; *) hook_path=$PWD/${hook_path#./} ;; esac
|
|
302
302
|
sanitize_display "$hook_path"
|
|
303
|
-
echo "This check comes from the pre-commit hook placed by accel CLI ($display_text)."
|
|
303
|
+
echo "This check comes from the pre-commit hook placed by accel CLI (${display_text})."
|
|
304
304
|
exit 1
|
|
305
305
|
fi
|
|
306
306
|
|
|
@@ -282,7 +282,7 @@ if [ "$found" -eq 1 ]; then
|
|
|
282
282
|
hook_path=$0
|
|
283
283
|
case $hook_path in /*|[A-Za-z]:[\\/]*) ;; *) hook_path=$PWD/${hook_path#./} ;; esac
|
|
284
284
|
sanitize_display "$hook_path"
|
|
285
|
-
echo "このチェックは accel CLI が配置した pre-commit フック($display_text)によるものです。"
|
|
285
|
+
echo "このチェックは accel CLI が配置した pre-commit フック(${display_text})によるものです。"
|
|
286
286
|
exit 1
|
|
287
287
|
fi
|
|
288
288
|
|
|
@@ -217,7 +217,7 @@ check_base64_tokens() {
|
|
|
217
217
|
|
|
218
218
|
if (( is_match == 0 )); then
|
|
219
219
|
sanitize_display "$file"
|
|
220
|
-
findings+=("[$display_text:$lineno] 检测到 intra-mart OAuth
|
|
220
|
+
findings+=("[$display_text:$lineno] 检测到 intra-mart OAuth 客户端密钥字符串:${token:0:12}...")
|
|
221
221
|
found=1
|
|
222
222
|
fi
|
|
223
223
|
done
|
|
@@ -237,13 +237,13 @@ in_hunk=0
|
|
|
237
237
|
while IFS= read -r line; do
|
|
238
238
|
case "$line" in
|
|
239
239
|
"diff --git "*)
|
|
240
|
-
#
|
|
240
|
+
# 例如:diff --git a/path/to/file b/path/to/file
|
|
241
241
|
current_file="${line#diff --git a/}"
|
|
242
242
|
current_file="${current_file%% b/*}"
|
|
243
243
|
in_hunk=0
|
|
244
244
|
;;
|
|
245
245
|
"@@ "*)
|
|
246
|
-
#
|
|
246
|
+
# 例如:@@ -12,0 +13,2 @@ ... → 获取新文件一侧的起始行号(13)
|
|
247
247
|
if [[ "$line" =~ \+([0-9]+) ]]; then
|
|
248
248
|
current_line="${BASH_REMATCH[1]}"
|
|
249
249
|
fi
|
|
@@ -282,7 +282,7 @@ if [ "$found" -eq 1 ]; then
|
|
|
282
282
|
hook_path=$0
|
|
283
283
|
case $hook_path in /*|[A-Za-z]:[\\/]*) ;; *) hook_path=$PWD/${hook_path#./} ;; esac
|
|
284
284
|
sanitize_display "$hook_path"
|
|
285
|
-
echo "此检查来自 accel CLI 部署的 pre-commit 钩子($display_text)。"
|
|
285
|
+
echo "此检查来自 accel CLI 部署的 pre-commit 钩子(${display_text})。"
|
|
286
286
|
exit 1
|
|
287
287
|
fi
|
|
288
288
|
|
|
@@ -117,7 +117,10 @@ export const MESSAGES = {
|
|
|
117
117
|
"対処: {path} を削除してから再実行してください。",
|
|
118
118
|
"cause.unsafePath": "原因: 依存ディレクトリ {dir} がプロジェクトの外を指しています。",
|
|
119
119
|
"remedy.unsafePath":
|
|
120
|
-
"対処: {
|
|
120
|
+
"対処: {link} を通常のディレクトリに置き換えてから、accel update を実行してください。",
|
|
121
|
+
"remedy.unsafePathNoUpdate": "対処: {link} を通常のディレクトリに置き換えてください。",
|
|
122
|
+
"cause.linkedPath":
|
|
123
|
+
"原因: {link} がシンボリックリンクのため、依存ディレクトリ {dir} に資材が配備されていません。",
|
|
121
124
|
"cause.lockTimeout": "原因: 別のプロセスが {dir} の依存を準備中のまま、待ち時間内に完了しませんでした。",
|
|
122
125
|
"remedy.lockTimeout":
|
|
123
126
|
"対処: しばらく待ってから再実行してください。止まったままなら .accel/runtime/{id}.lock を削除してから再実行してください。",
|
|
@@ -153,7 +156,10 @@ export const MESSAGES = {
|
|
|
153
156
|
"cause.unsafeLayout": "Cause: {path} is a symbolic link (not a directory created by the CLI).",
|
|
154
157
|
"remedy.unsafeLayout": "Remedy: delete {path}, then rerun.",
|
|
155
158
|
"cause.unsafePath": "Cause: the dependency directory {dir} points outside the project.",
|
|
156
|
-
"remedy.unsafePath": "Remedy:
|
|
159
|
+
"remedy.unsafePath": "Remedy: replace {link} with a regular directory, then run accel update.",
|
|
160
|
+
"remedy.unsafePathNoUpdate": "Remedy: replace {link} with a regular directory.",
|
|
161
|
+
"cause.linkedPath":
|
|
162
|
+
"Cause: {link} is a symbolic link, so the assets were not deployed to the dependency directory {dir}.",
|
|
157
163
|
"cause.lockTimeout": "Cause: another process is still preparing the dependencies in {dir} and did not finish within the wait time.",
|
|
158
164
|
"remedy.lockTimeout":
|
|
159
165
|
"Remedy: wait a moment and rerun. If it stays stuck, delete .accel/runtime/{id}.lock, then rerun.",
|
|
@@ -165,38 +171,40 @@ export const MESSAGES = {
|
|
|
165
171
|
rerun: "Rerun command: {command}",
|
|
166
172
|
},
|
|
167
173
|
zh_CN: {
|
|
168
|
-
installed: "已安装 skill
|
|
174
|
+
installed: "已安装 skill 依赖:{dir}(id:{id})",
|
|
169
175
|
summary: "skill 依赖准备失败({count} 项)。",
|
|
170
176
|
"cause.conflict":
|
|
171
|
-
"
|
|
172
|
-
"remedy.conflict": "
|
|
173
|
-
"cause.lockMissing": "
|
|
174
|
-
"remedy.lockMissing": "
|
|
175
|
-
"cause.packageJsonMissing": "
|
|
177
|
+
"原因:{dir} 的 package.json / 锁文件中仍残留未解决的冲突标记(update 的冲突尚未解决)。",
|
|
178
|
+
"remedy.conflict": "处理:解决 {dir} 的冲突后,重新执行。",
|
|
179
|
+
"cause.lockMissing": "原因:{dir} 中没有 {pm} 对应的锁文件({file})。",
|
|
180
|
+
"remedy.lockMissing": "处理:资源仓库可能不完整。请联系资源的维护者。",
|
|
181
|
+
"cause.packageJsonMissing": "原因:{dir} 中没有 package.json。",
|
|
176
182
|
"remedy.packageJsonMissing":
|
|
177
|
-
"
|
|
178
|
-
"cause.lockMismatch": "
|
|
183
|
+
"处理:资源仓库可能不完整。请联系资源的维护者。",
|
|
184
|
+
"cause.lockMismatch": "原因:{dir} 的 package.json 与锁文件的内容不一致。",
|
|
179
185
|
"remedy.lockMismatch":
|
|
180
|
-
"
|
|
181
|
-
"cause.pmNotFound": "
|
|
182
|
-
"remedy.pmNotFound": "
|
|
183
|
-
"cause.network": "
|
|
184
|
-
"remedy.network": "
|
|
185
|
-
"cause.linkBlocked": "
|
|
186
|
+
"处理:如果你在本地编辑过 {dir},请在 {dir} 中执行 `{pm} install` 更新锁文件,删除生成的 node_modules 后重新执行。",
|
|
187
|
+
"cause.pmNotFound": "原因:找不到包管理器 {pm} 的可执行文件。",
|
|
188
|
+
"remedy.pmNotFound": "处理:请安装 {pm},或修改 .accel/settings.json 中的 packageManager。",
|
|
189
|
+
"cause.network": "原因:无法连接到包注册表。",
|
|
190
|
+
"remedy.network": "处理:连接网络后重新执行。",
|
|
191
|
+
"cause.linkBlocked": "原因:{path} 处存在非链接的目录或文件。",
|
|
186
192
|
"remedy.linkBlocked":
|
|
187
|
-
"
|
|
188
|
-
"cause.unsafeLayout": "
|
|
189
|
-
"remedy.unsafeLayout": "
|
|
190
|
-
"cause.unsafePath": "
|
|
191
|
-
"remedy.unsafePath": "
|
|
192
|
-
"
|
|
193
|
+
"处理:不会触碰 {path} 处现有的目录或文件。如需替换为链接,请删除 {path} 后重新执行。",
|
|
194
|
+
"cause.unsafeLayout": "原因:{path} 是符号链接(不是 CLI 创建的目录)。",
|
|
195
|
+
"remedy.unsafeLayout": "处理:请删除 {path} 后重新执行。",
|
|
196
|
+
"cause.unsafePath": "原因:依赖目录 {dir} 指向了项目之外。",
|
|
197
|
+
"remedy.unsafePath": "处理:请将 {link} 替换为普通目录后,运行 accel update。",
|
|
198
|
+
"remedy.unsafePathNoUpdate": "处理:请将 {link} 替换为普通目录。",
|
|
199
|
+
"cause.linkedPath": "原因:{link} 是符号链接,因此依赖目录 {dir} 中未部署资源。",
|
|
200
|
+
"cause.lockTimeout": "原因:另一个进程仍在准备 {dir} 的依赖,且未在等待时间内完成。",
|
|
193
201
|
"remedy.lockTimeout":
|
|
194
|
-
"
|
|
195
|
-
"cause.installFailed": "
|
|
196
|
-
"remedy.installFailed": "
|
|
197
|
-
outputTail: "
|
|
202
|
+
"处理:请稍候再重新执行。如果一直停滞,请删除 .accel/runtime/{id}.lock 后重新执行。",
|
|
203
|
+
"cause.installFailed": "原因:install 命令执行失败。命令:{command} / 工作目录:{cwd}",
|
|
204
|
+
"remedy.installFailed": "处理:请查看输出并排除原因后,重新执行。",
|
|
205
|
+
outputTail: "输出(末尾):",
|
|
198
206
|
runnerSkipped: "由于 skill 依赖准备失败,未启动 {script}。",
|
|
199
|
-
rerun: "
|
|
207
|
+
rerun: "重新执行命令:{command}",
|
|
200
208
|
},
|
|
201
209
|
};
|
|
202
210
|
|
|
@@ -311,6 +319,36 @@ function isInsideRoot(rootReal, p) {
|
|
|
311
319
|
return real.startsWith(rootReal + path.sep);
|
|
312
320
|
}
|
|
313
321
|
|
|
322
|
+
/**
|
|
323
|
+
* 依存ディレクトリ dep(ルート相対の POSIX パス)がシンボリックリンクのせいで使えない場合に、
|
|
324
|
+
* 失敗の種類と、案内に示す最初のシンボリックリンク(ジャンクションを含む)の段(ルート相対)を
|
|
325
|
+
* 返す。使えるなら null(spec §4.8「処理手順」の 3.1)。
|
|
326
|
+
* - unsafePath: 存在する段の実体がプロジェクトの外を指す。依存ディレクトリが無い場合は、存在する
|
|
327
|
+
* 最も近い上の段で判定することになる。リンク先が無いリンクの段も外として扱う(実体を解決できないため)
|
|
328
|
+
* - linkedPath: 依存ディレクトリが無く、途中の段がプロジェクトの中を指すシンボリックリンク
|
|
329
|
+
* CLI はシンボリックリンク等を経由して配備しないので、リンクの先に依存ディレクトリが作られない。
|
|
330
|
+
* 判定しないと package.json の不足として資材の不備に見えてしまう
|
|
331
|
+
*/
|
|
332
|
+
function findLinkedPath(root, rootReal, dep) {
|
|
333
|
+
const segments = dep.split("/").filter((s) => s !== "" && s !== ".");
|
|
334
|
+
let firstLink = null;
|
|
335
|
+
for (let i = 0; i < segments.length; i++) {
|
|
336
|
+
const abs = path.join(root, ...segments.slice(0, i + 1));
|
|
337
|
+
let st;
|
|
338
|
+
try {
|
|
339
|
+
st = fs.lstatSync(abs);
|
|
340
|
+
} catch {
|
|
341
|
+
// 無い段から下は作られていない。途中にリンクがあれば、それが理由で配備されていない
|
|
342
|
+
return firstLink === null ? null : { kind: "linkedPath", link: firstLink };
|
|
343
|
+
}
|
|
344
|
+
if (st.isSymbolicLink() && firstLink === null) {
|
|
345
|
+
firstLink = segments.slice(0, i + 1).join("/");
|
|
346
|
+
}
|
|
347
|
+
if (!isInsideRoot(rootReal, abs)) return { kind: "unsafePath", link: firstLink ?? dep };
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
|
|
314
352
|
/**
|
|
315
353
|
* `.accel` / `.accel/runtime` が CLI の作るディレクトリでない(シンボリックリンク等)
|
|
316
354
|
* 場合はそのパス(ルート相対)を返す。GC が runtime 配下を削除するため、リンク経由で
|
|
@@ -374,10 +412,15 @@ function readSettings(root) {
|
|
|
374
412
|
? parsed.packageManager
|
|
375
413
|
: DEFAULT_PM;
|
|
376
414
|
const locale = typeof parsed.locale === "string" ? parsed.locale : "en";
|
|
415
|
+
// 資材の取得元が git のときだけ accel update を案内できる(git でなければ update は前提条件のエラー)
|
|
416
|
+
const updateAvailable =
|
|
417
|
+
parsed.assetSource !== null &&
|
|
418
|
+
typeof parsed.assetSource === "object" &&
|
|
419
|
+
parsed.assetSource.type === "git";
|
|
377
420
|
const raw = Array.isArray(parsed.dependencies) ? parsed.dependencies : [];
|
|
378
421
|
// 辞書順(コードポイント順。CLI 側の collectDependencyDirs と同じ規則)
|
|
379
422
|
const dependencies = [...new Set(raw.filter(isAllowedDependencyDir))].sort();
|
|
380
|
-
return { packageManager, locale, dependencies };
|
|
423
|
+
return { packageManager, locale, dependencies, updateAvailable };
|
|
381
424
|
}
|
|
382
425
|
|
|
383
426
|
/** `.accel/runtime/state.json` を読む。読めない・壊れている場合は空として扱う。 */
|
|
@@ -639,7 +682,8 @@ function ensureLink(depDirAbs, targetAbs) {
|
|
|
639
682
|
|
|
640
683
|
/**
|
|
641
684
|
* 依存ディレクトリを処理し、結果を返す。
|
|
642
|
-
* 戻り値: { installed: [{ dir, id }], failures: [{ kind, params, tail? }] }
|
|
685
|
+
* 戻り値: { installed: [{ dir, id }], failures: [{ kind, params, tail?, remedy? }] }
|
|
686
|
+
* (remedy は対処の文のキー。省略時は kind と同じ)
|
|
643
687
|
*/
|
|
644
688
|
export function ensure(root, settings) {
|
|
645
689
|
const { packageManager: pm, dependencies } = settings;
|
|
@@ -666,9 +710,15 @@ export function ensure(root, settings) {
|
|
|
666
710
|
const pkgFile = path.join(depDirAbs, "package.json");
|
|
667
711
|
const lockFile = path.join(depDirAbs, lockName);
|
|
668
712
|
|
|
669
|
-
// 1.
|
|
670
|
-
|
|
671
|
-
|
|
713
|
+
// 1. 依存ディレクトリがシンボリックリンクのせいで使えないこと(実体がプロジェクトの外、
|
|
714
|
+
// または途中のリンクのため作られていない)、両ファイルの存在確認
|
|
715
|
+
const linked = findLinkedPath(root, rootReal, dep);
|
|
716
|
+
if (linked !== null) {
|
|
717
|
+
failures.push({
|
|
718
|
+
kind: linked.kind,
|
|
719
|
+
params: { dir: dep, link: linked.link },
|
|
720
|
+
remedy: settings.updateAvailable ? "unsafePath" : "unsafePathNoUpdate",
|
|
721
|
+
});
|
|
672
722
|
continue;
|
|
673
723
|
}
|
|
674
724
|
let pkgText;
|
|
@@ -843,7 +893,7 @@ export function formatGuidance(locale, failures) {
|
|
|
843
893
|
for (const failure of failures) {
|
|
844
894
|
const lines = [
|
|
845
895
|
t(locale, `cause.${failure.kind}`, failure.params),
|
|
846
|
-
t(locale, `remedy.${failure.kind}`, failure.params),
|
|
896
|
+
t(locale, `remedy.${failure.remedy ?? failure.kind}`, failure.params),
|
|
847
897
|
];
|
|
848
898
|
if (failure.tail && failure.tail.length > 0) {
|
|
849
899
|
lines.push(t(locale, "outputTail"));
|
package/dist/asset/deployer.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AssetProvider, AccelSettings, HashsumEntry } from "../core/types.js";
|
|
2
2
|
import { type AssetMessage } from "./messages.js";
|
|
3
|
+
import { type BlockedFile } from "../utils/path-guard.js";
|
|
4
|
+
export type { BlockedFile };
|
|
3
5
|
export type OverwriteDecision = "overwrite" | "skip";
|
|
4
6
|
export type ExistingFileHandler = (relativePath: string) => Promise<OverwriteDecision>;
|
|
5
7
|
export type ProgressCallbacks = {
|
|
@@ -26,6 +28,11 @@ export type DeployResult = {
|
|
|
26
28
|
skippedFiles: string[];
|
|
27
29
|
overwrittenFiles: string[];
|
|
28
30
|
dependencies: string[];
|
|
31
|
+
blockedFiles: BlockedFile[];
|
|
29
32
|
};
|
|
30
33
|
export declare const ROOT_SECTION = "(root)";
|
|
34
|
+
export type DeployInternalOptions = {
|
|
35
|
+
reflectManagedHooks: boolean;
|
|
36
|
+
};
|
|
31
37
|
export declare const deployAssets: (options: DeployOptions) => Promise<DeployResult>;
|
|
38
|
+
export declare const deployAssetsWithOptions: (options: DeployOptions, internal: DeployInternalOptions) => Promise<DeployResult>;
|
package/dist/asset/deployer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writeFile, mkdir
|
|
1
|
+
import { writeFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import { join, dirname, resolve, sep } from "node:path";
|
|
3
3
|
import { buildEvalContext } from "../core/eval-context.js";
|
|
4
4
|
import { normalizeAbort } from "../core/errors.js";
|
|
@@ -8,16 +8,9 @@ import { createMessageCollector } from "./messages.js";
|
|
|
8
8
|
import { renderAssetContent } from "./renderer.js";
|
|
9
9
|
import { computeSha1 } from "../utils/hash.js";
|
|
10
10
|
import { FS_CONCURRENCY, mapWithConcurrency } from "../utils/concurrency.js";
|
|
11
|
-
import { writeSettings, writeHashsum } from "../utils/settings-io.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
await stat(path);
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
11
|
+
import { ACCEL_RECORD_PATHS, writeSettings, writeHashsum, } from "../utils/settings-io.js";
|
|
12
|
+
import { managedHookStateOf, reflectManagedHooks, } from "../utils/managed-hooks.js";
|
|
13
|
+
import { assertPathsWritable, createPathGuard, } from "../utils/path-guard.js";
|
|
21
14
|
const isWithinDir = (parentDir, candidate) => {
|
|
22
15
|
const parent = resolve(parentDir);
|
|
23
16
|
const target = resolve(candidate);
|
|
@@ -50,9 +43,11 @@ const groupSections = (entries) => {
|
|
|
50
43
|
}
|
|
51
44
|
return [...groups.values()];
|
|
52
45
|
};
|
|
53
|
-
export const deployAssets =
|
|
46
|
+
export const deployAssets = (options) => deployAssetsWithOptions(options, { reflectManagedHooks: false });
|
|
47
|
+
export const deployAssetsWithOptions = async (options, internal) => {
|
|
54
48
|
const { projectDir, settings, provider, skipExistingFiles, onExistingFile, progress, signal, } = options;
|
|
55
49
|
try {
|
|
50
|
+
await assertPathsWritable(projectDir, ACCEL_RECORD_PATHS, settings.locale);
|
|
56
51
|
progress?.onFetchStart?.();
|
|
57
52
|
const repoDir = await provider.fetch();
|
|
58
53
|
const tree = {
|
|
@@ -63,7 +58,7 @@ export const deployAssets = async (options) => {
|
|
|
63
58
|
const context = buildEvalContext(settings);
|
|
64
59
|
const messageCollector = createMessageCollector();
|
|
65
60
|
const allEntries = await walkAssetRepo(tree, context, messageCollector.collect);
|
|
66
|
-
const
|
|
61
|
+
const plannedEntries = allEntries.filter((entry) => {
|
|
67
62
|
if (!isWithinDir(projectDir, join(projectDir, entry.relativePath))) {
|
|
68
63
|
progress?.onPathRejected?.("project", entry.relativePath);
|
|
69
64
|
return false;
|
|
@@ -74,6 +69,25 @@ export const deployAssets = async (options) => {
|
|
|
74
69
|
}
|
|
75
70
|
return true;
|
|
76
71
|
});
|
|
72
|
+
const dependencies = collectDependencyDirs(plannedEntries);
|
|
73
|
+
const hookState = internal.reflectManagedHooks
|
|
74
|
+
? managedHookStateOf({ ...settings, dependencies })
|
|
75
|
+
: null;
|
|
76
|
+
const guard = createPathGuard(projectDir);
|
|
77
|
+
const guarded = await mapWithConcurrency(plannedEntries, FS_CONCURRENCY, (entry) => guard.check(entry.relativePath));
|
|
78
|
+
const entries = [];
|
|
79
|
+
const existsFlags = [];
|
|
80
|
+
const blockedFiles = [];
|
|
81
|
+
for (const [index, entry] of plannedEntries.entries()) {
|
|
82
|
+
const result = guarded[index];
|
|
83
|
+
if (result.ok) {
|
|
84
|
+
entries.push(entry);
|
|
85
|
+
existsFlags.push(result.exists);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
blockedFiles.push({ path: entry.relativePath, blockedBy: result.blockedBy });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
77
91
|
signal?.throwIfAborted();
|
|
78
92
|
progress?.onDownloadStart?.();
|
|
79
93
|
await provider.materialize([
|
|
@@ -84,7 +98,6 @@ export const deployAssets = async (options) => {
|
|
|
84
98
|
progress.onSectionDeploy(group.section, group.files);
|
|
85
99
|
}
|
|
86
100
|
}
|
|
87
|
-
const existsFlags = await mapWithConcurrency(entries, FS_CONCURRENCY, (entry) => fileExists(join(projectDir, entry.relativePath)));
|
|
88
101
|
const skippedFiles = [];
|
|
89
102
|
const overwrittenFiles = [];
|
|
90
103
|
const toDeploy = [];
|
|
@@ -111,7 +124,10 @@ export const deployAssets = async (options) => {
|
|
|
111
124
|
const targetPath = entry.relativePath;
|
|
112
125
|
const destPath = join(projectDir, targetPath);
|
|
113
126
|
const raw = await tree.readFile(entry.sourceRelPath);
|
|
114
|
-
const
|
|
127
|
+
const rendered = renderAssetContent(raw, targetPath, collectReplacements(entry), context);
|
|
128
|
+
const content = hookState === null
|
|
129
|
+
? rendered
|
|
130
|
+
: reflectManagedHooks(targetPath, rendered, hookState);
|
|
115
131
|
await mkdir(dirname(destPath), { recursive: true });
|
|
116
132
|
await writeFile(destPath, content, "utf-8");
|
|
117
133
|
return {
|
|
@@ -125,7 +141,6 @@ export const deployAssets = async (options) => {
|
|
|
125
141
|
for (const h of hashEntries) {
|
|
126
142
|
deployedAssets[h.filePath] = h.version;
|
|
127
143
|
}
|
|
128
|
-
const dependencies = collectDependencyDirs(entries);
|
|
129
144
|
const updatedSettings = withDependencies({
|
|
130
145
|
...settings,
|
|
131
146
|
assetSource: provider.sourceInfo(),
|
|
@@ -143,6 +158,7 @@ export const deployAssets = async (options) => {
|
|
|
143
158
|
skippedFiles,
|
|
144
159
|
overwrittenFiles,
|
|
145
160
|
dependencies,
|
|
161
|
+
blockedFiles,
|
|
146
162
|
};
|
|
147
163
|
}
|
|
148
164
|
catch (err) {
|
package/dist/asset/updater.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { AccelSettings, HashsumEntry } from "../core/types.js";
|
|
2
2
|
import type { AssetTree } from "./asset-tree.js";
|
|
3
3
|
import type { MessageSink } from "./messages.js";
|
|
4
|
+
import { type BlockedFile } from "../utils/path-guard.js";
|
|
4
5
|
import type { MergeFn } from "../utils/merge-file.js";
|
|
6
|
+
import { type ManagedHookState } from "../utils/managed-hooks.js";
|
|
5
7
|
export type RenderedAsset = {
|
|
6
8
|
relativePath: string;
|
|
7
9
|
content: string;
|
|
@@ -11,7 +13,9 @@ export type RenderedAsset = {
|
|
|
11
13
|
};
|
|
12
14
|
export type RenderedPlan = Map<string, RenderedAsset>;
|
|
13
15
|
export declare const buildRenderedPlan: (tree: AssetTree, settings: AccelSettings, materialize?: (files: string[]) => Promise<void>, collect?: MessageSink, onPathRejected?: (kind: "project" | "assetRepo", path: string) => void) => Promise<RenderedPlan>;
|
|
16
|
+
export declare const reflectManagedHooksInPlan: (plan: RenderedPlan, state: ManagedHookState) => RenderedPlan;
|
|
14
17
|
export declare const dependencyDirsOfPlan: (plan: RenderedPlan) => string[];
|
|
18
|
+
export declare const reflectManagedHooksInTheirsPlan: (theirsRawPlan: RenderedPlan, newSettings: AccelSettings) => RenderedPlan;
|
|
15
19
|
export type FileState = {
|
|
16
20
|
relativePath: string;
|
|
17
21
|
base: RenderedAsset | null;
|
|
@@ -29,7 +33,17 @@ export type UpdateAction = {
|
|
|
29
33
|
skipReason?: SwitchSkipReason;
|
|
30
34
|
record: HashsumEntry | "keep" | "remove";
|
|
31
35
|
};
|
|
32
|
-
export
|
|
36
|
+
export type CollectedFileStates = {
|
|
37
|
+
states: FileState[];
|
|
38
|
+
recorded: HashsumEntry[];
|
|
39
|
+
blocked: BlockedFile[];
|
|
40
|
+
};
|
|
41
|
+
export declare const collectFileStates: (projectDir: string, basePlan: RenderedPlan, theirsPlan: RenderedPlan, recorded: HashsumEntry[]) => Promise<CollectedFileStates>;
|
|
42
|
+
export declare const migrateLegacyHookRecords: (states: FileState[], rawBasePlan: RenderedPlan, recorded: HashsumEntry[]) => {
|
|
43
|
+
states: FileState[];
|
|
44
|
+
recorded: HashsumEntry[];
|
|
45
|
+
};
|
|
46
|
+
export declare const collectFileStatesWithManagedHooks: (projectDir: string, baseRawPlan: RenderedPlan, theirsPlan: RenderedPlan, oldSettings: AccelSettings, recorded: HashsumEntry[]) => Promise<CollectedFileStates>;
|
|
33
47
|
export declare const classifyFile: (state: FileState, merge: MergeFn) => Promise<UpdateAction>;
|
|
34
48
|
export declare const classifyFileFallback: (state: FileState, merge: MergeFn, keepEdited: boolean) => Promise<UpdateAction>;
|
|
35
49
|
export declare const classifyFileSwitch: (state: FileState) => UpdateAction;
|
package/dist/asset/updater.js
CHANGED
|
@@ -2,11 +2,13 @@ import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { buildEvalContext } from "../core/eval-context.js";
|
|
4
4
|
import { walkAssetRepo, replacementsFor } from "./walker.js";
|
|
5
|
-
import { collectDependencyDirs } from "./dependencies.js";
|
|
5
|
+
import { collectDependencyDirs, withDependencies } from "./dependencies.js";
|
|
6
6
|
import { renderAssetContent } from "./renderer.js";
|
|
7
7
|
import { computeSha1 } from "../utils/hash.js";
|
|
8
8
|
import { FS_CONCURRENCY, mapWithConcurrency } from "../utils/concurrency.js";
|
|
9
9
|
import { isSafeRelPath } from "../utils/safe-rel-path.js";
|
|
10
|
+
import { createPathGuard } from "../utils/path-guard.js";
|
|
11
|
+
import { MANAGED_HOOK_TARGETS, managedHookStateOf, reflectManagedHooks, } from "../utils/managed-hooks.js";
|
|
10
12
|
export const buildRenderedPlan = async (tree, settings, materialize, collect, onPathRejected) => {
|
|
11
13
|
const context = buildEvalContext(settings);
|
|
12
14
|
const entries = await walkAssetRepo(tree, context, collect);
|
|
@@ -39,7 +41,22 @@ export const buildRenderedPlan = async (tree, settings, materialize, collect, on
|
|
|
39
41
|
});
|
|
40
42
|
return new Map(rendered.map((asset) => [asset.relativePath, asset]));
|
|
41
43
|
};
|
|
44
|
+
export const reflectManagedHooksInPlan = (plan, state) => {
|
|
45
|
+
const next = new Map();
|
|
46
|
+
for (const [key, asset] of plan) {
|
|
47
|
+
if (!MANAGED_HOOK_TARGETS.has(key)) {
|
|
48
|
+
next.set(key, asset);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const content = reflectManagedHooks(key, asset.content, state);
|
|
52
|
+
next.set(key, content === asset.content
|
|
53
|
+
? asset
|
|
54
|
+
: { ...asset, content, sha1: computeSha1(content) });
|
|
55
|
+
}
|
|
56
|
+
return next;
|
|
57
|
+
};
|
|
42
58
|
export const dependencyDirsOfPlan = (plan) => collectDependencyDirs([...plan.values()]);
|
|
59
|
+
export const reflectManagedHooksInTheirsPlan = (theirsRawPlan, newSettings) => reflectManagedHooksInPlan(theirsRawPlan, managedHookStateOf(withDependencies(newSettings, dependencyDirsOfPlan(theirsRawPlan))));
|
|
43
60
|
export const collectFileStates = async (projectDir, basePlan, theirsPlan, recorded) => {
|
|
44
61
|
const recordedMap = new Map(recorded.map((e) => [e.filePath, e]));
|
|
45
62
|
const keys = new Set([
|
|
@@ -52,7 +69,18 @@ export const collectFileStates = async (projectDir, basePlan, theirsPlan, record
|
|
|
52
69
|
const rec = recordedMap.get(key) ?? null;
|
|
53
70
|
return theirs || rec ? [{ key, theirs, rec }] : [];
|
|
54
71
|
});
|
|
55
|
-
|
|
72
|
+
const guard = createPathGuard(projectDir);
|
|
73
|
+
const guarded = await mapWithConcurrency(targets, FS_CONCURRENCY, (target) => guard.check(target.key));
|
|
74
|
+
const blocked = [];
|
|
75
|
+
const allowed = targets.filter((target, index) => {
|
|
76
|
+
const result = guarded[index];
|
|
77
|
+
if (result.ok)
|
|
78
|
+
return true;
|
|
79
|
+
blocked.push({ path: target.key, blockedBy: result.blockedBy });
|
|
80
|
+
return false;
|
|
81
|
+
});
|
|
82
|
+
const blockedKeys = new Set(blocked.map((file) => file.path));
|
|
83
|
+
const states = await mapWithConcurrency(allowed, FS_CONCURRENCY, async ({ key, theirs, rec }) => {
|
|
56
84
|
let oursContent = null;
|
|
57
85
|
try {
|
|
58
86
|
oursContent = await readFile(join(projectDir, key), "utf-8");
|
|
@@ -68,6 +96,47 @@ export const collectFileStates = async (projectDir, basePlan, theirsPlan, record
|
|
|
68
96
|
recorded: rec,
|
|
69
97
|
};
|
|
70
98
|
});
|
|
99
|
+
return {
|
|
100
|
+
states,
|
|
101
|
+
recorded: blockedKeys.size === 0
|
|
102
|
+
? recorded
|
|
103
|
+
: recorded.filter((entry) => !blockedKeys.has(entry.filePath)),
|
|
104
|
+
blocked,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
export const migrateLegacyHookRecords = (states, rawBasePlan, recorded) => {
|
|
108
|
+
const migrated = new Map();
|
|
109
|
+
const nextStates = states.map((state) => {
|
|
110
|
+
const { relativePath, base, oursContent, recorded: rec } = state;
|
|
111
|
+
if (!MANAGED_HOOK_TARGETS.has(relativePath))
|
|
112
|
+
return state;
|
|
113
|
+
const rawBase = rawBasePlan.get(relativePath);
|
|
114
|
+
if (rec === null || base === null || rawBase === undefined)
|
|
115
|
+
return state;
|
|
116
|
+
if (oursContent === null)
|
|
117
|
+
return state;
|
|
118
|
+
if (rec.sha1 !== rawBase.sha1 || base.sha1 === rawBase.sha1)
|
|
119
|
+
return state;
|
|
120
|
+
if (computeSha1(oursContent) === rec.sha1)
|
|
121
|
+
return state;
|
|
122
|
+
const nextRecord = { ...rec, sha1: base.sha1 };
|
|
123
|
+
migrated.set(relativePath, nextRecord);
|
|
124
|
+
return { ...state, recorded: nextRecord };
|
|
125
|
+
});
|
|
126
|
+
if (migrated.size === 0)
|
|
127
|
+
return { states, recorded };
|
|
128
|
+
return {
|
|
129
|
+
states: nextStates,
|
|
130
|
+
recorded: recorded.map((e) => migrated.get(e.filePath) ?? e),
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
export const collectFileStatesWithManagedHooks = async (projectDir, baseRawPlan, theirsPlan, oldSettings, recorded) => {
|
|
134
|
+
const basePlan = reflectManagedHooksInPlan(baseRawPlan, managedHookStateOf(oldSettings));
|
|
135
|
+
const collected = await collectFileStates(projectDir, basePlan, theirsPlan, recorded);
|
|
136
|
+
return {
|
|
137
|
+
...migrateLegacyHookRecords(collected.states, baseRawPlan, collected.recorded),
|
|
138
|
+
blocked: collected.blocked,
|
|
139
|
+
};
|
|
71
140
|
};
|
|
72
141
|
export const classifyFile = async (state, merge) => {
|
|
73
142
|
const { relativePath, base, theirs, oursContent, recorded } = state;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Logger } from "../core/logger.js";
|
|
2
2
|
import type { AssetSourceInfo } from "../core/types.js";
|
|
3
3
|
import type { DeployResult, ExistingFileHandler } from "../asset/deployer.js";
|
|
4
|
-
type AttachFileResult = Pick<DeployResult, "deployedFiles" | "overwrittenFiles" | "skippedFiles">;
|
|
5
|
-
export declare const stopsInstallBuild: (result: Pick<DeployResult, "skippedFiles">) => boolean;
|
|
4
|
+
type AttachFileResult = Pick<DeployResult, "deployedFiles" | "overwrittenFiles" | "skippedFiles" | "blockedFiles">;
|
|
5
|
+
export declare const stopsInstallBuild: (result: Pick<DeployResult, "skippedFiles" | "blockedFiles">) => boolean;
|
|
6
6
|
export declare const formatInstallStopped: (result: AttachFileResult, packageManager: string, locale: string) => string;
|
|
7
7
|
export declare const formatPomNotice: (result: AttachFileResult, locale: string) => string | undefined;
|
|
8
8
|
export declare const formatUpdateHint: (result: Pick<DeployResult, "skippedFiles">, sourceType: AssetSourceInfo["type"], locale: string) => string | undefined;
|
|
@@ -16,4 +16,5 @@ export declare const resolveExistingFilePolicy: (opts: {
|
|
|
16
16
|
onExistingFile?: ExistingFileHandler;
|
|
17
17
|
};
|
|
18
18
|
export declare const reportExistingFiles: (result: DeployResult, logger: Logger, locale: string) => void;
|
|
19
|
+
export declare const reportBlockedFiles: (result: Pick<DeployResult, "blockedFiles">, logger: Logger, locale: string, sourceType: AssetSourceInfo["type"]) => void;
|
|
19
20
|
export {};
|
|
@@ -4,10 +4,14 @@ import { createCancelledError } from "../core/errors.js";
|
|
|
4
4
|
import { lockfileFor, PACKAGE_JSON_NAME } from "../core/constants.js";
|
|
5
5
|
import { getInstallCmds, getLockfileUpdateInstallCmd, } from "../asset/installer.js";
|
|
6
6
|
import { getMessage } from "../i18n/index.js";
|
|
7
|
+
import { reportBlockedWarnings } from "../utils/path-guard.js";
|
|
7
8
|
import { sanitizeDisplayText } from "../utils/sanitize-text.js";
|
|
8
9
|
const GITIGNORE_NAME = ".gitignore";
|
|
9
10
|
const POM_XML_NAME = "pom.xml";
|
|
10
|
-
|
|
11
|
+
const hasNonGitignore = (paths) => paths.some((path) => posix.basename(path) !== GITIGNORE_NAME);
|
|
12
|
+
const stopsBySkipped = (result) => hasNonGitignore(result.skippedFiles);
|
|
13
|
+
export const stopsInstallBuild = (result) => stopsBySkipped(result) ||
|
|
14
|
+
hasNonGitignore(result.blockedFiles.map((file) => file.path));
|
|
11
15
|
const lockfileMismatchLikely = (result, packageManager) => {
|
|
12
16
|
const skipped = new Set(result.skippedFiles);
|
|
13
17
|
const written = new Set(result.deployedFiles);
|
|
@@ -17,6 +21,12 @@ const lockfileMismatchLikely = (result, packageManager) => {
|
|
|
17
21
|
};
|
|
18
22
|
export const formatInstallStopped = (result, packageManager, locale) => {
|
|
19
23
|
const [installCommand, buildCommand] = getInstallCmds(packageManager);
|
|
24
|
+
if (!stopsBySkipped(result)) {
|
|
25
|
+
return getMessage("attach.installStoppedBlocked", locale, {
|
|
26
|
+
installCommand,
|
|
27
|
+
buildCommand,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
20
30
|
const stopped = getMessage("attach.installStopped", locale, {
|
|
21
31
|
installCommand,
|
|
22
32
|
buildCommand,
|
|
@@ -120,3 +130,10 @@ export const reportExistingFiles = (result, logger, locale) => {
|
|
|
120
130
|
}));
|
|
121
131
|
}
|
|
122
132
|
};
|
|
133
|
+
export const reportBlockedFiles = (result, logger, locale, sourceType) => {
|
|
134
|
+
reportBlockedWarnings(logger, "deploy", result.blockedFiles, locale, {
|
|
135
|
+
guidanceKey: sourceType === "git"
|
|
136
|
+
? "pathGuard.guidance.attach"
|
|
137
|
+
: "pathGuard.guidance.attachNoUpdate",
|
|
138
|
+
});
|
|
139
|
+
};
|
|
@@ -135,7 +135,7 @@ export declare const attachCommand: import("citty").CommandDef<{
|
|
|
135
135
|
};
|
|
136
136
|
readonly "asset-ref": {
|
|
137
137
|
readonly type: "string";
|
|
138
|
-
readonly description: "Git branch/tag to fetch from the asset repository. Default:
|
|
138
|
+
readonly description: "Git branch/tag to fetch from the asset repository. Default: experiment";
|
|
139
139
|
};
|
|
140
140
|
readonly "asset-source": {
|
|
141
141
|
readonly type: "string";
|