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

map config sometimes improperly applied to loader resource name #47

Open
dgoldstein0 opened this issue Nov 8, 2018 · 3 comments
Open

Comments

@dgoldstein0
Copy link

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.

@jrburke
Copy link
Member

jrburke commented Nov 26, 2018

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.

@jrburke
Copy link
Member

jrburke commented Nov 26, 2018

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>

@dgoldstein0
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants