-
Notifications
You must be signed in to change notification settings - Fork 285
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
Some devDependencies should be dependencies? #3
Comments
The distinction between devDepedencies and dependencies is an NPM concept, not an ES6 concept. They are listed as devDepedencies because you can If you’re running d3-bundler (the thin wrapper on Rollup) inside the d3-scale repo, then yes, you’ll need to install the devDependencies. That’s standard practice when you are doing development inside a repository (as opposed to just using If you’re running d3-bundler outside the d3-scale repo (as demonstrated by the examples in the d3-bundler repo), then you’ll need to install the d3-scale dependencies explicitly at the top level. That’s because d3-bundler requires all the modules to be at the top-level, so that there’s no duplication if multiple modules share the same dependencies. For example, both d3-scale and d3-interpolate depend on d3-color, and you don’t want to rollup two copies of that code. So, if you want to just import
You also need to install d3-bundler, but you can do that globally if you prefer:
Then you need to define an index module that imports and re-exports whatever code you want to use. Here’s a simple example import {linear} from "d3-scale";
export default {
scale: {
linear: linear
}
}; Lastly, build the bundle: d3-bundler --format=umd --name=d3 -- index.js > d3.js In d3/d3-bundler#1, I mention having a |
Oh yes I see what you mean - thank you for the reminder that devDepedencies and dependencies relate only to the CommonJS build. That makes total sense the way you explain it, closing the issue. Thanks also for the info on how to create a custom D3 bundle. The d3-bundle work is very cool, but currently I am using your ES6 modules directly via Rollup in my own ES6 modules, not using d3-bundler at all (here's one example). I suppose in this case, I should include the ES6-land dependencies as devDependencies. I'm not sure if I am taking the right approach by using your ES6 modules directly via Rollup, perhaps I should start experimenting with using d3-bundler. It seems though that if my project is using ES6 and Rollup, it makes sense not to touch d3-bundler. I'm not sure.. |
Yeah. The only thing that’s different between d3-bundler and Rollup is that d3-bundler forces all external imports (e.g., |
I was under the impression that Rollup does exactly that, by looking at In an ideal world, it would be cool to have something like Indeed we are in the wild west of ES6, but the way you have set things up is the cleanest and simplest I have seen so far, and I'm thrilled that I can actually write code that depends on the new d3 modules via Rollup and NPM and actually works. |
The issue with Rollup as it currently stands is that it allows external imports to be resolved locally (like Node does), which can lead to duplicate code. I might be okay with duplicate code if the versions were different, but even with identical versions the external imports result in duplicate code. For example, let’s imagine that d3-scale depended on d3-color directly (it doesn’t, but imagine…), so its dependencies are: d3-arrays, d3-color, d3-format, and d3-interpolate. d3-interpolate also depends on d3-color. And again for the sake of argument lets say that these dependencies are listed in the package.json
If there’s code in d3-scale that says If you remove the d3-color from d3-interpolate, you no longer get duplicate code, but it seemed error-prone to allow external imports to be resolved this way. If people actually relied on this behavior to install nested dependencies, you can see how it would quickly duplicate code. Like imagine if d3-format also depended on d3-color: now you have three copies of it. So d3-bundler forces you to install it at the top-level. It sucks that this requires you knowing the transitive closure of all dependencies, but I think we can fix that by having d3-bundler compute the transitive closure of dependencies based on some initial set of direct dependencies… perhaps as The other thing that d3-bundler fixes is rollup/rollup#24 but that’s trivial. 😁 |
Oops, forgot rollup/rollup#24 was still open... will get to work on fixing that. Aye, it's vexed. Rollup's default resolver just mimics the node resolver, the only change being that it looks for Pragmatically, I think d3-bundler supplying a custom resolver is the best solution, at least for the moment. Ultimately we need a package manager and a bundler that work together to solve these problems, and I think JSPM will be it (some progress towards integrating Rollup into JSPM here). That doesn't solve @curran's problem though. I wonder if the solution for people who want to use D3's ES6 modules without using d3-bundler is for there to be a master |
Or, if the JSPM dependencies can be declared like this:
In this way, JSPM could be used solely as a package manager, and Rollup could be used solely as a bundler. The two tools don't really need to know about each other to be used together in a development workflow. Just an idea.. I did some experiments: If I run:
The following
At this point if I delete
Then JSPM generates the following directory structure:
So JSPM basically does the installing that we need (and it does install transitive dependencies). However it seems like it also does some things that we don't need if we are using it just to install packages, like the intermediate files e.g.
It also installs System.js (and I see no way to turn this off), which we also don't need if we are using Rollup for bundling. Lastly it generates a In order to make this work, Rollup needs to know how to resolve external imports that live in the JSPM directory structure. This could be implemented by a simple resolver that looks into It would be ideal if JSPM and Rollup could be used together, and the only thing that would need to change is
I wonder if @guybedford has thought about this case - where one wants to use JSPM as a package manager only, and not as a bundler, and without SystemJS. |
@mbostock
is no longer an issue. ( Given this, would you reconsider moving hard This is what extremely popular libraries like The current method makes it much more difficult for bundlers to de-duplicate code, and essentially forces the use of I realize this is just a stepping stone on the road to ES6 modules anyway, but it would be a really nice improvement in the meantime. (And just to be clear, you would still use ES6 modules in the source, but have Rollup compile to CommonJS imports for the npm build.) TL;DR: switching to |
Thanks for the suggestion, @billyjanitsch. I’ve switched the devDependencies on other D3 modules to be dependencies (across all D3 modules), and upgraded to the latest version of Rollup. The |
The one you linked is intentional: d3-arrays is only used by d3-random for testing. If you find another one that’s incorrect, please let me know. |
Ah, my mistake, sorry. |
I noticed that
d3-interpolate
andd3-format
are listed underdevDependencies
rather thandependencies
inpackage.json
, however they are hard dependencies (as in, the Rollup build breaks if they are not installed). Perhaps these should be promoted to dependencies?Here are some notes from my experience trying to use only the ticks functionality of
d3-scale
:When importing
linear
fromd3-scale
, I get the following error when running Rollup:Could not find package d3-interpolate (required by /Users/curran/repos/data-reduction/node_modules/d3-scale/src/linear.js)
Also, after I
npm install d3-interpolate
, I get another error:Could not find package d3-color (required by /Users/curran/repos/data-reduction/node_modules/d3-interpolate/src/interpolators.js)
Now I need to install
d3-color
to used3-scale
, however I just want to use the ticks functionality fromd3-scale
. This feels like it should not be necessary.After installing
d3-color
, I get another error:Could not find package d3-format (required by /Users/curran/repos/data-reduction/node_modules/d3-scale/src/tickFormat.js)
After installing
d3-format
, the build works. In the end, it is necessary to installd3-interpolate
,d3-color
andd3-format
in order to use the tick generation functionality from d3-scale.The text was updated successfully, but these errors were encountered: