mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-31 03:58:11 -04:00
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { writeSettings } from '@pnpm/config.writer'
|
|
import { parse } from '@pnpm/deps.path'
|
|
import {
|
|
IgnoredBuildsError,
|
|
} from '@pnpm/installing.deps-installer'
|
|
import type { IgnoredBuilds } from '@pnpm/types'
|
|
import { lexCompare } from '@pnpm/util.lex-comparator'
|
|
|
|
export interface HandleIgnoredBuildsOpts {
|
|
allowBuilds?: Record<string, boolean | string>
|
|
rootProjectManifestDir?: string
|
|
workspaceDir?: string
|
|
strictDepBuilds?: boolean
|
|
}
|
|
|
|
export async function handleIgnoredBuilds (
|
|
opts: HandleIgnoredBuildsOpts,
|
|
ignoredBuilds: IgnoredBuilds | undefined
|
|
): Promise<void> {
|
|
if (!ignoredBuilds?.size) return
|
|
await writeIgnoredBuildsToAllowBuilds(opts, ignoredBuilds)
|
|
if (opts.strictDepBuilds) {
|
|
throw new IgnoredBuildsError(ignoredBuilds)
|
|
}
|
|
}
|
|
|
|
async function writeIgnoredBuildsToAllowBuilds (
|
|
opts: Pick<HandleIgnoredBuildsOpts, 'allowBuilds' | 'rootProjectManifestDir' | 'workspaceDir'>,
|
|
ignoredBuilds: IgnoredBuilds
|
|
): Promise<void> {
|
|
const packageNames = packageNamesFromIgnoredBuilds(ignoredBuilds)
|
|
const newEntries: Record<string, string> = {}
|
|
for (const name of packageNames) {
|
|
if (opts.allowBuilds?.[name] == null) {
|
|
newEntries[name] = 'set this to true or false'
|
|
}
|
|
}
|
|
if (Object.keys(newEntries).length && opts.rootProjectManifestDir) {
|
|
await writeSettings({
|
|
rootProjectManifestDir: opts.rootProjectManifestDir,
|
|
workspaceDir: opts.workspaceDir ?? opts.rootProjectManifestDir,
|
|
updatedSettings: {
|
|
allowBuilds: { ...opts.allowBuilds, ...newEntries },
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
function packageNamesFromIgnoredBuilds (ignoredBuilds: IgnoredBuilds): string[] {
|
|
return Array.from(new Set(Array.from(ignoredBuilds).map((dp) => parse(dp).name ?? dp))).sort(lexCompare)
|
|
}
|