@lark-apaas/fullstack-cli 1.1.71-alpha.20261103133134 → 1.1.71-alpha.20261103162030
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/dist/index.js +1451 -814
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs39 from "fs";
|
|
3
|
+
import path34 from "path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
@@ -2807,28 +2807,125 @@ var ACTION_PLUGIN_RESTORE_COMMAND = "fullstack-cli action-plugin restore";
|
|
|
2807
2807
|
var LEGACY_ACTION_PLUGIN_INIT_COMMAND = "fullstack-cli action-plugin init";
|
|
2808
2808
|
var ACTION_PLUGIN_REENTRY_ENV = "FULLSTACK_CLI_ACTION_PLUGIN_REENTRY";
|
|
2809
2809
|
var ACTION_PLUGIN_REENTRY_VALUE = "1";
|
|
2810
|
-
function
|
|
2810
|
+
function normalizeManagedCommand(segment) {
|
|
2811
2811
|
return segment.trim().replace(/\s+/g, " ");
|
|
2812
2812
|
}
|
|
2813
|
-
function
|
|
2814
|
-
const
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2813
|
+
function isManagedLifecycleSegment(segment) {
|
|
2814
|
+
const normalized = normalizeManagedCommand(segment);
|
|
2815
|
+
return normalized === LEGACY_ACTION_PLUGIN_INIT_COMMAND || normalized === ACTION_PLUGIN_RESTORE_COMMAND;
|
|
2816
|
+
}
|
|
2817
|
+
function isShellWhitespace(character) {
|
|
2818
|
+
return /\s/.test(character);
|
|
2819
|
+
}
|
|
2820
|
+
function findTopLevelAndOperators(command) {
|
|
2821
|
+
const operators = [];
|
|
2822
|
+
let quote = null;
|
|
2823
|
+
let parenthesisDepth = 0;
|
|
2824
|
+
let braceDepth = 0;
|
|
2825
|
+
let inComment = false;
|
|
2826
|
+
for (let index = 0; index < command.length; index++) {
|
|
2827
|
+
const character = command[index];
|
|
2828
|
+
if (inComment) {
|
|
2829
|
+
if (character === "\n") inComment = false;
|
|
2830
|
+
continue;
|
|
2831
|
+
}
|
|
2832
|
+
if (quote) {
|
|
2833
|
+
if (quote !== "'" && character === "\\") {
|
|
2834
|
+
index++;
|
|
2835
|
+
continue;
|
|
2836
|
+
}
|
|
2837
|
+
if (character === quote) quote = null;
|
|
2838
|
+
continue;
|
|
2839
|
+
}
|
|
2840
|
+
if (character === "\\") {
|
|
2841
|
+
index++;
|
|
2842
|
+
continue;
|
|
2843
|
+
}
|
|
2844
|
+
if (character === "'" || character === '"' || character === "`") {
|
|
2845
|
+
quote = character;
|
|
2822
2846
|
continue;
|
|
2823
2847
|
}
|
|
2824
|
-
|
|
2848
|
+
if (character === "#" && (index === 0 || isShellWhitespace(command[index - 1]))) {
|
|
2849
|
+
inComment = true;
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
if (character === "(") {
|
|
2853
|
+
parenthesisDepth++;
|
|
2854
|
+
continue;
|
|
2855
|
+
}
|
|
2856
|
+
if (character === ")") {
|
|
2857
|
+
if (parenthesisDepth > 0) parenthesisDepth--;
|
|
2858
|
+
continue;
|
|
2859
|
+
}
|
|
2860
|
+
if (character === "{") {
|
|
2861
|
+
braceDepth++;
|
|
2862
|
+
continue;
|
|
2863
|
+
}
|
|
2864
|
+
if (character === "}") {
|
|
2865
|
+
if (braceDepth > 0) braceDepth--;
|
|
2866
|
+
continue;
|
|
2867
|
+
}
|
|
2868
|
+
if (character === "&" && command[index + 1] === "&" && parenthesisDepth === 0 && braceDepth === 0) {
|
|
2869
|
+
operators.push(index);
|
|
2870
|
+
index++;
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
return operators;
|
|
2874
|
+
}
|
|
2875
|
+
function splitShellAndList(command) {
|
|
2876
|
+
const segments = [];
|
|
2877
|
+
const separators = [];
|
|
2878
|
+
let cursor = 0;
|
|
2879
|
+
for (const [index, operator] of findTopLevelAndOperators(command).entries()) {
|
|
2880
|
+
let separatorStart = operator;
|
|
2881
|
+
while (separatorStart > cursor && isShellWhitespace(command[separatorStart - 1])) {
|
|
2882
|
+
separatorStart--;
|
|
2883
|
+
}
|
|
2884
|
+
let separatorEnd = operator + 2;
|
|
2885
|
+
while (separatorEnd < command.length && isShellWhitespace(command[separatorEnd])) {
|
|
2886
|
+
separatorEnd++;
|
|
2887
|
+
}
|
|
2888
|
+
segments.push({ text: command.slice(cursor, separatorStart), index });
|
|
2889
|
+
separators.push({ text: command.slice(separatorStart, separatorEnd) });
|
|
2890
|
+
cursor = separatorEnd;
|
|
2891
|
+
}
|
|
2892
|
+
segments.push({ text: command.slice(cursor), index: segments.length });
|
|
2893
|
+
return { segments, separators };
|
|
2894
|
+
}
|
|
2895
|
+
function stripManagedLifecycleSegments(command) {
|
|
2896
|
+
const { segments, separators } = splitShellAndList(command);
|
|
2897
|
+
const customSegments = segments.filter(
|
|
2898
|
+
(segment) => !isManagedLifecycleSegment(segment.text)
|
|
2899
|
+
);
|
|
2900
|
+
if (customSegments.length === segments.length) return command;
|
|
2901
|
+
if (customSegments.length === 0) return "";
|
|
2902
|
+
let result = customSegments[0].text;
|
|
2903
|
+
for (const segment of customSegments.slice(1)) {
|
|
2904
|
+
result += separators[segment.index - 1].text + segment.text;
|
|
2825
2905
|
}
|
|
2826
|
-
|
|
2906
|
+
return result;
|
|
2907
|
+
}
|
|
2908
|
+
function composeActionPluginLifecycle(pkg2) {
|
|
2909
|
+
const scripts = pkg2.scripts ?? {};
|
|
2910
|
+
const current = scripts.postinstall ?? "";
|
|
2911
|
+
const custom = stripManagedLifecycleSegments(current);
|
|
2912
|
+
const next = custom ? `${custom} && ${ACTION_PLUGIN_RESTORE_COMMAND}` : ACTION_PLUGIN_RESTORE_COMMAND;
|
|
2827
2913
|
if (current === next) return false;
|
|
2828
2914
|
pkg2.scripts = scripts;
|
|
2829
2915
|
scripts.postinstall = next;
|
|
2830
2916
|
return true;
|
|
2831
2917
|
}
|
|
2918
|
+
function removeActionPluginLifecycle(pkg2) {
|
|
2919
|
+
const scripts = pkg2.scripts;
|
|
2920
|
+
if (!scripts?.postinstall) return false;
|
|
2921
|
+
const current = scripts.postinstall;
|
|
2922
|
+
const next = stripManagedLifecycleSegments(current);
|
|
2923
|
+
if (current === next) return false;
|
|
2924
|
+
if (next) scripts.postinstall = next;
|
|
2925
|
+
else delete scripts.postinstall;
|
|
2926
|
+
if (Object.keys(scripts).length === 0) delete pkg2.scripts;
|
|
2927
|
+
return true;
|
|
2928
|
+
}
|
|
2832
2929
|
function atomicWriteFile(filePath, content) {
|
|
2833
2930
|
const directory = path6.dirname(filePath);
|
|
2834
2931
|
const temporaryPath = path6.join(
|
|
@@ -4046,8 +4143,8 @@ var upgradeCommand = {
|
|
|
4046
4143
|
};
|
|
4047
4144
|
|
|
4048
4145
|
// src/commands/action-plugin/install-engine.ts
|
|
4049
|
-
import
|
|
4050
|
-
import
|
|
4146
|
+
import fs22 from "fs";
|
|
4147
|
+
import path19 from "path";
|
|
4051
4148
|
import { spawnSync as spawnSync7 } from "child_process";
|
|
4052
4149
|
|
|
4053
4150
|
// src/commands/action-plugin/plugin-files.ts
|
|
@@ -4058,39 +4155,6 @@ import { execFileSync } from "child_process";
|
|
|
4058
4155
|
function createStagingRoot() {
|
|
4059
4156
|
return fs16.mkdtempSync(path13.join(os.tmpdir(), "fullstack-cli-action-plugin-"));
|
|
4060
4157
|
}
|
|
4061
|
-
function snapshotFile(filePath) {
|
|
4062
|
-
return {
|
|
4063
|
-
filePath,
|
|
4064
|
-
content: fs16.existsSync(filePath) ? fs16.readFileSync(filePath) : null
|
|
4065
|
-
};
|
|
4066
|
-
}
|
|
4067
|
-
function restoreFile(snapshot) {
|
|
4068
|
-
if (snapshot.content === null) {
|
|
4069
|
-
if (fs16.existsSync(snapshot.filePath))
|
|
4070
|
-
fs16.rmSync(snapshot.filePath, { force: true });
|
|
4071
|
-
return;
|
|
4072
|
-
}
|
|
4073
|
-
atomicWriteFile(snapshot.filePath, snapshot.content);
|
|
4074
|
-
}
|
|
4075
|
-
function snapshotDirectory(targetPath, stagingRoot, snapshotName) {
|
|
4076
|
-
if (!fs16.existsSync(targetPath)) return { targetPath, backupPath: null };
|
|
4077
|
-
const backupPath = path13.join(stagingRoot, "snapshots", snapshotName);
|
|
4078
|
-
fs16.mkdirSync(path13.dirname(backupPath), { recursive: true });
|
|
4079
|
-
fs16.cpSync(targetPath, backupPath, { recursive: true, force: true });
|
|
4080
|
-
return { targetPath, backupPath };
|
|
4081
|
-
}
|
|
4082
|
-
function restoreDirectory(snapshot) {
|
|
4083
|
-
if (fs16.existsSync(snapshot.targetPath)) {
|
|
4084
|
-
fs16.rmSync(snapshot.targetPath, { recursive: true, force: true });
|
|
4085
|
-
}
|
|
4086
|
-
if (snapshot.backupPath) {
|
|
4087
|
-
fs16.mkdirSync(path13.dirname(snapshot.targetPath), { recursive: true });
|
|
4088
|
-
fs16.cpSync(snapshot.backupPath, snapshot.targetPath, {
|
|
4089
|
-
recursive: true,
|
|
4090
|
-
force: true
|
|
4091
|
-
});
|
|
4092
|
-
}
|
|
4093
|
-
}
|
|
4094
4158
|
function replaceDirectory(sourcePath, targetPath) {
|
|
4095
4159
|
fs16.mkdirSync(path13.dirname(targetPath), { recursive: true });
|
|
4096
4160
|
const incomingPath = `${targetPath}.fullstack-cli-${process.pid}-${Date.now()}`;
|
|
@@ -4133,8 +4197,8 @@ function extractTgzToDirectory(tgzPath, targetPath) {
|
|
|
4133
4197
|
}
|
|
4134
4198
|
}
|
|
4135
4199
|
}
|
|
4136
|
-
function readPluginManifest(
|
|
4137
|
-
const manifestPath = path13.join(
|
|
4200
|
+
function readPluginManifest(pluginPath) {
|
|
4201
|
+
const manifestPath = path13.join(pluginPath, "package.json");
|
|
4138
4202
|
if (!fs16.existsSync(manifestPath)) {
|
|
4139
4203
|
throw new Error(`Plugin manifest not found: ${manifestPath}`);
|
|
4140
4204
|
}
|
|
@@ -4146,8 +4210,8 @@ function readPluginManifest(pluginPath2) {
|
|
|
4146
4210
|
}
|
|
4147
4211
|
return manifest;
|
|
4148
4212
|
}
|
|
4149
|
-
function assertPluginIdentity(
|
|
4150
|
-
const manifest = readPluginManifest(
|
|
4213
|
+
function assertPluginIdentity(pluginPath, expectedName, expectedVersion) {
|
|
4214
|
+
const manifest = readPluginManifest(pluginPath);
|
|
4151
4215
|
if (manifest.name !== expectedName || manifest.version !== expectedVersion) {
|
|
4152
4216
|
throw new Error(
|
|
4153
4217
|
`Plugin identity mismatch: expected ${expectedName}@${expectedVersion}, got ${manifest.name}@${manifest.version}`
|
|
@@ -4155,16 +4219,10 @@ function assertPluginIdentity(pluginPath2, expectedName, expectedVersion) {
|
|
|
4155
4219
|
}
|
|
4156
4220
|
return manifest;
|
|
4157
4221
|
}
|
|
4158
|
-
function findMissingPeerDependencies(projectRoot, peerDependencies) {
|
|
4159
|
-
if (!peerDependencies) return [];
|
|
4160
|
-
return Object.keys(peerDependencies).filter(
|
|
4161
|
-
(dependency) => !fs16.existsSync(path13.join(projectRoot, "node_modules", dependency))
|
|
4162
|
-
);
|
|
4163
|
-
}
|
|
4164
4222
|
|
|
4165
4223
|
// src/commands/action-plugin/plugin-preparation.ts
|
|
4166
|
-
import
|
|
4167
|
-
import
|
|
4224
|
+
import fs19 from "fs";
|
|
4225
|
+
import path16 from "path";
|
|
4168
4226
|
|
|
4169
4227
|
// src/commands/action-plugin/api-client.ts
|
|
4170
4228
|
import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
|
|
@@ -4291,8 +4349,6 @@ async function downloadPlugin(pluginKey, requestedVersion) {
|
|
|
4291
4349
|
pluginInfo
|
|
4292
4350
|
};
|
|
4293
4351
|
}
|
|
4294
|
-
function cleanupTempFile(tgzPath) {
|
|
4295
|
-
}
|
|
4296
4352
|
function getCachePath(pluginKey, version) {
|
|
4297
4353
|
ensureCacheDir();
|
|
4298
4354
|
const safeKey = pluginKey.replace(/[/@]/g, "_");
|
|
@@ -4367,18 +4423,301 @@ function cleanPluginCache(pluginKey, version) {
|
|
|
4367
4423
|
return count;
|
|
4368
4424
|
}
|
|
4369
4425
|
|
|
4426
|
+
// src/commands/action-plugin/graph-state.ts
|
|
4427
|
+
import fs18 from "fs";
|
|
4428
|
+
import path15 from "path";
|
|
4429
|
+
import { createRequire as createRequire2 } from "module";
|
|
4430
|
+
var ACTION_PLUGIN_STORE = ".action-plugins";
|
|
4431
|
+
var ACTION_PLUGIN_GITIGNORE_ENTRY = `${ACTION_PLUGIN_STORE}/`;
|
|
4432
|
+
function validatePluginName(name) {
|
|
4433
|
+
if (!/^@[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*$/i.test(name)) {
|
|
4434
|
+
throw new Error(`Invalid scoped plugin name: ${name}`);
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
function resolveProjectRoot(projectRoot) {
|
|
4438
|
+
const resolved = fs18.realpathSync(projectRoot);
|
|
4439
|
+
if (!fs18.statSync(resolved).isDirectory()) {
|
|
4440
|
+
throw new Error(`Project root is not a directory: ${projectRoot}`);
|
|
4441
|
+
}
|
|
4442
|
+
return resolved;
|
|
4443
|
+
}
|
|
4444
|
+
function isWithin(root, candidate) {
|
|
4445
|
+
const relative = path15.relative(root, candidate);
|
|
4446
|
+
return relative === "" || !relative.startsWith(`..${path15.sep}`) && relative !== ".." && !path15.isAbsolute(relative);
|
|
4447
|
+
}
|
|
4448
|
+
function assertProjectPath(projectRoot, targetPath) {
|
|
4449
|
+
const root = resolveProjectRoot(projectRoot);
|
|
4450
|
+
const resolvedTarget = path15.resolve(targetPath);
|
|
4451
|
+
if (!isWithin(root, resolvedTarget)) {
|
|
4452
|
+
throw new Error(`Action plugin path escapes project root: ${targetPath}`);
|
|
4453
|
+
}
|
|
4454
|
+
let existing = resolvedTarget;
|
|
4455
|
+
const targetStats = lstatOrNull(existing);
|
|
4456
|
+
if (targetStats?.isSymbolicLink()) {
|
|
4457
|
+
existing = path15.resolve(path15.dirname(existing), fs18.readlinkSync(existing));
|
|
4458
|
+
if (!isWithin(root, existing)) {
|
|
4459
|
+
throw new Error(`Action plugin link escapes project root: ${targetPath}`);
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4462
|
+
while (!lstatOrNull(existing)) {
|
|
4463
|
+
const parent = path15.dirname(existing);
|
|
4464
|
+
if (parent === existing) break;
|
|
4465
|
+
existing = parent;
|
|
4466
|
+
}
|
|
4467
|
+
const realExisting = fs18.realpathSync(existing);
|
|
4468
|
+
if (!isWithin(root, realExisting)) {
|
|
4469
|
+
throw new Error(
|
|
4470
|
+
`Action plugin path resolves outside project root: ${targetPath}`
|
|
4471
|
+
);
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4474
|
+
function lstatOrNull(targetPath) {
|
|
4475
|
+
try {
|
|
4476
|
+
return fs18.lstatSync(targetPath);
|
|
4477
|
+
} catch (error) {
|
|
4478
|
+
if (error.code === "ENOENT") return null;
|
|
4479
|
+
throw error;
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
function managedRootPath(projectRoot) {
|
|
4483
|
+
return path15.join(projectRoot, ACTION_PLUGIN_STORE);
|
|
4484
|
+
}
|
|
4485
|
+
function managedPluginPath(projectRoot, pluginName) {
|
|
4486
|
+
validatePluginName(pluginName);
|
|
4487
|
+
const result = path15.join(
|
|
4488
|
+
managedRootPath(projectRoot),
|
|
4489
|
+
"node_modules",
|
|
4490
|
+
pluginName
|
|
4491
|
+
);
|
|
4492
|
+
assertProjectPath(projectRoot, result);
|
|
4493
|
+
return result;
|
|
4494
|
+
}
|
|
4495
|
+
function nodePluginPath(projectRoot, pluginName) {
|
|
4496
|
+
validatePluginName(pluginName);
|
|
4497
|
+
const result = path15.join(projectRoot, "node_modules", pluginName);
|
|
4498
|
+
assertProjectPath(projectRoot, result);
|
|
4499
|
+
return result;
|
|
4500
|
+
}
|
|
4501
|
+
function localDependencySpec(pluginName) {
|
|
4502
|
+
validatePluginName(pluginName);
|
|
4503
|
+
return `file:${ACTION_PLUGIN_STORE}/node_modules/${pluginName}`;
|
|
4504
|
+
}
|
|
4505
|
+
function sourceLockKey(pluginName) {
|
|
4506
|
+
validatePluginName(pluginName);
|
|
4507
|
+
return `${ACTION_PLUGIN_STORE}/node_modules/${pluginName}`;
|
|
4508
|
+
}
|
|
4509
|
+
function nodeLockKey(pluginName) {
|
|
4510
|
+
validatePluginName(pluginName);
|
|
4511
|
+
return `node_modules/${pluginName}`;
|
|
4512
|
+
}
|
|
4513
|
+
function assertManagedRoot(projectRoot) {
|
|
4514
|
+
const root = managedRootPath(projectRoot);
|
|
4515
|
+
assertProjectPath(projectRoot, root);
|
|
4516
|
+
const stats = lstatOrNull(root);
|
|
4517
|
+
if (stats?.isSymbolicLink()) {
|
|
4518
|
+
throw new Error(`${ACTION_PLUGIN_STORE} must not be a symbolic link`);
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
function assertPluginDependencyOwnership(pkg2, pluginName) {
|
|
4522
|
+
const expected = localDependencySpec(pluginName);
|
|
4523
|
+
const dependency = pkg2.dependencies?.[pluginName];
|
|
4524
|
+
if (dependency !== void 0 && dependency !== expected) {
|
|
4525
|
+
throw new Error(
|
|
4526
|
+
`Dependency ${pluginName} is not managed by action-plugin (expected ${expected}, got ${dependency})`
|
|
4527
|
+
);
|
|
4528
|
+
}
|
|
4529
|
+
for (const section of ["devDependencies", "optionalDependencies"]) {
|
|
4530
|
+
const value = pkg2[section]?.[pluginName];
|
|
4531
|
+
if (value !== void 0) {
|
|
4532
|
+
throw new Error(
|
|
4533
|
+
`Dependency ${pluginName} is declared in ${section} and is not managed by action-plugin`
|
|
4534
|
+
);
|
|
4535
|
+
}
|
|
4536
|
+
}
|
|
4537
|
+
}
|
|
4538
|
+
function assertManagedSourcePath(projectRoot, pluginName) {
|
|
4539
|
+
assertManagedRoot(projectRoot);
|
|
4540
|
+
const source = managedPluginPath(projectRoot, pluginName);
|
|
4541
|
+
const stats = lstatOrNull(source);
|
|
4542
|
+
if (!stats) return;
|
|
4543
|
+
if (stats.isSymbolicLink() || !stats.isDirectory()) {
|
|
4544
|
+
throw new Error(
|
|
4545
|
+
`Managed plugin source must be a real directory: ${source}`
|
|
4546
|
+
);
|
|
4547
|
+
}
|
|
4548
|
+
const realSource = fs18.realpathSync(source);
|
|
4549
|
+
if (realSource !== source) {
|
|
4550
|
+
throw new Error(`Managed plugin source resolves unexpectedly: ${source}`);
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
function ensureActionPluginGitignore(projectRoot) {
|
|
4554
|
+
const gitignorePath = path15.join(projectRoot, ".gitignore");
|
|
4555
|
+
assertProjectPath(projectRoot, gitignorePath);
|
|
4556
|
+
const original = fs18.existsSync(gitignorePath) ? fs18.readFileSync(gitignorePath, "utf-8") : "";
|
|
4557
|
+
const hadTrailingNewline = original.endsWith("\n");
|
|
4558
|
+
const lines = original.split(/\r?\n/).filter((line, index, all) => {
|
|
4559
|
+
if (index === all.length - 1 && line === "") return false;
|
|
4560
|
+
return line !== ACTION_PLUGIN_GITIGNORE_ENTRY;
|
|
4561
|
+
});
|
|
4562
|
+
lines.push(ACTION_PLUGIN_GITIGNORE_ENTRY);
|
|
4563
|
+
const next = `${lines.join("\n")}
|
|
4564
|
+
`;
|
|
4565
|
+
if (original !== next || !hadTrailingNewline)
|
|
4566
|
+
atomicWriteFile(gitignorePath, next);
|
|
4567
|
+
}
|
|
4568
|
+
function removeActionPluginGitignore(projectRoot) {
|
|
4569
|
+
const gitignorePath = path15.join(projectRoot, ".gitignore");
|
|
4570
|
+
if (!fs18.existsSync(gitignorePath)) return;
|
|
4571
|
+
const original = fs18.readFileSync(gitignorePath, "utf-8");
|
|
4572
|
+
const lines = original.split(/\r?\n/);
|
|
4573
|
+
const filtered = lines.filter((line) => line !== ACTION_PLUGIN_GITIGNORE_ENTRY);
|
|
4574
|
+
if (filtered.length === lines.length) return;
|
|
4575
|
+
let next = filtered.join("\n");
|
|
4576
|
+
if (next && !next.endsWith("\n")) next += "\n";
|
|
4577
|
+
if (next === "") fs18.rmSync(gitignorePath, { force: true });
|
|
4578
|
+
else atomicWriteFile(gitignorePath, next);
|
|
4579
|
+
}
|
|
4580
|
+
function requiredPeerDependencies(manifest) {
|
|
4581
|
+
const required = {};
|
|
4582
|
+
for (const [name, range] of Object.entries(manifest.peerDependencies ?? {})) {
|
|
4583
|
+
if (!manifest.peerDependenciesMeta?.[name]?.optional)
|
|
4584
|
+
required[name] = range;
|
|
4585
|
+
}
|
|
4586
|
+
return required;
|
|
4587
|
+
}
|
|
4588
|
+
function findLockfilePath(projectRoot) {
|
|
4589
|
+
const shrinkwrap = path15.join(projectRoot, "npm-shrinkwrap.json");
|
|
4590
|
+
return fs18.existsSync(shrinkwrap) ? shrinkwrap : path15.join(projectRoot, "package-lock.json");
|
|
4591
|
+
}
|
|
4592
|
+
function readLockDocument(projectRoot) {
|
|
4593
|
+
const lockPath = findLockfilePath(projectRoot);
|
|
4594
|
+
if (!fs18.existsSync(lockPath)) {
|
|
4595
|
+
throw new Error("npm did not produce a package lock");
|
|
4596
|
+
}
|
|
4597
|
+
const lock = JSON.parse(fs18.readFileSync(lockPath, "utf-8"));
|
|
4598
|
+
if (lock.lockfileVersion !== 3 || !lock.packages) {
|
|
4599
|
+
throw new Error("Action plugins require an npm lockfile v3 graph");
|
|
4600
|
+
}
|
|
4601
|
+
return { lockPath, lock };
|
|
4602
|
+
}
|
|
4603
|
+
function verifyPluginGraph(projectRoot, pluginName, version) {
|
|
4604
|
+
const packagePath = path15.join(projectRoot, "package.json");
|
|
4605
|
+
const pkg2 = JSON.parse(
|
|
4606
|
+
fs18.readFileSync(packagePath, "utf-8")
|
|
4607
|
+
);
|
|
4608
|
+
const expectedSpec = localDependencySpec(pluginName);
|
|
4609
|
+
if (pkg2.actionPlugins?.[pluginName] !== version) {
|
|
4610
|
+
throw new Error(
|
|
4611
|
+
`Desired plugin identity is inconsistent for ${pluginName}`
|
|
4612
|
+
);
|
|
4613
|
+
}
|
|
4614
|
+
if (pkg2.dependencies?.[pluginName] !== expectedSpec) {
|
|
4615
|
+
throw new Error(`Managed dependency is inconsistent for ${pluginName}`);
|
|
4616
|
+
}
|
|
4617
|
+
assertManagedSourcePath(projectRoot, pluginName);
|
|
4618
|
+
const sourcePath = managedPluginPath(projectRoot, pluginName);
|
|
4619
|
+
const manifest = assertPluginIdentity(sourcePath, pluginName, version);
|
|
4620
|
+
const { lock } = readLockDocument(projectRoot);
|
|
4621
|
+
const packages = lock.packages;
|
|
4622
|
+
const rootDependencies = packages[""]?.dependencies;
|
|
4623
|
+
if (rootDependencies?.[pluginName] !== expectedSpec) {
|
|
4624
|
+
throw new Error(`Lock root is inconsistent for ${pluginName}`);
|
|
4625
|
+
}
|
|
4626
|
+
const sourceEntry = packages[sourceLockKey(pluginName)];
|
|
4627
|
+
if (!sourceEntry || sourceEntry.version !== version) {
|
|
4628
|
+
throw new Error(`Lock source is inconsistent for ${pluginName}`);
|
|
4629
|
+
}
|
|
4630
|
+
if (sourceEntry.name !== void 0 && sourceEntry.name !== pluginName) {
|
|
4631
|
+
throw new Error(`Lock source identity is inconsistent for ${pluginName}`);
|
|
4632
|
+
}
|
|
4633
|
+
const linkEntry = packages[nodeLockKey(pluginName)];
|
|
4634
|
+
if (!linkEntry || linkEntry.link !== true || linkEntry.resolved !== sourceLockKey(pluginName)) {
|
|
4635
|
+
throw new Error(`Lock link is inconsistent for ${pluginName}`);
|
|
4636
|
+
}
|
|
4637
|
+
const nodePath = nodePluginPath(projectRoot, pluginName);
|
|
4638
|
+
const nodeStats = lstatOrNull(nodePath);
|
|
4639
|
+
if (!nodeStats?.isSymbolicLink()) {
|
|
4640
|
+
throw new Error(`npm link is missing for ${pluginName}`);
|
|
4641
|
+
}
|
|
4642
|
+
const realNodePath = fs18.realpathSync(nodePath);
|
|
4643
|
+
if (realNodePath !== sourcePath) {
|
|
4644
|
+
throw new Error(`npm link escapes managed source for ${pluginName}`);
|
|
4645
|
+
}
|
|
4646
|
+
assertPluginIdentity(nodePath, pluginName, version);
|
|
4647
|
+
const resolvedEntry = createRequire2(packagePath).resolve(pluginName);
|
|
4648
|
+
const realResolvedEntry = fs18.realpathSync(resolvedEntry);
|
|
4649
|
+
if (!isWithin(sourcePath, realResolvedEntry)) {
|
|
4650
|
+
throw new Error(
|
|
4651
|
+
`Runtime resolution escapes managed source for ${pluginName}`
|
|
4652
|
+
);
|
|
4653
|
+
}
|
|
4654
|
+
const missingPeers = Object.keys(requiredPeerDependencies(manifest)).filter(
|
|
4655
|
+
(peer) => !lstatOrNull(path15.join(projectRoot, "node_modules", peer))
|
|
4656
|
+
);
|
|
4657
|
+
if (missingPeers.length > 0) {
|
|
4658
|
+
throw new Error(`Missing peer dependencies: ${missingPeers.join(", ")}`);
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
function assertNoInstallLifecycle(projectRoot, dependencyNames) {
|
|
4662
|
+
for (const dependency of dependencyNames) {
|
|
4663
|
+
const manifestPath = path15.join(
|
|
4664
|
+
projectRoot,
|
|
4665
|
+
"node_modules",
|
|
4666
|
+
dependency,
|
|
4667
|
+
"package.json"
|
|
4668
|
+
);
|
|
4669
|
+
if (!fs18.existsSync(manifestPath)) continue;
|
|
4670
|
+
const manifest = JSON.parse(fs18.readFileSync(manifestPath, "utf-8"));
|
|
4671
|
+
const lifecycle = ["preinstall", "install", "postinstall"].find(
|
|
4672
|
+
(script) => Boolean(manifest.scripts?.[script]?.trim())
|
|
4673
|
+
);
|
|
4674
|
+
if (lifecycle) {
|
|
4675
|
+
throw new Error(
|
|
4676
|
+
`Dependency ${dependency} requires ${lifecycle}; install it with the normal package manager before retrying action-plugin`
|
|
4677
|
+
);
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
function removePluginLockEntries(projectRoot, pluginName) {
|
|
4682
|
+
const lockPath = findLockfilePath(projectRoot);
|
|
4683
|
+
if (!fs18.existsSync(lockPath)) return;
|
|
4684
|
+
const lock = JSON.parse(fs18.readFileSync(lockPath, "utf-8"));
|
|
4685
|
+
if (lock.lockfileVersion !== 3 || !lock.packages) {
|
|
4686
|
+
throw new Error(
|
|
4687
|
+
"Cannot safely remove action plugin from a non-v3 npm lockfile"
|
|
4688
|
+
);
|
|
4689
|
+
}
|
|
4690
|
+
const rootDependencies = lock.packages[""]?.dependencies;
|
|
4691
|
+
if (rootDependencies) delete rootDependencies[pluginName];
|
|
4692
|
+
delete lock.packages[sourceLockKey(pluginName)];
|
|
4693
|
+
delete lock.packages[nodeLockKey(pluginName)];
|
|
4694
|
+
if (lock.dependencies) delete lock.dependencies[pluginName];
|
|
4695
|
+
atomicWriteJson(lockPath, lock);
|
|
4696
|
+
}
|
|
4697
|
+
function removePathAndEmptyParents(targetPath, stopAt) {
|
|
4698
|
+
const stats = lstatOrNull(targetPath);
|
|
4699
|
+
if (stats?.isDirectory() && !stats.isSymbolicLink()) {
|
|
4700
|
+
fs18.rmSync(targetPath, { recursive: true, force: true });
|
|
4701
|
+
} else if (stats) {
|
|
4702
|
+
fs18.unlinkSync(targetPath);
|
|
4703
|
+
}
|
|
4704
|
+
let current = path15.dirname(targetPath);
|
|
4705
|
+
while (current !== stopAt && isWithin(stopAt, current)) {
|
|
4706
|
+
if (!fs18.existsSync(current) || fs18.readdirSync(current).length > 0) break;
|
|
4707
|
+
fs18.rmdirSync(current);
|
|
4708
|
+
current = path15.dirname(current);
|
|
4709
|
+
}
|
|
4710
|
+
}
|
|
4711
|
+
|
|
4370
4712
|
// src/commands/action-plugin/plugin-preparation.ts
|
|
4371
4713
|
function readPackageDocument(packageJsonPath) {
|
|
4372
4714
|
return JSON.parse(
|
|
4373
|
-
|
|
4715
|
+
fs19.readFileSync(packageJsonPath, "utf-8")
|
|
4374
4716
|
);
|
|
4375
4717
|
}
|
|
4376
|
-
function pluginPath(projectRoot, pluginName) {
|
|
4377
|
-
return path15.join(projectRoot, "node_modules", pluginName);
|
|
4378
|
-
}
|
|
4379
4718
|
function rootDeclaresDependency(pkg2, dependency) {
|
|
4380
4719
|
return Boolean(
|
|
4381
|
-
pkg2.dependencies?.[dependency] || pkg2.devDependencies?.[dependency]
|
|
4720
|
+
pkg2.dependencies?.[dependency] || pkg2.devDependencies?.[dependency] || pkg2.optionalDependencies?.[dependency]
|
|
4382
4721
|
);
|
|
4383
4722
|
}
|
|
4384
4723
|
async function defaultMaterializePlugin(name, version, destination) {
|
|
@@ -4397,55 +4736,103 @@ async function defaultMaterializePlugin(name, version, destination) {
|
|
|
4397
4736
|
tgzPath = downloaded.tgzPath;
|
|
4398
4737
|
source = "download";
|
|
4399
4738
|
}
|
|
4400
|
-
|
|
4739
|
+
fs19.mkdirSync(path16.dirname(destination), { recursive: true });
|
|
4401
4740
|
extractTgzToDirectory(tgzPath, destination);
|
|
4402
4741
|
return source;
|
|
4403
4742
|
}
|
|
4404
|
-
function
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4743
|
+
function copyLegacyPlugin(source, destination) {
|
|
4744
|
+
fs19.mkdirSync(path16.dirname(destination), { recursive: true });
|
|
4745
|
+
fs19.cpSync(source, destination, {
|
|
4746
|
+
recursive: true,
|
|
4747
|
+
force: true,
|
|
4748
|
+
verbatimSymlinks: true
|
|
4749
|
+
});
|
|
4750
|
+
}
|
|
4751
|
+
function readManagedManifest(projectRoot, pluginName) {
|
|
4752
|
+
assertManagedSourcePath(projectRoot, pluginName);
|
|
4753
|
+
const sourcePath = managedPluginPath(projectRoot, pluginName);
|
|
4754
|
+
if (!lstatOrNull(sourcePath)) return null;
|
|
4755
|
+
const manifest = readPluginManifest(sourcePath);
|
|
4756
|
+
if (manifest.name !== pluginName) {
|
|
4757
|
+
throw new Error(
|
|
4758
|
+
`Plugin identity mismatch: expected ${pluginName}, got ${manifest.name}`
|
|
4411
4759
|
);
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
} catch {
|
|
4760
|
+
}
|
|
4761
|
+
return manifest;
|
|
4762
|
+
}
|
|
4763
|
+
function findLegacyPlugin(projectRoot, pluginName, version, initialPackage) {
|
|
4764
|
+
if (initialPackage.dependencies?.[pluginName] === localDependencySpec(pluginName)) {
|
|
4418
4765
|
return null;
|
|
4419
4766
|
}
|
|
4767
|
+
const legacyPath = nodePluginPath(projectRoot, pluginName);
|
|
4768
|
+
const stats = lstatOrNull(legacyPath);
|
|
4769
|
+
if (!stats || stats.isSymbolicLink() || !stats.isDirectory()) return null;
|
|
4770
|
+
const manifest = readPluginManifest(legacyPath);
|
|
4771
|
+
if (manifest.name !== pluginName) {
|
|
4772
|
+
throw new Error(
|
|
4773
|
+
`Plugin identity mismatch: expected ${pluginName}, got ${manifest.name}`
|
|
4774
|
+
);
|
|
4775
|
+
}
|
|
4776
|
+
const desiredVersion = initialPackage.actionPlugins?.[pluginName];
|
|
4777
|
+
if (manifest.version !== version && manifest.version !== desiredVersion) {
|
|
4778
|
+
throw new Error(
|
|
4779
|
+
`Plugin identity mismatch: expected ${pluginName}@${desiredVersion ?? version}, got ${manifest.name}@${manifest.version}`
|
|
4780
|
+
);
|
|
4781
|
+
}
|
|
4782
|
+
return manifest.version === version ? legacyPath : null;
|
|
4420
4783
|
}
|
|
4421
4784
|
async function preparePlugin(request, index, initialPackage, projectRoot, stagingRoot, options) {
|
|
4422
|
-
|
|
4785
|
+
validatePluginName(request.name);
|
|
4786
|
+
assertPluginDependencyOwnership(initialPackage, request.name);
|
|
4423
4787
|
const version = request.requestedVersion === "latest" ? await (options.resolveLatestVersion ?? (async (name) => (await getPluginVersion(name, "latest")).version))(request.name) : request.requestedVersion;
|
|
4788
|
+
if (!version || version === "latest") {
|
|
4789
|
+
throw new Error(
|
|
4790
|
+
`Plugin version did not resolve to an exact value: ${request.name}`
|
|
4791
|
+
);
|
|
4792
|
+
}
|
|
4424
4793
|
let manifest;
|
|
4425
4794
|
let stagedPath = null;
|
|
4426
|
-
let source
|
|
4427
|
-
|
|
4795
|
+
let source;
|
|
4796
|
+
const managedManifest = readManagedManifest(projectRoot, request.name);
|
|
4797
|
+
const desiredVersion = initialPackage.actionPlugins?.[request.name];
|
|
4798
|
+
if (managedManifest && managedManifest.version !== version && managedManifest.version !== desiredVersion) {
|
|
4799
|
+
throw new Error(
|
|
4800
|
+
`Plugin identity mismatch: expected ${request.name}@${desiredVersion ?? version}, got ${managedManifest.name}@${managedManifest.version}`
|
|
4801
|
+
);
|
|
4802
|
+
}
|
|
4803
|
+
if (managedManifest?.version === version) {
|
|
4428
4804
|
manifest = assertPluginIdentity(
|
|
4429
|
-
|
|
4805
|
+
managedPluginPath(projectRoot, request.name),
|
|
4430
4806
|
request.name,
|
|
4431
4807
|
version
|
|
4432
4808
|
);
|
|
4809
|
+
source = "managed";
|
|
4433
4810
|
} else {
|
|
4434
|
-
|
|
4435
|
-
|
|
4811
|
+
const legacyPath = findLegacyPlugin(
|
|
4812
|
+
projectRoot,
|
|
4436
4813
|
request.name,
|
|
4437
4814
|
version,
|
|
4438
|
-
|
|
4815
|
+
initialPackage
|
|
4439
4816
|
);
|
|
4817
|
+
stagedPath = path16.join(stagingRoot, "prepared", String(index));
|
|
4818
|
+
if (legacyPath) {
|
|
4819
|
+
copyLegacyPlugin(legacyPath, stagedPath);
|
|
4820
|
+
source = "legacy";
|
|
4821
|
+
} else {
|
|
4822
|
+
source = await (options.materializePlugin ?? defaultMaterializePlugin)(
|
|
4823
|
+
request.name,
|
|
4824
|
+
version,
|
|
4825
|
+
stagedPath
|
|
4826
|
+
);
|
|
4827
|
+
}
|
|
4440
4828
|
manifest = assertPluginIdentity(stagedPath, request.name, version);
|
|
4441
4829
|
}
|
|
4442
4830
|
const missingUndeclaredPeers = {};
|
|
4443
|
-
for (const dependency of
|
|
4444
|
-
|
|
4445
|
-
manifest.peerDependencies
|
|
4831
|
+
for (const [dependency, range] of Object.entries(
|
|
4832
|
+
requiredPeerDependencies(manifest)
|
|
4446
4833
|
)) {
|
|
4447
|
-
if (!rootDeclaresDependency(initialPackage, dependency)) {
|
|
4448
|
-
missingUndeclaredPeers[dependency] =
|
|
4834
|
+
if (!lstatOrNull(path16.join(projectRoot, "node_modules", dependency)) && !rootDeclaresDependency(initialPackage, dependency)) {
|
|
4835
|
+
missingUndeclaredPeers[dependency] = range;
|
|
4449
4836
|
}
|
|
4450
4837
|
}
|
|
4451
4838
|
return {
|
|
@@ -4454,7 +4841,8 @@ async function preparePlugin(request, index, initialPackage, projectRoot, stagin
|
|
|
4454
4841
|
manifest,
|
|
4455
4842
|
stagedPath,
|
|
4456
4843
|
missingUndeclaredPeers,
|
|
4457
|
-
source
|
|
4844
|
+
source,
|
|
4845
|
+
wasDesired: initialPackage.actionPlugins?.[request.name] === version
|
|
4458
4846
|
};
|
|
4459
4847
|
}
|
|
4460
4848
|
function findPeerRangeConflict(prepared) {
|
|
@@ -4484,132 +4872,274 @@ function collectPeerRanges(prepared) {
|
|
|
4484
4872
|
return peers;
|
|
4485
4873
|
}
|
|
4486
4874
|
|
|
4487
|
-
// src/commands/action-plugin/
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
const key = queue.shift();
|
|
4505
|
-
if (closure.has(key)) continue;
|
|
4506
|
-
closure.add(key);
|
|
4507
|
-
const entry = packages[key];
|
|
4508
|
-
const dependencies = {
|
|
4509
|
-
...entry.dependencies ?? {},
|
|
4510
|
-
...entry.optionalDependencies ?? {}
|
|
4511
|
-
};
|
|
4512
|
-
for (const dependency of Object.keys(dependencies)) {
|
|
4513
|
-
const resolved = resolveLockedDependency(packages, key, dependency);
|
|
4514
|
-
if (resolved && !closure.has(resolved)) queue.push(resolved);
|
|
4515
|
-
}
|
|
4875
|
+
// src/commands/action-plugin/transaction-journal.ts
|
|
4876
|
+
import fs20 from "fs";
|
|
4877
|
+
import path17 from "path";
|
|
4878
|
+
import { randomUUID } from "crypto";
|
|
4879
|
+
var JOURNAL_FILE = ".transaction-journal.json";
|
|
4880
|
+
var TRANSACTION_DIRECTORY = ".transactions";
|
|
4881
|
+
function journalPath(projectRoot) {
|
|
4882
|
+
return path17.join(managedRootPath(projectRoot), JOURNAL_FILE);
|
|
4883
|
+
}
|
|
4884
|
+
function isTransactionId(value) {
|
|
4885
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
|
|
4886
|
+
value
|
|
4887
|
+
);
|
|
4888
|
+
}
|
|
4889
|
+
function transactionRoot(projectRoot, transactionId) {
|
|
4890
|
+
if (!isTransactionId(transactionId)) {
|
|
4891
|
+
throw new Error("Action-plugin transaction id is invalid");
|
|
4516
4892
|
}
|
|
4517
|
-
|
|
4893
|
+
const result = path17.join(
|
|
4894
|
+
managedRootPath(projectRoot),
|
|
4895
|
+
TRANSACTION_DIRECTORY,
|
|
4896
|
+
transactionId
|
|
4897
|
+
);
|
|
4898
|
+
assertProjectPath(projectRoot, result);
|
|
4899
|
+
return result;
|
|
4518
4900
|
}
|
|
4519
|
-
function
|
|
4520
|
-
|
|
4901
|
+
function snapshotFile(projectRoot, relativePath) {
|
|
4902
|
+
const filePath = path17.join(projectRoot, relativePath);
|
|
4903
|
+
assertProjectPath(projectRoot, filePath);
|
|
4904
|
+
const stats = lstatOrNull(filePath);
|
|
4905
|
+
if (!stats) return { relativePath, content: null, mode: null };
|
|
4906
|
+
if (!stats.isFile()) throw new Error(`Expected a regular file: ${filePath}`);
|
|
4907
|
+
return {
|
|
4908
|
+
relativePath,
|
|
4909
|
+
content: fs20.readFileSync(filePath).toString("base64"),
|
|
4910
|
+
mode: stats.mode
|
|
4911
|
+
};
|
|
4521
4912
|
}
|
|
4522
|
-
function
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4913
|
+
function snapshotEntry(projectRoot, transactionId, name, location, index) {
|
|
4914
|
+
const targetPath = location === "source" ? managedPluginPath(projectRoot, name) : nodePluginPath(projectRoot, name);
|
|
4915
|
+
const stats = lstatOrNull(targetPath);
|
|
4916
|
+
if (!stats) {
|
|
4917
|
+
return {
|
|
4918
|
+
name,
|
|
4919
|
+
location,
|
|
4920
|
+
kind: "missing",
|
|
4921
|
+
backupRelativePath: null,
|
|
4922
|
+
linkTarget: null
|
|
4923
|
+
};
|
|
4528
4924
|
}
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
const closure = collectLockClosure(npmPackages, committedPeerNames);
|
|
4537
|
-
for (const key of closure)
|
|
4538
|
-
result2.packages[key] = cloneJson(npmPackages[key]);
|
|
4539
|
-
const npmRoot = npmPackages[""] ?? {};
|
|
4540
|
-
const resultRoot = (_a = result2.packages)[""] ?? (_a[""] = {});
|
|
4541
|
-
const npmRootDependencies = npmRoot.dependencies ?? {};
|
|
4542
|
-
const resultRootDependencies = {
|
|
4543
|
-
...resultRoot.dependencies ?? {}
|
|
4925
|
+
if (stats.isSymbolicLink()) {
|
|
4926
|
+
return {
|
|
4927
|
+
name,
|
|
4928
|
+
location,
|
|
4929
|
+
kind: "symlink",
|
|
4930
|
+
backupRelativePath: null,
|
|
4931
|
+
linkTarget: fs20.readlinkSync(targetPath)
|
|
4544
4932
|
};
|
|
4545
|
-
for (const peer of committedPeerNames) {
|
|
4546
|
-
if (npmRootDependencies[peer])
|
|
4547
|
-
resultRootDependencies[peer] = npmRootDependencies[peer];
|
|
4548
|
-
}
|
|
4549
|
-
if (Object.keys(resultRootDependencies).length > 0) {
|
|
4550
|
-
resultRoot.dependencies = resultRootDependencies;
|
|
4551
|
-
}
|
|
4552
|
-
if (npmLock.dependencies) {
|
|
4553
|
-
result2.dependencies ?? (result2.dependencies = {});
|
|
4554
|
-
for (const peer of committedPeerNames) {
|
|
4555
|
-
if (npmLock.dependencies[peer]) {
|
|
4556
|
-
result2.dependencies[peer] = cloneJson(npmLock.dependencies[peer]);
|
|
4557
|
-
}
|
|
4558
|
-
}
|
|
4559
|
-
}
|
|
4560
|
-
return Buffer.from(`${JSON.stringify(result2, null, 2)}
|
|
4561
|
-
`);
|
|
4562
4933
|
}
|
|
4563
|
-
const
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
...Object.keys(initialPackage.optionalDependencies ?? {})
|
|
4569
|
-
]);
|
|
4570
|
-
const retainedClosure = collectLockClosure(npmPackages, [
|
|
4571
|
-
...initialRoots,
|
|
4572
|
-
...committedPeerNames
|
|
4573
|
-
]);
|
|
4574
|
-
const uncommittedClosure = collectLockClosure(
|
|
4575
|
-
npmPackages,
|
|
4576
|
-
[...allPeerNames].filter((name) => !committedPeerNames.has(name))
|
|
4934
|
+
const relativeBackup = path17.join(
|
|
4935
|
+
TRANSACTION_DIRECTORY,
|
|
4936
|
+
transactionId,
|
|
4937
|
+
"entries",
|
|
4938
|
+
String(index)
|
|
4577
4939
|
);
|
|
4578
|
-
|
|
4579
|
-
|
|
4940
|
+
const backupPath = path17.join(managedRootPath(projectRoot), relativeBackup);
|
|
4941
|
+
assertProjectPath(projectRoot, backupPath);
|
|
4942
|
+
fs20.mkdirSync(path17.dirname(backupPath), { recursive: true });
|
|
4943
|
+
if (stats.isDirectory()) {
|
|
4944
|
+
fs20.cpSync(targetPath, backupPath, {
|
|
4945
|
+
recursive: true,
|
|
4946
|
+
force: true,
|
|
4947
|
+
verbatimSymlinks: true
|
|
4948
|
+
});
|
|
4949
|
+
return {
|
|
4950
|
+
name,
|
|
4951
|
+
location,
|
|
4952
|
+
kind: "directory",
|
|
4953
|
+
backupRelativePath: relativeBackup,
|
|
4954
|
+
linkTarget: null
|
|
4955
|
+
};
|
|
4580
4956
|
}
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
"
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
for (const peer of allPeerNames) {
|
|
4591
|
-
if (!committedPeerNames.has(peer) && !initialRoots.has(peer))
|
|
4592
|
-
delete values[peer];
|
|
4593
|
-
}
|
|
4594
|
-
}
|
|
4957
|
+
if (stats.isFile()) {
|
|
4958
|
+
fs20.copyFileSync(targetPath, backupPath);
|
|
4959
|
+
return {
|
|
4960
|
+
name,
|
|
4961
|
+
location,
|
|
4962
|
+
kind: "file",
|
|
4963
|
+
backupRelativePath: relativeBackup,
|
|
4964
|
+
linkTarget: null
|
|
4965
|
+
};
|
|
4595
4966
|
}
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4967
|
+
throw new Error(`Unsupported action plugin entry: ${targetPath}`);
|
|
4968
|
+
}
|
|
4969
|
+
function beginActionPluginTransaction(projectRootInput, pluginNames) {
|
|
4970
|
+
const projectRoot = resolveProjectRoot(projectRootInput);
|
|
4971
|
+
assertManagedRoot(projectRoot);
|
|
4972
|
+
if (lstatOrNull(journalPath(projectRoot))) {
|
|
4973
|
+
throw new Error("An action-plugin transaction journal already exists");
|
|
4974
|
+
}
|
|
4975
|
+
const managedRootExisted = Boolean(lstatOrNull(managedRootPath(projectRoot)));
|
|
4976
|
+
const transactionId = randomUUID();
|
|
4977
|
+
fs20.mkdirSync(transactionRoot(projectRoot, transactionId), {
|
|
4978
|
+
recursive: true
|
|
4979
|
+
});
|
|
4980
|
+
try {
|
|
4981
|
+
const names = [...new Set(pluginNames)];
|
|
4982
|
+
names.forEach(validatePluginName);
|
|
4983
|
+
const entries = [];
|
|
4984
|
+
let index = 0;
|
|
4985
|
+
for (const name of names) {
|
|
4986
|
+
entries.push(
|
|
4987
|
+
snapshotEntry(projectRoot, transactionId, name, "source", index++)
|
|
4988
|
+
);
|
|
4989
|
+
entries.push(
|
|
4990
|
+
snapshotEntry(projectRoot, transactionId, name, "node", index++)
|
|
4991
|
+
);
|
|
4992
|
+
}
|
|
4993
|
+
const journal = {
|
|
4994
|
+
schemaVersion: 1,
|
|
4995
|
+
transactionId,
|
|
4996
|
+
projectRoot,
|
|
4997
|
+
managedRootExisted,
|
|
4998
|
+
files: [
|
|
4999
|
+
snapshotFile(projectRoot, "package.json"),
|
|
5000
|
+
snapshotFile(projectRoot, "package-lock.json"),
|
|
5001
|
+
snapshotFile(projectRoot, "npm-shrinkwrap.json"),
|
|
5002
|
+
snapshotFile(projectRoot, ".gitignore")
|
|
5003
|
+
],
|
|
5004
|
+
entries
|
|
5005
|
+
};
|
|
5006
|
+
atomicWriteJson(journalPath(projectRoot), journal);
|
|
5007
|
+
return journal;
|
|
5008
|
+
} catch (error) {
|
|
5009
|
+
fs20.rmSync(transactionRoot(projectRoot, transactionId), {
|
|
5010
|
+
recursive: true,
|
|
5011
|
+
force: true
|
|
5012
|
+
});
|
|
5013
|
+
const transactionsPath = path17.join(
|
|
5014
|
+
managedRootPath(projectRoot),
|
|
5015
|
+
TRANSACTION_DIRECTORY
|
|
5016
|
+
);
|
|
5017
|
+
if (fs20.existsSync(transactionsPath) && fs20.readdirSync(transactionsPath).length === 0) {
|
|
5018
|
+
fs20.rmdirSync(transactionsPath);
|
|
4601
5019
|
}
|
|
5020
|
+
if (!managedRootExisted && fs20.existsSync(managedRootPath(projectRoot)) && fs20.readdirSync(managedRootPath(projectRoot)).length === 0) {
|
|
5021
|
+
fs20.rmdirSync(managedRootPath(projectRoot));
|
|
5022
|
+
}
|
|
5023
|
+
throw error;
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
5026
|
+
function restoreFile(projectRoot, snapshot) {
|
|
5027
|
+
const filePath = path17.join(projectRoot, snapshot.relativePath);
|
|
5028
|
+
assertProjectPath(projectRoot, filePath);
|
|
5029
|
+
if (snapshot.content === null) {
|
|
5030
|
+
if (lstatOrNull(filePath))
|
|
5031
|
+
fs20.rmSync(filePath, { recursive: true, force: true });
|
|
5032
|
+
return;
|
|
5033
|
+
}
|
|
5034
|
+
atomicWriteFile(filePath, Buffer.from(snapshot.content, "base64"));
|
|
5035
|
+
if (snapshot.mode !== null) fs20.chmodSync(filePath, snapshot.mode);
|
|
5036
|
+
}
|
|
5037
|
+
function removeEntry(targetPath) {
|
|
5038
|
+
const stats = lstatOrNull(targetPath);
|
|
5039
|
+
if (!stats) return;
|
|
5040
|
+
if (stats.isDirectory() && !stats.isSymbolicLink()) {
|
|
5041
|
+
fs20.rmSync(targetPath, { recursive: true, force: true });
|
|
5042
|
+
} else {
|
|
5043
|
+
fs20.unlinkSync(targetPath);
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
function restoreEntry(projectRoot, journal, snapshot) {
|
|
5047
|
+
validatePluginName(snapshot.name);
|
|
5048
|
+
const targetPath = snapshot.location === "source" ? managedPluginPath(projectRoot, snapshot.name) : nodePluginPath(projectRoot, snapshot.name);
|
|
5049
|
+
removeEntry(targetPath);
|
|
5050
|
+
if (snapshot.kind === "missing") return;
|
|
5051
|
+
fs20.mkdirSync(path17.dirname(targetPath), { recursive: true });
|
|
5052
|
+
if (snapshot.kind === "symlink") {
|
|
5053
|
+
if (snapshot.linkTarget === null)
|
|
5054
|
+
throw new Error("Journal symlink target is missing");
|
|
5055
|
+
fs20.symlinkSync(snapshot.linkTarget, targetPath);
|
|
5056
|
+
return;
|
|
5057
|
+
}
|
|
5058
|
+
if (snapshot.backupRelativePath === null) {
|
|
5059
|
+
throw new Error("Journal entry backup is missing");
|
|
5060
|
+
}
|
|
5061
|
+
const expectedPrefix = path17.join(
|
|
5062
|
+
TRANSACTION_DIRECTORY,
|
|
5063
|
+
journal.transactionId,
|
|
5064
|
+
"entries"
|
|
5065
|
+
);
|
|
5066
|
+
if (snapshot.backupRelativePath !== expectedPrefix && !snapshot.backupRelativePath.startsWith(`${expectedPrefix}${path17.sep}`)) {
|
|
5067
|
+
throw new Error("Journal entry backup path is invalid");
|
|
5068
|
+
}
|
|
5069
|
+
const backupPath = path17.join(
|
|
5070
|
+
managedRootPath(projectRoot),
|
|
5071
|
+
snapshot.backupRelativePath
|
|
5072
|
+
);
|
|
5073
|
+
assertProjectPath(projectRoot, backupPath);
|
|
5074
|
+
if (snapshot.kind === "directory") {
|
|
5075
|
+
fs20.cpSync(backupPath, targetPath, {
|
|
5076
|
+
recursive: true,
|
|
5077
|
+
force: true,
|
|
5078
|
+
verbatimSymlinks: true
|
|
5079
|
+
});
|
|
5080
|
+
} else {
|
|
5081
|
+
fs20.copyFileSync(backupPath, targetPath);
|
|
5082
|
+
}
|
|
5083
|
+
}
|
|
5084
|
+
function removeTransactionArtifacts(projectRoot, journal) {
|
|
5085
|
+
fs20.rmSync(journalPath(projectRoot), { force: true });
|
|
5086
|
+
fs20.rmSync(transactionRoot(projectRoot, journal.transactionId), {
|
|
5087
|
+
recursive: true,
|
|
5088
|
+
force: true
|
|
5089
|
+
});
|
|
5090
|
+
const transactionsPath = path17.join(
|
|
5091
|
+
managedRootPath(projectRoot),
|
|
5092
|
+
TRANSACTION_DIRECTORY
|
|
5093
|
+
);
|
|
5094
|
+
if (fs20.existsSync(transactionsPath) && fs20.readdirSync(transactionsPath).length === 0) {
|
|
5095
|
+
fs20.rmdirSync(transactionsPath);
|
|
5096
|
+
}
|
|
5097
|
+
if (!journal.managedRootExisted && fs20.existsSync(managedRootPath(projectRoot)) && fs20.readdirSync(managedRootPath(projectRoot)).length === 0) {
|
|
5098
|
+
fs20.rmdirSync(managedRootPath(projectRoot));
|
|
4602
5099
|
}
|
|
4603
|
-
|
|
4604
|
-
|
|
5100
|
+
}
|
|
5101
|
+
function rollbackActionPluginTransaction(journal) {
|
|
5102
|
+
const projectRoot = resolveProjectRoot(journal.projectRoot);
|
|
5103
|
+
if (journal.schemaVersion !== 1 || projectRoot !== journal.projectRoot || !isTransactionId(journal.transactionId)) {
|
|
5104
|
+
throw new Error("Action-plugin transaction journal is invalid");
|
|
5105
|
+
}
|
|
5106
|
+
for (const snapshot of journal.files) restoreFile(projectRoot, snapshot);
|
|
5107
|
+
for (const snapshot of journal.entries) {
|
|
5108
|
+
restoreEntry(projectRoot, journal, snapshot);
|
|
5109
|
+
}
|
|
5110
|
+
if (!journal.managedRootExisted) {
|
|
5111
|
+
fs20.rmSync(managedRootPath(projectRoot), { recursive: true, force: true });
|
|
5112
|
+
} else {
|
|
5113
|
+
removeTransactionArtifacts(projectRoot, journal);
|
|
5114
|
+
}
|
|
5115
|
+
}
|
|
5116
|
+
function commitActionPluginTransaction(journal) {
|
|
5117
|
+
const projectRoot = resolveProjectRoot(journal.projectRoot);
|
|
5118
|
+
removeTransactionArtifacts(projectRoot, journal);
|
|
5119
|
+
}
|
|
5120
|
+
function recoverInterruptedActionPluginTransaction(projectRootInput) {
|
|
5121
|
+
const projectRoot = resolveProjectRoot(projectRootInput);
|
|
5122
|
+
assertManagedRoot(projectRoot);
|
|
5123
|
+
const currentJournalPath = journalPath(projectRoot);
|
|
5124
|
+
if (!lstatOrNull(currentJournalPath)) return false;
|
|
5125
|
+
const journal = JSON.parse(
|
|
5126
|
+
fs20.readFileSync(currentJournalPath, "utf-8")
|
|
5127
|
+
);
|
|
5128
|
+
if (journal.schemaVersion !== 1 || journal.projectRoot !== projectRoot || !isTransactionId(journal.transactionId)) {
|
|
5129
|
+
throw new Error("Action-plugin transaction journal is invalid");
|
|
5130
|
+
}
|
|
5131
|
+
rollbackActionPluginTransaction(journal);
|
|
5132
|
+
return true;
|
|
4605
5133
|
}
|
|
4606
5134
|
|
|
4607
5135
|
// src/commands/action-plugin/utils.ts
|
|
4608
|
-
import
|
|
4609
|
-
import
|
|
5136
|
+
import fs21 from "fs";
|
|
5137
|
+
import path18 from "path";
|
|
4610
5138
|
import { spawnSync as spawnSync6, execSync as execSync2 } from "child_process";
|
|
4611
5139
|
function parsePluginName(input) {
|
|
4612
|
-
const match = input.match(
|
|
5140
|
+
const match = input.match(
|
|
5141
|
+
/^(@[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*)(?:@([^\s]+))?$/i
|
|
5142
|
+
);
|
|
4613
5143
|
if (!match) {
|
|
4614
5144
|
throw new Error(
|
|
4615
5145
|
`Invalid plugin name format: ${input}. Expected format: @scope/name or @scope/name@version`
|
|
@@ -4624,256 +5154,44 @@ function getProjectRoot() {
|
|
|
4624
5154
|
return process.cwd();
|
|
4625
5155
|
}
|
|
4626
5156
|
function getPackageJsonPath() {
|
|
4627
|
-
return
|
|
4628
|
-
}
|
|
4629
|
-
function getPluginPath(pluginName) {
|
|
4630
|
-
return path16.join(getProjectRoot(), "node_modules", pluginName);
|
|
5157
|
+
return path18.join(getProjectRoot(), "package.json");
|
|
4631
5158
|
}
|
|
4632
5159
|
function readPackageJson2() {
|
|
4633
5160
|
const pkgPath = getPackageJsonPath();
|
|
4634
|
-
if (!
|
|
5161
|
+
if (!fs21.existsSync(pkgPath)) {
|
|
4635
5162
|
throw new Error("package.json not found in current directory");
|
|
4636
5163
|
}
|
|
4637
5164
|
try {
|
|
4638
|
-
const content =
|
|
5165
|
+
const content = fs21.readFileSync(pkgPath, "utf-8");
|
|
4639
5166
|
return JSON.parse(content);
|
|
4640
5167
|
} catch {
|
|
4641
5168
|
throw new Error("Failed to parse package.json");
|
|
4642
5169
|
}
|
|
4643
5170
|
}
|
|
4644
|
-
function writePackageJson2(pkg2) {
|
|
4645
|
-
const pkgPath = getPackageJsonPath();
|
|
4646
|
-
fs19.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
4647
|
-
}
|
|
4648
5171
|
function readActionPlugins() {
|
|
4649
5172
|
const pkg2 = readPackageJson2();
|
|
4650
5173
|
return pkg2.actionPlugins || {};
|
|
4651
5174
|
}
|
|
4652
|
-
function writeActionPlugins(plugins) {
|
|
4653
|
-
const pkg2 = readPackageJson2();
|
|
4654
|
-
pkg2.actionPlugins = plugins;
|
|
4655
|
-
writePackageJson2(pkg2);
|
|
4656
|
-
}
|
|
4657
|
-
function isPluginInstalled(pluginName) {
|
|
4658
|
-
const plugins = readActionPlugins();
|
|
4659
|
-
return pluginName in plugins;
|
|
4660
|
-
}
|
|
4661
|
-
function getInstalledPluginVersion(pluginName) {
|
|
4662
|
-
const plugins = readActionPlugins();
|
|
4663
|
-
return plugins[pluginName] || null;
|
|
4664
|
-
}
|
|
4665
|
-
function npmInstall(tgzPath) {
|
|
4666
|
-
console.log(`[action-plugin] Running npm install ${tgzPath}...`);
|
|
4667
|
-
const result = spawnSync6("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
|
|
4668
|
-
cwd: getProjectRoot(),
|
|
4669
|
-
stdio: "inherit"
|
|
4670
|
-
});
|
|
4671
|
-
if (result.error) {
|
|
4672
|
-
throw new Error(`npm install failed: ${result.error.message}`);
|
|
4673
|
-
}
|
|
4674
|
-
if (result.status !== 0) {
|
|
4675
|
-
throw new Error(`npm install failed with exit code ${result.status}`);
|
|
4676
|
-
}
|
|
4677
|
-
}
|
|
4678
|
-
function getPackageVersion(pluginName) {
|
|
4679
|
-
const pkgJsonPath = path16.join(getPluginPath(pluginName), "package.json");
|
|
4680
|
-
if (!fs19.existsSync(pkgJsonPath)) {
|
|
4681
|
-
return null;
|
|
4682
|
-
}
|
|
4683
|
-
try {
|
|
4684
|
-
const content = fs19.readFileSync(pkgJsonPath, "utf-8");
|
|
4685
|
-
const pkg2 = JSON.parse(content);
|
|
4686
|
-
return pkg2.version || null;
|
|
4687
|
-
} catch {
|
|
4688
|
-
return null;
|
|
4689
|
-
}
|
|
4690
|
-
}
|
|
4691
|
-
function removePluginDirectory(pluginName) {
|
|
4692
|
-
const pluginPath2 = getPluginPath(pluginName);
|
|
4693
|
-
if (fs19.existsSync(pluginPath2)) {
|
|
4694
|
-
fs19.rmSync(pluginPath2, { recursive: true });
|
|
4695
|
-
console.log(`[action-plugin] Removed ${pluginName}`);
|
|
4696
|
-
}
|
|
4697
|
-
}
|
|
4698
|
-
|
|
4699
|
-
// src/commands/action-plugin/restore.handler.ts
|
|
4700
|
-
import fs20 from "fs";
|
|
4701
|
-
import path17 from "path";
|
|
4702
|
-
async function defaultMaterializePlugin2(name, version, destination) {
|
|
4703
|
-
let tgzPath;
|
|
4704
|
-
if (hasCachedPlugin(name, version)) {
|
|
4705
|
-
tgzPath = getCachePath(name, version);
|
|
4706
|
-
} else {
|
|
4707
|
-
const downloaded = await downloadPlugin(name, version);
|
|
4708
|
-
if (downloaded.version !== version) {
|
|
4709
|
-
throw new Error(
|
|
4710
|
-
`Downloaded version mismatch for ${name}: expected ${version}, got ${downloaded.version}`
|
|
4711
|
-
);
|
|
4712
|
-
}
|
|
4713
|
-
tgzPath = downloaded.tgzPath;
|
|
4714
|
-
}
|
|
4715
|
-
fs20.mkdirSync(path17.dirname(destination), { recursive: true });
|
|
4716
|
-
extractTgzToDirectory(tgzPath, destination);
|
|
4717
|
-
}
|
|
4718
|
-
async function restoreActionPlugins(plugins, options = {}) {
|
|
4719
|
-
const projectRoot = options.projectRoot ?? process.cwd();
|
|
4720
|
-
const stagingRoot = createStagingRoot();
|
|
4721
|
-
const results = [];
|
|
4722
|
-
try {
|
|
4723
|
-
for (const [index, [name, version]] of Object.entries(plugins).entries()) {
|
|
4724
|
-
const targetPath = path17.join(projectRoot, "node_modules", name);
|
|
4725
|
-
try {
|
|
4726
|
-
let manifest;
|
|
4727
|
-
try {
|
|
4728
|
-
manifest = assertPluginIdentity(targetPath, name, version);
|
|
4729
|
-
} catch {
|
|
4730
|
-
manifest = null;
|
|
4731
|
-
}
|
|
4732
|
-
if (manifest) {
|
|
4733
|
-
const missingPeers2 = findMissingPeerDependencies(
|
|
4734
|
-
projectRoot,
|
|
4735
|
-
manifest.peerDependencies
|
|
4736
|
-
);
|
|
4737
|
-
if (missingPeers2.length > 0) {
|
|
4738
|
-
throw new Error(
|
|
4739
|
-
`Missing peer dependencies: ${missingPeers2.join(", ")}`
|
|
4740
|
-
);
|
|
4741
|
-
}
|
|
4742
|
-
results.push({ name, version, success: true, skipped: true });
|
|
4743
|
-
continue;
|
|
4744
|
-
}
|
|
4745
|
-
const stagedPath = path17.join(stagingRoot, "prepared", String(index));
|
|
4746
|
-
await (options.materializePlugin ?? defaultMaterializePlugin2)(
|
|
4747
|
-
name,
|
|
4748
|
-
version,
|
|
4749
|
-
stagedPath
|
|
4750
|
-
);
|
|
4751
|
-
const stagedManifest = assertPluginIdentity(stagedPath, name, version);
|
|
4752
|
-
const missingPeers = findMissingPeerDependencies(
|
|
4753
|
-
projectRoot,
|
|
4754
|
-
stagedManifest.peerDependencies
|
|
4755
|
-
);
|
|
4756
|
-
if (missingPeers.length > 0) {
|
|
4757
|
-
throw new Error(
|
|
4758
|
-
`Missing peer dependencies: ${missingPeers.join(", ")}`
|
|
4759
|
-
);
|
|
4760
|
-
}
|
|
4761
|
-
const snapshot = snapshotDirectory(
|
|
4762
|
-
targetPath,
|
|
4763
|
-
stagingRoot,
|
|
4764
|
-
`restore-${index}`
|
|
4765
|
-
);
|
|
4766
|
-
try {
|
|
4767
|
-
replaceDirectory(stagedPath, targetPath);
|
|
4768
|
-
assertPluginIdentity(targetPath, name, version);
|
|
4769
|
-
} catch (error) {
|
|
4770
|
-
restoreDirectory(snapshot);
|
|
4771
|
-
throw error;
|
|
4772
|
-
}
|
|
4773
|
-
results.push({ name, version, success: true });
|
|
4774
|
-
} catch (error) {
|
|
4775
|
-
results.push({
|
|
4776
|
-
name,
|
|
4777
|
-
version,
|
|
4778
|
-
success: false,
|
|
4779
|
-
error: error instanceof Error ? error.message : String(error)
|
|
4780
|
-
});
|
|
4781
|
-
}
|
|
4782
|
-
}
|
|
4783
|
-
return results;
|
|
4784
|
-
} finally {
|
|
4785
|
-
fs20.rmSync(stagingRoot, { recursive: true, force: true });
|
|
4786
|
-
}
|
|
4787
|
-
}
|
|
4788
|
-
async function restore(options = {}) {
|
|
4789
|
-
console.log("[action-plugin] Restoring plugins from package.json...");
|
|
4790
|
-
const results = await restoreActionPlugins(readActionPlugins(), options);
|
|
4791
|
-
const failed = results.filter((result) => !result.success);
|
|
4792
|
-
for (const result of results) {
|
|
4793
|
-
if (result.success && !result.skipped) {
|
|
4794
|
-
console.log(
|
|
4795
|
-
`[action-plugin] \u2713 Restored ${result.name}@${result.version}`
|
|
4796
|
-
);
|
|
4797
|
-
} else if (!result.success) {
|
|
4798
|
-
console.error(
|
|
4799
|
-
`[action-plugin] \u2717 Failed to restore ${result.name}: ${result.error}`
|
|
4800
|
-
);
|
|
4801
|
-
}
|
|
4802
|
-
}
|
|
4803
|
-
if (failed.length > 0) process.exit(1);
|
|
4804
|
-
}
|
|
4805
5175
|
|
|
4806
5176
|
// src/commands/action-plugin/install-engine.ts
|
|
4807
|
-
var
|
|
4808
|
-
|
|
4809
|
-
|
|
5177
|
+
var NPM_REIFY_ARGUMENTS = [
|
|
5178
|
+
"install",
|
|
5179
|
+
"--ignore-scripts",
|
|
5180
|
+
"--install-links=false"
|
|
5181
|
+
];
|
|
5182
|
+
function defaultRunNpmInstall(projectRoot, env) {
|
|
5183
|
+
const result = spawnSync7("npm", [...NPM_REIFY_ARGUMENTS], {
|
|
4810
5184
|
cwd: projectRoot,
|
|
4811
5185
|
stdio: "inherit",
|
|
4812
5186
|
env
|
|
4813
5187
|
});
|
|
4814
|
-
if (result.error)
|
|
5188
|
+
if (result.error) {
|
|
4815
5189
|
throw new Error(`npm install failed: ${result.error.message}`);
|
|
5190
|
+
}
|
|
4816
5191
|
if (result.status !== 0) {
|
|
4817
5192
|
throw new Error(`npm install failed with exit code ${result.status}`);
|
|
4818
5193
|
}
|
|
4819
5194
|
}
|
|
4820
|
-
function preservePluginDirectories(projectRoot, packageDocument, requests, stagingRoot) {
|
|
4821
|
-
const names = /* @__PURE__ */ new Set([
|
|
4822
|
-
...Object.keys(packageDocument.actionPlugins ?? {}),
|
|
4823
|
-
...requests.map((request) => request.name)
|
|
4824
|
-
]);
|
|
4825
|
-
return [...names].map(
|
|
4826
|
-
(name, index) => snapshotDirectory(
|
|
4827
|
-
pluginPath(projectRoot, name),
|
|
4828
|
-
stagingRoot,
|
|
4829
|
-
`npm-${index}`
|
|
4830
|
-
)
|
|
4831
|
-
);
|
|
4832
|
-
}
|
|
4833
|
-
function runNpmOnce(projectRoot, peerRanges, packageSnapshot, lockSnapshots, pluginSnapshots, options) {
|
|
4834
|
-
const specifiers = [...peerRanges].map(([name, range]) => `${name}@${range}`);
|
|
4835
|
-
const env = {
|
|
4836
|
-
...process.env,
|
|
4837
|
-
[ACTION_PLUGIN_REENTRY_ENV]: ACTION_PLUGIN_REENTRY_VALUE
|
|
4838
|
-
};
|
|
4839
|
-
const capturedLocks = /* @__PURE__ */ new Map();
|
|
4840
|
-
let npmError;
|
|
4841
|
-
try {
|
|
4842
|
-
(options.runNpmInstall ?? ((specs, npmEnv) => defaultRunNpmInstall(projectRoot, specs, npmEnv)))(specifiers, env);
|
|
4843
|
-
for (const snapshot of lockSnapshots) {
|
|
4844
|
-
capturedLocks.set(snapshot.filePath, snapshotFile(snapshot.filePath));
|
|
4845
|
-
}
|
|
4846
|
-
} catch (error) {
|
|
4847
|
-
npmError = error;
|
|
4848
|
-
} finally {
|
|
4849
|
-
restoreFile(packageSnapshot);
|
|
4850
|
-
for (const snapshot of lockSnapshots) restoreFile(snapshot);
|
|
4851
|
-
for (const snapshot of pluginSnapshots) {
|
|
4852
|
-
if (npmError || snapshot.backupPath) restoreDirectory(snapshot);
|
|
4853
|
-
}
|
|
4854
|
-
}
|
|
4855
|
-
if (npmError) throw npmError;
|
|
4856
|
-
return { lockFiles: capturedLocks, pluginSnapshots };
|
|
4857
|
-
}
|
|
4858
|
-
function commitPluginPackage(packageJsonPath, plugin) {
|
|
4859
|
-
const latest = readPackageDocument(packageJsonPath);
|
|
4860
|
-
latest.actionPlugins = {
|
|
4861
|
-
...latest.actionPlugins ?? {},
|
|
4862
|
-
[plugin.name]: plugin.version
|
|
4863
|
-
};
|
|
4864
|
-
for (const [dependency, range] of Object.entries(
|
|
4865
|
-
plugin.missingUndeclaredPeers
|
|
4866
|
-
)) {
|
|
4867
|
-
if (!rootDeclaresDependency(latest, dependency)) {
|
|
4868
|
-
latest.dependencies = {
|
|
4869
|
-
...latest.dependencies ?? {},
|
|
4870
|
-
[dependency]: range
|
|
4871
|
-
};
|
|
4872
|
-
}
|
|
4873
|
-
}
|
|
4874
|
-
composeActionPluginLifecycle(latest);
|
|
4875
|
-
atomicWriteJson(packageJsonPath, latest);
|
|
4876
|
-
}
|
|
4877
5195
|
function formatPreparationFailure(request, error) {
|
|
4878
5196
|
return {
|
|
4879
5197
|
name: request.name,
|
|
@@ -4882,53 +5200,84 @@ function formatPreparationFailure(request, error) {
|
|
|
4882
5200
|
error: error instanceof Error ? error.message : String(error)
|
|
4883
5201
|
};
|
|
4884
5202
|
}
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
const desiredToRestore = Object.fromEntries(
|
|
4888
|
-
Object.entries(initialPackage.actionPlugins ?? {}).filter(
|
|
4889
|
-
([name]) => !requestedNames.has(name)
|
|
4890
|
-
)
|
|
4891
|
-
);
|
|
4892
|
-
const restoreResults = await restoreActionPlugins(desiredToRestore, {
|
|
4893
|
-
projectRoot,
|
|
4894
|
-
materializePlugin: options.materializePlugin ? async (name, version, destination) => {
|
|
4895
|
-
await options.materializePlugin(name, version, destination);
|
|
4896
|
-
} : void 0
|
|
4897
|
-
});
|
|
4898
|
-
const restoreFailure = restoreResults.find((result) => !result.success);
|
|
4899
|
-
if (!restoreFailure) return null;
|
|
4900
|
-
for (const snapshot of npmCapture.pluginSnapshots) restoreDirectory(snapshot);
|
|
4901
|
-
return `Failed to restore ${restoreFailure.name}: ${restoreFailure.error}`;
|
|
5203
|
+
function clonePackage(pkg2) {
|
|
5204
|
+
return JSON.parse(JSON.stringify(pkg2));
|
|
4902
5205
|
}
|
|
4903
|
-
function
|
|
4904
|
-
for (const [index, plugin] of
|
|
5206
|
+
function markPreparedFailed(publicPrepared, results, message) {
|
|
5207
|
+
for (const [index, plugin] of publicPrepared) {
|
|
4905
5208
|
results.set(index, {
|
|
4906
5209
|
name: plugin.name,
|
|
4907
5210
|
version: plugin.version,
|
|
5211
|
+
oldVersion: plugin.wasDesired ? plugin.version : void 0,
|
|
4908
5212
|
success: false,
|
|
4909
5213
|
error: message
|
|
4910
5214
|
});
|
|
4911
5215
|
}
|
|
4912
5216
|
}
|
|
4913
5217
|
async function executePluginBatch(requests, mode, options = {}) {
|
|
4914
|
-
const projectRoot = options.projectRoot ?? process.cwd();
|
|
4915
|
-
|
|
4916
|
-
|
|
5218
|
+
const projectRoot = resolveProjectRoot(options.projectRoot ?? process.cwd());
|
|
5219
|
+
assertManagedRoot(projectRoot);
|
|
5220
|
+
recoverInterruptedActionPluginTransaction(projectRoot);
|
|
5221
|
+
const packageJsonPath = path19.join(projectRoot, "package.json");
|
|
4917
5222
|
const initialPackage = readPackageDocument(packageJsonPath);
|
|
4918
|
-
const
|
|
4919
|
-
const commandLockSnapshots = LOCK_FILE_NAMES.map(
|
|
4920
|
-
(name) => snapshotFile(path18.join(projectRoot, name))
|
|
4921
|
-
);
|
|
4922
|
-
const preparedByIndex = /* @__PURE__ */ new Map();
|
|
5223
|
+
const stagingRoot = createStagingRoot();
|
|
4923
5224
|
const results = /* @__PURE__ */ new Map();
|
|
5225
|
+
const publicPrepared = /* @__PURE__ */ new Map();
|
|
5226
|
+
const implicitPrepared = /* @__PURE__ */ new Map();
|
|
4924
5227
|
try {
|
|
4925
|
-
|
|
4926
|
-
|
|
5228
|
+
const duplicateNames = /* @__PURE__ */ new Set();
|
|
5229
|
+
const seenNames = /* @__PURE__ */ new Set();
|
|
5230
|
+
for (const request of requests) {
|
|
5231
|
+
if (seenNames.has(request.name)) duplicateNames.add(request.name);
|
|
5232
|
+
seenNames.add(request.name);
|
|
5233
|
+
}
|
|
5234
|
+
if (duplicateNames.size > 0) {
|
|
5235
|
+
const message = `Duplicate plugin requests: ${[...duplicateNames].join(", ")}`;
|
|
5236
|
+
return requests.map((request) => ({
|
|
5237
|
+
name: request.name,
|
|
5238
|
+
version: request.requestedVersion,
|
|
5239
|
+
success: false,
|
|
5240
|
+
error: message
|
|
5241
|
+
}));
|
|
5242
|
+
}
|
|
5243
|
+
const publicPreparation = requests.map(async (request, index) => {
|
|
5244
|
+
if (mode === "update" && !initialPackage.actionPlugins?.[request.name]) {
|
|
5245
|
+
results.set(index, {
|
|
5246
|
+
name: request.name,
|
|
5247
|
+
version: request.requestedVersion,
|
|
5248
|
+
success: false,
|
|
5249
|
+
notInstalled: true,
|
|
5250
|
+
error: `Plugin ${request.name} is not installed`
|
|
5251
|
+
});
|
|
5252
|
+
return;
|
|
5253
|
+
}
|
|
5254
|
+
try {
|
|
5255
|
+
publicPrepared.set(
|
|
5256
|
+
index,
|
|
5257
|
+
await preparePlugin(
|
|
5258
|
+
request,
|
|
5259
|
+
index,
|
|
5260
|
+
initialPackage,
|
|
5261
|
+
projectRoot,
|
|
5262
|
+
stagingRoot,
|
|
5263
|
+
options
|
|
5264
|
+
)
|
|
5265
|
+
);
|
|
5266
|
+
} catch (error) {
|
|
5267
|
+
results.set(index, formatPreparationFailure(request, error));
|
|
5268
|
+
}
|
|
5269
|
+
});
|
|
5270
|
+
const implicitRequests = Object.entries(
|
|
5271
|
+
initialPackage.actionPlugins ?? {}
|
|
5272
|
+
).filter(([name]) => !seenNames.has(name));
|
|
5273
|
+
const implicitPreparation = implicitRequests.map(
|
|
5274
|
+
async ([name, version], offset) => {
|
|
5275
|
+
const index = requests.length + offset;
|
|
4927
5276
|
try {
|
|
4928
|
-
|
|
5277
|
+
implicitPrepared.set(
|
|
4929
5278
|
index,
|
|
4930
5279
|
await preparePlugin(
|
|
4931
|
-
|
|
5280
|
+
{ name, requestedVersion: version },
|
|
4932
5281
|
index,
|
|
4933
5282
|
initialPackage,
|
|
4934
5283
|
projectRoot,
|
|
@@ -4937,152 +5286,169 @@ async function executePluginBatch(requests, mode, options = {}) {
|
|
|
4937
5286
|
)
|
|
4938
5287
|
);
|
|
4939
5288
|
} catch (error) {
|
|
4940
|
-
|
|
5289
|
+
throw new Error(
|
|
5290
|
+
`Failed to prepare existing desired plugin ${name}: ${error instanceof Error ? error.message : String(error)}`
|
|
5291
|
+
);
|
|
4941
5292
|
}
|
|
4942
|
-
}
|
|
5293
|
+
}
|
|
4943
5294
|
);
|
|
4944
|
-
const
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
5295
|
+
const preparationResults = await Promise.allSettled([
|
|
5296
|
+
...publicPreparation,
|
|
5297
|
+
...implicitPreparation
|
|
5298
|
+
]);
|
|
5299
|
+
const rejectedPreparation = preparationResults.find(
|
|
5300
|
+
(result) => result.status === "rejected"
|
|
5301
|
+
);
|
|
5302
|
+
if (rejectedPreparation?.status === "rejected") {
|
|
5303
|
+
const error = rejectedPreparation.reason;
|
|
5304
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5305
|
+
markPreparedFailed(publicPrepared, results, message);
|
|
5306
|
+
return requests.map(
|
|
5307
|
+
(request, index) => results.get(index) ?? formatPreparationFailure(request, error)
|
|
5308
|
+
);
|
|
4953
5309
|
}
|
|
4954
|
-
const
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
5310
|
+
const failedDesiredRequest = [...results].find(
|
|
5311
|
+
([index, result]) => !result.notInstalled && Boolean(initialPackage.actionPlugins?.[requests[index].name])
|
|
5312
|
+
);
|
|
5313
|
+
if (failedDesiredRequest) {
|
|
5314
|
+
const message = failedDesiredRequest[1].error ?? "Desired plugin preparation failed";
|
|
5315
|
+
markPreparedFailed(publicPrepared, results, message);
|
|
5316
|
+
return requests.map(
|
|
5317
|
+
(request, index) => results.get(index) ?? {
|
|
5318
|
+
name: request.name,
|
|
5319
|
+
version: request.requestedVersion,
|
|
5320
|
+
success: false,
|
|
5321
|
+
error: message
|
|
5322
|
+
}
|
|
4962
5323
|
);
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
} catch (error) {
|
|
4973
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
4974
|
-
markPreparedPluginsFailed(preparedByIndex, results, message);
|
|
4975
|
-
return requests.map(
|
|
4976
|
-
(request, index) => results.get(index) ?? formatPreparationFailure(request, error)
|
|
4977
|
-
);
|
|
4978
|
-
}
|
|
4979
|
-
const restoreFailure = await restoreExistingDesiredState(
|
|
4980
|
-
initialPackage,
|
|
4981
|
-
requests,
|
|
4982
|
-
npmCapture,
|
|
4983
|
-
projectRoot,
|
|
4984
|
-
options
|
|
5324
|
+
}
|
|
5325
|
+
if (publicPrepared.size === 0) {
|
|
5326
|
+
return requests.map(
|
|
5327
|
+
(request, index) => results.get(index) ?? {
|
|
5328
|
+
name: request.name,
|
|
5329
|
+
version: request.requestedVersion,
|
|
5330
|
+
success: false,
|
|
5331
|
+
error: "Plugin was not prepared"
|
|
5332
|
+
}
|
|
4985
5333
|
);
|
|
4986
|
-
if (restoreFailure) {
|
|
4987
|
-
markPreparedPluginsFailed(preparedByIndex, results, restoreFailure);
|
|
4988
|
-
return requests.map(
|
|
4989
|
-
(request, index) => results.get(index) ?? {
|
|
4990
|
-
name: request.name,
|
|
4991
|
-
version: request.requestedVersion,
|
|
4992
|
-
success: false,
|
|
4993
|
-
error: restoreFailure
|
|
4994
|
-
}
|
|
4995
|
-
);
|
|
4996
|
-
}
|
|
4997
5334
|
}
|
|
4998
|
-
const
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5335
|
+
const allPrepared = [...publicPrepared, ...implicitPrepared].sort(([left], [right]) => left - right).map(([, plugin]) => plugin);
|
|
5336
|
+
const conflict = findPeerRangeConflict(allPrepared);
|
|
5337
|
+
if (conflict) {
|
|
5338
|
+
markPreparedFailed(publicPrepared, results, conflict);
|
|
5339
|
+
return requests.map(
|
|
5340
|
+
(request, index) => results.get(index) ?? {
|
|
5341
|
+
name: request.name,
|
|
5342
|
+
version: request.requestedVersion,
|
|
5343
|
+
success: false,
|
|
5344
|
+
error: conflict
|
|
5345
|
+
}
|
|
5005
5346
|
);
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5347
|
+
}
|
|
5348
|
+
const nextPackage = clonePackage(initialPackage);
|
|
5349
|
+
nextPackage.actionPlugins = { ...initialPackage.actionPlugins ?? {} };
|
|
5350
|
+
nextPackage.dependencies = { ...initialPackage.dependencies ?? {} };
|
|
5351
|
+
const peerRanges = collectPeerRanges(allPrepared);
|
|
5352
|
+
for (const plugin of allPrepared) {
|
|
5353
|
+
nextPackage.actionPlugins[plugin.name] = plugin.version;
|
|
5354
|
+
nextPackage.dependencies[plugin.name] = localDependencySpec(plugin.name);
|
|
5355
|
+
}
|
|
5356
|
+
for (const [dependency, range] of peerRanges) {
|
|
5357
|
+
if (!rootDeclaresDependency(nextPackage, dependency)) {
|
|
5358
|
+
nextPackage.dependencies[dependency] = range;
|
|
5359
|
+
}
|
|
5360
|
+
}
|
|
5361
|
+
composeActionPluginLifecycle(nextPackage);
|
|
5362
|
+
const transactionNames = /* @__PURE__ */ new Set([
|
|
5363
|
+
...Object.keys(initialPackage.actionPlugins ?? {}),
|
|
5364
|
+
...allPrepared.map((plugin) => plugin.name)
|
|
5365
|
+
]);
|
|
5366
|
+
let journal;
|
|
5367
|
+
try {
|
|
5368
|
+
journal = beginActionPluginTransaction(projectRoot, transactionNames);
|
|
5369
|
+
} catch (error) {
|
|
5370
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5371
|
+
markPreparedFailed(publicPrepared, results, message);
|
|
5372
|
+
return requests.map(
|
|
5373
|
+
(request, index) => results.get(index) ?? {
|
|
5374
|
+
name: request.name,
|
|
5375
|
+
version: request.requestedVersion,
|
|
5376
|
+
success: false,
|
|
5377
|
+
error: message
|
|
5378
|
+
}
|
|
5010
5379
|
);
|
|
5011
|
-
|
|
5380
|
+
}
|
|
5381
|
+
try {
|
|
5382
|
+
for (const [index, plugin] of [
|
|
5383
|
+
...publicPrepared,
|
|
5384
|
+
...implicitPrepared
|
|
5385
|
+
].sort(([left], [right]) => left - right)) {
|
|
5012
5386
|
if (plugin.stagedPath) {
|
|
5013
5387
|
replaceDirectory(
|
|
5014
5388
|
plugin.stagedPath,
|
|
5015
|
-
|
|
5016
|
-
);
|
|
5017
|
-
}
|
|
5018
|
-
const manifest = assertPluginIdentity(
|
|
5019
|
-
pluginPath(projectRoot, plugin.name),
|
|
5020
|
-
plugin.name,
|
|
5021
|
-
plugin.version
|
|
5022
|
-
);
|
|
5023
|
-
const missingPeers = findMissingPeerDependencies(
|
|
5024
|
-
projectRoot,
|
|
5025
|
-
manifest.peerDependencies
|
|
5026
|
-
);
|
|
5027
|
-
if (missingPeers.length > 0) {
|
|
5028
|
-
throw new Error(
|
|
5029
|
-
`Missing peer dependencies: ${missingPeers.join(", ")}`
|
|
5389
|
+
managedPluginPath(projectRoot, plugin.name)
|
|
5030
5390
|
);
|
|
5031
5391
|
}
|
|
5032
5392
|
options.beforeCommit?.(plugin, index);
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
}
|
|
5057
|
-
}
|
|
5058
|
-
commitPluginPackage(packageJsonPath, plugin);
|
|
5393
|
+
}
|
|
5394
|
+
atomicWriteJson(packageJsonPath, nextPackage);
|
|
5395
|
+
ensureActionPluginGitignore(projectRoot);
|
|
5396
|
+
const env = {
|
|
5397
|
+
...process.env,
|
|
5398
|
+
[ACTION_PLUGIN_REENTRY_ENV]: ACTION_PLUGIN_REENTRY_VALUE
|
|
5399
|
+
};
|
|
5400
|
+
const peerSpecifiers = [...peerRanges].map(
|
|
5401
|
+
([name, range]) => `${name}@${range}`
|
|
5402
|
+
);
|
|
5403
|
+
if (options.runNpmInstall) {
|
|
5404
|
+
options.runNpmInstall(peerSpecifiers, env, [...NPM_REIFY_ARGUMENTS]);
|
|
5405
|
+
} else {
|
|
5406
|
+
defaultRunNpmInstall(projectRoot, env);
|
|
5407
|
+
}
|
|
5408
|
+
assertNoInstallLifecycle(projectRoot, peerRanges.keys());
|
|
5409
|
+
for (const [name, version] of Object.entries(nextPackage.actionPlugins)) {
|
|
5410
|
+
verifyPluginGraph(projectRoot, name, version);
|
|
5411
|
+
}
|
|
5412
|
+
for (const [index, plugin] of [
|
|
5413
|
+
...publicPrepared,
|
|
5414
|
+
...implicitPrepared
|
|
5415
|
+
].sort(([left], [right]) => left - right)) {
|
|
5059
5416
|
options.afterCommit?.(plugin, index);
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
})
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
}
|
|
5075
|
-
);
|
|
5076
|
-
}
|
|
5077
|
-
} catch (error) {
|
|
5078
|
-
restoreFile(packageSnapshot);
|
|
5079
|
-
for (const lockSnapshot of lockSnapshots) restoreFile(lockSnapshot);
|
|
5080
|
-
restoreDirectory(directorySnapshot);
|
|
5081
|
-
results.set(index, {
|
|
5082
|
-
name: plugin.name,
|
|
5083
|
-
version: plugin.version,
|
|
5417
|
+
}
|
|
5418
|
+
commitActionPluginTransaction(journal);
|
|
5419
|
+
} catch (error) {
|
|
5420
|
+
let message = error instanceof Error ? error.message : String(error);
|
|
5421
|
+
try {
|
|
5422
|
+
rollbackActionPluginTransaction(journal);
|
|
5423
|
+
} catch (rollbackError) {
|
|
5424
|
+
message = `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`;
|
|
5425
|
+
}
|
|
5426
|
+
markPreparedFailed(publicPrepared, results, message);
|
|
5427
|
+
return requests.map(
|
|
5428
|
+
(request, index) => results.get(index) ?? {
|
|
5429
|
+
name: request.name,
|
|
5430
|
+
version: request.requestedVersion,
|
|
5084
5431
|
success: false,
|
|
5085
|
-
error:
|
|
5432
|
+
error: message
|
|
5433
|
+
}
|
|
5434
|
+
);
|
|
5435
|
+
}
|
|
5436
|
+
for (const [index, plugin] of publicPrepared) {
|
|
5437
|
+
const oldVersion = initialPackage.actionPlugins?.[plugin.name];
|
|
5438
|
+
const skipped = oldVersion === plugin.version && initialPackage.dependencies?.[plugin.name] === localDependencySpec(plugin.name) && plugin.source === "managed";
|
|
5439
|
+
results.set(index, {
|
|
5440
|
+
name: plugin.name,
|
|
5441
|
+
version: plugin.version,
|
|
5442
|
+
oldVersion,
|
|
5443
|
+
success: true,
|
|
5444
|
+
skipped
|
|
5445
|
+
});
|
|
5446
|
+
if (options.reportEvents !== false && mode === "install") {
|
|
5447
|
+
if (!skipped) {
|
|
5448
|
+
reportInstallEvent(plugin.name, plugin.version).catch(() => {
|
|
5449
|
+
});
|
|
5450
|
+
}
|
|
5451
|
+
reportCreateInstanceEvent(plugin.name, plugin.version).catch(() => {
|
|
5086
5452
|
});
|
|
5087
5453
|
}
|
|
5088
5454
|
}
|
|
@@ -5095,7 +5461,7 @@ async function executePluginBatch(requests, mode, options = {}) {
|
|
|
5095
5461
|
}
|
|
5096
5462
|
);
|
|
5097
5463
|
} finally {
|
|
5098
|
-
|
|
5464
|
+
fs22.rmSync(stagingRoot, { recursive: true, force: true });
|
|
5099
5465
|
}
|
|
5100
5466
|
}
|
|
5101
5467
|
async function installPluginBatch(namesWithVersions, options = {}) {
|
|
@@ -5119,9 +5485,200 @@ async function initPluginBatch(plugins, options = {}) {
|
|
|
5119
5485
|
options
|
|
5120
5486
|
);
|
|
5121
5487
|
}
|
|
5488
|
+
async function updatePluginBatch(names, options = {}) {
|
|
5489
|
+
const requests = names.map((value) => parsePluginName(value));
|
|
5490
|
+
return executePluginBatch(
|
|
5491
|
+
requests.map(({ name, version }) => ({
|
|
5492
|
+
name,
|
|
5493
|
+
requestedVersion: version
|
|
5494
|
+
})),
|
|
5495
|
+
"update",
|
|
5496
|
+
options
|
|
5497
|
+
);
|
|
5498
|
+
}
|
|
5499
|
+
|
|
5500
|
+
// src/commands/action-plugin/restore.handler.ts
|
|
5501
|
+
import fs23 from "fs";
|
|
5502
|
+
import path20 from "path";
|
|
5503
|
+
async function defaultMaterializePlugin2(name, version, destination) {
|
|
5504
|
+
let tgzPath;
|
|
5505
|
+
if (hasCachedPlugin(name, version)) {
|
|
5506
|
+
tgzPath = getCachePath(name, version);
|
|
5507
|
+
} else {
|
|
5508
|
+
const downloaded = await downloadPlugin(name, version);
|
|
5509
|
+
if (downloaded.version !== version) {
|
|
5510
|
+
throw new Error(
|
|
5511
|
+
`Downloaded version mismatch for ${name}: expected ${version}, got ${downloaded.version}`
|
|
5512
|
+
);
|
|
5513
|
+
}
|
|
5514
|
+
tgzPath = downloaded.tgzPath;
|
|
5515
|
+
}
|
|
5516
|
+
fs23.mkdirSync(path20.dirname(destination), { recursive: true });
|
|
5517
|
+
extractTgzToDirectory(tgzPath, destination);
|
|
5518
|
+
}
|
|
5519
|
+
function assertRequiredPeers(projectRoot, pluginPath) {
|
|
5520
|
+
const manifest = readPluginManifest(pluginPath);
|
|
5521
|
+
const missing = Object.keys(requiredPeerDependencies(manifest)).filter(
|
|
5522
|
+
(peer) => !lstatOrNull(path20.join(projectRoot, "node_modules", peer))
|
|
5523
|
+
);
|
|
5524
|
+
if (missing.length > 0) {
|
|
5525
|
+
throw new Error(`Missing peer dependencies: ${missing.join(", ")}`);
|
|
5526
|
+
}
|
|
5527
|
+
}
|
|
5528
|
+
async function restoreActionPlugins(plugins, options = {}) {
|
|
5529
|
+
const projectRoot = resolveProjectRoot(options.projectRoot ?? process.cwd());
|
|
5530
|
+
assertManagedRoot(projectRoot);
|
|
5531
|
+
recoverInterruptedActionPluginTransaction(projectRoot);
|
|
5532
|
+
const packageDocument = readPackageDocument(
|
|
5533
|
+
path20.join(projectRoot, "package.json")
|
|
5534
|
+
);
|
|
5535
|
+
const stagingRoot = createStagingRoot();
|
|
5536
|
+
const entries = Object.entries(plugins);
|
|
5537
|
+
const results = /* @__PURE__ */ new Map();
|
|
5538
|
+
const prepared = [];
|
|
5539
|
+
try {
|
|
5540
|
+
for (const [index, [name, version]] of entries.entries()) {
|
|
5541
|
+
try {
|
|
5542
|
+
assertPluginDependencyOwnership(packageDocument, name);
|
|
5543
|
+
const graphBacked = packageDocument.dependencies?.[name] === localDependencySpec(name);
|
|
5544
|
+
const targetPath = graphBacked ? managedPluginPath(projectRoot, name) : nodePluginPath(projectRoot, name);
|
|
5545
|
+
if (graphBacked) assertManagedSourcePath(projectRoot, name);
|
|
5546
|
+
if (lstatOrNull(targetPath)) {
|
|
5547
|
+
try {
|
|
5548
|
+
const existingManifest = readPluginManifest(targetPath);
|
|
5549
|
+
if (existingManifest.name !== name) {
|
|
5550
|
+
throw new Error(
|
|
5551
|
+
`Plugin identity mismatch: expected ${name}, got ${existingManifest.name}`
|
|
5552
|
+
);
|
|
5553
|
+
}
|
|
5554
|
+
} catch (error) {
|
|
5555
|
+
if (error instanceof Error && error.message.startsWith("Plugin identity mismatch:")) {
|
|
5556
|
+
throw error;
|
|
5557
|
+
}
|
|
5558
|
+
}
|
|
5559
|
+
}
|
|
5560
|
+
try {
|
|
5561
|
+
assertPluginIdentity(targetPath, name, version);
|
|
5562
|
+
assertRequiredPeers(projectRoot, targetPath);
|
|
5563
|
+
results.set(index, {
|
|
5564
|
+
name,
|
|
5565
|
+
version,
|
|
5566
|
+
success: true,
|
|
5567
|
+
skipped: true
|
|
5568
|
+
});
|
|
5569
|
+
continue;
|
|
5570
|
+
} catch {
|
|
5571
|
+
}
|
|
5572
|
+
const stagedPath = path20.join(stagingRoot, "prepared", String(index));
|
|
5573
|
+
await (options.materializePlugin ?? defaultMaterializePlugin2)(
|
|
5574
|
+
name,
|
|
5575
|
+
version,
|
|
5576
|
+
stagedPath
|
|
5577
|
+
);
|
|
5578
|
+
assertPluginIdentity(stagedPath, name, version);
|
|
5579
|
+
assertRequiredPeers(projectRoot, stagedPath);
|
|
5580
|
+
prepared.push({ index, name, version, stagedPath, targetPath });
|
|
5581
|
+
} catch (error) {
|
|
5582
|
+
results.set(index, {
|
|
5583
|
+
name,
|
|
5584
|
+
version,
|
|
5585
|
+
success: false,
|
|
5586
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5587
|
+
});
|
|
5588
|
+
}
|
|
5589
|
+
}
|
|
5590
|
+
if (prepared.length > 0) {
|
|
5591
|
+
let journal;
|
|
5592
|
+
try {
|
|
5593
|
+
journal = beginActionPluginTransaction(
|
|
5594
|
+
projectRoot,
|
|
5595
|
+
prepared.map((plugin) => plugin.name)
|
|
5596
|
+
);
|
|
5597
|
+
} catch (error) {
|
|
5598
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5599
|
+
for (const plugin of prepared) {
|
|
5600
|
+
results.set(plugin.index, {
|
|
5601
|
+
name: plugin.name,
|
|
5602
|
+
version: plugin.version,
|
|
5603
|
+
success: false,
|
|
5604
|
+
error: message
|
|
5605
|
+
});
|
|
5606
|
+
}
|
|
5607
|
+
return entries.map(
|
|
5608
|
+
([name, version], index) => results.get(index) ?? {
|
|
5609
|
+
name,
|
|
5610
|
+
version,
|
|
5611
|
+
success: false,
|
|
5612
|
+
error: message
|
|
5613
|
+
}
|
|
5614
|
+
);
|
|
5615
|
+
}
|
|
5616
|
+
try {
|
|
5617
|
+
for (const plugin of prepared) {
|
|
5618
|
+
replaceDirectory(plugin.stagedPath, plugin.targetPath);
|
|
5619
|
+
assertPluginIdentity(plugin.targetPath, plugin.name, plugin.version);
|
|
5620
|
+
assertRequiredPeers(projectRoot, plugin.targetPath);
|
|
5621
|
+
}
|
|
5622
|
+
commitActionPluginTransaction(journal);
|
|
5623
|
+
for (const plugin of prepared) {
|
|
5624
|
+
results.set(plugin.index, {
|
|
5625
|
+
name: plugin.name,
|
|
5626
|
+
version: plugin.version,
|
|
5627
|
+
success: true
|
|
5628
|
+
});
|
|
5629
|
+
}
|
|
5630
|
+
} catch (error) {
|
|
5631
|
+
let message = error instanceof Error ? error.message : String(error);
|
|
5632
|
+
try {
|
|
5633
|
+
rollbackActionPluginTransaction(journal);
|
|
5634
|
+
} catch (rollbackError) {
|
|
5635
|
+
message = `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`;
|
|
5636
|
+
}
|
|
5637
|
+
for (const plugin of prepared) {
|
|
5638
|
+
results.set(plugin.index, {
|
|
5639
|
+
name: plugin.name,
|
|
5640
|
+
version: plugin.version,
|
|
5641
|
+
success: false,
|
|
5642
|
+
error: message
|
|
5643
|
+
});
|
|
5644
|
+
}
|
|
5645
|
+
}
|
|
5646
|
+
}
|
|
5647
|
+
return entries.map(
|
|
5648
|
+
([name, version], index) => results.get(index) ?? {
|
|
5649
|
+
name,
|
|
5650
|
+
version,
|
|
5651
|
+
success: false,
|
|
5652
|
+
error: "Plugin was not restored"
|
|
5653
|
+
}
|
|
5654
|
+
);
|
|
5655
|
+
} finally {
|
|
5656
|
+
fs23.rmSync(stagingRoot, { recursive: true, force: true });
|
|
5657
|
+
}
|
|
5658
|
+
}
|
|
5659
|
+
async function restore(options = {}) {
|
|
5660
|
+
console.log("[action-plugin] Restoring plugins from package.json...");
|
|
5661
|
+
const results = await restoreActionPlugins(readActionPlugins(), options);
|
|
5662
|
+
const failed = results.filter((result) => !result.success);
|
|
5663
|
+
for (const result of results) {
|
|
5664
|
+
if (result.success && !result.skipped) {
|
|
5665
|
+
console.log(
|
|
5666
|
+
`[action-plugin] \u2713 Restored ${result.name}@${result.version}`
|
|
5667
|
+
);
|
|
5668
|
+
} else if (!result.success) {
|
|
5669
|
+
console.error(
|
|
5670
|
+
`[action-plugin] \u2717 Failed to restore ${result.name}: ${result.error}`
|
|
5671
|
+
);
|
|
5672
|
+
}
|
|
5673
|
+
}
|
|
5674
|
+
if (failed.length > 0) process.exit(1);
|
|
5675
|
+
}
|
|
5122
5676
|
|
|
5123
5677
|
// src/commands/action-plugin/init.handler.ts
|
|
5124
5678
|
async function init(options = {}) {
|
|
5679
|
+
recoverInterruptedActionPluginTransaction(
|
|
5680
|
+
options.projectRoot ?? options.restoreOptions?.projectRoot ?? process.cwd()
|
|
5681
|
+
);
|
|
5125
5682
|
if (process.env[ACTION_PLUGIN_REENTRY_ENV] === ACTION_PLUGIN_REENTRY_VALUE) {
|
|
5126
5683
|
await restore(options.restoreOptions);
|
|
5127
5684
|
return;
|
|
@@ -5168,6 +5725,9 @@ async function init(options = {}) {
|
|
|
5168
5725
|
|
|
5169
5726
|
// src/commands/action-plugin/install.handler.ts
|
|
5170
5727
|
async function install(namesWithVersion, options = {}) {
|
|
5728
|
+
recoverInterruptedActionPluginTransaction(
|
|
5729
|
+
options.projectRoot ?? process.cwd()
|
|
5730
|
+
);
|
|
5171
5731
|
if (namesWithVersion.length === 0) {
|
|
5172
5732
|
console.error("[action-plugin] No plugin names provided");
|
|
5173
5733
|
process.exit(1);
|
|
@@ -5216,91 +5776,150 @@ async function install(namesWithVersion, options = {}) {
|
|
|
5216
5776
|
}
|
|
5217
5777
|
|
|
5218
5778
|
// src/commands/action-plugin/update.handler.ts
|
|
5219
|
-
async function
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
console.log(`[action-plugin] Updating ${name}...`);
|
|
5224
|
-
if (!isPluginInstalled(name)) {
|
|
5225
|
-
console.error(`[action-plugin] Plugin ${name} is not installed`);
|
|
5226
|
-
return { name, success: false, notInstalled: true };
|
|
5227
|
-
}
|
|
5228
|
-
const oldVersion = getInstalledPluginVersion(name) || "unknown";
|
|
5229
|
-
console.log(`[action-plugin] Current version: ${oldVersion}`);
|
|
5230
|
-
const downloadResult = await downloadPlugin(name, "latest");
|
|
5231
|
-
tgzPath = downloadResult.tgzPath;
|
|
5232
|
-
if (oldVersion === downloadResult.version) {
|
|
5233
|
-
console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${downloadResult.version})`);
|
|
5234
|
-
return { name, oldVersion, newVersion: downloadResult.version, success: true, skipped: true };
|
|
5235
|
-
}
|
|
5236
|
-
npmInstall(tgzPath);
|
|
5237
|
-
const installedVersion = getPackageVersion(name) || downloadResult.version;
|
|
5238
|
-
const plugins = readActionPlugins();
|
|
5239
|
-
plugins[name] = installedVersion;
|
|
5240
|
-
writeActionPlugins(plugins);
|
|
5241
|
-
console.log(`[action-plugin] Successfully updated ${name} to ${installedVersion}`);
|
|
5242
|
-
return { name, oldVersion, newVersion: installedVersion, success: true };
|
|
5243
|
-
} catch (error) {
|
|
5244
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
5245
|
-
console.error(`[action-plugin] Failed to update ${name}: ${message}`);
|
|
5246
|
-
return { name, success: false, error: message };
|
|
5247
|
-
} finally {
|
|
5248
|
-
if (tgzPath) {
|
|
5249
|
-
cleanupTempFile(tgzPath);
|
|
5250
|
-
}
|
|
5251
|
-
}
|
|
5252
|
-
}
|
|
5253
|
-
async function update(names) {
|
|
5779
|
+
async function update(names, options = {}) {
|
|
5780
|
+
recoverInterruptedActionPluginTransaction(
|
|
5781
|
+
options.projectRoot ?? process.cwd()
|
|
5782
|
+
);
|
|
5254
5783
|
if (names.length === 0) {
|
|
5255
5784
|
console.error("[action-plugin] No plugin names provided");
|
|
5256
5785
|
process.exit(1);
|
|
5786
|
+
return;
|
|
5787
|
+
}
|
|
5788
|
+
const results = await updatePluginBatch(names, options);
|
|
5789
|
+
for (const result of results) {
|
|
5790
|
+
if (result.notInstalled) {
|
|
5791
|
+
console.error(`[action-plugin] Plugin ${result.name} is not installed`);
|
|
5792
|
+
} else if (result.success && result.skipped) {
|
|
5793
|
+
console.log(
|
|
5794
|
+
`[action-plugin] Plugin ${result.name} is already up to date (version: ${result.version})`
|
|
5795
|
+
);
|
|
5796
|
+
} else if (result.success) {
|
|
5797
|
+
console.log(
|
|
5798
|
+
`[action-plugin] Successfully updated ${result.name} to ${result.version}`
|
|
5799
|
+
);
|
|
5800
|
+
} else {
|
|
5801
|
+
console.error(
|
|
5802
|
+
`[action-plugin] Failed to update ${result.name}: ${result.error}`
|
|
5803
|
+
);
|
|
5804
|
+
}
|
|
5805
|
+
}
|
|
5806
|
+
if (names.length > 1) printSummary(results);
|
|
5807
|
+
if (results.some((result) => !result.success && !result.notInstalled)) {
|
|
5808
|
+
process.exit(1);
|
|
5809
|
+
}
|
|
5810
|
+
}
|
|
5811
|
+
function printSummary(results) {
|
|
5812
|
+
const updated = results.filter((result) => result.success && !result.skipped);
|
|
5813
|
+
const skipped = results.filter((result) => result.success && result.skipped);
|
|
5814
|
+
const notInstalled = results.filter((result) => result.notInstalled);
|
|
5815
|
+
const failed = results.filter(
|
|
5816
|
+
(result) => !result.success && !result.notInstalled
|
|
5817
|
+
);
|
|
5818
|
+
console.log("\n[action-plugin] Update summary:");
|
|
5819
|
+
if (updated.length > 0) {
|
|
5820
|
+
console.log(
|
|
5821
|
+
` \u2713 Updated: ${updated.map(
|
|
5822
|
+
(result) => `${result.name} (${result.oldVersion ?? "unknown"} \u2192 ${result.version})`
|
|
5823
|
+
).join(", ")}`
|
|
5824
|
+
);
|
|
5257
5825
|
}
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5826
|
+
if (skipped.length > 0) {
|
|
5827
|
+
console.log(
|
|
5828
|
+
` \u25CB Skipped (up to date): ${skipped.map((result) => result.name).join(", ")}`
|
|
5829
|
+
);
|
|
5262
5830
|
}
|
|
5263
|
-
if (
|
|
5264
|
-
console.log(
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5831
|
+
if (notInstalled.length > 0) {
|
|
5832
|
+
console.log(
|
|
5833
|
+
` \u26A0 Not installed: ${notInstalled.map((result) => result.name).join(", ")}`
|
|
5834
|
+
);
|
|
5835
|
+
}
|
|
5836
|
+
if (failed.length > 0) {
|
|
5837
|
+
console.log(` \u2717 Failed: ${failed.map((result) => result.name).join(", ")}`);
|
|
5838
|
+
}
|
|
5839
|
+
}
|
|
5840
|
+
|
|
5841
|
+
// src/commands/action-plugin/remove.handler.ts
|
|
5842
|
+
import fs24 from "fs";
|
|
5843
|
+
import path21 from "path";
|
|
5844
|
+
async function removePluginGraph(nameWithVersion, options = {}) {
|
|
5845
|
+
const projectRoot = resolveProjectRoot(options.projectRoot ?? process.cwd());
|
|
5846
|
+
assertManagedRoot(projectRoot);
|
|
5847
|
+
recoverInterruptedActionPluginTransaction(projectRoot);
|
|
5848
|
+
const { name } = parsePluginName(nameWithVersion);
|
|
5849
|
+
const packageJsonPath = path21.join(projectRoot, "package.json");
|
|
5850
|
+
const initialPackage = readPackageDocument(packageJsonPath);
|
|
5851
|
+
if (!initialPackage.actionPlugins?.[name]) {
|
|
5852
|
+
throw new Error(`Plugin ${name} is not installed`);
|
|
5853
|
+
}
|
|
5854
|
+
assertPluginDependencyOwnership(initialPackage, name);
|
|
5855
|
+
const journal = beginActionPluginTransaction(projectRoot, [name]);
|
|
5856
|
+
try {
|
|
5857
|
+
const nextPackage = JSON.parse(
|
|
5858
|
+
JSON.stringify(initialPackage)
|
|
5859
|
+
);
|
|
5860
|
+
nextPackage.actionPlugins = { ...nextPackage.actionPlugins ?? {} };
|
|
5861
|
+
delete nextPackage.actionPlugins[name];
|
|
5862
|
+
if (nextPackage.dependencies?.[name] === localDependencySpec(name)) {
|
|
5863
|
+
nextPackage.dependencies = { ...nextPackage.dependencies };
|
|
5864
|
+
delete nextPackage.dependencies[name];
|
|
5865
|
+
}
|
|
5866
|
+
if (Object.keys(nextPackage.actionPlugins).length === 0) {
|
|
5867
|
+
removeActionPluginLifecycle(nextPackage);
|
|
5868
|
+
}
|
|
5869
|
+
atomicWriteJson(packageJsonPath, nextPackage);
|
|
5870
|
+
removePluginLockEntries(projectRoot, name);
|
|
5871
|
+
removePathAndEmptyParents(
|
|
5872
|
+
nodePluginPath(projectRoot, name),
|
|
5873
|
+
path21.join(projectRoot, "node_modules")
|
|
5874
|
+
);
|
|
5875
|
+
removePathAndEmptyParents(
|
|
5876
|
+
managedPluginPath(projectRoot, name),
|
|
5877
|
+
managedRootPath(projectRoot)
|
|
5878
|
+
);
|
|
5879
|
+
if (Object.keys(nextPackage.actionPlugins).length === 0) {
|
|
5880
|
+
removeActionPluginGitignore(projectRoot);
|
|
5271
5881
|
}
|
|
5272
|
-
|
|
5273
|
-
|
|
5882
|
+
options.afterChange?.();
|
|
5883
|
+
const committedPackage2 = readPackageDocument(packageJsonPath);
|
|
5884
|
+
if (committedPackage2.actionPlugins?.[name] || committedPackage2.dependencies?.[name] || lstatOrNull(nodePluginPath(projectRoot, name)) || lstatOrNull(managedPluginPath(projectRoot, name))) {
|
|
5885
|
+
throw new Error(`Plugin removal left managed state for ${name}`);
|
|
5274
5886
|
}
|
|
5275
|
-
|
|
5276
|
-
|
|
5887
|
+
const lockPath = findLockfilePath(projectRoot);
|
|
5888
|
+
if (fs24.existsSync(lockPath)) {
|
|
5889
|
+
const lock = JSON.parse(fs24.readFileSync(lockPath, "utf-8"));
|
|
5890
|
+
if (lock.packages?.[sourceLockKey(name)] || lock.packages?.[nodeLockKey(name)]) {
|
|
5891
|
+
throw new Error(`Plugin removal left lock state for ${name}`);
|
|
5892
|
+
}
|
|
5277
5893
|
}
|
|
5278
|
-
|
|
5279
|
-
|
|
5894
|
+
commitActionPluginTransaction(journal);
|
|
5895
|
+
} catch (error) {
|
|
5896
|
+
try {
|
|
5897
|
+
rollbackActionPluginTransaction(journal);
|
|
5898
|
+
} catch (rollbackError) {
|
|
5899
|
+
throw new Error(
|
|
5900
|
+
`${error instanceof Error ? error.message : String(error)}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`
|
|
5901
|
+
);
|
|
5280
5902
|
}
|
|
5903
|
+
throw error;
|
|
5281
5904
|
}
|
|
5282
|
-
|
|
5283
|
-
|
|
5905
|
+
const committedPackage = readPackageDocument(packageJsonPath);
|
|
5906
|
+
if (Object.keys(committedPackage.actionPlugins ?? {}).length === 0 && fs24.existsSync(managedRootPath(projectRoot))) {
|
|
5907
|
+
fs24.rmSync(managedRootPath(projectRoot), { recursive: true, force: true });
|
|
5284
5908
|
}
|
|
5285
5909
|
}
|
|
5286
|
-
|
|
5287
|
-
// src/commands/action-plugin/remove.handler.ts
|
|
5288
|
-
async function remove(nameWithVersion) {
|
|
5910
|
+
async function remove(nameWithVersion, options = {}) {
|
|
5289
5911
|
try {
|
|
5290
5912
|
const { name } = parsePluginName(nameWithVersion);
|
|
5291
5913
|
console.log(`[action-plugin] Removing ${name}...`);
|
|
5292
|
-
|
|
5293
|
-
console.error(`[action-plugin] Plugin ${name} is not installed`);
|
|
5294
|
-
process.exit(1);
|
|
5295
|
-
}
|
|
5296
|
-
removePluginDirectory(name);
|
|
5297
|
-
const plugins = readActionPlugins();
|
|
5298
|
-
delete plugins[name];
|
|
5299
|
-
writeActionPlugins(plugins);
|
|
5914
|
+
await removePluginGraph(nameWithVersion, options);
|
|
5300
5915
|
console.log(`[action-plugin] Successfully removed ${name}`);
|
|
5301
5916
|
} catch (error) {
|
|
5302
5917
|
const message = error instanceof Error ? error.message : String(error);
|
|
5303
|
-
|
|
5918
|
+
if (message.includes("is not installed")) {
|
|
5919
|
+
console.error(`[action-plugin] ${message}`);
|
|
5920
|
+
} else {
|
|
5921
|
+
console.error(`[action-plugin] Failed to remove: ${message}`);
|
|
5922
|
+
}
|
|
5304
5923
|
process.exit(1);
|
|
5305
5924
|
}
|
|
5306
5925
|
}
|
|
@@ -5308,23 +5927,22 @@ async function remove(nameWithVersion) {
|
|
|
5308
5927
|
// src/commands/action-plugin/list.handler.ts
|
|
5309
5928
|
async function list() {
|
|
5310
5929
|
try {
|
|
5930
|
+
recoverInterruptedActionPluginTransaction(process.cwd());
|
|
5311
5931
|
const plugins = Object.entries(readActionPlugins());
|
|
5312
5932
|
if (plugins.length === 0) {
|
|
5313
5933
|
console.log("[action-plugin] No plugins installed");
|
|
5314
|
-
console.log(
|
|
5934
|
+
console.log(
|
|
5935
|
+
'[action-plugin] Use "action-plugin install <name>" to install a plugin'
|
|
5936
|
+
);
|
|
5315
5937
|
return;
|
|
5316
5938
|
}
|
|
5317
5939
|
console.log("[action-plugin] Installed plugins:\n");
|
|
5318
5940
|
const nameWidth = Math.max(40, ...plugins.map(([name]) => name.length + 2));
|
|
5319
5941
|
const versionWidth = 15;
|
|
5320
|
-
console.log(
|
|
5321
|
-
" " + "Plugin".padEnd(nameWidth) + "Version"
|
|
5322
|
-
);
|
|
5942
|
+
console.log(" " + "Plugin".padEnd(nameWidth) + "Version");
|
|
5323
5943
|
console.log(" " + "-".repeat(nameWidth + versionWidth));
|
|
5324
5944
|
for (const [name, version] of plugins) {
|
|
5325
|
-
console.log(
|
|
5326
|
-
" " + name.padEnd(nameWidth) + version
|
|
5327
|
-
);
|
|
5945
|
+
console.log(" " + name.padEnd(nameWidth) + version);
|
|
5328
5946
|
}
|
|
5329
5947
|
console.log(`
|
|
5330
5948
|
Total: ${plugins.length} plugin(s)`);
|
|
@@ -5336,15 +5954,25 @@ async function list() {
|
|
|
5336
5954
|
}
|
|
5337
5955
|
|
|
5338
5956
|
// src/commands/action-plugin/cache.handler.ts
|
|
5339
|
-
|
|
5957
|
+
function recoverBeforeCacheOperation(options) {
|
|
5958
|
+
recoverInterruptedActionPluginTransaction(
|
|
5959
|
+
options.projectRoot ?? process.cwd()
|
|
5960
|
+
);
|
|
5961
|
+
}
|
|
5962
|
+
async function cacheList(options = {}) {
|
|
5963
|
+
recoverBeforeCacheOperation(options);
|
|
5340
5964
|
const cached = listCachedPlugins();
|
|
5341
5965
|
if (cached.length === 0) {
|
|
5342
5966
|
console.log("[action-plugin] No cached plugins found");
|
|
5343
5967
|
return;
|
|
5344
5968
|
}
|
|
5345
5969
|
console.log("[action-plugin] Cached plugins:\n");
|
|
5346
|
-
console.log(
|
|
5347
|
-
|
|
5970
|
+
console.log(
|
|
5971
|
+
" Name Version Size Modified"
|
|
5972
|
+
);
|
|
5973
|
+
console.log(
|
|
5974
|
+
" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"
|
|
5975
|
+
);
|
|
5348
5976
|
let totalSize = 0;
|
|
5349
5977
|
for (const plugin of cached) {
|
|
5350
5978
|
const name = plugin.name.padEnd(38);
|
|
@@ -5354,16 +5982,25 @@ async function cacheList() {
|
|
|
5354
5982
|
console.log(` ${name} ${version} ${size} ${mtime}`);
|
|
5355
5983
|
totalSize += plugin.size;
|
|
5356
5984
|
}
|
|
5357
|
-
console.log(
|
|
5358
|
-
|
|
5985
|
+
console.log(
|
|
5986
|
+
" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"
|
|
5987
|
+
);
|
|
5988
|
+
console.log(
|
|
5989
|
+
` Total: ${cached.length} cached file(s), ${formatSize(totalSize)}`
|
|
5990
|
+
);
|
|
5359
5991
|
}
|
|
5360
|
-
async function cacheClean(pluginName, version) {
|
|
5992
|
+
async function cacheClean(pluginName, version, options = {}) {
|
|
5993
|
+
recoverBeforeCacheOperation(options);
|
|
5361
5994
|
let count;
|
|
5362
5995
|
if (pluginName) {
|
|
5363
|
-
console.log(
|
|
5996
|
+
console.log(
|
|
5997
|
+
`[action-plugin] Cleaning cache for ${pluginName}${version ? `@${version}` : ""}...`
|
|
5998
|
+
);
|
|
5364
5999
|
count = cleanPluginCache(pluginName, version);
|
|
5365
6000
|
if (count === 0) {
|
|
5366
|
-
console.log(
|
|
6001
|
+
console.log(
|
|
6002
|
+
`[action-plugin] No cached files found for ${pluginName}${version ? `@${version}` : ""}`
|
|
6003
|
+
);
|
|
5367
6004
|
} else {
|
|
5368
6005
|
console.log(`[action-plugin] Cleaned ${count} cached file(s)`);
|
|
5369
6006
|
}
|
|
@@ -5471,45 +6108,45 @@ var actionPluginCommandGroup = {
|
|
|
5471
6108
|
};
|
|
5472
6109
|
|
|
5473
6110
|
// src/commands/capability/utils.ts
|
|
5474
|
-
import
|
|
5475
|
-
import { createRequire as
|
|
5476
|
-
import
|
|
6111
|
+
import fs25 from "fs";
|
|
6112
|
+
import { createRequire as createRequire3 } from "module";
|
|
6113
|
+
import path22 from "path";
|
|
5477
6114
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
5478
6115
|
var SHARED_CAPABILITIES_DIR = "shared/capabilities";
|
|
5479
6116
|
function getProjectRoot2() {
|
|
5480
6117
|
return process.cwd();
|
|
5481
6118
|
}
|
|
5482
6119
|
function getCapabilitiesDir() {
|
|
5483
|
-
const sharedDir =
|
|
5484
|
-
if (
|
|
6120
|
+
const sharedDir = path22.join(getProjectRoot2(), SHARED_CAPABILITIES_DIR);
|
|
6121
|
+
if (fs25.existsSync(sharedDir)) {
|
|
5485
6122
|
return sharedDir;
|
|
5486
6123
|
}
|
|
5487
|
-
return
|
|
6124
|
+
return path22.join(getProjectRoot2(), CAPABILITIES_DIR);
|
|
5488
6125
|
}
|
|
5489
6126
|
function getCapabilityPath(id) {
|
|
5490
|
-
return
|
|
6127
|
+
return path22.join(getCapabilitiesDir(), `${id}.json`);
|
|
5491
6128
|
}
|
|
5492
6129
|
function getPluginManifestPath(pluginKey) {
|
|
5493
|
-
return
|
|
6130
|
+
return path22.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
|
|
5494
6131
|
}
|
|
5495
6132
|
function capabilitiesDirExists() {
|
|
5496
|
-
return
|
|
6133
|
+
return fs25.existsSync(getCapabilitiesDir());
|
|
5497
6134
|
}
|
|
5498
6135
|
function listCapabilityIds() {
|
|
5499
6136
|
const dir = getCapabilitiesDir();
|
|
5500
|
-
if (!
|
|
6137
|
+
if (!fs25.existsSync(dir)) {
|
|
5501
6138
|
return [];
|
|
5502
6139
|
}
|
|
5503
|
-
const files =
|
|
6140
|
+
const files = fs25.readdirSync(dir);
|
|
5504
6141
|
return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
|
|
5505
6142
|
}
|
|
5506
6143
|
function readCapability(id) {
|
|
5507
6144
|
const filePath = getCapabilityPath(id);
|
|
5508
|
-
if (!
|
|
6145
|
+
if (!fs25.existsSync(filePath)) {
|
|
5509
6146
|
throw new Error(`Capability not found: ${id}`);
|
|
5510
6147
|
}
|
|
5511
6148
|
try {
|
|
5512
|
-
const content =
|
|
6149
|
+
const content = fs25.readFileSync(filePath, "utf-8");
|
|
5513
6150
|
return JSON.parse(content);
|
|
5514
6151
|
} catch (error) {
|
|
5515
6152
|
if (error instanceof SyntaxError) {
|
|
@@ -5534,13 +6171,13 @@ function readAllCapabilities() {
|
|
|
5534
6171
|
}
|
|
5535
6172
|
return capabilities;
|
|
5536
6173
|
}
|
|
5537
|
-
function
|
|
6174
|
+
function readPluginManifest3(pluginKey) {
|
|
5538
6175
|
const manifestPath = getPluginManifestPath(pluginKey);
|
|
5539
|
-
if (!
|
|
6176
|
+
if (!fs25.existsSync(manifestPath)) {
|
|
5540
6177
|
throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
|
|
5541
6178
|
}
|
|
5542
6179
|
try {
|
|
5543
|
-
const content =
|
|
6180
|
+
const content = fs25.readFileSync(manifestPath, "utf-8");
|
|
5544
6181
|
return JSON.parse(content);
|
|
5545
6182
|
} catch (error) {
|
|
5546
6183
|
if (error instanceof SyntaxError) {
|
|
@@ -5557,7 +6194,7 @@ function hasValidParamsSchema(paramsSchema) {
|
|
|
5557
6194
|
}
|
|
5558
6195
|
async function loadPlugin(pluginKey) {
|
|
5559
6196
|
try {
|
|
5560
|
-
const userRequire =
|
|
6197
|
+
const userRequire = createRequire3(path22.join(getProjectRoot2(), "package.json"));
|
|
5561
6198
|
const resolvedPath = userRequire.resolve(pluginKey);
|
|
5562
6199
|
const pluginModule = await import(resolvedPath);
|
|
5563
6200
|
const pluginPackage = pluginModule.default ?? pluginModule;
|
|
@@ -5576,7 +6213,7 @@ async function loadPlugin(pluginKey) {
|
|
|
5576
6213
|
}
|
|
5577
6214
|
async function hydrateCapability(capability) {
|
|
5578
6215
|
try {
|
|
5579
|
-
const manifest =
|
|
6216
|
+
const manifest = readPluginManifest3(capability.pluginKey);
|
|
5580
6217
|
if (!manifest.actions || manifest.actions.length === 0) {
|
|
5581
6218
|
throw new Error(`Plugin ${capability.pluginKey} has no actions defined`);
|
|
5582
6219
|
}
|
|
@@ -5720,8 +6357,8 @@ var capabilityCommandGroup = {
|
|
|
5720
6357
|
import { execFile } from "child_process";
|
|
5721
6358
|
|
|
5722
6359
|
// src/commands/component/registry-preparer.ts
|
|
5723
|
-
import
|
|
5724
|
-
import
|
|
6360
|
+
import fs26 from "fs";
|
|
6361
|
+
import path23 from "path";
|
|
5725
6362
|
import os2 from "os";
|
|
5726
6363
|
|
|
5727
6364
|
// src/commands/component/service.ts
|
|
@@ -5781,7 +6418,7 @@ async function sendInstallEvent(key) {
|
|
|
5781
6418
|
}
|
|
5782
6419
|
|
|
5783
6420
|
// src/commands/component/registry-preparer.ts
|
|
5784
|
-
var REGISTRY_TEMP_DIR =
|
|
6421
|
+
var REGISTRY_TEMP_DIR = path23.join(os2.tmpdir(), "miaoda-registry");
|
|
5785
6422
|
function parseComponentKey(key) {
|
|
5786
6423
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
5787
6424
|
if (!match) {
|
|
@@ -5793,11 +6430,11 @@ function parseComponentKey(key) {
|
|
|
5793
6430
|
}
|
|
5794
6431
|
function getLocalRegistryPath(key) {
|
|
5795
6432
|
const { scope, name } = parseComponentKey(key);
|
|
5796
|
-
return
|
|
6433
|
+
return path23.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
5797
6434
|
}
|
|
5798
6435
|
function ensureDir(dirPath) {
|
|
5799
|
-
if (!
|
|
5800
|
-
|
|
6436
|
+
if (!fs26.existsSync(dirPath)) {
|
|
6437
|
+
fs26.mkdirSync(dirPath, { recursive: true });
|
|
5801
6438
|
}
|
|
5802
6439
|
}
|
|
5803
6440
|
async function prepareRecursive(key, visited) {
|
|
@@ -5830,8 +6467,8 @@ async function prepareRecursive(key, visited) {
|
|
|
5830
6467
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
5831
6468
|
};
|
|
5832
6469
|
const localPath = getLocalRegistryPath(key);
|
|
5833
|
-
ensureDir(
|
|
5834
|
-
|
|
6470
|
+
ensureDir(path23.dirname(localPath));
|
|
6471
|
+
fs26.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
5835
6472
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
5836
6473
|
}
|
|
5837
6474
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -5841,18 +6478,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
5841
6478
|
}
|
|
5842
6479
|
function cleanupTempDir() {
|
|
5843
6480
|
try {
|
|
5844
|
-
if (
|
|
5845
|
-
|
|
6481
|
+
if (fs26.existsSync(REGISTRY_TEMP_DIR)) {
|
|
6482
|
+
fs26.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
5846
6483
|
}
|
|
5847
6484
|
} catch {
|
|
5848
6485
|
}
|
|
5849
6486
|
}
|
|
5850
6487
|
function getDownloadedRegistryItem(itemId) {
|
|
5851
6488
|
const localPath = getLocalRegistryPath(itemId);
|
|
5852
|
-
if (!
|
|
6489
|
+
if (!fs26.existsSync(localPath)) {
|
|
5853
6490
|
return null;
|
|
5854
6491
|
}
|
|
5855
|
-
const content =
|
|
6492
|
+
const content = fs26.readFileSync(localPath, "utf-8");
|
|
5856
6493
|
return JSON.parse(content);
|
|
5857
6494
|
}
|
|
5858
6495
|
|
|
@@ -6020,58 +6657,58 @@ var componentCommandGroup = {
|
|
|
6020
6657
|
};
|
|
6021
6658
|
|
|
6022
6659
|
// src/commands/migration/version-manager.ts
|
|
6023
|
-
import
|
|
6024
|
-
import
|
|
6660
|
+
import fs27 from "fs";
|
|
6661
|
+
import path24 from "path";
|
|
6025
6662
|
var PACKAGE_JSON = "package.json";
|
|
6026
6663
|
var VERSION_FIELD = "migrationVersion";
|
|
6027
6664
|
function getPackageJsonPath2() {
|
|
6028
|
-
return
|
|
6665
|
+
return path24.join(process.cwd(), PACKAGE_JSON);
|
|
6029
6666
|
}
|
|
6030
6667
|
function getCurrentVersion() {
|
|
6031
6668
|
const pkgPath = getPackageJsonPath2();
|
|
6032
|
-
if (!
|
|
6669
|
+
if (!fs27.existsSync(pkgPath)) {
|
|
6033
6670
|
throw new Error("package.json not found");
|
|
6034
6671
|
}
|
|
6035
|
-
const pkg2 = JSON.parse(
|
|
6672
|
+
const pkg2 = JSON.parse(fs27.readFileSync(pkgPath, "utf-8"));
|
|
6036
6673
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
6037
6674
|
}
|
|
6038
6675
|
function setCurrentVersion(version) {
|
|
6039
6676
|
const pkgPath = getPackageJsonPath2();
|
|
6040
|
-
const pkg2 = JSON.parse(
|
|
6677
|
+
const pkg2 = JSON.parse(fs27.readFileSync(pkgPath, "utf-8"));
|
|
6041
6678
|
pkg2[VERSION_FIELD] = version;
|
|
6042
|
-
|
|
6679
|
+
fs27.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
6043
6680
|
}
|
|
6044
6681
|
|
|
6045
6682
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
6046
|
-
import
|
|
6047
|
-
import
|
|
6683
|
+
import fs29 from "fs";
|
|
6684
|
+
import path26 from "path";
|
|
6048
6685
|
|
|
6049
6686
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
6050
|
-
import
|
|
6051
|
-
import
|
|
6687
|
+
import fs28 from "fs";
|
|
6688
|
+
import path25 from "path";
|
|
6052
6689
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
6053
6690
|
function getProjectRoot3() {
|
|
6054
6691
|
return process.cwd();
|
|
6055
6692
|
}
|
|
6056
6693
|
function getCapabilitiesDir2() {
|
|
6057
|
-
return
|
|
6694
|
+
return path25.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
6058
6695
|
}
|
|
6059
6696
|
function getPluginManifestPath2(pluginKey) {
|
|
6060
|
-
return
|
|
6697
|
+
return path25.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
6061
6698
|
}
|
|
6062
6699
|
|
|
6063
6700
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
6064
6701
|
function detectJsonMigration() {
|
|
6065
6702
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
6066
|
-
const oldFilePath =
|
|
6067
|
-
if (!
|
|
6703
|
+
const oldFilePath = path26.join(capabilitiesDir, "capabilities.json");
|
|
6704
|
+
if (!fs29.existsSync(oldFilePath)) {
|
|
6068
6705
|
return {
|
|
6069
6706
|
needsMigration: false,
|
|
6070
6707
|
reason: "capabilities.json not found"
|
|
6071
6708
|
};
|
|
6072
6709
|
}
|
|
6073
6710
|
try {
|
|
6074
|
-
const content =
|
|
6711
|
+
const content = fs29.readFileSync(oldFilePath, "utf-8");
|
|
6075
6712
|
const parsed = JSON.parse(content);
|
|
6076
6713
|
if (!Array.isArray(parsed)) {
|
|
6077
6714
|
return {
|
|
@@ -6122,8 +6759,8 @@ async function check(options) {
|
|
|
6122
6759
|
}
|
|
6123
6760
|
|
|
6124
6761
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
6125
|
-
import
|
|
6126
|
-
import
|
|
6762
|
+
import fs30 from "fs";
|
|
6763
|
+
import path27 from "path";
|
|
6127
6764
|
|
|
6128
6765
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
6129
6766
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -6353,18 +6990,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
6353
6990
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
6354
6991
|
function loadExistingCapabilities() {
|
|
6355
6992
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
6356
|
-
if (!
|
|
6993
|
+
if (!fs30.existsSync(capabilitiesDir)) {
|
|
6357
6994
|
return [];
|
|
6358
6995
|
}
|
|
6359
|
-
const files =
|
|
6996
|
+
const files = fs30.readdirSync(capabilitiesDir);
|
|
6360
6997
|
const capabilities = [];
|
|
6361
6998
|
for (const file of files) {
|
|
6362
6999
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
6363
7000
|
continue;
|
|
6364
7001
|
}
|
|
6365
7002
|
try {
|
|
6366
|
-
const filePath =
|
|
6367
|
-
const content =
|
|
7003
|
+
const filePath = path27.join(capabilitiesDir, file);
|
|
7004
|
+
const content = fs30.readFileSync(filePath, "utf-8");
|
|
6368
7005
|
const capability = JSON.parse(content);
|
|
6369
7006
|
if (capability.id && capability.pluginKey) {
|
|
6370
7007
|
capabilities.push(capability);
|
|
@@ -6422,9 +7059,9 @@ async function migrateJsonFiles(options) {
|
|
|
6422
7059
|
}
|
|
6423
7060
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
6424
7061
|
for (const cap of newCapabilities) {
|
|
6425
|
-
const filePath =
|
|
7062
|
+
const filePath = path27.join(capabilitiesDir, `${cap.id}.json`);
|
|
6426
7063
|
const content = JSON.stringify(cap, null, 2);
|
|
6427
|
-
|
|
7064
|
+
fs30.writeFileSync(filePath, content, "utf-8");
|
|
6428
7065
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
6429
7066
|
}
|
|
6430
7067
|
return {
|
|
@@ -6436,11 +7073,11 @@ async function migrateJsonFiles(options) {
|
|
|
6436
7073
|
}
|
|
6437
7074
|
|
|
6438
7075
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
6439
|
-
import
|
|
6440
|
-
function
|
|
7076
|
+
import fs31 from "fs";
|
|
7077
|
+
function isPluginInstalled(pluginKey) {
|
|
6441
7078
|
const actionPlugins = readActionPlugins();
|
|
6442
7079
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
6443
|
-
return
|
|
7080
|
+
return fs31.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
6444
7081
|
}
|
|
6445
7082
|
function detectPluginsToInstall(capabilities) {
|
|
6446
7083
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -6450,7 +7087,7 @@ function detectPluginsToInstall(capabilities) {
|
|
|
6450
7087
|
const toInstall = [];
|
|
6451
7088
|
const alreadyInstalled = [];
|
|
6452
7089
|
for (const pluginKey of pluginKeys) {
|
|
6453
|
-
if (
|
|
7090
|
+
if (isPluginInstalled(pluginKey)) {
|
|
6454
7091
|
alreadyInstalled.push(pluginKey);
|
|
6455
7092
|
} else {
|
|
6456
7093
|
toInstall.push(pluginKey);
|
|
@@ -6516,12 +7153,12 @@ async function installPlugins(capabilities, options) {
|
|
|
6516
7153
|
}
|
|
6517
7154
|
|
|
6518
7155
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
6519
|
-
import
|
|
7156
|
+
import path29 from "path";
|
|
6520
7157
|
import { Project as Project3 } from "ts-morph";
|
|
6521
7158
|
|
|
6522
7159
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
6523
|
-
import
|
|
6524
|
-
import
|
|
7160
|
+
import fs32 from "fs";
|
|
7161
|
+
import path28 from "path";
|
|
6525
7162
|
var EXCLUDED_DIRS = [
|
|
6526
7163
|
"node_modules",
|
|
6527
7164
|
"dist",
|
|
@@ -6536,9 +7173,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
6536
7173
|
/\.d\.ts$/
|
|
6537
7174
|
];
|
|
6538
7175
|
function scanDirectory(dir, files = []) {
|
|
6539
|
-
const entries =
|
|
7176
|
+
const entries = fs32.readdirSync(dir, { withFileTypes: true });
|
|
6540
7177
|
for (const entry of entries) {
|
|
6541
|
-
const fullPath =
|
|
7178
|
+
const fullPath = path28.join(dir, entry.name);
|
|
6542
7179
|
if (entry.isDirectory()) {
|
|
6543
7180
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
6544
7181
|
continue;
|
|
@@ -6554,14 +7191,14 @@ function scanDirectory(dir, files = []) {
|
|
|
6554
7191
|
return files;
|
|
6555
7192
|
}
|
|
6556
7193
|
function scanServerFiles() {
|
|
6557
|
-
const serverDir =
|
|
6558
|
-
if (!
|
|
7194
|
+
const serverDir = path28.join(getProjectRoot3(), "server");
|
|
7195
|
+
if (!fs32.existsSync(serverDir)) {
|
|
6559
7196
|
return [];
|
|
6560
7197
|
}
|
|
6561
7198
|
return scanDirectory(serverDir);
|
|
6562
7199
|
}
|
|
6563
7200
|
function hasCapabilityImport(filePath) {
|
|
6564
|
-
const content =
|
|
7201
|
+
const content = fs32.readFileSync(filePath, "utf-8");
|
|
6565
7202
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
6566
7203
|
}
|
|
6567
7204
|
function scanFilesToMigrate() {
|
|
@@ -6938,7 +7575,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6938
7575
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
6939
7576
|
const classInfo = analyzeClass(sourceFile);
|
|
6940
7577
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
6941
|
-
const relativePath =
|
|
7578
|
+
const relativePath = path29.relative(getProjectRoot3(), filePath);
|
|
6942
7579
|
return {
|
|
6943
7580
|
filePath: relativePath,
|
|
6944
7581
|
imports,
|
|
@@ -6949,7 +7586,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6949
7586
|
};
|
|
6950
7587
|
}
|
|
6951
7588
|
function migrateFile(project, analysis, dryRun) {
|
|
6952
|
-
const absolutePath =
|
|
7589
|
+
const absolutePath = path29.join(getProjectRoot3(), analysis.filePath);
|
|
6953
7590
|
if (!analysis.canAutoMigrate) {
|
|
6954
7591
|
return {
|
|
6955
7592
|
filePath: analysis.filePath,
|
|
@@ -7052,17 +7689,17 @@ function getSuggestion(analysis) {
|
|
|
7052
7689
|
}
|
|
7053
7690
|
|
|
7054
7691
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
7055
|
-
import
|
|
7056
|
-
import
|
|
7692
|
+
import fs33 from "fs";
|
|
7693
|
+
import path30 from "path";
|
|
7057
7694
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
7058
7695
|
const deletedFiles = [];
|
|
7059
7696
|
const errors = [];
|
|
7060
7697
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
7061
|
-
const oldJsonPath =
|
|
7062
|
-
if (
|
|
7698
|
+
const oldJsonPath = path30.join(capabilitiesDir, "capabilities.json");
|
|
7699
|
+
if (fs33.existsSync(oldJsonPath)) {
|
|
7063
7700
|
try {
|
|
7064
7701
|
if (!dryRun) {
|
|
7065
|
-
|
|
7702
|
+
fs33.unlinkSync(oldJsonPath);
|
|
7066
7703
|
}
|
|
7067
7704
|
deletedFiles.push("capabilities.json");
|
|
7068
7705
|
} catch (error) {
|
|
@@ -7070,11 +7707,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
7070
7707
|
}
|
|
7071
7708
|
}
|
|
7072
7709
|
for (const cap of capabilities) {
|
|
7073
|
-
const tsFilePath =
|
|
7074
|
-
if (
|
|
7710
|
+
const tsFilePath = path30.join(capabilitiesDir, `${cap.id}.ts`);
|
|
7711
|
+
if (fs33.existsSync(tsFilePath)) {
|
|
7075
7712
|
try {
|
|
7076
7713
|
if (!dryRun) {
|
|
7077
|
-
|
|
7714
|
+
fs33.unlinkSync(tsFilePath);
|
|
7078
7715
|
}
|
|
7079
7716
|
deletedFiles.push(`${cap.id}.ts`);
|
|
7080
7717
|
} catch (error) {
|
|
@@ -7090,10 +7727,10 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
7090
7727
|
}
|
|
7091
7728
|
|
|
7092
7729
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
7093
|
-
import
|
|
7094
|
-
import
|
|
7730
|
+
import fs34 from "fs";
|
|
7731
|
+
import path31 from "path";
|
|
7095
7732
|
var REPORT_FILE = "capability-migration-report.md";
|
|
7096
|
-
function
|
|
7733
|
+
function printSummary2(result) {
|
|
7097
7734
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
7098
7735
|
console.log("\u{1F4CA} Migration Summary");
|
|
7099
7736
|
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
@@ -7254,15 +7891,15 @@ async function generateReport(result) {
|
|
|
7254
7891
|
}
|
|
7255
7892
|
lines.push("");
|
|
7256
7893
|
const logDir = process.env.LOG_DIR || "logs";
|
|
7257
|
-
if (!
|
|
7894
|
+
if (!fs34.existsSync(logDir)) {
|
|
7258
7895
|
return;
|
|
7259
7896
|
}
|
|
7260
|
-
const reportDir =
|
|
7261
|
-
if (!
|
|
7262
|
-
|
|
7897
|
+
const reportDir = path31.join(logDir, "migration");
|
|
7898
|
+
if (!fs34.existsSync(reportDir)) {
|
|
7899
|
+
fs34.mkdirSync(reportDir, { recursive: true });
|
|
7263
7900
|
}
|
|
7264
|
-
const reportPath =
|
|
7265
|
-
|
|
7901
|
+
const reportPath = path31.join(reportDir, REPORT_FILE);
|
|
7902
|
+
fs34.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
7266
7903
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
7267
7904
|
}
|
|
7268
7905
|
|
|
@@ -7419,7 +8056,7 @@ async function runCapabilityMigration(options = {}) {
|
|
|
7419
8056
|
};
|
|
7420
8057
|
}
|
|
7421
8058
|
const result = buildResult(jsonResult, pluginResult, codeResult, cleanupResult);
|
|
7422
|
-
|
|
8059
|
+
printSummary2(result);
|
|
7423
8060
|
if (!fullOptions.dryRun) {
|
|
7424
8061
|
try {
|
|
7425
8062
|
await generateReport(result);
|
|
@@ -7586,7 +8223,7 @@ async function executeSingle(migration, options) {
|
|
|
7586
8223
|
};
|
|
7587
8224
|
}
|
|
7588
8225
|
}
|
|
7589
|
-
function
|
|
8226
|
+
function printSummary3(summary, dryRun) {
|
|
7590
8227
|
console.log("");
|
|
7591
8228
|
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
7592
8229
|
console.log(dryRun ? "Dry-run Summary:" : "Migration Summary:");
|
|
@@ -7650,7 +8287,7 @@ async function runMigrations(options) {
|
|
|
7650
8287
|
summary.failed.push(result);
|
|
7651
8288
|
hasAnyMigration = true;
|
|
7652
8289
|
log("Migration aborted due to failure.");
|
|
7653
|
-
|
|
8290
|
+
printSummary3(summary, !!options.dryRun);
|
|
7654
8291
|
return summary;
|
|
7655
8292
|
}
|
|
7656
8293
|
console.log("");
|
|
@@ -7663,7 +8300,7 @@ async function runMigrations(options) {
|
|
|
7663
8300
|
} else if (!options.dryRun && summary.completed.length > 0) {
|
|
7664
8301
|
log(`Migration complete. Updated to version ${getCurrentVersion()}.`);
|
|
7665
8302
|
}
|
|
7666
|
-
|
|
8303
|
+
printSummary3(summary, !!options.dryRun);
|
|
7667
8304
|
return summary;
|
|
7668
8305
|
}
|
|
7669
8306
|
function printMigrationResult(result) {
|
|
@@ -7794,10 +8431,10 @@ var migrationCommand = {
|
|
|
7794
8431
|
};
|
|
7795
8432
|
|
|
7796
8433
|
// src/commands/read-logs/index.ts
|
|
7797
|
-
import
|
|
8434
|
+
import path32 from "path";
|
|
7798
8435
|
|
|
7799
8436
|
// src/commands/read-logs/std-utils.ts
|
|
7800
|
-
import
|
|
8437
|
+
import fs35 from "fs";
|
|
7801
8438
|
function formatStdPrefixTime(localTime) {
|
|
7802
8439
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
7803
8440
|
if (!match) return localTime;
|
|
@@ -7827,11 +8464,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
7827
8464
|
return `[${time}] ${content}`;
|
|
7828
8465
|
}
|
|
7829
8466
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
7830
|
-
const stat =
|
|
8467
|
+
const stat = fs35.statSync(filePath);
|
|
7831
8468
|
if (stat.size === 0) {
|
|
7832
8469
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
7833
8470
|
}
|
|
7834
|
-
const fd =
|
|
8471
|
+
const fd = fs35.openSync(filePath, "r");
|
|
7835
8472
|
const chunkSize = 64 * 1024;
|
|
7836
8473
|
let position = stat.size;
|
|
7837
8474
|
let remainder = "";
|
|
@@ -7845,7 +8482,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7845
8482
|
const length = Math.min(chunkSize, position);
|
|
7846
8483
|
position -= length;
|
|
7847
8484
|
const buffer = Buffer.alloc(length);
|
|
7848
|
-
|
|
8485
|
+
fs35.readSync(fd, buffer, 0, length, position);
|
|
7849
8486
|
let chunk = buffer.toString("utf8");
|
|
7850
8487
|
if (remainder) {
|
|
7851
8488
|
chunk += remainder;
|
|
@@ -7887,7 +8524,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7887
8524
|
}
|
|
7888
8525
|
}
|
|
7889
8526
|
} finally {
|
|
7890
|
-
|
|
8527
|
+
fs35.closeSync(fd);
|
|
7891
8528
|
}
|
|
7892
8529
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
7893
8530
|
}
|
|
@@ -7908,21 +8545,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
7908
8545
|
}
|
|
7909
8546
|
|
|
7910
8547
|
// src/commands/read-logs/tail.ts
|
|
7911
|
-
import
|
|
8548
|
+
import fs36 from "fs";
|
|
7912
8549
|
function fileExists(filePath) {
|
|
7913
8550
|
try {
|
|
7914
|
-
|
|
8551
|
+
fs36.accessSync(filePath, fs36.constants.F_OK | fs36.constants.R_OK);
|
|
7915
8552
|
return true;
|
|
7916
8553
|
} catch {
|
|
7917
8554
|
return false;
|
|
7918
8555
|
}
|
|
7919
8556
|
}
|
|
7920
8557
|
function readFileTailLines(filePath, maxLines) {
|
|
7921
|
-
const stat =
|
|
8558
|
+
const stat = fs36.statSync(filePath);
|
|
7922
8559
|
if (stat.size === 0) {
|
|
7923
8560
|
return [];
|
|
7924
8561
|
}
|
|
7925
|
-
const fd =
|
|
8562
|
+
const fd = fs36.openSync(filePath, "r");
|
|
7926
8563
|
const chunkSize = 64 * 1024;
|
|
7927
8564
|
const chunks = [];
|
|
7928
8565
|
let position = stat.size;
|
|
@@ -7932,13 +8569,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7932
8569
|
const length = Math.min(chunkSize, position);
|
|
7933
8570
|
position -= length;
|
|
7934
8571
|
const buffer = Buffer.alloc(length);
|
|
7935
|
-
|
|
8572
|
+
fs36.readSync(fd, buffer, 0, length, position);
|
|
7936
8573
|
chunks.unshift(buffer.toString("utf8"));
|
|
7937
8574
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
7938
8575
|
collectedLines += chunkLines;
|
|
7939
8576
|
}
|
|
7940
8577
|
} finally {
|
|
7941
|
-
|
|
8578
|
+
fs36.closeSync(fd);
|
|
7942
8579
|
}
|
|
7943
8580
|
const content = chunks.join("");
|
|
7944
8581
|
const allLines = content.split("\n");
|
|
@@ -7954,11 +8591,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7954
8591
|
return allLines.slice(allLines.length - maxLines);
|
|
7955
8592
|
}
|
|
7956
8593
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
7957
|
-
const stat =
|
|
8594
|
+
const stat = fs36.statSync(filePath);
|
|
7958
8595
|
if (stat.size === 0) {
|
|
7959
8596
|
return { lines: [], totalLinesCount: 0 };
|
|
7960
8597
|
}
|
|
7961
|
-
const fd =
|
|
8598
|
+
const fd = fs36.openSync(filePath, "r");
|
|
7962
8599
|
const chunkSize = 64 * 1024;
|
|
7963
8600
|
let position = stat.size;
|
|
7964
8601
|
let remainder = "";
|
|
@@ -7970,7 +8607,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7970
8607
|
const length = Math.min(chunkSize, position);
|
|
7971
8608
|
position -= length;
|
|
7972
8609
|
const buffer = Buffer.alloc(length);
|
|
7973
|
-
|
|
8610
|
+
fs36.readSync(fd, buffer, 0, length, position);
|
|
7974
8611
|
let chunk = buffer.toString("utf8");
|
|
7975
8612
|
if (remainder) {
|
|
7976
8613
|
chunk += remainder;
|
|
@@ -8001,7 +8638,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
8001
8638
|
}
|
|
8002
8639
|
}
|
|
8003
8640
|
} finally {
|
|
8004
|
-
|
|
8641
|
+
fs36.closeSync(fd);
|
|
8005
8642
|
}
|
|
8006
8643
|
return { lines: collected.reverse(), totalLinesCount };
|
|
8007
8644
|
}
|
|
@@ -8143,7 +8780,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
8143
8780
|
}
|
|
8144
8781
|
|
|
8145
8782
|
// src/commands/read-logs/json-lines.ts
|
|
8146
|
-
import
|
|
8783
|
+
import fs37 from "fs";
|
|
8147
8784
|
|
|
8148
8785
|
// src/commands/read-logs/structured-log.ts
|
|
8149
8786
|
function normalizeLevelName(value) {
|
|
@@ -8219,11 +8856,11 @@ function buildWantedLevelSet(levels) {
|
|
|
8219
8856
|
return set.size > 0 ? set : null;
|
|
8220
8857
|
}
|
|
8221
8858
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
8222
|
-
const stat =
|
|
8859
|
+
const stat = fs37.statSync(filePath);
|
|
8223
8860
|
if (stat.size === 0) {
|
|
8224
8861
|
return { lines: [], totalLinesCount: 0 };
|
|
8225
8862
|
}
|
|
8226
|
-
const fd =
|
|
8863
|
+
const fd = fs37.openSync(filePath, "r");
|
|
8227
8864
|
const chunkSize = 64 * 1024;
|
|
8228
8865
|
let position = stat.size;
|
|
8229
8866
|
let remainder = "";
|
|
@@ -8238,7 +8875,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
8238
8875
|
const length = Math.min(chunkSize, position);
|
|
8239
8876
|
position -= length;
|
|
8240
8877
|
const buffer = Buffer.alloc(length);
|
|
8241
|
-
|
|
8878
|
+
fs37.readSync(fd, buffer, 0, length, position);
|
|
8242
8879
|
let chunk = buffer.toString("utf8");
|
|
8243
8880
|
if (remainder) {
|
|
8244
8881
|
chunk += remainder;
|
|
@@ -8300,7 +8937,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
8300
8937
|
}
|
|
8301
8938
|
}
|
|
8302
8939
|
} finally {
|
|
8303
|
-
|
|
8940
|
+
fs37.closeSync(fd);
|
|
8304
8941
|
}
|
|
8305
8942
|
return { lines: collected.reverse(), totalLinesCount };
|
|
8306
8943
|
}
|
|
@@ -8343,11 +8980,11 @@ function extractTraceId(obj) {
|
|
|
8343
8980
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
8344
8981
|
const wanted = traceId.trim();
|
|
8345
8982
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
8346
|
-
const stat =
|
|
8983
|
+
const stat = fs37.statSync(filePath);
|
|
8347
8984
|
if (stat.size === 0) {
|
|
8348
8985
|
return { lines: [], totalLinesCount: 0 };
|
|
8349
8986
|
}
|
|
8350
|
-
const fd =
|
|
8987
|
+
const fd = fs37.openSync(filePath, "r");
|
|
8351
8988
|
const chunkSize = 64 * 1024;
|
|
8352
8989
|
let position = stat.size;
|
|
8353
8990
|
let remainder = "";
|
|
@@ -8360,7 +8997,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
8360
8997
|
const length = Math.min(chunkSize, position);
|
|
8361
8998
|
position -= length;
|
|
8362
8999
|
const buffer = Buffer.alloc(length);
|
|
8363
|
-
|
|
9000
|
+
fs37.readSync(fd, buffer, 0, length, position);
|
|
8364
9001
|
let chunk = buffer.toString("utf8");
|
|
8365
9002
|
if (remainder) {
|
|
8366
9003
|
chunk += remainder;
|
|
@@ -8413,7 +9050,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
8413
9050
|
}
|
|
8414
9051
|
}
|
|
8415
9052
|
} finally {
|
|
8416
|
-
|
|
9053
|
+
fs37.closeSync(fd);
|
|
8417
9054
|
}
|
|
8418
9055
|
return { lines: collected.reverse(), totalLinesCount };
|
|
8419
9056
|
}
|
|
@@ -8422,11 +9059,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
8422
9059
|
if (!wantedLevelSet) {
|
|
8423
9060
|
return { lines: [], totalLinesCount: 0 };
|
|
8424
9061
|
}
|
|
8425
|
-
const stat =
|
|
9062
|
+
const stat = fs37.statSync(filePath);
|
|
8426
9063
|
if (stat.size === 0) {
|
|
8427
9064
|
return { lines: [], totalLinesCount: 0 };
|
|
8428
9065
|
}
|
|
8429
|
-
const fd =
|
|
9066
|
+
const fd = fs37.openSync(filePath, "r");
|
|
8430
9067
|
const chunkSize = 64 * 1024;
|
|
8431
9068
|
let position = stat.size;
|
|
8432
9069
|
let remainder = "";
|
|
@@ -8438,7 +9075,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
8438
9075
|
const length = Math.min(chunkSize, position);
|
|
8439
9076
|
position -= length;
|
|
8440
9077
|
const buffer = Buffer.alloc(length);
|
|
8441
|
-
|
|
9078
|
+
fs37.readSync(fd, buffer, 0, length, position);
|
|
8442
9079
|
let chunk = buffer.toString("utf8");
|
|
8443
9080
|
if (remainder) {
|
|
8444
9081
|
chunk += remainder;
|
|
@@ -8485,7 +9122,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
8485
9122
|
}
|
|
8486
9123
|
}
|
|
8487
9124
|
} finally {
|
|
8488
|
-
|
|
9125
|
+
fs37.closeSync(fd);
|
|
8489
9126
|
}
|
|
8490
9127
|
return { lines: collected.reverse(), totalLinesCount };
|
|
8491
9128
|
}
|
|
@@ -8978,30 +9615,30 @@ async function readLogsJsonResult(options) {
|
|
|
8978
9615
|
};
|
|
8979
9616
|
}
|
|
8980
9617
|
function resolveLogFilePath(logDir, type) {
|
|
8981
|
-
const base =
|
|
9618
|
+
const base = path32.isAbsolute(logDir) ? logDir : path32.join(process.cwd(), logDir);
|
|
8982
9619
|
if (type === "server") {
|
|
8983
|
-
return
|
|
9620
|
+
return path32.join(base, "server.log");
|
|
8984
9621
|
}
|
|
8985
9622
|
if (type === "trace") {
|
|
8986
|
-
return
|
|
9623
|
+
return path32.join(base, "trace.log");
|
|
8987
9624
|
}
|
|
8988
9625
|
if (type === "server-std") {
|
|
8989
|
-
return
|
|
9626
|
+
return path32.join(base, "server.std.log");
|
|
8990
9627
|
}
|
|
8991
9628
|
if (type === "client-std") {
|
|
8992
|
-
return
|
|
9629
|
+
return path32.join(base, "client.std.log");
|
|
8993
9630
|
}
|
|
8994
9631
|
if (type === "dev") {
|
|
8995
|
-
return
|
|
9632
|
+
return path32.join(base, "dev.log");
|
|
8996
9633
|
}
|
|
8997
9634
|
if (type === "dev-std") {
|
|
8998
|
-
return
|
|
9635
|
+
return path32.join(base, "dev.std.log");
|
|
8999
9636
|
}
|
|
9000
9637
|
if (type === "install-dep-std") {
|
|
9001
|
-
return
|
|
9638
|
+
return path32.join(base, "install-dep.std.log");
|
|
9002
9639
|
}
|
|
9003
9640
|
if (type === "browser") {
|
|
9004
|
-
return
|
|
9641
|
+
return path32.join(base, "browser.log");
|
|
9005
9642
|
}
|
|
9006
9643
|
throw new Error(`Unsupported log type: ${type}`);
|
|
9007
9644
|
}
|
|
@@ -9171,9 +9808,9 @@ function camelToKebab(str) {
|
|
|
9171
9808
|
}
|
|
9172
9809
|
|
|
9173
9810
|
// src/commands/build/upload-static.handler.ts
|
|
9174
|
-
import * as
|
|
9811
|
+
import * as fs38 from "fs";
|
|
9175
9812
|
import * as os3 from "os";
|
|
9176
|
-
import * as
|
|
9813
|
+
import * as path33 from "path";
|
|
9177
9814
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
9178
9815
|
function readCredentialsFromEnv() {
|
|
9179
9816
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -9197,8 +9834,8 @@ async function uploadStatic(options) {
|
|
|
9197
9834
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
9198
9835
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
9199
9836
|
} = options;
|
|
9200
|
-
const resolvedStaticDir =
|
|
9201
|
-
if (!
|
|
9837
|
+
const resolvedStaticDir = path33.resolve(staticDir);
|
|
9838
|
+
if (!fs38.existsSync(resolvedStaticDir)) {
|
|
9202
9839
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
9203
9840
|
return;
|
|
9204
9841
|
}
|
|
@@ -9231,8 +9868,8 @@ async function uploadStatic(options) {
|
|
|
9231
9868
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
9232
9869
|
}
|
|
9233
9870
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
9234
|
-
const confPath =
|
|
9235
|
-
|
|
9871
|
+
const confPath = path33.join(os3.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
9872
|
+
fs38.writeFileSync(confPath, "");
|
|
9236
9873
|
try {
|
|
9237
9874
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
9238
9875
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -9246,7 +9883,7 @@ async function uploadStatic(options) {
|
|
|
9246
9883
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
9247
9884
|
} finally {
|
|
9248
9885
|
try {
|
|
9249
|
-
|
|
9886
|
+
fs38.unlinkSync(confPath);
|
|
9250
9887
|
} catch {
|
|
9251
9888
|
}
|
|
9252
9889
|
}
|
|
@@ -9266,8 +9903,8 @@ async function uploadStatic(options) {
|
|
|
9266
9903
|
}
|
|
9267
9904
|
}
|
|
9268
9905
|
function resolveTosutilPath(tosutilPath) {
|
|
9269
|
-
if (
|
|
9270
|
-
return
|
|
9906
|
+
if (path33.isAbsolute(tosutilPath)) {
|
|
9907
|
+
return fs38.existsSync(tosutilPath) ? tosutilPath : null;
|
|
9271
9908
|
}
|
|
9272
9909
|
try {
|
|
9273
9910
|
const resolved = execFileSync2("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -9312,7 +9949,7 @@ async function resolveBucketId(appId) {
|
|
|
9312
9949
|
return bucketId;
|
|
9313
9950
|
}
|
|
9314
9951
|
function isDirEmpty(dirPath) {
|
|
9315
|
-
const entries =
|
|
9952
|
+
const entries = fs38.readdirSync(dirPath);
|
|
9316
9953
|
return entries.length === 0;
|
|
9317
9954
|
}
|
|
9318
9955
|
|
|
@@ -9408,13 +10045,13 @@ var commands = [
|
|
|
9408
10045
|
|
|
9409
10046
|
// src/index.ts
|
|
9410
10047
|
for (const filename of [".env.local", ".env"]) {
|
|
9411
|
-
const envPath =
|
|
9412
|
-
if (
|
|
10048
|
+
const envPath = path34.join(process.cwd(), filename);
|
|
10049
|
+
if (fs39.existsSync(envPath)) {
|
|
9413
10050
|
dotenvConfig({ path: envPath });
|
|
9414
10051
|
}
|
|
9415
10052
|
}
|
|
9416
|
-
var __dirname =
|
|
9417
|
-
var pkg = JSON.parse(
|
|
10053
|
+
var __dirname = path34.dirname(fileURLToPath5(import.meta.url));
|
|
10054
|
+
var pkg = JSON.parse(fs39.readFileSync(path34.join(__dirname, "../package.json"), "utf-8"));
|
|
9418
10055
|
var cli = new FullstackCLI(pkg.version);
|
|
9419
10056
|
cli.useAll(commands);
|
|
9420
10057
|
cli.run();
|