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

Support URLs such as https://domain/@scope/package #53

Merged
merged 6 commits into from
Jan 20, 2022
Merged

Conversation

takker99
Copy link
Contributor

close #6

registry.ts Outdated
version(): string {
const { version } = this.parts();
if (version === undefined) {
throw Error(`Unable to find version in ${this.url}`);
Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's right. I should have paid more attention.
Thank you for your pointing. I'll fix it.

registry.ts Outdated
at(version: string): RegistryUrl {
const { parts, packageName } = this.parts();
parts[4] = `${packageName}@${version}`;
return new UnpkgScope(parts.join("/"));
Copy link
Owner

Choose a reason for hiding this comment

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

To decrease some boilerplate perhaps:

function defaultScopeAt(that: RegistryUrl): string {
   const { parts, packageName } = defaultParts(this);
   parts[4] = `${packageName}@${version}`;
   return parts.join("/");
}

could be pulled out or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks good!
I consider whether to merge defaultScopeAt into defaultAt like this:

export function defaultAt(
  that: RegistryUrl,
  version: string,
  hasScope = false,
): string {
  if (!hasScope) return that.url.replace(/@(.*?)(\/|$)/, `@${version}/`);

  const { parts, packageName } = defaultParts(that);
  parts[4] = `${packageName}@${version}`;
  return parts.join("/");
}

but this refactoring merely makes registry.ts little shorter, so I'll use the code you suggested.

@hayd
Copy link
Owner

hayd commented Jan 16, 2022

Wow, this is great. Slightly agree with your comment about boilerplate but this functionality will be fantastic to have.
So I am happy to merge if you are.

(That said, it might be good to test some erroring cases for the parser - i.e. things that throw. But.. looking at test file there aren't any for any of the REGISTRIES! 😳 )

@takker99 takker99 marked this pull request as ready for review January 19, 2022 03:33
@takker99
Copy link
Contributor Author

I'm sorry for late reply. I appreciate your review!
Would you review again and merge the PR?

registry.ts Outdated
packageName: string;
version: string;
}
function defaultParts(that: RegistryUrl): PackageInfo {
Copy link
Owner

Choose a reason for hiding this comment

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

nit: this should probably have been defaultInfo etc ? 😆
but it's fine.

registry.ts Outdated
version: string,
hasScope = false,
): string {
if (!hasScope) return that.url.replace(/@(.*?)(\/|$)/, `@${version}/`);
Copy link
Owner

Choose a reason for hiding this comment

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

This is probably too clever :), can you delete _defaultAt (unused I think) ?

Copy link
Contributor Author

@takker99 takker99 Jan 19, 2022

Choose a reason for hiding this comment

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

Oops! I forgot to delete this. Thanks!
(I wonder if there is such a lint feature which tells me unused export functions and values...)

@hayd
Copy link
Owner

hayd commented Jan 19, 2022

Thanks @takker99 , If you've tested this on a project or two I am happy to merge! 💪

@takker99
Copy link
Contributor Author

Thanks! I've fixed them!

@hayd
Copy link
Owner

hayd commented Jan 20, 2022

Fantastic! Thanks for this @takker99 , this is a very valuable feature.

@hayd hayd merged commit 7d917a0 into hayd:master Jan 20, 2022
@takker99 takker99 deleted the scope branch January 20, 2022 03:07
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.

unpkg (et al?) must have non-zero directory
2 participants