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

question: export custom provider implemention "resolveLatestTarget" #314

Open
Bisstocuz opened this issue Jul 27, 2023 · 3 comments
Open

Comments

@Bisstocuz
Copy link
Contributor

Bisstocuz commented Jul 27, 2023

I wanna write a custom provider like unpkg.ts to use vite-plugin-jspm.

But these code below cannot work:

import { ExactPackage } from '@jspm/generator/src/install/package'

const cdnUrl = 'https://npm.<proxy-url>.com/'

export async function pkgToUrl(pkg: ExactPackage): Promise<`${string}/`> {
	return `${cdnUrl}${pkg.name}@${pkg.version}/`
}

const exactPkgRegEx = /^((?:@[^/\\%@]+\/)?[^./\\%@][^/\\%@]*)@([^/]+)(\/.*)?$/

export function parseUrlPkg(url: string) {
	if (!url.startsWith(cdnUrl)) return null
	const [, name, version] = url.slice(cdnUrl.length).match(exactPkgRegEx) || []
	if (name && version) {
		return { registry: 'npm', name, version }
	}
	return null
}

export { resolveLatestTarget } from '@jspm/generator/src/providers/jspm'

Vite reported:

X [ERROR] No known conditions for "./src/providers/jspm" specifier in "@jspm/generator" package [plugin externalize-deps]

How to call resolveLatestTarget outside of @jspm/generator?

@guybedford
Copy link
Member

Good point, it's not currently exposed. The best I can suggest right now would just be to copy and paste the implementation exactly.

@Bisstocuz
Copy link
Contributor Author

Good point, it's not currently exposed. The best I can suggest right now would just be to copy and paste the implementation exactly.

Another question is, if I tried to implement own resolveLatestTarget, the TypeScript will give a warning "cannot assign this: Provider to this: Resolver". I'm really getting numb from TypeScript.

@guybedford
Copy link
Member

This should definitely be easier... you're welcome to make any suggestions to the public interface to improve the user experience here.

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

No branches or pull requests

2 participants