Skip to content

critical bug - AOT relative paths resolved incorrectly (app source to ngfactory src) #45

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
shlomiassaf opened this issue Dec 30, 2016 · 0 comments

Comments

@shlomiassaf
Copy link

Just run this test:

  describe('AoT + genDir', function() {
    var resourcePath = 'src/app/my-module/my-module.routes.ts';
    var modulePath = '../groups/inventory/index#InventoryModule';

    beforeEach(function () {
      query = '?aot=true&genDir=compiled/src/app'
    });

    it('should return a loadChildren async require statement', function() {
      var result = [
        'loadChildren: () => new Promise(function (resolve) {',
        '  (require as any).ensure([], function (require: any) {',
        '    resolve(require(\'../../../compiled/src/app/groups/inventory/index.ngfactory\')[\'InventoryModuleNgFactory\']);',
        '  });',
        '})'
      ];

      var loadedString = loader.call({
        resourcePath: resourcePath,
        query: query
      }, `loadChildren: '${modulePath}'`);

      checkResult(loadedString, result);
    });
  });

Basically the whole resolving logic is not current.

The Wiki says, if "genDir": "src/compiled" then 'angular-router-loader?aot=true&genDir=src/compiled/src/app' which makes no sense... why adding the addition app?

The genDir in the query should point to the genDir defined in tsconfig.json but relative to the root, which is genDir=src/compiled

Basically if tsconfig is in the app root both genDir values are identical

Even with this change it's still not working...

The unit tests for AOT are all wrong

All unit tests expect

  var resourcePath = 'path/to/routes.ts';
  var modulePath = './path/to/file.module#FileModule';

With query ?aot=true&genDir=.

To resolve this path ../../path/to/file.module.ngfactory

Which is incorrect (and confusing)
The actual resolved path should be ./path/to/file.module.ngfactory

Why?
Because genDir=. is the same as no genDir or empty string.
If you set genDir: "." in tsconfig it's like setting "" or not setting genDir at all, i.e: emit compiled files in the source tree.

The tests assume emit source file in the root of the project which is a non valid scenario.

And again, my supplied unit test provides a scenario that the loader can't handle.

I will post a PR soon with a refactor for the relative module path resolution when using AOT.

This is not a breaking change but it will be for some projects since they are setting an invalid value in the genDir query parameter.

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

No branches or pull requests

1 participant