Skip to content
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

Module or package specific configuration (with config overrides) #219

Closed
webpro opened this issue Sep 4, 2013 · 9 comments
Closed

Module or package specific configuration (with config overrides) #219

webpro opened this issue Sep 4, 2013 · 9 comments

Comments

@webpro
Copy link
Contributor

webpro commented Sep 4, 2013

How can I add module-specific configuration with curl? E.g. packages: [{ name: 'bar', location: 'foo', main: 'core', config: {foo:1} }].

This completely confuses curl it seems. The "proposed standard" way also doesn't seem to work (https://github.com/amdjs/amdjs-api/wiki/Common-Config#config-).

I can request module.config() in a module, yet I don't know how to add data in the main config.

@unscriptable
Copy link
Member

This completely confuses curl it seems.

Can you elaborate? This feature works fine in my tests.

curl.config({ packages: [{ name: 'bar', location: 'foo', main: 'core', config: {foo:1} }] });

//... later, in a module in the bar package:

var cfg = module.config ? module.config() : {};
var foo = cfg.foo;

@webpro
Copy link
Contributor Author

webpro commented Sep 4, 2013

A bit time-consuming to set up a proper test case, but I will if needed.

If I put a config property like you did, and after this I'm doing another call to curl.config() (also containing packages), then that second config is not applied. If I combine the configs into one call, it works fine.

@unscriptable
Copy link
Member

Interesting. That's the opposite of what I would have expected. As a work-around until I test this, you could try something like the following if there is only one module that needs module.config() (curl 0.8 or higher):

curl.config({
    paths: {
        'core/module-that-needs-config': { location: 'core/module-that-needs-config', config: { foo: 1 } }
    }
});

@webpro
Copy link
Contributor Author

webpro commented Sep 4, 2013

Thanks for the work-around, that works fine. Obviously I'm interested in a possible fix.

@unscriptable
Copy link
Member

Yes. Let's keep this issue open until I have a chance to look into the problem further. :)

@CNSKnight
Copy link

I've been grappling with similar:

Specifically, curl package will not use paths:{} not defined in the original config object.

This, taken from my bootstrapping config.js.config.js has no effect:

        {
            name: 'MyPkg',
            location: 'path/to/templates',
            main: 'js/my-package.source',
            // config options specific to MyPkg
            config: {
                paths: {
                    foo: 'path/to/foo',
                    bootstrap: 'sample/path/to/bootstrap.js'
                }
            }
        }

...and doing this in the above package module throws error (see below)

curl.config({
        paths: {
            bootstrap: 'path/to/bower_components/bootstrap-sass-official/assets/javascripts/bootstrap.js'
        }
});

define(['firstPkg', 'some/js/module.source', 'js!bootstrap'], function(exposure1, exposure2) {
        // sidenote: module property is not available here in a package 'module'?

        return exposure1;
});

Error thrown:

            // adds the path matching regexp onto the cfg or plugin cfgs.
            function convertPathMatcher (cfg) {
                var pathMap = cfg.pathMap;
                cfg.pathRx = new RegExp('^(' +
                    cfg.pathList.sort(function (a, b) { return pathMap[b].specificity - pathMap[a].specificity; } )
X Uncaught TypeError: Cannot read property 'specificity' of undefined
                        .join('|')
                        .replace(/\/|\./g, '\\$&') +
                    ')(?=\\/|$)'
                );
                delete cfg.pathList;
            }

To be clear, defining the 'bootstrap' path in the paths hash of the mentioned bootstrapping config.js works fine.

@unscriptable
Copy link
Member

Hey @CNSKnight,

I think it's highly unlikely that curl will offer per-package paths and packages configuration as you've shown. When implementing the per-package configuration feature, we realized that the complexity of curl's internals would increase significantly. Of course, we could refactor and/or rewrite curl's internals, but that would take some time.

At the moment, we're spending most of our module-focused efforts on rave. Rave already handles per-package mappings automatically (without configuration).

Yes, rave is still under development, but it sounds like you have a work-around that you can use for now?

I'm going to close this issue, but please keep posting if you need additional help on your work-around.

Regards,

-- John

@CNSKnight
Copy link

Gotit. Meantime, let's update the docs to to that effect.
Still makes it challenging to do tru drop-in modular development but I'll work w/what we got & wait a bit on your rave effort.

Best

@unscriptable
Copy link
Member

Done: 38fbed6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants