Skip to content

Resolve, and perhaps control, versions of imported libraries? #135

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

Closed
mbostock opened this issue Nov 9, 2023 · 1 comment · Fixed by #303
Closed

Resolve, and perhaps control, versions of imported libraries? #135

mbostock opened this issue Nov 9, 2023 · 1 comment · Fixed by #303
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@mbostock
Copy link
Member

mbostock commented Nov 9, 2023

In client.js, we currently load the latest versions of recommended libraries such as D3, Observable Plot, and KaTeX. I think this has a lot of nice properties — it means folks aren’t waiting for us to update the CLI in order to use the latest versions of these libraries so bug fixes and new features automatically reach users, and it’s a lot less work for us to keep updating and re-releasing the CLI whenever recommended libraries have new releases.

But the downside is that users don’t have a way to pin versions to prevent automatic upgrades, if desired. Perhaps in the project’s config file we could expose a dependencies map similar to package.json. This could specify both the semver range for a dependency, and whether it’s loaded from jsDelivr or another CDN or self-hosted. (Related #20.) Perhaps also we could automatically capture unpinned versions the first time they are referenced? Or perhaps we could warn if they are unpinned, and provide a command such as observable add npm:d3 for pinning a dependency?

@mbostock mbostock added enhancement New feature or request question Further information is requested labels Nov 9, 2023
@mbostock mbostock added this to the Future milestone Nov 13, 2023
@mbostock mbostock changed the title Control versions of recommended libraries? Resolve, and perhaps control, versions of imported libraries? Dec 2, 2023
@mbostock
Copy link
Member Author

mbostock commented Dec 2, 2023

Generalizing this:

  • We want version control not just for recommended libraries, but any npm: protocol import
  • Even if you can’t specify a semver range, it’d be good to resolve the version at build time

In particular, resolving the version of an npm library at build time will avoid some cases where we load duplicate copies of a library. For example, if you load npm:htl and you load npm:@observablehq/inputs which depends on npm:htl, you get two copies of npm:htl because the direct request isn’t versioned (and jsDelivr doesn’t redirect to the versioned request):

Resolving exact versions has the further benefit that you get immutable caching. 🚀

jsDelivr has a nice API for this: https://www.jsdelivr.com/docs/data.jsdelivr.com#get-/v1/packages/npm/-package-/resolved

@mbostock mbostock mentioned this issue Dec 2, 2023
7 tasks
@mbostock mbostock self-assigned this Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant