Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(builder): Add packageref validation for name and variant size #1185

Merged
merged 38 commits into from
Jul 11, 2024

Conversation

FuzzB0t
Copy link
Contributor

@FuzzB0t FuzzB0t commented Jul 2, 2024

Added a validation on the package reference class that throws an error when name or variant size exceeds 32 bytes
image

fixes https://linear.app/usecannon/issue/CAN-376/verify-target-in-clone-step-isnt-too-long-to-publish-before-building

Copy link

changeset-bot bot commented Jul 2, 2024

⚠️ No Changeset found

Latest commit: 978931a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

nx-cloud bot commented Jul 2, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 978931a. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@@ -89,6 +89,17 @@ export class PackageReference {
}

static isValid(ref: string) {
const pkgRef = new PackageReference(ref);
Copy link
Contributor Author

@FuzzB0t FuzzB0t Jul 2, 2024

Choose a reason for hiding this comment

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

I added the error logic here so that I could run this function on the zod schema as a refine, however it seems wrong to add error logic to a boolean function. There's likely a better way to achieve this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored this to add the error logic in the parse function of the package ref class, and add custom refinements in zod on the schema itself.

Comment on lines 103 to 108
try {
PackageReference.parse(ref);
} catch (err) {
return false;
}
return !!PackageReference.PACKAGE_REGEX.test(ref);
Copy link
Member

Choose a reason for hiding this comment

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

The regex is already being used inside the .parse:

Suggested change
try {
PackageReference.parse(ref);
} catch (err) {
return false;
}
return !!PackageReference.PACKAGE_REGEX.test(ref);
try {
PackageReference.parse(ref);
return true;
} catch (err) {
return false;
}

if (match.groups.version) res.version = match.groups.version;

const versionSize = res.name.length;
if (!(versionSize <= 32)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think versionSize > 32 is the same and easier to read

@FuzzB0t FuzzB0t dismissed dbeal-eth’s stale review July 11, 2024 23:34

Requested changes have been resolved

@FuzzB0t FuzzB0t merged commit fb04e41 into main Jul 11, 2024
9 checks passed
@FuzzB0t FuzzB0t deleted the packageref-validation branch July 11, 2024 23:35
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.

4 participants