perf(util): load npm config lazily (#42458)
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
export * as NpmConfig from "./npm-config.js"
|
||||
|
||||
import { fileURLToPath } from "url"
|
||||
// @ts-expect-error npm does not publish types for this internal config API.
|
||||
import Config from "@npmcli/config"
|
||||
// @ts-expect-error npm does not publish types for this internal config API.
|
||||
import { definitions, flatten, nerfDarts, shorthands } from "@npmcli/config/lib/definitions/index.js"
|
||||
import { Effect } from "effect"
|
||||
|
||||
export const load = (dir: string) =>
|
||||
Effect.tryPromise({
|
||||
try: async () => {
|
||||
// @ts-expect-error npm does not publish types for this internal config API.
|
||||
const { default: Config } = await import("@npmcli/config")
|
||||
// @ts-expect-error npm does not publish types for this internal config API.
|
||||
const { default: npmDefinitions } = await import("@npmcli/config/lib/definitions/index.js")
|
||||
const { definitions, flatten, nerfDarts, shorthands } = npmDefinitions
|
||||
const config = new Config({
|
||||
// Resolved per call: on workerd import.meta.url is undefined and building
|
||||
// this URL at module scope fails startup validation; npm config never runs there.
|
||||
|
||||
@@ -51,10 +51,8 @@ export default defineWorkersConfig({
|
||||
// mime-types requires mime-db's JSON database at require time; keep the
|
||||
// lookup surface but back it with a static shim.
|
||||
{ find: /^mime-types$/, replacement: new URL("./test/shims/mime-types.mjs", import.meta.url).pathname },
|
||||
// util/npm.ts imports the npm toolchain at module scope; plugin installs
|
||||
// never happen in the workerd profile (plugin discovery is precompiled-only),
|
||||
// and @npmcli/config touches process.stdout.isTTY during module init.
|
||||
{ find: /^@npmcli\/config(\/.*)?$/, replacement: mockProxy },
|
||||
// Plugin installs never happen in the workerd profile (plugin discovery
|
||||
// is precompiled-only), so mock the package installation toolchain.
|
||||
{ find: /^@npmcli\/arborist(\/.*)?$/, replacement: mockProxy },
|
||||
{ find: /^pacote(\/.*)?$/, replacement: mockProxy },
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user