|
| 1 | +import { resolve } from 'node:path'; |
| 2 | + |
1 | 3 | import virtual from '@rollup/plugin-virtual'; |
2 | 4 | import { build } from 'rolldown'; |
3 | 5 |
|
4 | 6 | import cssLoader from './css.mjs'; |
5 | 7 | import getStaticData from './data.mjs'; |
6 | 8 | import getConfig from '../../../utils/configuration/index.mjs'; |
7 | | -import { NODE_MODULES } from '../constants.mjs'; |
| 9 | +import { lazy } from '../../../utils/misc.mjs'; |
| 10 | + |
| 11 | +// Resolve node_modules relative to this package (doc-kit), not cwd. |
| 12 | +// We do this by finding where one of our dependencies (preact) is stored, |
| 13 | +// and using it's NODE_MODULES |
| 14 | +// |
| 15 | +// FIXME(@avivkeller): When our CI (in Node.js Core) supports v22.x, |
| 16 | +// this lazy-loading solution can be replaced by a simple import. For that |
| 17 | +// matter, glob can also be replaced in other files throughout this repo. |
| 18 | +const getNodeModules = lazy(async () => { |
| 19 | + const { findPackageJSON } = await import('node:module'); |
| 20 | + |
| 21 | + return resolve( |
| 22 | + findPackageJSON(new URL(import.meta.resolve('preact'))), |
| 23 | + '../..' |
| 24 | + ); |
| 25 | +}); |
8 | 26 |
|
9 | 27 | /** |
10 | 28 | * Asynchronously bundles JavaScript source code (and its CSS imports), |
@@ -92,7 +110,7 @@ export default async function bundleCode(codeMap, { server = false } = {}) { |
92 | 110 |
|
93 | 111 | // Tell the bundler where to find node_modules. |
94 | 112 | // We use our custom `NODE_MODULES`, and then the cwd's `node_modules`. |
95 | | - modules: [NODE_MODULES, 'node_modules'], |
| 113 | + modules: [await getNodeModules(), 'node_modules'], |
96 | 114 | }, |
97 | 115 |
|
98 | 116 | // Array of plugins to apply during the build. |
|
0 commit comments