joeybaker / remapify

Alias directories for browserify
Other
117 stars 23 forks source link

Invalid expandedAliases being provided to aliasify #6

Closed skubus closed 10 years ago

skubus commented 10 years ago

Hya all,

I'm running into issues concerning the expandedAliases being passed to aliasify. As I understand it, aliasify.configure expects an object with aliases formatted as {alias: path/to/alias}, so that I may later require('alias'). Unfortunately the alias attribute is being garbled.

My directory setup is as follows:

├── Gruntfile.js
└── source
    ├── config.js
    └── init.js

I wish to call the config in the init.js (and elsewhere, but the init serves as proof of concept) via require('config'). I've added remapify as a plugin to browserify in the Gruntfile:

preBundleCB: function (b) {
    b.plugin(remapify, {
        src: 'source/config.js',
        expose: 'config',
        cwd: __dirname,
        config: {verbose: true}
    });
}

Now I would expect mapify to pass something like {config: 'absolute/path/to/source/config.js'} to aliasify. Instead, when I log the expandedAliases object in the globMatch callback, I receive following output:

{
    'config/source/config.js': 'absolute/path/to/source/config.js',
    'config/source/config': 'absolute/path/to/source/config.js'
}

The attributes keys look kind of strange to me (and my require('config') barks errors at me). On the other hand, if I replace:

expandedAliases[path.join(pattern.expose || '', file)] = filePath
expandedAliases[path.join(pattern.expose || '', file.replace(/\.js$/, ''))] = filePath

with

expandedAliases[pattern.expose] = filePath

this object is passed to aliasify: {config: 'absolute/path/to/source/config.js'}. All is well (I can access the config via require('config') without a problem).

Is this a configuration/set-up error on my part? Where am I going wrong?

Thank-you in advance for any support. :)

dwick commented 10 years ago

You need to use the cwd option to get what you want:

preBundleCB: function (b) {
    b.plugin(remapify, {
        src: 'config.js',
        expose: 'config',
        cwd: 'path/to/source',
        config: {verbose: true}
    });
}