disnet / contracts.js

Contract library for JavaScript
http://www.contractsjs.org
MIT License
149 stars 8 forks source link

"contracts.js" gives RequireJS trouble #14

Closed kennknowles closed 11 years ago

kennknowles commented 11 years ago

I have a project that is tested both with node and with RequireJS. Unfortunately, the module name "contracts.js" for node makes RequireJS believe this is a relative import (see http://requirejs.org/docs/api.html#jsfiles) rather than an installed package.

disnet commented 11 years ago

It's being defined as contracts not contracts.js here. Are you running into problems trying to load just contracts?

disnet commented 11 years ago

Oh! But node forces you to call it contracts.js. Reading comprehension. Yeah, I see the problem now.

disnet commented 11 years ago

I guess renaming the npm package makes the most sense right? Maybe "contracts-js".

kennknowles commented 11 years ago

Yea, exactly. Works fine in each context, just not in both via the same code. I do think "contracts-js" will work.

disnet commented 11 years ago

Pushed "contracts-js" so it should work now.

kennknowles commented 11 years ago

Awesome, thanks!

kennknowles commented 11 years ago

Just took a shot at integrating this, and I'm afraid there's another snag: Coffee compiles to a named module, see https://github.com/disnet/contracts.js/blob/master/lib/contracts.js#L1566

So actually in RequireJS one must call it "contracts" but when using node+amdefine one must call it "contracts-js"

kennknowles commented 11 years ago

Hmm, the "paths" config may be able to sort this out; I'll try it. Unfortunately, I think the only workaround-free solution is to have the file, module, and npm package share a name.

disnet commented 11 years ago

Changed the module name, do we really need the filename to be the same?

kennknowles commented 11 years ago

Probably not, actually. I was imagining module systems that always base the module name on the file name, of which I thought RequireJS was one until I saw the named define in this code. Thanks! I'll try this out shortly.