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

fix: hook into deno.json for deno dependencies #290

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/install/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ export class Installer {
if (opts.defaultProvider)
this.defaultProvider = parseProviderStr(opts.defaultProvider);
this.providers = Object.assign({}, registryProviders);

// TODO: this is a hack, as we currently don't have proper support for
// providers owning particular registries. The proper way to do this would
// be to have each provider declare what registries it supports, and
// construct a providers mapping at init when we detect default provider:
if (opts.defaultProvider.includes("deno"))
this.providers["npm:"] ??= "jspm.io";

if (opts.providers) Object.assign(this.providers, opts.providers);
}

Expand Down
11 changes: 11 additions & 0 deletions src/providers/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SemverRange } from "sver";
// @ts-ignore
import { fetch } from "#fetch";
import { Install } from "../generator.js";
import { IImportMap, ImportMap } from "@jspm/import-map";

const cdnUrl = "https://deno.land/x/";
const stdlibUrl = "https://deno.land/std";
Expand Down Expand Up @@ -148,6 +149,16 @@ export async function getPackageConfig(
},
};
}

// If there's a package.json, return that:
const pkgJsonUrl = new URL("package.json", pkgUrl);
guybedford marked this conversation as resolved.
Show resolved Hide resolved
const pkgRes = await fetch(pkgJsonUrl.href, this.fetchOpts);
switch (pkgRes.status) {
case 200:
case 304:
return (await pkgRes.json()) as PackageConfig;
}

return null;
}

Expand Down
60 changes: 17 additions & 43 deletions test/providers/deno.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { Generator, lookup } from "@jspm/generator";
import assert from "assert";

{
const generator = new Generator({
defaultProvider: "deno",
});

await generator.install("denoland:fresh@1.1.5/runtime.ts");
const json = generator.getMap();

assert.strictEqual(
json.imports["fresh/runtime.ts"],
"https://deno.land/x/fresh@1.1.5/runtime.ts",
);
assert.ok(
json.scopes["https://deno.land/"]["preact"]
);
}

const denoStdVersion = (await lookup("deno:path")).resolved.version;
const oakVersion = (await lookup("denoland:oak")).resolved.version;

Expand Down Expand Up @@ -43,37 +60,6 @@ const oakVersion = (await lookup("denoland:oak")).resolved.version;
}
}

// {
// const generator = new Generator();

// await generator.link(new URL('./coremods/deno.js', import.meta.url).href);

// const json = generator.getMap();

// console.log(json);
// }

// {
// const generator = new Generator();

// await generator.install({ target: new URL('./coremods/', import.meta.url).href, subpath: './deno' });

// const json = generator.getMap();

// console.log(json);
// }

// {
// const generator = new Generator();

// try {
// await generator.link(new URL('./coremods/deno.notfound.js', import.meta.url).href);
// }
// catch (e) {
// console.log(e);
// }
// }

{
const generator = new Generator({
mapUrl: new URL("../../", import.meta.url),
Expand Down Expand Up @@ -222,16 +208,4 @@ const oakVersion = (await lookup("denoland:oak")).resolved.version;
json.imports["testing/asserts"],
`https://deno.land/std@0.148.0/testing/asserts.ts`
);

// await generator.update();

// {
// const json = generator.getMap();

// console.log(json);

// assert.strictEqual(json.imports['fs'], `https://deno.land/std@${denoStdVersion}/fs/mod.ts`);
// assert.strictEqual(json.imports['async/abortable.ts'], `https://deno.land/std@${denoStdVersion}/async/abortable.ts`);
// assert.strictEqual(json.imports['testing/asserts'], `https://deno.land/std@${denoStdVersion}/testing/asserts.ts`);
// }
}