replicas-engine 0.1.46 → 0.1.48
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/src/index.js +28 -22
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -872,14 +872,14 @@ function parseWarmHookConfig(value) {
|
|
|
872
872
|
if (!isRecord2(value)) {
|
|
873
873
|
throw new Error('Invalid replicas.json: "warmHook" must be a string or object');
|
|
874
874
|
}
|
|
875
|
-
if (
|
|
876
|
-
throw new Error('Invalid replicas.json: "warmHook.
|
|
875
|
+
if (!Array.isArray(value.commands) || !value.commands.every((entry) => typeof entry === "string")) {
|
|
876
|
+
throw new Error('Invalid replicas.json: "warmHook.commands" must be an array of shell commands');
|
|
877
877
|
}
|
|
878
878
|
if (value.timeout !== void 0 && (typeof value.timeout !== "number" || value.timeout <= 0)) {
|
|
879
879
|
throw new Error('Invalid replicas.json: "warmHook.timeout" must be a positive number');
|
|
880
880
|
}
|
|
881
881
|
return {
|
|
882
|
-
|
|
882
|
+
commands: value.commands,
|
|
883
883
|
timeout: value.timeout
|
|
884
884
|
};
|
|
885
885
|
}
|
|
@@ -888,12 +888,12 @@ function resolveWarmHookConfig(value) {
|
|
|
888
888
|
return null;
|
|
889
889
|
}
|
|
890
890
|
const parsed = parseWarmHookConfig(value);
|
|
891
|
-
const
|
|
892
|
-
if (
|
|
891
|
+
const commands = typeof parsed === "string" ? [parsed.trim()].filter(Boolean) : parsed.commands.map((command) => command.trim()).filter(Boolean);
|
|
892
|
+
if (commands.length === 0) {
|
|
893
893
|
return null;
|
|
894
894
|
}
|
|
895
895
|
return {
|
|
896
|
-
|
|
896
|
+
commands,
|
|
897
897
|
timeoutMs: typeof parsed === "string" ? void 0 : parsed.timeout
|
|
898
898
|
};
|
|
899
899
|
}
|
|
@@ -2867,8 +2867,12 @@ async function readRepoWarmHook(repoPath) {
|
|
|
2867
2867
|
return null;
|
|
2868
2868
|
}
|
|
2869
2869
|
return resolveWarmHookConfig(parsed.warmHook);
|
|
2870
|
-
} catch {
|
|
2871
|
-
|
|
2870
|
+
} catch (error) {
|
|
2871
|
+
const nodeError = error;
|
|
2872
|
+
if (nodeError?.code === "ENOENT") {
|
|
2873
|
+
return null;
|
|
2874
|
+
}
|
|
2875
|
+
throw error;
|
|
2872
2876
|
}
|
|
2873
2877
|
}
|
|
2874
2878
|
async function collectRepoWarmHooks() {
|
|
@@ -2882,7 +2886,7 @@ async function collectRepoWarmHooks() {
|
|
|
2882
2886
|
collected.push({
|
|
2883
2887
|
repoName: repo.name,
|
|
2884
2888
|
repoPath: repo.path,
|
|
2885
|
-
|
|
2889
|
+
commands: warmHook.commands,
|
|
2886
2890
|
timeoutMs: warmHook.timeoutMs
|
|
2887
2891
|
});
|
|
2888
2892
|
}
|
|
@@ -2911,19 +2915,21 @@ async function runWarmHooks(params) {
|
|
|
2911
2915
|
if (params.includeRepoHooks !== false) {
|
|
2912
2916
|
const repoHooks = await collectRepoWarmHooks();
|
|
2913
2917
|
for (const repoHook of repoHooks) {
|
|
2914
|
-
const
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2918
|
+
for (const command of repoHook.commands) {
|
|
2919
|
+
const repoResult = await executeHookScript({
|
|
2920
|
+
label: `repo-warm-hook:${repoHook.repoName}`,
|
|
2921
|
+
cwd: repoHook.repoPath,
|
|
2922
|
+
content: command,
|
|
2923
|
+
timeoutMs: repoHook.timeoutMs
|
|
2924
|
+
});
|
|
2925
|
+
outputBlocks.push(repoResult.output);
|
|
2926
|
+
if (repoResult.exitCode !== 0) {
|
|
2927
|
+
return {
|
|
2928
|
+
exitCode: repoResult.exitCode,
|
|
2929
|
+
output: outputBlocks.join("\n\n"),
|
|
2930
|
+
timedOut: repoResult.timedOut
|
|
2931
|
+
};
|
|
2932
|
+
}
|
|
2927
2933
|
}
|
|
2928
2934
|
}
|
|
2929
2935
|
}
|