-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1bf182
commit 4c71009
Showing
6 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ExactPackage, LatestPackageTarget } from "../install/package.js"; | ||
import { Resolver } from "../trace/resolver.js"; | ||
// @ts-ignore | ||
import { fetch } from '#fetch'; | ||
|
||
const cdnUrl = 'https://deno.land/x/'; | ||
|
||
export function pkgToUrl (pkg: ExactPackage) { | ||
return cdnUrl + pkg.name + '@v' + pkg.version + '/'; | ||
} | ||
|
||
export function parseUrlPkg (url: string): ExactPackage | undefined { | ||
if (!url.startsWith(cdnUrl)) | ||
return; | ||
const path = url.slice(cdnUrl.length); | ||
const versionIndex = path.indexOf('@v'); | ||
if (versionIndex === -1) | ||
return; | ||
const sepIndex = path.indexOf('/', versionIndex); | ||
return { registry: 'deno', name: path.slice(0, versionIndex), version: path.slice(versionIndex + 2, sepIndex === -1 ? path.length : sepIndex) }; | ||
} | ||
|
||
export async function resolveLatestTarget (this: Resolver, target: LatestPackageTarget, unstable: boolean, _layer: string, parentUrl: string): Promise<ExactPackage | null> { | ||
const { registry, name, range } = target; | ||
|
||
if (range.isExact) | ||
return { registry, name, version: range.version.toString() }; | ||
|
||
if (!range.isWildcard) | ||
throw new Error(`Version ranges are not supported looking up in the Deno registry currently, until an API is available.`); | ||
|
||
const fetchOpts = { ...this.fetchOpts, headers: Object.assign({}, this.fetchOpts.headers || {}, { 'accept': 'text/html' }) }; | ||
const res = await fetch(cdnUrl + name, fetchOpts); | ||
if (!res.ok) | ||
throw new Error(`Deno: Unable to lookup ${cdnUrl + name}`); | ||
return parseUrlPkg(res.url); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Generator } from '@jspm/generator'; | ||
import assert from 'assert'; | ||
|
||
const generator = new Generator({ | ||
mapUrl: new URL('../../', import.meta.url), | ||
defaultProvider: 'deno' | ||
}); | ||
|
||
await generator.install('oak@10.6.0'); | ||
|
||
const json = generator.getMap(); | ||
|
||
assert.strictEqual(json.imports['oak'], 'https://deno.land/x/oak@v10.6.0/mod.ts'); |