Skip to content

fix(cdk/schematics): remove instanceof check since it was always false when checking if a directory exists #24999

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 1 commit into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/cdk/schematics/ng-update/devkit-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ export class DevkitFileSystem extends FileSystem {
try {
this._tree.get(dirPath);
} catch (e) {
// Note: We do not use an `instanceof` check here. It could happen that the devkit version
// used by the CLI is different than the one we end up loading. This can happen depending
// on how Yarn/NPM hoists the NPM packages / whether there are multiple versions installed.
if (e instanceof Error && e.constructor.name === 'PathIsDirectoryException') {
// Note: We do not use an `instanceof` check here. It could happen that
// the devkit version used by the CLI is different than the one we end up
// loading. This can happen depending on how Yarn/NPM hoists the NPM
// packages / whether there are multiple versions installed. Typescript
// throws a compilation error if the type isn't specified and we can't
// check the type, so we have to cast the error output to any.
if ((e as any).constructor.name === 'PathIsDirectoryException') {
Copy link
Member

Choose a reason for hiding this comment

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

For additional context in this PR: It was unclear to us why specifically the error instanceof check did not work anymore, but likely due to the schematics being run in another sandbox context.

return true;
}
}
Expand Down