@format.dev/compile 0.3.0 → 0.4.0
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/server/compile/document-assets.d.mts.map +1 -1
- package/dist/server/compile/document-assets.mjs +19 -4
- package/dist/server/compile/document-assets.mjs.map +1 -1
- package/dist/server/compile/producer-release.mjs +2 -2
- package/dist/server/render-worker/client.d.mts +1 -1
- package/dist/server/render-worker/client.d.mts.map +1 -1
- package/dist/server/render-worker/client.mjs +3 -2
- package/dist/server/render-worker/client.mjs.map +1 -1
- package/dist/server/render-worker/host.mjs.map +1 -1
- package/dist/server/render-worker/permission-flag.d.mts +13 -0
- package/dist/server/render-worker/permission-flag.d.mts.map +1 -0
- package/dist/server/render-worker/permission-flag.mjs +17 -0
- package/dist/server/render-worker/permission-flag.mjs.map +1 -0
- package/dist/server/render-worker/sandbox.d.mts +1 -1
- package/dist/server/render-worker/sandbox.mjs +1 -1
- package/dist/server/render-worker/sandbox.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-assets.d.mts","names":[],"sources":["../../../src/server/compile/document-assets.ts"],"sourcesContent":[],"mappings":";;;;cAUa,wBAAA;AAAb;AAUA;AAKC;AAUD;;;;;
|
|
1
|
+
{"version":3,"file":"document-assets.d.mts","names":[],"sources":["../../../src/server/compile/document-assets.ts"],"sourcesContent":[],"mappings":";;;;cAUa,wBAAA;AAAb;AAUA;AAKC;AAUD;;;;;AA4FiB,UA3GA,oBAAA,CA+GX;EAkBgB,eAAA,EAAA,MAAA,GAAA,IAAyB;EACrC,iBAAA,EAAA,MAAA,GAAA,IAAA;EAEC;EAAR,UAAA,EAAA,MAAA,GAAA,IAAA;;AA4BH,UAzJU,kBAAA,CAyJO;EAiBD;EAiBC,aAAA,EAAA,MAAA;EAuBK,MAAA,EA/Mb,YA+Ma;EACb,MAAA,EAAA,MAAA;EAGG,sBAAA,EAAA,MAAA;;AAAD,iBA9MW,2BAAA,CA8MX,IAAA,EA9M6C,kBA8M7C,CAAA,EA9MkE,OA8MlE,CA9M0E,oBA8M1E,CAAA;AAwCW,UA1JL,kBAAA,CA0J+B;EAGjC;EACH,KAAA,EAAA,MAAA,EAAA;EAAR;EAAO,GAAA,EA1JL,UA0JK,GAAA,SAAA;;;;;;;;;;;iBAxIW,yBAAA,UACZ,2CAEP,QAAQ;UA4BM,yBAAA;;;;;;;;;;;;;;;;iBAiBD,uBAAA;;;UAGP;IACL;UAaa,mBAAA;;;;;;;UAOR;;;;;;;;;;;;;;;iBAgBa,8BAAA;UACb;;;IAGL,QAAQ;;;;;;;iBAwCU,0BAAA;;;gBAGP;IACX,QAAQ"}
|
|
@@ -26,14 +26,23 @@ async function resolveDocumentAssetSources(args) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Dotfiles such as `.gitkeep` hold a folder in git or carry tool settings. They
|
|
30
|
+
* are never assets, so they are left out without the "renders can't use" warning
|
|
31
|
+
* that real files of an unsupported type get.
|
|
32
|
+
*/
|
|
33
|
+
function isDotfile(file) {
|
|
34
|
+
return basename(file).startsWith(".");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Recursively list a directory's files as '/'-separated paths relative to it,
|
|
38
|
+
* dotfiles included.
|
|
30
39
|
*
|
|
31
40
|
* Walks by hand with `stat` (not `readdir({ recursive: true })`) so it descends
|
|
32
41
|
* through symlinked directories. Asset roots are often wired up with symlinks —
|
|
33
42
|
* a shared `assets/` dir linked into a project, for example — and those files
|
|
34
43
|
* must still be discovered and shipped.
|
|
35
44
|
*/
|
|
36
|
-
async function
|
|
45
|
+
async function listAllFiles(dir) {
|
|
37
46
|
const walk = async (current) => {
|
|
38
47
|
const entries = await readdir(current, { withFileTypes: true }).catch(() => []);
|
|
39
48
|
return (await Promise.all(entries.map(async (entry) => {
|
|
@@ -46,6 +55,10 @@ async function listFiles(dir) {
|
|
|
46
55
|
};
|
|
47
56
|
return (await walk(dir)).map((file) => relative(dir, file).split("\\").join("/")).sort();
|
|
48
57
|
}
|
|
58
|
+
/** The files in a directory that could be assets: everything but dotfiles. */
|
|
59
|
+
async function listFiles(dir) {
|
|
60
|
+
return (await listAllFiles(dir)).filter((file) => !isDotfile(file));
|
|
61
|
+
}
|
|
49
62
|
/**
|
|
50
63
|
* Copy the document-scoped sources (shared assets dir, then the per-document
|
|
51
64
|
* `./assets/` folder on top — last write wins) into `destDir`.
|
|
@@ -88,10 +101,12 @@ async function buildDocumentStaticAssets(sources, stagingDir) {
|
|
|
88
101
|
});
|
|
89
102
|
}
|
|
90
103
|
try {
|
|
91
|
-
const
|
|
104
|
+
const everything = await listAllFiles(stagingDir);
|
|
105
|
+
const files = everything.filter((file) => !isDotfile(file));
|
|
92
106
|
const known = files.filter((file) => isRenderableAsset(file));
|
|
93
107
|
const unsupported = files.filter((file) => !isRenderableAsset(file));
|
|
94
|
-
|
|
108
|
+
const leftOut = everything.filter((file) => !known.includes(file));
|
|
109
|
+
await Promise.all(leftOut.map((file) => rm(join(stagingDir, file), { force: true })));
|
|
95
110
|
return {
|
|
96
111
|
known,
|
|
97
112
|
zip: await zipDir(stagingDir),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-assets.mjs","names":["urlMap: Record<string, string>"],"sources":["../../../src/server/compile/document-assets.ts"],"sourcesContent":["import type { FormatConfig } from '../../shared/types'\n\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path'\nimport { cp, mkdir, readdir, rm, stat } from 'node:fs/promises'\nimport { isUserAssetExtension } from '@format.dev/utils'\nimport { zipDir, isSystemJunkFile } from '@format.dev/zip'\nimport { getSharedAssetsDir } from '../project/paths'\nimport { checkDir } from '../utils'\n\n/** Reserved co-location folder: `documents/<name>/assets/` travels with the document. */\nexport const DOCUMENT_ASSETS_DIR_NAME = 'assets'\n\n/**\n * Everything that can contribute files to one document's asset set:\n * the shared assets dir, the document's own `./assets/` folder, and the\n * Vite-emitted output (hashed images and fonts). The shared assets dir and the\n * Vite-emitted output both live in the bundle's shared `shared-assets/` dir;\n * the document's `./assets/` lands under `<doc>/assets/`. On filename clash the\n * per-document folder wins.\n */\nexport interface DocumentAssetSources {\n\tsharedAssetsDir: string | null\n\tdocumentAssetsDir: string | null\n\t/** The shared Vite-emitted dir (hashed images + fonts), or null when absent. */\n\temittedDir: string | null\n}\n\ninterface ResolveSourcesArgs {\n\t/** The document's entry file path — its `assets/` sibling is the per-doc folder. */\n\tentryFilePath: string\n\tconfig: FormatConfig\n\toutDir: string\n\tsharedAssetsOutDirName: string\n}\n\nexport async function resolveDocumentAssetSources(args: ResolveSourcesArgs): Promise<DocumentAssetSources> {\n\tconst { entryFilePath, config, outDir, sharedAssetsOutDirName } = args\n\n\tconst sharedAssetsDir = getSharedAssetsDir(config)\n\tconst documentAssetsDir = join(dirname(entryFilePath), DOCUMENT_ASSETS_DIR_NAME)\n\tconst emittedDir = resolve(outDir, sharedAssetsOutDirName)\n\n\tconst [sharedOk, perDocOk, emittedOk] = await Promise.all([\n\t\tcheckDir(sharedAssetsDir),\n\t\tcheckDir(documentAssetsDir),\n\t\tcheckDir(emittedDir)\n\t])\n\n\treturn {\n\t\tsharedAssetsDir: sharedOk.isDirectory ? sharedAssetsDir : null,\n\t\tdocumentAssetsDir: perDocOk.isDirectory ? documentAssetsDir : null,\n\t\temittedDir: emittedOk.isDirectory ? emittedDir : null\n\t}\n}\n\n/**\n * Recursively list a directory's files as '/'-separated paths relative to it.\n *\n * Walks by hand with `stat` (not `readdir({ recursive: true })`) so it descends\n * through symlinked directories. Asset roots are often wired up with symlinks —\n * a shared `assets/` dir linked into a project, for example — and those files\n * must still be discovered and shipped.\n */\nasync function listFiles(dir: string): Promise<string[]> {\n\tconst walk = async (current: string): Promise<string[]> => {\n\t\tconst entries = await readdir(current, { withFileTypes: true }).catch(() => [])\n\n\t\tconst nested = await Promise.all(\n\t\t\tentries.map(async entry => {\n\t\t\t\tconst entryPath = join(current, entry.name)\n\t\t\t\tconst stats = await stat(entryPath).catch(() => null)\n\n\t\t\t\tif (!stats) {\n\t\t\t\t\treturn []\n\t\t\t\t}\n\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\treturn walk(entryPath)\n\t\t\t\t}\n\n\t\t\t\tconst isShippableFile = stats.isFile() && !isSystemJunkFile(entry.name)\n\n\t\t\t\treturn isShippableFile ? [entryPath] : []\n\t\t\t})\n\t\t)\n\n\t\treturn nested.flat()\n\t}\n\n\tconst files = await walk(dir)\n\n\treturn files.map(file => relative(dir, file).split('\\\\').join('/')).sort()\n}\n\n/**\n * Copy the document-scoped sources (shared assets dir, then the per-document\n * `./assets/` folder on top — last write wins) into `destDir`.\n */\nasync function overlayDocumentSources(sources: DocumentAssetSources, destDir: string) {\n\tawait mkdir(destDir, { recursive: true })\n\n\tif (sources.sharedAssetsDir) {\n\t\tawait cp(sources.sharedAssetsDir, destDir, { recursive: true, force: true, dereference: true })\n\t}\n\n\tif (sources.documentAssetsDir) {\n\t\tawait cp(sources.documentAssetsDir, destDir, { recursive: true, force: true, dereference: true })\n\t}\n}\n\nexport interface StaticAssetsResult {\n\t/** Zip entry names — the document's known-asset set. Empty when no assets. */\n\tknown: string[]\n\t/** The merged archive, or undefined when the document has no assets. */\n\tzip: Uint8Array | undefined\n\t/** Files left out because renders can't use their type, such as a font licence `.txt`. */\n\tunsupported: string[]\n}\n\n// The same check the render API applies when it unpacks the zip. It refuses the\n// whole archive over one unknown type, so these files must never reach it.\nfunction isRenderableAsset(file: string) {\n\treturn isUserAssetExtension(extname(file).slice(1).toLowerCase())\n}\n\n/**\n * Build one document's merged `assets.zip` (static mode): the full merged set,\n * with no filtering by rendered HTML — any variant renders from the same zip.\n *\n * Standalone by design: callable without emitting any JS wrapper, so HTML\n * output (`format compile --output=html`) can reuse the same artefact.\n */\nexport async function buildDocumentStaticAssets(\n\tsources: DocumentAssetSources,\n\tstagingDir: string\n): Promise<StaticAssetsResult> {\n\tawait rm(stagingDir, { recursive: true, force: true })\n\tawait overlayDocumentSources(sources, stagingDir)\n\n\tif (sources.emittedDir) {\n\t\tconst emittedName = sources.emittedDir.split('\\\\').join('/').split('/').pop()!\n\t\tawait cp(sources.emittedDir, join(stagingDir, emittedName), { recursive: true, force: true, dereference: true })\n\t}\n\n\ttry {\n\t\tconst files = await listFiles(stagingDir)\n\t\tconst known = files.filter(file => isRenderableAsset(file))\n\t\tconst unsupported = files.filter(file => !isRenderableAsset(file))\n\n\t\tawait Promise.all(unsupported.map(file => rm(join(stagingDir, file), { force: true })))\n\n\t\tconst zip = await zipDir(stagingDir)\n\n\t\treturn { known, zip, unsupported }\n\t} finally {\n\t\tawait rm(stagingDir, { recursive: true, force: true }).catch(() => {})\n\t}\n}\n\nexport interface CompiledDynamicAssetEntry {\n\t/** The known-asset path (URL map key) this file backs. */\n\tknownPath: string\n\t/** Absolute path of the file in the compiled outDir. */\n\tsourcePath: string\n\t/** '/'-separated path for emission into a consumer bundle, mirroring the outDir layout. */\n\temitPath: string\n}\n\n/**\n * Turn a compiled document's dynamic-mode URL map into per-file emit entries,\n * for consumers that re-host the assets (the unplugin, Next.js). The map value\n * is each file's location relative to the document's `index.js`, so it already\n * encodes the on-disk path — no need to re-scan the output or re-infer which\n * dir a file came from. `<doc>/assets/x` → emitted under the document; a\n * `../shared-assets/x` value → emitted under the shared dir, shared across docs.\n */\nexport function dynamicAssetEmitEntries(args: {\n\toutDir: string\n\tdocumentName: string\n\turlMap: Record<string, string>\n}): CompiledDynamicAssetEntry[] {\n\tconst { outDir, documentName, urlMap } = args\n\n\tconst documentOutDir = join(outDir, documentName)\n\n\treturn Object.entries(urlMap).map(([knownPath, url]) => {\n\t\tconst sourcePath = resolve(documentOutDir, url)\n\t\tconst emitPath = relative(outDir, sourcePath).split('\\\\').join('/')\n\n\t\treturn { knownPath, sourcePath, emitPath }\n\t})\n}\n\nexport interface DynamicAssetsResult {\n\t/** The document's known-asset set (map keys). Empty when no assets. */\n\tknown: string[]\n\t/**\n\t * Known-asset path → URL relative to the document's `index.js`. The wrapper\n\t * resolves each against `import.meta.url` at render time.\n\t */\n\turlMap: Record<string, string>\n}\n\n/**\n * Materialise the dynamic-mode shared asset layout once per build and return the\n * shared portion of every document's URL map (relative to a document dir). Both\n * the `sharedAssetsDir` contents and the Vite-emitted output (hashed images +\n * fonts) live in the bundle's `shared-assets/` dir, so they are shared across\n * documents and never duplicated.\n *\n * Their map keys differ by how the rendered HTML references them: author files\n * from `sharedAssetsDir` are referenced by their bare path (e.g. `cube.svg`),\n * while Vite rewrites its emitted references to include the dir (e.g.\n * `shared-assets/chart-abc.png`). We snapshot the Vite-emitted files *before*\n * copying `sharedAssetsDir` in, so the two are never confused.\n */\nexport async function materialiseSharedDynamicAssets(args: {\n\tconfig: FormatConfig\n\toutDir: string\n\tsharedAssetsOutDirName: string\n}): Promise<Record<string, string>> {\n\tconst { config, outDir, sharedAssetsOutDirName } = args\n\n\tconst sharedAssetsOutDir = resolve(outDir, sharedAssetsOutDirName)\n\tconst sharedName = basename(sharedAssetsOutDir)\n\n\tconst sharedAssetsSource = getSharedAssetsDir(config)\n\tconst [sharedSourceOk, emittedOk] = await Promise.all([checkDir(sharedAssetsSource), checkDir(sharedAssetsOutDir)])\n\n\tconst sharedAssetsDir = sharedSourceOk.isDirectory ? sharedAssetsSource : null\n\tconst emittedDir = emittedOk.isDirectory ? sharedAssetsOutDir : null\n\n\tconst urlMap: Record<string, string> = {}\n\n\t// Vite emits straight into the shared dir, so its current contents are the\n\t// emitted files — snapshot them before the sharedAssetsDir copy lands on top.\n\tconst emittedRels = emittedDir ? await listFiles(emittedDir) : []\n\n\tfor (const rel of emittedRels) {\n\t\turlMap[`${sharedName}/${rel}`] = `../${sharedName}/${rel}`\n\t}\n\n\tif (sharedAssetsDir) {\n\t\tawait mkdir(sharedAssetsOutDir, { recursive: true })\n\t\tawait cp(sharedAssetsDir, sharedAssetsOutDir, { recursive: true, force: true, dereference: true })\n\n\t\tfor (const rel of await listFiles(sharedAssetsDir)) {\n\t\t\turlMap[rel] = `../${sharedName}/${rel}`\n\t\t}\n\t}\n\n\treturn urlMap\n}\n\n/**\n * Materialise one document's own runtime asset layout (dynamic mode) and return\n * its full URL map. The document's `./assets/` folder is copied to\n * `<documentOutDir>/assets/**` (bare keys, document-local urls); the shared\n * entries are merged in on top with the per-document folder winning on clash.\n */\nexport async function buildDocumentDynamicAssets(args: {\n\tdocumentAssetsDir: string | null\n\tdocumentOutDir: string\n\tsharedUrlMap: Record<string, string>\n}): Promise<DynamicAssetsResult> {\n\tconst { documentAssetsDir, documentOutDir, sharedUrlMap } = args\n\n\tconst runtimeAssetsDir = join(documentOutDir, DOCUMENT_ASSETS_DIR_NAME)\n\n\tawait rm(runtimeAssetsDir, { recursive: true, force: true })\n\n\tconst urlMap: Record<string, string> = { ...sharedUrlMap }\n\n\tif (documentAssetsDir) {\n\t\tawait mkdir(runtimeAssetsDir, { recursive: true })\n\t\tawait cp(documentAssetsDir, runtimeAssetsDir, { recursive: true, force: true, dereference: true })\n\n\t\tfor (const rel of await listFiles(runtimeAssetsDir)) {\n\t\t\turlMap[rel] = `./${DOCUMENT_ASSETS_DIR_NAME}/${rel}`\n\t\t}\n\t}\n\n\treturn { known: Object.keys(urlMap).sort(), urlMap }\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAa,2BAA2B;AAyBxC,eAAsB,4BAA4B,MAAyD;CAC1G,MAAM,EAAE,eAAe,QAAQ,QAAQ,2BAA2B;CAElE,MAAM,kBAAkB,mBAAmB,OAAO;CAClD,MAAM,oBAAoB,KAAK,QAAQ,cAAc,EAAE,yBAAyB;CAChF,MAAM,aAAa,QAAQ,QAAQ,uBAAuB;CAE1D,MAAM,CAAC,UAAU,UAAU,aAAa,MAAM,QAAQ,IAAI;EACzD,SAAS,gBAAgB;EACzB,SAAS,kBAAkB;EAC3B,SAAS,WAAW;EACpB,CAAC;AAEF,QAAO;EACN,iBAAiB,SAAS,cAAc,kBAAk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B,aAAa,MAAM,QAAQ,IAAI,CAAC,SAAS,mBAAmB,EAAE,SAAS,mBAAmB,CAAC,CAAC;CAEnH,MAAM,kBAAkB,eAAe,cAAc,qBAAqB;CAC1E,MAAM,aAAa,UAAU,cAAc,qBAAqB;CAEhE,MAAMA,SAAiC,EAAE;CAIzC,MAAM,cAAc,aAAa,MAAM,UAAU,WAAW,GAAG,EAAE;AAEjE,MAAK,MAAM,OAAO,YACjB,QAAO,GAAG,WAAW,GAAG,SAAS,MAAM,WAAW,GAAG;AAGtD,KAAI,iBAAiB;AACpB,QAAM,MAAM,oBAAoB,EAAE,WAAW,MAAM,CAAC;AACpD,QAAM,GAAG,iBAAiB,oBAAoB;GAAE,WAAW;GAAM,OAAO;GAAM,aAAa;GAAM,CAAC;AAElG,OAAK,MAAM,OAAO,MAAM,UAAU,gBAAgB,CACjD,QAAO,OAAO,MAAM,WAAW,GAAG;;AAIpC,QAAO;;;;;;;;AASR,eAAsB,2BAA2B,MAIhB;CAChC,MAAM,EAAE,mBAAmB,gBAAgB,iBAAiB;CAE5D,MAAM,mBAAmB,KAAK,gBAAgB,yBAAyB;AAEvE,OAAM,GAAG,kBAAkB;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC;CAE5D,MAAMA,SAAiC,EAAE,GAAG,cAAc;AAE1D,KAAI,mBAAmB;AACtB,QAAM,MAAM,kBAAkB,EAAE,WAAW,MAAM,CAAC;AAClD,QAAM,GAAG,mBAAmB,kBAAkB;GAAE,WAAW;GAAM,OAAO;GAAM,aAAa;GAAM,CAAC;AAElG,OAAK,MAAM,OAAO,MAAM,UAAU,iBAAiB,CAClD,QAAO,OAAO,KAAK,yBAAyB,GAAG;;AAIjD,QAAO;EAAE,OAAO,OAAO,KAAK,OAAO,CAAC,MAAM;EAAE;EAAQ"}
|
|
1
|
+
{"version":3,"file":"document-assets.mjs","names":["urlMap: Record<string, string>"],"sources":["../../../src/server/compile/document-assets.ts"],"sourcesContent":["import type { FormatConfig } from '../../shared/types'\n\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path'\nimport { cp, mkdir, readdir, rm, stat } from 'node:fs/promises'\nimport { isUserAssetExtension } from '@format.dev/utils'\nimport { zipDir, isSystemJunkFile } from '@format.dev/zip'\nimport { getSharedAssetsDir } from '../project/paths'\nimport { checkDir } from '../utils'\n\n/** Reserved co-location folder: `documents/<name>/assets/` travels with the document. */\nexport const DOCUMENT_ASSETS_DIR_NAME = 'assets'\n\n/**\n * Everything that can contribute files to one document's asset set:\n * the shared assets dir, the document's own `./assets/` folder, and the\n * Vite-emitted output (hashed images and fonts). The shared assets dir and the\n * Vite-emitted output both live in the bundle's shared `shared-assets/` dir;\n * the document's `./assets/` lands under `<doc>/assets/`. On filename clash the\n * per-document folder wins.\n */\nexport interface DocumentAssetSources {\n\tsharedAssetsDir: string | null\n\tdocumentAssetsDir: string | null\n\t/** The shared Vite-emitted dir (hashed images + fonts), or null when absent. */\n\temittedDir: string | null\n}\n\ninterface ResolveSourcesArgs {\n\t/** The document's entry file path — its `assets/` sibling is the per-doc folder. */\n\tentryFilePath: string\n\tconfig: FormatConfig\n\toutDir: string\n\tsharedAssetsOutDirName: string\n}\n\nexport async function resolveDocumentAssetSources(args: ResolveSourcesArgs): Promise<DocumentAssetSources> {\n\tconst { entryFilePath, config, outDir, sharedAssetsOutDirName } = args\n\n\tconst sharedAssetsDir = getSharedAssetsDir(config)\n\tconst documentAssetsDir = join(dirname(entryFilePath), DOCUMENT_ASSETS_DIR_NAME)\n\tconst emittedDir = resolve(outDir, sharedAssetsOutDirName)\n\n\tconst [sharedOk, perDocOk, emittedOk] = await Promise.all([\n\t\tcheckDir(sharedAssetsDir),\n\t\tcheckDir(documentAssetsDir),\n\t\tcheckDir(emittedDir)\n\t])\n\n\treturn {\n\t\tsharedAssetsDir: sharedOk.isDirectory ? sharedAssetsDir : null,\n\t\tdocumentAssetsDir: perDocOk.isDirectory ? documentAssetsDir : null,\n\t\temittedDir: emittedOk.isDirectory ? emittedDir : null\n\t}\n}\n\n/**\n * Dotfiles such as `.gitkeep` hold a folder in git or carry tool settings. They\n * are never assets, so they are left out without the \"renders can't use\" warning\n * that real files of an unsupported type get.\n */\nfunction isDotfile(file: string) {\n\treturn basename(file).startsWith('.')\n}\n\n/**\n * Recursively list a directory's files as '/'-separated paths relative to it,\n * dotfiles included.\n *\n * Walks by hand with `stat` (not `readdir({ recursive: true })`) so it descends\n * through symlinked directories. Asset roots are often wired up with symlinks —\n * a shared `assets/` dir linked into a project, for example — and those files\n * must still be discovered and shipped.\n */\nasync function listAllFiles(dir: string): Promise<string[]> {\n\tconst walk = async (current: string): Promise<string[]> => {\n\t\tconst entries = await readdir(current, { withFileTypes: true }).catch(() => [])\n\n\t\tconst nested = await Promise.all(\n\t\t\tentries.map(async entry => {\n\t\t\t\tconst entryPath = join(current, entry.name)\n\t\t\t\tconst stats = await stat(entryPath).catch(() => null)\n\n\t\t\t\tif (!stats) {\n\t\t\t\t\treturn []\n\t\t\t\t}\n\n\t\t\t\tif (stats.isDirectory()) {\n\t\t\t\t\treturn walk(entryPath)\n\t\t\t\t}\n\n\t\t\t\tconst isShippableFile = stats.isFile() && !isSystemJunkFile(entry.name)\n\n\t\t\t\treturn isShippableFile ? [entryPath] : []\n\t\t\t})\n\t\t)\n\n\t\treturn nested.flat()\n\t}\n\n\tconst files = await walk(dir)\n\n\treturn files.map(file => relative(dir, file).split('\\\\').join('/')).sort()\n}\n\n/** The files in a directory that could be assets: everything but dotfiles. */\nasync function listFiles(dir: string): Promise<string[]> {\n\tconst files = await listAllFiles(dir)\n\n\treturn files.filter(file => !isDotfile(file))\n}\n\n/**\n * Copy the document-scoped sources (shared assets dir, then the per-document\n * `./assets/` folder on top — last write wins) into `destDir`.\n */\nasync function overlayDocumentSources(sources: DocumentAssetSources, destDir: string) {\n\tawait mkdir(destDir, { recursive: true })\n\n\tif (sources.sharedAssetsDir) {\n\t\tawait cp(sources.sharedAssetsDir, destDir, { recursive: true, force: true, dereference: true })\n\t}\n\n\tif (sources.documentAssetsDir) {\n\t\tawait cp(sources.documentAssetsDir, destDir, { recursive: true, force: true, dereference: true })\n\t}\n}\n\nexport interface StaticAssetsResult {\n\t/** Zip entry names — the document's known-asset set. Empty when no assets. */\n\tknown: string[]\n\t/** The merged archive, or undefined when the document has no assets. */\n\tzip: Uint8Array | undefined\n\t/** Files left out because renders can't use their type, such as a font licence `.txt`. */\n\tunsupported: string[]\n}\n\n// The same check the render API applies when it unpacks the zip. It refuses the\n// whole archive over one unknown type, so these files must never reach it.\nfunction isRenderableAsset(file: string) {\n\treturn isUserAssetExtension(extname(file).slice(1).toLowerCase())\n}\n\n/**\n * Build one document's merged `assets.zip` (static mode): the full merged set,\n * with no filtering by rendered HTML — any variant renders from the same zip.\n *\n * Standalone by design: callable without emitting any JS wrapper, so HTML\n * output (`format compile --output=html`) can reuse the same artefact.\n */\nexport async function buildDocumentStaticAssets(\n\tsources: DocumentAssetSources,\n\tstagingDir: string\n): Promise<StaticAssetsResult> {\n\tawait rm(stagingDir, { recursive: true, force: true })\n\tawait overlayDocumentSources(sources, stagingDir)\n\n\tif (sources.emittedDir) {\n\t\tconst emittedName = sources.emittedDir.split('\\\\').join('/').split('/').pop()!\n\t\tawait cp(sources.emittedDir, join(stagingDir, emittedName), { recursive: true, force: true, dereference: true })\n\t}\n\n\ttry {\n\t\tconst everything = await listAllFiles(stagingDir)\n\t\tconst files = everything.filter(file => !isDotfile(file))\n\t\tconst known = files.filter(file => isRenderableAsset(file))\n\t\tconst unsupported = files.filter(file => !isRenderableAsset(file))\n\n\t\t// The render API refuses the whole archive over one unknown type, so dotfiles go too.\n\t\tconst leftOut = everything.filter(file => !known.includes(file))\n\n\t\tawait Promise.all(leftOut.map(file => rm(join(stagingDir, file), { force: true })))\n\n\t\tconst zip = await zipDir(stagingDir)\n\n\t\treturn { known, zip, unsupported }\n\t} finally {\n\t\tawait rm(stagingDir, { recursive: true, force: true }).catch(() => {})\n\t}\n}\n\nexport interface CompiledDynamicAssetEntry {\n\t/** The known-asset path (URL map key) this file backs. */\n\tknownPath: string\n\t/** Absolute path of the file in the compiled outDir. */\n\tsourcePath: string\n\t/** '/'-separated path for emission into a consumer bundle, mirroring the outDir layout. */\n\temitPath: string\n}\n\n/**\n * Turn a compiled document's dynamic-mode URL map into per-file emit entries,\n * for consumers that re-host the assets (the unplugin, Next.js). The map value\n * is each file's location relative to the document's `index.js`, so it already\n * encodes the on-disk path — no need to re-scan the output or re-infer which\n * dir a file came from. `<doc>/assets/x` → emitted under the document; a\n * `../shared-assets/x` value → emitted under the shared dir, shared across docs.\n */\nexport function dynamicAssetEmitEntries(args: {\n\toutDir: string\n\tdocumentName: string\n\turlMap: Record<string, string>\n}): CompiledDynamicAssetEntry[] {\n\tconst { outDir, documentName, urlMap } = args\n\n\tconst documentOutDir = join(outDir, documentName)\n\n\treturn Object.entries(urlMap).map(([knownPath, url]) => {\n\t\tconst sourcePath = resolve(documentOutDir, url)\n\t\tconst emitPath = relative(outDir, sourcePath).split('\\\\').join('/')\n\n\t\treturn { knownPath, sourcePath, emitPath }\n\t})\n}\n\nexport interface DynamicAssetsResult {\n\t/** The document's known-asset set (map keys). Empty when no assets. */\n\tknown: string[]\n\t/**\n\t * Known-asset path → URL relative to the document's `index.js`. The wrapper\n\t * resolves each against `import.meta.url` at render time.\n\t */\n\turlMap: Record<string, string>\n}\n\n/**\n * Materialise the dynamic-mode shared asset layout once per build and return the\n * shared portion of every document's URL map (relative to a document dir). Both\n * the `sharedAssetsDir` contents and the Vite-emitted output (hashed images +\n * fonts) live in the bundle's `shared-assets/` dir, so they are shared across\n * documents and never duplicated.\n *\n * Their map keys differ by how the rendered HTML references them: author files\n * from `sharedAssetsDir` are referenced by their bare path (e.g. `cube.svg`),\n * while Vite rewrites its emitted references to include the dir (e.g.\n * `shared-assets/chart-abc.png`). We snapshot the Vite-emitted files *before*\n * copying `sharedAssetsDir` in, so the two are never confused.\n */\nexport async function materialiseSharedDynamicAssets(args: {\n\tconfig: FormatConfig\n\toutDir: string\n\tsharedAssetsOutDirName: string\n}): Promise<Record<string, string>> {\n\tconst { config, outDir, sharedAssetsOutDirName } = args\n\n\tconst sharedAssetsOutDir = resolve(outDir, sharedAssetsOutDirName)\n\tconst sharedName = basename(sharedAssetsOutDir)\n\n\tconst sharedAssetsSource = getSharedAssetsDir(config)\n\tconst [sharedSourceOk, emittedOk] = await Promise.all([checkDir(sharedAssetsSource), checkDir(sharedAssetsOutDir)])\n\n\tconst sharedAssetsDir = sharedSourceOk.isDirectory ? sharedAssetsSource : null\n\tconst emittedDir = emittedOk.isDirectory ? sharedAssetsOutDir : null\n\n\tconst urlMap: Record<string, string> = {}\n\n\t// Vite emits straight into the shared dir, so its current contents are the\n\t// emitted files — snapshot them before the sharedAssetsDir copy lands on top.\n\tconst emittedRels = emittedDir ? await listFiles(emittedDir) : []\n\n\tfor (const rel of emittedRels) {\n\t\turlMap[`${sharedName}/${rel}`] = `../${sharedName}/${rel}`\n\t}\n\n\tif (sharedAssetsDir) {\n\t\tawait mkdir(sharedAssetsOutDir, { recursive: true })\n\t\tawait cp(sharedAssetsDir, sharedAssetsOutDir, { recursive: true, force: true, dereference: true })\n\n\t\tfor (const rel of await listFiles(sharedAssetsDir)) {\n\t\t\turlMap[rel] = `../${sharedName}/${rel}`\n\t\t}\n\t}\n\n\treturn urlMap\n}\n\n/**\n * Materialise one document's own runtime asset layout (dynamic mode) and return\n * its full URL map. The document's `./assets/` folder is copied to\n * `<documentOutDir>/assets/**` (bare keys, document-local urls); the shared\n * entries are merged in on top with the per-document folder winning on clash.\n */\nexport async function buildDocumentDynamicAssets(args: {\n\tdocumentAssetsDir: string | null\n\tdocumentOutDir: string\n\tsharedUrlMap: Record<string, string>\n}): Promise<DynamicAssetsResult> {\n\tconst { documentAssetsDir, documentOutDir, sharedUrlMap } = args\n\n\tconst runtimeAssetsDir = join(documentOutDir, DOCUMENT_ASSETS_DIR_NAME)\n\n\tawait rm(runtimeAssetsDir, { recursive: true, force: true })\n\n\tconst urlMap: Record<string, string> = { ...sharedUrlMap }\n\n\tif (documentAssetsDir) {\n\t\tawait mkdir(runtimeAssetsDir, { recursive: true })\n\t\tawait cp(documentAssetsDir, runtimeAssetsDir, { recursive: true, force: true, dereference: true })\n\n\t\tfor (const rel of await listFiles(runtimeAssetsDir)) {\n\t\t\turlMap[rel] = `./${DOCUMENT_ASSETS_DIR_NAME}/${rel}`\n\t\t}\n\t}\n\n\treturn { known: Object.keys(urlMap).sort(), urlMap }\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAa,2BAA2B;AAyBxC,eAAsB,4BAA4B,MAAyD;CAC1G,MAAM,EAAE,eAAe,QAAQ,QAAQ,2BAA2B;CAElE,MAAM,kBAAkB,mBAAmB,OAAO;CAClD,MAAM,oBAAoB,KAAK,QAAQ,cAAc,EAAE,yBAAyB;CAChF,MAAM,aAAa,QAAQ,QAAQ,uBAAuB;CAE1D,MAAM,CAAC,UAAU,UAAU,aAAa,MAAM,QAAQ,IAAI;EACzD,SAAS,gBAAgB;EACzB,SAAS,kBAAkB;EAC3B,SAAS,WAAW;EACpB,CAAC;AAEF,QAAO;EACN,iBAAiB,SAAS,cAAc,kBAAkB;EAC1D,mBAAmB,SAAS,cAAc,oBAAoB;EAC9D,YAAY,UAAU,cAAc,aAAa;EACjD;;;;;;;AAQF,SAAS,UAAU,MAAc;AAChC,QAAO,SAAS,KAAK,CAAC,WAAW,IAAI;;;;;;;;;;;AAYtC,eAAe,aAAa,KAAgC;CAC3D,MAAM,OAAO,OAAO,YAAuC;EAC1D,MAAM,UAAU,MAAM,QAAQ,SAAS,EAAE,eAAe,MAAM,CAAC,CAAC,YAAY,EAAE,CAAC;AAqB/E,UAnBe,MAAM,QAAQ,IAC5B,QAAQ,IAAI,OAAM,UAAS;GAC1B,MAAM,YAAY,KAAK,SAAS,MAAM,KAAK;GAC3C,MAAM,QAAQ,MAAM,KAAK,UAAU,CAAC,YAAY,KAAK;AAErD,OAAI,CAAC,MACJ,QAAO,EAAE;AAGV,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AAM,cAAc,aAAa,MAAM,UAAU,WAAW,GAAG,EAAE;AAEjE,MAAK,MAAM,OAAO,YACjB,QAAO,GAAG,WAAW,GAAG,SAAS,MAAM,WAAW,GAAG;AAGtD,KAAI,iBAAiB;AACpB,QAAM,MAAM,oBAAoB,EAAE,WAAW,MAAM,CAAC;AACpD,QAAM,GAAG,iBAAiB,oBAAoB;GAAE,WAAW;GAAM,OAAO;GAAM,aAAa;GAAM,CAAC;AAElG,OAAK,MAAM,OAAO,MAAM,UAAU,gBAAgB,CACjD,QAAO,OAAO,MAAM,WAAW,GAAG;;AAIpC,QAAO;;;;;;;;AASR,eAAsB,2BAA2B,MAIhB;CAChC,MAAM,EAAE,mBAAmB,gBAAgB,iBAAiB;CAE5D,MAAM,mBAAmB,KAAK,gBAAgB,yBAAyB;AAEvE,OAAM,GAAG,kBAAkB;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC;CAE5D,MAAMA,SAAiC,EAAE,GAAG,cAAc;AAE1D,KAAI,mBAAmB;AACtB,QAAM,MAAM,kBAAkB,EAAE,WAAW,MAAM,CAAC;AAClD,QAAM,GAAG,mBAAmB,kBAAkB;GAAE,WAAW;GAAM,OAAO;GAAM,aAAa;GAAM,CAAC;AAElG,OAAK,MAAM,OAAO,MAAM,UAAU,iBAAiB,CAClD,QAAO,OAAO,KAAK,yBAAyB,GAAG;;AAIjD,QAAO;EAAE,OAAO,OAAO,KAAK,OAAO,CAAC,MAAM;EAAE;EAAQ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/server/compile/producer-release.ts
|
|
2
|
-
const sdkVersion = "0.
|
|
3
|
-
const engineTarget = "0.
|
|
2
|
+
const sdkVersion = "0.4.0";
|
|
3
|
+
const engineTarget = "0.4.0";
|
|
4
4
|
/**
|
|
5
5
|
* The `define` entries a renderer build needs so its output names both the
|
|
6
6
|
* release that produced it and the engine it targets.
|
|
@@ -17,7 +17,7 @@ interface RenderWorkerOptions {
|
|
|
17
17
|
/**
|
|
18
18
|
* Sandbox mode for the worker subprocess.
|
|
19
19
|
*
|
|
20
|
-
* - 'strict': Node's
|
|
20
|
+
* - 'strict': Node's permission model with filesystem scoping.
|
|
21
21
|
* No native addons, worker threads, or child processes. Used by compile
|
|
22
22
|
* where the subprocess just does import() on a pre-built bundle.
|
|
23
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":[],"sources":["../../../src/server/render-worker/client.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../../../src/server/render-worker/client.ts"],"sourcesContent":[],"mappings":";;;;AAihB+D,UAvU9C,mBAAA,CAuU8C;EAe/B,OAAA,CAAA,EAAA,MAAA;EAAL;EAA4C,GAAA,CAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA;EAarD;EAAO,IAAA,CAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;cArUZ,YAAA;;;;;;;;;;;;;wBAuBU;;;;;;;;gBAyLF,KAAK,iCAAiC;;;;;;;;;;;;;;;;;;;aAiEzC;kBAwBK,KAAK,mCAAmC;;;sBAepC,KAAK,uCAAuC;aAarD"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _dirname } from "../project/paths.mjs";
|
|
2
2
|
import { buildSafeEnv } from "./env.mjs";
|
|
3
3
|
import { deserializeError } from "./error.mjs";
|
|
4
|
+
import { getPermissionFlag } from "./permission-flag.mjs";
|
|
4
5
|
import { SANDBOX_ERROR_CODE } from "./sandbox.mjs";
|
|
5
6
|
import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs";
|
|
6
7
|
import { dirname, resolve } from "node:path";
|
|
@@ -22,7 +23,7 @@ function getWorkerHostPath() {
|
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Compute the minimal set of filesystem paths the render worker needs
|
|
25
|
-
* read access to. Used with Node's
|
|
26
|
+
* read access to. Used with Node's permission model to
|
|
26
27
|
* prevent user template code from reading sensitive files (.env, ~/.ssh, etc.).
|
|
27
28
|
*
|
|
28
29
|
* The worker needs:
|
|
@@ -156,7 +157,7 @@ var RenderWorker = class {
|
|
|
156
157
|
const allowedWritePaths = [realTmpDir + "/*"];
|
|
157
158
|
execArgv = [
|
|
158
159
|
"--no-warnings",
|
|
159
|
-
|
|
160
|
+
getPermissionFlag(),
|
|
160
161
|
...allowedReadPaths.map((p) => `--allow-fs-read=${p}`),
|
|
161
162
|
...allowedWritePaths.map((p) => `--allow-fs-write=${p}`)
|
|
162
163
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":["resolved: string","gapDirs: string[]","entries: string[]","execArgv: string[]","realTmpDir: string","pending"],"sources":["../../../src/server/render-worker/client.ts"],"sourcesContent":["/**\n * Main-process client for the render worker subprocess.\n *\n * Manages worker lifecycle (spawn, restart, dispose) and provides\n * typed methods for compile-path and dev-server-path rendering.\n *\n * For dev-server rendering, the subprocess runs its own headless Vite\n * server with the same plugin configuration. All module resolution,\n * transforms, and evaluation happen in the subprocess — the main\n * process just sends render requests and receives final HTML.\n */\n\nimport type {\n\tWorkerRequest,\n\tWorkerResponse,\n\tRenderResult,\n\tCompileRenderRequest,\n\tDevRenderRequest,\n\tDevInitRequest\n} from './types'\n\nimport { fork, type ChildProcess } from 'node:child_process'\nimport { dirname, resolve } from 'node:path'\nimport { randomUUID } from 'node:crypto'\nimport { existsSync, readdirSync, realpathSync } from 'node:fs'\nimport { tmpdir } from 'node:os'\nimport { buildSafeEnv } from './env'\nimport { deserializeError } from './error'\nimport { SANDBOX_ERROR_CODE } from './sandbox'\nimport { _dirname } from '../project/paths'\n\n/**\n * Resolve the path to the compiled worker host entry point. The dist is\n * unbundled, so host.js sits next to this module at dist/server/render-worker/.\n * In dev/test _dirname points to src/, so fall back to the built dist.\n */\nfunction getWorkerHostPath(): string {\n\tconst fromDist = resolve(_dirname, 'server', 'render-worker', 'host.mjs')\n\tif (existsSync(fromDist)) return fromDist\n\treturn resolve(_dirname, '..', 'dist', 'server', 'render-worker', 'host.mjs')\n}\n\n/**\n * Compute the minimal set of filesystem paths the render worker needs\n * read access to. Used with Node's --experimental-permission model to\n * prevent user template code from reading sensitive files (.env, ~/.ssh, etc.).\n *\n * The worker needs:\n * 1. Its own dist directory (compiled worker host + chunks)\n * 2. node_modules directories (for externalized deps like vite, react, vue)\n * 3. The Node.js installation directory (for native addons, if any)\n * 4. Any extra paths provided by the caller (e.g. project source dirs)\n */\nfunction computeAllowedReadPaths(extraPaths?: string[]): string[] {\n\tconst paths = new Set<string>()\n\n\t/**\n\t * Add a directory to the allowed set. Uses realpathSync so symlinked\n\t * directories (e.g. /tmp → /private/tmp on macOS) match what the\n\t * permission model actually checks.\n\t *\n\t * The `/*` suffix is required — Node 22's permission model treats\n\t * bare paths as exact-file matches. `dir/*` grants recursive read\n\t * access to all files under `dir` (including `stat(dir)` itself).\n\t */\n\tconst addDir = (dir: string) => {\n\t\tlet resolved: string\n\n\t\ttry {\n\t\t\tresolved = realpathSync(resolve(dir))\n\t\t} catch {\n\t\t\tresolved = resolve(dir)\n\t\t}\n\n\t\tif (resolved.endsWith('/')) {\n\t\t\tresolved = resolved.slice(0, -1)\n\t\t}\n\n\t\tpaths.add(resolved + '/*')\n\t}\n\n\t// Worker's own code directory (dist/node/)\n\taddDir(dirname(getWorkerHostPath()))\n\n\t/**\n\t * Walk up from a directory, adding every node_modules found.\n\t * Also resolves symlinks inside each node_modules — pnpm workspace\n\t * packages are symlinked to their real source directories, and Node's\n\t * permission model checks the real path, not the symlink.\n\t *\n\t * Intermediate directories between consecutive node_modules are also\n\t * added because Node's module resolver does stat() on\n\t * `<dir>/node_modules` at every level. Without read permission on\n\t * these gaps, the Permission Model throws ERR_ACCESS_DENIED (instead\n\t * of ENOENT), which breaks module resolution entirely.\n\t */\n\tconst findNodeModules = (startDir: string) => {\n\t\tlet dir = resolve(startDir)\n\t\tconst gapDirs: string[] = []\n\n\t\twhile (true) {\n\t\t\tconst nm = resolve(dir, 'node_modules')\n\n\t\t\tif (existsSync(nm)) {\n\t\t\t\taddDir(nm)\n\t\t\t\tresolveSymlinkedPackages(nm)\n\n\t\t\t\tfor (const gap of gapDirs) {\n\t\t\t\t\taddDir(gap)\n\t\t\t\t}\n\t\t\t\tgapDirs.length = 0\n\t\t\t} else {\n\t\t\t\tgapDirs.push(dir)\n\t\t\t}\n\n\t\t\tconst parent = dirname(dir)\n\t\t\tif (parent === dir) break\n\t\t\tdir = parent\n\t\t}\n\t}\n\n\t/** Resolve symlinks in a node_modules directory (top-level + scoped). */\n\tconst resolveSymlinkedPackages = (nmDir: string) => {\n\t\tlet entries: string[]\n\n\t\ttry {\n\t\t\tentries = readdirSync(nmDir)\n\t\t} catch {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const entry of entries) {\n\t\t\tconst entryPath = resolve(nmDir, entry)\n\n\t\t\tif (entry.startsWith('@')) {\n\t\t\t\tresolveSymlinkedPackages(entryPath)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst realPath = realpathSync(entryPath)\n\t\t\t\tif (realPath !== entryPath) {\n\t\t\t\t\taddDir(realPath)\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Broken symlink or inaccessible — skip\n\t\t\t}\n\t\t}\n\t}\n\n\t// Find node_modules from the worker's dist dir and the project cwd.\n\t// Covers pnpm workspace hoisting where deps live at the monorepo root.\n\tfindNodeModules(dirname(getWorkerHostPath()))\n\tfindNodeModules(process.cwd())\n\n\t// For extra paths (e.g. project source dirs, compile output dirs):\n\t// walk up to the workspace root, adding each directory and any\n\t// node_modules found along the way. Vite's searchForWorkspaceRoot\n\t// calls existsSync() in every ancestor looking for markers like\n\t// .git and pnpm-workspace.yaml. Without read permission on these\n\t// directories the Permission Model throws ERR_ACCESS_DENIED\n\t// (instead of ENOENT), which crashes Vite during init.\n\t//\n\t// We stop at the workspace root (.git or pnpm-workspace.yaml) so\n\t// ancestor directories above the project (e.g. ~/.ssh, ~/.aws)\n\t// remain inaccessible.\n\tif (extraPaths) {\n\t\tfor (const p of extraPaths) {\n\t\t\tlet dir = resolve(p)\n\t\t\twhile (true) {\n\t\t\t\taddDir(dir)\n\n\t\t\t\tconst nm = resolve(dir, 'node_modules')\n\t\t\t\tif (existsSync(nm)) {\n\t\t\t\t\taddDir(nm)\n\t\t\t\t\tresolveSymlinkedPackages(nm)\n\t\t\t\t}\n\n\t\t\t\tconst isWorkspaceRoot = existsSync(resolve(dir, '.git')) || existsSync(resolve(dir, 'pnpm-workspace.yaml'))\n\n\t\t\t\tif (isWorkspaceRoot) break\n\n\t\t\t\tconst parent = dirname(dir)\n\t\t\t\tif (parent === dir) break\n\t\t\t\tdir = parent\n\t\t\t}\n\t\t}\n\t}\n\n\t// Node.js installation — needed for native addons and internal resolution\n\taddDir(dirname(process.execPath))\n\n\treturn [...paths]\n}\n\ninterface PendingRequest {\n\tresolve: (result: RenderResult) => void\n\treject: (error: Error) => void\n\ttimer: ReturnType<typeof setTimeout>\n}\n\nexport interface RenderWorkerOptions {\n\ttimeout?: number\n\t/** Custom log function — defaults to console.debug */\n\tlog?: (msg: string) => void\n\t/** Custom warn function — defaults to console.warn */\n\twarn?: (msg: string) => void\n\t/**\n\t * Extra filesystem paths the worker is allowed to read.\n\t * The worker always has read access to its own dist directory and\n\t * node_modules. Use this for additional paths like project source dirs.\n\t */\n\tallowedReadPaths?: string[]\n\t/**\n\t * Sandbox mode for the worker subprocess.\n\t *\n\t * - 'strict': Node's --experimental-permission model with filesystem scoping.\n\t * No native addons, worker threads, or child processes. Used by compile\n\t * where the subprocess just does import() on a pre-built bundle.\n\t *\n\t * - 'standard': JS-level API patches that block network (fetch, http, net),\n\t * child_process, and other exfiltration vectors. Used by the dev path\n\t * where Vite's toolchain needs unrestricted filesystem access.\n\t *\n\t * - false: no sandbox. Worker still runs with a scrubbed environment.\n\t *\n\t * Both modes run with a scrubbed environment (env.ts allowlist).\n\t */\n\tsandbox?: 'strict' | 'standard' | false\n}\n\nexport class RenderWorker {\n\tprivate worker: ChildProcess | null = null\n\tprivate pending = new Map<string, PendingRequest>()\n\tprivate readyPromise: Promise<void> | null = null\n\tprivate timeout: number\n\tprivate log: (msg: string) => void\n\tprivate _warn: (msg: string) => void\n\tprivate allowedReadPaths?: string[]\n\tprivate sandbox: 'strict' | 'standard' | false\n\t// Replayed by restart() so a fresh subprocess re-initializes its headless\n\t// Vite server the same way the original dev-init call did.\n\tprivate lastInitArgs: Omit<DevInitRequest, 'id' | 'type'> | null = null\n\t// True while the current subprocess has a dev-init'd headless Vite server.\n\t// Cleared on dispose and on unexpected worker exit, so ensureDevInit()\n\t// knows a freshly spawned subprocess still needs its init replayed.\n\tprivate devInitialized = false\n\t// In-flight dev-init, shared so concurrent renders await one init\n\t// instead of each sending their own.\n\tprivate devInitPromise: Promise<void> | null = null\n\t// Held for the duration of a restart (dispose + dev-init). Renders await it so\n\t// one can't land in the gap after dispose() and spawn a fresh, un-init'd worker.\n\tprivate restartPromise: Promise<void> | null = null\n\n\tconstructor(options?: RenderWorkerOptions) {\n\t\tthis.timeout = options?.timeout ?? 30_000\n\t\tthis.log = options?.log ?? ((msg: string) => console.debug(msg))\n\t\tthis._warn = options?.warn ?? ((msg: string) => console.warn(msg))\n\t\tthis.allowedReadPaths = options?.allowedReadPaths\n\t\tthis.sandbox = options?.sandbox ?? false\n\t}\n\n\tprivate spawn(): ChildProcess {\n\t\tconst hostPath = getWorkerHostPath()\n\t\tconst env = buildSafeEnv()\n\n\t\tlet execArgv: string[] = []\n\n\t\tif (this.sandbox === 'strict') {\n\t\t\tconst allowedReadPaths = computeAllowedReadPaths(this.allowedReadPaths)\n\n\t\t\tlet realTmpDir: string\n\t\t\ttry {\n\t\t\t\trealTmpDir = realpathSync(tmpdir())\n\t\t\t} catch {\n\t\t\t\trealTmpDir = tmpdir()\n\t\t\t}\n\t\t\tconst allowedWritePaths = [realTmpDir + '/*']\n\n\t\t\texecArgv = [\n\t\t\t\t'--no-warnings',\n\t\t\t\t'--experimental-permission',\n\t\t\t\t...allowedReadPaths.map(p => `--allow-fs-read=${p}`),\n\t\t\t\t...allowedWritePaths.map(p => `--allow-fs-write=${p}`)\n\t\t\t]\n\n\t\t\tthis.log(`Spawning sandboxed render worker (strict): ${hostPath}`)\n\t\t} else if (this.sandbox === 'standard') {\n\t\t\tthis.log(`Spawning sandboxed render worker (standard): ${hostPath}`)\n\t\t} else {\n\t\t\tthis.log(`Spawning render worker: ${hostPath}`)\n\t\t}\n\n\t\tif (this.sandbox) {\n\t\t\tenv.FMT_SANDBOX_MODE = this.sandbox\n\t\t}\n\n\t\tconst child = fork(hostPath, [], {\n\t\t\tenv,\n\t\t\tstdio: ['ignore', 'pipe', 'pipe', 'ipc'],\n\t\t\tserialization: 'advanced',\n\t\t\texecArgv\n\t\t})\n\n\t\t// Forward worker stdout/stderr through the logger\n\t\tchild.stdout?.on('data', (data: Buffer) => {\n\t\t\tconst text = data.toString().trim()\n\n\t\t\tif (text) {\n\t\t\t\tthis.log(`[render-worker] ${text}`)\n\t\t\t}\n\t\t})\n\n\t\tchild.stderr?.on('data', (data: Buffer) => {\n\t\t\tconst text = data.toString().trim()\n\n\t\t\tif (!text) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (text.includes(SANDBOX_ERROR_CODE)) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis._warn(`[render-worker] ${text}`)\n\t\t})\n\n\t\tchild.on('message', (msg: any) => {\n\t\t\tconst response = msg as WorkerResponse\n\n\t\t\tif (response.type === 'ready') {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Route dev-init-result to pending callbacks (same as render results)\n\t\t\tif (response.type === 'dev-init-result') {\n\t\t\t\tconst pending = this.pending.get(response.id)\n\n\t\t\t\tif (!pending) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tthis.pending.delete(response.id)\n\t\t\t\tclearTimeout(pending.timer)\n\t\t\t\tpending.resolve(response as any)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst pending = this.pending.get(response.id)\n\n\t\t\tif (!pending) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.pending.delete(response.id)\n\t\t\tclearTimeout(pending.timer)\n\n\t\t\tif (response.type === 'render-result') {\n\t\t\t\tpending.resolve(response)\n\t\t\t} else if (response.type === 'render-error') {\n\t\t\t\tpending.reject(deserializeError(response.error))\n\t\t\t}\n\t\t})\n\n\t\tchild.on('exit', (code, signal) => {\n\t\t\tthis.log(`Render worker exited (code=${code}, signal=${signal})`)\n\n\t\t\t// A killed worker's 'exit' event fires asynchronously, sometimes after\n\t\t\t// restart() has already spawned and initialized its replacement. Only\n\t\t\t// clear state if this child is still the active worker — otherwise a\n\t\t\t// stale exit event wipes out a perfectly healthy newer one, leaving\n\t\t\t// `this.worker` null until the next request spawns an uninitialized\n\t\t\t// worker that was never sent dev-init.\n\t\t\tif (this.worker !== child) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.worker = null\n\t\t\tthis.devInitialized = false\n\n\t\t\t// Reject all pending requests\n\t\t\tfor (const [, pending] of this.pending) {\n\t\t\t\tclearTimeout(pending.timer)\n\t\t\t\tpending.reject(new Error(`Render worker exited unexpectedly (code=${code})`))\n\t\t\t}\n\t\t\tthis.pending.clear()\n\t\t})\n\n\t\tthis.worker = child\n\t\treturn child\n\t}\n\n\tprivate async ensureWorker(): Promise<ChildProcess> {\n\t\tif (this.worker && !this.worker.killed) {\n\t\t\treturn this.worker\n\t\t}\n\n\t\tconst child = this.spawn()\n\n\t\tthis.readyPromise = new Promise<void>((resolve, reject) => {\n\t\t\tconst onReady = (msg: any) => {\n\t\t\t\tif (msg?.type === 'ready') {\n\t\t\t\t\tchild.off('message', onReady)\n\t\t\t\t\tchild.off('error', onError)\n\t\t\t\t\tresolve()\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst onError = (err: Error) => {\n\t\t\t\tchild.off('message', onReady)\n\t\t\t\treject(err)\n\t\t\t}\n\t\t\tchild.on('message', onReady)\n\t\t\tchild.once('error', onError)\n\t\t})\n\n\t\tawait this.readyPromise\n\t\treturn child\n\t}\n\n\tprivate async send<T extends WorkerRequest>(request: T): Promise<RenderResult> {\n\t\tconst child = await this.ensureWorker()\n\t\tconst id = request.id || randomUUID()\n\t\tconst msg = { ...request, id }\n\n\t\treturn new Promise<RenderResult>((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.pending.delete(id)\n\t\t\t\treject(new Error(`Render worker timed out after ${this.timeout}ms`))\n\t\t\t}, this.timeout)\n\n\t\t\tthis.pending.set(id, { resolve, reject, timer })\n\t\t\tchild.send(msg)\n\t\t})\n\t}\n\n\t/**\n\t * Initialize the subprocess's headless Vite dev server.\n\t * Must be called once before any devRender() calls.\n\t */\n\tasync initDev(args: Omit<DevInitRequest, 'id' | 'type'>): Promise<void> {\n\t\tthis.lastInitArgs = args\n\n\t\tconst init = this.send({\n\t\t\tid: randomUUID(),\n\t\t\ttype: 'dev-init',\n\t\t\t...args\n\t\t} as DevInitRequest).then(() => {\n\t\t\tthis.devInitialized = true\n\t\t})\n\n\t\tthis.devInitPromise = init\n\n\t\ttry {\n\t\t\tawait init\n\t\t} finally {\n\t\t\tif (this.devInitPromise === init) {\n\t\t\t\tthis.devInitPromise = null\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Guarantee the current subprocess has been dev-init'd before a dev render\n\t * is sent. Without this, a worker spawned in the gap after dispose() (or\n\t * after a crash) starts with no headless Vite server, and every dev render\n\t * against it fails until something replays the init.\n\t */\n\tprivate async ensureDevInit(): Promise<void> {\n\t\tif (this.devInitPromise) {\n\t\t\tawait this.devInitPromise\n\t\t}\n\n\t\tconst workerAlive = this.worker !== null && !this.worker.killed\n\n\t\tif (workerAlive && this.devInitialized) {\n\t\t\treturn\n\t\t}\n\n\t\tif (!this.lastInitArgs) {\n\t\t\tthrow new Error('Render worker is not initialized for dev rendering. Call initDev() before devRender().')\n\t\t}\n\n\t\tawait this.initDev(this.lastInitArgs)\n\t}\n\n\t// Refresh the config that restart() replays, so a restart after a config change\n\t// (e.g. enabling Panda) re-initialises the worker with the new config rather than\n\t// the one captured at first init.\n\tupdateInitConfig(configJson: string): void {\n\t\tif (this.lastInitArgs) {\n\t\t\tthis.lastInitArgs = { ...this.lastInitArgs, configJson }\n\t\t}\n\t}\n\n\t/**\n\t * Kill and respawn the subprocess, replaying the last dev-init call.\n\t *\n\t * The subprocess's headless Vite server is created once and reused for\n\t * every render, with dependency discovery disabled (optimizeDeps.noDiscovery)\n\t * for determinism. That means a package installed mid-session — e.g. by the\n\t * \"new document\" flow's install-dependencies step — is invisible to its\n\t * resolver until the process (and its Vite instance) starts fresh. Call this\n\t * after any change to node_modules the next render depends on.\n\t */\n\tasync restart(): Promise<void> {\n\t\tconst doRestart = async () => {\n\t\t\tif (!this.lastInitArgs) {\n\t\t\t\tawait this.dispose()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst initArgs = this.lastInitArgs\n\t\t\tawait this.dispose()\n\t\t\tawait this.initDev(initArgs)\n\t\t}\n\n\t\t// Publish the in-flight restart so renders wait for re-init instead of\n\t\t// spawning a worker into the disposed gap. initDev's own send bypasses this\n\t\t// (it's part of the restart), so there's no deadlock.\n\t\tthis.restartPromise = doRestart()\n\n\t\ttry {\n\t\t\tawait this.restartPromise\n\t\t} finally {\n\t\t\tthis.restartPromise = null\n\t\t}\n\t}\n\n\tasync devRender(args: Omit<DevRenderRequest, 'id' | 'type'>): Promise<{ html: string }> {\n\t\tif (this.restartPromise) {\n\t\t\tawait this.restartPromise\n\t\t}\n\n\t\tawait this.ensureDevInit()\n\n\t\tconst result = await this.send({\n\t\t\tid: randomUUID(),\n\t\t\ttype: 'dev-render',\n\t\t\t...args\n\t\t})\n\t\treturn { html: result.html }\n\t}\n\n\tasync compileRender(args: Omit<CompileRenderRequest, 'id' | 'type'>): Promise<string> {\n\t\tif (this.restartPromise) {\n\t\t\tawait this.restartPromise\n\t\t}\n\n\t\tconst result = await this.send({\n\t\t\tid: randomUUID(),\n\t\t\ttype: 'compile-render',\n\t\t\t...args\n\t\t})\n\t\treturn result.html\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tif (this.worker) {\n\t\t\tthis.worker.kill()\n\t\t\tthis.worker = null\n\t\t}\n\n\t\tthis.devInitialized = false\n\n\t\tfor (const [, pending] of this.pending) {\n\t\t\tclearTimeout(pending.timer)\n\t\t\tpending.reject(new Error('Render worker disposed'))\n\t\t}\n\t\tthis.pending.clear()\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoCA,SAAS,oBAA4B;CACpC,MAAM,WAAW,QAAQ,UAAU,UAAU,iBAAiB,WAAW;AACzE,KAAI,WAAW,SAAS,CAAE,QAAO;AACjC,QAAO,QAAQ,UAAU,MAAM,QAAQ,UAAU,iBAAiB,WAAW;;;;;;;;;;;;;AAc9E,SAAS,wBAAwB,YAAiC;CACjE,MAAM,wBAAQ,IAAI,KAAa;;;;;;;;;;CAW/B,MAAM,UAAU,QAAgB;EAC/B,IAAIA;AAEJ,MAAI;AACH,cAAW,aAAa,QAAQ,IAAI,CAAC;UAC9B;AACP,cAAW,QAAQ,IAAI;;AAGxB,MAAI,SAAS,SAAS,IAAI,CACzB,YAAW,SAAS,MAAM,GAAG,GAAG;AAGjC,QAAM,IAAI,WAAW,KAAK;;AAI3B,QAAO,QAAQ,mBAAmB,CAAC,CAAC;;;;;;;;;;;;;CAcpC,MAAM,mBAAmB,aAAqB;EAC7C,IAAI,MAAM,QAAQ,SAAS;EAC3B,MAAMC,UAAoB,EAAE;AAE5B,SAAO,MAAM;GACZ,MAAM,KAAK,QAAQ,KAAK,eAAe;AAEvC,OAAI,WAAW,GAAG,EAAE;AACnB,WAAO,GAAG;AACV,6BAAyB,GAAG;AAE5B,SAAK,MAAM,OAAO,Q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,KAAK;AACtB,SAAM,KAAK,SAAS;AACpB,SAAM,KAAK,QAAQ,SAAS;;AAM7B,OAAK,iBAAiB,WAAW;AAEjC,MAAI;AACH,SAAM,KAAK;YACF;AACT,QAAK,iBAAiB;;;CAIxB,MAAM,UAAU,MAAwE;AACvF,MAAI,KAAK,eACR,OAAM,KAAK;AAGZ,QAAM,KAAK,eAAe;AAO1B,SAAO,EAAE,OALM,MAAM,KAAK,KAAK;GAC9B,IAAI,YAAY;GAChB,MAAM;GACN,GAAG;GACH,CAAC,EACoB,MAAM;;CAG7B,MAAM,cAAc,MAAkE;AACrF,MAAI,KAAK,eACR,OAAM,KAAK;AAQZ,UALe,MAAM,KAAK,KAAK;GAC9B,IAAI,YAAY;GAChB,MAAM;GACN,GAAG;GACH,CAAC,EACY;;CAGf,MAAM,UAAyB;AAC9B,MAAI,KAAK,QAAQ;AAChB,QAAK,OAAO,MAAM;AAClB,QAAK,SAAS;;AAGf,OAAK,iBAAiB;AAEtB,OAAK,MAAM,GAAG,YAAY,KAAK,SAAS;AACvC,gBAAa,QAAQ,MAAM;AAC3B,WAAQ,uBAAO,IAAI,MAAM,yBAAyB,CAAC;;AAEpD,OAAK,QAAQ,OAAO"}
|
|
1
|
+
{"version":3,"file":"client.mjs","names":["resolved: string","gapDirs: string[]","entries: string[]","execArgv: string[]","realTmpDir: string","pending"],"sources":["../../../src/server/render-worker/client.ts"],"sourcesContent":["/**\n * Main-process client for the render worker subprocess.\n *\n * Manages worker lifecycle (spawn, restart, dispose) and provides\n * typed methods for compile-path and dev-server-path rendering.\n *\n * For dev-server rendering, the subprocess runs its own headless Vite\n * server with the same plugin configuration. All module resolution,\n * transforms, and evaluation happen in the subprocess — the main\n * process just sends render requests and receives final HTML.\n */\n\nimport type {\n\tWorkerRequest,\n\tWorkerResponse,\n\tRenderResult,\n\tCompileRenderRequest,\n\tDevRenderRequest,\n\tDevInitRequest\n} from './types'\n\nimport { fork, type ChildProcess } from 'node:child_process'\nimport { dirname, resolve } from 'node:path'\nimport { randomUUID } from 'node:crypto'\nimport { existsSync, readdirSync, realpathSync } from 'node:fs'\nimport { tmpdir } from 'node:os'\nimport { buildSafeEnv } from './env'\nimport { deserializeError } from './error'\nimport { getPermissionFlag } from './permission-flag'\nimport { SANDBOX_ERROR_CODE } from './sandbox'\nimport { _dirname } from '../project/paths'\n\n/**\n * Resolve the path to the compiled worker host entry point. The dist is\n * unbundled, so host.js sits next to this module at dist/server/render-worker/.\n * In dev/test _dirname points to src/, so fall back to the built dist.\n */\nfunction getWorkerHostPath(): string {\n\tconst fromDist = resolve(_dirname, 'server', 'render-worker', 'host.mjs')\n\tif (existsSync(fromDist)) return fromDist\n\treturn resolve(_dirname, '..', 'dist', 'server', 'render-worker', 'host.mjs')\n}\n\n/**\n * Compute the minimal set of filesystem paths the render worker needs\n * read access to. Used with Node's permission model to\n * prevent user template code from reading sensitive files (.env, ~/.ssh, etc.).\n *\n * The worker needs:\n * 1. Its own dist directory (compiled worker host + chunks)\n * 2. node_modules directories (for externalized deps like vite, react, vue)\n * 3. The Node.js installation directory (for native addons, if any)\n * 4. Any extra paths provided by the caller (e.g. project source dirs)\n */\nfunction computeAllowedReadPaths(extraPaths?: string[]): string[] {\n\tconst paths = new Set<string>()\n\n\t/**\n\t * Add a directory to the allowed set. Uses realpathSync so symlinked\n\t * directories (e.g. /tmp → /private/tmp on macOS) match what the\n\t * permission model actually checks.\n\t *\n\t * The `/*` suffix is required — Node 22's permission model treats\n\t * bare paths as exact-file matches. `dir/*` grants recursive read\n\t * access to all files under `dir` (including `stat(dir)` itself).\n\t */\n\tconst addDir = (dir: string) => {\n\t\tlet resolved: string\n\n\t\ttry {\n\t\t\tresolved = realpathSync(resolve(dir))\n\t\t} catch {\n\t\t\tresolved = resolve(dir)\n\t\t}\n\n\t\tif (resolved.endsWith('/')) {\n\t\t\tresolved = resolved.slice(0, -1)\n\t\t}\n\n\t\tpaths.add(resolved + '/*')\n\t}\n\n\t// Worker's own code directory (dist/node/)\n\taddDir(dirname(getWorkerHostPath()))\n\n\t/**\n\t * Walk up from a directory, adding every node_modules found.\n\t * Also resolves symlinks inside each node_modules — pnpm workspace\n\t * packages are symlinked to their real source directories, and Node's\n\t * permission model checks the real path, not the symlink.\n\t *\n\t * Intermediate directories between consecutive node_modules are also\n\t * added because Node's module resolver does stat() on\n\t * `<dir>/node_modules` at every level. Without read permission on\n\t * these gaps, the Permission Model throws ERR_ACCESS_DENIED (instead\n\t * of ENOENT), which breaks module resolution entirely.\n\t */\n\tconst findNodeModules = (startDir: string) => {\n\t\tlet dir = resolve(startDir)\n\t\tconst gapDirs: string[] = []\n\n\t\twhile (true) {\n\t\t\tconst nm = resolve(dir, 'node_modules')\n\n\t\t\tif (existsSync(nm)) {\n\t\t\t\taddDir(nm)\n\t\t\t\tresolveSymlinkedPackages(nm)\n\n\t\t\t\tfor (const gap of gapDirs) {\n\t\t\t\t\taddDir(gap)\n\t\t\t\t}\n\t\t\t\tgapDirs.length = 0\n\t\t\t} else {\n\t\t\t\tgapDirs.push(dir)\n\t\t\t}\n\n\t\t\tconst parent = dirname(dir)\n\t\t\tif (parent === dir) break\n\t\t\tdir = parent\n\t\t}\n\t}\n\n\t/** Resolve symlinks in a node_modules directory (top-level + scoped). */\n\tconst resolveSymlinkedPackages = (nmDir: string) => {\n\t\tlet entries: string[]\n\n\t\ttry {\n\t\t\tentries = readdirSync(nmDir)\n\t\t} catch {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const entry of entries) {\n\t\t\tconst entryPath = resolve(nmDir, entry)\n\n\t\t\tif (entry.startsWith('@')) {\n\t\t\t\tresolveSymlinkedPackages(entryPath)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst realPath = realpathSync(entryPath)\n\t\t\t\tif (realPath !== entryPath) {\n\t\t\t\t\taddDir(realPath)\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Broken symlink or inaccessible — skip\n\t\t\t}\n\t\t}\n\t}\n\n\t// Find node_modules from the worker's dist dir and the project cwd.\n\t// Covers pnpm workspace hoisting where deps live at the monorepo root.\n\tfindNodeModules(dirname(getWorkerHostPath()))\n\tfindNodeModules(process.cwd())\n\n\t// For extra paths (e.g. project source dirs, compile output dirs):\n\t// walk up to the workspace root, adding each directory and any\n\t// node_modules found along the way. Vite's searchForWorkspaceRoot\n\t// calls existsSync() in every ancestor looking for markers like\n\t// .git and pnpm-workspace.yaml. Without read permission on these\n\t// directories the Permission Model throws ERR_ACCESS_DENIED\n\t// (instead of ENOENT), which crashes Vite during init.\n\t//\n\t// We stop at the workspace root (.git or pnpm-workspace.yaml) so\n\t// ancestor directories above the project (e.g. ~/.ssh, ~/.aws)\n\t// remain inaccessible.\n\tif (extraPaths) {\n\t\tfor (const p of extraPaths) {\n\t\t\tlet dir = resolve(p)\n\t\t\twhile (true) {\n\t\t\t\taddDir(dir)\n\n\t\t\t\tconst nm = resolve(dir, 'node_modules')\n\t\t\t\tif (existsSync(nm)) {\n\t\t\t\t\taddDir(nm)\n\t\t\t\t\tresolveSymlinkedPackages(nm)\n\t\t\t\t}\n\n\t\t\t\tconst isWorkspaceRoot = existsSync(resolve(dir, '.git')) || existsSync(resolve(dir, 'pnpm-workspace.yaml'))\n\n\t\t\t\tif (isWorkspaceRoot) break\n\n\t\t\t\tconst parent = dirname(dir)\n\t\t\t\tif (parent === dir) break\n\t\t\t\tdir = parent\n\t\t\t}\n\t\t}\n\t}\n\n\t// Node.js installation — needed for native addons and internal resolution\n\taddDir(dirname(process.execPath))\n\n\treturn [...paths]\n}\n\ninterface PendingRequest {\n\tresolve: (result: RenderResult) => void\n\treject: (error: Error) => void\n\ttimer: ReturnType<typeof setTimeout>\n}\n\nexport interface RenderWorkerOptions {\n\ttimeout?: number\n\t/** Custom log function — defaults to console.debug */\n\tlog?: (msg: string) => void\n\t/** Custom warn function — defaults to console.warn */\n\twarn?: (msg: string) => void\n\t/**\n\t * Extra filesystem paths the worker is allowed to read.\n\t * The worker always has read access to its own dist directory and\n\t * node_modules. Use this for additional paths like project source dirs.\n\t */\n\tallowedReadPaths?: string[]\n\t/**\n\t * Sandbox mode for the worker subprocess.\n\t *\n\t * - 'strict': Node's permission model with filesystem scoping.\n\t * No native addons, worker threads, or child processes. Used by compile\n\t * where the subprocess just does import() on a pre-built bundle.\n\t *\n\t * - 'standard': JS-level API patches that block network (fetch, http, net),\n\t * child_process, and other exfiltration vectors. Used by the dev path\n\t * where Vite's toolchain needs unrestricted filesystem access.\n\t *\n\t * - false: no sandbox. Worker still runs with a scrubbed environment.\n\t *\n\t * Both modes run with a scrubbed environment (env.ts allowlist).\n\t */\n\tsandbox?: 'strict' | 'standard' | false\n}\n\nexport class RenderWorker {\n\tprivate worker: ChildProcess | null = null\n\tprivate pending = new Map<string, PendingRequest>()\n\tprivate readyPromise: Promise<void> | null = null\n\tprivate timeout: number\n\tprivate log: (msg: string) => void\n\tprivate _warn: (msg: string) => void\n\tprivate allowedReadPaths?: string[]\n\tprivate sandbox: 'strict' | 'standard' | false\n\t// Replayed by restart() so a fresh subprocess re-initializes its headless\n\t// Vite server the same way the original dev-init call did.\n\tprivate lastInitArgs: Omit<DevInitRequest, 'id' | 'type'> | null = null\n\t// True while the current subprocess has a dev-init'd headless Vite server.\n\t// Cleared on dispose and on unexpected worker exit, so ensureDevInit()\n\t// knows a freshly spawned subprocess still needs its init replayed.\n\tprivate devInitialized = false\n\t// In-flight dev-init, shared so concurrent renders await one init\n\t// instead of each sending their own.\n\tprivate devInitPromise: Promise<void> | null = null\n\t// Held for the duration of a restart (dispose + dev-init). Renders await it so\n\t// one can't land in the gap after dispose() and spawn a fresh, un-init'd worker.\n\tprivate restartPromise: Promise<void> | null = null\n\n\tconstructor(options?: RenderWorkerOptions) {\n\t\tthis.timeout = options?.timeout ?? 30_000\n\t\tthis.log = options?.log ?? ((msg: string) => console.debug(msg))\n\t\tthis._warn = options?.warn ?? ((msg: string) => console.warn(msg))\n\t\tthis.allowedReadPaths = options?.allowedReadPaths\n\t\tthis.sandbox = options?.sandbox ?? false\n\t}\n\n\tprivate spawn(): ChildProcess {\n\t\tconst hostPath = getWorkerHostPath()\n\t\tconst env = buildSafeEnv()\n\n\t\tlet execArgv: string[] = []\n\n\t\tif (this.sandbox === 'strict') {\n\t\t\tconst allowedReadPaths = computeAllowedReadPaths(this.allowedReadPaths)\n\n\t\t\tlet realTmpDir: string\n\t\t\ttry {\n\t\t\t\trealTmpDir = realpathSync(tmpdir())\n\t\t\t} catch {\n\t\t\t\trealTmpDir = tmpdir()\n\t\t\t}\n\t\t\tconst allowedWritePaths = [realTmpDir + '/*']\n\n\t\t\texecArgv = [\n\t\t\t\t'--no-warnings',\n\t\t\t\tgetPermissionFlag(),\n\t\t\t\t...allowedReadPaths.map(p => `--allow-fs-read=${p}`),\n\t\t\t\t...allowedWritePaths.map(p => `--allow-fs-write=${p}`)\n\t\t\t]\n\n\t\t\tthis.log(`Spawning sandboxed render worker (strict): ${hostPath}`)\n\t\t} else if (this.sandbox === 'standard') {\n\t\t\tthis.log(`Spawning sandboxed render worker (standard): ${hostPath}`)\n\t\t} else {\n\t\t\tthis.log(`Spawning render worker: ${hostPath}`)\n\t\t}\n\n\t\tif (this.sandbox) {\n\t\t\tenv.FMT_SANDBOX_MODE = this.sandbox\n\t\t}\n\n\t\tconst child = fork(hostPath, [], {\n\t\t\tenv,\n\t\t\tstdio: ['ignore', 'pipe', 'pipe', 'ipc'],\n\t\t\tserialization: 'advanced',\n\t\t\texecArgv\n\t\t})\n\n\t\t// Forward worker stdout/stderr through the logger\n\t\tchild.stdout?.on('data', (data: Buffer) => {\n\t\t\tconst text = data.toString().trim()\n\n\t\t\tif (text) {\n\t\t\t\tthis.log(`[render-worker] ${text}`)\n\t\t\t}\n\t\t})\n\n\t\tchild.stderr?.on('data', (data: Buffer) => {\n\t\t\tconst text = data.toString().trim()\n\n\t\t\tif (!text) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (text.includes(SANDBOX_ERROR_CODE)) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis._warn(`[render-worker] ${text}`)\n\t\t})\n\n\t\tchild.on('message', (msg: any) => {\n\t\t\tconst response = msg as WorkerResponse\n\n\t\t\tif (response.type === 'ready') {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Route dev-init-result to pending callbacks (same as render results)\n\t\t\tif (response.type === 'dev-init-result') {\n\t\t\t\tconst pending = this.pending.get(response.id)\n\n\t\t\t\tif (!pending) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tthis.pending.delete(response.id)\n\t\t\t\tclearTimeout(pending.timer)\n\t\t\t\tpending.resolve(response as any)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst pending = this.pending.get(response.id)\n\n\t\t\tif (!pending) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.pending.delete(response.id)\n\t\t\tclearTimeout(pending.timer)\n\n\t\t\tif (response.type === 'render-result') {\n\t\t\t\tpending.resolve(response)\n\t\t\t} else if (response.type === 'render-error') {\n\t\t\t\tpending.reject(deserializeError(response.error))\n\t\t\t}\n\t\t})\n\n\t\tchild.on('exit', (code, signal) => {\n\t\t\tthis.log(`Render worker exited (code=${code}, signal=${signal})`)\n\n\t\t\t// A killed worker's 'exit' event fires asynchronously, sometimes after\n\t\t\t// restart() has already spawned and initialized its replacement. Only\n\t\t\t// clear state if this child is still the active worker — otherwise a\n\t\t\t// stale exit event wipes out a perfectly healthy newer one, leaving\n\t\t\t// `this.worker` null until the next request spawns an uninitialized\n\t\t\t// worker that was never sent dev-init.\n\t\t\tif (this.worker !== child) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tthis.worker = null\n\t\t\tthis.devInitialized = false\n\n\t\t\t// Reject all pending requests\n\t\t\tfor (const [, pending] of this.pending) {\n\t\t\t\tclearTimeout(pending.timer)\n\t\t\t\tpending.reject(new Error(`Render worker exited unexpectedly (code=${code})`))\n\t\t\t}\n\t\t\tthis.pending.clear()\n\t\t})\n\n\t\tthis.worker = child\n\t\treturn child\n\t}\n\n\tprivate async ensureWorker(): Promise<ChildProcess> {\n\t\tif (this.worker && !this.worker.killed) {\n\t\t\treturn this.worker\n\t\t}\n\n\t\tconst child = this.spawn()\n\n\t\tthis.readyPromise = new Promise<void>((resolve, reject) => {\n\t\t\tconst onReady = (msg: any) => {\n\t\t\t\tif (msg?.type === 'ready') {\n\t\t\t\t\tchild.off('message', onReady)\n\t\t\t\t\tchild.off('error', onError)\n\t\t\t\t\tresolve()\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst onError = (err: Error) => {\n\t\t\t\tchild.off('message', onReady)\n\t\t\t\treject(err)\n\t\t\t}\n\t\t\tchild.on('message', onReady)\n\t\t\tchild.once('error', onError)\n\t\t})\n\n\t\tawait this.readyPromise\n\t\treturn child\n\t}\n\n\tprivate async send<T extends WorkerRequest>(request: T): Promise<RenderResult> {\n\t\tconst child = await this.ensureWorker()\n\t\tconst id = request.id || randomUUID()\n\t\tconst msg = { ...request, id }\n\n\t\treturn new Promise<RenderResult>((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tthis.pending.delete(id)\n\t\t\t\treject(new Error(`Render worker timed out after ${this.timeout}ms`))\n\t\t\t}, this.timeout)\n\n\t\t\tthis.pending.set(id, { resolve, reject, timer })\n\t\t\tchild.send(msg)\n\t\t})\n\t}\n\n\t/**\n\t * Initialize the subprocess's headless Vite dev server.\n\t * Must be called once before any devRender() calls.\n\t */\n\tasync initDev(args: Omit<DevInitRequest, 'id' | 'type'>): Promise<void> {\n\t\tthis.lastInitArgs = args\n\n\t\tconst init = this.send({\n\t\t\tid: randomUUID(),\n\t\t\ttype: 'dev-init',\n\t\t\t...args\n\t\t} as DevInitRequest).then(() => {\n\t\t\tthis.devInitialized = true\n\t\t})\n\n\t\tthis.devInitPromise = init\n\n\t\ttry {\n\t\t\tawait init\n\t\t} finally {\n\t\t\tif (this.devInitPromise === init) {\n\t\t\t\tthis.devInitPromise = null\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Guarantee the current subprocess has been dev-init'd before a dev render\n\t * is sent. Without this, a worker spawned in the gap after dispose() (or\n\t * after a crash) starts with no headless Vite server, and every dev render\n\t * against it fails until something replays the init.\n\t */\n\tprivate async ensureDevInit(): Promise<void> {\n\t\tif (this.devInitPromise) {\n\t\t\tawait this.devInitPromise\n\t\t}\n\n\t\tconst workerAlive = this.worker !== null && !this.worker.killed\n\n\t\tif (workerAlive && this.devInitialized) {\n\t\t\treturn\n\t\t}\n\n\t\tif (!this.lastInitArgs) {\n\t\t\tthrow new Error('Render worker is not initialized for dev rendering. Call initDev() before devRender().')\n\t\t}\n\n\t\tawait this.initDev(this.lastInitArgs)\n\t}\n\n\t// Refresh the config that restart() replays, so a restart after a config change\n\t// (e.g. enabling Panda) re-initialises the worker with the new config rather than\n\t// the one captured at first init.\n\tupdateInitConfig(configJson: string): void {\n\t\tif (this.lastInitArgs) {\n\t\t\tthis.lastInitArgs = { ...this.lastInitArgs, configJson }\n\t\t}\n\t}\n\n\t/**\n\t * Kill and respawn the subprocess, replaying the last dev-init call.\n\t *\n\t * The subprocess's headless Vite server is created once and reused for\n\t * every render, with dependency discovery disabled (optimizeDeps.noDiscovery)\n\t * for determinism. That means a package installed mid-session — e.g. by the\n\t * \"new document\" flow's install-dependencies step — is invisible to its\n\t * resolver until the process (and its Vite instance) starts fresh. Call this\n\t * after any change to node_modules the next render depends on.\n\t */\n\tasync restart(): Promise<void> {\n\t\tconst doRestart = async () => {\n\t\t\tif (!this.lastInitArgs) {\n\t\t\t\tawait this.dispose()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst initArgs = this.lastInitArgs\n\t\t\tawait this.dispose()\n\t\t\tawait this.initDev(initArgs)\n\t\t}\n\n\t\t// Publish the in-flight restart so renders wait for re-init instead of\n\t\t// spawning a worker into the disposed gap. initDev's own send bypasses this\n\t\t// (it's part of the restart), so there's no deadlock.\n\t\tthis.restartPromise = doRestart()\n\n\t\ttry {\n\t\t\tawait this.restartPromise\n\t\t} finally {\n\t\t\tthis.restartPromise = null\n\t\t}\n\t}\n\n\tasync devRender(args: Omit<DevRenderRequest, 'id' | 'type'>): Promise<{ html: string }> {\n\t\tif (this.restartPromise) {\n\t\t\tawait this.restartPromise\n\t\t}\n\n\t\tawait this.ensureDevInit()\n\n\t\tconst result = await this.send({\n\t\t\tid: randomUUID(),\n\t\t\ttype: 'dev-render',\n\t\t\t...args\n\t\t})\n\t\treturn { html: result.html }\n\t}\n\n\tasync compileRender(args: Omit<CompileRenderRequest, 'id' | 'type'>): Promise<string> {\n\t\tif (this.restartPromise) {\n\t\t\tawait this.restartPromise\n\t\t}\n\n\t\tconst result = await this.send({\n\t\t\tid: randomUUID(),\n\t\t\ttype: 'compile-render',\n\t\t\t...args\n\t\t})\n\t\treturn result.html\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tif (this.worker) {\n\t\t\tthis.worker.kill()\n\t\t\tthis.worker = null\n\t\t}\n\n\t\tthis.devInitialized = false\n\n\t\tfor (const [, pending] of this.pending) {\n\t\t\tclearTimeout(pending.timer)\n\t\t\tpending.reject(new Error('Render worker disposed'))\n\t\t}\n\t\tthis.pending.clear()\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqCA,SAAS,oBAA4B;CACpC,MAAM,WAAW,QAAQ,UAAU,UAAU,iBAAiB,WAAW;AACzE,KAAI,WAAW,SAAS,CAAE,QAAO;AACjC,QAAO,QAAQ,UAAU,MAAM,QAAQ,UAAU,iBAAiB,WAAW;;;;;;;;;;;;;AAc9E,SAAS,wBAAwB,YAAiC;CACjE,MAAM,wBAAQ,IAAI,KAAa;;;;;;;;;;CAW/B,MAAM,UAAU,QAAgB;EAC/B,IAAIA;AAEJ,MAAI;AACH,cAAW,aAAa,QAAQ,IAAI,CAAC;UAC9B;AACP,cAAW,QAAQ,IAAI;;AAGxB,MAAI,SAAS,SAAS,IAAI,CACzB,YAAW,SAAS,MAAM,GAAG,GAAG;A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C,KAAK,eACvB;AAGD,MAAI,CAAC,KAAK,aACT,OAAM,IAAI,MAAM,yFAAyF;AAG1G,QAAM,KAAK,QAAQ,KAAK,aAAa;;CAMtC,iBAAiB,YAA0B;AAC1C,MAAI,KAAK,aACR,MAAK,eAAe;GAAE,GAAG,KAAK;GAAc;GAAY;;;;;;;;;;;;CAc1D,MAAM,UAAyB;EAC9B,MAAM,YAAY,YAAY;AAC7B,OAAI,CAAC,KAAK,cAAc;AACvB,UAAM,KAAK,SAAS;AACpB;;GAGD,MAAM,WAAW,KAAK;AACtB,SAAM,KAAK,SAAS;AACpB,SAAM,KAAK,QAAQ,SAAS;;AAM7B,OAAK,iBAAiB,WAAW;AAEjC,MAAI;AACH,SAAM,KAAK;YACF;AACT,QAAK,iBAAiB;;;CAIxB,MAAM,UAAU,MAAwE;AACvF,MAAI,KAAK,eACR,OAAM,KAAK;AAGZ,QAAM,KAAK,eAAe;AAO1B,SAAO,EAAE,OALM,MAAM,KAAK,KAAK;GAC9B,IAAI,YAAY;GAChB,MAAM;GACN,GAAG;GACH,CAAC,EACoB,MAAM;;CAG7B,MAAM,cAAc,MAAkE;AACrF,MAAI,KAAK,eACR,OAAM,KAAK;AAQZ,UALe,MAAM,KAAK,KAAK;GAC9B,IAAI,YAAY;GAChB,MAAM;GACN,GAAG;GACH,CAAC,EACY;;CAGf,MAAM,UAAyB;AAC9B,MAAI,KAAK,QAAQ;AAChB,QAAK,OAAO,MAAM;AAClB,QAAK,SAAS;;AAGf,OAAK,iBAAiB;AAEtB,OAAK,MAAM,GAAG,YAAY,KAAK,SAAS;AACvC,gBAAa,QAAQ,MAAM;AAC3B,WAAQ,uBAAO,IAAI,MAAM,yBAAyB,CAAC;;AAEpD,OAAK,QAAQ,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.mjs","names":["devServer: ViteDevServer | null","frameworkAdaptors: Record<string, () => Promise<any>>","userModule: any"],"sources":["../../../src/server/render-worker/host.ts"],"sourcesContent":["/**\n * Render worker host — runs in a forked child process.\n *\n * Handles two execution paths:\n * 1. compile-render: imports a pre-built bundle, calls its render()\n * 2. dev-render: runs a headless Vite dev server with ssrLoadModule()\n * so all plugins (Vue SFC, Linaria, Vanilla Extract, etc.) work\n * with transforms and evaluation in the same process\n *\n * This process runs with a scrubbed environment (see env.ts), so user\n * code cannot access the parent process's secrets.\n */\n\nimport type { WorkerRequest, WorkerResponse, CompileRenderRequest, DevRenderRequest, DevInitRequest } from './types'\nimport type { ViteDevServer } from 'vite'\n\nimport { serializeError } from './error'\nimport { pathToFileURL } from 'node:url'\nimport { getDocumentExportName } from '@format.dev/cli/scaffold'\nimport { formatForLog } from '../utils/format-for-log'\nimport { finalizeDocumentHtml, restampDocumentEngine } from '../compile/finalize-document-html'\nimport { engineTarget, sdkVersion } from '../compile/producer-release'\nimport { applySandboxPatches } from './sandbox'\nimport { collectDocumentCss, invalidateModuleTree } from './document-css'\n\n// Apply JS-level API patches (network, child_process) before any user code\n// runs. In 'strict' mode, Node's --experimental-permission handles this\n// at the runtime level instead.\nif (process.env.FMT_SANDBOX_MODE === 'standard') {\n\tapplySandboxPatches()\n}\n\nasync function handleCompileRender(request: CompileRenderRequest): Promise<string> {\n\tconst { bundlePath, documentName, data, cwd } = request\n\n\t// Dynamic import with cache buster — same strategy as get-renderer.ts\n\tconst url = new URL(pathToFileURL(bundlePath).href)\n\turl.search = `?t=${Date.now()}-${Math.random().toString(36).slice(2)}`\n\n\tconst bundle = await import(url.href)\n\n\t// Resolve the named export (same logic as resolveRenderer in get-renderer.ts)\n\tconst exportName = getDocumentExportName(documentName)\n\n\tconst renderer = bundle?.[exportName] ?? bundle?.default?.[exportName] ?? bundle?.default?.default?.[exportName]\n\n\tif (!renderer) {\n\t\tthrow new Error(`Renderer export \"${exportName}\" not found for document \"${documentName}\"`)\n\t}\n\n\tconst result = await renderer.render(data || {}, cwd)\n\n\t// The CLI-compiled wrapper returns a FormatDocument object while the inner renderer\n\t// returns a plain string. Extract FormatDocument.html for IPC serialization.\n\treturn typeof result === 'object' && result !== null && 'html' in result ? result.html : result\n}\n\nlet devServer: ViteDevServer | null = null\nlet devDecodeStyleEntities = false\n\nasync function handleDevInit(request: DevInitRequest): Promise<void> {\n\tconst { root, configJson, decodeStyleEntities: decode } = request\n\n\tdevDecodeStyleEntities = decode === true\n\n\t// Hydrate runtime state so createConfig() and adaptors work\n\tconst { setUserProjectDir } = await import('../project/user-project-dir')\n\tsetUserProjectDir(root)\n\n\tconst { compileState } = await import('../runtime-state')\n\tcompileState.setConfig(JSON.parse(configJson))\n\n\t// Build Vite config using the same factory as the main server\n\tconst { createConfig } = await import('../vite/create-config')\n\tconst { collectCssPlugin } = await import('../vite/plugins/collect-css')\n\tconst { stylesPreProcessor } = await import('../vite/plugins/styles-pre-processor')\n\n\tconst { baseViteConfig, frameworkPlugins, stylePlugins } = createConfig()\n\n\tconst { createServer, mergeConfig } = await import('vite')\n\n\tconst { join } = await import('node:path')\n\tconst { tmpdir } = await import('node:os')\n\n\tconst workerLogger = {\n\t\tinfo: (msg: string) => console.log(msg),\n\t\twarn: (msg: string) => console.warn(msg),\n\t\terror: () => {},\n\t\twarnOnce: (msg: string) => console.warn(msg),\n\t\thasWarned: false,\n\t\tclearScreen: () => {},\n\t\thasErrorLogged: () => false\n\t}\n\n\tconst serverConfig = mergeConfig(baseViteConfig, {\n\t\tconfigFile: false,\n\t\tclearScreen: false,\n\t\tenvDir: false, // Block .env file loading — primary .env protection\n\t\tcacheDir: join(tmpdir(), 'format-vite-cache'),\n\t\tlogLevel: 'info',\n\t\tcustomLogger: workerLogger,\n\t\tserver: {\n\t\t\tmiddlewareMode: true,\n\t\t\twatch: null // No file watching — main server handles HMR\n\t\t},\n\t\tplugins: [await stylesPreProcessor(false), ...frameworkPlugins, ...stylePlugins, collectCssPlugin()],\n\t\tresolve: {\n\t\t\t// Force framework packages to resolve from the user's project\n\t\t\t// (Vite root) rather than from workspace packages like\n\t\t\t// @format.dev/react or @format.dev/vue, which may resolve to a different\n\t\t\t// version at the workspace root.\n\t\t\tdedupe: ['react', 'react-dom', 'vue', 'vue/server-renderer']\n\t\t},\n\t\tssr: {\n\t\t\t// We externalize third-party node_modules to Node's own loader,\n\t\t\t// which is the only path that handles CommonJS packages. Inlining\n\t\t\t// CJS into Vite's ESM module runner throws \"module is not defined\"\n\t\t\t// (its entry has no `module` global), so a document importing any\n\t\t\t// CJS-only library — highlight.js, and thousands like it — would\n\t\t\t// otherwise crash the render.\n\t\t\t//\n\t\t\t// noExternal as an array keeps Vite's default of auto-bundling\n\t\t\t// linked workspace packages and adds @format.dev/* on top, so our SDK\n\t\t\t// is always bundled (even when installed from npm, not symlinked).\n\t\t\t// Bundling routes its react/vue imports through resolve.dedupe\n\t\t\t// below, giving the user's single framework instance and avoiding\n\t\t\t// the dual-instance crashes that a blanket noExternal was added for.\n\t\t\t//\n\t\t\t// react/react-dom and vue/vue-server-renderer stay external\n\t\t\t// because their entry files are CJS (module.exports) which fails\n\t\t\t// in Vite's ESM evaluator. The adaptors manually load them from\n\t\t\t// the user's project via createRequire.\n\t\t\tnoExternal: [/@format(?:\\.dev)?\\//],\n\t\t\texternal: ['react', 'react-dom', 'vue', 'vue/server-renderer']\n\t\t},\n\t\toptimizeDeps: {\n\t\t\tnoDiscovery: true,\n\t\t\tentries: false\n\t\t}\n\t})\n\n\tdevServer = await createServer(serverConfig)\n}\n\nconst frameworkAdaptors: Record<string, () => Promise<any>> = {\n\treact: () => import('../compile/adaptors/react-node'),\n\tvue: () => import('../compile/adaptors/vue-node'),\n\thtml: () => import('../compile/adaptors/html')\n}\n\nasync function handleDevRender(request: DevRenderRequest): Promise<{ html: string }> {\n\tif (!devServer) {\n\t\tthrow new Error('Dev server not initialized. Send a dev-init message first.')\n\t}\n\n\tconst { entryFilePath, data, framework, engineVersion } = request\n\tconst { compileState } = await import('../runtime-state')\n\tconst { decodeStyleEntities } = await import('../compile/decode-style-entities')\n\n\tconsole.log(`Render started (framework=${framework}, engine=${engineVersion})`)\n\n\t// Look the entry up by URL, the same way ssrLoadModule resolves it, so\n\t// invalidation and CSS collection find the module that was loaded.\n\tconst { moduleGraph } = devServer.environments.ssr\n\n\tinvalidateModuleTree({\n\t\tentry: await moduleGraph.getModuleByUrl(entryFilePath),\n\t\tinvalidate: module => moduleGraph.invalidateModule(module)\n\t})\n\n\tconst userModule: any = await devServer.ssrLoadModule(entryFilePath)\n\n\tif (!userModule?.default) {\n\t\tthrow new Error(`Entry module does not export a default export: ${entryFilePath}`)\n\t}\n\n\tconst Component = userModule.default\n\tconst mod = await frameworkAdaptors[framework]()\n\tconst adaptor = mod.default\n\tconst { create, render } = adaptor\n\n\t// Resolve react/react-dom (and vue) from the user's project — the same\n\t// root Vite uses to resolve the document's jsx-runtime. Without this the\n\t// adaptor falls back to process.cwd(), which can resolve a different\n\t// framework copy: the document's elements would be created by one React\n\t// and rendered by another (\"Objects are not valid as a React child\").\n\tconst { getUserProjectDir } = await import('../project/user-project-dir')\n\tconst cwd = getUserProjectDir()\n\n\tconst element = await create({ Component, data, cwd })\n\tconst rawHtml = await render({ element: element as any, engine: engineVersion, cwd })\n\n\t// Stamp the producing release and inject the collected CSS as a document-level\n\t// <style>, in one parse. Empty payloads emit no tag (see finalize-document-html).\n\tconst combinedStyles = collectDocumentCss({\n\t\tentry: await moduleGraph.getModuleByUrl(entryFilePath),\n\t\tcss: compileState.getCss()\n\t})\n\n\t// This build's own two numbers, so an SDK rendering from a different release\n\t// fails here rather than having its output relabelled.\n\tlet finalHtml = finalizeDocumentHtml({\n\t\thtml: rawHtml,\n\t\tsdk: sdkVersion,\n\t\tengine: engineTarget,\n\t\tcss: combinedStyles\n\t})\n\n\t// Then the engine Studio actually resolved, which is the released target\n\t// unless FMT_ENGINE_VERSION pinned a local build. Written separately because\n\t// a locally pinned engine is not a different producing release: it changes\n\t// which engine lays the preview out and nothing about what produced it.\n\tfinalHtml = restampDocumentEngine(finalHtml, engineVersion)\n\n\tif (devDecodeStyleEntities) {\n\t\tfinalHtml = decodeStyleEntities(finalHtml)\n\t}\n\n\tconst isDebug = process.env.FORMAT_DEBUG === '1' || process.env.FORMAT_DEBUG === 'true'\n\n\tif (isDebug) {\n\t\tconst stylesLog = await formatForLog(combinedStyles, 'css')\n\t\tconst htmlLog = await formatForLog(finalHtml, 'html')\n\n\t\tconsole.log('Final styles\\n', `<style>\\n${stylesLog}</style>`)\n\t\t// This is the raw render output; the dev-server middleware sanitizes it afterwards\n\t\t// and logs the post-sanitize result as \"Final HTML (post-sanitize)\".\n\t\tconsole.log('Rendered HTML (pre-sanitize)\\n', htmlLog)\n\t}\n\n\treturn { html: finalHtml }\n}\n\nfunction reply(msg: WorkerResponse) {\n\tprocess.send!(msg)\n}\n\nprocess.on('message', async (msg: any) => {\n\tconst request = msg as WorkerRequest\n\ttry {\n\t\tswitch (request.type) {\n\t\t\tcase 'compile-render': {\n\t\t\t\tconst html = await handleCompileRender(request)\n\t\t\t\treply({ id: request.id, type: 'render-result', html })\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tcase 'dev-init': {\n\t\t\t\tawait handleDevInit(request)\n\t\t\t\treply({ id: request.id, type: 'dev-init-result' })\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tcase 'dev-render': {\n\t\t\t\tconst result = await handleDevRender(request)\n\t\t\t\treply({ id: request.id, type: 'render-result', html: result.html })\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\treply({\n\t\t\tid: request.id,\n\t\t\ttype: 'render-error',\n\t\t\terror: serializeError(error)\n\t\t})\n\t}\n})\n\n// Signal readiness to the parent process\nreply({ type: 'ready' } as WorkerResponse)\n"],"mappings":";;;;;;;;;;AA4BA,IAAI,QAAQ,IAAI,qBAAqB,WACpC,sBAAqB;AAGtB,eAAe,oBAAoB,SAAgD;CAClF,MAAM,EAAE,YAAY,cAAc,MAAM,QAAQ;CAGhD,MAAM,MAAM,IAAI,IAAI,cAAc,WAAW,CAAC,KAAK;AACnD,KA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AS,CAAmB"}
|
|
1
|
+
{"version":3,"file":"host.mjs","names":["devServer: ViteDevServer | null","frameworkAdaptors: Record<string, () => Promise<any>>","userModule: any"],"sources":["../../../src/server/render-worker/host.ts"],"sourcesContent":["/**\n * Render worker host — runs in a forked child process.\n *\n * Handles two execution paths:\n * 1. compile-render: imports a pre-built bundle, calls its render()\n * 2. dev-render: runs a headless Vite dev server with ssrLoadModule()\n * so all plugins (Vue SFC, Linaria, Vanilla Extract, etc.) work\n * with transforms and evaluation in the same process\n *\n * This process runs with a scrubbed environment (see env.ts), so user\n * code cannot access the parent process's secrets.\n */\n\nimport type { WorkerRequest, WorkerResponse, CompileRenderRequest, DevRenderRequest, DevInitRequest } from './types'\nimport type { ViteDevServer } from 'vite'\n\nimport { serializeError } from './error'\nimport { pathToFileURL } from 'node:url'\nimport { getDocumentExportName } from '@format.dev/cli/scaffold'\nimport { formatForLog } from '../utils/format-for-log'\nimport { finalizeDocumentHtml, restampDocumentEngine } from '../compile/finalize-document-html'\nimport { engineTarget, sdkVersion } from '../compile/producer-release'\nimport { applySandboxPatches } from './sandbox'\nimport { collectDocumentCss, invalidateModuleTree } from './document-css'\n\n// Apply JS-level API patches (network, child_process) before any user code\n// runs. In 'strict' mode, Node's permission model handles this\n// at the runtime level instead.\nif (process.env.FMT_SANDBOX_MODE === 'standard') {\n\tapplySandboxPatches()\n}\n\nasync function handleCompileRender(request: CompileRenderRequest): Promise<string> {\n\tconst { bundlePath, documentName, data, cwd } = request\n\n\t// Dynamic import with cache buster — same strategy as get-renderer.ts\n\tconst url = new URL(pathToFileURL(bundlePath).href)\n\turl.search = `?t=${Date.now()}-${Math.random().toString(36).slice(2)}`\n\n\tconst bundle = await import(url.href)\n\n\t// Resolve the named export (same logic as resolveRenderer in get-renderer.ts)\n\tconst exportName = getDocumentExportName(documentName)\n\n\tconst renderer = bundle?.[exportName] ?? bundle?.default?.[exportName] ?? bundle?.default?.default?.[exportName]\n\n\tif (!renderer) {\n\t\tthrow new Error(`Renderer export \"${exportName}\" not found for document \"${documentName}\"`)\n\t}\n\n\tconst result = await renderer.render(data || {}, cwd)\n\n\t// The CLI-compiled wrapper returns a FormatDocument object while the inner renderer\n\t// returns a plain string. Extract FormatDocument.html for IPC serialization.\n\treturn typeof result === 'object' && result !== null && 'html' in result ? result.html : result\n}\n\nlet devServer: ViteDevServer | null = null\nlet devDecodeStyleEntities = false\n\nasync function handleDevInit(request: DevInitRequest): Promise<void> {\n\tconst { root, configJson, decodeStyleEntities: decode } = request\n\n\tdevDecodeStyleEntities = decode === true\n\n\t// Hydrate runtime state so createConfig() and adaptors work\n\tconst { setUserProjectDir } = await import('../project/user-project-dir')\n\tsetUserProjectDir(root)\n\n\tconst { compileState } = await import('../runtime-state')\n\tcompileState.setConfig(JSON.parse(configJson))\n\n\t// Build Vite config using the same factory as the main server\n\tconst { createConfig } = await import('../vite/create-config')\n\tconst { collectCssPlugin } = await import('../vite/plugins/collect-css')\n\tconst { stylesPreProcessor } = await import('../vite/plugins/styles-pre-processor')\n\n\tconst { baseViteConfig, frameworkPlugins, stylePlugins } = createConfig()\n\n\tconst { createServer, mergeConfig } = await import('vite')\n\n\tconst { join } = await import('node:path')\n\tconst { tmpdir } = await import('node:os')\n\n\tconst workerLogger = {\n\t\tinfo: (msg: string) => console.log(msg),\n\t\twarn: (msg: string) => console.warn(msg),\n\t\terror: () => {},\n\t\twarnOnce: (msg: string) => console.warn(msg),\n\t\thasWarned: false,\n\t\tclearScreen: () => {},\n\t\thasErrorLogged: () => false\n\t}\n\n\tconst serverConfig = mergeConfig(baseViteConfig, {\n\t\tconfigFile: false,\n\t\tclearScreen: false,\n\t\tenvDir: false, // Block .env file loading — primary .env protection\n\t\tcacheDir: join(tmpdir(), 'format-vite-cache'),\n\t\tlogLevel: 'info',\n\t\tcustomLogger: workerLogger,\n\t\tserver: {\n\t\t\tmiddlewareMode: true,\n\t\t\twatch: null // No file watching — main server handles HMR\n\t\t},\n\t\tplugins: [await stylesPreProcessor(false), ...frameworkPlugins, ...stylePlugins, collectCssPlugin()],\n\t\tresolve: {\n\t\t\t// Force framework packages to resolve from the user's project\n\t\t\t// (Vite root) rather than from workspace packages like\n\t\t\t// @format.dev/react or @format.dev/vue, which may resolve to a different\n\t\t\t// version at the workspace root.\n\t\t\tdedupe: ['react', 'react-dom', 'vue', 'vue/server-renderer']\n\t\t},\n\t\tssr: {\n\t\t\t// We externalize third-party node_modules to Node's own loader,\n\t\t\t// which is the only path that handles CommonJS packages. Inlining\n\t\t\t// CJS into Vite's ESM module runner throws \"module is not defined\"\n\t\t\t// (its entry has no `module` global), so a document importing any\n\t\t\t// CJS-only library — highlight.js, and thousands like it — would\n\t\t\t// otherwise crash the render.\n\t\t\t//\n\t\t\t// noExternal as an array keeps Vite's default of auto-bundling\n\t\t\t// linked workspace packages and adds @format.dev/* on top, so our SDK\n\t\t\t// is always bundled (even when installed from npm, not symlinked).\n\t\t\t// Bundling routes its react/vue imports through resolve.dedupe\n\t\t\t// below, giving the user's single framework instance and avoiding\n\t\t\t// the dual-instance crashes that a blanket noExternal was added for.\n\t\t\t//\n\t\t\t// react/react-dom and vue/vue-server-renderer stay external\n\t\t\t// because their entry files are CJS (module.exports) which fails\n\t\t\t// in Vite's ESM evaluator. The adaptors manually load them from\n\t\t\t// the user's project via createRequire.\n\t\t\tnoExternal: [/@format(?:\\.dev)?\\//],\n\t\t\texternal: ['react', 'react-dom', 'vue', 'vue/server-renderer']\n\t\t},\n\t\toptimizeDeps: {\n\t\t\tnoDiscovery: true,\n\t\t\tentries: false\n\t\t}\n\t})\n\n\tdevServer = await createServer(serverConfig)\n}\n\nconst frameworkAdaptors: Record<string, () => Promise<any>> = {\n\treact: () => import('../compile/adaptors/react-node'),\n\tvue: () => import('../compile/adaptors/vue-node'),\n\thtml: () => import('../compile/adaptors/html')\n}\n\nasync function handleDevRender(request: DevRenderRequest): Promise<{ html: string }> {\n\tif (!devServer) {\n\t\tthrow new Error('Dev server not initialized. Send a dev-init message first.')\n\t}\n\n\tconst { entryFilePath, data, framework, engineVersion } = request\n\tconst { compileState } = await import('../runtime-state')\n\tconst { decodeStyleEntities } = await import('../compile/decode-style-entities')\n\n\tconsole.log(`Render started (framework=${framework}, engine=${engineVersion})`)\n\n\t// Look the entry up by URL, the same way ssrLoadModule resolves it, so\n\t// invalidation and CSS collection find the module that was loaded.\n\tconst { moduleGraph } = devServer.environments.ssr\n\n\tinvalidateModuleTree({\n\t\tentry: await moduleGraph.getModuleByUrl(entryFilePath),\n\t\tinvalidate: module => moduleGraph.invalidateModule(module)\n\t})\n\n\tconst userModule: any = await devServer.ssrLoadModule(entryFilePath)\n\n\tif (!userModule?.default) {\n\t\tthrow new Error(`Entry module does not export a default export: ${entryFilePath}`)\n\t}\n\n\tconst Component = userModule.default\n\tconst mod = await frameworkAdaptors[framework]()\n\tconst adaptor = mod.default\n\tconst { create, render } = adaptor\n\n\t// Resolve react/react-dom (and vue) from the user's project — the same\n\t// root Vite uses to resolve the document's jsx-runtime. Without this the\n\t// adaptor falls back to process.cwd(), which can resolve a different\n\t// framework copy: the document's elements would be created by one React\n\t// and rendered by another (\"Objects are not valid as a React child\").\n\tconst { getUserProjectDir } = await import('../project/user-project-dir')\n\tconst cwd = getUserProjectDir()\n\n\tconst element = await create({ Component, data, cwd })\n\tconst rawHtml = await render({ element: element as any, engine: engineVersion, cwd })\n\n\t// Stamp the producing release and inject the collected CSS as a document-level\n\t// <style>, in one parse. Empty payloads emit no tag (see finalize-document-html).\n\tconst combinedStyles = collectDocumentCss({\n\t\tentry: await moduleGraph.getModuleByUrl(entryFilePath),\n\t\tcss: compileState.getCss()\n\t})\n\n\t// This build's own two numbers, so an SDK rendering from a different release\n\t// fails here rather than having its output relabelled.\n\tlet finalHtml = finalizeDocumentHtml({\n\t\thtml: rawHtml,\n\t\tsdk: sdkVersion,\n\t\tengine: engineTarget,\n\t\tcss: combinedStyles\n\t})\n\n\t// Then the engine Studio actually resolved, which is the released target\n\t// unless FMT_ENGINE_VERSION pinned a local build. Written separately because\n\t// a locally pinned engine is not a different producing release: it changes\n\t// which engine lays the preview out and nothing about what produced it.\n\tfinalHtml = restampDocumentEngine(finalHtml, engineVersion)\n\n\tif (devDecodeStyleEntities) {\n\t\tfinalHtml = decodeStyleEntities(finalHtml)\n\t}\n\n\tconst isDebug = process.env.FORMAT_DEBUG === '1' || process.env.FORMAT_DEBUG === 'true'\n\n\tif (isDebug) {\n\t\tconst stylesLog = await formatForLog(combinedStyles, 'css')\n\t\tconst htmlLog = await formatForLog(finalHtml, 'html')\n\n\t\tconsole.log('Final styles\\n', `<style>\\n${stylesLog}</style>`)\n\t\t// This is the raw render output; the dev-server middleware sanitizes it afterwards\n\t\t// and logs the post-sanitize result as \"Final HTML (post-sanitize)\".\n\t\tconsole.log('Rendered HTML (pre-sanitize)\\n', htmlLog)\n\t}\n\n\treturn { html: finalHtml }\n}\n\nfunction reply(msg: WorkerResponse) {\n\tprocess.send!(msg)\n}\n\nprocess.on('message', async (msg: any) => {\n\tconst request = msg as WorkerRequest\n\ttry {\n\t\tswitch (request.type) {\n\t\t\tcase 'compile-render': {\n\t\t\t\tconst html = await handleCompileRender(request)\n\t\t\t\treply({ id: request.id, type: 'render-result', html })\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tcase 'dev-init': {\n\t\t\t\tawait handleDevInit(request)\n\t\t\t\treply({ id: request.id, type: 'dev-init-result' })\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tcase 'dev-render': {\n\t\t\t\tconst result = await handleDevRender(request)\n\t\t\t\treply({ id: request.id, type: 'render-result', html: result.html })\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\treply({\n\t\t\tid: request.id,\n\t\t\ttype: 'render-error',\n\t\t\terror: serializeError(error)\n\t\t})\n\t}\n})\n\n// Signal readiness to the parent process\nreply({ type: 'ready' } as WorkerResponse)\n"],"mappings":";;;;;;;;;;AA4BA,IAAI,QAAQ,IAAI,qBAAqB,WACpC,sBAAqB;AAGt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AACnE;;;UAGM,OAAO;AACf,QAAM;GACL,IAAI,QAAQ;GACZ,MAAM;GACN,OAAO,eAAe,MAAM;GAC5B,CAAC;;EAEF;AAGF,MAAM,EAAE,MAAM,SAAS,CAAmB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/server/render-worker/permission-flag.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The flag that turns on Node's permission model for a forked worker.
|
|
4
|
+
*
|
|
5
|
+
* Node 22.13 added `--permission` as the stable name and Node 24 removed
|
|
6
|
+
* `--experimental-permission`, so no single name works across the supported
|
|
7
|
+
* range. Ask the running Node which one it accepts instead of parsing its
|
|
8
|
+
* version: the worker is forked with the same binary.
|
|
9
|
+
*/
|
|
10
|
+
declare function getPermissionFlag(): '--permission' | '--experimental-permission';
|
|
11
|
+
//#endregion
|
|
12
|
+
export { getPermissionFlag };
|
|
13
|
+
//# sourceMappingURL=permission-flag.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-flag.d.mts","names":[],"sources":["../../../src/server/render-worker/permission-flag.ts"],"sourcesContent":[],"mappings":";;AAQA;;;;;;;iBAAgB,iBAAA,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/server/render-worker/permission-flag.ts
|
|
2
|
+
/**
|
|
3
|
+
* The flag that turns on Node's permission model for a forked worker.
|
|
4
|
+
*
|
|
5
|
+
* Node 22.13 added `--permission` as the stable name and Node 24 removed
|
|
6
|
+
* `--experimental-permission`, so no single name works across the supported
|
|
7
|
+
* range. Ask the running Node which one it accepts instead of parsing its
|
|
8
|
+
* version: the worker is forked with the same binary.
|
|
9
|
+
*/
|
|
10
|
+
function getPermissionFlag() {
|
|
11
|
+
if (process.allowedNodeEnvironmentFlags.has("--permission")) return "--permission";
|
|
12
|
+
return "--experimental-permission";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getPermissionFlag };
|
|
17
|
+
//# sourceMappingURL=permission-flag.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-flag.mjs","names":[],"sources":["../../../src/server/render-worker/permission-flag.ts"],"sourcesContent":["/**\n * The flag that turns on Node's permission model for a forked worker.\n *\n * Node 22.13 added `--permission` as the stable name and Node 24 removed\n * `--experimental-permission`, so no single name works across the supported\n * range. Ask the running Node which one it accepts instead of parsing its\n * version: the worker is forked with the same binary.\n */\nexport function getPermissionFlag(): '--permission' | '--experimental-permission' {\n\tconst hasStablePermissionFlag = process.allowedNodeEnvironmentFlags.has('--permission')\n\n\tif (hasStablePermissionFlag) {\n\t\treturn '--permission'\n\t}\n\n\treturn '--experimental-permission'\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,oBAAkE;AAGjF,KAFgC,QAAQ,4BAA4B,IAAI,eAAe,CAGtF,QAAO;AAGR,QAAO"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* JS-level API patches for the render worker subprocess.
|
|
4
4
|
*
|
|
5
5
|
* Applied in 'standard' sandbox mode (dev path) where Node's
|
|
6
|
-
*
|
|
6
|
+
* permission model can't be used because Vite's
|
|
7
7
|
* plugin toolchain needs unrestricted filesystem and child_process
|
|
8
8
|
* access (esbuild, Panda CSS, Tailwind, etc.).
|
|
9
9
|
*
|
|
@@ -5,7 +5,7 @@ import { createRequire } from "node:module";
|
|
|
5
5
|
* JS-level API patches for the render worker subprocess.
|
|
6
6
|
*
|
|
7
7
|
* Applied in 'standard' sandbox mode (dev path) where Node's
|
|
8
|
-
*
|
|
8
|
+
* permission model can't be used because Vite's
|
|
9
9
|
* plugin toolchain needs unrestricted filesystem and child_process
|
|
10
10
|
* access (esbuild, Panda CSS, Tailwind, etc.).
|
|
11
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.mjs","names":[],"sources":["../../../src/server/render-worker/sandbox.ts"],"sourcesContent":["/**\n * JS-level API patches for the render worker subprocess.\n *\n * Applied in 'standard' sandbox mode (dev path) where Node's\n *
|
|
1
|
+
{"version":3,"file":"sandbox.mjs","names":[],"sources":["../../../src/server/render-worker/sandbox.ts"],"sourcesContent":["/**\n * JS-level API patches for the render worker subprocess.\n *\n * Applied in 'standard' sandbox mode (dev path) where Node's\n * permission model can't be used because Vite's\n * plugin toolchain needs unrestricted filesystem and child_process\n * access (esbuild, Panda CSS, Tailwind, etc.).\n *\n * We patch outbound network APIs (fetch, http.request, https.request)\n * to block the primary exfiltration vector. Combined with the scrubbed\n * environment (env.ts), this means malicious template code can't read\n * secrets from process.env AND can't phone home with stolen data.\n *\n * What we intentionally do NOT patch:\n * - child_process: esbuild spawns its own binary, Panda CSS uses it\n * - net.Socket / net.connect: esbuild uses local sockets for IPC\n * - http.createServer: Vite creates an internal WebSocket server\n * - fs: Vite plugins need broad filesystem access\n */\n\nimport { createRequire } from 'node:module'\n\nconst require = createRequire(import.meta.url)\n\nexport const SANDBOX_ERROR_CODE = 'ERR_SANDBOX_RESTRICTION'\n\nfunction blocked(api: string): never {\n\tconst error = new Error(\n\t\t`The ${api} API is disabled in document template code. ` + 'Template code cannot make network requests.'\n\t)\n\terror.name = SANDBOX_ERROR_CODE\n\t;(error as any).code = SANDBOX_ERROR_CODE\n\tthrow error\n}\n\nfunction patchFetch() {\n\tglobalThis.fetch = function fetch(): never {\n\t\tblocked('fetch')\n\t}\n\n\tif (typeof globalThis.WebSocket !== 'undefined') {\n\t\tglobalThis.WebSocket = class WebSocket {\n\t\t\tconstructor() {\n\t\t\t\tblocked('WebSocket')\n\t\t\t}\n\t\t} as unknown as typeof globalThis.WebSocket\n\t}\n}\n\nfunction patchOutboundHttp() {\n\tconst http = require('node:http')\n\thttp.request = () => blocked('http.request')\n\thttp.get = () => blocked('http.get')\n\n\tconst https = require('node:https')\n\thttps.request = () => blocked('https.request')\n\thttps.get = () => blocked('https.get')\n\n\tconst tls = require('node:tls')\n\ttls.connect = () => blocked('tls.connect')\n\n\tconst dgram = require('node:dgram')\n\tdgram.createSocket = () => blocked('dgram.createSocket')\n}\n\nexport function applySandboxPatches() {\n\tpatchFetch()\n\tpatchOutboundHttp()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,MAAa,qBAAqB;AAElC,SAAS,QAAQ,KAAoB;CACpC,MAAM,wBAAQ,IAAI,MACjB,OAAO,IAAI,yFACX;AACD,OAAM,OAAO;AACZ,CAAC,MAAc,OAAO;AACvB,OAAM;;AAGP,SAAS,aAAa;AACrB,YAAW,QAAQ,SAAS,QAAe;AAC1C,UAAQ,QAAQ;;AAGjB,KAAI,OAAO,WAAW,cAAc,YACnC,YAAW,YAAY,MAAM,UAAU;EACtC,cAAc;AACb,WAAQ,YAAY;;;;AAMxB,SAAS,oBAAoB;CAC5B,MAAM,OAAO,QAAQ,YAAY;AACjC,MAAK,gBAAgB,QAAQ,eAAe;AAC5C,MAAK,YAAY,QAAQ,WAAW;CAEpC,MAAM,QAAQ,QAAQ,aAAa;AACnC,OAAM,gBAAgB,QAAQ,gBAAgB;AAC9C,OAAM,YAAY,QAAQ,YAAY;CAEtC,MAAM,MAAM,QAAQ,WAAW;AAC/B,KAAI,gBAAgB,QAAQ,cAAc;CAE1C,MAAM,QAAQ,QAAQ,aAAa;AACnC,OAAM,qBAAqB,QAAQ,qBAAqB;;AAGzD,SAAgB,sBAAsB;AACrC,aAAY;AACZ,oBAAmB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@format.dev/compile",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Compile Format documents into renderers, without the Studio UI",
|
|
6
6
|
"author": "the format.dev developers",
|
|
@@ -89,10 +89,10 @@
|
|
|
89
89
|
"vite": "8.3.2",
|
|
90
90
|
"vite-plugin-svgr": "^4.5.0",
|
|
91
91
|
"vite-svg-loader": "^5.1.0",
|
|
92
|
-
"@format.dev/cli": "0.
|
|
93
|
-
"@format.dev/
|
|
94
|
-
"@format.dev/zip": "0.
|
|
95
|
-
"@format.dev/
|
|
92
|
+
"@format.dev/cli": "0.4.0",
|
|
93
|
+
"@format.dev/utils": "0.4.0",
|
|
94
|
+
"@format.dev/zip": "0.4.0",
|
|
95
|
+
"@format.dev/types": "0.4.0"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@pandacss/dev": "^1.8.0",
|