anodynos / uRequire

The Ultimate JavaScript Module Builder & Automagical Task Runner. Convert AMD & CommonJS/NodeJS modules to UMD, AMD, CommonJS or bundle them as `combined.js` (rjs & almond, AMDclean soon) & automagically run/test/watch them on nodejs, Web/AMD or Web/Script. Declarative & DRY config with inheritance. Manipulate & inject dependencies, module code, banners, version etc while building with a single line. Support two kinds of plugins, ResourceConverter (i.e file level) and AfterBuilder (i.e the whole bundle). Transparent support for Coffeescript, IcedCoffeescript, Coco, LiveScript – they’re just JavaScript :-)
http://anodynos.github.io/uRequire
MIT License
265 stars 20 forks source link

Handle commonjs require('./someDirName') #34

Closed anodynos closed 10 years ago

anodynos commented 11 years ago

CommonJs/nodejs has require('./someDirName') which simply looks and requires './someDirName/index.js'

/someDirName/
   - moduleA.js
   - moduleB.js

where require('./someDirName') would return a generated object

{ moduleA: require('moduleA'),  moduleB: require('moduleB') }

What about nested subdirectories inside 'someDirName' ?

willprice commented 10 years ago

If one were to implement this (importing index.js), which test cases would be the most relevant to look at? I might have a bash at this.

anodynos commented 10 years ago

Unfortunatelly the /process directory is fabulously absent from the unit tests :-( That where reading filenames and instantiating BundleFiles takes place.

In short we need to replace dependencies like 'some/path/directory' to 'some/path/directory/index' (when index.js is present), so it works on AMD/UMD properly. I'll have a look on how to hack this quickly, so I can perhaps implement it or guide you to have a bash at it.

anodynos commented 10 years ago

The 'dirname/index.js' case is best handled at Dependency and be transparent in all other parts - Ill have a go about it.

willprice commented 10 years ago

Awesome, thanks.

On 13 August 2014 20:32, Agelos Pikoulas notifications@github.com wrote:

The 'dirname/index.js' case is best handled at Dependency https://github.com/anodynos/uRequire/blob/master/source/code/fileResources/Dependency.coffee and be transparent in all other parts - Ill have a go about it.

— Reply to this email directly or view it on GitHub https://github.com/anodynos/uRequire/issues/34#issuecomment-52098489.

[image: --] Will Price [image: http://]about.me/will_price http://about.me/will_price

anodynos commented 10 years ago

Hey @willprice check it out - appending /index in the dependency should work on both commonjs and AMD/UMD in version 0.6.19. Let me know if it worked OK for your project.

Note that the 2nd part (automatic generation of index.js) is not dealt with - you need to have index.js or index.coffee etc in place