diff --git a/docs/docs/features/module-resolution.mdx b/docs/docs/features/module-resolution.mdx index 1198a9ec92..8e2e2e8096 100644 --- a/docs/docs/features/module-resolution.mdx +++ b/docs/docs/features/module-resolution.mdx @@ -135,6 +135,20 @@ If you want to bundle (and transpile) any import URL, prefix it with `bundle:` ( ::: +## pkg.pr.new + +Unpublished npm packages can be imported while still under development using the [pkg.pr.new](https://pkg.pr.new/) service. + +Use the prefix `pr:` or `pkg.pr.new:`. + +Example: + +```js +import { Bench } from 'pr:tinybench@a832a55'; +// or +// import { Bench } from 'pr:tinylibs/tinybench/tinybench@a832a55'; +``` + ## CDN Providers By default, npm modules are imported from [esm.sh](https://esm.sh/). You may choose another provider by using a CDN prefix. These are examples of importing the library `uuid`: @@ -165,6 +179,10 @@ By default, npm modules are imported from [esm.sh](https://esm.sh/). You may cho `jsr:@std/uuid` → https://esm.sh/jsr/@std/uuid ([info](https://esm.sh)) +`pr:tinybench@a832a55` → https://esm.sh/pr/tinybench@a832a55 ([info](https://esm.sh)) + +`pkg.pr.new:tinybench@a832a55` → https://esm.sh/pkg.pr.new/tinybench@a832a55 ([info](https://esm.sh)) + `jspm:uuid` → https://jspm.dev/uuid ([info](https://jspm.org) - [DEPRECATED](https://jspm.org/jspm-dev-deprecation)) Example: diff --git a/src/livecodes/services/__tests__/modulesService.spec.ts b/src/livecodes/services/__tests__/modulesService.spec.ts index 42b96379a6..c06f702c14 100644 --- a/src/livecodes/services/__tests__/modulesService.spec.ts +++ b/src/livecodes/services/__tests__/modulesService.spec.ts @@ -38,6 +38,12 @@ describe('modulesService', () => { expect(url('esm.sh:uuid')).toEqual('https://esm.sh/uuid'); + expect(url('jsr:uuid')).toEqual('https://esm.sh/jsr/uuid'); + + expect(url('pr:uuid@10')).toEqual('https://esm.sh/pr/uuid@10'); + + expect(url('pkg.pr.new:uuid@10')).toEqual('https://esm.sh/pkg.pr.new/uuid@10'); + expect(url('unpkg:uuid')).toEqual('https://unpkg.com/uuid?module'); expect(url('bundlejs:uuid')).toEqual('https://deno.bundlejs.com/?file&q=uuid'); diff --git a/src/livecodes/services/modules.ts b/src/livecodes/services/modules.ts index ffd853bf95..5ec3f1d25a 100644 --- a/src/livecodes/services/modules.ts +++ b/src/livecodes/services/modules.ts @@ -120,6 +120,10 @@ const TEMPLATES: Array<[RegExp, string]> = [ [/^(jsr:)(.+)/i, 'https://esm.sh/jsr/$2'], + [/^(pr:)(.+)/i, 'https://esm.sh/pr/$2'], + + [/^(pkg\.pr\.new:)(.+)/i, 'https://esm.sh/pkg.pr.new/$2'], + [/^(skypack:)(.+)/i, 'https://cdn.skypack.dev/$2'], [/^(jsdelivr:)(.+)/i, 'https://cdn.jsdelivr.net/npm/$2'],