Skip to content

Conversation

@zkochan
Copy link
Member

@zkochan zkochan commented Oct 19, 2025

close #10076

@zkochan zkochan requested a review from Copilot October 20, 2025 23:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for specifying exact versions of dependencies when controlling which packages are allowed to build, enhancing the granularity of build policy configuration.

Key changes:

  • Updated the AllowBuild type signature to accept both package name and version parameters
  • Introduced version-aware filtering in the @pnpm/builder.policy package with support for exact version matching
  • Modified all callsites to pass version information to allowBuild functions

Reviewed Changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/types/src/config.ts Added new AllowBuild type definition accepting name and version
builder/policy/src/index.ts New package implementing version-aware build policy logic
config/matcher/src/index.ts Added expandPackageVersionSpecs function to handle version-specific package specs
pkg-manager/headless/src/index.ts Updated allowBuild calls to include version parameter
pkg-manager/core/src/install/link.ts Updated allowBuild type annotations and invocations
exec/build-modules/src/index.ts Updated to pass version to allowBuild function
exec/plugin-commands-rebuild/src/implementation/index.ts Updated rebuild logic to use version-aware build policy
deps/graph-builder/src/lockfileToDepGraph.ts Added version field to DependenciesGraphNode
pnpm-workspace.yaml Added builder packages to workspace and removed catalog dependency
pkg-manager/core/test/install/lifecycleScripts.ts Added test coverage for exact version matching in build policies
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

if (opts.onlyBuiltDependenciesFile != null || opts.onlyBuiltDependencies != null) {
const onlyBuiltDeps = opts.onlyBuiltDependencies ?? []
if (opts.onlyBuiltDependenciesFile) {
onlyBuiltDeps.push(...JSON.parse(fs.readFileSync(opts.onlyBuiltDependenciesFile, 'utf8')))
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for file read and JSON parse operations. If the file doesn't exist or contains invalid JSON, this will throw an unhelpful error. Add try-catch with a clear error message indicating the file path and nature of the problem.

Suggested change
onlyBuiltDeps.push(...JSON.parse(fs.readFileSync(opts.onlyBuiltDependenciesFile, 'utf8')))
try {
const fileContent = fs.readFileSync(opts.onlyBuiltDependenciesFile, 'utf8');
onlyBuiltDeps.push(...JSON.parse(fileContent));
} catch (err) {
throw new Error(
`Failed to read or parse JSON from file "${opts.onlyBuiltDependenciesFile}": ${err instanceof Error ? err.message : String(err)}`
);
}

Copilot uses AI. Check for mistakes.
@zkochan zkochan marked this pull request as ready for review October 20, 2025 23:52
@zkochan zkochan requested a review from Copilot October 21, 2025 09:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 45 out of 46 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

function parseExactVersionsUnion (versionsStr: string): string[] | null {
const versions: string[] = []
for (const versionRaw of versionsStr.split('||')) {
const version = semver.valid(versionRaw)
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version string is not being trimmed before validation. Whitespace in version unions like '1.0.0||1.0.1 || 1.0.2' will cause semver.valid() to return null. Add .trim() before calling semver.valid().

Suggested change
const version = semver.valid(versionRaw)
const version = semver.valid(versionRaw.trim())

Copilot uses AI. Check for mistakes.

type Matcher = (input: string) => boolean
type MatcherWithIndex = (input: string) => number
export type Matcher = (input: string) => boolean
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types were previously not exported but are now exported. However, they're being imported in config/version-policy/src/index.ts which creates a dependency on @pnpm/matcher. Consider documenting this breaking change or verifying that all consumers are updated to import from the correct location.

Suggested change
export type Matcher = (input: string) => boolean
export type Matcher = (input: string) => boolean
// BREAKING CHANGE: MatcherWithIndex is now exported from @pnpm/matcher. Consumers should import from this location.

Copilot uses AI. Check for mistakes.
@zkochan zkochan merged commit dee39ec into main Oct 21, 2025
14 of 15 checks passed
@zkochan zkochan deleted the only-built-dependencies-version branch October 21, 2025 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tie onlyBuiltDependencies to package version/hash

2 participants