@ms-cloudpack/app-server 0.20.1 → 0.20.3

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.
Files changed (31) hide show
  1. package/lib/renderRoute/injectScripts.js.map +1 -1
  2. package/lib/renderRoute/ssr/bundleServerEntry.d.ts +1 -1
  3. package/lib/renderRoute/ssr/bundleServerEntry.d.ts.map +1 -1
  4. package/lib/renderRoute/ssr/bundleServerEntry.js.map +1 -1
  5. package/lib/renderRoute/ssr/renderCustomScript.d.ts +1 -0
  6. package/lib/renderRoute/ssr/renderCustomScript.d.ts.map +1 -1
  7. package/lib/renderRoute/ssr/renderCustomScript.js +2 -8
  8. package/lib/renderRoute/ssr/renderCustomScript.js.map +1 -1
  9. package/lib/renderRoute/ssr/runServerEntryInWorker.d.ts +1 -1
  10. package/lib/renderRoute/ssr/runServerEntryInWorker.d.ts.map +1 -1
  11. package/lib/renderRoute/ssr/runServerEntryInWorker.js +8 -18
  12. package/lib/renderRoute/ssr/runServerEntryInWorker.js.map +1 -1
  13. package/lib/renderRoute/ssr/types/RunServerEntryOptions.d.ts +7 -2
  14. package/lib/renderRoute/ssr/types/RunServerEntryOptions.d.ts.map +1 -1
  15. package/lib/renderRoute/ssr/types/RunServerEntryOptions.js.map +1 -1
  16. package/lib/renderRoute/ssr/worker/importMapLoader.d.ts +30 -7
  17. package/lib/renderRoute/ssr/worker/importMapLoader.d.ts.map +1 -1
  18. package/lib/renderRoute/ssr/worker/importMapLoader.js +29 -2
  19. package/lib/renderRoute/ssr/worker/importMapLoader.js.map +1 -1
  20. package/lib/renderRoute/ssr/worker/runServerEntry.d.ts +10 -1
  21. package/lib/renderRoute/ssr/worker/runServerEntry.d.ts.map +1 -1
  22. package/lib/renderRoute/ssr/worker/runServerEntry.js +18 -8
  23. package/lib/renderRoute/ssr/worker/runServerEntry.js.map +1 -1
  24. package/lib/renderRoute/ssr/worker/ssrWorkerEntry.d.ts +2 -0
  25. package/lib/renderRoute/ssr/worker/ssrWorkerEntry.d.ts.map +1 -0
  26. package/lib/renderRoute/ssr/worker/{workerEntry.js → ssrWorkerEntry.js} +3 -3
  27. package/lib/renderRoute/ssr/worker/ssrWorkerEntry.js.map +1 -0
  28. package/package.json +4 -4
  29. package/lib/renderRoute/ssr/worker/workerEntry.d.ts +0 -2
  30. package/lib/renderRoute/ssr/worker/workerEntry.d.ts.map +0 -1
  31. package/lib/renderRoute/ssr/worker/workerEntry.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"injectScripts.js","sourceRoot":"","sources":["../../src/renderRoute/injectScripts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAiB,MAAM,WAAW,CAAC;AAClD,OAAO,cAAc,MAAM,iDAAiD,CAAC;AAE7E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA8B,EAC9B,MAAoC;IAEpC,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC1F,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,GAAG,EAAE,OAAO;QACZ,QAAQ,EAAE;YACR,4BAA4B,EAAE,IAAI;YAClC,2BAA2B,EAAE,IAAI;YACjC,qBAAqB,EAAE,IAAI;YAC3B,wBAAwB,EAAE,IAAI;SAC/B;KACF,CAAC,CAAC;IACH,IAAI,CAAC;QACH,+FAA+F;QAC/F,4FAA4F;QAC5F,oFAAoF;QACpF,4CAA4C;QAC5C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,0FAA0F;QAC1F,OAAO,CAAC,KAAK,CACX,oDAAoD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,OAAQ,CAAW,CAAC,KAAK,IAAI,CAAC,EAAE,CAChH,CAAC;QAC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I,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACpE,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;SAAM,IAAI,OAAO,EAAE,CAAC;QACnB,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC;IAC7B,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;AACH,CAAC","sourcesContent":["import type { RenderFunctionOptions, ExpandedRenderFunctionResult } from '@ms-cloudpack/common-types';\nimport { Window, type Document } from 'happy-dom';\nimport HTMLSerializer from 'happy-dom/lib/html-serializer/HTMLSerializer.js';\n\n/**\n * Modify the HTML response by injecting the import map, inline scripts, and entry/overlay scripts.\n *\n * Note that this just logs an error rather than returning an error response if something fails, for now.\n */\nexport async function injectScripts(\n options: RenderFunctionOptions,\n result: ExpandedRenderFunctionResult,\n): Promise<void> {\n const { route, overlayScript, entryScripts, inlineScripts, importMap, baseUrl } = options;\n const window = new Window({\n url: baseUrl,\n settings: {\n disableJavaScriptFileLoading: true,\n disableJavaScriptEvaluation: true,\n disableCSSFileLoading: true,\n disableIframePageLoading: true,\n },\n });\n try {\n // TODO: happy-dom is overkill for what we're doing here--a full browser-like environment isn't\n // needed to just parse and modify the HTML. If it becomes a perf concern (less likely since\n // HTML page rendering is probably just done once per page load), we could switch to\n // a pure parser like parse5 or htmlparser2.\n window.document.write(result.content);\n } catch (e) {\n // Trying to write a test for the above, it seemed very permissive, but catch just in case\n console.error(\n `Error parsing html response for rendering route \"${JSON.stringify(route.match)}\":\\n${(e as Error).stack || e}`,\n );\n return;\n }\n\n try {\n const document = window.document;\n\n if (entryScripts || overlayScript) {\n // Inject the import map at the top of the head, in case other scripts use it\n addScript({ document, type: 'importmap', prepend: true, content: JSON.stringify(importMap, null, 2) });\n }\n\n if (inlineScripts) {\n for (const inlineScript of inlineScripts) {\n addScript({ document, content: inlineScript });\n }\n }\n\n // inject the overlay and entry scripts\n addScript({ document, url: overlayScript });\n\n if (entryScripts) {\n for (const entryScript of entryScripts) {\n addScript({ document, url: entryScript });\n }\n }\n\n const serializer = new HTMLSerializer();\n result.content = serializer.serializeToString(document);\n await window.happyDOM.close();\n } catch (e) {\n console.error(`Error injecting scripts for route \"${JSON.stringify(route.match)}\":\\n${(e as Error).stack || e}`);\n }\n}\n/**\n * Helper function to add a script to the document.\n * No-op if neither `url` nor `content` is provided.\n */\nfunction addScript(params: {\n document: Document;\n type?: string;\n prepend?: boolean;\n url?: string;\n content?: string;\n}): void {\n const { document, type = 'module', prepend, url, content } = params;\n if (!url && !content) {\n return;\n }\n\n const script = document.createElement('script');\n script.type = type;\n if (url) {\n script.src = url;\n } else if (content) {\n script.innerHTML = content;\n }\n\n if (prepend) {\n document.head.prepend(script);\n } else {\n document.head.appendChild(script);\n }\n}\n"]}
1
+ {"version":3,"file":"injectScripts.js","sourceRoot":"","sources":["../../src/renderRoute/injectScripts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAiB,MAAM,WAAW,CAAC;AAClD,OAAO,cAAc,MAAM,iDAAiD,CAAC;AAE7E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA8B,EAC9B,MAAoC;IAEpC,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAA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derFunctionResult } from '@ms-cloudpack/common-types';\nimport { Window, type Document } from 'happy-dom';\nimport HTMLSerializer from 'happy-dom/lib/html-serializer/HTMLSerializer.js';\n\n/**\n * Modify the HTML response by injecting the import map, inline scripts, and entry/overlay scripts.\n *\n * Note that this just logs an error rather than returning an error response if something fails, for now.\n */\nexport async function injectScripts(\n options: RenderFunctionOptions,\n result: ExpandedRenderFunctionResult,\n): Promise<void> {\n const { route, overlayScript, entryScripts, inlineScripts, importMap, baseUrl } = options;\n const window = new Window({\n url: baseUrl,\n settings: {\n disableJavaScriptFileLoading: true,\n disableJavaScriptEvaluation: true,\n disableCSSFileLoading: true,\n disableIframePageLoading: true,\n },\n });\n try {\n // TODO: happy-dom is overkill for what we're doing here--a full browser-like environment isn't\n // needed to just parse and modify the HTML. If it becomes a perf concern (less likely since\n // HTML page rendering is probably just done once per page load), we could switch to\n // a pure parser like parse5 or htmlparser2.\n window.document.write(result.content);\n } catch (e) {\n // Trying to write a test for the above, it seemed very permissive, but catch just in case\n console.error(\n `Error parsing html response for rendering route \"${JSON.stringify(route.match)}\":\\n${(e as Error).stack || e}`,\n );\n return;\n }\n\n try {\n const document = window.document;\n\n if (entryScripts || overlayScript) {\n // Inject the import map at the top of the head, in case other scripts use it\n addScript({ document, type: 'importmap', prepend: true, content: JSON.stringify(importMap, null, 2) });\n }\n\n if (inlineScripts) {\n for (const inlineScript of inlineScripts) {\n addScript({ document, content: inlineScript });\n }\n }\n\n // inject the overlay and entry scripts\n addScript({ document, url: overlayScript });\n\n if (entryScripts) {\n for (const entryScript of entryScripts) {\n addScript({ document, url: entryScript });\n }\n }\n\n const serializer = new HTMLSerializer();\n result.content = serializer.serializeToString(document);\n await window.happyDOM.close();\n } catch (e) {\n console.error(`Error injecting scripts for route \"${JSON.stringify(route.match)}\":\\n${(e as Error).stack || e}`);\n }\n}\n\n/**\n * Helper function to add a script to the document.\n * No-op if neither `url` nor `content` is provided.\n */\nfunction addScript(params: {\n document: Document;\n type?: string;\n prepend?: boolean;\n url?: string;\n content?: string;\n}): void {\n const { document, type = 'module', prepend, url, content } = params;\n if (!url && !content) {\n return;\n }\n\n const script = document.createElement('script');\n script.type = type;\n if (url) {\n script.src = url;\n } else if (content) {\n script.innerHTML = content;\n }\n\n if (prepend) {\n document.head.prepend(script);\n } else {\n document.head.appendChild(script);\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { type EnsurePackageBundledContext } from '@ms-cloudpack/api-server';
2
2
  import type { RenderFunctionOptions, ExpandedRenderFunctionResult } from '@ms-cloudpack/common-types';
3
- export declare function bundleServerEntry(options: Pick<RenderFunctionOptions, 'definition' | 'route' | 'req' | 'baseUrl'> & {
3
+ export declare function bundleServerEntry(options: Pick<RenderFunctionOptions, 'definition' | 'route' | 'req'> & {
4
4
  /** Relative serverEntry source path from the route */
5
5
  serverEntryPath: string;
6
6
  }, context: EnsurePackageBundledContext): Promise<string | ExpandedRenderFunctionResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"bundleServerEntry.d.ts","sourceRoot":"","sources":["../../../src/renderRoute/ssr/bundleServerEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,2BAA2B,EAAwB,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAOtG,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,YAAY,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,CAAC,GAAG;IACjF,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;CACzB,EACD,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,MAAM,GAAG,4BAA4B,CAAC,CAwDhD"}
1
+ {"version":3,"file":"bundleServerEntry.d.ts","sourceRoot":"","sources":["../../../src/renderRoute/ssr/bundleServerEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,2BAA2B,EAAwB,MAAM,0BAA0B,CA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AAC,CAAC,UAAU,YAAY,CAAC,CAAC,UAAU,IAAI,SAAS,GAAG,CAAC,CAAC;gBAC/F,CAAC,CAAC,MACN,EAAE;YACF,KAAK;YACL,GAAG;YACH,UAAU,EAAE,eAAe;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,2DAA2D;IAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { type EnsurePackageBundledContext, ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport type { RenderFunctionOptions, ExpandedRenderFunctionResult } from '@ms-cloudpack/common-types';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport { sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport { bulletedList } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { getCustomRenderErrorResponse } from '../getErrorResponse.js';\n\nexport async function bundleServerEntry(\n options: Pick<RenderFunctionOptions, 'definition' | 'route' | 'req' | 'baseUrl'> & {\n /** Relative serverEntry source path from the route */\n serverEntryPath: string;\n },\n context: EnsurePackageBundledContext,\n): Promise<string | ExpandedRenderFunctionResult> {\n const { definition, route, req, serverEntryPath } = options;\n const { name, version } = definition;\n\n // targetEnvironment: node currently bundles all node or agnostic entries, and implicitly does\n // production bundling. This seems like it could get expensive, but it's probably okay because\n // createPackageSettingsTransform overwrites the package's actual exports with the ones generated\n // from routes, and those will always have environment conditions.\n const response = await ensurePackageBundled(\n {\n name,\n version,\n targetEnvironment: 'node',\n // TODO: This will only watch for changes in the given package, not dependencies.\n // File watching is disabled in production mode for performance.\n shouldWatch: !environmentInfo.isJest && context.session.config.mode !== 'production',\n // Irrelevant with implicit production bundling\n enqueueDependencies: false,\n },\n context,\n );\n const { errors, outputPath = '', outputFiles = [] } = response.result;\n\n if (errors?.length) {\n return getCustomRenderErrorResponse({\n message: `failed to bundle: ${JSON.stringify(response.result.errors, null, 2)}`,\n route,\n req,\n scriptPath: serverEntryPath,\n });\n }\n\n let serverEntryOutput = outputFiles.find((f) => f.entryPoint === serverEntryPath)?.outputPath;\n if (!serverEntryOutput) {\n // No literal match, so try the intermediate path without extension.\n const intermediateServerEntryPath = sourceToIntermediatePath(serverEntryPath).replace(/\\.\\w+$/, '');\n serverEntryOutput =\n outputFiles.find((f) => f.entryPoint === serverEntryPath)?.outputPath ||\n outputFiles.find((f) => f.outputPath.replace(/\\.\\w+$/, '') === intermediateServerEntryPath)?.outputPath;\n }\n\n if (!serverEntryOutput) {\n return getCustomRenderErrorResponse({\n message: `did not produce a bundle output file corresponding to the serverEntry script (${serverEntryPath}). Produced files:\\n${\n outputFiles.length\n ? bulletedList(outputFiles.map((f) => `${f.outputPath} (entry: ${f.entryPoint || 'unknown'})`))\n : 'none'\n }`,\n route,\n req,\n scriptPath: serverEntryPath,\n });\n }\n\n // Translate relative-to-output path into an absolute path.\n return path.resolve(outputPath, serverEntryOutput);\n}\n"]}
1
+ {"version":3,"file":"bundleServerEntry.js","sourceRoot":"","sources":["../../../src/renderRoute/ssr/bundleServerEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAElG,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAEtE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAGC,EACD,OAAoC;IAEpC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAC5D,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAErC,8FAA8F;IAC9F,8FAA8F;IAC9F,iGAAiG;IACjG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,EAAE,UAAU,CAAC;IAC5G,CAAC;IAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,4BAA4B,CAAC;YAClC,OAAO,EAAE,iFAAiF,eAAe,uBACvG,WAAW,CAAC,MAAM;gBAChB,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,YAAY,CAAC,CAAC,UAAU,IAAI,SAAS,GAAG,CAAC,CAAC;gBAC/F,CAAC,CAAC,MACN,EAAE;YACF,KAAK;YACL,GAAG;YACH,UAAU,EAAE,eAAe;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,2DAA2D;IAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { type EnsurePackageBundledContext, ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport type { RenderFunctionOptions, ExpandedRenderFunctionResult } from '@ms-cloudpack/common-types';\nimport { environmentInfo } from '@ms-cloudpack/environment';\nimport { sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport { bulletedList } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { getCustomRenderErrorResponse } from '../getErrorResponse.js';\n\nexport async function bundleServerEntry(\n options: Pick<RenderFunctionOptions, 'definition' | 'route' | 'req'> & {\n /** Relative serverEntry source path from the route */\n serverEntryPath: string;\n },\n context: EnsurePackageBundledContext,\n): Promise<string | ExpandedRenderFunctionResult> {\n const { definition, route, req, serverEntryPath } = options;\n const { name, version } = definition;\n\n // targetEnvironment: node currently bundles all node or agnostic entries, and implicitly does\n // production bundling. This seems like it could get expensive, but it's probably okay because\n // createPackageSettingsTransform overwrites the package's actual exports with the ones generated\n // from routes, and those will always have environment conditions.\n const response = await ensurePackageBundled(\n {\n name,\n version,\n targetEnvironment: 'node',\n // TODO: This will only watch for changes in the given package, not dependencies.\n // File watching is disabled in production mode for performance.\n shouldWatch: !environmentInfo.isJest && context.session.config.mode !== 'production',\n // Irrelevant with implicit production bundling\n enqueueDependencies: false,\n },\n context,\n );\n const { errors, outputPath = '', outputFiles = [] } = response.result;\n\n if (errors?.length) {\n return getCustomRenderErrorResponse({\n message: `failed to bundle: ${JSON.stringify(response.result.errors, null, 2)}`,\n route,\n req,\n scriptPath: serverEntryPath,\n });\n }\n\n let serverEntryOutput = outputFiles.find((f) => f.entryPoint === serverEntryPath)?.outputPath;\n if (!serverEntryOutput) {\n // No literal match, so try the intermediate path without extension.\n const intermediateServerEntryPath = sourceToIntermediatePath(serverEntryPath).replace(/\\.\\w+$/, '');\n serverEntryOutput =\n outputFiles.find((f) => f.entryPoint === serverEntryPath)?.outputPath ||\n outputFiles.find((f) => f.outputPath.replace(/\\.\\w+$/, '') === intermediateServerEntryPath)?.outputPath;\n }\n\n if (!serverEntryOutput) {\n return getCustomRenderErrorResponse({\n message: `did not produce a bundle output file corresponding to the serverEntry script (${serverEntryPath}). Produced files:\\n${\n outputFiles.length\n ? bulletedList(outputFiles.map((f) => `${f.outputPath} (entry: ${f.entryPoint || 'unknown'})`))\n : 'none'\n }`,\n route,\n req,\n scriptPath: serverEntryPath,\n });\n }\n\n // Translate relative-to-output path into an absolute path.\n return path.resolve(outputPath, serverEntryOutput);\n}\n"]}
@@ -4,6 +4,7 @@ import type { RenderFunctionOptions, RenderFunctionResult } from '@ms-cloudpack/
4
4
  * and return either the result of running the function, or an error page if something fails.
5
5
  */
6
6
  export declare function renderCustomScript(params: RenderFunctionOptions & {
7
+ /** Full path to the render script (bundled version if relevant) */
7
8
  renderScriptPath: string;
8
9
  }): Promise<RenderFunctionResult>;
9
10
  //# sourceMappingURL=renderCustomScript.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderCustomScript.d.ts","sourceRoot":"","sources":["../../../src/renderRoute/ssr/renderCustomScript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,qBAAqB,EACrB,oBAAoB,EAErB,MAAM,4BAA4B,CAAC;AAOpC;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,qBAAqB,GAAG;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAAE,GAC3D,OAAO,CAAC,oBAAoB,CAAC,CAyD/B"}
1
+ {"version":3,"file":"renderCustomScript.d.ts","sourceRoot":"","sources":["../../../src/renderRoute/ssr/renderCustomScript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,qBAAqB,EACrB,oBAAoB,EAErB,MAAM,4BAA4B,CAAC;AAMpC;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,qBAAqB,GAAG;IAC9B,mEAAmE;IACnE,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACA,OAAO,CAAC,oBAAoB,CAAC,CAyD/B"}
@@ -1,8 +1,7 @@
1
- import { fileURLToPath, pathToFileURL } from 'url';
2
1
  import fsPromises from 'fs/promises';
3
- import path from 'path';
4
- import { runServerEntryInWorker } from './runServerEntryInWorker.js';
2
+ import { pathToFileURL } from 'url';
5
3
  import { getCustomRenderErrorResponse, getErrorResponse } from '../getErrorResponse.js';
4
+ import { runServerEntryInWorker } from './runServerEntryInWorker.js';
6
5
  /**
7
6
  * Load the default export from a JS file passed as the `renderScript` in a route,
8
7
  * and return either the result of running the function, or an error page if something fails.
@@ -65,12 +64,7 @@ export async function renderCustomScript(params) {
65
64
  }
66
65
  async function executeRenderScriptInSsrMode(params) {
67
66
  const { renderScriptPath, renderScriptUrl, importMap, options } = params;
68
- const dirname = path.dirname(fileURLToPath(import.meta.url));
69
- // Tests run the worker from the compiled version, so we need to replace /src/ with /lib/ in the path.
70
- // This replace call has no effect in production, where the worker is always run from the compiled version.
71
- const loaderPath = path.join(dirname, 'worker/importMapLoader.js').replace(/\/src\//, '/lib/');
72
67
  const serverEntryResult = await runServerEntryInWorker({
73
- loaderPath,
74
68
  renderScriptUrl,
75
69
  importMap,
76
70
  renderParams: {},
@@ -1 +1 @@
1
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AC,OAAO,EAAE,2BAA2B,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAE/F,MAAM,iBAAiB,GAAG,MAAM,sBAAsB,CAAC;QACrD,UAAU;QACV,eAAe;QACf,SAAS;QACT,YAAY,EAAE,EAAE;KACjB,CAAC,CAAC;IAEH,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,iBAAiB,CAAC;IACtD,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,4BAA4B,CAAC;YAClC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,OAAO,EAAE,2BAA2B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAC1E,UAAU,EAAE,gBAAgB;SAC7B,CAAC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;AACjF,CAAC","sourcesContent":["import type {\n ExpandedRenderFunctionResult,\n ImportMap,\n RenderFunction,\n RenderFunctionOptions,\n RenderFunctionResult,\n RenderFunctionScript,\n} from '@ms-cloudpack/common-types';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport fsPromises from 'fs/promises';\nimport path from 'path';\nimport { runServerEntryInWorker } from './runServerEntryInWorker.js';\nimport { getCustomRenderErrorResponse, getErrorResponse } from '../getErrorResponse.js';\n\n/**\n * Load the default export from a JS file passed as the `renderScript` in a route,\n * and return either the result of running the function, or an error page if something fails.\n */\nexport async function renderCustomScript(\n params: RenderFunctionOptions & { renderScriptPath: string },\n): Promise<RenderFunctionResult> {\n const { renderScriptPath, ...options } = params;\n // Get the html factory function from a script default export.\n const renderScriptUrl = pathToFileURL(renderScriptPath).toString();\n\n // Note: because there isn't a way to purge the require cache, we need to add a cache breaker query param to the\n // script path to ensure we get the latest version of the script. This could be improved by using the git hash of\n // the file if it exists, or a hash of the content, or even the timestamp of the file.\n // TODO: this won't work to update anything the file imports, and doesn't seem to work for serverEntry at all...\n let cacheBreakerQueryParam = `?t=${Date.now()}`;\n try {\n const { mtime } = await fsPromises.stat(renderScriptPath);\n cacheBreakerQueryParam = `?t=${mtime.getTime()}`;\n } catch {\n /* no-op */\n }\n\n const renderScriptUrlWithCacheBreaker = renderScriptUrl + cacheBreakerQueryParam;\n\n const { config } = options.session;\n if (config.features?.enableSSR) {\n return executeRenderScriptInSsrMode({\n renderScriptPath,\n renderScriptUrl: renderScriptUrlWithCacheBreaker,\n // TODO this should be a Node-specific import map\n importMap: options.importMap,\n options,\n });\n }\n\n // Try importing the script\n let createHtml: RenderFunction | undefined;\n let errorMessage: string | undefined;\n try {\n const importResult = ((await import(renderScriptUrlWithCacheBreaker)) as RenderFunctionScript).default;\n if (typeof importResult === 'function') {\n createHtml = importResult;\n } else {\n errorMessage = `The render script at \"${renderScriptPath}\" does not export a default function.`;\n }\n } catch (e) {\n errorMessage = `Error importing render script at \"${renderScriptUrl}\":\\n${(e as Error).stack || e}`;\n }\n\n if (createHtml) {\n // Try running the script\n try {\n return await createHtml(options);\n } catch (e) {\n errorMessage = `Error running render script at \"${renderScriptPath}\":\\n${(e as Error).stack || e}`;\n }\n }\n\n // Return an error page. Doing this instead of returning a default or empty response ensures that\n // the user is aware of any configuration issues.\n errorMessage ??= `Unknown error loading render script at \"${renderScriptPath}\".`;\n return getErrorResponse({ req: options.req, message: errorMessage });\n}\n\nasync function executeRenderScriptInSsrMode(params: {\n renderScriptPath: string;\n renderScriptUrl: string;\n importMap: ImportMap;\n options: RenderFunctionOptions;\n}): Promise<ExpandedRenderFunctionResult> {\n const { renderScriptPath, renderScriptUrl, importMap, options } = params;\n\n const dirname = path.dirname(fileURLToPath(import.meta.url));\n // Tests run the worker from the compiled version, so we need to replace /src/ with /lib/ in the path.\n // This replace call has no effect in production, where the worker is always run from the compiled version.\n const loaderPath = path.join(dirname, 'worker/importMapLoader.js').replace(/\\/src\\//, '/lib/');\n\n const serverEntryResult = await runServerEntryInWorker({\n loaderPath,\n renderScriptUrl,\n importMap,\n renderParams: {},\n });\n\n const { errors, renderedContent } = serverEntryResult;\n if (errors?.length) {\n return getCustomRenderErrorResponse({\n req: options.req,\n route: options.route,\n message: `- error running script: ${errors.map((e) => e.text).join('\\n')}`,\n scriptPath: renderScriptPath,\n });\n }\n return { content: renderedContent, contentType: 'text/html', statusCode: 200 };\n}\n"]}
1
+ {"version":3,"file":"renderCustomScript.js","sourceRoot":"","sources":["../../../src/renderRoute/ssr/renderCustomScript.ts"],"names":[],"mappings":"AAQA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAGC;IAED,MAAM,EAAE,gBAAgB,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC;IAChD,8DAA8D;IAC9D,MAAM,eAAe,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE,CAAC;IAEnE,gHAAgH;IAChH,iHAAiH;IACjH,sFAAsF;IACtF,gHAAgH;IAChH,IAAI,sBAAsB,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAChD,IAAI,CAAC;QACH,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC1D,sBAAsB,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,WAAW;IACb,CAAC;IAED,MAAM,+BAA+B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AK,UAAU,4BAA4B,CAAC,MAK3C;IACC,MAAM,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAEzE,MAAM,iBAAiB,GAAG,MAAM,sBAAsB,CAAC;QACrD,eAAe;QACf,SAAS;QACT,YAAY,EAAE,EAAE;KACjB,CAAC,CAAC;IAEH,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,iBAAiB,CAAC;IACtD,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,4BAA4B,CAAC;YAClC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,OAAO,EAAE,2BAA2B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAC1E,UAAU,EAAE,gBAAgB;SAC7B,CAAC,CAAC;IACL,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;AACjF,CAAC","sourcesContent":["import type {\n ExpandedRenderFunctionResult,\n ImportMap,\n RenderFunction,\n RenderFunctionOptions,\n RenderFunctionResult,\n RenderFunctionScript,\n} from '@ms-cloudpack/common-types';\nimport fsPromises from 'fs/promises';\nimport { pathToFileURL } from 'url';\nimport { getCustomRenderErrorResponse, getErrorResponse } from '../getErrorResponse.js';\nimport { runServerEntryInWorker } from './runServerEntryInWorker.js';\n\n/**\n * Load the default export from a JS file passed as the `renderScript` in a route,\n * and return either the result of running the function, or an error page if something fails.\n */\nexport async function renderCustomScript(\n params: RenderFunctionOptions & {\n /** Full path to the render script (bundled version if relevant) */\n renderScriptPath: string;\n },\n): Promise<RenderFunctionResult> {\n const { renderScriptPath, ...options } = params;\n // Get the html factory function from a script default export.\n const renderScriptUrl = pathToFileURL(renderScriptPath).toString();\n\n // Note: because there isn't a way to purge the require cache, we need to add a cache breaker query param to the\n // script path to ensure we get the latest version of the script. This could be improved by using the git hash of\n // the file if it exists, or a hash of the content, or even the timestamp of the file.\n // TODO: this won't work to update anything the file imports, and doesn't seem to work for serverEntry at all...\n let cacheBreakerQueryParam = `?t=${Date.now()}`;\n try {\n const { mtime } = await fsPromises.stat(renderScriptPath);\n cacheBreakerQueryParam = `?t=${mtime.getTime()}`;\n } catch {\n /* no-op */\n }\n\n const renderScriptUrlWithCacheBreaker = renderScriptUrl + cacheBreakerQueryParam;\n\n const { config } = options.session;\n if (config.features?.enableSSR) {\n return executeRenderScriptInSsrMode({\n renderScriptPath,\n renderScriptUrl: renderScriptUrlWithCacheBreaker,\n // TODO this should be a Node-specific import map\n importMap: options.importMap,\n options,\n });\n }\n\n // Try importing the script\n let createHtml: RenderFunction | undefined;\n let errorMessage: string | undefined;\n try {\n const importResult = ((await import(renderScriptUrlWithCacheBreaker)) as RenderFunctionScript).default;\n if (typeof importResult === 'function') {\n createHtml = importResult;\n } else {\n errorMessage = `The render script at \"${renderScriptPath}\" does not export a default function.`;\n }\n } catch (e) {\n errorMessage = `Error importing render script at \"${renderScriptUrl}\":\\n${(e as Error).stack || e}`;\n }\n\n if (createHtml) {\n // Try running the script\n try {\n return await createHtml(options);\n } catch (e) {\n errorMessage = `Error running render script at \"${renderScriptPath}\":\\n${(e as Error).stack || e}`;\n }\n }\n\n // Return an error page. Doing this instead of returning a default or empty response ensures that\n // the user is aware of any configuration issues.\n errorMessage ??= `Unknown error loading render script at \"${renderScriptPath}\".`;\n return getErrorResponse({ req: options.req, message: errorMessage });\n}\n\nasync function executeRenderScriptInSsrMode(params: {\n renderScriptPath: string;\n renderScriptUrl: string;\n importMap: ImportMap;\n options: RenderFunctionOptions;\n}): Promise<ExpandedRenderFunctionResult> {\n const { renderScriptPath, renderScriptUrl, importMap, options } = params;\n\n const serverEntryResult = await runServerEntryInWorker({\n renderScriptUrl,\n importMap,\n renderParams: {},\n });\n\n const { errors, renderedContent } = serverEntryResult;\n if (errors?.length) {\n return getCustomRenderErrorResponse({\n req: options.req,\n route: options.route,\n message: `- error running script: ${errors.map((e) => e.text).join('\\n')}`,\n scriptPath: renderScriptPath,\n });\n }\n return { content: renderedContent, contentType: 'text/html', statusCode: 200 };\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { RunServerEntryOptions } from './types/RunServerEntryOptions.js';
2
2
  import type { RunServerEntryResult } from './types/RunServerEntryResult.js';
3
3
  /**
4
- * Run server entry in a worker pool.
4
+ * Run server entry in a child process pool. (Despite the naming, this does not use worker threads.)
5
5
  */
6
6
  export declare function runServerEntryInWorker(options: RunServerEntryOptions & {
7
7
  maxWorkers?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"runServerEntryInWorker.d.ts","sourceRoot":"","sources":["../../../src/renderRoute/ssr/runServerEntryInWorker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAW5E;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,qBAAqB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACvD,OAAO,CAAC,oBAAoB,CAAC,CAqC/B;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3D"}
1
+ {"version":3,"file":"runServerEntryInWorker.d.ts","sourceRoot":"","sources":["../../../src/renderRoute/ssr/runServerEntryInWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAO5E;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,qBAAqB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACvD,OAAO,CAAC,oBAAoB,CAAC,CAgC/B;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3D"}
@@ -1,31 +1,21 @@
1
- import { getAdjustedTimeout } from '@ms-cloudpack/environment';
2
1
  import { WorkerPool } from '@ms-cloudpack/worker-pool';
3
2
  import path from 'path';
4
- import { fileURLToPath } from 'url';
5
- const dirname = path.dirname(fileURLToPath(import.meta.url));
6
- // Tests run the worker from the compiled version, so we need to replace /src/ with /lib/ in the path.
7
- // This replace call has no effect in production, where the worker is always run from the compiled version.
8
- const workerPath = path.join(dirname, 'worker/workerEntry.js').replace(/\/src\//, '/lib/');
3
+ const workerPath = path.join(import.meta.dirname, 'worker/ssrProcessEntry.js');
9
4
  let workerPool;
10
5
  /**
11
- * Run server entry in a worker pool.
6
+ * Run server entry in a child process pool. (Despite the naming, this does not use worker threads.)
12
7
  */
13
8
  export async function runServerEntryInWorker(options) {
14
9
  workerPool ??= new WorkerPool({
15
10
  workerType: 'process',
16
- name: 'Server Entry Execution',
11
+ name: 'serverEntry execution',
17
12
  entryPath: workerPath,
18
- maxWorkers: options.maxWorkers || 5,
19
- // Stop inactive workers after 5 minutes. This is intended to prevent one possible cause of
20
- // OOM crashes if cloudpack start is left running for a long time (though it's much more likely
21
- // that the issue is caused by servers or file watchers). The timeout is conservative because
22
- // the fake browser environment has nontrivial startup time, so killing workers too quickly
23
- // could slow down rebuilds.
13
+ // Currently we're unlikely to be server-rendering more than one thing at a time.
14
+ // Keep this low unless we find a case where it needs to be higher.
15
+ maxWorkers: 3,
16
+ // Stop inactive processes after 5 minutes. This is intended to prevent one possible cause of
17
+ // OOM crashes if cloudpack start is left running for a long time.
24
18
  inactiveTimeout: 5 * 60 * 1000,
25
- // max heap size for running server entry in worker pool
26
- maxHeapSize: 500 * 1024 * 1024,
27
- // console.warn if running a server entry in work pool takes too long
28
- warnAboveTime: getAdjustedTimeout(2000),
29
19
  });
30
20
  try {
31
21
  const runServerEntryResult = await workerPool.execute({
@@ -1 +1 @@
1
- {"version":3,"file":"runServerEntryInWorker.js","sourceRoot":"","sources":["../../../src/renderRoute/ssr/runServerEntryInWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7D,sGAAsG;AACtG,2GAA2G;AAC3G,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAE3F,IAAI,UAAkC,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAwD;IAExD,UAAU,KAAK,IAAI,UAAU,CAAC;QAC5B,UAAU,EAAE,SAAS;QACrB,IAAI,EAAE,wBAAwB;QAC9B,SAAS,EAAE,UAAU;QACrB,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC;QACnC,2FAA2F;QAC3F,+FAA+F;QAC/F,6FAA6F;QAC7F,2FAA2F;QAC3F,4BAA4B;QAC5B,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;QAC9B,wDAAwD;QACxD,WAAW,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;QAC9B,qEAAqE;QACrE,aAAa,EAAE,kBAAkB,CAAC,IAAI,CAAC;KACxC,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,oBAAoB,GAAG,MAAM,UAAU,CAAC,OAAO,CAAuB;YAC1E,MAAM,EAAE,gBAAgB;YACxB,IAAI,EAAE,CAAC,OAAO,CAAC;SAChB,CAAC,CAAC;QAEH,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,eAAe,EAAE,EAAE;YACnB,MAAM,EAAE;gBACN;oBACE,MAAM,EAAE,wBAAwB;oBAChC,mEAAmE;oBACnE,IAAI,EAAG,GAAa,EAAE,KAAK,IAAK,GAAa,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC;iBACtE;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,UAAU,EAAE,OAAO,EAAE,CAAC;IAC5B,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["import { getAdjustedTimeout } from '@ms-cloudpack/environment';\nimport { WorkerPool } from '@ms-cloudpack/worker-pool';\nimport type { RunServerEntryOptions } from './types/RunServerEntryOptions.js';\nimport type { RunServerEntryResult } from './types/RunServerEntryResult.js';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\n// Tests run the worker from the compiled version, so we need to replace /src/ with /lib/ in the path.\n// This replace call has no effect in production, where the worker is always run from the compiled version.\nconst workerPath = path.join(dirname, 'worker/workerEntry.js').replace(/\\/src\\//, '/lib/');\n\nlet workerPool: WorkerPool | undefined;\n\n/**\n * Run server entry in a worker pool.\n */\nexport async function runServerEntryInWorker(\n options: RunServerEntryOptions & { maxWorkers?: number },\n): Promise<RunServerEntryResult> {\n workerPool ??= new WorkerPool({\n workerType: 'process',\n name: 'Server Entry Execution',\n entryPath: workerPath,\n maxWorkers: options.maxWorkers || 5,\n // Stop inactive workers after 5 minutes. This is intended to prevent one possible cause of\n // OOM crashes if cloudpack start is left running for a long time (though it's much more likely\n // that the issue is caused by servers or file watchers). The timeout is conservative because\n // the fake browser environment has nontrivial startup time, so killing workers too quickly\n // could slow down rebuilds.\n inactiveTimeout: 5 * 60 * 1000,\n // max heap size for running server entry in worker pool\n maxHeapSize: 500 * 1024 * 1024,\n // console.warn if running a server entry in work pool takes too long\n warnAboveTime: getAdjustedTimeout(2000),\n });\n\n try {\n const runServerEntryResult = await workerPool.execute<RunServerEntryResult>({\n method: 'runServerEntry',\n args: [options],\n });\n\n return runServerEntryResult;\n } catch (err) {\n return {\n renderedContent: '',\n errors: [\n {\n source: 'Server Entry Execution',\n // note: err won't be an instance of Error because of serialization\n text: (err as Error)?.stack || (err as Error)?.message || String(err),\n },\n ],\n };\n }\n}\n\nexport async function disposeStubWorkerPool(): Promise<void> {\n await workerPool?.dispose();\n workerPool = undefined;\n}\n"]}
1
+ {"version":3,"file":"runServerEntryInWorker.js","sourceRoot":"","sources":["../../../src/renderRoute/ssr/runServerEntryInWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,2BAA2B,CAAC,CAAC;AAE/E,IAAI,UAAkC,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAwD;IAExD,UAAU,KAAK,IAAI,UAAU,CAAC;QAC5B,UAAU,EAAE,SAAS;QACrB,IAAI,EAAE,uBAAuB;QAC7B,SAAS,EAAE,UAAU;QACrB,iFAAiF;QACjF,mEAAmE;QACnE,UAAU,EAAE,CAAC;QACb,6FAA6F;QAC7F,kEAAkE;QAClE,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;KAC/B,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,oBAAoB,GAAG,MAAM,UAAU,CAAC,OAAO,CAAuB;YAC1E,MAAM,EAAE,gBAAgB;YACxB,IAAI,EAAE,CAAC,OAAO,CAAC;SAChB,CAAC,CAAC;QAEH,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,eAAe,EAAE,EAAE;YACnB,MAAM,EAAE;gBACN;oBACE,MAAM,EAAE,wBAAwB;oBAChC,mEAAmE;oBACnE,IAAI,EAAG,GAAa,EAAE,KAAK,IAAK,GAAa,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC;iBACtE;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,UAAU,EAAE,OAAO,EAAE,CAAC;IAC5B,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["import { WorkerPool } from '@ms-cloudpack/worker-pool';\nimport type { RunServerEntryOptions } from './types/RunServerEntryOptions.js';\nimport type { RunServerEntryResult } from './types/RunServerEntryResult.js';\nimport path from 'path';\n\nconst workerPath = path.join(import.meta.dirname, 'worker/ssrProcessEntry.js');\n\nlet workerPool: WorkerPool | undefined;\n\n/**\n * Run server entry in a child process pool. (Despite the naming, this does not use worker threads.)\n */\nexport async function runServerEntryInWorker(\n options: RunServerEntryOptions & { maxWorkers?: number },\n): Promise<RunServerEntryResult> {\n workerPool ??= new WorkerPool({\n workerType: 'process',\n name: 'serverEntry execution',\n entryPath: workerPath,\n // Currently we're unlikely to be server-rendering more than one thing at a time.\n // Keep this low unless we find a case where it needs to be higher.\n maxWorkers: 3,\n // Stop inactive processes after 5 minutes. This is intended to prevent one possible cause of\n // OOM crashes if cloudpack start is left running for a long time.\n inactiveTimeout: 5 * 60 * 1000,\n });\n\n try {\n const runServerEntryResult = await workerPool.execute<RunServerEntryResult>({\n method: 'runServerEntry',\n args: [options],\n });\n\n return runServerEntryResult;\n } catch (err) {\n return {\n renderedContent: '',\n errors: [\n {\n source: 'Server Entry Execution',\n // note: err won't be an instance of Error because of serialization\n text: (err as Error)?.stack || (err as Error)?.message || String(err),\n },\n ],\n };\n }\n}\n\nexport async function disposeStubWorkerPool(): Promise<void> {\n await workerPool?.dispose();\n workerPool = undefined;\n}\n"]}
@@ -1,9 +1,14 @@
1
1
  import type { ServerRenderFunctionOptions } from '@ms-cloudpack/common-types';
2
2
  import type { ImportMap } from '@ms-cloudpack/import-map';
3
3
  export type RunServerEntryOptions = {
4
- loaderPath: string;
4
+ /**
5
+ * TODO: This should be the import map specific to the render script in Node
6
+ * (as of writing, it reuses the browser one)
7
+ */
5
8
  importMap: ImportMap;
9
+ /** Absolute file URL for the render script (bundled if relevant) */
6
10
  renderScriptUrl: string;
7
- renderParams?: ServerRenderFunctionOptions;
11
+ /** Params to pass to the user's render function */
12
+ renderParams: ServerRenderFunctionOptions;
8
13
  };
9
14
  //# sourceMappingURL=RunServerEntryOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RunServerEntryOptions.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/types/RunServerEntryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,2BAA2B,CAAC;CAC5C,CAAC"}
1
+ {"version":3,"file":"RunServerEntryOptions.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/types/RunServerEntryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC;IACrB,oEAAoE;IACpE,eAAe,EAAE,MAAM,CAAC;IACxB,mDAAmD;IACnD,YAAY,EAAE,2BAA2B,CAAC;CAC3C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"RunServerEntryOptions.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/types/RunServerEntryOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServerRenderFunctionOptions } from '@ms-cloudpack/common-types';\nimport type { ImportMap } from '@ms-cloudpack/import-map';\n\nexport type RunServerEntryOptions = {\n loaderPath: string;\n importMap: ImportMap;\n renderScriptUrl: string;\n renderParams?: ServerRenderFunctionOptions;\n};\n"]}
1
+ {"version":3,"file":"RunServerEntryOptions.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/types/RunServerEntryOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServerRenderFunctionOptions } from '@ms-cloudpack/common-types';\nimport type { ImportMap } from '@ms-cloudpack/import-map';\n\nexport type RunServerEntryOptions = {\n /**\n * TODO: This should be the import map specific to the render script in Node\n * (as of writing, it reuses the browser one)\n */\n importMap: ImportMap;\n /** Absolute file URL for the render script (bundled if relevant) */\n renderScriptUrl: string;\n /** Params to pass to the user's render function */\n renderParams: ServerRenderFunctionOptions;\n};\n"]}
@@ -1,13 +1,36 @@
1
+ /**
2
+ * @param {RunServerEntryOptions} context
3
+ * @returns {void}
4
+ */
5
+ export function initialize(context: RunServerEntryOptions): void;
6
+ /**
7
+ *
8
+ * @param {string} specifier
9
+ * @param {ResolveHookContext} context
10
+ * @param {DefaultResolve} defaultResolve
11
+ * @returns {ResolveFnOutput}
12
+ */
13
+ export function resolve(specifier: string, context: ResolveHookContext, defaultResolve: DefaultResolve): ResolveFnOutput;
14
+ /**
15
+ * @param {string} url
16
+ * @param {LoadHookContext} context
17
+ * @param {DefaultLoad} defaultLoad
18
+ * @returns {Promise<LoadFnOutput>}
19
+ */
20
+ export function load(url: string, context: LoadHookContext, defaultLoad: DefaultLoad): Promise<LoadFnOutput>;
21
+ /**
22
+ * NOTE: This file is a custom loader for "bare" imports in nodejs
23
+ * It should ONLY import types and not any runtime code.
24
+ */
25
+ export type DefaultResolve = (specifier: string, context: ResolveHookContext) => ResolveFnOutput;
1
26
  /**
2
27
  * NOTE: This file is a custom loader for "bare" imports in nodejs
3
28
  * It should ONLY import types and not any runtime code.
4
29
  */
5
- import type { LoadFnOutput, LoadHookContext, ResolveFnOutput, ResolveHookContext } from 'module';
30
+ export type DefaultLoad = (url: string, context: LoadHookContext) => Promise<LoadFnOutput>;
6
31
  import type { RunServerEntryOptions } from '../types/RunServerEntryOptions.js';
7
- export declare function initialize(context: RunServerEntryOptions): void;
8
- type DefaultResolve = (specifier: string, context: ResolveHookContext) => ResolveFnOutput;
9
- export declare function resolve(specifier: string, context: ResolveHookContext, defaultResolve: DefaultResolve): ResolveFnOutput;
10
- type DefaultLoad = (url: string, context: LoadHookContext) => Promise<LoadFnOutput>;
11
- export declare function load(url: string, context: LoadHookContext, defaultLoad: DefaultLoad): Promise<LoadFnOutput>;
12
- export {};
32
+ import type { ResolveHookContext } from 'module';
33
+ import type { ResolveFnOutput } from 'module';
34
+ import type { LoadHookContext } from 'module';
35
+ import type { LoadFnOutput } from 'module';
13
36
  //# sourceMappingURL=importMapLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"importMapLoader.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/importMapLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AACjG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG/E,wBAAgB,UAAU,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAE/D;AAED,KAAK,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,KAAK,eAAe,CAAC;AAE1F,wBAAgB,OAAO,CACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,EAC3B,cAAc,EAAE,cAAc,GAC7B,eAAe,CAYjB;AAED,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAEpF,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAmBjH"}
1
+ {"version":3,"file":"importMapLoader.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/importMapLoader.js"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,oCAHW,qBAAqB,GACnB,IAAI,CAIhB;AAED;;;;;;GAMG;AACH,mCALW,MAAM,WACN,kBAAkB,kBAClB,cAAc,GACZ,eAAe,CAc3B;AAED;;;;;GAKG;AACH,0BALW,MAAM,WACN,eAAe,eACf,WAAW,GACT,OAAO,CAAC,YAAY,CAAC,CAsBjC;;;;;6BA/DY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,KAAK,eAAe;;;;;0BAEnE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,YAAY,CAAC;2CAJnC,mCAAmC;wCADU,QAAQ;qCAAR,QAAQ;qCAAR,QAAQ;kCAAR,QAAQ"}
@@ -1,16 +1,36 @@
1
1
  /**
2
2
  * NOTE: This file is a custom loader for "bare" imports in nodejs
3
3
  * It should ONLY import types and not any runtime code.
4
+ *
5
+ * @import { ImportMap } from '@ms-cloudpack/common-types';
6
+ * @import { LoadFnOutput, LoadHookContext, ResolveFnOutput, ResolveHookContext } from 'module';
7
+ * @import { RunServerEntryOptions } from '../types/RunServerEntryOptions.js';
8
+ *
9
+ * @typedef {(specifier: string, context: ResolveHookContext) => ResolveFnOutput} DefaultResolve
10
+ *
11
+ * @typedef {(url: string, context: LoadHookContext) => Promise<LoadFnOutput>} DefaultLoad
4
12
  */
13
+ /** @type {ImportMap} */
5
14
  let importMap = { imports: {} };
15
+ /**
16
+ * @param {RunServerEntryOptions} context
17
+ * @returns {void}
18
+ */
6
19
  export function initialize(context) {
7
20
  importMap = context.importMap || { imports: {} };
8
21
  }
22
+ /**
23
+ *
24
+ * @param {string} specifier
25
+ * @param {ResolveHookContext} context
26
+ * @param {DefaultResolve} defaultResolve
27
+ * @returns {ResolveFnOutput}
28
+ */
9
29
  export function resolve(specifier, context, defaultResolve) {
10
30
  // TODO: Deal with scope
11
31
  const target = importMap?.imports?.[specifier];
12
32
  if (target) {
13
- console.log(`Import map redirect: ${specifier} -> ${target}`);
33
+ console.info(`Import map redirect: ${specifier} -> ${target}`);
14
34
  return {
15
35
  url: target,
16
36
  shortCircuit: true,
@@ -18,11 +38,18 @@ export function resolve(specifier, context, defaultResolve) {
18
38
  }
19
39
  return defaultResolve(specifier, context);
20
40
  }
41
+ /**
42
+ * @param {string} url
43
+ * @param {LoadHookContext} context
44
+ * @param {DefaultLoad} defaultLoad
45
+ * @returns {Promise<LoadFnOutput>}
46
+ */
21
47
  export async function load(url, context, defaultLoad) {
22
48
  if (url.startsWith('http')) {
23
- console.log(`Importing from URL: ${url}`);
49
+ console.info(`Importing from URL: ${url}`);
24
50
  const res = await fetch(url);
25
51
  if (!res.ok) {
52
+ // TODO include the response text?
26
53
  throw new Error(`Failed to fetch ${url} (Status: ${res.status})`);
27
54
  }
28
55
  const source = await res.text();
@@ -1 +1 @@
1
- {"version":3,"file":"importMapLoader.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/importMapLoader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,IAAI,SAAS,GAAc,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAC3C,MAAM,UAAU,UAAU,CAAC,OAA8B;IACvD,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACnD,CAAC;AAID,MAAM,UAAU,OAAO,CACrB,SAAiB,EACjB,OAA2B,EAC3B,cAA8B;IAE9B,wBAAwB;IACxB,MAAM,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,wBAAwB,SAAS,OAAO,MAAM,EAAE,CAAC,CAAC;QAC9D,OAAO;YACL,GAAG,EAAE,MAAM;YACX,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAID,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,GAAW,EAAE,OAAwB,EAAE,WAAwB;IACxF,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAE1C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,aAAa,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAEhC,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,MAAM;YACN,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED,OAAO,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/**\n * NOTE: This file is a custom loader for \"bare\" imports in nodejs\n * It should ONLY import types and not any runtime code.\n */\n\nimport type { ImportMap } from '@ms-cloudpack/common-types';\nimport type { LoadFnOutput, LoadHookContext, ResolveFnOutput, ResolveHookContext } from 'module';\nimport type { RunServerEntryOptions } from '../types/RunServerEntryOptions.js';\n\nlet importMap: ImportMap = { imports: {} };\nexport function initialize(context: RunServerEntryOptions): void {\n importMap = context.importMap || { imports: {} };\n}\n\ntype DefaultResolve = (specifier: string, context: ResolveHookContext) => ResolveFnOutput;\n\nexport function resolve(\n specifier: string,\n context: ResolveHookContext,\n defaultResolve: DefaultResolve,\n): ResolveFnOutput {\n // TODO: Deal with scope\n const target = importMap?.imports?.[specifier];\n if (target) {\n console.log(`Import map redirect: ${specifier} -> ${target}`);\n return {\n url: target,\n shortCircuit: true,\n };\n }\n\n return defaultResolve(specifier, context);\n}\n\ntype DefaultLoad = (url: string, context: LoadHookContext) => Promise<LoadFnOutput>;\n\nexport async function load(url: string, context: LoadHookContext, defaultLoad: DefaultLoad): Promise<LoadFnOutput> {\n if (url.startsWith('http')) {\n console.log(`Importing from URL: ${url}`);\n\n const res = await fetch(url);\n if (!res.ok) {\n throw new Error(`Failed to fetch ${url} (Status: ${res.status})`);\n }\n\n const source = await res.text();\n\n return {\n format: 'module',\n source,\n shortCircuit: true,\n };\n }\n\n return defaultLoad(url, context);\n}\n"]}
1
+ {"version":3,"file":"importMapLoader.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/importMapLoader.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,wBAAwB;AACxB,IAAI,SAAS,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEhC;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,OAAO;IAChC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACnD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,cAAc;IACxD,wBAAwB;IACxB,MAAM,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,wBAAwB,SAAS,OAAO,MAAM,EAAE,CAAC,CAAC;QAC/D,OAAO;YACL,GAAG,EAAE,MAAM;YACX,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW;IAClD,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAE3C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,kCAAkC;YAClC,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,aAAa,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAEhC,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,MAAM;YACN,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED,OAAO,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/**\n * NOTE: This file is a custom loader for \"bare\" imports in nodejs\n * It should ONLY import types and not any runtime code.\n *\n * @import { ImportMap } from '@ms-cloudpack/common-types';\n * @import { LoadFnOutput, LoadHookContext, ResolveFnOutput, ResolveHookContext } from 'module';\n * @import { RunServerEntryOptions } from '../types/RunServerEntryOptions.js';\n *\n * @typedef {(specifier: string, context: ResolveHookContext) => ResolveFnOutput} DefaultResolve\n *\n * @typedef {(url: string, context: LoadHookContext) => Promise<LoadFnOutput>} DefaultLoad\n */\n\n/** @type {ImportMap} */\nlet importMap = { imports: {} };\n\n/**\n * @param {RunServerEntryOptions} context\n * @returns {void}\n */\nexport function initialize(context) {\n importMap = context.importMap || { imports: {} };\n}\n\n/**\n *\n * @param {string} specifier\n * @param {ResolveHookContext} context\n * @param {DefaultResolve} defaultResolve\n * @returns {ResolveFnOutput}\n */\nexport function resolve(specifier, context, defaultResolve) {\n // TODO: Deal with scope\n const target = importMap?.imports?.[specifier];\n if (target) {\n console.info(`Import map redirect: ${specifier} -> ${target}`);\n return {\n url: target,\n shortCircuit: true,\n };\n }\n\n return defaultResolve(specifier, context);\n}\n\n/**\n * @param {string} url\n * @param {LoadHookContext} context\n * @param {DefaultLoad} defaultLoad\n * @returns {Promise<LoadFnOutput>}\n */\nexport async function load(url, context, defaultLoad) {\n if (url.startsWith('http')) {\n console.info(`Importing from URL: ${url}`);\n\n const res = await fetch(url);\n if (!res.ok) {\n // TODO include the response text?\n throw new Error(`Failed to fetch ${url} (Status: ${res.status})`);\n }\n\n const source = await res.text();\n\n return {\n format: 'module',\n source,\n shortCircuit: true,\n };\n }\n\n return defaultLoad(url, context);\n}\n"]}
@@ -1,4 +1,13 @@
1
+ /**
2
+ * @param {RunServerEntryOptions} options
3
+ * @returns {Promise<RunServerEntryResult>}
4
+ */
5
+ export function runServerEntry(options: RunServerEntryOptions): Promise<RunServerEntryResult>;
6
+ export type RenderModule = {
7
+ render?: (params?: ServerRenderFunctionOptions) => Promise<string>;
8
+ default?: (params?: ServerRenderFunctionOptions) => Promise<string>;
9
+ };
1
10
  import type { RunServerEntryOptions } from '../types/RunServerEntryOptions.js';
2
11
  import type { RunServerEntryResult } from '../types/RunServerEntryResult.js';
3
- export declare function runServerEntry(options: RunServerEntryOptions): Promise<RunServerEntryResult>;
12
+ import type { ServerRenderFunctionOptions } from '@ms-cloudpack/common-types';
4
13
  //# sourceMappingURL=runServerEntry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runServerEntry.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/runServerEntry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAO7E,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA4BlG"}
1
+ {"version":3,"file":"runServerEntry.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/runServerEntry.js"],"names":[],"mappings":"AAYA;;;GAGG;AACH,wCAHW,qBAAqB,GACnB,OAAO,CAAC,oBAAoB,CAAC,CA2BzC;2BApCY;IACR,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,2BAA2B,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACnE,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,2BAA2B,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACrE;2CANsC,mCAAmC;0CACpC,kCAAkC;iDAF3B,4BAA4B"}
@@ -1,15 +1,28 @@
1
+ /**
2
+ * @import { ServerRenderFunctionOptions } from '@ms-cloudpack/common-types';
3
+ * @import { RunServerEntryOptions } from '../types/RunServerEntryOptions.js';
4
+ * @import { RunServerEntryResult } from '../types/RunServerEntryResult.js';
5
+ *
6
+ * @typedef {{
7
+ * render?: (params?: ServerRenderFunctionOptions) => Promise<string>;
8
+ * default?: (params?: ServerRenderFunctionOptions) => Promise<string>;
9
+ * }} RenderModule
10
+ */
1
11
  import { register } from 'node:module';
2
- import { pathToFileURL } from 'node:url';
12
+ /**
13
+ * @param {RunServerEntryOptions} options
14
+ * @returns {Promise<RunServerEntryResult>}
15
+ */
3
16
  export async function runServerEntry(options) {
4
- const { importMap, renderScriptUrl, loaderPath, renderParams } = options;
17
+ const { importMap, renderScriptUrl, renderParams } = options;
5
18
  // Registers the customer loader, which is responsible for handling base-imports in a nodejs environment..
6
- register(loaderPath, {
7
- parentURL: pathToFileURL(import.meta.url),
19
+ register('./importMapLoader.js', {
20
+ parentURL: import.meta.url,
8
21
  data: { importMap },
9
22
  });
10
23
  // With the custom loader registered, we can now import the render script.
11
24
  // We support both named and default exports for the render function.
12
- const renderedResult = await import(renderScriptUrl)
25
+ const renderedResult = await /** @type {Promise<RenderModule>} */ (import(renderScriptUrl))
13
26
  .then((mod) => {
14
27
  if (typeof mod.render === 'function') {
15
28
  return mod.render(renderParams);
@@ -18,9 +31,6 @@ export async function runServerEntry(options) {
18
31
  return mod.default(renderParams);
19
32
  }
20
33
  throw new Error(`No render function found in module: ${renderScriptUrl}`);
21
- })
22
- .then((output) => {
23
- return output;
24
34
  })
25
35
  .catch((err) => {
26
36
  console.log('Error:', err);
@@ -1 +1 @@
1
- {"version":3,"file":"runServerEntry.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/runServerEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AASzC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA8B;IACjE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEzE,0GAA0G;IAC1G,QAAQ,CAAC,UAAU,EAAE;QACnB,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QACzC,IAAI,EAAE,EAAE,SAAS,EAAE;KACpB,CAAC,CAAC;IAEH,0EAA0E;IAC1E,qEAAqE;IACrE,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;SACjD,IAAI,CAAC,CAAC,GAAiB,EAAE,EAAE;QAC1B,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACrC,OAAO,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;aAAM,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,uCAAuC,eAAe,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEL,OAAO,EAAE,eAAe,EAAE,cAAc,IAAI,EAAE,EAAE,CAAC;AACnD,CAAC","sourcesContent":["import type { ServerRenderFunctionOptions } from '@ms-cloudpack/common-types';\nimport { register } from 'node:module';\nimport { pathToFileURL } from 'node:url';\nimport type { RunServerEntryOptions } from '../types/RunServerEntryOptions.js';\nimport type { RunServerEntryResult } from '../types/RunServerEntryResult.js';\n\ntype RenderModule = {\n render?: (params?: ServerRenderFunctionOptions) => Promise<string>;\n default?: (params?: ServerRenderFunctionOptions) => Promise<string>;\n};\n\nexport async function runServerEntry(options: RunServerEntryOptions): Promise<RunServerEntryResult> {\n const { importMap, renderScriptUrl, loaderPath, renderParams } = options;\n\n // Registers the customer loader, which is responsible for handling base-imports in a nodejs environment..\n register(loaderPath, {\n parentURL: pathToFileURL(import.meta.url),\n data: { importMap },\n });\n\n // With the custom loader registered, we can now import the render script.\n // We support both named and default exports for the render function.\n const renderedResult = await import(renderScriptUrl)\n .then((mod: RenderModule) => {\n if (typeof mod.render === 'function') {\n return mod.render(renderParams);\n } else if (typeof mod.default === 'function') {\n return mod.default(renderParams);\n }\n throw new Error(`No render function found in module: ${renderScriptUrl}`);\n })\n .then((output) => {\n return output;\n })\n .catch((err) => {\n console.log('Error:', err);\n });\n\n return { renderedContent: renderedResult || '' };\n}\n"]}
1
+ {"version":3,"file":"runServerEntry.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/runServerEntry.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAO;IAC1C,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAE7D,0GAA0G;IAC1G,QAAQ,CAAC,sBAAsB,EAAE;QAC/B,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;QAC1B,IAAI,EAAE,EAAE,SAAS,EAAE;KACpB,CAAC,CAAC;IAEH,0EAA0E;IAC1E,qEAAqE;IACrE,MAAM,cAAc,GAAG,MAAM,oCAAoC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;SACxF,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QACZ,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACrC,OAAO,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;aAAM,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,uCAAuC,eAAe,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEL,OAAO,EAAE,eAAe,EAAE,cAAc,IAAI,EAAE,EAAE,CAAC;AACnD,CAAC","sourcesContent":["/**\n * @import { ServerRenderFunctionOptions } from '@ms-cloudpack/common-types';\n * @import { RunServerEntryOptions } from '../types/RunServerEntryOptions.js';\n * @import { RunServerEntryResult } from '../types/RunServerEntryResult.js';\n *\n * @typedef {{\n * render?: (params?: ServerRenderFunctionOptions) => Promise<string>;\n * default?: (params?: ServerRenderFunctionOptions) => Promise<string>;\n * }} RenderModule\n */\nimport { register } from 'node:module';\n\n/**\n * @param {RunServerEntryOptions} options\n * @returns {Promise<RunServerEntryResult>}\n */\nexport async function runServerEntry(options) {\n const { importMap, renderScriptUrl, renderParams } = options;\n\n // Registers the customer loader, which is responsible for handling base-imports in a nodejs environment..\n register('./importMapLoader.js', {\n parentURL: import.meta.url,\n data: { importMap },\n });\n\n // With the custom loader registered, we can now import the render script.\n // We support both named and default exports for the render function.\n const renderedResult = await /** @type {Promise<RenderModule>} */ (import(renderScriptUrl))\n .then((mod) => {\n if (typeof mod.render === 'function') {\n return mod.render(renderParams);\n } else if (typeof mod.default === 'function') {\n return mod.default(renderParams);\n }\n throw new Error(`No render function found in module: ${renderScriptUrl}`);\n })\n .catch((err) => {\n console.log('Error:', err);\n });\n\n return { renderedContent: renderedResult || '' };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ssrWorkerEntry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssrWorkerEntry.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/ssrWorkerEntry.js"],"names":[],"mappings":""}
@@ -2,14 +2,14 @@ import { initializeWorker } from '@ms-cloudpack/worker-pool';
2
2
  import { runServerEntry } from './runServerEntry.js';
3
3
  // eslint-disable-next-line no-restricted-properties -- exit handling for a worker
4
4
  const processExit = process.exit.bind(process);
5
- // Then initialize the worker with the appropriate listeners and api dictionary.
5
+ // Initialize message handlers and APIs for the subprocess.
6
6
  initializeWorker({
7
7
  methods: {
8
8
  runServerEntry,
9
9
  },
10
10
  beforeEach: () => {
11
11
  // Override process.exit calls to throw rather than exit the process, in case we load some
12
- // CJS code that calls process.exit. This gives an actual call stack for debugging.
12
+ // code that calls process.exit. This gives an actual call stack for debugging.
13
13
  // eslint-disable-next-line no-restricted-properties
14
14
  process.exit = (code) => {
15
15
  throw new Error(`process.exit called with code ${code}`);
@@ -23,4 +23,4 @@ initializeWorker({
23
23
  // good to be conservative here in case of resource contention.
24
24
  timeout: 30 * 1000,
25
25
  });
26
- //# sourceMappingURL=workerEntry.js.map
26
+ //# sourceMappingURL=ssrWorkerEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssrWorkerEntry.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/ssrWorkerEntry.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,kFAAkF;AAClF,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAE/C,2DAA2D;AAC3D,gBAAgB,CAAC;IACf,OAAO,EAAE;QACP,cAAc;KACf;IACD,UAAU,EAAE,GAAG,EAAE;QACf,0FAA0F;QAC1F,+EAA+E;QAC/E,oDAAoD;QACpD,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC;IACD,SAAS,EAAE,GAAG,EAAE;QACd,oDAAoD;QACpD,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;IAC7B,CAAC;IACD,4FAA4F;IAC5F,+DAA+D;IAC/D,OAAO,EAAE,EAAE,GAAG,IAAI;CACnB,CAAC,CAAC","sourcesContent":["import { initializeWorker } from '@ms-cloudpack/worker-pool';\nimport { runServerEntry } from './runServerEntry.js';\n\n// eslint-disable-next-line no-restricted-properties -- exit handling for a worker\nconst processExit = process.exit.bind(process);\n\n// Initialize message handlers and APIs for the subprocess.\ninitializeWorker({\n methods: {\n runServerEntry,\n },\n beforeEach: () => {\n // Override process.exit calls to throw rather than exit the process, in case we load some\n // code that calls process.exit. This gives an actual call stack for debugging.\n // eslint-disable-next-line no-restricted-properties\n process.exit = (code) => {\n throw new Error(`process.exit called with code ${code}`);\n };\n },\n afterEach: () => {\n // eslint-disable-next-line no-restricted-properties\n process.exit = processExit;\n },\n // Stop the worker after 30s. This is much longer than should usually be necessary, but it's\n // good to be conservative here in case of resource contention.\n timeout: 30 * 1000,\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/app-server",
3
- "version": "0.20.1",
3
+ "version": "0.20.3",
4
4
  "description": "An implementation of the App server for Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,13 +14,13 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/api-server": "^0.64.9",
18
- "@ms-cloudpack/bundle-server": "^0.8.1",
17
+ "@ms-cloudpack/api-server": "^0.64.11",
18
+ "@ms-cloudpack/bundle-server": "^0.8.3",
19
19
  "@ms-cloudpack/common-types": "^0.26.4",
20
20
  "@ms-cloudpack/create-express-app": "^1.10.43",
21
21
  "@ms-cloudpack/environment": "^0.1.1",
22
22
  "@ms-cloudpack/import-map": "^0.10.37",
23
- "@ms-cloudpack/inline-scripts": "^0.2.23",
23
+ "@ms-cloudpack/inline-scripts": "^0.2.25",
24
24
  "@ms-cloudpack/path-string-parsing": "^1.2.7",
25
25
  "@ms-cloudpack/path-utilities": "^3.1.14",
26
26
  "@ms-cloudpack/task-reporter": "^0.17.2",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=workerEntry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workerEntry.d.ts","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/workerEntry.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"workerEntry.js","sourceRoot":"","sources":["../../../../src/renderRoute/ssr/worker/workerEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,kFAAkF;AAClF,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAE/C,gFAAgF;AAChF,gBAAgB,CAAC;IACf,OAAO,EAAE;QACP,cAAc;KACf;IACD,UAAU,EAAE,GAAG,EAAE;QACf,0FAA0F;QAC1F,mFAAmF;QACnF,oDAAoD;QACpD,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC;IACD,SAAS,EAAE,GAAG,EAAE;QACd,oDAAoD;QACpD,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;IAC7B,CAAC;IACD,4FAA4F;IAC5F,+DAA+D;IAC/D,OAAO,EAAE,EAAE,GAAG,IAAI;CACnB,CAAC,CAAC","sourcesContent":["import { initializeWorker } from '@ms-cloudpack/worker-pool';\nimport { runServerEntry } from './runServerEntry.js';\n\n// eslint-disable-next-line no-restricted-properties -- exit handling for a worker\nconst processExit = process.exit.bind(process);\n\n// Then initialize the worker with the appropriate listeners and api dictionary.\ninitializeWorker({\n methods: {\n runServerEntry,\n },\n beforeEach: () => {\n // Override process.exit calls to throw rather than exit the process, in case we load some\n // CJS code that calls process.exit. This gives an actual call stack for debugging.\n // eslint-disable-next-line no-restricted-properties\n process.exit = (code) => {\n throw new Error(`process.exit called with code ${code}`);\n };\n },\n afterEach: () => {\n // eslint-disable-next-line no-restricted-properties\n process.exit = processExit;\n },\n // Stop the worker after 30s. This is much longer than should usually be necessary, but it's\n // good to be conservative here in case of resource contention.\n timeout: 30 * 1000,\n});\n"]}