@format.dev/compile 0.0.0 → 0.1.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/README.md +30 -20
- package/bin/format-compile +3 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
- package/dist/_virtual/rolldown_runtime.mjs +46 -0
- package/dist/node_modules/.pnpm/@babel_parser@7.29.8/node_modules/@babel/parser/lib/index.mjs +12606 -0
- package/dist/node_modules/.pnpm/@babel_parser@7.29.8/node_modules/@babel/parser/lib/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_compiler-core@3.5.41/node_modules/@vue/compiler-core/dist/compiler-core.cjs.mjs +4866 -0
- package/dist/node_modules/.pnpm/@vue_compiler-core@3.5.41/node_modules/@vue/compiler-core/dist/compiler-core.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_compiler-core@3.5.41/node_modules/@vue/compiler-core/index.mjs +13 -0
- package/dist/node_modules/.pnpm/@vue_compiler-core@3.5.41/node_modules/@vue/compiler-core/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_compiler-dom@3.5.41/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.mjs +663 -0
- package/dist/node_modules/.pnpm/@vue_compiler-dom@3.5.41/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_compiler-dom@3.5.41/node_modules/@vue/compiler-dom/index.mjs +13 -0
- package/dist/node_modules/.pnpm/@vue_compiler-dom@3.5.41/node_modules/@vue/compiler-dom/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_compiler-ssr@3.5.41/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.mjs +846 -0
- package/dist/node_modules/.pnpm/@vue_compiler-ssr@3.5.41/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_reactivity@3.5.41/node_modules/@vue/reactivity/dist/reactivity.cjs.mjs +1600 -0
- package/dist/node_modules/.pnpm/@vue_reactivity@3.5.41/node_modules/@vue/reactivity/dist/reactivity.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_reactivity@3.5.41/node_modules/@vue/reactivity/index.mjs +13 -0
- package/dist/node_modules/.pnpm/@vue_reactivity@3.5.41/node_modules/@vue/reactivity/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_runtime-core@3.5.41/node_modules/@vue/runtime-core/dist/runtime-core.cjs.mjs +5619 -0
- package/dist/node_modules/.pnpm/@vue_runtime-core@3.5.41/node_modules/@vue/runtime-core/dist/runtime-core.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_runtime-core@3.5.41/node_modules/@vue/runtime-core/index.mjs +13 -0
- package/dist/node_modules/.pnpm/@vue_runtime-core@3.5.41/node_modules/@vue/runtime-core/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_runtime-dom@3.5.41/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.mjs +1479 -0
- package/dist/node_modules/.pnpm/@vue_runtime-dom@3.5.41/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_runtime-dom@3.5.41/node_modules/@vue/runtime-dom/index.mjs +13 -0
- package/dist/node_modules/.pnpm/@vue_runtime-dom@3.5.41/node_modules/@vue/runtime-dom/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_server-renderer@3.5.41/node_modules/@vue/server-renderer/dist/server-renderer.cjs.mjs +510 -0
- package/dist/node_modules/.pnpm/@vue_server-renderer@3.5.41/node_modules/@vue/server-renderer/dist/server-renderer.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_server-renderer@3.5.41/node_modules/@vue/server-renderer/index.mjs +13 -0
- package/dist/node_modules/.pnpm/@vue_server-renderer@3.5.41/node_modules/@vue/server-renderer/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_shared@3.5.41/node_modules/@vue/shared/dist/shared.cjs.mjs +499 -0
- package/dist/node_modules/.pnpm/@vue_shared@3.5.41/node_modules/@vue/shared/dist/shared.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/@vue_shared@3.5.41/node_modules/@vue/shared/index.mjs +13 -0
- package/dist/node_modules/.pnpm/@vue_shared@3.5.41/node_modules/@vue/shared/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/decode-codepoint.mjs +79 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/decode-codepoint.mjs.map +1 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/decode.mjs +471 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/decode.mjs.map +1 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/generated/decode-data-html.mjs +16 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/generated/decode-data-html.mjs.map +1 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/generated/decode-data-xml.mjs +16 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/generated/decode-data-xml.mjs.map +1 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/internal/bin-trie-flags.mjs +30 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/internal/bin-trie-flags.mjs.map +1 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/internal/decode-shared.mjs +24 -0
- package/dist/node_modules/.pnpm/entities@7.0.1/node_modules/entities/dist/commonjs/internal/decode-shared.mjs.map +1 -0
- package/dist/node_modules/.pnpm/estree-walker@2.0.2/node_modules/estree-walker/dist/umd/estree-walker.mjs +253 -0
- package/dist/node_modules/.pnpm/estree-walker@2.0.2/node_modules/estree-walker/dist/umd/estree-walker.mjs.map +1 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.mjs +5246 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.mjs.map +1 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom-server.node.development.mjs +5616 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom-server.node.development.mjs.map +1 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom.development.mjs +183 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/cjs/react-dom.development.mjs.map +1 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/index.mjs +13 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/server.node.mjs +21 -0
- package/dist/node_modules/.pnpm/react-dom@19.2.8_react@19.2.8/node_modules/react-dom/server.node.mjs.map +1 -0
- package/dist/node_modules/.pnpm/react@19.2.8/node_modules/react/cjs/react.development.mjs +766 -0
- package/dist/node_modules/.pnpm/react@19.2.8/node_modules/react/cjs/react.development.mjs.map +1 -0
- package/dist/node_modules/.pnpm/react@19.2.8/node_modules/react/index.mjs +13 -0
- package/dist/node_modules/.pnpm/react@19.2.8/node_modules/react/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/array-set.mjs +100 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/array-set.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/base64-vlq.mjs +73 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/base64-vlq.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/base64.mjs +41 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/base64.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/binary-search.mjs +68 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/binary-search.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/mapping-list.mjs +77 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/mapping-list.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/quick-sort.mjs +89 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/quick-sort.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-map-consumer.mjs +788 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-map-consumer.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-map-generator.mjs +295 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-map-generator.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-node.mjs +293 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/source-node.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/util.mjs +352 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/lib/util.mjs.map +1 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/source-map.mjs +17 -0
- package/dist/node_modules/.pnpm/source-map-js@1.2.1/node_modules/source-map-js/source-map.mjs.map +1 -0
- package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/dist/vue.cjs.mjs +67 -0
- package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/dist/vue.cjs.mjs.map +1 -0
- package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/index.mjs +13 -0
- package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/index.mjs.map +1 -0
- package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/index2.mjs +10 -0
- package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/index2.mjs.map +1 -0
- package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/server-renderer/index.mjs +10 -0
- package/dist/node_modules/.pnpm/vue@3.5.41_typescript@5.9.3/node_modules/vue/server-renderer/index.mjs.map +1 -0
- package/dist/server/cli/bin.d.mts +1 -0
- package/dist/server/cli/bin.mjs +8 -0
- package/dist/server/cli/bin.mjs.map +1 -0
- package/dist/server/cli/cli-spec.mjs +150 -0
- package/dist/server/cli/cli-spec.mjs.map +1 -0
- package/dist/server/cli/index.d.mts +16 -0
- package/dist/server/cli/index.d.mts.map +1 -0
- package/dist/server/cli/index.mjs +64 -0
- package/dist/server/cli/index.mjs.map +1 -0
- package/dist/server/compile/adaptors/html-partials.d.mts +24 -0
- package/dist/server/compile/adaptors/html-partials.d.mts.map +1 -0
- package/dist/server/compile/adaptors/html-partials.mjs +50 -0
- package/dist/server/compile/adaptors/html-partials.mjs.map +1 -0
- package/dist/server/compile/adaptors/html.d.mts +15 -0
- package/dist/server/compile/adaptors/html.d.mts.map +1 -0
- package/dist/server/compile/adaptors/html.mjs +39 -0
- package/dist/server/compile/adaptors/html.mjs.map +1 -0
- package/dist/server/compile/adaptors/node-require.d.mts +6 -0
- package/dist/server/compile/adaptors/node-require.d.mts.map +1 -0
- package/dist/server/compile/adaptors/node-require.mjs +35 -0
- package/dist/server/compile/adaptors/node-require.mjs.map +1 -0
- package/dist/server/compile/adaptors/react-browser.d.mts +20 -0
- package/dist/server/compile/adaptors/react-browser.d.mts.map +1 -0
- package/dist/server/compile/adaptors/react-browser.mjs +19 -0
- package/dist/server/compile/adaptors/react-browser.mjs.map +1 -0
- package/dist/server/compile/adaptors/react-node.d.mts +17 -0
- package/dist/server/compile/adaptors/react-node.d.mts.map +1 -0
- package/dist/server/compile/adaptors/react-node.mjs +50 -0
- package/dist/server/compile/adaptors/react-node.mjs.map +1 -0
- package/dist/server/compile/adaptors/types.d.mts +14 -0
- package/dist/server/compile/adaptors/types.d.mts.map +1 -0
- package/dist/server/compile/adaptors/types.mjs +1 -0
- package/dist/server/compile/adaptors/vue-browser.d.mts +16 -0
- package/dist/server/compile/adaptors/vue-browser.d.mts.map +1 -0
- package/dist/server/compile/adaptors/vue-browser.mjs +16 -0
- package/dist/server/compile/adaptors/vue-browser.mjs.map +1 -0
- package/dist/server/compile/adaptors/vue-node.d.mts +17 -0
- package/dist/server/compile/adaptors/vue-node.d.mts.map +1 -0
- package/dist/server/compile/adaptors/vue-node.mjs +50 -0
- package/dist/server/compile/adaptors/vue-node.mjs.map +1 -0
- package/dist/server/compile/build-entry-module.d.mts +20 -0
- package/dist/server/compile/build-entry-module.d.mts.map +1 -0
- package/dist/server/compile/build-entry-module.mjs +56 -0
- package/dist/server/compile/build-entry-module.mjs.map +1 -0
- package/dist/server/compile/bundle-name.d.mts +5 -0
- package/dist/server/compile/bundle-name.d.mts.map +1 -0
- package/dist/server/compile/bundle-name.mjs +13 -0
- package/dist/server/compile/bundle-name.mjs.map +1 -0
- package/dist/server/compile/compile-cache.d.mts +23 -0
- package/dist/server/compile/compile-cache.d.mts.map +1 -0
- package/dist/server/compile/compile-cache.mjs +102 -0
- package/dist/server/compile/compile-cache.mjs.map +1 -0
- package/dist/server/compile/compile.d.mts +100 -0
- package/dist/server/compile/compile.d.mts.map +1 -0
- package/dist/server/compile/compile.mjs +735 -0
- package/dist/server/compile/compile.mjs.map +1 -0
- package/dist/server/compile/constants.d.mts +11 -0
- package/dist/server/compile/constants.d.mts.map +1 -0
- package/dist/server/compile/constants.mjs +12 -0
- package/dist/server/compile/constants.mjs.map +1 -0
- package/dist/server/compile/create-renderer.d.mts +16 -0
- package/dist/server/compile/create-renderer.d.mts.map +1 -0
- package/dist/server/compile/create-renderer.mjs +59 -0
- package/dist/server/compile/create-renderer.mjs.map +1 -0
- package/dist/server/compile/decode-style-entities.d.mts +12 -0
- package/dist/server/compile/decode-style-entities.d.mts.map +1 -0
- package/dist/server/compile/decode-style-entities.mjs +32 -0
- package/dist/server/compile/decode-style-entities.mjs.map +1 -0
- package/dist/server/compile/defaults.d.mts +18 -0
- package/dist/server/compile/defaults.d.mts.map +1 -0
- package/dist/server/compile/defaults.mjs +128 -0
- package/dist/server/compile/defaults.mjs.map +1 -0
- package/dist/server/compile/dependency-closure.d.mts +10 -0
- package/dist/server/compile/dependency-closure.d.mts.map +1 -0
- package/dist/server/compile/dependency-closure.mjs +79 -0
- package/dist/server/compile/dependency-closure.mjs.map +1 -0
- package/dist/server/compile/document-assets.d.mts +103 -0
- package/dist/server/compile/document-assets.d.mts.map +1 -0
- package/dist/server/compile/document-assets.mjs +184 -0
- package/dist/server/compile/document-assets.mjs.map +1 -0
- package/dist/server/compile/finalize-document-html.d.mts +53 -0
- package/dist/server/compile/finalize-document-html.d.mts.map +1 -0
- package/dist/server/compile/finalize-document-html.mjs +132 -0
- package/dist/server/compile/finalize-document-html.mjs.map +1 -0
- package/dist/server/compile/generated/adaptorHtml.mjs +6 -0
- package/dist/server/compile/generated/adaptorHtml.mjs.map +1 -0
- package/dist/server/compile/generated/adaptorReactBrowser.mjs +6 -0
- package/dist/server/compile/generated/adaptorReactBrowser.mjs.map +1 -0
- package/dist/server/compile/generated/adaptorReactNode.mjs +6 -0
- package/dist/server/compile/generated/adaptorReactNode.mjs.map +1 -0
- package/dist/server/compile/generated/adaptorVueBrowser.mjs +6 -0
- package/dist/server/compile/generated/adaptorVueBrowser.mjs.map +1 -0
- package/dist/server/compile/generated/adaptorVueNode.mjs +6 -0
- package/dist/server/compile/generated/adaptorVueNode.mjs.map +1 -0
- package/dist/server/compile/generated/createRenderer.mjs +6 -0
- package/dist/server/compile/generated/createRenderer.mjs.map +1 -0
- package/dist/server/compile/generated/decodeStyleEntities.mjs +6 -0
- package/dist/server/compile/generated/decodeStyleEntities.mjs.map +1 -0
- package/dist/server/compile/generated/sanitizeHtml.mjs +6 -0
- package/dist/server/compile/generated/sanitizeHtml.mjs.map +1 -0
- package/dist/server/compile/generated/validate.mjs +6 -0
- package/dist/server/compile/generated/validate.mjs.map +1 -0
- package/dist/server/compile/generated/virtualStyles.mjs +6 -0
- package/dist/server/compile/generated/virtualStyles.mjs.map +1 -0
- package/dist/server/compile/get-renderer.d.mts +18 -0
- package/dist/server/compile/get-renderer.d.mts.map +1 -0
- package/dist/server/compile/get-renderer.mjs +31 -0
- package/dist/server/compile/get-renderer.mjs.map +1 -0
- package/dist/server/compile/index.d.mts +2 -0
- package/dist/server/compile/index.mjs +3 -0
- package/dist/server/compile/make-config.d.mts +39 -0
- package/dist/server/compile/make-config.d.mts.map +1 -0
- package/dist/server/compile/make-config.mjs +272 -0
- package/dist/server/compile/make-config.mjs.map +1 -0
- package/dist/server/compile/package-json.d.mts +5 -0
- package/dist/server/compile/package-json.d.mts.map +1 -0
- package/dist/server/compile/package-json.mjs +33 -0
- package/dist/server/compile/package-json.mjs.map +1 -0
- package/dist/server/compile/producer-agreement.d.mts +82 -0
- package/dist/server/compile/producer-agreement.d.mts.map +1 -0
- package/dist/server/compile/producer-agreement.mjs +143 -0
- package/dist/server/compile/producer-agreement.mjs.map +1 -0
- package/dist/server/compile/producer-release.d.mts +19 -0
- package/dist/server/compile/producer-release.d.mts.map +1 -0
- package/dist/server/compile/producer-release.mjs +27 -0
- package/dist/server/compile/producer-release.mjs.map +1 -0
- package/dist/server/compile/render-error.d.mts +37 -0
- package/dist/server/compile/render-error.d.mts.map +1 -0
- package/dist/server/compile/render-error.mjs +55 -0
- package/dist/server/compile/render-error.mjs.map +1 -0
- package/dist/server/compile/sanitize/shared.d.mts +19 -0
- package/dist/server/compile/sanitize/shared.d.mts.map +1 -0
- package/dist/server/compile/sanitize/shared.mjs +131 -0
- package/dist/server/compile/sanitize/shared.mjs.map +1 -0
- package/dist/server/compile/sanitize-html.d.mts +5 -0
- package/dist/server/compile/sanitize-html.d.mts.map +1 -0
- package/dist/server/compile/sanitize-html.mjs +65 -0
- package/dist/server/compile/sanitize-html.mjs.map +1 -0
- package/dist/server/compile/structured-log.d.mts +22 -0
- package/dist/server/compile/structured-log.d.mts.map +1 -0
- package/dist/server/compile/structured-log.mjs +31 -0
- package/dist/server/compile/structured-log.mjs.map +1 -0
- package/dist/server/compile/virtual-styles.d.mts +5 -0
- package/dist/server/compile/virtual-styles.d.mts.map +1 -0
- package/dist/server/compile/virtual-styles.mjs +19 -0
- package/dist/server/compile/virtual-styles.mjs.map +1 -0
- package/dist/server/compile/wrapper-source.d.mts +55 -0
- package/dist/server/compile/wrapper-source.d.mts.map +1 -0
- package/dist/server/compile/wrapper-source.mjs +187 -0
- package/dist/server/compile/wrapper-source.mjs.map +1 -0
- package/dist/server/constants.d.mts +17 -0
- package/dist/server/constants.d.mts.map +1 -0
- package/dist/server/constants.mjs +41 -0
- package/dist/server/constants.mjs.map +1 -0
- package/dist/server/errors.d.mts +21 -0
- package/dist/server/errors.d.mts.map +1 -0
- package/dist/server/errors.mjs +24 -0
- package/dist/server/errors.mjs.map +1 -0
- package/dist/server/index.d.mts +4 -0
- package/dist/server/index.mjs +4 -0
- package/dist/server/integrations/nextjs/generate-entry.d.mts +19 -0
- package/dist/server/integrations/nextjs/generate-entry.d.mts.map +1 -0
- package/dist/server/integrations/nextjs/generate-entry.mjs +246 -0
- package/dist/server/integrations/nextjs/generate-entry.mjs.map +1 -0
- package/dist/server/integrations/nextjs/index.d.mts +8 -0
- package/dist/server/integrations/nextjs/index.d.mts.map +1 -0
- package/dist/server/integrations/nextjs/index.mjs +90 -0
- package/dist/server/integrations/nextjs/index.mjs.map +1 -0
- package/dist/server/integrations/nextjs/watcher.d.mts +9 -0
- package/dist/server/integrations/nextjs/watcher.d.mts.map +1 -0
- package/dist/server/integrations/nextjs/watcher.mjs +45 -0
- package/dist/server/integrations/nextjs/watcher.mjs.map +1 -0
- package/dist/server/integrations/unplugin/esbuild.d.mts +2 -0
- package/dist/server/integrations/unplugin/esbuild.mjs +3 -0
- package/dist/server/integrations/unplugin/index.d.mts +69 -0
- package/dist/server/integrations/unplugin/index.d.mts.map +1 -0
- package/dist/server/integrations/unplugin/index.mjs +539 -0
- package/dist/server/integrations/unplugin/index.mjs.map +1 -0
- package/dist/server/integrations/unplugin/rollup.d.mts +2 -0
- package/dist/server/integrations/unplugin/rollup.mjs +3 -0
- package/dist/server/integrations/unplugin/utils.d.mts +12 -0
- package/dist/server/integrations/unplugin/utils.d.mts.map +1 -0
- package/dist/server/integrations/unplugin/utils.mjs +46 -0
- package/dist/server/integrations/unplugin/utils.mjs.map +1 -0
- package/dist/server/integrations/unplugin/vite.d.mts +2 -0
- package/dist/server/integrations/unplugin/vite.mjs +3 -0
- package/dist/server/integrations/unplugin/webpack.d.mts +2 -0
- package/dist/server/integrations/unplugin/webpack.mjs +3 -0
- package/dist/server/project/documents.d.mts +21 -0
- package/dist/server/project/documents.d.mts.map +1 -0
- package/dist/server/project/documents.mjs +114 -0
- package/dist/server/project/documents.mjs.map +1 -0
- package/dist/server/project/format-env-types.d.mts +19 -0
- package/dist/server/project/format-env-types.d.mts.map +1 -0
- package/dist/server/project/format-env-types.mjs +64 -0
- package/dist/server/project/format-env-types.mjs.map +1 -0
- package/dist/server/project/paths.d.mts +21 -0
- package/dist/server/project/paths.d.mts.map +1 -0
- package/dist/server/project/paths.mjs +31 -0
- package/dist/server/project/paths.mjs.map +1 -0
- package/dist/server/project/user-project-dir.d.mts +7 -0
- package/dist/server/project/user-project-dir.d.mts.map +1 -0
- package/dist/server/project/user-project-dir.mjs +16 -0
- package/dist/server/project/user-project-dir.mjs.map +1 -0
- package/dist/server/render-worker/client.d.mts +83 -0
- package/dist/server/render-worker/client.d.mts.map +1 -0
- package/dist/server/render-worker/client.mjs +359 -0
- package/dist/server/render-worker/client.mjs.map +1 -0
- package/dist/server/render-worker/document-css.d.mts +27 -0
- package/dist/server/render-worker/document-css.d.mts.map +1 -0
- package/dist/server/render-worker/document-css.mjs +37 -0
- package/dist/server/render-worker/document-css.mjs.map +1 -0
- package/dist/server/render-worker/env.d.mts +11 -0
- package/dist/server/render-worker/env.d.mts.map +1 -0
- package/dist/server/render-worker/env.mjs +26 -0
- package/dist/server/render-worker/env.mjs.map +1 -0
- package/dist/server/render-worker/error.d.mts +17 -0
- package/dist/server/render-worker/error.d.mts.map +1 -0
- package/dist/server/render-worker/error.mjs +40 -0
- package/dist/server/render-worker/error.mjs.map +1 -0
- package/dist/server/render-worker/host.d.mts +1 -0
- package/dist/server/render-worker/host.mjs +181 -0
- package/dist/server/render-worker/host.mjs.map +1 -0
- package/dist/server/render-worker/index.d.mts +4 -0
- package/dist/server/render-worker/index.mjs +4 -0
- package/dist/server/render-worker/sandbox.d.mts +25 -0
- package/dist/server/render-worker/sandbox.d.mts.map +1 -0
- package/dist/server/render-worker/sandbox.mjs +60 -0
- package/dist/server/render-worker/sandbox.mjs.map +1 -0
- package/dist/server/render-worker/types.d.mts +59 -0
- package/dist/server/render-worker/types.d.mts.map +1 -0
- package/dist/server/render-worker/types.mjs +1 -0
- package/dist/server/runtime-state.d.mts +12 -0
- package/dist/server/runtime-state.d.mts.map +1 -0
- package/dist/server/runtime-state.mjs +24 -0
- package/dist/server/runtime-state.mjs.map +1 -0
- package/dist/server/utils/check-dir.d.mts +12 -0
- package/dist/server/utils/check-dir.d.mts.map +1 -0
- package/dist/server/utils/check-dir.mjs +30 -0
- package/dist/server/utils/check-dir.mjs.map +1 -0
- package/dist/server/utils/dependencies.d.mts +11 -0
- package/dist/server/utils/dependencies.d.mts.map +1 -0
- package/dist/server/utils/dependencies.mjs +34 -0
- package/dist/server/utils/dependencies.mjs.map +1 -0
- package/dist/server/utils/env-var.d.mts +6 -0
- package/dist/server/utils/env-var.d.mts.map +1 -0
- package/dist/server/utils/env-var.mjs +28 -0
- package/dist/server/utils/env-var.mjs.map +1 -0
- package/dist/server/utils/format-for-log.d.mts +5 -0
- package/dist/server/utils/format-for-log.d.mts.map +1 -0
- package/dist/server/utils/format-for-log.mjs +17 -0
- package/dist/server/utils/format-for-log.mjs.map +1 -0
- package/dist/server/utils/index.d.mts +8 -0
- package/dist/server/utils/index.mjs +9 -0
- package/dist/server/utils/load-config.d.mts +13 -0
- package/dist/server/utils/load-config.d.mts.map +1 -0
- package/dist/server/utils/load-config.mjs +65 -0
- package/dist/server/utils/load-config.mjs.map +1 -0
- package/dist/server/utils/log.d.mts +36 -0
- package/dist/server/utils/log.d.mts.map +1 -0
- package/dist/server/utils/log.mjs +125 -0
- package/dist/server/utils/log.mjs.map +1 -0
- package/dist/server/utils/read-file.d.mts +5 -0
- package/dist/server/utils/read-file.d.mts.map +1 -0
- package/dist/server/utils/read-file.mjs +14 -0
- package/dist/server/utils/read-file.mjs.map +1 -0
- package/dist/server/utils/resolve-path-with-extensions.d.mts +21 -0
- package/dist/server/utils/resolve-path-with-extensions.d.mts.map +1 -0
- package/dist/server/utils/resolve-path-with-extensions.mjs +39 -0
- package/dist/server/utils/resolve-path-with-extensions.mjs.map +1 -0
- package/dist/server/utils/schema.d.mts +7 -0
- package/dist/server/utils/schema.d.mts.map +1 -0
- package/dist/server/utils/schema.mjs +21 -0
- package/dist/server/utils/schema.mjs.map +1 -0
- package/dist/server/utils/standard-schema-validate.d.mts +13 -0
- package/dist/server/utils/standard-schema-validate.d.mts.map +1 -0
- package/dist/server/utils/standard-schema-validate.mjs +21 -0
- package/dist/server/utils/standard-schema-validate.mjs.map +1 -0
- package/dist/server/utils/suggest-similar.d.mts +9 -0
- package/dist/server/utils/suggest-similar.d.mts.map +1 -0
- package/dist/server/utils/suggest-similar.mjs +39 -0
- package/dist/server/utils/suggest-similar.mjs.map +1 -0
- package/dist/server/utils/warn-lockstep.d.mts +13 -0
- package/dist/server/utils/warn-lockstep.d.mts.map +1 -0
- package/dist/server/utils/warn-lockstep.mjs +23 -0
- package/dist/server/utils/warn-lockstep.mjs.map +1 -0
- package/dist/server/vite/create-config.d.mts +35 -0
- package/dist/server/vite/create-config.d.mts.map +1 -0
- package/dist/server/vite/create-config.mjs +64 -0
- package/dist/server/vite/create-config.mjs.map +1 -0
- package/dist/server/vite/plugins/collect-css.d.mts +8 -0
- package/dist/server/vite/plugins/collect-css.d.mts.map +1 -0
- package/dist/server/vite/plugins/collect-css.mjs +21 -0
- package/dist/server/vite/plugins/collect-css.mjs.map +1 -0
- package/dist/server/vite/plugins/get-styles.d.mts +14 -0
- package/dist/server/vite/plugins/get-styles.d.mts.map +1 -0
- package/dist/server/vite/plugins/get-styles.mjs +88 -0
- package/dist/server/vite/plugins/get-styles.mjs.map +1 -0
- package/dist/server/vite/plugins/html-loader.d.mts +18 -0
- package/dist/server/vite/plugins/html-loader.d.mts.map +1 -0
- package/dist/server/vite/plugins/html-loader.mjs +88 -0
- package/dist/server/vite/plugins/html-loader.mjs.map +1 -0
- package/dist/server/vite/plugins/postcss/import-url.d.mts +14 -0
- package/dist/server/vite/plugins/postcss/import-url.d.mts.map +1 -0
- package/dist/server/vite/plugins/postcss/import-url.mjs +163 -0
- package/dist/server/vite/plugins/postcss/import-url.mjs.map +1 -0
- package/dist/server/vite/plugins/styles-pre-processor.d.mts +7 -0
- package/dist/server/vite/plugins/styles-pre-processor.d.mts.map +1 -0
- package/dist/server/vite/plugins/styles-pre-processor.mjs +64 -0
- package/dist/server/vite/plugins/styles-pre-processor.mjs.map +1 -0
- package/dist/server/vite/plugins/utils.d.mts +9 -0
- package/dist/server/vite/plugins/utils.d.mts.map +1 -0
- package/dist/server/vite/plugins/utils.mjs +14 -0
- package/dist/server/vite/plugins/utils.mjs.map +1 -0
- package/dist/shared/constants.d.mts +11 -0
- package/dist/shared/constants.d.mts.map +1 -0
- package/dist/shared/constants.mjs +12 -0
- package/dist/shared/constants.mjs.map +1 -0
- package/dist/shared/env.d.mts +6 -0
- package/dist/shared/env.d.mts.map +1 -0
- package/dist/shared/env.mjs +11 -0
- package/dist/shared/env.mjs.map +1 -0
- package/dist/shared/http.d.mts +15 -0
- package/dist/shared/http.d.mts.map +1 -0
- package/dist/shared/http.mjs +54 -0
- package/dist/shared/http.mjs.map +1 -0
- package/dist/shared/types/document.d.mts +17 -0
- package/dist/shared/types/document.d.mts.map +1 -0
- package/dist/shared/types/document.mjs +1 -0
- package/dist/shared/types/index.d.mts +7 -0
- package/dist/shared/types/index.mjs +4 -0
- package/dist/shared/types/log.d.mts +10 -0
- package/dist/shared/types/log.d.mts.map +1 -0
- package/dist/shared/types/log.mjs +12 -0
- package/dist/shared/types/log.mjs.map +1 -0
- package/dist/shared/types/public/cli.d.mts +33 -0
- package/dist/shared/types/public/cli.d.mts.map +1 -0
- package/dist/shared/types/public/cli.mjs +1 -0
- package/dist/shared/types/public/compile.d.mts +45 -0
- package/dist/shared/types/public/compile.d.mts.map +1 -0
- package/dist/shared/types/public/compile.mjs +29 -0
- package/dist/shared/types/public/compile.mjs.map +1 -0
- package/dist/shared/types/public/config.d.mts +94 -0
- package/dist/shared/types/public/config.d.mts.map +1 -0
- package/dist/shared/types/public/config.mjs +20 -0
- package/dist/shared/types/public/config.mjs.map +1 -0
- package/dist/shared/types/public/index.d.mts +6 -0
- package/dist/shared/types/public/index.mjs +4 -0
- package/dist/shared/types/public/nextjs.d.mts +111 -0
- package/dist/shared/types/public/nextjs.d.mts.map +1 -0
- package/dist/shared/types/public/nextjs.mjs +1 -0
- package/dist/shared/types/public/renderer.d.mts +2 -0
- package/dist/shared/types/public/renderer.mjs +1 -0
- package/dist/shared/types/public/unplugin.d.mts +65 -0
- package/dist/shared/types/public/unplugin.d.mts.map +1 -0
- package/dist/shared/types/public/unplugin.mjs +1 -0
- package/dist/shared/types/server.d.mts +5 -0
- package/dist/shared/types/server.d.mts.map +1 -0
- package/dist/shared/types/server.mjs +1 -0
- package/dist/shared/types/state.d.mts +15 -0
- package/dist/shared/types/state.d.mts.map +1 -0
- package/dist/shared/types/state.mjs +1 -0
- package/dist/shared/types/system.d.mts +18 -0
- package/dist/shared/types/system.d.mts.map +1 -0
- package/dist/shared/types/system.mjs +1 -0
- package/package.json +146 -34
- package/types/next.d.ts +6 -0
- package/index.d.ts +0 -2
- package/index.js +0 -3
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { _dirname } from "../project/paths.mjs";
|
|
2
|
+
import { buildSafeEnv } from "./env.mjs";
|
|
3
|
+
import { deserializeError } from "./error.mjs";
|
|
4
|
+
import { SANDBOX_ERROR_CODE } from "./sandbox.mjs";
|
|
5
|
+
import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs";
|
|
6
|
+
import { dirname, resolve } from "node:path";
|
|
7
|
+
import { existsSync, readdirSync, realpathSync } from "node:fs";
|
|
8
|
+
import { fork } from "node:child_process";
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
|
|
12
|
+
//#region src/server/render-worker/client.ts
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the path to the compiled worker host entry point. The dist is
|
|
15
|
+
* unbundled, so host.js sits next to this module at dist/server/render-worker/.
|
|
16
|
+
* In dev/test _dirname points to src/, so fall back to the built dist.
|
|
17
|
+
*/
|
|
18
|
+
function getWorkerHostPath() {
|
|
19
|
+
const fromDist = resolve(_dirname, "server", "render-worker", "host.mjs");
|
|
20
|
+
if (existsSync(fromDist)) return fromDist;
|
|
21
|
+
return resolve(_dirname, "..", "dist", "server", "render-worker", "host.mjs");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compute the minimal set of filesystem paths the render worker needs
|
|
25
|
+
* read access to. Used with Node's --experimental-permission model to
|
|
26
|
+
* prevent user template code from reading sensitive files (.env, ~/.ssh, etc.).
|
|
27
|
+
*
|
|
28
|
+
* The worker needs:
|
|
29
|
+
* 1. Its own dist directory (compiled worker host + chunks)
|
|
30
|
+
* 2. node_modules directories (for externalized deps like vite, react, vue)
|
|
31
|
+
* 3. The Node.js installation directory (for native addons, if any)
|
|
32
|
+
* 4. Any extra paths provided by the caller (e.g. project source dirs)
|
|
33
|
+
*/
|
|
34
|
+
function computeAllowedReadPaths(extraPaths) {
|
|
35
|
+
const paths = /* @__PURE__ */ new Set();
|
|
36
|
+
/**
|
|
37
|
+
* Add a directory to the allowed set. Uses realpathSync so symlinked
|
|
38
|
+
* directories (e.g. /tmp → /private/tmp on macOS) match what the
|
|
39
|
+
* permission model actually checks.
|
|
40
|
+
*
|
|
41
|
+
* The `/*` suffix is required — Node 22's permission model treats
|
|
42
|
+
* bare paths as exact-file matches. `dir/*` grants recursive read
|
|
43
|
+
* access to all files under `dir` (including `stat(dir)` itself).
|
|
44
|
+
*/
|
|
45
|
+
const addDir = (dir) => {
|
|
46
|
+
let resolved;
|
|
47
|
+
try {
|
|
48
|
+
resolved = realpathSync(resolve(dir));
|
|
49
|
+
} catch {
|
|
50
|
+
resolved = resolve(dir);
|
|
51
|
+
}
|
|
52
|
+
if (resolved.endsWith("/")) resolved = resolved.slice(0, -1);
|
|
53
|
+
paths.add(resolved + "/*");
|
|
54
|
+
};
|
|
55
|
+
addDir(dirname(getWorkerHostPath()));
|
|
56
|
+
/**
|
|
57
|
+
* Walk up from a directory, adding every node_modules found.
|
|
58
|
+
* Also resolves symlinks inside each node_modules — pnpm workspace
|
|
59
|
+
* packages are symlinked to their real source directories, and Node's
|
|
60
|
+
* permission model checks the real path, not the symlink.
|
|
61
|
+
*
|
|
62
|
+
* Intermediate directories between consecutive node_modules are also
|
|
63
|
+
* added because Node's module resolver does stat() on
|
|
64
|
+
* `<dir>/node_modules` at every level. Without read permission on
|
|
65
|
+
* these gaps, the Permission Model throws ERR_ACCESS_DENIED (instead
|
|
66
|
+
* of ENOENT), which breaks module resolution entirely.
|
|
67
|
+
*/
|
|
68
|
+
const findNodeModules = (startDir) => {
|
|
69
|
+
let dir = resolve(startDir);
|
|
70
|
+
const gapDirs = [];
|
|
71
|
+
while (true) {
|
|
72
|
+
const nm = resolve(dir, "node_modules");
|
|
73
|
+
if (existsSync(nm)) {
|
|
74
|
+
addDir(nm);
|
|
75
|
+
resolveSymlinkedPackages(nm);
|
|
76
|
+
for (const gap of gapDirs) addDir(gap);
|
|
77
|
+
gapDirs.length = 0;
|
|
78
|
+
} else gapDirs.push(dir);
|
|
79
|
+
const parent = dirname(dir);
|
|
80
|
+
if (parent === dir) break;
|
|
81
|
+
dir = parent;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/** Resolve symlinks in a node_modules directory (top-level + scoped). */
|
|
85
|
+
const resolveSymlinkedPackages = (nmDir) => {
|
|
86
|
+
let entries;
|
|
87
|
+
try {
|
|
88
|
+
entries = readdirSync(nmDir);
|
|
89
|
+
} catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
const entryPath = resolve(nmDir, entry);
|
|
94
|
+
if (entry.startsWith("@")) {
|
|
95
|
+
resolveSymlinkedPackages(entryPath);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const realPath = realpathSync(entryPath);
|
|
100
|
+
if (realPath !== entryPath) addDir(realPath);
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
findNodeModules(dirname(getWorkerHostPath()));
|
|
105
|
+
findNodeModules(process.cwd());
|
|
106
|
+
if (extraPaths) for (const p of extraPaths) {
|
|
107
|
+
let dir = resolve(p);
|
|
108
|
+
while (true) {
|
|
109
|
+
addDir(dir);
|
|
110
|
+
const nm = resolve(dir, "node_modules");
|
|
111
|
+
if (existsSync(nm)) {
|
|
112
|
+
addDir(nm);
|
|
113
|
+
resolveSymlinkedPackages(nm);
|
|
114
|
+
}
|
|
115
|
+
if (existsSync(resolve(dir, ".git")) || existsSync(resolve(dir, "pnpm-workspace.yaml"))) break;
|
|
116
|
+
const parent = dirname(dir);
|
|
117
|
+
if (parent === dir) break;
|
|
118
|
+
dir = parent;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
addDir(dirname(process.execPath));
|
|
122
|
+
return [...paths];
|
|
123
|
+
}
|
|
124
|
+
var RenderWorker = class {
|
|
125
|
+
constructor(options) {
|
|
126
|
+
_defineProperty(this, "worker", null);
|
|
127
|
+
_defineProperty(this, "pending", /* @__PURE__ */ new Map());
|
|
128
|
+
_defineProperty(this, "readyPromise", null);
|
|
129
|
+
_defineProperty(this, "timeout", void 0);
|
|
130
|
+
_defineProperty(this, "log", void 0);
|
|
131
|
+
_defineProperty(this, "_warn", void 0);
|
|
132
|
+
_defineProperty(this, "allowedReadPaths", void 0);
|
|
133
|
+
_defineProperty(this, "sandbox", void 0);
|
|
134
|
+
_defineProperty(this, "lastInitArgs", null);
|
|
135
|
+
_defineProperty(this, "devInitialized", false);
|
|
136
|
+
_defineProperty(this, "devInitPromise", null);
|
|
137
|
+
_defineProperty(this, "restartPromise", null);
|
|
138
|
+
this.timeout = options?.timeout ?? 3e4;
|
|
139
|
+
this.log = options?.log ?? ((msg) => console.debug(msg));
|
|
140
|
+
this._warn = options?.warn ?? ((msg) => console.warn(msg));
|
|
141
|
+
this.allowedReadPaths = options?.allowedReadPaths;
|
|
142
|
+
this.sandbox = options?.sandbox ?? false;
|
|
143
|
+
}
|
|
144
|
+
spawn() {
|
|
145
|
+
const hostPath = getWorkerHostPath();
|
|
146
|
+
const env = buildSafeEnv();
|
|
147
|
+
let execArgv = [];
|
|
148
|
+
if (this.sandbox === "strict") {
|
|
149
|
+
const allowedReadPaths = computeAllowedReadPaths(this.allowedReadPaths);
|
|
150
|
+
let realTmpDir;
|
|
151
|
+
try {
|
|
152
|
+
realTmpDir = realpathSync(tmpdir());
|
|
153
|
+
} catch {
|
|
154
|
+
realTmpDir = tmpdir();
|
|
155
|
+
}
|
|
156
|
+
const allowedWritePaths = [realTmpDir + "/*"];
|
|
157
|
+
execArgv = [
|
|
158
|
+
"--no-warnings",
|
|
159
|
+
"--experimental-permission",
|
|
160
|
+
...allowedReadPaths.map((p) => `--allow-fs-read=${p}`),
|
|
161
|
+
...allowedWritePaths.map((p) => `--allow-fs-write=${p}`)
|
|
162
|
+
];
|
|
163
|
+
this.log(`Spawning sandboxed render worker (strict): ${hostPath}`);
|
|
164
|
+
} else if (this.sandbox === "standard") this.log(`Spawning sandboxed render worker (standard): ${hostPath}`);
|
|
165
|
+
else this.log(`Spawning render worker: ${hostPath}`);
|
|
166
|
+
if (this.sandbox) env.FMT_SANDBOX_MODE = this.sandbox;
|
|
167
|
+
const child = fork(hostPath, [], {
|
|
168
|
+
env,
|
|
169
|
+
stdio: [
|
|
170
|
+
"ignore",
|
|
171
|
+
"pipe",
|
|
172
|
+
"pipe",
|
|
173
|
+
"ipc"
|
|
174
|
+
],
|
|
175
|
+
serialization: "advanced",
|
|
176
|
+
execArgv
|
|
177
|
+
});
|
|
178
|
+
child.stdout?.on("data", (data) => {
|
|
179
|
+
const text = data.toString().trim();
|
|
180
|
+
if (text) this.log(`[render-worker] ${text}`);
|
|
181
|
+
});
|
|
182
|
+
child.stderr?.on("data", (data) => {
|
|
183
|
+
const text = data.toString().trim();
|
|
184
|
+
if (!text) return;
|
|
185
|
+
if (text.includes(SANDBOX_ERROR_CODE)) return;
|
|
186
|
+
this._warn(`[render-worker] ${text}`);
|
|
187
|
+
});
|
|
188
|
+
child.on("message", (msg) => {
|
|
189
|
+
const response = msg;
|
|
190
|
+
if (response.type === "ready") return;
|
|
191
|
+
if (response.type === "dev-init-result") {
|
|
192
|
+
const pending$1 = this.pending.get(response.id);
|
|
193
|
+
if (!pending$1) return;
|
|
194
|
+
this.pending.delete(response.id);
|
|
195
|
+
clearTimeout(pending$1.timer);
|
|
196
|
+
pending$1.resolve(response);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const pending = this.pending.get(response.id);
|
|
200
|
+
if (!pending) return;
|
|
201
|
+
this.pending.delete(response.id);
|
|
202
|
+
clearTimeout(pending.timer);
|
|
203
|
+
if (response.type === "render-result") pending.resolve(response);
|
|
204
|
+
else if (response.type === "render-error") pending.reject(deserializeError(response.error));
|
|
205
|
+
});
|
|
206
|
+
child.on("exit", (code, signal) => {
|
|
207
|
+
this.log(`Render worker exited (code=${code}, signal=${signal})`);
|
|
208
|
+
if (this.worker !== child) return;
|
|
209
|
+
this.worker = null;
|
|
210
|
+
this.devInitialized = false;
|
|
211
|
+
for (const [, pending] of this.pending) {
|
|
212
|
+
clearTimeout(pending.timer);
|
|
213
|
+
pending.reject(/* @__PURE__ */ new Error(`Render worker exited unexpectedly (code=${code})`));
|
|
214
|
+
}
|
|
215
|
+
this.pending.clear();
|
|
216
|
+
});
|
|
217
|
+
this.worker = child;
|
|
218
|
+
return child;
|
|
219
|
+
}
|
|
220
|
+
async ensureWorker() {
|
|
221
|
+
if (this.worker && !this.worker.killed) return this.worker;
|
|
222
|
+
const child = this.spawn();
|
|
223
|
+
this.readyPromise = new Promise((resolve$1, reject) => {
|
|
224
|
+
const onReady = (msg) => {
|
|
225
|
+
if (msg?.type === "ready") {
|
|
226
|
+
child.off("message", onReady);
|
|
227
|
+
child.off("error", onError);
|
|
228
|
+
resolve$1();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const onError = (err) => {
|
|
232
|
+
child.off("message", onReady);
|
|
233
|
+
reject(err);
|
|
234
|
+
};
|
|
235
|
+
child.on("message", onReady);
|
|
236
|
+
child.once("error", onError);
|
|
237
|
+
});
|
|
238
|
+
await this.readyPromise;
|
|
239
|
+
return child;
|
|
240
|
+
}
|
|
241
|
+
async send(request) {
|
|
242
|
+
const child = await this.ensureWorker();
|
|
243
|
+
const id = request.id || randomUUID();
|
|
244
|
+
const msg = {
|
|
245
|
+
...request,
|
|
246
|
+
id
|
|
247
|
+
};
|
|
248
|
+
return new Promise((resolve$1, reject) => {
|
|
249
|
+
const timer = setTimeout(() => {
|
|
250
|
+
this.pending.delete(id);
|
|
251
|
+
reject(/* @__PURE__ */ new Error(`Render worker timed out after ${this.timeout}ms`));
|
|
252
|
+
}, this.timeout);
|
|
253
|
+
this.pending.set(id, {
|
|
254
|
+
resolve: resolve$1,
|
|
255
|
+
reject,
|
|
256
|
+
timer
|
|
257
|
+
});
|
|
258
|
+
child.send(msg);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Initialize the subprocess's headless Vite dev server.
|
|
263
|
+
* Must be called once before any devRender() calls.
|
|
264
|
+
*/
|
|
265
|
+
async initDev(args) {
|
|
266
|
+
this.lastInitArgs = args;
|
|
267
|
+
const init = this.send({
|
|
268
|
+
id: randomUUID(),
|
|
269
|
+
type: "dev-init",
|
|
270
|
+
...args
|
|
271
|
+
}).then(() => {
|
|
272
|
+
this.devInitialized = true;
|
|
273
|
+
});
|
|
274
|
+
this.devInitPromise = init;
|
|
275
|
+
try {
|
|
276
|
+
await init;
|
|
277
|
+
} finally {
|
|
278
|
+
if (this.devInitPromise === init) this.devInitPromise = null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Guarantee the current subprocess has been dev-init'd before a dev render
|
|
283
|
+
* is sent. Without this, a worker spawned in the gap after dispose() (or
|
|
284
|
+
* after a crash) starts with no headless Vite server, and every dev render
|
|
285
|
+
* against it fails until something replays the init.
|
|
286
|
+
*/
|
|
287
|
+
async ensureDevInit() {
|
|
288
|
+
if (this.devInitPromise) await this.devInitPromise;
|
|
289
|
+
if (this.worker !== null && !this.worker.killed && this.devInitialized) return;
|
|
290
|
+
if (!this.lastInitArgs) throw new Error("Render worker is not initialized for dev rendering. Call initDev() before devRender().");
|
|
291
|
+
await this.initDev(this.lastInitArgs);
|
|
292
|
+
}
|
|
293
|
+
updateInitConfig(configJson) {
|
|
294
|
+
if (this.lastInitArgs) this.lastInitArgs = {
|
|
295
|
+
...this.lastInitArgs,
|
|
296
|
+
configJson
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Kill and respawn the subprocess, replaying the last dev-init call.
|
|
301
|
+
*
|
|
302
|
+
* The subprocess's headless Vite server is created once and reused for
|
|
303
|
+
* every render, with dependency discovery disabled (optimizeDeps.noDiscovery)
|
|
304
|
+
* for determinism. That means a package installed mid-session — e.g. by the
|
|
305
|
+
* "new document" flow's install-dependencies step — is invisible to its
|
|
306
|
+
* resolver until the process (and its Vite instance) starts fresh. Call this
|
|
307
|
+
* after any change to node_modules the next render depends on.
|
|
308
|
+
*/
|
|
309
|
+
async restart() {
|
|
310
|
+
const doRestart = async () => {
|
|
311
|
+
if (!this.lastInitArgs) {
|
|
312
|
+
await this.dispose();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const initArgs = this.lastInitArgs;
|
|
316
|
+
await this.dispose();
|
|
317
|
+
await this.initDev(initArgs);
|
|
318
|
+
};
|
|
319
|
+
this.restartPromise = doRestart();
|
|
320
|
+
try {
|
|
321
|
+
await this.restartPromise;
|
|
322
|
+
} finally {
|
|
323
|
+
this.restartPromise = null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async devRender(args) {
|
|
327
|
+
if (this.restartPromise) await this.restartPromise;
|
|
328
|
+
await this.ensureDevInit();
|
|
329
|
+
return { html: (await this.send({
|
|
330
|
+
id: randomUUID(),
|
|
331
|
+
type: "dev-render",
|
|
332
|
+
...args
|
|
333
|
+
})).html };
|
|
334
|
+
}
|
|
335
|
+
async compileRender(args) {
|
|
336
|
+
if (this.restartPromise) await this.restartPromise;
|
|
337
|
+
return (await this.send({
|
|
338
|
+
id: randomUUID(),
|
|
339
|
+
type: "compile-render",
|
|
340
|
+
...args
|
|
341
|
+
})).html;
|
|
342
|
+
}
|
|
343
|
+
async dispose() {
|
|
344
|
+
if (this.worker) {
|
|
345
|
+
this.worker.kill();
|
|
346
|
+
this.worker = null;
|
|
347
|
+
}
|
|
348
|
+
this.devInitialized = false;
|
|
349
|
+
for (const [, pending] of this.pending) {
|
|
350
|
+
clearTimeout(pending.timer);
|
|
351
|
+
pending.reject(/* @__PURE__ */ new Error("Render worker disposed"));
|
|
352
|
+
}
|
|
353
|
+
this.pending.clear();
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
//#endregion
|
|
358
|
+
export { RenderWorker };
|
|
359
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +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":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CssConcat } from "../../shared/types/server.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/server/render-worker/document-css.d.ts
|
|
4
|
+
interface DocumentModule {
|
|
5
|
+
id: string | null;
|
|
6
|
+
importedModules: Set<DocumentModule>;
|
|
7
|
+
}
|
|
8
|
+
interface InvalidateModuleTreeArgs<Module extends DocumentModule> {
|
|
9
|
+
entry: Module | undefined;
|
|
10
|
+
invalidate: (module: Module) => void;
|
|
11
|
+
}
|
|
12
|
+
interface CollectDocumentCssArgs {
|
|
13
|
+
entry: DocumentModule | undefined;
|
|
14
|
+
css: CssConcat;
|
|
15
|
+
}
|
|
16
|
+
/** Force the next load to transform and evaluate every module the document imports again. */
|
|
17
|
+
declare function invalidateModuleTree<Module extends DocumentModule>(args: InvalidateModuleTreeArgs<Module>): void;
|
|
18
|
+
/**
|
|
19
|
+
* Join the CSS of every style module the document imports, in import order.
|
|
20
|
+
* Vite skips the transform for a module another document already loaded, so
|
|
21
|
+
* the CSS has to come from what was stored at its last transform, not from
|
|
22
|
+
* what this render happened to transform.
|
|
23
|
+
*/
|
|
24
|
+
declare function collectDocumentCss(args: CollectDocumentCssArgs): string;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { DocumentModule, collectDocumentCss, invalidateModuleTree };
|
|
27
|
+
//# sourceMappingURL=document-css.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-css.d.mts","names":[],"sources":["../../../src/server/render-worker/document-css.ts"],"sourcesContent":[],"mappings":";;;UAEiB,cAAA;;EAAA,eAAA,EAEC,GAFa,CAET,cAAA,CAAA;AACrB;UAES,wBAAwC,CAAA,eAAA,cAAA,CAAA,CAAA;EAC1C,KAAA,EAAA,MAAA,GAAA,SAAA;EACc,UAAA,EAAA,CAAA,MAAA,EAAA,MAAA,EAAA,GAAA,IAAA;;AAAM,UAGlB,sBAAA,CAAsB;EAsBhB,KAAA,EArBR,cAqBQ,GAAoB,SAAA;EAAgB,GAAA,EApB9C,SAoB8C;;;AAA8C,iBAAlF,oBAAkF,CAAA,eAA9C,cAA8C,CAAA,CAAA,IAAA,EAAxB,wBAAwB,CAAC,MAAD,CAAA,CAAA,EAAA,IAAA;AAgBlG;;;;;;iBAAgB,kBAAA,OAAyB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/server/render-worker/document-css.ts
|
|
2
|
+
function walkModuleTree(entry, visit) {
|
|
3
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4
|
+
const walk = (module) => {
|
|
5
|
+
if (seen.has(module)) return;
|
|
6
|
+
seen.add(module);
|
|
7
|
+
visit(module);
|
|
8
|
+
module.importedModules.forEach((imported) => walk(imported));
|
|
9
|
+
};
|
|
10
|
+
walk(entry);
|
|
11
|
+
}
|
|
12
|
+
/** Force the next load to transform and evaluate every module the document imports again. */
|
|
13
|
+
function invalidateModuleTree(args) {
|
|
14
|
+
const { entry, invalidate } = args;
|
|
15
|
+
if (!entry) return;
|
|
16
|
+
walkModuleTree(entry, invalidate);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Join the CSS of every style module the document imports, in import order.
|
|
20
|
+
* Vite skips the transform for a module another document already loaded, so
|
|
21
|
+
* the CSS has to come from what was stored at its last transform, not from
|
|
22
|
+
* what this render happened to transform.
|
|
23
|
+
*/
|
|
24
|
+
function collectDocumentCss(args) {
|
|
25
|
+
const { entry, css } = args;
|
|
26
|
+
if (!entry) return "";
|
|
27
|
+
const styles = [];
|
|
28
|
+
walkModuleTree(entry, (module) => {
|
|
29
|
+
const moduleCss = module.id ? css.get(module.id) : void 0;
|
|
30
|
+
if (moduleCss !== void 0) styles.push(moduleCss);
|
|
31
|
+
});
|
|
32
|
+
return styles.join("");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { collectDocumentCss, invalidateModuleTree };
|
|
37
|
+
//# sourceMappingURL=document-css.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-css.mjs","names":["styles: string[]"],"sources":["../../../src/server/render-worker/document-css.ts"],"sourcesContent":["import type { CssConcat } from '../../shared/types'\n\nexport interface DocumentModule {\n\tid: string | null\n\timportedModules: Set<DocumentModule>\n}\n\ninterface InvalidateModuleTreeArgs<Module extends DocumentModule> {\n\tentry: Module | undefined\n\tinvalidate: (module: Module) => void\n}\n\ninterface CollectDocumentCssArgs {\n\tentry: DocumentModule | undefined\n\tcss: CssConcat\n}\n\nfunction walkModuleTree<Module extends DocumentModule>(entry: Module, visit: (module: Module) => void) {\n\tconst seen = new Set<Module>()\n\n\tconst walk = (module: Module) => {\n\t\tif (seen.has(module)) {\n\t\t\treturn\n\t\t}\n\n\t\tseen.add(module)\n\t\tvisit(module)\n\t\tmodule.importedModules.forEach(imported => walk(imported as Module))\n\t}\n\n\twalk(entry)\n}\n\n/** Force the next load to transform and evaluate every module the document imports again. */\nexport function invalidateModuleTree<Module extends DocumentModule>(args: InvalidateModuleTreeArgs<Module>) {\n\tconst { entry, invalidate } = args\n\n\tif (!entry) {\n\t\treturn\n\t}\n\n\twalkModuleTree(entry, invalidate)\n}\n\n/**\n * Join the CSS of every style module the document imports, in import order.\n * Vite skips the transform for a module another document already loaded, so\n * the CSS has to come from what was stored at its last transform, not from\n * what this render happened to transform.\n */\nexport function collectDocumentCss(args: CollectDocumentCssArgs): string {\n\tconst { entry, css } = args\n\n\tif (!entry) {\n\t\treturn ''\n\t}\n\n\tconst styles: string[] = []\n\n\twalkModuleTree(entry, module => {\n\t\tconst moduleCss = module.id ? css.get(module.id) : undefined\n\n\t\tif (moduleCss !== undefined) {\n\t\t\tstyles.push(moduleCss)\n\t\t}\n\t})\n\n\treturn styles.join('')\n}\n"],"mappings":";AAiBA,SAAS,eAA8C,OAAe,OAAiC;CACtG,MAAM,uBAAO,IAAI,KAAa;CAE9B,MAAM,QAAQ,WAAmB;AAChC,MAAI,KAAK,IAAI,OAAO,CACnB;AAGD,OAAK,IAAI,OAAO;AAChB,QAAM,OAAO;AACb,SAAO,gBAAgB,SAAQ,aAAY,KAAK,SAAmB,CAAC;;AAGrE,MAAK,MAAM;;;AAIZ,SAAgB,qBAAoD,MAAwC;CAC3G,MAAM,EAAE,OAAO,eAAe;AAE9B,KAAI,CAAC,MACJ;AAGD,gBAAe,OAAO,WAAW;;;;;;;;AASlC,SAAgB,mBAAmB,MAAsC;CACxE,MAAM,EAAE,OAAO,QAAQ;AAEvB,KAAI,CAAC,MACJ,QAAO;CAGR,MAAMA,SAAmB,EAAE;AAE3B,gBAAe,QAAO,WAAU;EAC/B,MAAM,YAAY,OAAO,KAAK,IAAI,IAAI,OAAO,GAAG,GAAG;AAEnD,MAAI,cAAc,OACjB,QAAO,KAAK,UAAU;GAEtB;AAEF,QAAO,OAAO,KAAK,GAAG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/server/render-worker/env.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Build a minimal environment for the render worker process.
|
|
4
|
+
*
|
|
5
|
+
* Starts from an empty object and adds only what the worker strictly needs.
|
|
6
|
+
* No prefixes, no pattern matching — just an explicit allowlist.
|
|
7
|
+
*/
|
|
8
|
+
declare function buildSafeEnv(source?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { buildSafeEnv };
|
|
11
|
+
//# sourceMappingURL=env.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.mts","names":[],"sources":["../../../src/server/render-worker/env.ts"],"sourcesContent":[],"mappings":";;AAwBA;;;;;iBAAgB,YAAA,UAAqB,MAAA,CAAO,aAA2B,MAAA,CAAO"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/server/render-worker/env.ts
|
|
2
|
+
/**
|
|
3
|
+
* Build a minimal environment for the render worker process.
|
|
4
|
+
*
|
|
5
|
+
* Starts from an empty object and adds only what the worker strictly needs.
|
|
6
|
+
* No prefixes, no pattern matching — just an explicit allowlist.
|
|
7
|
+
*/
|
|
8
|
+
const SAFE_KEYS = new Set([
|
|
9
|
+
"NODE_ENV",
|
|
10
|
+
"FORMAT_DEBUG",
|
|
11
|
+
"HOME",
|
|
12
|
+
"PATH",
|
|
13
|
+
"FMT_SANDBOX_MODE"
|
|
14
|
+
]);
|
|
15
|
+
function buildSafeEnv(source = process.env) {
|
|
16
|
+
const safe = {};
|
|
17
|
+
for (const [key, value] of Object.entries(source)) {
|
|
18
|
+
if (value === void 0) continue;
|
|
19
|
+
if (SAFE_KEYS.has(key)) safe[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return safe;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { buildSafeEnv };
|
|
26
|
+
//# sourceMappingURL=env.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.mjs","names":["safe: NodeJS.ProcessEnv"],"sources":["../../../src/server/render-worker/env.ts"],"sourcesContent":["/**\n * Build a minimal environment for the render worker process.\n *\n * Starts from an empty object and adds only what the worker strictly needs.\n * No prefixes, no pattern matching — just an explicit allowlist.\n */\n\nconst SAFE_KEYS = new Set([\n\t// React/Vue use this to switch between development and production behavior\n\t'NODE_ENV',\n\n\t// Enables verbose logging (debug-level output, adaptor diagnostics, etc.)\n\t'FORMAT_DEBUG',\n\n\t// Vite and native addons need HOME for cache directories and config resolution\n\t'HOME',\n\n\t// System PATH is needed for external tools (sass, etc.) invoked by plugins\n\t'PATH',\n\n\t// Tells the subprocess which sandbox mode to apply (strict, standard, or absent)\n\t'FMT_SANDBOX_MODE'\n])\n\nexport function buildSafeEnv(source: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {\n\tconst safe: NodeJS.ProcessEnv = {}\n\n\tfor (const [key, value] of Object.entries(source)) {\n\t\tif (value === undefined) continue\n\n\t\tif (SAFE_KEYS.has(key)) {\n\t\t\tsafe[key] = value\n\t\t}\n\t}\n\n\treturn safe\n}\n"],"mappings":";;;;;;;AAOA,MAAM,YAAY,IAAI,IAAI;CAEzB;CAGA;CAGA;CAGA;CAGA;CACA,CAAC;AAEF,SAAgB,aAAa,SAA4B,QAAQ,KAAwB;CACxF,MAAMA,OAA0B,EAAE;AAElC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,EAAE;AAClD,MAAI,UAAU,OAAW;AAEzB,MAAI,UAAU,IAAI,IAAI,CACrB,MAAK,OAAO;;AAId,QAAO"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SerializedError } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/server/render-worker/error.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serialize an error for IPC transport. Preserves name, message, stack, the
|
|
7
|
+
* custom `data` property used by FormatRenderError, and the `missing`/`known`
|
|
8
|
+
* asset lists an AssetMismatchError carries (the class itself can't survive IPC).
|
|
9
|
+
*/
|
|
10
|
+
declare function serializeError(error: unknown): SerializedError;
|
|
11
|
+
/**
|
|
12
|
+
* Reconstruct an Error instance from a serialized representation.
|
|
13
|
+
*/
|
|
14
|
+
declare function deserializeError(serialized: SerializedError): Error;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { deserializeError, serializeError };
|
|
17
|
+
//# sourceMappingURL=error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.mts","names":[],"sources":["../../../src/server/render-worker/error.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAuBA;;iBAvBgB,cAAA,kBAAgC;;;;iBAuBhC,gBAAA,aAA6B,kBAAkB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/server/render-worker/error.ts
|
|
2
|
+
/**
|
|
3
|
+
* Serialize an error for IPC transport. Preserves name, message, stack, the
|
|
4
|
+
* custom `data` property used by FormatRenderError, and the `missing`/`known`
|
|
5
|
+
* asset lists an AssetMismatchError carries (the class itself can't survive IPC).
|
|
6
|
+
*/
|
|
7
|
+
function serializeError(error) {
|
|
8
|
+
if (error instanceof Error) return {
|
|
9
|
+
name: error.name,
|
|
10
|
+
message: error.message,
|
|
11
|
+
stack: error.stack,
|
|
12
|
+
code: error.code,
|
|
13
|
+
data: error.data,
|
|
14
|
+
missing: error.missing,
|
|
15
|
+
known: error.known,
|
|
16
|
+
remoteRefs: error.remoteRefs
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
name: "Error",
|
|
20
|
+
message: String(error)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reconstruct an Error instance from a serialized representation.
|
|
25
|
+
*/
|
|
26
|
+
function deserializeError(serialized) {
|
|
27
|
+
const error = new Error(serialized.message);
|
|
28
|
+
error.name = serialized.name;
|
|
29
|
+
if (serialized.stack) error.stack = serialized.stack;
|
|
30
|
+
if (serialized.code !== void 0) error.code = serialized.code;
|
|
31
|
+
if (serialized.data !== void 0) error.data = serialized.data;
|
|
32
|
+
if (serialized.missing !== void 0) error.missing = serialized.missing;
|
|
33
|
+
if (serialized.known !== void 0) error.known = serialized.known;
|
|
34
|
+
if (serialized.remoteRefs !== void 0) error.remoteRefs = serialized.remoteRefs;
|
|
35
|
+
return error;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { deserializeError, serializeError };
|
|
40
|
+
//# sourceMappingURL=error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.mjs","names":[],"sources":["../../../src/server/render-worker/error.ts"],"sourcesContent":["import type { SerializedError } from './types'\n\n/**\n * Serialize an error for IPC transport. Preserves name, message, stack, the\n * custom `data` property used by FormatRenderError, and the `missing`/`known`\n * asset lists an AssetMismatchError carries (the class itself can't survive IPC).\n */\nexport function serializeError(error: unknown): SerializedError {\n\tif (error instanceof Error) {\n\t\treturn {\n\t\t\tname: error.name,\n\t\t\tmessage: error.message,\n\t\t\tstack: error.stack,\n\t\t\tcode: (error as any).code,\n\t\t\tdata: (error as any).data,\n\t\t\tmissing: (error as any).missing,\n\t\t\tknown: (error as any).known,\n\t\t\tremoteRefs: (error as any).remoteRefs\n\t\t}\n\t}\n\n\treturn {\n\t\tname: 'Error',\n\t\tmessage: String(error)\n\t}\n}\n\n/**\n * Reconstruct an Error instance from a serialized representation.\n */\nexport function deserializeError(serialized: SerializedError): Error {\n\tconst error = new Error(serialized.message)\n\terror.name = serialized.name\n\n\tif (serialized.stack) {\n\t\terror.stack = serialized.stack\n\t}\n\n\tif (serialized.code !== undefined) {\n\t\t;(error as any).code = serialized.code\n\t}\n\n\tif (serialized.data !== undefined) {\n\t\t;(error as any).data = serialized.data\n\t}\n\n\tif (serialized.missing !== undefined) {\n\t\t;(error as any).missing = serialized.missing\n\t}\n\n\tif (serialized.known !== undefined) {\n\t\t;(error as any).known = serialized.known\n\t}\n\n\tif (serialized.remoteRefs !== undefined) {\n\t\t;(error as any).remoteRefs = serialized.remoteRefs\n\t}\n\n\treturn error\n}\n"],"mappings":";;;;;;AAOA,SAAgB,eAAe,OAAiC;AAC/D,KAAI,iBAAiB,MACpB,QAAO;EACN,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,OAAO,MAAM;EACb,MAAO,MAAc;EACrB,MAAO,MAAc;EACrB,SAAU,MAAc;EACxB,OAAQ,MAAc;EACtB,YAAa,MAAc;EAC3B;AAGF,QAAO;EACN,MAAM;EACN,SAAS,OAAO,MAAM;EACtB;;;;;AAMF,SAAgB,iBAAiB,YAAoC;CACpE,MAAM,QAAQ,IAAI,MAAM,WAAW,QAAQ;AAC3C,OAAM,OAAO,WAAW;AAExB,KAAI,WAAW,MACd,OAAM,QAAQ,WAAW;AAG1B,KAAI,WAAW,SAAS,OACtB,CAAC,MAAc,OAAO,WAAW;AAGnC,KAAI,WAAW,SAAS,OACtB,CAAC,MAAc,OAAO,WAAW;AAGnC,KAAI,WAAW,YAAY,OACzB,CAAC,MAAc,UAAU,WAAW;AAGtC,KAAI,WAAW,UAAU,OACvB,CAAC,MAAc,QAAQ,WAAW;AAGpC,KAAI,WAAW,eAAe,OAC5B,CAAC,MAAc,aAAa,WAAW;AAGzC,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|