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

Implement JavaScript-based constraints #220

Merged
merged 10 commits into from
Mar 15, 2024
Merged

Implement JavaScript-based constraints #220

merged 10 commits into from
Mar 15, 2024

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Sep 30, 2023

I've replaced the Prolog-based constraints (deprecated in Yarn v4) with JavaScript-based constraints. This has the benefit that the constraints file is much more readable, especially for those who are not well-versed in Prolog. As an added benefit, the error messages produced by Yarn are more readable too.

The new constraints file implements all the Prolog-based constraints, and some extras. For example, we can now verify that the README.md does not contain the template instructions (if the current repository is not the module template), and that the .nvmrc version matches with the Node.js version mentioned in the README.md. Since the new constraints file has access to all Node.js APIs (including fs), we have much more flexibility in the kinds of constraints.

Using these constraints requires bumping Yarn to v4, and using a minimum Node.js version of 18.12.0. The Node.js version bump is a .nvmrc only bump, so this shouldn't be a breaking change.

Blocked by

@Mrtenz Mrtenz requested a review from a team as a code owner September 30, 2023 09:36
@socket-security
Copy link

socket-security bot commented Sep 30, 2023

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@yarnpkg/[email protected] None +1 92.8 kB yarnbot
npm/[email protected] None 0 84 kB typescript-bot

View full report↗︎

@socket-security
Copy link

socket-security bot commented Sep 30, 2023

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

@Mrtenz
Copy link
Member Author

Mrtenz commented Sep 30, 2023

Using these constraints requires bumping Yarn to v4, and using a minimum Node.js version of 18.12.0. The Node.js version bump is a .nvmrc only bump, so this shouldn't be a breaking change.

Unfortunately this causes CI to fail, so it looks like we may want to drop support for Node.js 16 (EOL) anyway.

@Mrtenz Mrtenz marked this pull request as draft September 30, 2023 09:53
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

This would be great to have, because we've definitely stumbled on the Prolog versions of the constraints multiple times.

package.json Outdated Show resolved Hide resolved
.eslintrc.js Show resolved Hide resolved
.eslintrc.js Show resolved Hide resolved
.nvmrc Outdated Show resolved Hide resolved
@Mrtenz Mrtenz force-pushed the mrtenz/js-constraints branch from a0da5b1 to db52e4f Compare March 7, 2024 08:24
@Mrtenz Mrtenz marked this pull request as ready for review March 7, 2024 08:41
@Mrtenz Mrtenz requested a review from mcmire March 7, 2024 08:41
@@ -1,3 +1,7 @@
compressionLevel: mixed
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for these new config options?

Copy link
Member Author

Choose a reason for hiding this comment

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

They were added by Yarn when updating the version. I haven't changed anything.

});
}

module.exports = defineConfig({
Copy link
Member

Choose a reason for hiding this comment

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

So much more readable 🎉

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

This is the first time I'm looking at the new constraints API up close, and unfortunately it's not as readable or understandable as I'd hoped (I should really submit a pull request to the Yarn repo). That said, wrapping each step in a well-named function is a good idea, and the fact that we can read files and do other kinds of things is a big win.

I just had some comments but overall this is looking good.

.yarnrc.yml Show resolved Hide resolved
yarn.config.cjs Outdated

// The list of files included in the package must only include files
// generated during the build process.
workspace.set('files[0]', 'dist');
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this says that dist must be the first item in files. Does that matter? Should we say that dist must be present in files instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Order of files doesn't matter. I've changed it to workspace.set('files', ['dist']) to make this clear. We could also check if the array contains dist, but I don't think that's possible with workspace.set.

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 that's okay. Projects can customize this if they really need to, but I imagine that will be rare.

yarn.config.cjs Outdated Show resolved Hide resolved
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks good! Let's do it!

@Mrtenz Mrtenz force-pushed the mrtenz/js-constraints branch from 99217a4 to 984dc40 Compare March 14, 2024 22:14
@Mrtenz Mrtenz merged commit c2b55bc into main Mar 15, 2024
16 checks passed
@Mrtenz Mrtenz deleted the mrtenz/js-constraints branch March 15, 2024 09:37
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.

3 participants