Skip to content

map config sometimes improperly applied to loader resource name #47

Open

Description

@dgoldstein0
var foorequire = requirejs.config({context: 'foo', map: {'*': {'modules/constants': 'loader!modules/constants'}}});
define("loader", [], () => {
  return {load: function(name, localRequire, onload, config) {console.log(name);}};
});
foorequire(["modules/constants/foo"]);

expected output: modules/constants/foo
actual output: loader!modules/constants/foo

if the map is changed to something different like {'*': {'modules/constants': 'loader!constants'}} the unexpected map application seems not to apply (and in which case the output of the example is constants/foo instead).

the loader api docs make no mention that the map config should apply to the loader resource names, and I believe this is a bug. https://requirejs.org/docs/plugins.html

I think I've seen this working nondeterministically in the past but I'm having a hard time working that into my repro.

Activity

  1. jrburke commented on Nov 26, 2018

    @jrburke
    Member

    This is definitely an issue: the module ID is getting resolved twice with a map config, which is incorrect. It affects map items that use a loader and the first non-loader part of the ID is the same as the value before it.

    I am not sure yet how to fix it yet. I have been away from the code long enough that I think it will take a larger change to fix. No quick and easy fix. Will leave this open to track the issue, but I do not expect to resolve it in the near future.

  2. jrburke commented on Nov 26, 2018

    @jrburke
    Member

    Test file to add to show the error in tests at tests/mapConfigPluginMultiSegment.html:

    <!DOCTYPE html>
    <html>
    <head>
        <title>alameda: Simple Test</title>
        <script type="text/javascript" src="doh/runner.js"></script>
        <script type="text/javascript" src="doh/_browserRunner.js"></script>
        <script src="../alameda.js"></script>
        <script type="text/javascript">
          var foorequire = requirejs.config({
            context: 'foo',
            map: {
              '*': {
                'modules/constants': 'loader!modules/constants'
              }
            }
          });
          
          define("loader", [], () => {
            return {
              load: function(name, localRequire, onload, config) {
                console.log(name);
              }
            };
          });
    
          foorequire(["modules/constants/foo"]);
    
          require(['modules/constants/foo'], function (foo) {
            doh.register(
                'mapConfigPluginMultiSegment',
                [
                    function mapConfigPluginMultiSegment(t){
                        t.is('foo', foo.name);
                    }
                ]
            );
            doh.run();
          });
        </script>
    </head>
    <body>
        <h1>alameda: mapConfigPluginMultiSegment Test</h1>
        <p>Check console for messages</p>
    </body>
    </html>
  3. dgoldstein0 commented on Nov 28, 2018

    @dgoldstein0
    Author

    It affects map items that use a loader and the first non-loader part of the ID is the same as the value before it.

    my guess is that while this is a situation that shows the bug, it's not the only one - doesn't this mean that all resource names are going through the map when they should not be? so e.g. if I load loader!foo and there's a map entry for foo, e.g. map = {"*": {foo: "bar"}} I think I'd end up loading loader!bar in the end (which is also incorrect)

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