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

deno as defaultProvider is loading depdendencies from npm #367

Open
JayaKrishnaNamburu opened this issue Jul 12, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@JayaKrishnaNamburu
Copy link
Member

When passing defaultProvider as deno to Generator. The dependencies should be loaded from denoland. But instead the dependencies are being loaded from npm but they are loading from denoland if users pass denoland protocol for the package name.

Here are some examples

const generator = new Generator({
  defaultProvider: "deno",
});
await generator.install("zod");
await generator.install("lodash");

console.log(
  `Installing by passing defaultProvider as deno \n`,
  JSON.stringify(generator.getMap(), null, 2),
);

Will result in an importmap of

{
  "imports": {
    "lodash": "https://ga.jspm.io/npm:[email protected]/lodash.js",
    "zod": "https://ga.jspm.io/npm:[email protected]/lib/index.mjs"
  }
}

The dependencies are loaded from ga.jspm.io with npm: as prefix for protocol.

When we pass the protocol for the package name. Then it loaded from deno registry.

const generatorNPM = new Generator();
await generatorNPM.install("denoland:zod");
await generatorNPM.install("lodash");
console.log(
  `Installing by passing denoland: protocol for the dependency \n`,
  JSON.stringify(generatorNPM.getMap(), null, 2),
);

Will result in an importmap of

{
  "imports": {
    "lodash": "https://ga.jspm.io/npm:[email protected]/lodash.js",
    "zod": "https://deno.land/x/[email protected]/mod.ts"
  }
}

Here the package zod comes from denoland since the protocol is denoland. But we can see the package loadash is coming from npm here as expected.

Let's try the same with skypack

const generatorSkypack = new Generator({
  defaultProvider: "skypack",
});
await generatorSkypack.install("zod");
console.log(
  `Installing by passing defaultProvider as skypack \n`,
  JSON.stringify(generatorSkypack.getMap(), null, 2),
);

This will result in an import of

{
  "imports": {
    "zod": "https://cdn.skypack.dev/[email protected]/mod.ts"
  }
}

Here the package loads from skypack respecting the defaultProtocol that is passed to the generator.
Sandbox for the same to test.

@JayaKrishnaNamburu JayaKrishnaNamburu added the bug Something isn't working label Jul 12, 2024
@JayaKrishnaNamburu
Copy link
Member Author

JayaKrishnaNamburu commented Jul 12, 2024

Looks like the bug might be from here
https://github.com/jspm/generator/blob/main/src/install/installer.ts#L137

if (opts.defaultRegistry) this.defaultRegistry = opts.defaultRegistry;

Before assigning the his.defaultRegistry. We need to do something like

if (opts.defaultRegistry) {
  this.defaultRegistry =
    registryProviders[`${opts.defaultProvider}:`] ?? opts.defaultRegistry;
}

So, when a provider of denoland is selected, it automatically assigns to denoland registry. The only issue i see for the approach is, the standard libs of deno are moved to jsr which in turn need to add support for jsr #366

@guybedford
Copy link
Member

We have two separate providers for Deno:

  • denoland the (now deprecated it seems) Denoland URLs which host packages for Deno
  • deno the Deno core libraries

That is, you would want to set defaultProvider: 'denoland' here.

@JayaKrishnaNamburu
Copy link
Member Author

Thanks for the clarification @guybedford. I am not aware of that, but looking like even when we set the defaultProvider to denoland. The import map seems to load from the ga.jspm.io

const generator = new Generator({
  defaultProvider: "denoland",
});
await generator.install("zod");
await generator.install("lodash");

console.log(
  `Installing by passing defaultProvider as deno land\n`,
  JSON.stringify(generator.getMap(), null, 2),
);

is generating

{
  "imports": {
    "lodash": "https://ga.jspm.io/npm:[email protected]/lodash.js",
    "zod": "https://ga.jspm.io/npm:[email protected]/lib/index.mjs"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants