-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
perf: fine tune schematics #1925
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as ts from 'typescript'; | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { Tree, DirEntry } from '@angular-devkit/schematics'; | ||
|
||
export function visitTSSourceFiles<Result = void>( | ||
tree: Tree, | ||
|
@@ -10,24 +10,35 @@ export function visitTSSourceFiles<Result = void>( | |
) => Result | undefined | ||
): Result | undefined { | ||
let result: Result | undefined = undefined; | ||
for (const sourceFile of visit(tree.root)) { | ||
result = visitor(sourceFile, tree, result); | ||
} | ||
|
||
tree.visit(path => { | ||
if (!path.endsWith('.ts')) { | ||
return; | ||
} | ||
|
||
const sourceFile = ts.createSourceFile( | ||
path, | ||
tree.read(path)!.toString(), | ||
ts.ScriptTarget.Latest | ||
); | ||
return result; | ||
} | ||
|
||
if (sourceFile.isDeclarationFile) { | ||
return; | ||
function* visit(directory: DirEntry): IterableIterator<ts.SourceFile> { | ||
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. Don't use Another option is to use the Or to simple check if |
||
for (const path of directory.subfiles) { | ||
if (path.endsWith('.ts') && !path.endsWith('.d.ts')) { | ||
const entry = directory.file(path); | ||
if (entry) { | ||
const content = entry.content; | ||
const source = ts.createSourceFile( | ||
entry.path, | ||
content.toString().replace(/^\uFEFF/, ''), | ||
ts.ScriptTarget.Latest, | ||
true | ||
); | ||
yield source; | ||
} | ||
} | ||
} | ||
|
||
result = visitor(sourceFile, tree, result); | ||
}); | ||
for (const path of directory.subdirs) { | ||
if (path === 'node_modules') { | ||
continue; | ||
} | ||
|
||
return result; | ||
yield* visit(directory.dir(path)); | ||
} | ||
} |
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.
Only commit the file when there are changes, I forgot this in some of the v8 migrations making them slow (plus there was a information message on every file changes, even node_modules, which might confuse people).