Skip to content

Commit a1e2b90

Browse files
committed
hotfix: lazy-load node:module
1 parent 0f69d7b commit a1e2b90

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@node-core/doc-kit",
33
"type": "module",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"repository": {
66
"type": "git",
77
"url": "git+https://github.com/nodejs/doc-kit.git"

src/generators/web/constants.mjs

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

54
export const ROOT = dirname(fileURLToPath(import.meta.url));
65

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-
156
/**
167
* @typedef {Object} JSXImportConfig
178
* @property {string} name - The name of the component to be imported.

src/generators/web/utils/bundle.mjs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
import { resolve } from 'node:path';
2+
13
import virtual from '@rollup/plugin-virtual';
24
import { build } from 'rolldown';
35

46
import cssLoader from './css.mjs';
57
import getStaticData from './data.mjs';
68
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+
const getNodeModules = lazy(async () => {
15+
const { findPackageJSON } = await import('node:module');
16+
17+
return resolve(
18+
findPackageJSON(new URL(import.meta.resolve('preact'))),
19+
'../..'
20+
);
21+
});
822

923
/**
1024
* Asynchronously bundles JavaScript source code (and its CSS imports),
@@ -92,7 +106,7 @@ export default async function bundleCode(codeMap, { server = false } = {}) {
92106

93107
// Tell the bundler where to find node_modules.
94108
// We use our custom `NODE_MODULES`, and then the cwd's `node_modules`.
95-
modules: [NODE_MODULES, 'node_modules'],
109+
modules: [await getNodeModules(), 'node_modules'],
96110
},
97111

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

0 commit comments

Comments
 (0)