Skip to content

pluginBuilder not applied when used as a sub-dependency that loads first #228

Closed

Description

@guybedford

I have a plugin module that defines a pluginBuilder -

moduleA.js::

define(function() {
  return {
    pluginBuilder: './pluginBuilder'
  };
});

Another plugin module requires that module as a dependency:

moduleB::

define(['moduleA'], function(A) {
  //...
});

I have a build that results in moduleB being used alongside moduleA.

{
  modules: [
  {
    name: 'core',
    create: true,
    include: ['moduleB!test', 'moduleA!test2']
  }
  ]
}

Then during the build, I am getting the version of moduleA without the pluginBuilder substitution run against the module 'test2'.

What I'd like is for 'moduleA' to be the pluginBuilder version during a build and the normal version outside a build. This allows moduleB to act like an 'extension' of moduleA sharing API calls.

Activity

  1. jrburke commented on Jul 17, 2012

    @jrburke
    Member

    Marking this for "next" consideration, which means that it may get included in the next bug fix build, but would not block a higher priority bug fix build if there were worse bugs in the queue.

  2. guybedford commented on Sep 19, 2012

    @guybedford
    Author

    I'm still in need of this support for some refactoring in RequireCSS. I want the css module to have an 'injection' api for dynamic css injection as well as the plugin injections.

    Basically, I think the main thing is to check if a module defines a "pluginBuilder" property before loading it as part of an optimized build. If it does, then to load that version, even when the load isn't a plugin-style load.

    Otherwise I think the work around for this is just to ensure that some dummy plugin load is run before the normal load to ensure it is defined this way from the start.

  3. jrburke commented on Sep 19, 2012

    @jrburke
    Member

    The "next" tag has not worked out as I hoped, putting this in the 2.1 bucket for consideration, but may get bumped to a later release.

  4. guybedford commented on Sep 24, 2012

    @guybedford
    Author

    I think the workaround above should work. In the end I didn't need this functionality, as the dynamic plugin use during an optimizer build turned out to be an unnecessary edge case. Rather put the time into 241 if you can!

  5. jrburke commented on Sep 29, 2012

    @jrburke
    Member

    OK, going to close this for now. We can reopen if there is a use case that really needs this to work.

  6. guybedford commented on Oct 1, 2012

    @guybedford
    Author

    I just realised this issue is actually critically affecting many of my plugins.

    If I have a plugin, which I load through a wrapper module, then during the build the wrapper module loads the plugin as a normal module. Because the plugin is loaded, the pluginBuilder config item is ignored. Thus plugins loaded via wrapper modules have no ability to specify a pluginBuilder!

  7. reopened this on Oct 1, 2012
  8. jrburke commented on Oct 2, 2012

    @jrburke
    Member

    This is tricky because moduleB wants to use moduleA in source form, because moduleB is used as a plugin, but then you want moduleA's pluginBuilder to be used when processing plugin resources handled by moduleA. I'm not sure how to support that right now because it basically means having two different module values for the same module ID. The loader just uses requirejs under the covers, and it does not support that concept.

    Unfortunately, I'm under a time constriction for getting 2.1 out, so I'm going to bump this out of that milestone. It will require a bigger change, and I'm not sure what that will look like yet. I have reopened the bug though.

  9. guybedford commented on Oct 2, 2012

    @guybedford
    Author

    I think the initial case mentioned is somewhat of an edge case.

    In the latter case, the module is being used for the first time as a plugin, but because it was passed through a wrapper this distinction is not detected. A quick but perhaps hacky fix would be to detect wrapper module structures (with a regular expression) and apply the pluginBuilder check in this case.

    The alternative is that I provide map config instructions for plugin users which really isn't a big issue, I've just been trying to avoid it and perhaps unnecessarily.

  10. guybedford commented on Oct 2, 2012

    @guybedford
    Author

    I just realised the wrapper issue is a duplicate of #209. Perhaps this should be reopened over this one, as the main issue here still remains an edge case.

  11. jrburke commented on Oct 2, 2012

    @jrburke
    Member

    I'm not sure I follow, the brief scan of #209 seems to be that it is closed out, the map config fixes it. Maybe the issue was the just opened today requirejs/requirejs#484 which is now fixed in the dev2.1 branch? If not, then I think I need a test case/test repo I can try to understand the problem.

  12. guybedford commented on Oct 2, 2012

    @guybedford
    Author

    I will try and explain it a bit more clearly, I've confused a few points above anyway. Let me know if anything still doesn't make sense.

    I was using the volo.main config setting in the package.json to allow for the automatic generation of a wrapper module. So for example:

    volo add guybedford/require-css

    Would create:

    require-css/css.js
    require-css/css-builder.js
    require-css/normalize.js
    css.js

    The main motivation being saving users the need to enter a map config (which is not a big deal I know, I've changed the modules for now to avoid this).

    css.js is the automatically created wrapper module of the form:

      define(['require-css/css'], function(css) {
        return css;
      });

    Css is a plugin, and has a 'pluginBuilder' property pointing to './css-builder'.

    When building, the relative path for the pluginBuilder is seen relative to the wrapper module, causing the pluginBuilder call to fail.

    One other side point is that pluginBuilder fails are quite silent and difficult to spot. A nicer error message for the path not resolving (instead of a null issue later I think it was) would assist spotting this.

    I'm quite happy to move to the map config method as I have done. I just really liked the idea of a config-free install with volo.

  13. jrburke commented on Oct 2, 2012

    @jrburke
    Member

    Thanks for walking through the test case. This case fails because the wrapper module is the one that is parsed to check for the pluginBuilder property, not its "dependency" 'require-css/css'.

    Dependencies of loader plugins need to be executed in full because they may be used as regular modules to do things, they are not considered to be the "real" plugin implementation. This one is tricky because the "real" implementation that has the pluginBuilder is a dependency.

    So this will be tricky to sort out. It is getting caught against the general desire to avoid configuration, the use of pluginBuilder. pluginBuilder to me is less common than just using the plugin that can also do builds but then just excluding the module wholesale via a stubModules build config after the build. But the pluginBuilder capability exists.

    I guess the answer it so task the developer to insert a config, either a packages config or a map config to get this to resolve correctly.

    I cannot think of an easy code fix though, so going to close this out as "use config to sort it out". There is only so far convention-based programming can go. However we can reopen it later if we think of a way to support this.

  14. guybedford commented on Oct 3, 2012

    @guybedford
    Author

    Sure, more than happy to go ahead with the config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions