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

Allow npm: protocol imports from JavaScript & TypeScript data loaders #288

Open
mbostock opened this issue Nov 30, 2023 · 1 comment · Fixed by #1229
Open

Allow npm: protocol imports from JavaScript & TypeScript data loaders #288

mbostock opened this issue Nov 30, 2023 · 1 comment · Fixed by #1229
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Nov 30, 2023

To further increase parity between JavaScript in Markdown and JavaScript in data loaders, we could add a loader that allows npm: protocol imports to be automatically loaded from jsDelivr, or we could resolve them to node_modules (just stripping the npm: prefix). For example, in npm-loader.js:

export function resolve(specifier, context, nextResolve) {
  return specifier.startsWith("npm:")
    ? {shortCircuit: true, url: `https://cdn.jsdelivr.net/npm/${specifier.slice("npm:".length)}/+esm`}
    : nextResolve(specifier, context);
}

And then adding additional args when running node for data loaders:

node --experimental-network-imports --loader ./npm-loader.js ./data.csv.js
@mbostock mbostock added the enhancement New feature or request label Nov 30, 2023
@cinxmo cinxmo added this to the Future milestone Jan 16, 2024
@mbostock mbostock removed this from the Future milestone Mar 24, 2024
@mbostock
Copy link
Member Author

mbostock commented May 3, 2024

Not fixed; erroneously closed by GitHub’s shorthand. 🤦

@mbostock mbostock reopened this May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants