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

fix(compiler-cli): Return original sourceFile instead of redirected sourceFile #26036

Closed
wants to merge 1 commit into from

Conversation

JonWallsten
Copy link
Contributor

@JonWallsten JonWallsten commented Sep 20, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

When using webpack dev server and AngularCompilerPlugin (maybe other combinations as well) all but the first compile always fails with the the following error:

Host should not return a redirect source file from `getSourceFile`

The problem is causes by duplicated definition files with different paths.
Example:

C:/Users/me/repo/web-app-angular/node_modules/@types/webpack/node_modules/source-map/source-map.d.ts
C:/Users/me/repo/web-app-angular/node_modules/@types/uglify-js/node_modules/source-map/source-map.d.ts

Typescript expects the redirect's target instead of the redirects source.
This fix solves that.
Issue Number: #22524

What is the new behavior?

The error message is not thrown. Fix is borrowed from here: ng-packagr/ng-packagr@c1fced0

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

This is definitely a hotfix. I don't have enough knowledge about TypeScript to solve the root cause. But this has been stopping our project since March, and based ont he up votes on the issue I'm not the only one.

@JonWallsten JonWallsten force-pushed the patch-issue-22524 branch 4 times, most recently from 42f8e6e to 800b878 Compare September 20, 2018 13:46
@JonWallsten JonWallsten changed the title Patch issue 22524 fix(compiler-cli): Temp fix in program.ts issue Sep 20, 2018
@JonWallsten
Copy link
Contributor Author

Build seems to be failing because:

===== archive - skip deploy - commit not HEAD
fatal: unable to access 'https://github.com/angular/angular.git/': gnutls_handshake() failed: A TLS packet with unexpected length was received.
Fail

@kara kara added the area: core Issues related to the framework runtime label Sep 24, 2018
@yannickglt
Copy link

I confirm that it fixes watch on server. Is there a chance it get merged and released on an angular patch soon?

@JonWallsten
Copy link
Contributor Author

Is this just going to be ignored forever?

@ngbot ngbot bot added this to the needsTriage milestone Jan 24, 2019
@petebacondarwin petebacondarwin added area: compiler Issues related to `ngc`, Angular's template compiler comp: ivy action: review The PR is still awaiting reviews from at least one requested reviewer type: bug/fix labels Jul 4, 2019
@JonWallsten
Copy link
Contributor Author

Please note that this needs to be fixed in for IVY as well:
https://github.com/angular/angular/blob/master/packages/compiler-cli/src/ngtsc/typecheck/src/context.ts#L176

@kara kara added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 4, 2019
@Splaktar
Copy link
Member

Splaktar commented Jul 4, 2019

@JonWallsten sorry for the delay on this. It should start moving forward now.

Would it be possible to post a PR with the Ivy fix as well?

@JonWallsten
Copy link
Contributor Author

@Splaktar Sure! I'll get one done by this weekend.

@JonWallsten
Copy link
Contributor Author

JonWallsten commented Jul 6, 2019

@Splaktar: I've updated the PR now. However, I don't know if there are more places. These are the two I've come across in my current project while bulding with Webpack. I did dig around some in the project but couldn't find any obvious ones. But then again. It's not crystal clear code-wise where this is an issue. There are around 40 places where getSourceFiles is used, but not all of them uses the source files.

@JonWallsten
Copy link
Contributor Author

@JoostK: Is it possible to trigger tests again without a new commit?

@petebacondarwin
Copy link
Member

@JonWallsten - hi Jon. Members of the angular org can retrigger CircleCI tests (possibly the PR author themselves can) by going to the CircleCI UI. CodeFresh doesn't have this ability (AFAIK) so that can only be re-run by a new commit.
A simple way to push a new run is git commit --amend --reuse-message=HEAD && git push --force-with-lease. Hope I am not teaching you something you already know there!

@JonWallsten
Copy link
Contributor Author

@petebacondarwin: That's a new one! Will be usefull! Thanks!

@JonWallsten
Copy link
Contributor Author

@JoostK @petebacondarwin - the build seems to fail. And I have no idea what the error message means.

@JoostK
Copy link
Member

JoostK commented Jul 9, 2019

@JonWallsten neither do I, it seems like a flake. I restarted the workflow for you, lets hope that resolves the issue.

@petebacondarwin
Copy link
Member

LOL! So did I. I'll leave @JoostK to help out here. I think it was probably a flake.

@JonWallsten
Copy link
Contributor Author

@JoostK @petebacondarwin: Weird! Happends twice in a row. That's why I thought it was a real error. But third times the charm it seems! Thanks guys!

@JonWallsten
Copy link
Contributor Author

@JoostK: Let me know if there's anything more you'd need me to do!

// location.
// We return 'redirectInfo.unredirected' to return the original file and not the, by
// TypeScript, suggested target file.
if ((summary.sourceFile as any).redirectInfo) {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer the code to read as follows:

sf = summary.sourceFile;
const redirectInfo = (sf as any).redirectInfo;
if (redirectInfo !== undefined) {
  sf = redirectInfo.unredirected;
}

@@ -39,6 +39,12 @@ export class TypeCheckProgramHost implements ts.CompilerHost {
sf = this.delegate.getSourceFile(
fileName, languageVersion, onError, shouldCreateNewSourceFile);
sf && this.sfMap.set(fileName, sf);
} else if ((sf as any).redirectInfo) {
Copy link
Member

Choose a reason for hiding this comment

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

Also here, I think the following reads better:

} else {
  const redirectInfo = (sf as any).redirectInfo;
  if (redirectInfo !== undefined) {
    sf = redirectInfo.unredirected;
  }
}

Maybe the comment should mention that offering the redirect source file is not allowed by TypeScript, hence the effort to obtain the original source file.

@JonWallsten JonWallsten force-pushed the patch-issue-22524 branch 2 times, most recently from 64361a2 to 5bd001a Compare July 9, 2019 16:57
@JonWallsten
Copy link
Contributor Author

JonWallsten commented Jul 9, 2019

@JoostK: Done! Probably what have taken you much less time to do this yourself. I feel like a middleman! ;)
But I appreciate your patience.

@JoostK
Copy link
Member

JoostK commented Jul 9, 2019

@JonWallsten thank you for your perseverance! It is much appreciated 👍The compiler master @alxhub is not available this week, but I am pretty confident we can get this approved and merged soon.

@Splaktar
Copy link
Member

Splaktar commented Jul 9, 2019

@JonWallsten many thanks for your contribution here!

Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

👍

@JoostK JoostK added target: patch This PR is targeted for the next patch release merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Jul 15, 2019
@JoostK
Copy link
Member

JoostK commented Jul 15, 2019

merge-assistance: please run presubmit

@matsko
Copy link
Contributor

matsko commented Jul 15, 2019

@matsko matsko closed this in 3166cff Jul 15, 2019
matsko pushed a commit that referenced this pull request Jul 15, 2019
@JonWallsten JonWallsten deleted the patch-issue-22524 branch July 18, 2019 09:20
@jorroll
Copy link
Contributor

jorroll commented Jul 21, 2019

That moment when you first encounter a really annoying Angular bug, only to realize that other people have been dealing with it for over a year and just fixed it for you.

Thank you @JonWallsten!!!!!! 🎉 🎉 🎊

sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants