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

Dependency version resolution? #9

Closed
mbostock opened this issue May 10, 2018 · 0 comments
Closed

Dependency version resolution? #9

mbostock opened this issue May 10, 2018 · 0 comments

Comments

@mbostock
Copy link
Member

Per observablehq/stdlib#27, we need require to support version resolution for dependencies rather than always loading the latest version. While this is theoretically possible by passing in a resolver function, there are some issues:

First, the resolver function is currently synchronous; we need it to be asynchronous to allow it to load the package.json and resolve the dependency version. (We’d also want multiple async calls to the resolver to be canonicalized so as to avoid fetching the same package.json more than once, though possibly that could happen inside the resolver.)

Second, we should provide a default resolver that understands the module[@range][/path] supported by unpkg. It would fetch the package.json to resolve the exact version of the requested module, and resolve the entry point if a path was not specified. For example, if you said:

require("d3@5")

This would fetch the package.json here:

https://unpkg.com/d3@5/package.json

The resolver could then identify the exact requested version (such as 5.3.0) and the desired entry point (such as dist/d3.min.js). The resolved URL would then be:

https://unpkg.com/d3@5.3.0/dist/d3.min.js

This would be loaded as a script as normal. This would also ensure that any other equivalent request for d3, such as

require("d3@5.3")

would resolve to the same exact module (without loading it again).

Third, we may want this default resolver to support an amd entry point. This would allow the d3 default bundle to provide an AMD-specific entry point that would then load the thirty D3 modules separately rather than loading a monolithic bundle. This would allow you to use the d3 default bundle in conjunction with non-core D3 modules such as d3-geo-projection without duplicate loading.

(As an alternative to the third issue, we could support named module definitions like the RequireJS optimizer, so that the d3 default bundle could define the D3 modules from a single file, but this seems questionable because you don’t want to allow any module to define the contents of any other module! In theory if the thirty modules are cached, it should be fast to load…)

mbostock added a commit that referenced this issue May 10, 2018
Fixes #9. This commit allows the resolver to be asynchronous, and changes the
default resolver to resolve the version of dependencies by loading the
package.json from unpkg. The package.json is also used to resolve the exact
version and file of a requested module such that equivalent requests (such as
for d3-array and d3-array@1) are coalesced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant