mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-22 13:42:50 -04:00
* fix: refresh ignored builds when allowBuilds changes * refactor: extract isBuildExplicitlyDisallowed into @pnpm/building.policy Removes the duplicated ignored-build filter from deps-installer and deps-restorer and exposes it as `isBuildExplicitlyDisallowed` on `@pnpm/building.policy`, alongside `createAllowBuildFunction`. * fix: respect ignoredWorkspaceStateSettings in allowBuilds stale-state check The fallback that flagged installs when allowBuilds went from unset to non-empty bypassed the ignoredSettings filter, so callers that explicitly opted out of allowBuilds tracking (via ignoredWorkspaceStateSettings) could still be forced into a redundant install. --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
64 lines
2.5 KiB
TypeScript
64 lines
2.5 KiB
TypeScript
import { expect, it } from '@jest/globals'
|
|
import { createAllowBuildFunction, isBuildExplicitlyDisallowed } from '@pnpm/building.policy'
|
|
import type { DepPath } from '@pnpm/types'
|
|
|
|
it('should allowBuilds with true value', () => {
|
|
const allowBuild = createAllowBuildFunction({
|
|
allowBuilds: { foo: true, 'qar@1.0.0 || 2.0.0': true },
|
|
})
|
|
expect(typeof allowBuild).toBe('function')
|
|
expect(allowBuild!('foo', '1.0.0')).toBe(true)
|
|
expect(allowBuild!('bar', '1.0.0')).toBeUndefined()
|
|
expect(allowBuild!('qar', '1.1.0')).toBeUndefined()
|
|
expect(allowBuild!('qar', '1.0.0')).toBe(true)
|
|
expect(allowBuild!('qar', '2.0.0')).toBe(true)
|
|
})
|
|
|
|
it('should allowBuilds with false value', () => {
|
|
const allowBuild = createAllowBuildFunction({
|
|
allowBuilds: { foo: false, bar: true },
|
|
})
|
|
expect(typeof allowBuild).toBe('function')
|
|
expect(allowBuild!('foo', '1.0.0')).toBe(false)
|
|
expect(allowBuild!('bar', '1.0.0')).toBe(true)
|
|
expect(allowBuild!('baz', '1.0.0')).toBeUndefined()
|
|
})
|
|
|
|
it('should not allow patterns in allowBuilds', () => {
|
|
const allowBuild = createAllowBuildFunction({
|
|
allowBuilds: { 'is-*': true },
|
|
})
|
|
expect(typeof allowBuild).toBe('function')
|
|
expect(allowBuild!('is-odd', '1.0.0')).toBeUndefined()
|
|
})
|
|
|
|
it('should return undefined if no policy is set', () => {
|
|
expect(createAllowBuildFunction({})).toBeUndefined()
|
|
})
|
|
|
|
it('should allow everything when dangerouslyAllowAllBuilds is true', () => {
|
|
const allowBuild = createAllowBuildFunction({
|
|
dangerouslyAllowAllBuilds: true,
|
|
})
|
|
expect(typeof allowBuild).toBe('function')
|
|
expect(allowBuild!('foo', '1.0.0')).toBeTruthy()
|
|
})
|
|
|
|
it('isBuildExplicitlyDisallowed() flags only builds the policy explicitly forbids', () => {
|
|
const allowBuild = createAllowBuildFunction({
|
|
allowBuilds: { foo: false, bar: true },
|
|
})
|
|
expect(isBuildExplicitlyDisallowed('foo@1.0.0' as DepPath, allowBuild)).toBe(true)
|
|
expect(isBuildExplicitlyDisallowed('bar@1.0.0' as DepPath, allowBuild)).toBe(false)
|
|
expect(isBuildExplicitlyDisallowed('baz@1.0.0' as DepPath, allowBuild)).toBe(false)
|
|
})
|
|
|
|
it('isBuildExplicitlyDisallowed() returns false when no policy is set', () => {
|
|
expect(isBuildExplicitlyDisallowed('foo@1.0.0' as DepPath, undefined)).toBe(false)
|
|
})
|
|
|
|
it('isBuildExplicitlyDisallowed() returns false for unparsable depPaths', () => {
|
|
const allowBuild = createAllowBuildFunction({ allowBuilds: { foo: false } })
|
|
expect(isBuildExplicitlyDisallowed('not-a-valid-dep-path' as DepPath, allowBuild)).toBe(false)
|
|
})
|