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

build.bootstrap could take grunt.initConfig obj as param #1

Open
andrewk opened this issue Feb 25, 2014 · 3 comments
Open

build.bootstrap could take grunt.initConfig obj as param #1

andrewk opened this issue Feb 25, 2014 · 3 comments

Comments

@andrewk
Copy link
Member

andrewk commented Feb 25, 2014

This would prevent the need for "call grunt.initConfig first!" warnings in the docs.
build would simply call grunt.initConfig internally.

build.bootstrap({
    paths: {
            css: {
                src: 'src/scss',
                dist: 'dist/css'
            },
            js: {
                src: 'src/js',
                dist: 'dist/js'
            }
        }
});
@xzyfer
Copy link
Member

xzyfer commented Feb 25, 2014

I see what you're getting it here but it only solves half the grunt.initConfig issue.

There a couple problems here:

  1. Users expect to call grunt.initConfig in their Gruntfile, and all of the internet tells them that's what they should be doing it
  2. Calling grunt.initConfig resets all existing config, so either we nuke their config, or they nuke ours.

Calling build.bootstrap after the consumer's config has been set also has many benefits such being able to detect what plugins they're using so we can do the minimum amount of interfering.

This doesn't mean we can't still pass the paths object into bootstrap, but we'd then also need to pass it into the getSassLoadPaths and getRequireJSComponents methods as well.

All in all to be safe build.bootstrap needs to be call as late as possible in the grunt bootstrapping process. It'd be great if grunt supplied this mechanism.

@andrewk
Copy link
Member Author

andrewk commented Feb 25, 2014

Sure, I figured there would be complexities.

My real point is that comments of "dont do this or bad things will happen!" is a failing of the API. Build tools already has access to the grunt module, can it inspect grunt to see if its received its config and exit gracefully (with a meaningful error message) if it has not?

@xzyfer
Copy link
Member

xzyfer commented Feb 25, 2014

Build tools already has access to the grunt module, can it inspect grunt to see if its received its config

I'm not sure I'm following. The only mechanism we have for determining what plugins are being used, is simply inferring it from the config that's been set. So if build.bootstrap is called before the config is initialised we have no information to base our decisions on.

For example if an application is already using sass in Gruntfile, then they're almost certainly going to have something like this:

grunt.initConfig({
  sass: {
    dist: {
      files: [{
        expand: true,
        cwd: 'styles',
        src: ['*.scss'],
        dest: '../public',
        ext: '.css'
      }]
    }
  }
});

If you call build.bootstrap before that grunt.initConfig there's no way for use to determine if you're already using sass. If we were to go ahead and set our sass config, the impending grunt.initConfig would overwrite what we just set.


I agree it's not ideal. A possible solution is to clone the config, and reinitialise it with the old values. I'm fairly sure it'll work, but I'm not confident there won't be unintended side effects. It's worth looking into and should probably be it's own ticket.

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

2 participants