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

Handle path mappings in Nx monorepos #300

Merged
merged 2 commits into from Jan 13, 2020
Merged

Handle path mappings in Nx monorepos #300

merged 2 commits into from Jan 13, 2020

Conversation

@mgechev
Copy link
Member

mgechev commented Jan 10, 2020

No description provided.

@mgechev

This comment has been minimized.

Copy link
Member Author

mgechev commented Jan 10, 2020

@chrisguttandin would you have a look since you have the most context.

if (loadChildren.startsWith('.')) {
return join(dirname(parentPath), childModule);
return join(dirname(parentPath), childModuleFile);
}
const parentSegments = dirname(parentPath).split(sep);

This comment has been minimized.

Copy link
@mgechev

mgechev Jan 10, 2020

Author Member

I was hoping to get rid of this but resolveModuleName seems to get confused when the route is relative to the app root, which in Angular is possible.

This comment has been minimized.

Copy link
@chrisguttandin

chrisguttandin Jan 11, 2020

Contributor

I think this is because TypeScript does not even attempt to look up a file if it does not start with a dot. I guess it does try to look up the first part of those paths as a node module instead. So if we define loadChildren: 'app/qux/qux.module' TypeScript will probably look for a node module named 'app' and if it exists it would attempt to find the 'qux/qux.module' file in it.

Anyway I wondered if we could help TypeScript by prepending a './' to tell it that we want it to look for a file and not a node module. I did a quick test but it doesn't work right now. I think it's because the test fixture is inconsistent when it comes to the the old loadChildren syntax. The path defined here would have to be prepended with '../' since the path starts with the parent folder. But here the path would have to be prepended with './' since it starts with a folder inside the current directory. Did Angular resolve both of them correctly or is that a bug in the test fixture?

@mgechev mgechev force-pushed the nx-monorepos branch from e4064a8 to 3f58874 Jan 11, 2020
@mgechev mgechev merged commit f901574 into master Jan 13, 2020
2 checks passed
2 checks passed
Travis CI - Branch Build Passed
Details
Travis CI - Pull Request Build Passed
Details
@mgechev mgechev deleted the nx-monorepos branch Jan 13, 2020
@chrisguttandin

This comment has been minimized.

Copy link
Contributor

chrisguttandin commented Jan 16, 2020

Unfortunately the update broke the integration tests of angular-prerender.

https://github.com/chrisguttandin/angular-prerender/runs/393678803

I'm on the run now but I will try to have a look later today.

@mgechev

This comment has been minimized.

Copy link
Member Author

mgechev commented Jan 16, 2020

Looking at the failure, seems like the route did not get rendered:

     AssertionError: expected '<!doctype html>\n<html lang="en">\n<head>\n  <meta charset="utf-8">\n  <title>Universe</title>\n  <base href="/">\n  <meta name="viewport" content="width=device-width, initial-scale=1">\n  <link rel="icon" type="image/x-icon" href="favicon.ico">\n</head>\n<body>\n  <app-root></app-root>\n<script src="runtime-es2015.js" type="module"></script><script src="runtime-es5.js" nomodule defer></script><script src="polyfills-es5.js" nomodule defer></script><script src="polyfills-es2015.js" type="module"></script><script src="styles-es2015.js" type="module"></script><script src="styles-es5.js" nomodule defer></script><script src="vendor-es2015.js" type="module"></script><script src="vendor-es5.js" nomodule defer></script><script src="main-es2015.js" type="module"></script><script src="main-es5.js" nomodule defer></script></body>\n</html>\n' to match /<span.*>universe app is running!<\/span>/
@chrisguttandin

This comment has been minimized.

Copy link
Contributor

chrisguttandin commented Jan 17, 2020

Sorry, the error was unrelated to this update. It was a side effect of the update of @wessberg/ts-evaluator. It used to have typescript as a dependency but that got removed. I had to define typescript as an explicit dependency of angular-prerender to get it working with npx again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.