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

feat: add support for URL in "packageManager" #359

Merged
merged 20 commits into from
Feb 20, 2024
Merged

feat: add support for URL in "packageManager" #359

merged 20 commits into from
Feb 20, 2024

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented Jan 22, 2024

Fixes: #354

@aduh95 aduh95 marked this pull request as ready for review January 22, 2024 22:23
@aduh95 aduh95 marked this pull request as draft January 22, 2024 22:38
@aduh95
Copy link
Contributor Author

aduh95 commented Jan 22, 2024

This PR still lacks a protection for the built-in package manager (Corepack should not silently use a non-official Yarn/PNPM/npm version, unless there's some env variable that explicitly opt-into that)

@aduh95
Copy link
Contributor Author

aduh95 commented Jan 23, 2024

I'm sure how to handle the corepack pkgName --version, when pkgName is not one of the supported package managers – I guess we'd need a new command, e.g. corepack run pkgName --version, but I figured I'd better get some reviews first to see if I'm going in a wrong direction.
Code could use some cleanup, I'm not very proficient in TS, if someone wants to refactor to make it more readable, be my guest.

README.md Show resolved Hide resolved
@aduh95 aduh95 marked this pull request as ready for review January 30, 2024 18:39
sources/corepackUtils.ts Outdated Show resolved Hide resolved
sources/types.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
tests/_runCli.ts Outdated Show resolved Hide resolved
@Raedalmalki250

This comment was marked as off-topic.

sources/corepackUtils.ts Outdated Show resolved Hide resolved
}

export function isSupportedPackageManagerLocator(locator: Locator): locator is SupportedPackageManagerLocator {
return !locator.isURL;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this isURL property? Why not just do a URL.canParse(locator.reference) like we do with descriptors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to avoid calling URL.canParse more than one – it's a way to cache the value rather than re-compute it every time we need it.

Copy link
Contributor

@arcanis arcanis Feb 16, 2024

Choose a reason for hiding this comment

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

That feels a little unnecessary imo, we're only going to make a single such check per command, I doubt it'd have a significant perf impact compared to the complexity cost.

I'd also tend to just check whether the string startsWith('https://') rather than validate the full correctness - validating everything feels a little too susceptible to typos (what if I add a character that makes the string an invalid url? should it go in the semver path?).

Copy link
Contributor Author

@aduh95 aduh95 Feb 16, 2024

Choose a reason for hiding this comment

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

what if I add a character that makes the string an invalid url? should it go in the semver path?

In all likeliness, an invalid URL due to a typo won't be a valid semver version either, so I don't think it matters.

validating everything feels a little too susceptible to typos

Well we can only work with well formed reference (either semver or URL), so I'm not sure where you going with that, I don't see how we could be forgiving, we need full correctness.

That feels a little unnecessary imo, we're only going to make a single such check per command, I doubt it'd have a significant perf impact compared to the complexity cost.

I feel like I'm missing something, I don't see how it can be simplified (except maybe by using URL instances) – because otherwise TS cannot differenciate between the URL-based spec and the semver-based ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

because otherwise TS cannot differenciate between the URL-based spec and the semver-based ones.

Why does it need to differenciate? That's the same thing we do in Yarn: we treat all ranges the same (as string), and we just branch their behaviour by runtime pattern matching. I don't see what we gain by using strict typing here.

sources/corepackUtils.ts Outdated Show resolved Hide resolved
Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

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

We'll need a fallback / polyfill for URL.canParse or drop support for some Node.js versions.

https://nodejs.org/docs/latest-v21.x/api/url.html#urlcanparseinput-base specifies that it was added in v19.9.0, v18.17.0 and our engines.node specifies that we support >=18.17.1.

@aduh95
Copy link
Contributor Author

aduh95 commented Feb 14, 2024

I think we dropped support for Node.js 19.x when it went EOL a while back, although I reckon it wouldn't hurt to specify that in the engines field.

@merceyz
Copy link
Member

merceyz commented Feb 16, 2024

I reckon it wouldn't hurt to specify that in the engines field.

Keep in mind that's a breaking change, could you do it in a separate PR?

sources/specUtils.ts Outdated Show resolved Hide resolved
@aduh95 aduh95 requested a review from arcanis February 16, 2024 15:57
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.

Loosen packageManager field to support any package on npm
5 participants