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

Add scope to config #636

Merged
merged 1 commit into from
May 19, 2023
Merged

Add scope to config #636

merged 1 commit into from
May 19, 2023

Conversation

johnpangalos
Copy link
Contributor

Use Case: Hosting private npm packages in a custom npm registry, like GitHub's npm registry, and that npm registry is not a mirror.

Issue: When using a custom npm registry you set the npmRegistry in the config and it downloads the correct npm package, but if you try and download any other package (such as a dependency) it fails because the custom npm registry does not contain any packages but private ones.

Solution: Use scope in the .npmrc, this seemed the easiest since the .npmrc file was being created anyway.

Not sure how to test this, any advice about that would be appreciated.

server/build.go Outdated
@@ -45,6 +45,15 @@ type BuildTask struct {
stage string
}

func removeHttpPrefix(s string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

i would like to put this function in utils.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, I'll move this.

if cfg.NpmRegistryScope != "" {
isInScope := strings.HasPrefix(name, cfg.NpmRegistryScope)
if !isInScope {
url = "https://registry.npmjs.org/" + name
Copy link
Member

Choose a reason for hiding this comment

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

can you explain this line a bit? thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is reproducing what npm does when you have a scope, where if the package you are trying to download is in the scope it goes to one registry and if it's not it goes to the default public registry.

Copy link
Member

Choose a reason for hiding this comment

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

i see, thanks

Copy link
Member

@ije ije left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for contributing

@johnpangalos
Copy link
Contributor Author

No problem, thanks for the prompt review!

@ije ije merged commit c8a940d into esm-dev:main May 19, 2023
@ije
Copy link
Member

ije commented May 19, 2023

hi @johnpangalos would you like to update the config.example.jsonc for the new config?

@johnpangalos
Copy link
Contributor Author

I can do that!

@ije
Copy link
Member

ije commented May 19, 2023

thanks!

johnpangalos added a commit to johnpangalos/esm.sh that referenced this pull request May 19, 2023
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.

2 participants