cujojs / when

A solid, fast Promises/A+ and when() implementation, plus other async goodies.
Other
3.44k stars 396 forks source link

Bower package.json 'main' is missing files #421

Closed chrylis closed 9 years ago

chrylis commented 9 years ago

The package.json for when.js only includes the top-level when.js file in the main attribute. The main needs to include all necessary files, and when.js apparently also needs a number of files from the lib/ directory.

When using tools such as Mimosa that only copy the "main" files into the vendor tree for a project, when.js fails because these other files are not present.

sompylasar commented 9 years ago

The package.json is used by npm, and npm downloads the whole package, then uses main as the entry point to get the object returned by require('when').

Bower uses bower.json.

unscriptable commented 9 years ago

Hey @chrylis,

While the spec for package.json (npm) is clear and consistent, the spec for bower.json is problematic. When the bower folks created the spec, they had no knowledge of module systems (or at least decided to ignore them). They therefore decided not to take npm's lead wherein "main" declares the main entry point of the code base.

Instead, there seems to be some ongoing confusion within the bower ecosystem about whether "main" means "main entry point" or "all the files necessary to use a minimal or default set of the code base". Libraries that don't use a module system (I.e. global scripts) tend to use the latter definition, unfortunately.

Furthermore, many tools assume the former definition to be consistent with npm, but some assume the latter because they were built to deal with global scripts rather than modules.

I don't know anything about mimosa, but many tools have an alternate mechanism to deal with modular code bases. Perhaps mimosa does too?

briancavalier commented 9 years ago

@chrylis I think the thing to do here is to figure out if mimosa supports an alternate way of specifying what files need to be included in a mimosa build.

As a similar example, ender looks at an "ender" key in package.json to list the files that should be included in an ender build. Or perhaps the files can be listed in a mimosa-specific config file in your project?

unscriptable commented 9 years ago

I've also seen this common problem solved via gulp and grunt plugins, so I have to wonder about a mimosa plugin (if such a concept exists).

chrylis commented 9 years ago

Mimosa does use plugins. In this case, it also appears that there are some issues with RequireJS, which goes all twitchy with the relative module paths (./lib/foo) For now, as I'm still working to get my head around the subtleties of AMD relationships (and lots of JavaScript in general), I'm going with a more trivial promise library that does the basics I need right now, but I'd like to figure this out so I can use rest.js in the future.

As a workaround for the copying issue, I can specify per-Bower-component overrides that include all of the necessary files; this is how I got to the point where RequireJS got snippy (which seemed to have something to do with not being able to specify an alternate location for an entire module prefix, such as when/). Mimosa and the Bower docs both seem to indicate that main should list all of the files required at runtime, though.

unscriptable commented 9 years ago

The future of bower is uncertain (partly due to ambiguous specifications and internal disagreements such as the meaning of main). Perhaps you should consider using npm instead? It's pretty easy to switch.

briancavalier commented 9 years ago

@chrylis when.js works great with RequireJS. My guess is that you've configured when.js using a path rather than a package. Have a look at the AMD install docs for an example of how to configure using a package.

Mimosa and the Bower docs both seem to indicate that main should list all of the files required at runtime

The official docs say either string or array, and "The primary acting files necessary to use your package". There is also not much guidance here in the bower.json "spec".

It is typical only to list the one main entry point for a modular JavaScript package as a single string in bower.json. Many packages do this. For a package such as when.js that expresses its dependencies using the module system, tools can discover the dependency graph via the modules themselves. It seems like mimosa may not have that capability. Other tools, such as webpack and browserify do handle that.

I don't know much about mimosa, but if npm is an option, I agree with @unscriptable that it would be worth investigating.

briancavalier commented 9 years ago

Ping @chrylis. I'm inclined to close this, since it seems like mimosa is the outlier. If there's some way we can help without deviating from the de facto standard of listing the one main module, feel free to reopen this, or create a new issue, and we can discuss further.