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

Print reason when node engine does not match #1424

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rbnayax
Copy link
Contributor

@rbnayax rbnayax commented Jun 8, 2024

Fix: #1422

@rbnayax rbnayax marked this pull request as draft June 8, 2024 17:47
@rbnayax rbnayax marked this pull request as ready for review June 8, 2024 18:32
@rbnayax
Copy link
Contributor Author

rbnayax commented Jun 8, 2024

@raineorshine would appreciate your CR

@raineorshine raineorshine changed the title feat: when packages are filter due to engine not matching, we need to print it out, just like we do in peer checks Print reason when node engine does not match Jun 12, 2024
* @param version
* @returns Promised engines collection
*/
export const getEngines = async (packageName: string, version: Version): Promise<Index<Version | undefined>> => {
Copy link
Owner

Choose a reason for hiding this comment

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

You can use fetchPartialPackument instead of doing a separate spawn. fetchPartialPackument uses streaming for performance, and is already used in other places to fetch node engines.

You might need to add a version param.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 15 to 16
engines?: Index<VersionSpec>
engines?: Index<Version | undefined>
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is correct. If a package does not define a node engine, it should be omitted from the engines object. Explicit undefined should not be allowed.

Copy link
Owner

Choose a reason for hiding this comment

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

VersionSpec (i.e. a version range) is correct, not Version (an exact version).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you don't put undefined, the any access to the engines object will produce a type of VersionSpec which is not correct... engines.foo is not a string, but a sring | undefined this is just more safe, so when I access engines.node I will know to make sure it is not undefined.

nodeEngineVersion?: VersionSpec
nodeEngineVersion?: Version
Copy link
Owner

Choose a reason for hiding this comment

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

VersionSpec (i.e. a version range) is correct, not Version (an exact version).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if (!options.nodeEngineVersion) return {}
const optionsEnginesNodeMinVersion = minVersion(options.nodeEngineVersion)?.version
if (!optionsEnginesNodeMinVersion) return {}
const [upgradedLatestVersions] = await upgradePackageDefinitions(current, {
Copy link
Owner

Choose a reason for hiding this comment

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

It's unfortunate that we have to call upgradePackageDefinitions again, since it was already called to produce upgraded. Optimizing this probably involves larger changes to the upgrade pipeline though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I first tried to see how I can overcome it, but it requires major changes. If we ever do go ahead and make those changes, we can also not run the upgrades again for the ignored upgrades due to peer dependencies...

import upgradePackageDefinitions from './upgradePackageDefinitions'

/** Checks if package.json min node version satisfies given package engine.node spec */
const satisfiesNodeEngine = (enginesNode: Maybe<Version>, optionsEnginesNodeMinVersion: string) =>
Copy link
Owner

Choose a reason for hiding this comment

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

enginesNode should be Maybe<VersionSpec>, not Maybe<Version>, since it can be represented as a version range.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

import upgradePackageDefinitions from './upgradePackageDefinitions'

/** Checks if package.json min node version satisfies given package engine.node spec */
const satisfiesNodeEngine = (enginesNode: Maybe<Version>, optionsEnginesNodeMinVersion: string) =>
Copy link
Owner

Choose a reason for hiding this comment

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

You could also reuse satisfiesNodeEngine from filters.ts if you wanted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could but I would rather not call minVersion a bunch of times and instead call it once and reuse it

@rbnayax
Copy link
Contributor Author

rbnayax commented Jun 15, 2024

@raineorshine would appreciate your CR

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.

when packages are filter due to engine not matching, we need to print it out, just like we do in peer checks
2 participants