From 675a46e23e679c294355435584ae662a7c0903c7 Mon Sep 17 00:00:00 2001 From: Dax Date: Thu, 16 Apr 2026 02:03:03 -0400 Subject: CLI perf: reduce deps (#22652) --- packages/shared/src/npm.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'packages/shared/src/npm.ts') diff --git a/packages/shared/src/npm.ts b/packages/shared/src/npm.ts index 8bd0cc468..955cafa19 100644 --- a/packages/shared/src/npm.ts +++ b/packages/shared/src/npm.ts @@ -1,6 +1,5 @@ import path from "path" import semver from "semver" -import { Arborist } from "@npmcli/arborist" import { Effect, Schema, Context, Layer, Option, FileSystem } from "effect" import { NodeFileSystem } from "@effect/platform-node" import { AppFileSystem } from "./filesystem" @@ -19,8 +18,8 @@ export namespace Npm { } export interface Interface { - readonly add: (pkg: string) => Effect.Effect - readonly install: (dir: string) => Effect.Effect + readonly add: (pkg: string) => Effect.Effect + readonly install: (dir: string, input?: { add: string[] }) => Effect.Effect readonly outdated: (pkg: string, cachedVersion: string) => Effect.Effect readonly which: (pkg: string) => Effect.Effect> } @@ -92,6 +91,7 @@ export namespace Npm { }) const add = Effect.fn("Npm.add")(function* (pkg: string) { + const { Arborist } = yield* Effect.promise(() => import("@npmcli/arborist")) const dir = directory(pkg) yield* flock.acquire(`npm-install:${dir}`) @@ -133,10 +133,17 @@ export namespace Npm { return resolveEntryPoint(first.name, first.path) }, Effect.scoped) - const install = Effect.fn("Npm.install")(function* (dir: string) { + const install = Effect.fn("Npm.install")(function* (dir: string, input?: { add: string[] }) { + const canWrite = yield* afs.access(dir, { writable: true }).pipe( + Effect.as(true), + Effect.orElseSucceed(() => false), + ) + if (!canWrite) return + yield* flock.acquire(`npm-install:${dir}`) const reify = Effect.fnUntraced(function* () { + const { Arborist } = yield* Effect.promise(() => import("@npmcli/arborist")) const arb = new Arborist({ path: dir, binLinks: true, @@ -145,7 +152,14 @@ export namespace Npm { ignoreScripts: true, }) yield* Effect.tryPromise({ - try: () => arb.reify().catch(() => {}), + try: () => + arb + .reify({ + add: input?.add || [], + save: true, + saveType: "prod", + }) + .catch(() => {}), catch: () => {}, }).pipe(Effect.orElseSucceed(() => {})) }) @@ -167,6 +181,7 @@ export namespace Npm { ...Object.keys(pkgAny?.devDependencies || {}), ...Object.keys(pkgAny?.peerDependencies || {}), ...Object.keys(pkgAny?.optionalDependencies || {}), + ...(input?.add || []), ]) const root = lockAny?.packages?.[""] || {} -- cgit v1.2.3