Skip to content

Commit bee9a0f

Browse files
committed
fixup!
1 parent 827a52f commit bee9a0f

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/generators/web/constants.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import { findPackageJSON } from 'node:module';
12
import { resolve, dirname } from 'node:path';
23
import { fileURLToPath } from 'node:url';
34

45
export const ROOT = dirname(fileURLToPath(import.meta.url));
56

7+
// Resolve node_modules relative to this package (doc-kit), not cwd.
8+
// We do this by finding where one of our dependencies (preact) is stored,
9+
// and using it's NODE_MODULES
10+
export const NODE_MODULES = resolve(
11+
findPackageJSON(new URL(import.meta.resolve('preact'))),
12+
'../..'
13+
);
14+
615
/**
716
* @typedef {Object} JSXImportConfig
817
* @property {string} name - The name of the component to be imported.

src/generators/web/utils/bundle.mjs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
import module from 'node:module';
2-
import { join } from 'node:path';
3-
41
import virtual from '@rollup/plugin-virtual';
52
import { build } from 'rolldown';
63

74
import cssLoader from './css.mjs';
85
import getStaticData from './data.mjs';
96
import getConfig from '../../../utils/configuration/index.mjs';
10-
11-
// Resolve node_modules relative to this package (doc-kit), not cwd.
12-
// This ensures modules are found when running from external directories.
13-
const DOC_KIT_NODE_MODULES = join(
14-
module.findPackageJSON(new URL(import.meta.resolve('preact'))),
15-
'../../../node_modules'
16-
);
7+
import { NODE_MODULES } from '../constants.mjs';
178

189
/**
1910
* Asynchronously bundles JavaScript source code (and its CSS imports),
@@ -100,9 +91,8 @@ export default async function bundleCode(codeMap, { server = false } = {}) {
10091
},
10192

10293
// Tell the bundler where to find node_modules.
103-
// This ensures packages are found when running doc-kit from external directories
104-
// (e.g., running from the node repository via tools/doc/node_modules/.bin/doc-kit).
105-
modules: [DOC_KIT_NODE_MODULES, 'node_modules'],
94+
// We use our custom `NODE_MODULES`, and then the cwd's `node_modules`.
95+
modules: [NODE_MODULES, 'node_modules'],
10696
},
10797

10898
// Array of plugins to apply during the build.

0 commit comments

Comments
 (0)