mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 05:56:19 -10:00
refactor(web): centralize isolated script paths
This commit is contained in:
1 parent
8dc4421325
commit
bfdde7ee4c
2 files changed
+9
-10
No files matched your search
@@ -18,6 +18,7 @@ import {
|
||||
type WebScriptExportResult,
|
||||
} from "../../domain/webScriptExport.js";
|
||||
import {
|
||||
isolatedWebScriptPath,
|
||||
planWebScriptExport,
|
||||
type PlannedWebScript,
|
||||
} from "../../domain/webScriptExportPlan.js";
|
||||
@@ -212,7 +213,7 @@ const publishPlannedScript = async (
|
||||
record.content.layout !== "url-path"
|
||||
)
|
||||
throw cause;
|
||||
const relativePath = isolatedScriptPath(script, index);
|
||||
const relativePath = isolatedWebScriptPath(script.source, index);
|
||||
await write(relativePath);
|
||||
return {
|
||||
...record,
|
||||
@@ -226,11 +227,5 @@ const publishPlannedScript = async (
|
||||
}
|
||||
};
|
||||
|
||||
const isolatedScriptPath = (
|
||||
script: PlannedWebScript["script"],
|
||||
index: number,
|
||||
): string =>
|
||||
`isolated/source-${index + 1}-${createHash("sha256").update(JSON.stringify(script.source)).digest("hex")}.js`;
|
||||
|
||||
const message = (cause: unknown): string =>
|
||||
cause instanceof Error ? cause.message : "Unknown publication failure";
|
||||
@@ -17,6 +17,12 @@ export interface PlannedWebScript {
|
||||
readonly record: ExportedWebScript;
|
||||
}
|
||||
|
||||
/** Stable isolated identity shared by planning and destination collision fallback. */
|
||||
export const isolatedWebScriptPath = (
|
||||
source: CapturedWebScript["source"],
|
||||
index: number,
|
||||
): string => `isolated/source-${index + 1}-${hash(JSON.stringify(source))}.js`;
|
||||
|
||||
/** Preserve safe URL layouts only when every captured path is unambiguous. */
|
||||
export const planWebScriptExport = (
|
||||
scripts: readonly CapturedWebScript[],
|
||||
@@ -45,9 +51,7 @@ export const planWebScriptExport = (
|
||||
url: script.url,
|
||||
content: {
|
||||
state: "exported",
|
||||
relative_path:
|
||||
path ??
|
||||
`isolated/source-${index + 1}-${hash(JSON.stringify(script.source))}.js`,
|
||||
relative_path: path ?? isolatedWebScriptPath(script.source, index),
|
||||
layout: path === undefined ? "isolated" : "url-path",
|
||||
layout_reason: reason,
|
||||
sha256: script.content.sha256,
|
||||
|
||||
Reference in new issue
Block a user