fix(build): resolve undeclared hoisted dependencies from declaring packages

Resolve the bundled buffer import in webworker-runtime and the Mermaid
component plus vue in the website from their declared dependencies, so
builds no longer rely on pnpm hoisting undeclared dependencies.

Fixes #8497
This commit is contained in:
imccyu committed 2026-11-16 00:50:38 +08:00
1 parent f3ac7b9078
commit 3b55cf3525
2 files changed
+29 -1

No files matched your search

@@ -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
+11
View File
@@ -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<DocsPage['sidebar']>): 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',