@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,143 @@
|
|
|
1
|
+
import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs";
|
|
2
|
+
import { sdkVersion } from "./producer-release.mjs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
|
|
6
|
+
//#region src/server/compile/producer-agreement.ts
|
|
7
|
+
/**
|
|
8
|
+
* Check that every installed Format package that produces documents is on the
|
|
9
|
+
* same release as this compiler.
|
|
10
|
+
*
|
|
11
|
+
* The compiler stamps `data-sdk` with its own version, but React or Vue rendered
|
|
12
|
+
* the markup. If they are on a different version that stamp is wrong, so this
|
|
13
|
+
* refuses before anything renders and names the packages to fix.
|
|
14
|
+
*
|
|
15
|
+
* It finds each package by walking up `node_modules` and reading the first
|
|
16
|
+
* `package.json` it hits, which is the copy Node would load. It does not use
|
|
17
|
+
* `require.resolve`: under vitest that resolves to this workspace's own source,
|
|
18
|
+
* so a test for "not installed" would pass by finding the repo it runs in.
|
|
19
|
+
*
|
|
20
|
+
* A package that is not installed is fine — a React project has no Vue, and a
|
|
21
|
+
* build that aliases an SDK to source has no manifest to read. A `package.json`
|
|
22
|
+
* that exists but will not parse is not fine: the walk stops there rather than
|
|
23
|
+
* carrying on up and reporting some other installation's version as this one's.
|
|
24
|
+
*
|
|
25
|
+
* `finalize-document-html` checks again at render time, comparing the `data-sdk`
|
|
26
|
+
* already on the markup against this compiler's. That catches what this cannot
|
|
27
|
+
* see, such as Yarn PnP, where there is no `node_modules` tree to walk.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* The packages that produce document markup this compiler then stamps.
|
|
31
|
+
*
|
|
32
|
+
* Only these. `@format.dev/zip`, `@format.dev/fonts` and the rest move on the
|
|
33
|
+
* same release number and are checked by the lockstep warning, but none of them
|
|
34
|
+
* writes markup, so none of them can make a document's provenance wrong.
|
|
35
|
+
*/
|
|
36
|
+
const PRODUCING_PACKAGES = ["@format.dev/react", "@format.dev/vue"];
|
|
37
|
+
/**
|
|
38
|
+
* A producing package is installed and its version cannot be established.
|
|
39
|
+
*
|
|
40
|
+
* Separate from disagreement because it is a different fact: nothing has been
|
|
41
|
+
* shown to disagree, and nothing has been shown to agree either. The reason it
|
|
42
|
+
* stops the compile anyway is that this module exists to make one claim
|
|
43
|
+
* honest — that the release number about to be stamped on a document is the
|
|
44
|
+
* release that produced it — and a package whose version is unreadable is
|
|
45
|
+
* exactly the case where that claim cannot be made.
|
|
46
|
+
*
|
|
47
|
+
* Only a package that is absent is silence. Absent is an ordinary state with an
|
|
48
|
+
* ordinary meaning: a project that uses React never installed Vue, or a build
|
|
49
|
+
* aliased an SDK to source. A manifest that exists and will not parse is neither
|
|
50
|
+
* of those, and reading past it to a copy in a parent directory would be worse
|
|
51
|
+
* than failing — it would report a version belonging to an installation that is
|
|
52
|
+
* not the one Node will load.
|
|
53
|
+
*/
|
|
54
|
+
var ProducerManifestError = class extends Error {
|
|
55
|
+
constructor(packageName, manifest, problem) {
|
|
56
|
+
super(`Format cannot read which version of ${packageName} is installed:\n\n ${manifest}\n ${problem}\n\nThat package produces document markup and Format stamps the release that produced it onto every document, so a version it cannot establish is one it cannot honestly write down. Nothing was compiled. Reinstall your dependencies — \`format update\` brings every @format.dev/* package to one version.`);
|
|
57
|
+
_defineProperty(this, "name", "ProducerManifestError");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var ProducerAgreementError = class extends Error {
|
|
61
|
+
constructor(compilerSdk, disagreeing) {
|
|
62
|
+
const listed = disagreeing.map((producer) => ` ${producer.name} ${producer.version}`).join("\n");
|
|
63
|
+
super(`Format ${compilerSdk} is compiling, and these packages are a different release:\n\n${listed}\n\nA document would be stamped as one release having produced work from two, so nothing was compiled. Bring every @format.dev/* package to one version — \`format update\` does it.`);
|
|
64
|
+
_defineProperty(this, "compilerSdk", void 0);
|
|
65
|
+
_defineProperty(this, "disagreeing", void 0);
|
|
66
|
+
this.name = "ProducerAgreementError";
|
|
67
|
+
this.compilerSdk = compilerSdk;
|
|
68
|
+
this.disagreeing = disagreeing;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The producing packages that resolve from `cwd`, with the versions that will
|
|
73
|
+
* actually run.
|
|
74
|
+
*
|
|
75
|
+
* Exported so a test can see what resolution found without inferring it from
|
|
76
|
+
* whether a throw happened.
|
|
77
|
+
*/
|
|
78
|
+
function resolveProducers(cwd, packages = PRODUCING_PACKAGES) {
|
|
79
|
+
const found = [];
|
|
80
|
+
for (const name of packages) {
|
|
81
|
+
const version = installedVersion(cwd, name);
|
|
82
|
+
if (version !== null) found.push({
|
|
83
|
+
name,
|
|
84
|
+
version
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return found;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The version of `name` this project would load, or null when it is not
|
|
91
|
+
* installed anywhere above `cwd`.
|
|
92
|
+
*
|
|
93
|
+
* Null means one thing only: no `node_modules/<name>/package.json` exists on the
|
|
94
|
+
* way up. That is the ordinary "this project does not use Vue" answer, and the
|
|
95
|
+
* aliased-to-source answer, and neither is a fault.
|
|
96
|
+
*
|
|
97
|
+
* Everything else raises. Once a manifest exists at a level, the walk stops
|
|
98
|
+
* there whatever the file turns out to be — because that is the copy Node will
|
|
99
|
+
* load, and continuing upward would answer with a version belonging to a
|
|
100
|
+
* different installation. A file that cannot be read, cannot be parsed, or names
|
|
101
|
+
* no usable version is therefore a refusal rather than a shrug: this compiler is
|
|
102
|
+
* about to stamp a release number onto a document on the strength of it.
|
|
103
|
+
*/
|
|
104
|
+
function installedVersion(cwd, name) {
|
|
105
|
+
let directory = resolve(cwd);
|
|
106
|
+
for (;;) {
|
|
107
|
+
const manifest = join(directory, "node_modules", ...name.split("/"), "package.json");
|
|
108
|
+
let text;
|
|
109
|
+
try {
|
|
110
|
+
text = readFileSync(manifest, "utf8");
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error.code !== "ENOENT") throw new ProducerManifestError(name, manifest, error.message);
|
|
113
|
+
const parent = dirname(directory);
|
|
114
|
+
if (parent === directory) return null;
|
|
115
|
+
directory = parent;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
let version;
|
|
119
|
+
try {
|
|
120
|
+
version = JSON.parse(text).version;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
throw new ProducerManifestError(name, manifest, `its package.json is not valid JSON (${error.message})`);
|
|
123
|
+
}
|
|
124
|
+
if (typeof version !== "string" || version.trim() === "") throw new ProducerManifestError(name, manifest, `its package.json declares version ${JSON.stringify(version)}, which names no release`);
|
|
125
|
+
return version;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Refuse to compile when a producing package is a different release from this
|
|
130
|
+
* compiler.
|
|
131
|
+
*
|
|
132
|
+
* Called once per compile run, before any document is rendered, so the failure
|
|
133
|
+
* arrives as one message about the installation rather than as a stamping error
|
|
134
|
+
* per document.
|
|
135
|
+
*/
|
|
136
|
+
function assertProducersAgree(cwd, compilerSdk = sdkVersion) {
|
|
137
|
+
const disagreeing = resolveProducers(cwd).filter((producer) => producer.version !== compilerSdk);
|
|
138
|
+
if (disagreeing.length > 0) throw new ProducerAgreementError(compilerSdk, disagreeing);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
export { PRODUCING_PACKAGES, ProducerAgreementError, ProducerManifestError, assertProducersAgree, resolveProducers };
|
|
143
|
+
//# sourceMappingURL=producer-agreement.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"producer-agreement.mjs","names":["found: ResolvedProducer[]","text: string","version: unknown"],"sources":["../../../src/server/compile/producer-agreement.ts"],"sourcesContent":["/**\n * Check that every installed Format package that produces documents is on the\n * same release as this compiler.\n *\n * The compiler stamps `data-sdk` with its own version, but React or Vue rendered\n * the markup. If they are on a different version that stamp is wrong, so this\n * refuses before anything renders and names the packages to fix.\n *\n * It finds each package by walking up `node_modules` and reading the first\n * `package.json` it hits, which is the copy Node would load. It does not use\n * `require.resolve`: under vitest that resolves to this workspace's own source,\n * so a test for \"not installed\" would pass by finding the repo it runs in.\n *\n * A package that is not installed is fine — a React project has no Vue, and a\n * build that aliases an SDK to source has no manifest to read. A `package.json`\n * that exists but will not parse is not fine: the walk stops there rather than\n * carrying on up and reporting some other installation's version as this one's.\n *\n * `finalize-document-html` checks again at render time, comparing the `data-sdk`\n * already on the markup against this compiler's. That catches what this cannot\n * see, such as Yarn PnP, where there is no `node_modules` tree to walk.\n */\n\nimport { readFileSync } from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\n\nimport { sdkVersion } from './producer-release'\n\n/**\n * The packages that produce document markup this compiler then stamps.\n *\n * Only these. `@format.dev/zip`, `@format.dev/fonts` and the rest move on the\n * same release number and are checked by the lockstep warning, but none of them\n * writes markup, so none of them can make a document's provenance wrong.\n */\nexport const PRODUCING_PACKAGES = ['@format.dev/react', '@format.dev/vue'] as const\n\n/** One producing package, as it resolves from the project being compiled. */\nexport interface ResolvedProducer {\n\tname: string\n\tversion: string\n}\n\n/**\n * A producing package is installed and its version cannot be established.\n *\n * Separate from disagreement because it is a different fact: nothing has been\n * shown to disagree, and nothing has been shown to agree either. The reason it\n * stops the compile anyway is that this module exists to make one claim\n * honest — that the release number about to be stamped on a document is the\n * release that produced it — and a package whose version is unreadable is\n * exactly the case where that claim cannot be made.\n *\n * Only a package that is absent is silence. Absent is an ordinary state with an\n * ordinary meaning: a project that uses React never installed Vue, or a build\n * aliased an SDK to source. A manifest that exists and will not parse is neither\n * of those, and reading past it to a copy in a parent directory would be worse\n * than failing — it would report a version belonging to an installation that is\n * not the one Node will load.\n */\nexport class ProducerManifestError extends Error {\n\treadonly name = 'ProducerManifestError'\n\n\tconstructor(packageName: string, manifest: string, problem: string) {\n\t\tsuper(\n\t\t\t`Format cannot read which version of ${packageName} is installed:\\n\\n ${manifest}\\n ${problem}\\n\\n` +\n\t\t\t\t'That package produces document markup and Format stamps the release that produced it onto every ' +\n\t\t\t\t'document, so a version it cannot establish is one it cannot honestly write down. Nothing was ' +\n\t\t\t\t'compiled. Reinstall your dependencies — `format update` brings every @format.dev/* package to one ' +\n\t\t\t\t'version.'\n\t\t)\n\t}\n}\n\nexport class ProducerAgreementError extends Error {\n\treadonly compilerSdk: string\n\treadonly disagreeing: ResolvedProducer[]\n\n\tconstructor(compilerSdk: string, disagreeing: ResolvedProducer[]) {\n\t\tconst listed = disagreeing.map(producer => ` ${producer.name} ${producer.version}`).join('\\n')\n\n\t\tsuper(\n\t\t\t`Format ${compilerSdk} is compiling, and these packages are a different release:\\n\\n${listed}\\n\\n` +\n\t\t\t\t'A document would be stamped as one release having produced work from two, so nothing was ' +\n\t\t\t\t'compiled. Bring every @format.dev/* package to one version — `format update` does it.'\n\t\t)\n\n\t\tthis.name = 'ProducerAgreementError'\n\t\tthis.compilerSdk = compilerSdk\n\t\tthis.disagreeing = disagreeing\n\t}\n}\n\n/**\n * The producing packages that resolve from `cwd`, with the versions that will\n * actually run.\n *\n * Exported so a test can see what resolution found without inferring it from\n * whether a throw happened.\n */\nexport function resolveProducers(cwd: string, packages: readonly string[] = PRODUCING_PACKAGES): ResolvedProducer[] {\n\tconst found: ResolvedProducer[] = []\n\n\tfor (const name of packages) {\n\t\tconst version = installedVersion(cwd, name)\n\n\t\tif (version !== null) {\n\t\t\tfound.push({ name, version })\n\t\t}\n\t}\n\n\treturn found\n}\n\n/**\n * The version of `name` this project would load, or null when it is not\n * installed anywhere above `cwd`.\n *\n * Null means one thing only: no `node_modules/<name>/package.json` exists on the\n * way up. That is the ordinary \"this project does not use Vue\" answer, and the\n * aliased-to-source answer, and neither is a fault.\n *\n * Everything else raises. Once a manifest exists at a level, the walk stops\n * there whatever the file turns out to be — because that is the copy Node will\n * load, and continuing upward would answer with a version belonging to a\n * different installation. A file that cannot be read, cannot be parsed, or names\n * no usable version is therefore a refusal rather than a shrug: this compiler is\n * about to stamp a release number onto a document on the strength of it.\n */\nfunction installedVersion(cwd: string, name: string): string | null {\n\tlet directory = resolve(cwd)\n\n\tfor (;;) {\n\t\tconst manifest = join(directory, 'node_modules', ...name.split('/'), 'package.json')\n\n\t\tlet text: string\n\t\ttry {\n\t\t\ttext = readFileSync(manifest, 'utf8')\n\t\t} catch (error) {\n\t\t\t// Absent here, so look higher. Anything else — a directory in the way, a\n\t\t\t// file the process may not read — is a broken installation of a package\n\t\t\t// that is present, and reading past it would attribute a parent's version\n\t\t\t// to it.\n\t\t\tif ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\n\t\t\t\tthrow new ProducerManifestError(name, manifest, (error as Error).message)\n\t\t\t}\n\n\t\t\tconst parent = dirname(directory)\n\t\t\t// `dirname` of the root is the root, which is how the walk ends.\n\t\t\tif (parent === directory) return null\n\n\t\t\tdirectory = parent\n\t\t\tcontinue\n\t\t}\n\n\t\tlet version: unknown\n\t\ttry {\n\t\t\tversion = (JSON.parse(text) as { version?: unknown }).version\n\t\t} catch (error) {\n\t\t\tthrow new ProducerManifestError(\n\t\t\t\tname,\n\t\t\t\tmanifest,\n\t\t\t\t`its package.json is not valid JSON (${(error as Error).message})`\n\t\t\t)\n\t\t}\n\n\t\tif (typeof version !== 'string' || version.trim() === '') {\n\t\t\tthrow new ProducerManifestError(\n\t\t\t\tname,\n\t\t\t\tmanifest,\n\t\t\t\t`its package.json declares version ${JSON.stringify(version)}, which names no release`\n\t\t\t)\n\t\t}\n\n\t\treturn version\n\t}\n}\n\n/**\n * Refuse to compile when a producing package is a different release from this\n * compiler.\n *\n * Called once per compile run, before any document is rendered, so the failure\n * arrives as one message about the installation rather than as a stamping error\n * per document.\n */\nexport function assertProducersAgree(cwd: string, compilerSdk: string = sdkVersion): void {\n\tconst disagreeing = resolveProducers(cwd).filter(producer => producer.version !== compilerSdk)\n\n\tif (disagreeing.length > 0) {\n\t\tthrow new ProducerAgreementError(compilerSdk, disagreeing)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,qBAAqB,CAAC,qBAAqB,kBAAkB;;;;;;;;;;;;;;;;;;AAyB1E,IAAa,wBAAb,cAA2C,MAAM;CAGhD,YAAY,aAAqB,UAAkB,SAAiB;AACnE,QACC,uCAAuC,YAAY,sBAAsB,SAAS,MAAM,QAAQ,+SAKhG;wBATO,QAAO;;;AAajB,IAAa,yBAAb,cAA4C,MAAM;CAIjD,YAAY,aAAqB,aAAiC;EACjE,MAAM,SAAS,YAAY,KAAI,aAAY,KAAK,SAAS,KAAK,IAAI,SAAS,UAAU,CAAC,KAAK,KAAK;AAEhG,QACC,UAAU,YAAY,gEAAgE,OAAO,sLAG7F;wBAVO;wBACA;AAWR,OAAK,OAAO;AACZ,OAAK,cAAc;AACnB,OAAK,cAAc;;;;;;;;;;AAWrB,SAAgB,iBAAiB,KAAa,WAA8B,oBAAwC;CACnH,MAAMA,QAA4B,EAAE;AAEpC,MAAK,MAAM,QAAQ,UAAU;EAC5B,MAAM,UAAU,iBAAiB,KAAK,KAAK;AAE3C,MAAI,YAAY,KACf,OAAM,KAAK;GAAE;GAAM;GAAS,CAAC;;AAI/B,QAAO;;;;;;;;;;;;;;;;;AAkBR,SAAS,iBAAiB,KAAa,MAA6B;CACnE,IAAI,YAAY,QAAQ,IAAI;AAE5B,UAAS;EACR,MAAM,WAAW,KAAK,WAAW,gBAAgB,GAAG,KAAK,MAAM,IAAI,EAAE,eAAe;EAEpF,IAAIC;AACJ,MAAI;AACH,UAAO,aAAa,UAAU,OAAO;WAC7B,OAAO;AAKf,OAAK,MAAgC,SAAS,SAC7C,OAAM,IAAI,sBAAsB,MAAM,UAAW,MAAgB,QAAQ;GAG1E,MAAM,SAAS,QAAQ,UAAU;AAEjC,OAAI,WAAW,UAAW,QAAO;AAEjC,eAAY;AACZ;;EAGD,IAAIC;AACJ,MAAI;AACH,aAAW,KAAK,MAAM,KAAK,CAA2B;WAC9C,OAAO;AACf,SAAM,IAAI,sBACT,MACA,UACA,uCAAwC,MAAgB,QAAQ,GAChE;;AAGF,MAAI,OAAO,YAAY,YAAY,QAAQ,MAAM,KAAK,GACrD,OAAM,IAAI,sBACT,MACA,UACA,qCAAqC,KAAK,UAAU,QAAQ,CAAC,0BAC7D;AAGF,SAAO;;;;;;;;;;;AAYT,SAAgB,qBAAqB,KAAa,cAAsB,YAAkB;CACzF,MAAM,cAAc,iBAAiB,IAAI,CAAC,QAAO,aAAY,SAAS,YAAY,YAAY;AAE9F,KAAI,YAAY,SAAS,EACxB,OAAM,IAAI,uBAAuB,aAAa,YAAY"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/server/compile/producer-release.d.ts
|
|
2
|
+
declare const sdkVersion: string;
|
|
3
|
+
declare const engineTarget: string;
|
|
4
|
+
/**
|
|
5
|
+
* The `define` entries a renderer build needs so its output names both the
|
|
6
|
+
* release that produced it and the engine it targets.
|
|
7
|
+
*
|
|
8
|
+
* Two spellings of each number, because a renderer bundle holds two kinds of
|
|
9
|
+
* code. The compiled wrapper reads `_FMT_JS_VERSION_` and
|
|
10
|
+
* `_FMT_ENGINE_VERSION_`; an SDK bundled from source rather than installed
|
|
11
|
+
* reads `FORMAT_JS_VERSION` and `FORMAT_ENGINE_TARGET`, whose own build-time
|
|
12
|
+
* substitution never ran. All four come from here, so a single document cannot
|
|
13
|
+
* carry two answers to either question — and in particular an SDK aliased to
|
|
14
|
+
* source can never disagree with the wrapper that finalises its output.
|
|
15
|
+
*/
|
|
16
|
+
declare function producerDefines(sdk?: string, engine?: string): Record<string, string>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { engineTarget, producerDefines, sdkVersion };
|
|
19
|
+
//# sourceMappingURL=producer-release.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"producer-release.d.mts","names":[],"sources":["../../../src/server/compile/producer-release.ts"],"sourcesContent":[],"mappings":";cAiBa;AAAA,cAEA,YAFsC,EAAA,MAAA;AAEnD;AAcA;;;;;;;;;;;iBAAgB,eAAA,iCAA0E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/server/compile/producer-release.ts
|
|
2
|
+
const sdkVersion = "0.1.0";
|
|
3
|
+
const engineTarget = "0.1.0";
|
|
4
|
+
/**
|
|
5
|
+
* The `define` entries a renderer build needs so its output names both the
|
|
6
|
+
* release that produced it and the engine it targets.
|
|
7
|
+
*
|
|
8
|
+
* Two spellings of each number, because a renderer bundle holds two kinds of
|
|
9
|
+
* code. The compiled wrapper reads `_FMT_JS_VERSION_` and
|
|
10
|
+
* `_FMT_ENGINE_VERSION_`; an SDK bundled from source rather than installed
|
|
11
|
+
* reads `FORMAT_JS_VERSION` and `FORMAT_ENGINE_TARGET`, whose own build-time
|
|
12
|
+
* substitution never ran. All four come from here, so a single document cannot
|
|
13
|
+
* carry two answers to either question — and in particular an SDK aliased to
|
|
14
|
+
* source can never disagree with the wrapper that finalises its output.
|
|
15
|
+
*/
|
|
16
|
+
function producerDefines(sdk = sdkVersion, engine = engineTarget) {
|
|
17
|
+
return {
|
|
18
|
+
_FMT_JS_VERSION_: JSON.stringify(sdk),
|
|
19
|
+
_FMT_ENGINE_VERSION_: JSON.stringify(engine),
|
|
20
|
+
FORMAT_JS_VERSION: JSON.stringify(sdk),
|
|
21
|
+
FORMAT_ENGINE_TARGET: JSON.stringify(engine)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { engineTarget, producerDefines, sdkVersion };
|
|
27
|
+
//# sourceMappingURL=producer-release.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"producer-release.mjs","names":["sdkVersion: string","engineTarget: string"],"sources":["../../../src/server/compile/producer-release.ts"],"sourcesContent":["// The two release numbers this compiler stamps into every document it produces.\n//\n// `sdkVersion` is J, the Format release the compiler itself belongs to, written\n// as `data-sdk`. It names the toolchain that produced the markup.\n// `engineTarget` is E, the released engine that release targets, written as\n// `data-engine`. It names the engine that must lay the document out.\n//\n// Documents authored as HTML have no SDK to stamp them, so this is their only\n// source of either. A document an SDK did stamp is checked against these two\n// rather than relabelled — see ./finalize-document-html.\n//\n// The build supplies `FORMAT_JS_VERSION` and `FORMAT_ENGINE_TARGET`. Both have\n// to arrive as free identifiers, because `define` substitutes those and not\n// import bindings; see build/release/README.md.\ndeclare const FORMAT_JS_VERSION: string\ndeclare const FORMAT_ENGINE_TARGET: string\n\nexport const sdkVersion: string = FORMAT_JS_VERSION\n\nexport const engineTarget: string = FORMAT_ENGINE_TARGET\n\n/**\n * The `define` entries a renderer build needs so its output names both the\n * release that produced it and the engine it targets.\n *\n * Two spellings of each number, because a renderer bundle holds two kinds of\n * code. The compiled wrapper reads `_FMT_JS_VERSION_` and\n * `_FMT_ENGINE_VERSION_`; an SDK bundled from source rather than installed\n * reads `FORMAT_JS_VERSION` and `FORMAT_ENGINE_TARGET`, whose own build-time\n * substitution never ran. All four come from here, so a single document cannot\n * carry two answers to either question — and in particular an SDK aliased to\n * source can never disagree with the wrapper that finalises its output.\n */\nexport function producerDefines(sdk: string = sdkVersion, engine: string = engineTarget): Record<string, string> {\n\treturn {\n\t\t_FMT_JS_VERSION_: JSON.stringify(sdk),\n\t\t_FMT_ENGINE_VERSION_: JSON.stringify(engine),\n\t\tFORMAT_JS_VERSION: JSON.stringify(sdk),\n\t\tFORMAT_ENGINE_TARGET: JSON.stringify(engine)\n\t}\n}\n"],"mappings":";AAiBA,MAAaA;AAEb,MAAaC;;;;;;;;;;;;;AAcb,SAAgB,gBAAgB,MAAc,YAAY,SAAiB,cAAsC;AAChH,QAAO;EACN,kBAAkB,KAAK,UAAU,IAAI;EACrC,sBAAsB,KAAK,UAAU,OAAO;EAC5C,mBAAmB,KAAK,UAAU,IAAI;EACtC,sBAAsB,KAAK,UAAU,OAAO;EAC5C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CompileError } from "../errors.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/server/compile/render-error.d.ts
|
|
4
|
+
declare const DOCUMENT_RENDER_FAILED_CODE = "DOCUMENT_RENDER_FAILED";
|
|
5
|
+
/**
|
|
6
|
+
* Whether a render failure is an asset mismatch (the rendered HTML referenced
|
|
7
|
+
* assets the bundle cannot supply). Checked via the `code` field rather than
|
|
8
|
+
* `instanceof` because the class is lost crossing the render worker's IPC
|
|
9
|
+
* boundary — only the serialized fields survive.
|
|
10
|
+
*/
|
|
11
|
+
declare function isAssetMismatchFailure(error: unknown): boolean;
|
|
12
|
+
interface DocumentRenderErrorArgs {
|
|
13
|
+
documentName: string;
|
|
14
|
+
variant: string;
|
|
15
|
+
cause: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A per-document render failure inside a compile. Multi-document builds throw
|
|
19
|
+
* this so the error itself names the document (and variant) that broke, and an
|
|
20
|
+
* asset mismatch reads differently from a crash in the document's component.
|
|
21
|
+
*
|
|
22
|
+
* The cause's asset lists are copied onto this error because consumers (e.g.
|
|
23
|
+
* the download middleware) read `missing`/`brokenRemote` structurally off
|
|
24
|
+
* whatever a failed compile throws.
|
|
25
|
+
*/
|
|
26
|
+
declare class DocumentRenderError extends CompileError {
|
|
27
|
+
readonly documentName: string;
|
|
28
|
+
readonly variant: string;
|
|
29
|
+
missing?: string[];
|
|
30
|
+
known?: string[];
|
|
31
|
+
remoteRefs?: string[];
|
|
32
|
+
brokenRemote?: string[];
|
|
33
|
+
constructor(args: DocumentRenderErrorArgs);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { DOCUMENT_RENDER_FAILED_CODE, DocumentRenderError, DocumentRenderErrorArgs, isAssetMismatchFailure };
|
|
37
|
+
//# sourceMappingURL=render-error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-error.d.mts","names":[],"sources":["../../../src/server/compile/render-error.ts"],"sourcesContent":[],"mappings":";;;cAEa,2BAAA;;AAAb;AAkBA;AAMA;AAeA;;iBArBgB,sBAAA;UAMC,uBAAA;;;;;;;;;;;;;;cAeJ,mBAAA,SAA4B,YAAA;;;;;;;oBAQtB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { CompileError } from "../errors.mjs";
|
|
2
|
+
import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/server/compile/render-error.ts
|
|
5
|
+
const DOCUMENT_RENDER_FAILED_CODE = "DOCUMENT_RENDER_FAILED";
|
|
6
|
+
function readStringArray(source, key) {
|
|
7
|
+
const value = source?.[key];
|
|
8
|
+
if (!Array.isArray(value)) return;
|
|
9
|
+
return value.filter((item) => typeof item === "string");
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether a render failure is an asset mismatch (the rendered HTML referenced
|
|
13
|
+
* assets the bundle cannot supply). Checked via the `code` field rather than
|
|
14
|
+
* `instanceof` because the class is lost crossing the render worker's IPC
|
|
15
|
+
* boundary — only the serialized fields survive.
|
|
16
|
+
*/
|
|
17
|
+
function isAssetMismatchFailure(error) {
|
|
18
|
+
return error?.code === "ASSET_MISMATCH";
|
|
19
|
+
}
|
|
20
|
+
const failureMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
21
|
+
/**
|
|
22
|
+
* A per-document render failure inside a compile. Multi-document builds throw
|
|
23
|
+
* this so the error itself names the document (and variant) that broke, and an
|
|
24
|
+
* asset mismatch reads differently from a crash in the document's component.
|
|
25
|
+
*
|
|
26
|
+
* The cause's asset lists are copied onto this error because consumers (e.g.
|
|
27
|
+
* the download middleware) read `missing`/`brokenRemote` structurally off
|
|
28
|
+
* whatever a failed compile throws.
|
|
29
|
+
*/
|
|
30
|
+
var DocumentRenderError = class extends CompileError {
|
|
31
|
+
constructor(args) {
|
|
32
|
+
const { documentName, variant, cause } = args;
|
|
33
|
+
const isAssetMismatch = isAssetMismatchFailure(cause);
|
|
34
|
+
super({
|
|
35
|
+
code: DOCUMENT_RENDER_FAILED_CODE,
|
|
36
|
+
message: `Document "${documentName}" (variant "${variant}") failed to render: ${isAssetMismatch ? "the rendered HTML references assets the bundle cannot supply" : "the document threw while rendering"}.\n\n${failureMessage(cause)}`,
|
|
37
|
+
cause
|
|
38
|
+
});
|
|
39
|
+
_defineProperty(this, "documentName", void 0);
|
|
40
|
+
_defineProperty(this, "variant", void 0);
|
|
41
|
+
this.name = "DocumentRenderError";
|
|
42
|
+
this.documentName = documentName;
|
|
43
|
+
this.variant = variant;
|
|
44
|
+
if (isAssetMismatch) {
|
|
45
|
+
this.missing = readStringArray(cause, "missing");
|
|
46
|
+
this.known = readStringArray(cause, "known");
|
|
47
|
+
this.remoteRefs = readStringArray(cause, "remoteRefs");
|
|
48
|
+
this.brokenRemote = readStringArray(cause, "brokenRemote");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { DOCUMENT_RENDER_FAILED_CODE, DocumentRenderError, isAssetMismatchFailure };
|
|
55
|
+
//# sourceMappingURL=render-error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-error.mjs","names":[],"sources":["../../../src/server/compile/render-error.ts"],"sourcesContent":["import { CompileError } from '../errors'\n\nexport const DOCUMENT_RENDER_FAILED_CODE = 'DOCUMENT_RENDER_FAILED'\n\nfunction readStringArray(source: unknown, key: string): string[] | undefined {\n\tconst value = (source as Record<string, unknown> | null)?.[key]\n\n\tif (!Array.isArray(value)) {\n\t\treturn undefined\n\t}\n\n\treturn value.filter((item): item is string => typeof item === 'string')\n}\n\n/**\n * Whether a render failure is an asset mismatch (the rendered HTML referenced\n * assets the bundle cannot supply). Checked via the `code` field rather than\n * `instanceof` because the class is lost crossing the render worker's IPC\n * boundary — only the serialized fields survive.\n */\nexport function isAssetMismatchFailure(error: unknown): boolean {\n\treturn (error as { code?: unknown } | null)?.code === 'ASSET_MISMATCH'\n}\n\nconst failureMessage = (error: unknown) => (error instanceof Error ? error.message : String(error))\n\nexport interface DocumentRenderErrorArgs {\n\tdocumentName: string\n\tvariant: string\n\tcause: unknown\n}\n\n/**\n * A per-document render failure inside a compile. Multi-document builds throw\n * this so the error itself names the document (and variant) that broke, and an\n * asset mismatch reads differently from a crash in the document's component.\n *\n * The cause's asset lists are copied onto this error because consumers (e.g.\n * the download middleware) read `missing`/`brokenRemote` structurally off\n * whatever a failed compile throws.\n */\nexport class DocumentRenderError extends CompileError {\n\treadonly documentName: string\n\treadonly variant: string\n\tdeclare missing?: string[]\n\tdeclare known?: string[]\n\tdeclare remoteRefs?: string[]\n\tdeclare brokenRemote?: string[]\n\n\tconstructor(args: DocumentRenderErrorArgs) {\n\t\tconst { documentName, variant, cause } = args\n\n\t\tconst isAssetMismatch = isAssetMismatchFailure(cause)\n\t\tconst reason = isAssetMismatch\n\t\t\t? 'the rendered HTML references assets the bundle cannot supply'\n\t\t\t: 'the document threw while rendering'\n\n\t\tsuper({\n\t\t\tcode: DOCUMENT_RENDER_FAILED_CODE,\n\t\t\tmessage: `Document \"${documentName}\" (variant \"${variant}\") failed to render: ${reason}.\\n\\n${failureMessage(cause)}`,\n\t\t\tcause\n\t\t})\n\n\t\tthis.name = 'DocumentRenderError'\n\t\tthis.documentName = documentName\n\t\tthis.variant = variant\n\n\t\tif (isAssetMismatch) {\n\t\t\tthis.missing = readStringArray(cause, 'missing')\n\t\t\tthis.known = readStringArray(cause, 'known')\n\t\t\tthis.remoteRefs = readStringArray(cause, 'remoteRefs')\n\t\t\tthis.brokenRemote = readStringArray(cause, 'brokenRemote')\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAEA,MAAa,8BAA8B;AAE3C,SAAS,gBAAgB,QAAiB,KAAmC;CAC5E,MAAM,QAAS,SAA4C;AAE3D,KAAI,CAAC,MAAM,QAAQ,MAAM,CACxB;AAGD,QAAO,MAAM,QAAQ,SAAyB,OAAO,SAAS,SAAS;;;;;;;;AASxE,SAAgB,uBAAuB,OAAyB;AAC/D,QAAQ,OAAqC,SAAS;;AAGvD,MAAM,kBAAkB,UAAoB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;;;;;;;;;;AAiBlG,IAAa,sBAAb,cAAyC,aAAa;CAQrD,YAAY,MAA+B;EAC1C,MAAM,EAAE,cAAc,SAAS,UAAU;EAEzC,MAAM,kBAAkB,uBAAuB,MAAM;AAKrD,QAAM;GACL,MAAM;GACN,SAAS,aAAa,aAAa,cAAc,QAAQ,uBAN3C,kBACZ,iEACA,qCAIqF,OAAO,eAAe,MAAM;GACnH;GACA,CAAC;wBAnBM;wBACA;AAoBR,OAAK,OAAO;AACZ,OAAK,eAAe;AACpB,OAAK,UAAU;AAEf,MAAI,iBAAiB;AACpB,QAAK,UAAU,gBAAgB,OAAO,UAAU;AAChD,QAAK,QAAQ,gBAAgB,OAAO,QAAQ;AAC5C,QAAK,aAAa,gBAAgB,OAAO,aAAa;AACtD,QAAK,eAAe,gBAAgB,OAAO,eAAe"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/server/compile/sanitize/shared.d.ts
|
|
2
|
+
type HastNode = {
|
|
3
|
+
type: string;
|
|
4
|
+
tagName?: string;
|
|
5
|
+
properties?: Record<string, unknown>;
|
|
6
|
+
children?: HastNode[];
|
|
7
|
+
content?: HastNode;
|
|
8
|
+
};
|
|
9
|
+
declare function isDangerousUrl(value: string): boolean;
|
|
10
|
+
declare function stripDangerousUrls(node: HastNode, onStrip?: () => void): void;
|
|
11
|
+
declare function buildObservedSchema(defaultSchema: any, tree: HastNode, keepUnknownTags?: boolean): any;
|
|
12
|
+
declare function templateContentToChildren(node: HastNode): void;
|
|
13
|
+
declare function templateChildrenToContent(node: HastNode): void;
|
|
14
|
+
declare function parseHtmlFragment(html: string): HastNode;
|
|
15
|
+
declare function stringifyHtmlFragment(tree: HastNode): string;
|
|
16
|
+
declare function removeTags(node: HastNode, forbiddenTags: Set<string>, onRemove?: (tag: string) => void): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { HastNode, buildObservedSchema, isDangerousUrl, parseHtmlFragment, removeTags, stringifyHtmlFragment, stripDangerousUrls, templateChildrenToContent, templateContentToChildren };
|
|
19
|
+
//# sourceMappingURL=shared.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.mts","names":[],"sources":["../../../../src/server/compile/sanitize/shared.ts"],"sourcesContent":[],"mappings":";KAOY,QAAA;EAAA,IAAA,EAAA,MAAQ;EAGN,OAAA,CAAA,EAAA,MAAA;EACF,UAAA,CAAA,EADE,MACF,CAAA,MAAA,EAAA,OAAA,CAAA;EACD,QAAA,CAAA,EADC,QACD,EAAA;EAAQ,OAAA,CAAA,EAAR,QAAQ;AAcnB,CAAA;AAUgB,iBAVA,cAAA,CAUyB,KAAA,EAAA,MAAQ,CAAA,EAAA,OAAA;AA4CjC,iBA5CA,kBAAA,CA4C8C,IAAA,EA5CrB,QA4C6B,EAAA,OAAA,CAAA,EAAA,GAAA,GAAA,IAAA,CAAA,EAAA,IAAA;AAgDtD,iBAhDA,mBAAA,CAgDyB,aAAe,EAAA,GAAA,EAAA,IAAA,EAhDM,QAgDN,EAAA,eAAA,CAAA,EAAA,OAAA,CAAA,EAAA,GAAA;AAWxC,iBAXA,yBAAA,CAWgC,IAAQ,EAXR,QAWQ,CAAA,EAAA,IAAA;AAmBxC,iBAnBA,yBAAA,CAmByC,IAAA,EAnBT,QAmBS,CAAA,EAAA,IAAA;AAOzC,iBAPA,iBAAA,CAO4B,IAAA,EAAA,MAAQ,CAAA,EAPH,QAOG;AAQpC,iBARA,qBAAA,CAQ6C,IAAA,EARjB,QAQiB,CAAA,EAAA,MAAA;iBAA7C,UAAA,OAAiB,yBAAyB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { parseFragment } from "parse5";
|
|
2
|
+
import { unified } from "unified";
|
|
3
|
+
import rehypeStringify from "rehype-stringify";
|
|
4
|
+
import { fromParse5 } from "hast-util-from-parse5";
|
|
5
|
+
|
|
6
|
+
//#region src/server/compile/sanitize/shared.ts
|
|
7
|
+
function isDangerousProperty(key) {
|
|
8
|
+
const lower = key.toLowerCase();
|
|
9
|
+
return lower.startsWith("on") || lower === "srcdoc";
|
|
10
|
+
}
|
|
11
|
+
const DANGEROUS_URL_SCHEMES = [
|
|
12
|
+
"javascript:",
|
|
13
|
+
"vbscript:",
|
|
14
|
+
"data:",
|
|
15
|
+
"file:",
|
|
16
|
+
"blob:"
|
|
17
|
+
];
|
|
18
|
+
const NAVIGATIONAL_URL_PROPS = ["href", "xlinkhref"];
|
|
19
|
+
function isDangerousUrl(value) {
|
|
20
|
+
const normalized = [...value].filter((ch) => ch.charCodeAt(0) > 32).join("").toLowerCase();
|
|
21
|
+
return DANGEROUS_URL_SCHEMES.some((scheme) => normalized.startsWith(scheme));
|
|
22
|
+
}
|
|
23
|
+
function stripDangerousUrls(node, onStrip) {
|
|
24
|
+
const props = node.properties;
|
|
25
|
+
if (props) for (const key of Object.keys(props)) {
|
|
26
|
+
const isNavigational = NAVIGATIONAL_URL_PROPS.includes(key.toLowerCase());
|
|
27
|
+
const value = props[key];
|
|
28
|
+
if (isNavigational && typeof value === "string" && isDangerousUrl(value)) {
|
|
29
|
+
delete props[key];
|
|
30
|
+
onStrip?.();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const child of node.children || []) stripDangerousUrls(child, onStrip);
|
|
34
|
+
}
|
|
35
|
+
function collectSchema(node, tagNames, attributes) {
|
|
36
|
+
if (node.type === "element" && node.tagName) {
|
|
37
|
+
const tag = node.tagName;
|
|
38
|
+
tagNames.add(tag);
|
|
39
|
+
const props = node.properties || {};
|
|
40
|
+
let set = attributes.get(tag);
|
|
41
|
+
if (!set) {
|
|
42
|
+
set = /* @__PURE__ */ new Set();
|
|
43
|
+
attributes.set(tag, set);
|
|
44
|
+
}
|
|
45
|
+
for (const key of Object.keys(props)) if (!isDangerousProperty(key)) set.add(key);
|
|
46
|
+
}
|
|
47
|
+
for (const child of node.children || []) collectSchema(child, tagNames, attributes);
|
|
48
|
+
}
|
|
49
|
+
function buildObservedSchema(defaultSchema, tree, keepUnknownTags = false) {
|
|
50
|
+
const tagNames = /* @__PURE__ */ new Set();
|
|
51
|
+
const attributesByTag = /* @__PURE__ */ new Map();
|
|
52
|
+
collectSchema(tree, tagNames, attributesByTag);
|
|
53
|
+
const mergedAttributes = { ...defaultSchema.attributes };
|
|
54
|
+
for (const [tag, attrs] of attributesByTag) {
|
|
55
|
+
const base = mergedAttributes[tag];
|
|
56
|
+
if (Array.isArray(base)) {
|
|
57
|
+
const filtered = base.filter((entry) => {
|
|
58
|
+
if (Array.isArray(entry) && typeof entry[0] === "string") return !attrs.has(entry[0]);
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
61
|
+
mergedAttributes[tag] = [...new Set([...filtered, ...attrs])];
|
|
62
|
+
} else mergedAttributes[tag] = [...attrs];
|
|
63
|
+
}
|
|
64
|
+
const ancestors = {};
|
|
65
|
+
const protocols = { ...defaultSchema.protocols };
|
|
66
|
+
delete protocols.href;
|
|
67
|
+
protocols.src = [...protocols.src ?? [], "data"];
|
|
68
|
+
return {
|
|
69
|
+
...defaultSchema,
|
|
70
|
+
clobber: [],
|
|
71
|
+
clobberPrefix: "",
|
|
72
|
+
tagNames: [...new Set([...defaultSchema.tagNames ?? [], ...tagNames])],
|
|
73
|
+
attributes: mergedAttributes,
|
|
74
|
+
ancestors,
|
|
75
|
+
protocols,
|
|
76
|
+
...keepUnknownTags ? { strip: [] } : {}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function templateContentToChildren(node) {
|
|
80
|
+
if (node.type === "element" && (node.tagName || "").toLowerCase() === "template" && node.content) {
|
|
81
|
+
node.children = Array.isArray(node.content.children) ? node.content.children : [];
|
|
82
|
+
delete node.content;
|
|
83
|
+
}
|
|
84
|
+
for (const child of node.children || []) templateContentToChildren(child);
|
|
85
|
+
}
|
|
86
|
+
function templateChildrenToContent(node) {
|
|
87
|
+
if (node.type === "element" && (node.tagName || "").toLowerCase() === "template") {
|
|
88
|
+
const kids = node.children || [];
|
|
89
|
+
node.children = [];
|
|
90
|
+
node.content = {
|
|
91
|
+
type: "root",
|
|
92
|
+
children: kids
|
|
93
|
+
};
|
|
94
|
+
for (const child of kids) templateChildrenToContent(child);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
for (const child of node.children || []) templateChildrenToContent(child);
|
|
98
|
+
}
|
|
99
|
+
function parseHtmlFragment(html) {
|
|
100
|
+
const tree = fromParse5(parseFragment(html, {
|
|
101
|
+
sourceCodeLocationInfo: false,
|
|
102
|
+
scriptingEnabled: false
|
|
103
|
+
}));
|
|
104
|
+
templateContentToChildren(tree);
|
|
105
|
+
return tree;
|
|
106
|
+
}
|
|
107
|
+
function stringifyHtmlFragment(tree) {
|
|
108
|
+
templateChildrenToContent(tree);
|
|
109
|
+
const out = unified().use(rehypeStringify, { allowDangerousHtml: false }).stringify(tree);
|
|
110
|
+
return String(out).trim();
|
|
111
|
+
}
|
|
112
|
+
function removeTags(node, forbiddenTags, onRemove) {
|
|
113
|
+
if (!node.children) return;
|
|
114
|
+
const next = [];
|
|
115
|
+
for (const child of node.children) {
|
|
116
|
+
if (child.type === "element") {
|
|
117
|
+
const tag = (child.tagName || "").toLowerCase();
|
|
118
|
+
if (forbiddenTags.has(tag)) {
|
|
119
|
+
onRemove?.(tag);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
next.push(child);
|
|
124
|
+
removeTags(child, forbiddenTags, onRemove);
|
|
125
|
+
}
|
|
126
|
+
node.children = next;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
export { buildObservedSchema, isDangerousUrl, parseHtmlFragment, removeTags, stringifyHtmlFragment, stripDangerousUrls, templateChildrenToContent, templateContentToChildren };
|
|
131
|
+
//# sourceMappingURL=shared.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.mjs","names":["mergedAttributes: Record<string, unknown>","next: HastNode[]"],"sources":["../../../../src/server/compile/sanitize/shared.ts"],"sourcesContent":["import { unified } from 'unified'\nimport rehypeStringify from 'rehype-stringify'\nimport { parseFragment } from 'parse5'\nimport { fromParse5 } from 'hast-util-from-parse5'\n\n// See SANITIZE.md in this directory for the design rationale and behavioural decisions.\n\nexport type HastNode = {\n\ttype: string\n\ttagName?: string\n\tproperties?: Record<string, unknown>\n\tchildren?: HastNode[]\n\tcontent?: HastNode\n}\n\nfunction isDangerousProperty(key: string): boolean {\n\tconst lower = key.toLowerCase()\n\treturn lower.startsWith('on') || lower === 'srcdoc'\n}\n\n// Schemes stripped from href/xlink:href (the link blocklist).\nconst DANGEROUS_URL_SCHEMES = ['javascript:', 'vbscript:', 'data:', 'file:', 'blob:']\n// Compared case-insensitively against hast property names — rehype produces\n// `xLinkHref` (capital L) for SVG `xlink:href`, so we normalise before matching.\nconst NAVIGATIONAL_URL_PROPS = ['href', 'xlinkhref']\n\nexport function isDangerousUrl(value: string): boolean {\n\t// Strip whitespace/control chars before testing the scheme — browsers ignore\n\t// them when resolving a URL, so `java\\tscript:` would otherwise slip through.\n\tconst normalized = [...value]\n\t\t.filter(ch => ch.charCodeAt(0) > 0x20)\n\t\t.join('')\n\t\t.toLowerCase()\n\treturn DANGEROUS_URL_SCHEMES.some(scheme => normalized.startsWith(scheme))\n}\n\nexport function stripDangerousUrls(node: HastNode, onStrip?: () => void) {\n\tconst props = node.properties\n\n\tif (props) {\n\t\tfor (const key of Object.keys(props)) {\n\t\t\tconst isNavigational = NAVIGATIONAL_URL_PROPS.includes(key.toLowerCase())\n\t\t\tconst value = props[key]\n\n\t\t\tif (isNavigational && typeof value === 'string' && isDangerousUrl(value)) {\n\t\t\t\tdelete props[key]\n\t\t\t\tonStrip?.()\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const child of node.children || []) {\n\t\tstripDangerousUrls(child, onStrip)\n\t}\n}\n\nfunction collectSchema(node: HastNode, tagNames: Set<string>, attributes: Map<string, Set<string>>) {\n\tif (node.type === 'element' && node.tagName) {\n\t\tconst tag = node.tagName\n\t\ttagNames.add(tag)\n\n\t\tconst props = node.properties || {}\n\t\tlet set = attributes.get(tag)\n\t\tif (!set) {\n\t\t\tset = new Set()\n\t\t\tattributes.set(tag, set)\n\t\t}\n\n\t\tfor (const key of Object.keys(props)) {\n\t\t\tif (!isDangerousProperty(key)) {\n\t\t\t\tset.add(key)\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const child of node.children || []) {\n\t\tcollectSchema(child, tagNames, attributes)\n\t}\n}\n\nexport function buildObservedSchema(defaultSchema: any, tree: HastNode, keepUnknownTags = false) {\n\tconst tagNames = new Set<string>()\n\tconst attributesByTag = new Map<string, Set<string>>()\n\tcollectSchema(tree, tagNames, attributesByTag)\n\n\tconst mergedAttributes: Record<string, unknown> = { ...(defaultSchema as any).attributes }\n\tfor (const [tag, attrs] of attributesByTag) {\n\t\tconst base = mergedAttributes[tag]\n\t\tif (Array.isArray(base)) {\n\t\t\t// When an observed attribute (unrestricted string) collides with a\n\t\t\t// defaultSchema tuple like ['className', 'specific-value'], the tuple\n\t\t\t// must be removed. hast-util-sanitize's findDefinition returns the\n\t\t\t// first match — if the restricted tuple comes first the unrestricted\n\t\t\t// string is never reached, silently dropping valid attribute values.\n\t\t\tconst filtered = base.filter((entry: unknown) => {\n\t\t\t\tif (Array.isArray(entry) && typeof entry[0] === 'string') {\n\t\t\t\t\treturn !attrs.has(entry[0])\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t})\n\t\t\tmergedAttributes[tag] = [...new Set([...filtered, ...attrs])]\n\t\t} else {\n\t\t\tmergedAttributes[tag] = [...attrs]\n\t\t}\n\t}\n\n\t// Parent-less fragments must survive, so the structural `ancestors` rule is off.\n\tconst ancestors = {}\n\n\tconst protocols = { ...(defaultSchema as any).protocols }\n\t// href is policed by stripDangerousUrls (a blocklist), not this whitelist.\n\tdelete protocols.href\n\t// Allow data: image sources.\n\tprotocols.src = [...(protocols.src ?? []), 'data']\n\n\treturn {\n\t\t...defaultSchema,\n\t\t// Keep stable IDs/names and avoid GitHub-style clobbering.\n\t\tclobber: [],\n\t\tclobberPrefix: '',\n\t\ttagNames: [...new Set([...((defaultSchema as any).tagNames ?? []), ...tagNames])],\n\t\tattributes: mergedAttributes,\n\t\tancestors,\n\t\tprotocols,\n\t\t...(keepUnknownTags ? { strip: [] } : {})\n\t}\n}\n\nexport function templateContentToChildren(node: HastNode) {\n\tif (node.type === 'element' && (node.tagName || '').toLowerCase() === 'template' && node.content) {\n\t\t// `rehype-sanitize` strips the non-standard `content` field.\n\t\t// Move it into `children` before sanitization.\n\t\tnode.children = Array.isArray(node.content.children) ? node.content.children : []\n\t\tdelete (node as any).content\n\t}\n\n\tfor (const child of node.children || []) templateContentToChildren(child)\n}\n\nexport function templateChildrenToContent(node: HastNode) {\n\tif (node.type === 'element' && (node.tagName || '').toLowerCase() === 'template') {\n\t\tconst kids = node.children || []\n\t\tnode.children = []\n\t\tnode.content = { type: 'root', children: kids }\n\t\tfor (const child of kids) templateChildrenToContent(child)\n\t\treturn\n\t}\n\n\tfor (const child of node.children || []) templateChildrenToContent(child)\n}\n\n// Parse with parse5 + hast-util-from-parse5 directly rather than through rehype-parse.\n// rehype-parse routes through hast-util-from-html, which always passes a VFile to\n// fromParse5, and fromParse5 with a `file` resolves every node's source offset to a\n// line/column point — quadratic on a large document (~12s here vs ~40ms without). We\n// never use source positions for sanitization, so skip the file and the location info\n// entirely. `scriptingEnabled: false` matches rehype-parse's template/noscript parsing,\n// so the resulting tree is unchanged.\nexport function parseHtmlFragment(html: string): HastNode {\n\tconst parsed = parseFragment(html, { sourceCodeLocationInfo: false, scriptingEnabled: false })\n\tconst tree = fromParse5(parsed) as unknown as HastNode\n\ttemplateContentToChildren(tree)\n\treturn tree\n}\n\nexport function stringifyHtmlFragment(tree: HastNode): string {\n\ttemplateChildrenToContent(tree)\n\tconst out = unified()\n\t\t.use(rehypeStringify, { allowDangerousHtml: false })\n\t\t.stringify(tree as any)\n\treturn String(out).trim()\n}\n\nexport function removeTags(node: HastNode, forbiddenTags: Set<string>, onRemove?: (tag: string) => void) {\n\tif (!node.children) return\n\n\tconst next: HastNode[] = []\n\tfor (const child of node.children) {\n\t\tif (child.type === 'element') {\n\t\t\tconst tag = (child.tagName || '').toLowerCase()\n\t\t\tif (forbiddenTags.has(tag)) {\n\t\t\t\tonRemove?.(tag)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\tnext.push(child)\n\t\tremoveTags(child, forbiddenTags, onRemove)\n\t}\n\n\tnode.children = next\n}\n"],"mappings":";;;;;;AAeA,SAAS,oBAAoB,KAAsB;CAClD,MAAM,QAAQ,IAAI,aAAa;AAC/B,QAAO,MAAM,WAAW,KAAK,IAAI,UAAU;;AAI5C,MAAM,wBAAwB;CAAC;CAAe;CAAa;CAAS;CAAS;CAAQ;AAGrF,MAAM,yBAAyB,CAAC,QAAQ,YAAY;AAEpD,SAAgB,eAAe,OAAwB;CAGtD,MAAM,aAAa,CAAC,GAAG,MAAM,CAC3B,QAAO,OAAM,GAAG,WAAW,EAAE,GAAG,GAAK,CACrC,KAAK,GAAG,CACR,aAAa;AACf,QAAO,sBAAsB,MAAK,WAAU,WAAW,WAAW,OAAO,CAAC;;AAG3E,SAAgB,mBAAmB,MAAgB,SAAsB;CACxE,MAAM,QAAQ,KAAK;AAEnB,KAAI,MACH,MAAK,MAAM,OAAO,OAAO,KAAK,MAAM,EAAE;EACrC,MAAM,iBAAiB,uBAAuB,SAAS,IAAI,aAAa,CAAC;EACzE,MAAM,QAAQ,MAAM;AAEpB,MAAI,kBAAkB,OAAO,UAAU,YAAY,eAAe,MAAM,EAAE;AACzE,UAAO,MAAM;AACb,cAAW;;;AAKd,MAAK,MAAM,SAAS,KAAK,YAAY,EAAE,CACtC,oBAAmB,OAAO,QAAQ;;AAIpC,SAAS,cAAc,MAAgB,UAAuB,YAAsC;AACnG,KAAI,KAAK,SAAS,aAAa,KAAK,SAAS;EAC5C,MAAM,MAAM,KAAK;AACjB,WAAS,IAAI,IAAI;EAEjB,MAAM,QAAQ,KAAK,cAAc,EAAE;EACnC,IAAI,MAAM,WAAW,IAAI,IAAI;AAC7B,MAAI,CAAC,KAAK;AACT,yBAAM,IAAI,KAAK;AACf,cAAW,IAAI,KAAK,IAAI;;AAGzB,OAAK,MAAM,OAAO,OAAO,KAAK,MAAM,CACnC,KAAI,CAAC,oBAAoB,IAAI,CAC5B,KAAI,IAAI,IAAI;;AAKf,MAAK,MAAM,SAAS,KAAK,YAAY,EAAE,CACtC,eAAc,OAAO,UAAU,WAAW;;AAI5C,SAAgB,oBAAoB,eAAoB,MAAgB,kBAAkB,OAAO;CAChG,MAAM,2BAAW,IAAI,KAAa;CAClC,MAAM,kCAAkB,IAAI,KAA0B;AACtD,eAAc,MAAM,UAAU,gBAAgB;CAE9C,MAAMA,mBAA4C,EAAE,GAAI,cAAsB,YAAY;AAC1F,MAAK,MAAM,CAAC,KAAK,UAAU,iBAAiB;EAC3C,MAAM,OAAO,iBAAiB;AAC9B,MAAI,MAAM,QAAQ,KAAK,EAAE;GAMxB,MAAM,WAAW,KAAK,QAAQ,UAAmB;AAChD,QAAI,MAAM,QAAQ,MAAM,IAAI,OAAO,MAAM,OAAO,SAC/C,QAAO,CAAC,MAAM,IAAI,MAAM,GAAG;AAE5B,WAAO;KACN;AACF,oBAAiB,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,UAAU,GAAG,MAAM,CAAC,CAAC;QAE7D,kBAAiB,OAAO,CAAC,GAAG,MAAM;;CAKpC,MAAM,YAAY,EAAE;CAEpB,MAAM,YAAY,EAAE,GAAI,cAAsB,WAAW;AAEzD,QAAO,UAAU;AAEjB,WAAU,MAAM,CAAC,GAAI,UAAU,OAAO,EAAE,EAAG,OAAO;AAElD,QAAO;EACN,GAAG;EAEH,SAAS,EAAE;EACX,eAAe;EACf,UAAU,CAAC,GAAG,IAAI,IAAI,CAAC,GAAK,cAAsB,YAAY,EAAE,EAAG,GAAG,SAAS,CAAC,CAAC;EACjF,YAAY;EACZ;EACA;EACA,GAAI,kBAAkB,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE;EACxC;;AAGF,SAAgB,0BAA0B,MAAgB;AACzD,KAAI,KAAK,SAAS,cAAc,KAAK,WAAW,IAAI,aAAa,KAAK,cAAc,KAAK,SAAS;AAGjG,OAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,SAAS,GAAG,KAAK,QAAQ,WAAW,EAAE;AACjF,SAAQ,KAAa;;AAGtB,MAAK,MAAM,SAAS,KAAK,YAAY,EAAE,CAAE,2BAA0B,MAAM;;AAG1E,SAAgB,0BAA0B,MAAgB;AACzD,KAAI,KAAK,SAAS,cAAc,KAAK,WAAW,IAAI,aAAa,KAAK,YAAY;EACjF,MAAM,OAAO,KAAK,YAAY,EAAE;AAChC,OAAK,WAAW,EAAE;AAClB,OAAK,UAAU;GAAE,MAAM;GAAQ,UAAU;GAAM;AAC/C,OAAK,MAAM,SAAS,KAAM,2BAA0B,MAAM;AAC1D;;AAGD,MAAK,MAAM,SAAS,KAAK,YAAY,EAAE,CAAE,2BAA0B,MAAM;;AAU1E,SAAgB,kBAAkB,MAAwB;CAEzD,MAAM,OAAO,WADE,cAAc,MAAM;EAAE,wBAAwB;EAAO,kBAAkB;EAAO,CAAC,CAC/D;AAC/B,2BAA0B,KAAK;AAC/B,QAAO;;AAGR,SAAgB,sBAAsB,MAAwB;AAC7D,2BAA0B,KAAK;CAC/B,MAAM,MAAM,SAAS,CACnB,IAAI,iBAAiB,EAAE,oBAAoB,OAAO,CAAC,CACnD,UAAU,KAAY;AACxB,QAAO,OAAO,IAAI,CAAC,MAAM;;AAG1B,SAAgB,WAAW,MAAgB,eAA4B,UAAkC;AACxG,KAAI,CAAC,KAAK,SAAU;CAEpB,MAAMC,OAAmB,EAAE;AAC3B,MAAK,MAAM,SAAS,KAAK,UAAU;AAClC,MAAI,MAAM,SAAS,WAAW;GAC7B,MAAM,OAAO,MAAM,WAAW,IAAI,aAAa;AAC/C,OAAI,cAAc,IAAI,IAAI,EAAE;AAC3B,eAAW,IAAI;AACf;;;AAIF,OAAK,KAAK,MAAM;AAChB,aAAW,OAAO,eAAe,SAAS;;AAG3C,MAAK,WAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize-html.d.mts","names":[],"sources":["../../../src/server/compile/sanitize-html.ts"],"sourcesContent":[],"mappings":";iBA8FgB,YAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { buildObservedSchema, parseHtmlFragment, stringifyHtmlFragment, stripDangerousUrls } from "./sanitize/shared.mjs";
|
|
2
|
+
import { FORBID_TAGS } from "@format.dev/utils";
|
|
3
|
+
import { unified } from "unified";
|
|
4
|
+
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
|
|
5
|
+
|
|
6
|
+
//#region src/server/compile/sanitize-html.ts
|
|
7
|
+
function isLocalHref(href) {
|
|
8
|
+
return !/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(href) && !href.startsWith("//");
|
|
9
|
+
}
|
|
10
|
+
function isForbiddenUrl(value) {
|
|
11
|
+
return value.trim().toLowerCase().startsWith("javascript:");
|
|
12
|
+
}
|
|
13
|
+
function isStylesheetLink(properties) {
|
|
14
|
+
const rel = properties.rel;
|
|
15
|
+
const href = typeof properties.href === "string" ? properties.href : "";
|
|
16
|
+
const isStylesheet = (Array.isArray(rel) ? rel : typeof rel === "string" ? rel.split(/\s+/) : []).some((v) => String(v).toLowerCase() === "stylesheet");
|
|
17
|
+
const isCssHref = href.toLowerCase().includes(".css");
|
|
18
|
+
return {
|
|
19
|
+
href,
|
|
20
|
+
ok: isStylesheet && isCssHref && isLocalHref(href)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function stripDangerousProperties(properties) {
|
|
24
|
+
for (const key of Object.keys(properties)) if (key.toLowerCase().startsWith("on")) delete properties[key];
|
|
25
|
+
delete properties.srcdoc;
|
|
26
|
+
for (const key of [
|
|
27
|
+
"href",
|
|
28
|
+
"src",
|
|
29
|
+
"xlinkHref"
|
|
30
|
+
]) {
|
|
31
|
+
const value = properties[key];
|
|
32
|
+
if (typeof value === "string" && isForbiddenUrl(value)) delete properties[key];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function removeForbiddenNodes(node, forbiddenTags) {
|
|
36
|
+
if (!node.children) return;
|
|
37
|
+
const next = [];
|
|
38
|
+
for (const child of node.children) {
|
|
39
|
+
if (child.type === "element") {
|
|
40
|
+
const tag = (child.tagName || "").toLowerCase();
|
|
41
|
+
if (forbiddenTags.has(tag)) continue;
|
|
42
|
+
if (tag === "link") {
|
|
43
|
+
const { ok } = isStylesheetLink(child.properties || {});
|
|
44
|
+
if (!ok) continue;
|
|
45
|
+
}
|
|
46
|
+
if (child.properties) stripDangerousProperties(child.properties);
|
|
47
|
+
}
|
|
48
|
+
next.push(child);
|
|
49
|
+
removeForbiddenNodes(child, forbiddenTags);
|
|
50
|
+
}
|
|
51
|
+
node.children = next;
|
|
52
|
+
}
|
|
53
|
+
const forbiddenTagSet = new Set([...FORBID_TAGS, "script"].map((t) => t.toLowerCase()));
|
|
54
|
+
function sanitizeHtml(html) {
|
|
55
|
+
const tree = parseHtmlFragment(html);
|
|
56
|
+
removeForbiddenNodes(tree, forbiddenTagSet);
|
|
57
|
+
stripDangerousUrls(tree);
|
|
58
|
+
const schema = buildObservedSchema(defaultSchema, tree);
|
|
59
|
+
return stringifyHtmlFragment(unified().use(rehypeSanitize, schema).runSync(tree));
|
|
60
|
+
}
|
|
61
|
+
var sanitize_html_default = sanitizeHtml;
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { sanitize_html_default as default, sanitizeHtml };
|
|
65
|
+
//# sourceMappingURL=sanitize-html.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize-html.mjs","names":["next: HastNode[]"],"sources":["../../../src/server/compile/sanitize-html.ts"],"sourcesContent":["import { FORBID_TAGS } from '@format.dev/utils'\n\nimport { unified } from 'unified'\nimport rehypeSanitize, { defaultSchema } from 'rehype-sanitize'\nimport {\n\tbuildObservedSchema,\n\tparseHtmlFragment,\n\tstripDangerousUrls,\n\tstringifyHtmlFragment,\n\ttype HastNode\n} from './sanitize/shared'\n\n// What this sanitizer strips vs keeps is kept as internal architecture\n// documentation.\n\nfunction isLocalHref(href: string) {\n\t// Relative URLs are always \"local\".\n\t// We also treat protocol-relative URLs (//example.com) as remote.\n\t// Everything else with a scheme (http:, https:, data:, etc) is remote.\n\treturn !/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(href) && !href.startsWith('//')\n}\n\nfunction isForbiddenUrl(value: string) {\n\tconst normalized = value.trim().toLowerCase()\n\treturn normalized.startsWith('javascript:')\n}\n\nfunction isStylesheetLink(properties: Record<string, unknown>): { href: string; ok: boolean } {\n\tconst rel = properties.rel\n\tconst href = typeof properties.href === 'string' ? properties.href : ''\n\n\tconst relValues = Array.isArray(rel) ? rel : typeof rel === 'string' ? rel.split(/\\s+/) : []\n\tconst isStylesheet = relValues.some(v => String(v).toLowerCase() === 'stylesheet')\n\tconst isCssHref = href.toLowerCase().includes('.css')\n\tconst isLocalStylesheet = isStylesheet && isCssHref && isLocalHref(href)\n\n\treturn { href, ok: isLocalStylesheet }\n}\n\nfunction stripDangerousProperties(properties: Record<string, unknown>) {\n\tfor (const key of Object.keys(properties)) {\n\t\tif (key.toLowerCase().startsWith('on')) {\n\t\t\tdelete properties[key]\n\t\t}\n\t}\n\n\t// `srcdoc` is a common XSS vector; compiled output should never rely on it.\n\tdelete properties.srcdoc\n\n\tconst urlKeys = ['href', 'src', 'xlinkHref']\n\tfor (const key of urlKeys) {\n\t\tconst value = properties[key]\n\t\tif (typeof value === 'string' && isForbiddenUrl(value)) {\n\t\t\tdelete properties[key]\n\t\t}\n\t}\n}\n\nfunction removeForbiddenNodes(node: HastNode, forbiddenTags: Set<string>) {\n\tif (!node.children) return\n\n\tconst next: HastNode[] = []\n\tfor (const child of node.children) {\n\t\tif (child.type === 'element') {\n\t\t\tconst tag = (child.tagName || '').toLowerCase()\n\n\t\t\t// Remove explicitly forbidden tags.\n\t\t\tif (forbiddenTags.has(tag)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Allow engine-compatible stylesheet links only.\n\t\t\tif (tag === 'link') {\n\t\t\t\tconst props = child.properties || {}\n\t\t\t\tconst { ok } = isStylesheetLink(props)\n\t\t\t\tif (!ok) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (child.properties) {\n\t\t\t\tstripDangerousProperties(child.properties)\n\t\t\t}\n\t\t}\n\n\t\tnext.push(child)\n\t\tremoveForbiddenNodes(child, forbiddenTags)\n\t}\n\n\tnode.children = next\n}\n\nconst forbiddenTagSet = new Set([...FORBID_TAGS, 'script'].map(t => t.toLowerCase()))\n\nexport function sanitizeHtml(html: string): string {\n\tconst tree = parseHtmlFragment(html)\n\n\tremoveForbiddenNodes(tree, forbiddenTagSet)\n\tstripDangerousUrls(tree)\n\n\tconst schema = buildObservedSchema(defaultSchema, tree)\n\tconst sanitized = unified()\n\t\t.use(rehypeSanitize, schema)\n\t\t.runSync(tree as any)\n\treturn stringifyHtmlFragment(sanitized as unknown as HastNode)\n}\n\nexport default sanitizeHtml\n"],"mappings":";;;;;;AAeA,SAAS,YAAY,MAAc;AAIlC,QAAO,CAAC,4BAA4B,KAAK,KAAK,IAAI,CAAC,KAAK,WAAW,KAAK;;AAGzE,SAAS,eAAe,OAAe;AAEtC,QADmB,MAAM,MAAM,CAAC,aAAa,CAC3B,WAAW,cAAc;;AAG5C,SAAS,iBAAiB,YAAoE;CAC7F,MAAM,MAAM,WAAW;CACvB,MAAM,OAAO,OAAO,WAAW,SAAS,WAAW,WAAW,OAAO;CAGrE,MAAM,gBADY,MAAM,QAAQ,IAAI,GAAG,MAAM,OAAO,QAAQ,WAAW,IAAI,MAAM,MAAM,GAAG,EAAE,EAC7D,MAAK,MAAK,OAAO,EAAE,CAAC,aAAa,KAAK,aAAa;CAClF,MAAM,YAAY,KAAK,aAAa,CAAC,SAAS,OAAO;AAGrD,QAAO;EAAE;EAAM,IAFW,gBAAgB,aAAa,YAAY,KAAK;EAElC;;AAGvC,SAAS,yBAAyB,YAAqC;AACtE,MAAK,MAAM,OAAO,OAAO,KAAK,WAAW,CACxC,KAAI,IAAI,aAAa,CAAC,WAAW,KAAK,CACrC,QAAO,WAAW;AAKpB,QAAO,WAAW;AAGlB,MAAK,MAAM,OADK;EAAC;EAAQ;EAAO;EAAY,EACjB;EAC1B,MAAM,QAAQ,WAAW;AACzB,MAAI,OAAO,UAAU,YAAY,eAAe,MAAM,CACrD,QAAO,WAAW;;;AAKrB,SAAS,qBAAqB,MAAgB,eAA4B;AACzE,KAAI,CAAC,KAAK,SAAU;CAEpB,MAAMA,OAAmB,EAAE;AAC3B,MAAK,MAAM,SAAS,KAAK,UAAU;AAClC,MAAI,MAAM,SAAS,WAAW;GAC7B,MAAM,OAAO,MAAM,WAAW,IAAI,aAAa;AAG/C,OAAI,cAAc,IAAI,IAAI,CACzB;AAID,OAAI,QAAQ,QAAQ;IAEnB,MAAM,EAAE,OAAO,iBADD,MAAM,cAAc,EAAE,CACE;AACtC,QAAI,CAAC,GACJ;;AAIF,OAAI,MAAM,WACT,0BAAyB,MAAM,WAAW;;AAI5C,OAAK,KAAK,MAAM;AAChB,uBAAqB,OAAO,cAAc;;AAG3C,MAAK,WAAW;;AAGjB,MAAM,kBAAkB,IAAI,IAAI,CAAC,GAAG,aAAa,SAAS,CAAC,KAAI,MAAK,EAAE,aAAa,CAAC,CAAC;AAErF,SAAgB,aAAa,MAAsB;CAClD,MAAM,OAAO,kBAAkB,KAAK;AAEpC,sBAAqB,MAAM,gBAAgB;AAC3C,oBAAmB,KAAK;CAExB,MAAM,SAAS,oBAAoB,eAAe,KAAK;AAIvD,QAAO,sBAHW,SAAS,CACzB,IAAI,gBAAgB,OAAO,CAC3B,QAAQ,KAAY,CACwC;;AAG/D,4BAAe"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/server/compile/structured-log.d.ts
|
|
2
|
+
type StructuredOutputStatus = 'success' | 'error';
|
|
3
|
+
interface StructuredOutputError {
|
|
4
|
+
name?: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
interface StructuredOutput {
|
|
8
|
+
documentName: string;
|
|
9
|
+
outDir: string;
|
|
10
|
+
compiledIn: string;
|
|
11
|
+
status: StructuredOutputStatus;
|
|
12
|
+
error?: StructuredOutputError;
|
|
13
|
+
}
|
|
14
|
+
declare function createStructuredOutput(args: {
|
|
15
|
+
documentName: string;
|
|
16
|
+
outDir: string;
|
|
17
|
+
compiledIn: string;
|
|
18
|
+
error?: unknown;
|
|
19
|
+
}): StructuredOutput;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { StructuredOutput, StructuredOutputError, StructuredOutputStatus, createStructuredOutput };
|
|
22
|
+
//# sourceMappingURL=structured-log.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structured-log.d.mts","names":[],"sources":["../../../src/server/compile/structured-log.ts"],"sourcesContent":[],"mappings":";KAAY,sBAAA;AAAA,UAEK,qBAAA,CAFiB;EAEjB,IAAA,CAAA,EAAA,MAAA;EAKA,OAAA,EAAA,MAAA;AAmBjB;UAnBiB,gBAAA;;;;UAIR;UACA;;iBAcO,sBAAA;;;;;IAKZ"}
|