-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@schematics/angular): add
/.angular/cache
to .gitignore
With this change we add `/.angular/cache` to `.gitignore`. This folder will primary be used to store the build disk cache artifacts.
- Loading branch information
1 parent
5904afd
commit 7ff8c53
Showing
6 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
!.vscode/extensions.json | ||
|
||
# misc | ||
/.angular/cache | ||
/.sass-cache | ||
/connect.lock | ||
/coverage | ||
|
This file contains 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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
!.vscode/extensions.json | ||
|
||
# misc | ||
/.angular/cache | ||
/.sass-cache | ||
/connect.lock | ||
/coverage | ||
|
This file contains 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
51 changes: 51 additions & 0 deletions
51
packages/schematics/angular/migrations/update-13/update-gitignore.ts
This file contains 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,51 @@ | ||
/** | ||
* @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 { Rule } from '@angular-devkit/schematics'; | ||
|
||
export default function (): Rule { | ||
return (tree, context) => { | ||
const gitIgnoreEntry = '/.angular/cache'; | ||
const gitIgnorePath = '.gitignore'; | ||
|
||
const contents = tree.read(gitIgnorePath)?.toString(); | ||
if (!contents) { | ||
context.logger.warn(`Could not find '${gitIgnorePath}'.`); | ||
|
||
return; | ||
} | ||
|
||
if (contents.includes(gitIgnoreEntry)) { | ||
// The migration has run already. | ||
return; | ||
} | ||
|
||
// Try to insert the new entry in the misc section. | ||
const recorder = tree.beginUpdate(gitIgnorePath); | ||
let idx = contents.indexOf('# misc'); | ||
if (idx < 0) { | ||
idx = 0; | ||
} else { | ||
switch (contents[idx + 6]) { | ||
case '\n': | ||
idx += 7; | ||
break; | ||
case '\r': | ||
idx += 8; | ||
break; | ||
default: | ||
// the word is something else. | ||
idx = 0; | ||
break; | ||
} | ||
} | ||
|
||
recorder.insertLeft(idx, `${gitIgnoreEntry}\n`); | ||
tree.commitUpdate(recorder); | ||
}; | ||
} |
128 changes: 128 additions & 0 deletions
128
packages/schematics/angular/migrations/update-13/update-gitignore_spec.ts
This file contains 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,128 @@ | ||
/** | ||
* @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 { tags } from '@angular-devkit/core'; | ||
import { EmptyTree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
|
||
describe('Migration to update "gitignore".', () => { | ||
const schematicName = 'update-gitignore'; | ||
const schematicRunner = new SchematicTestRunner( | ||
'migrations', | ||
require.resolve('../migration-collection.json'), | ||
); | ||
|
||
let tree: UnitTestTree; | ||
beforeEach(() => { | ||
tree = new UnitTestTree(new EmptyTree()); | ||
}); | ||
|
||
it(`should not modify '.gitignore' if '.angular/cache' is already present.`, async () => { | ||
const input = tags.stripIndents` | ||
# dependencies | ||
/node_modules | ||
# profiling files | ||
chrome-profiler-events*.json | ||
# misc | ||
/.angular/cache | ||
/.sass-cache | ||
/connect.lock | ||
/coverage | ||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
`; | ||
|
||
tree.create('.gitignore', input); | ||
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); | ||
expect(newTree.readContent('.gitignore')).toBe(input); | ||
}); | ||
|
||
it(`should insert '.angular/cache' in '# misc' section when it exists.`, async () => { | ||
const input = tags.stripIndents` | ||
# dependencies | ||
/node_modules | ||
# profiling files | ||
chrome-profiler-events*.json | ||
# misc | ||
/.sass-cache | ||
/connect.lock | ||
/coverage | ||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
`; | ||
|
||
const output = tags.stripIndents` | ||
# dependencies | ||
/node_modules | ||
# profiling files | ||
chrome-profiler-events*.json | ||
# misc | ||
/.angular/cache | ||
/.sass-cache | ||
/connect.lock | ||
/coverage | ||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
`; | ||
|
||
tree.create('.gitignore', input); | ||
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); | ||
expect(newTree.readContent('.gitignore')).toBe(output); | ||
}); | ||
|
||
it(`should insert '.angular/cache' at the top when '# misc' section does not exist.`, async () => { | ||
const input = tags.stripIndents` | ||
# dependencies | ||
/node_modules | ||
# profiling files | ||
chrome-profiler-events*.json | ||
# miscs | ||
/connect.lock | ||
/coverage | ||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
`; | ||
|
||
const output = tags.stripIndents` | ||
/.angular/cache | ||
# dependencies | ||
/node_modules | ||
# profiling files | ||
chrome-profiler-events*.json | ||
# miscs | ||
/connect.lock | ||
/coverage | ||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
`; | ||
|
||
tree.create('.gitignore', input); | ||
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise(); | ||
expect(newTree.readContent('.gitignore')).toBe(output); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
|
@@ -31,6 +31,7 @@ chrome-profiler-events*.json | |
.history/* | ||
|
||
# misc | ||
/.angular/cache | ||
/.sass-cache | ||
/connect.lock | ||
/coverage | ||
|