From e6ba9d8caa3866215095f63b62290f3110e523fd Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:43:31 +0530 Subject: [PATCH] fix(build): don't rely on checkout directory name when externalizing types The `typesExternal` regex matched the absolute build path against `/vitepress/`, so repo-root `.d.ts` files (types/*) were only kept external when the repo was checked out in a directory named "vitepress". When built elsewhere, `DefaultTheme` got inlined into `dist/node/index.d.ts`, orphaning the `declare module` augmentations from `defaultTheme.ts` and breaking node-only options like `search.options._render` (regressed in v2.0.0-alpha.18). Compare paths resolved against this config's directory instead, normalized for separators and drive-letter casing so it also works on windows. Co-Authored-By: Claude Fable 5 --- rollup.config.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/rollup.config.ts b/rollup.config.ts index 23c9d41f..7f040f6f 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -5,6 +5,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve' import replace from '@rollup/plugin-replace' import { rm } from 'node:fs/promises' import { builtinModules, createRequire } from 'node:module' +import { fileURLToPath } from 'node:url' import { type RollupOptions, defineConfig } from 'rollup' import dts from 'rollup-plugin-dts' import esbuild from 'rollup-plugin-esbuild' @@ -53,11 +54,27 @@ const esmBuild: RollupOptions = { } } -const typesExternal = [ - ...external, - /\/vitepress\/(?!(dist|node_modules|vitepress)\/).*\.d\.ts$/, - /^markdown-it(?:\/|$)/ -] +// keep .d.ts files under the repo root (e.g. types/*) external so module +// augmentations in the bundle still target the same files users reference. +// compared on normalized resolved paths so this works regardless of the +// checkout location, path separators, or drive-letter casing. +const normalizePath = (id: string): string => { + const normalized = id.replaceAll('\\', '/') + return process.platform === 'win32' ? normalized.toLowerCase() : normalized +} + +const root = normalizePath(fileURLToPath(new URL('.', import.meta.url))) + +const typesExternal = (id: string): boolean => { + if (external.includes(id) || /^markdown-it(?:\/|$)/.test(id)) return true + const normalized = normalizePath(id) + return ( + normalized.endsWith('.d.ts') && + normalized.startsWith(root) && + !normalized.startsWith(`${root}dist/`) && + !normalized.startsWith(`${root}node_modules/`) + ) +} const dtsNode = dts({ respectExternal: true,