-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(ng-update): properly handle update from different working directory #19933
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
Closed
devversion
wants to merge
1
commit into
angular:master
from
devversion:fix/properly-handle-ng-update-from-different-working-dir
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/cdk/schematics/ng-update/test-cases/misc/working-directory.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {join} from 'path'; | ||
import {MIGRATION_PATH} from '../../../index.spec'; | ||
import {createTestCaseSetup} from '../../../testing'; | ||
|
||
describe('ng-update working directory', () => { | ||
|
||
it('should migrate project if working directory is not workspace root', async () => { | ||
const {runFixers, writeFile, removeTempDir, tempPath, appTree} = await createTestCaseSetup( | ||
'migration-v6', MIGRATION_PATH, []); | ||
const stylesheetPath = 'projects/cdk-testing/src/test-cases/global-stylesheets-test.scss'; | ||
|
||
// Write a stylesheet that will be captured by the migration. | ||
writeFile(stylesheetPath, ` | ||
[cdkPortalHost] { | ||
color: red; | ||
} | ||
`); | ||
|
||
// We want to switch into a given project directory. This means that the devkit | ||
// file system tree is at workspace root while the working directory is not the | ||
// workspace directory as previously assumed. See the following issue for more details: | ||
// https://github.com/angular/components/issues/19779 | ||
await runFixers(join(tempPath, 'projects/cdk-testing')); | ||
|
||
expect(appTree.readContent(stylesheetPath)).not | ||
.toContain('[cdkPortalHost]', 'Expected migration to change stylesheet contents.'); | ||
|
||
removeTempDir(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {getSystemPath} from '@angular-devkit/core'; | ||
import {HostDirEntry, HostTree, Tree} from '@angular-devkit/schematics'; | ||
|
||
/** | ||
* Gets the workspace file system path from the given tree. Returns | ||
* `null` if the path could not be determined. | ||
*/ | ||
// TODO: Remove this once we have a fully virtual TypeScript compiler host: COMP-387 | ||
export function getWorkspaceFileSystemPath(tree: Tree): string|null { | ||
if (!(tree.root instanceof HostDirEntry)) { | ||
return null; | ||
} | ||
const hostTree = tree.root['_tree']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment about this private accesses in this function? |
||
if (!(hostTree instanceof HostTree) || hostTree['_backend'] === undefined) { | ||
return null; | ||
} | ||
const backend = hostTree['_backend']; | ||
if (backend['_root'] !== undefined) { | ||
return getSystemPath(backend['_root']); | ||
} | ||
return null; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the TODO should go above the JsDoc block