Skip to content

Commit 0b29712

Browse files
authored
fix(web): use proper node_modules directory (#623)
* fix(web): use proper node_modules directory * fixup!
1 parent e27fb0c commit 0b29712

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import { join } from 'node:path';
2-
31
import virtual from '@rollup/plugin-virtual';
42
import { build } from 'rolldown';
53

64
import cssLoader from './css.mjs';
75
import getStaticData from './data.mjs';
86
import getConfig from '../../../utils/configuration/index.mjs';
9-
10-
// Resolve node_modules relative to this package (doc-kit), not cwd.
11-
// This ensures modules are found when running from external directories.
12-
const DOC_KIT_NODE_MODULES = join(
13-
import.meta.dirname,
14-
'../../../../node_modules'
15-
);
7+
import { NODE_MODULES } from '../constants.mjs';
168

179
/**
1810
* Asynchronously bundles JavaScript source code (and its CSS imports),
@@ -99,9 +91,8 @@ export default async function bundleCode(codeMap, { server = false } = {}) {
9991
},
10092

10193
// Tell the bundler where to find node_modules.
102-
// This ensures packages are found when running doc-kit from external directories
103-
// (e.g., running from the node repository via tools/doc/node_modules/.bin/doc-kit).
104-
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'],
10596
},
10697

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

0 commit comments

Comments
 (0)