/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/core/src/npm-config.ts
40 строк
1 KB
Dax
Refactor npm config handling (#24565)
27 апр 2026, 06:54
Не верифицирован
27 апр 2026, 06:54
a9b62d6
Код
Авторство
О чём код?
export * as NpmConfig from "./npm-config" 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" const npmPath = fileURLToPath(new URL("..", import.meta.url)) export const load = (dir: string) => Effect.tryPromise({ try: async () => { const config = new Config({ npmPath, cwd: dir, env: { ...process.env }, argv: [process.execPath, process.execPath], execPath: process.execPath, platform: process.platform, definitions, flatten, nerfDarts, shorthands, warn: false, }) await config.load() return config.flat as Record<string, unknown> }, catch: (cause) => cause, }).pipe(Effect.orElseSucceed(() => ({}) as Record<string, unknown>)) export const registry = (dir: string) => load(dir).pipe( Effect.map((config) => { const registry = typeof config.registry === "string" ? config.registry : "https://registry.npmjs.org" return registry.endsWith("/") ? registry.slice(0, -1) : registry }), )