observablehq / framework

A static site generator for data apps, dashboards, reports, and more. Observable Framework combines JavaScript on the front-end for interactive graphics with any language on the back-end for data analysis.
https://observablehq.com/framework/
ISC License
2.46k stars 117 forks source link

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

Open mbostock opened 10 months ago

mbostock commented 10 months ago

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 commented 5 months ago

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