From 827a52f8b28b93b74085b16a6cf071d7cafec30c Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sat, 28 Feb 2026 20:12:28 -0500 Subject: [PATCH 1/2] fix(web): use proper node_modules directory --- src/generators/web/utils/bundle.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/generators/web/utils/bundle.mjs b/src/generators/web/utils/bundle.mjs index 69780372..b18e7b76 100644 --- a/src/generators/web/utils/bundle.mjs +++ b/src/generators/web/utils/bundle.mjs @@ -1,3 +1,4 @@ +import module from 'node:module'; import { join } from 'node:path'; import virtual from '@rollup/plugin-virtual'; @@ -10,8 +11,8 @@ import getConfig from '../../../utils/configuration/index.mjs'; // Resolve node_modules relative to this package (doc-kit), not cwd. // This ensures modules are found when running from external directories. const DOC_KIT_NODE_MODULES = join( - import.meta.dirname, - '../../../../node_modules' + module.findPackageJSON(new URL(import.meta.resolve('preact'))), + '../../../node_modules' ); /** From bee9a0f78aa4a6f94d458fda98676b776216c201 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Sun, 1 Mar 2026 16:43:17 -0500 Subject: [PATCH 2/2] fixup! --- src/generators/web/constants.mjs | 9 +++++++++ src/generators/web/utils/bundle.mjs | 16 +++------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/generators/web/constants.mjs b/src/generators/web/constants.mjs index 8a18f8d9..44efdabb 100644 --- a/src/generators/web/constants.mjs +++ b/src/generators/web/constants.mjs @@ -1,8 +1,17 @@ +import { findPackageJSON } from 'node:module'; import { resolve, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; export const ROOT = dirname(fileURLToPath(import.meta.url)); +// Resolve node_modules relative to this package (doc-kit), not cwd. +// We do this by finding where one of our dependencies (preact) is stored, +// and using it's NODE_MODULES +export const NODE_MODULES = resolve( + findPackageJSON(new URL(import.meta.resolve('preact'))), + '../..' +); + /** * @typedef {Object} JSXImportConfig * @property {string} name - The name of the component to be imported. diff --git a/src/generators/web/utils/bundle.mjs b/src/generators/web/utils/bundle.mjs index b18e7b76..e9f4efbd 100644 --- a/src/generators/web/utils/bundle.mjs +++ b/src/generators/web/utils/bundle.mjs @@ -1,19 +1,10 @@ -import module from 'node:module'; -import { join } from 'node:path'; - import virtual from '@rollup/plugin-virtual'; import { build } from 'rolldown'; import cssLoader from './css.mjs'; import getStaticData from './data.mjs'; import getConfig from '../../../utils/configuration/index.mjs'; - -// Resolve node_modules relative to this package (doc-kit), not cwd. -// This ensures modules are found when running from external directories. -const DOC_KIT_NODE_MODULES = join( - module.findPackageJSON(new URL(import.meta.resolve('preact'))), - '../../../node_modules' -); +import { NODE_MODULES } from '../constants.mjs'; /** * Asynchronously bundles JavaScript source code (and its CSS imports), @@ -100,9 +91,8 @@ export default async function bundleCode(codeMap, { server = false } = {}) { }, // Tell the bundler where to find node_modules. - // This ensures packages are found when running doc-kit from external directories - // (e.g., running from the node repository via tools/doc/node_modules/.bin/doc-kit). - modules: [DOC_KIT_NODE_MODULES, 'node_modules'], + // We use our custom `NODE_MODULES`, and then the cwd's `node_modules`. + modules: [NODE_MODULES, 'node_modules'], }, // Array of plugins to apply during the build.