-
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.
perf(@angular/cli): register CLI commands lazily
Currently there is a lot of overhead coming from requiring external modules when registering commands such as `ng update` and `ng add`. This is because these commands do not lazily require all the modules causes the resolution of unneeded packages to be part of the critical path. With this change we "require” only the command that we we need to execute, which reduce the number of node modules resolutions in the critical path. (cherry picked from commit 5b62074)
- Loading branch information
1 parent
a710a26
commit 19f9d35
Showing
22 changed files
with
204 additions
and
76 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
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
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
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
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
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
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,114 @@ | ||
/** | ||
* @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 { CommandModuleConstructor } from '../command-builder/utilities/command'; | ||
|
||
export type CommandNames = | ||
| 'add' | ||
| 'analytics' | ||
| 'build' | ||
| 'cache' | ||
| 'completion' | ||
| 'config' | ||
| 'deploy' | ||
| 'doc' | ||
| 'e2e' | ||
| 'extract-i18n' | ||
| 'generate' | ||
| 'lint' | ||
| 'make-this-awesome' | ||
| 'new' | ||
| 'run' | ||
| 'serve' | ||
| 'test' | ||
| 'update' | ||
| 'version'; | ||
|
||
export interface CommandConfig { | ||
aliases?: string[]; | ||
factory: () => Promise<{ default: CommandModuleConstructor }>; | ||
} | ||
|
||
export const RootCommands: Record< | ||
/* Command */ CommandNames & string, | ||
/* Command Config */ CommandConfig | ||
> = { | ||
'add': { | ||
factory: () => import('./add/cli'), | ||
}, | ||
'analytics': { | ||
factory: () => import('./analytics/cli'), | ||
}, | ||
'build': { | ||
factory: () => import('./build/cli'), | ||
aliases: ['b'], | ||
}, | ||
'cache': { | ||
factory: () => import('./cache/cli'), | ||
}, | ||
'completion': { | ||
factory: () => import('./completion/cli'), | ||
}, | ||
'config': { | ||
factory: () => import('./config/cli'), | ||
}, | ||
'deploy': { | ||
factory: () => import('./deploy/cli'), | ||
}, | ||
'doc': { | ||
factory: () => import('./doc/cli'), | ||
aliases: ['d'], | ||
}, | ||
'e2e': { | ||
factory: () => import('./e2e/cli'), | ||
aliases: ['e2e'], | ||
}, | ||
'extract-i18n': { | ||
factory: () => import('./extract-i18n/cli'), | ||
}, | ||
'generate': { | ||
factory: () => import('./generate/cli'), | ||
aliases: ['g'], | ||
}, | ||
'lint': { | ||
factory: () => import('./lint/cli'), | ||
}, | ||
'make-this-awesome': { | ||
factory: () => import('./make-this-awesome/cli'), | ||
}, | ||
'new': { | ||
factory: () => import('./new/cli'), | ||
aliases: ['n'], | ||
}, | ||
'run': { | ||
factory: () => import('./run/cli'), | ||
}, | ||
'serve': { | ||
factory: () => import('./serve/cli'), | ||
aliases: ['s'], | ||
}, | ||
'test': { | ||
factory: () => import('./test/cli'), | ||
aliases: ['t'], | ||
}, | ||
'update': { | ||
factory: () => import('./update/cli'), | ||
}, | ||
'version': { | ||
factory: () => import('./version/cli'), | ||
aliases: ['v'], | ||
}, | ||
}; | ||
|
||
export const RootCommandsAliases = Object.values(RootCommands).reduce((prev, current) => { | ||
current.aliases?.forEach((alias) => { | ||
prev[alias] = current; | ||
}); | ||
|
||
return prev; | ||
}, {} as Record<string, CommandConfig>); |
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
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
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
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
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
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
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
Oops, something went wrong.