Skip to content

Handle path mappings in Nx monorepos #300

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

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 mgechev commented Jan 10, 2020

No description provided.

@mgechev
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@chrisguttandin chrisguttandin Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 merged commit f901574 into master Jan 13, 2020
@mgechev mgechev deleted the nx-monorepos branch January 13, 2020 20:30
@chrisguttandin
Copy link
Contributor

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
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
Copy link
Contributor

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants