diff --git a/packages/experimental/webworker-runtime/tsdown.config.ts b/packages/experimental/webworker-runtime/tsdown.config.ts index 720bba61b7..97620c09bb 100644 --- a/packages/experimental/webworker-runtime/tsdown.config.ts +++ b/packages/experimental/webworker-runtime/tsdown.config.ts @@ -31,6 +31,23 @@ const shellParserOnlyPlugin = { }, } +/** + * The `buffer` package this package declares. Bundled CommonJS that names the + * `buffer` builtin without declaring the npm package, such as `safe-buffer` under + * `string_decoder`, resolves here instead of through whatever the installer + * hoists; pnpm's global virtual store hoists nothing above a stored package. + * The trailing slash skips Node's `buffer` builtin and resolves the npm package. + */ +const BUFFER_ENTRY = resolveFrom.resolve('buffer/') + +/** Redirects every bare `buffer` specifier onto {@link BUFFER_ENTRY}. */ +const bufferPackagePlugin = { + name: 'dsh-buffer-package', + resolveId(source: string): string | null { + return source === 'buffer' ? BUFFER_ENTRY : null + }, +} + /** * Resolve the module proxy table at bundle time: every Node builtin or * replaced external the worker graph imports lands on its `./node/` proxy, @@ -77,7 +94,7 @@ export default defineConfig([{ dts: false, clean: false, noExternal: [/.*/], - plugins: [moduleProxyPlugin, shellParserOnlyPlugin], + plugins: [moduleProxyPlugin, shellParserOnlyPlugin, bufferPackagePlugin], outputOptions: { inlineDynamicImports: true }, }, { // Page half: an ordinary browser ES module the deployment's page imports. It diff --git a/website/.vitepress/config.ts b/website/.vitepress/config.ts index 8c49540c01..99d6db25f4 100644 --- a/website/.vitepress/config.ts +++ b/website/.vitepress/config.ts @@ -1,6 +1,7 @@ /** VitePress configuration for the locally projected documentation site. */ import { readFileSync, writeFileSync } from 'node:fs' +import { createRequire } from 'node:module' import { resolve } from 'node:path' import type { DefaultTheme, PageData, SiteConfig } from 'vitepress' import type { ViteDevServer } from 'vite' @@ -12,6 +13,8 @@ import { rawMarkdownMiddleware } from '../raw-markdown.ts' projectDocs() +const websiteRequire = createRequire(import.meta.url) + function sidebar(locale: DocsLocale, collection: NonNullable): DefaultTheme.SidebarItem[] { // `orderedPages` already sorts by section placement, so insertion order // carries the group order and each group keeps its pages in sequence. @@ -341,6 +344,14 @@ export default withMermaid({ // `srcDir` puts the Vite root inside the disposable generated tree, whose // own `public/` no tracked asset can live in. publicDir: resolve(import.meta.dirname, '../public'), + // `withMermaid` injects `vitepress-plugin-mermaid/Mermaid.vue` into the VitePress client, which + // resolves it from the `vitepress` package, and the component imports `vue` without declaring it. + // Both resolve from the website's declared dependencies, so the build does not rely on the + // installer hoisting undeclared dependencies, which pnpm's global virtual store never does. + resolve: { + alias: { 'vitepress-plugin-mermaid/Mermaid.vue': websiteRequire.resolve('vitepress-plugin-mermaid/Mermaid.vue') }, + dedupe: ['vue'], + }, plugins: [ { name: 'deepseek-harness-doc-projector',