|
|
|
|
@@ -1,25 +1,57 @@
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
SSR_FILE="/app/apps/web/.output/server/_ssr/pdf-document-COfeOLVC.mjs"
|
|
|
|
|
PUBLIC_FILENAME_FILE="/app/apps/web/.output/public/assets/file-D5WsIgJH.js"
|
|
|
|
|
PUBLIC_PDF_FILE="/app/apps/web/.output/public/assets/pdf-document-BplbXx-0.js"
|
|
|
|
|
SERVER_INDEX_FILE="/app/apps/web/.output/server/index.mjs"
|
|
|
|
|
CACHE_BUST_FILENAME="rr-filename-title-20260520"
|
|
|
|
|
CACHE_BUST_PDF="rr-glalie-layout-20260520"
|
|
|
|
|
APP_DIR="${REACTIVE_RESUME_APP_DIR:-}"
|
|
|
|
|
if [ -z "$APP_DIR" ]; then
|
|
|
|
|
for candidate in /app/apps/web /app; do
|
|
|
|
|
if [ -f "$candidate/.output/server/index.mjs" ]; then
|
|
|
|
|
APP_DIR="$candidate"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "$APP_DIR" ]; then
|
|
|
|
|
index_file="$(find /app -path "*/.output/server/index.mjs" -type f 2>/dev/null | head -n 1 || true)"
|
|
|
|
|
if [ -n "$index_file" ]; then
|
|
|
|
|
APP_DIR="${index_file%/.output/server/index.mjs}"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -z "$APP_DIR" ] || [ ! -f "$APP_DIR/.output/server/index.mjs" ]; then
|
|
|
|
|
echo "Reactive Resume runtime patch skipped: .output/server/index.mjs not found under /app" >&2
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
printf "%s" "$APP_DIR" > /tmp/reactive-resume-app-dir
|
|
|
|
|
export APP_DIR
|
|
|
|
|
|
|
|
|
|
node - <<'NODE'
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const path = require("path");
|
|
|
|
|
const crypto = require("crypto");
|
|
|
|
|
|
|
|
|
|
const ssrFile = "/app/apps/web/.output/server/_ssr/pdf-document-COfeOLVC.mjs";
|
|
|
|
|
const publicFilenameFile = "/app/apps/web/.output/public/assets/file-D5WsIgJH.js";
|
|
|
|
|
const publicPdfFile = "/app/apps/web/.output/public/assets/pdf-document-BplbXx-0.js";
|
|
|
|
|
const serverIndexFile = "/app/apps/web/.output/server/index.mjs";
|
|
|
|
|
const appDir = process.env.APP_DIR;
|
|
|
|
|
const outputDir = path.join(appDir, ".output");
|
|
|
|
|
const assetsDir = path.join(outputDir, "public/assets");
|
|
|
|
|
const ssrDir = path.join(outputDir, "server/_ssr");
|
|
|
|
|
const serverIndexFile = path.join(outputDir, "server/index.mjs");
|
|
|
|
|
const filenameCacheBust = "rr-filename-title-20260520";
|
|
|
|
|
const pdfCacheBust = "rr-glalie-layout-20260520";
|
|
|
|
|
const browserBufferPolyfill = "var Buffer=globalThis.Buffer??{isBuffer:()=>false,allocUnsafe:e=>new Uint8Array(e),alloc:e=>new Uint8Array(e)};/* rr-browser-buffer-polyfill */";
|
|
|
|
|
|
|
|
|
|
function warn(message) {
|
|
|
|
|
console.warn(`Reactive Resume runtime patch: ${message}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function read(file) {
|
|
|
|
|
return fs.readFileSync(file, "utf8");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function write(file, source) {
|
|
|
|
|
fs.writeFileSync(file, source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function makeEtag(buffer) {
|
|
|
|
|
const digest = crypto.createHash("sha1").update(buffer).digest("base64").replace(/=+$/g, "");
|
|
|
|
|
return `"${buffer.length.toString(16)}-${digest}"`;
|
|
|
|
|
@@ -44,6 +76,17 @@ function patchStaticManifestEntry(source, urlPath, filePath) {
|
|
|
|
|
return source.slice(0, start) + entry + source.slice(end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function escapeRegex(value) {
|
|
|
|
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function listJsFiles(dir) {
|
|
|
|
|
if (!fs.existsSync(dir)) return [];
|
|
|
|
|
return fs.readdirSync(dir)
|
|
|
|
|
.filter((name) => name.endsWith(".js"))
|
|
|
|
|
.map((name) => path.join(dir, name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function replaceOnce(source, from, to) {
|
|
|
|
|
return source.includes(to) ? source : source.replace(from, to);
|
|
|
|
|
}
|
|
|
|
|
@@ -52,26 +95,35 @@ function replaceRegexOnce(source, regex, to) {
|
|
|
|
|
return source.includes(to) ? source : source.replace(regex, to);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function patchFilenameBundle() {
|
|
|
|
|
let source = fs.readFileSync(publicFilenameFile, "utf8");
|
|
|
|
|
function patchFilenameBundle(file) {
|
|
|
|
|
let source = read(file);
|
|
|
|
|
const replacement = 'function t(e,t){let n=(e||"resume").toString().trim()||"resume";return n=n.replace(/[\\\\/:*?"<>|]/g,"-").replace(/\\s+/g," ").replace(/\\.+$/,"").trim()||"resume",t&&n.toLowerCase().endsWith("."+t.toLowerCase())?n:`${n}${t?`.${t}`:""}`}';
|
|
|
|
|
if (!source.includes(replacement)) {
|
|
|
|
|
const start = source.indexOf("function t(");
|
|
|
|
|
const end = source.indexOf("function n(", start);
|
|
|
|
|
if (start === -1 || end === -1) throw new Error("filename function marker not found");
|
|
|
|
|
source = source.slice(0, start) + replacement + source.slice(end);
|
|
|
|
|
fs.writeFileSync(publicFilenameFile, source);
|
|
|
|
|
if (source.includes(replacement)) return true;
|
|
|
|
|
|
|
|
|
|
const start = source.indexOf("function t(");
|
|
|
|
|
const end = source.indexOf("function n(", start);
|
|
|
|
|
if (start === -1 || end === -1) {
|
|
|
|
|
warn(`filename bundle marker not found in ${path.basename(file)}, skipped`);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source = source.slice(0, start) + replacement + source.slice(end);
|
|
|
|
|
write(file, source);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function patchSsr(source) {
|
|
|
|
|
source = source.replace(/\n\t\tname: "",\n\t\tdata: \{/, "\n\t\tname: resume.name,\n\t\tdata: {");
|
|
|
|
|
|
|
|
|
|
const filenameReplacement = `function generateFilename(prefix, extension) {\n\tlet filename = (prefix || "resume").toString().trim() || "resume";\n\tfilename = filename.replace(/[\\\\/:*?"<>|]/g, "-").replace(/\\s+/g, " ").replace(/\\.+$/, "").trim() || "resume";\n\treturn extension && filename.toLowerCase().endsWith(\`.\${extension.toLowerCase()}\`) ? filename : \`\${filename}\${extension ? \`.\${extension}\` : ""}\`;\n}`;
|
|
|
|
|
if (!source.includes(filenameReplacement)) {
|
|
|
|
|
const start = source.indexOf("function generateFilename(");
|
|
|
|
|
const end = source.indexOf("\nfunction downloadWithAnchor(", start);
|
|
|
|
|
if (start === -1 || end === -1) throw new Error("SSR generateFilename marker not found");
|
|
|
|
|
source = source.slice(0, start) + filenameReplacement + source.slice(end);
|
|
|
|
|
if (start !== -1 && end !== -1) {
|
|
|
|
|
source = source.slice(0, start) + filenameReplacement + source.slice(end);
|
|
|
|
|
} else {
|
|
|
|
|
warn("SSR generateFilename marker not found, skipped");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source = source
|
|
|
|
|
@@ -82,6 +134,7 @@ function patchSsr(source) {
|
|
|
|
|
.replace(/style: composeStyles\(styles\.sidebarContent, \{ rowGap: metrics\.sectionGap \}\),/g, "style: composeStyles(styles.sidebarContent, { rowGap: metrics.gapY(3.0) }),")
|
|
|
|
|
.replace(/style: composeStyles\(styles\.mainContent, \{ rowGap: metrics\.sectionGap \}\),/g, "style: composeStyles(styles.mainContent, { rowGap: metrics.gapY(3.0) }),")
|
|
|
|
|
.replace(/sectionHeading: \{\s*borderBottomWidth: 1,\s*borderBottomColor: primary(?:,\s*paddingBottom: 1(?:\.3)?)?\s*\},/, "sectionHeading: {\n\t\t\t\t\tborderBottomWidth: 1,\n\t\t\t\t\tborderBottomColor: primary,\n\t\t\t\t\tpaddingBottom: 1.3\n\t\t\t\t},");
|
|
|
|
|
|
|
|
|
|
source = replaceRegexOnce(
|
|
|
|
|
source,
|
|
|
|
|
/sectionHeading: \{\s*borderBottomWidth: 1,\s*borderBottomColor: primary,\s*paddingBottom: 1(?:\.3)?\s*\},\s*item: \{ rowGap: metrics\.gapY\(\.125\) \},/,
|
|
|
|
|
@@ -100,15 +153,16 @@ function patchSsr(source) {
|
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ensureBrowserBufferPolyfill(source) {
|
|
|
|
|
if (source.includes("rr-browser-buffer-polyfill")) return source;
|
|
|
|
|
const insertAt = source.indexOf(";") + 1;
|
|
|
|
|
if (insertAt <= 0 || !source.startsWith("import")) throw new Error("PDF bundle import prelude not found");
|
|
|
|
|
return source.slice(0, insertAt) + browserBufferPolyfill + source.slice(insertAt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function patchPublicPdf(source) {
|
|
|
|
|
source = ensureBrowserBufferPolyfill(source);
|
|
|
|
|
if (!source.includes("rr-browser-buffer-polyfill")) {
|
|
|
|
|
const insertAt = source.indexOf(";") + 1;
|
|
|
|
|
if (insertAt > 0 && source.startsWith("import")) {
|
|
|
|
|
source = source.slice(0, insertAt) + browserBufferPolyfill + source.slice(insertAt);
|
|
|
|
|
} else {
|
|
|
|
|
warn("PDF bundle import prelude not found, Buffer shim skipped");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source = source
|
|
|
|
|
.replace(/([A-Za-z_$][\w$]*)=([A-Za-z_$][\w$]*)\*\.(?:2|08);return\{paragraph:\{marginTop:\1,marginBottom:\1\},listItem:\{marginTop:\1,marginBottom:\1\}\}/, "$1=$2*.08;return{paragraph:{marginTop:$1,marginBottom:$1},listItem:{marginTop:$1,marginBottom:$1}}")
|
|
|
|
|
.replace(/[oc]\.gapY\(3\.5\)/g, (m) => `${m[0]}.gapY(3.0)`)
|
|
|
|
|
@@ -118,43 +172,80 @@ function patchPublicPdf(source) {
|
|
|
|
|
.replace(/style:\$\(a\.mainContent,\{rowGap:o\.sectionGap\}\)/g, "style:$(a.mainContent,{rowGap:o.gapY(3.0)})")
|
|
|
|
|
.replace(/sectionHeading:\{borderBottomWidth:1,borderBottomColor:a(?:,paddingBottom:1(?:\.3)?)?\}/, "sectionHeading:{borderBottomWidth:1,borderBottomColor:a,paddingBottom:1.3}")
|
|
|
|
|
.replace(/sectionHeading:\{borderBottomWidth:1,borderBottomColor:a,paddingBottom:1(?:\.3)?\},item:\{rowGap:([a-zA-Z_$][\w$]*)\.gapY\(\.125\)\}/, "sectionHeading:{borderBottomWidth:1,borderBottomColor:a,paddingBottom:1.3},sectionItems:{paddingTop:$1.gapY(.55)},item:{rowGap:$1.gapY(.2)}");
|
|
|
|
|
|
|
|
|
|
source = replaceOnce(source, "sidebarColumn:{zIndex:1,backgroundColor:o,paddingHorizontal:c.page.paddingHorizontal,paddingTop:c.page.paddingVertical,rowGap:c.sectionGap}", "sidebarColumn:{zIndex:1,backgroundColor:o,paddingHorizontal:c.page.paddingHorizontal,paddingTop:c.page.paddingVertical,paddingBottom:c.page.paddingVertical,rowGap:c.gapY(3.0)}");
|
|
|
|
|
source = replaceOnce(source, "mainContent:{paddingHorizontal:c.page.paddingHorizontal,paddingTop:c.page.paddingVertical}", "mainContent:{paddingHorizontal:c.page.paddingHorizontal,paddingTop:c.page.paddingVertical,paddingBottom:c.page.paddingVertical}");
|
|
|
|
|
return source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function patchImporters() {
|
|
|
|
|
const assetsDir = "/app/apps/web/.output/public/assets";
|
|
|
|
|
const files = fs.readdirSync(assetsDir).filter((name) => name.endsWith(".js")).map((name) => `${assetsDir}/${name}`);
|
|
|
|
|
const touched = [];
|
|
|
|
|
for (const file of files) {
|
|
|
|
|
let source = fs.readFileSync(file, "utf8");
|
|
|
|
|
let next = source
|
|
|
|
|
.replace(/\.\/file-D5WsIgJH\.js(?:\?v=rr-filename-[A-Za-z0-9-]+)?/g, `./file-D5WsIgJH.js?v=${filenameCacheBust}`)
|
|
|
|
|
.replace(/\.\/pdf-document-BplbXx-0\.js(?:\?v=rr-[^"'`]+)?/g, `./pdf-document-BplbXx-0.js?v=${pdfCacheBust}`);
|
|
|
|
|
if (next !== source) {
|
|
|
|
|
fs.writeFileSync(file, next);
|
|
|
|
|
touched.push(file);
|
|
|
|
|
}
|
|
|
|
|
const assetFiles = listJsFiles(assetsDir);
|
|
|
|
|
const filenameFiles = assetFiles
|
|
|
|
|
.filter((file) => {
|
|
|
|
|
const source = read(file);
|
|
|
|
|
return source.includes("URL.createObjectURL") && source.includes(".download");
|
|
|
|
|
})
|
|
|
|
|
.sort((a, b) => fs.statSync(a).size - fs.statSync(b).size);
|
|
|
|
|
|
|
|
|
|
const patchedFilenameFiles = [];
|
|
|
|
|
for (const file of filenameFiles) {
|
|
|
|
|
if (patchFilenameBundle(file)) patchedFilenameFiles.push(file);
|
|
|
|
|
}
|
|
|
|
|
if (patchedFilenameFiles.length === 0) warn("no filename bundle patched");
|
|
|
|
|
|
|
|
|
|
let ssrFile = "";
|
|
|
|
|
if (fs.existsSync(ssrDir)) {
|
|
|
|
|
ssrFile = fs.readdirSync(ssrDir)
|
|
|
|
|
.filter((name) => name.endsWith(".mjs"))
|
|
|
|
|
.map((name) => path.join(ssrDir, name))
|
|
|
|
|
.find((file) => read(file).includes("function generateFilename(")) || "";
|
|
|
|
|
}
|
|
|
|
|
if (ssrFile) {
|
|
|
|
|
write(ssrFile, patchSsr(read(ssrFile)));
|
|
|
|
|
} else {
|
|
|
|
|
warn("SSR bundle with generateFilename not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pdfFile = assetFiles
|
|
|
|
|
.filter((file) => path.basename(file).startsWith("pdf-document-"))
|
|
|
|
|
.sort((a, b) => fs.statSync(b).size - fs.statSync(a).size)[0] || "";
|
|
|
|
|
if (pdfFile) {
|
|
|
|
|
write(pdfFile, patchPublicPdf(read(pdfFile)));
|
|
|
|
|
} else {
|
|
|
|
|
warn("public PDF bundle not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const filenameBases = patchedFilenameFiles.map((file) => path.basename(file));
|
|
|
|
|
const pdfBase = pdfFile ? path.basename(pdfFile) : "";
|
|
|
|
|
const touchedImporters = [];
|
|
|
|
|
for (const file of assetFiles) {
|
|
|
|
|
let source = read(file);
|
|
|
|
|
let next = source;
|
|
|
|
|
for (const base of filenameBases) {
|
|
|
|
|
next = next.replace(new RegExp(`\\./${escapeRegex(base)}(?:\\?v=rr-filename-[A-Za-z0-9-]+)?`, "g"), `./${base}?v=${filenameCacheBust}`);
|
|
|
|
|
}
|
|
|
|
|
if (pdfBase) {
|
|
|
|
|
next = next.replace(new RegExp(`\\./${escapeRegex(pdfBase)}(?:\\?v=rr-[^"'\\\`]+)?`, "g"), `./${pdfBase}?v=${pdfCacheBust}`);
|
|
|
|
|
}
|
|
|
|
|
if (next !== source) {
|
|
|
|
|
write(file, next);
|
|
|
|
|
touchedImporters.push(file);
|
|
|
|
|
}
|
|
|
|
|
return touched;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
patchFilenameBundle();
|
|
|
|
|
fs.writeFileSync(ssrFile, patchSsr(fs.readFileSync(ssrFile, "utf8")));
|
|
|
|
|
fs.writeFileSync(publicPdfFile, patchPublicPdf(fs.readFileSync(publicPdfFile, "utf8")));
|
|
|
|
|
const importers = patchImporters();
|
|
|
|
|
|
|
|
|
|
let serverIndex = fs.readFileSync(serverIndexFile, "utf8");
|
|
|
|
|
serverIndex = patchStaticManifestEntry(serverIndex, "/assets/file-D5WsIgJH.js", publicFilenameFile);
|
|
|
|
|
serverIndex = patchStaticManifestEntry(serverIndex, "/assets/pdf-document-BplbXx-0.js", publicPdfFile);
|
|
|
|
|
for (const file of importers) {
|
|
|
|
|
serverIndex = patchStaticManifestEntry(serverIndex, `/assets/${file.split("/").pop()}`, file);
|
|
|
|
|
if (fs.existsSync(serverIndexFile)) {
|
|
|
|
|
let serverIndex = read(serverIndexFile);
|
|
|
|
|
for (const file of [...patchedFilenameFiles, pdfFile, ...touchedImporters].filter(Boolean)) {
|
|
|
|
|
serverIndex = patchStaticManifestEntry(serverIndex, `/assets/${path.basename(file)}`, file);
|
|
|
|
|
}
|
|
|
|
|
write(serverIndexFile, serverIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const file of [...patchedFilenameFiles, pdfFile, ssrFile, serverIndexFile].filter(Boolean)) {
|
|
|
|
|
try {
|
|
|
|
|
new Function(read(file));
|
|
|
|
|
} catch {
|
|
|
|
|
// ESM/import bundles are validated by Node at application startup; keep this
|
|
|
|
|
// best-effort so a harmless syntax-check limitation never blocks boot.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fs.writeFileSync(serverIndexFile, serverIndex);
|
|
|
|
|
NODE
|
|
|
|
|
|
|
|
|
|
node --check "$SSR_FILE" >/dev/null
|
|
|
|
|
node --check "$PUBLIC_FILENAME_FILE" >/dev/null
|
|
|
|
|
node --check "$PUBLIC_PDF_FILE" >/dev/null
|
|
|
|
|
node --check "$SERVER_INDEX_FILE" >/dev/null
|
|
|
|
|
|