- ExecutorContext
- FileChange
- FileData
- ImplicitJsonSubsetDependency
- JsonParseOptions
- JsonSerializeOptions
- NxAffectedConfig
- NxJsonConfiguration
- NxJsonProjectConfiguration
- NxPlugin
- ProjectConfiguration
- ProjectFileMap
- ProjectGraph
- ProjectGraphDependency
- ProjectGraphNode
- ProjectGraphProcessorContext
- StringDeletion
- StringInsertion
- Target
- TargetConfiguration
- TargetDependencyConfig
- Task
- TaskGraph
- Tree
- Workspace
- WorkspaceJsonConfiguration
- Executor
- Generator
- GeneratorCallback
- ImplicitDependencyEntry
- PackageManager
- ProjectType
- StringChange
- TaskGraphExecutor
- WorkspaceConfiguration
- addDependenciesToPackageJson
- addProjectConfiguration
- applyChangesToString
- convertNxExecutor
- convertNxGenerator
- detectPackageManager
- formatFiles
- generateFiles
- getPackageManagerCommand
- getPackageManagerVersion
- getProjects
- getWorkspaceLayout
- getWorkspacePath
- installPackagesTask
- isStandaloneProject
- joinPathFragments
- moveFilesToNewDirectory
- names
- normalizePath
- offsetFromRoot
- parseJson
- parseTargetString
- readJson
- readJsonFile
- readProjectConfiguration
- readTargetOptions
- readWorkspaceConfiguration
- removeDependenciesFromPackageJson
- removeProjectConfiguration
- runExecutor
- serializeJson
- stripIndents
- stripJsonComments
- targetToTargetString
- toJS
- updateJson
- updateProjectConfiguration
- updateTsConfigsToJs
- updateWorkspaceConfiguration
- visitNotIgnoredFiles
- writeJson
- writeJsonFile
• ChangeType: Object
• DependencyType: Object
Type of dependency between projects
• ProjectGraphBuilder: Object
Builder for adding nodes and dependencies to a ProjectGraph
• ExecutorContext: Object
Context that is passed into an executor
• FileChange: Object
Description of a file change in the Nx virtual file system/
• FileData: Object
Some metadata about a file
• ImplicitJsonSubsetDependency<T
>: Object
Name | Type |
---|---|
T |
"*" | string [] |
• JsonParseOptions: Object
• JsonSerializeOptions: Object
• NxAffectedConfig: Object
• NxJsonConfiguration<T
>: Object
Nx.json configuration
Name | Type |
---|---|
T |
"*" | string [] |
• NxJsonProjectConfiguration: Object
• NxPlugin: Object
A plugin for Nx
• ProjectConfiguration: Object
Project configuration
• ProjectFileMap: Object
A list of files separated by the project they belong to
• ProjectGraph<T
>: Object
A Graph of projects in the workspace and dependencies between them
Name | Type |
---|---|
T |
any |
• ProjectGraphDependency: Object
A dependency between two projects
• ProjectGraphNode<T
>: Object
A node describing a project in a workspace
Name | Type |
---|---|
T |
any |
• ProjectGraphProcessorContext: Object
Additional information to be used to process a project graph
• StringDeletion: Object
• StringInsertion: Object
• Target: Object
• TargetConfiguration: Object
Target's configuration
• TargetDependencyConfig: Object
• Task: Object
A representation of the invocation of an Executor
• TaskGraph: Object
Graph of Tasks to be executed
• Tree: Object
Virtual file system tree.
• Workspace: Object
• WorkspaceJsonConfiguration: Object
Workspace configuration
Ƭ Executor<T
>: (options
: T
, context
: ExecutorContext
) => Promise
<Object
> | AsyncIterableIterator
<Object
>
Name | Type |
---|---|
T |
any |
▸ (options
, context
): Promise
<Object
> | AsyncIterableIterator
<Object
>
Implementation of a target of a project
Name | Type |
---|---|
options |
T |
context |
ExecutorContext |
Promise
<Object
> | AsyncIterableIterator
<Object
>
Ƭ Generator<T
>: (tree
: any
, schema
: T
) => void
| GeneratorCallback
| Promise
<void
| GeneratorCallback
>
Name | Type |
---|---|
T |
unknown |
▸ (tree
, schema
): void
| GeneratorCallback
| Promise
<void
| GeneratorCallback
>
A function that schedules updates to the filesystem to be done atomically
Name | Type |
---|---|
tree |
any |
schema |
T |
void
| GeneratorCallback
| Promise
<void
| GeneratorCallback
>
Ƭ GeneratorCallback: () => void
| Promise
<void
>
▸ (): void
| Promise
<void
>
A callback function that is executed after changes are made to the file system
void
| Promise
<void
>
Ƭ ImplicitDependencyEntry<T
>: Object
Name | Type |
---|---|
T |
"*" | string [] |
▪ [key: string
]: T
| ImplicitJsonSubsetDependency
<T
>
Ƭ PackageManager: "yarn"
| "pnpm"
| "npm"
Ƭ ProjectType: "library"
| "application"
Type of project supported
Ƭ StringChange: StringInsertion
| StringDeletion
A change to be made to a string
Ƭ TaskGraphExecutor<T
>: (taskGraph
: TaskGraph
, options
: Record
<string
, T
>, overrides
: T
, context
: ExecutorContext
) => Promise
<Record
<string
, Object
>>
Name | Type |
---|---|
T |
any |
▸ (taskGraph
, options
, overrides
, context
): Promise
<Record
<string
, Object
>>
Implementation of a target of a project that handles multiple projects to be batched
Name | Type |
---|---|
taskGraph |
TaskGraph |
options |
Record <string , T > |
overrides |
T |
context |
ExecutorContext |
Promise
<Record
<string
, Object
>>
Ƭ WorkspaceConfiguration: Omit
<WorkspaceJsonConfiguration
, "projects"
> & Omit
<NxJsonConfiguration
, "projects"
>
• Const
logger: Object
Name | Type |
---|---|
debug |
(...s : any []) => void |
error |
(s : any ) => void |
fatal |
(...s : any []) => void |
info |
(s : any ) => void |
log |
(...s : any []) => void |
warn |
(s : any ) => void |
▸ addDependenciesToPackageJson(host
, dependencies
, devDependencies
, packageJsonPath?
): GeneratorCallback
Add Dependencies and Dev Dependencies to package.json
For example:
addDependenciesToPackageJson(host, { react: 'latest' }, { jest: 'latest' });
This will add react
and jest
to the dependencies and devDependencies sections of package.json respectively.
Name | Type | Default value | Description |
---|---|---|---|
host |
Tree |
undefined |
Tree representing file system to modify |
dependencies |
Record <string , string > |
undefined |
Dependencies to be added to the dependencies section of package.json |
devDependencies |
Record <string , string > |
undefined |
Dependencies to be added to the devDependencies section of package.json |
packageJsonPath |
string |
'package.json' |
Path to package.json |
Callback to install dependencies only if necessary. undefined is returned if changes are not necessary.
▸ addProjectConfiguration(host
, projectName
, projectConfiguration
, standalone?
): void
Adds project configuration to the Nx workspace.
The project configuration is stored in workspace.json and nx.json. The utility will update both files.
Name | Type | Default value | Description |
---|---|---|---|
host |
Tree |
undefined |
the file system tree |
projectName |
string |
undefined |
unique name. Often directories are part of the name (e.g., mydir-mylib) |
projectConfiguration |
ProjectConfiguration & NxJsonProjectConfiguration |
undefined |
project configuration |
standalone |
boolean |
false |
should the project use package.json? If false, the project config is inside workspace.json |
void
▸ applyChangesToString(text
, changes
): string
Applies a list of changes to a string's original value.
This is useful when working with ASTs.
For Example, to rename a property in a method's options:
const code = `bootstrap({
target: document.querySelector('#app')
})`;
const indexOfPropertyName = 13; // Usually determined by analyzing an AST.
const updatedCode = applyChangesToString(code, [
{
type: ChangeType.Insert,
index: indexOfPropertyName,
text: 'element',
},
{
type: ChangeType.Delete,
start: indexOfPropertyName,
length: 6,
},
]);
bootstrap({
element: document.querySelector('#app'),
});
Name | Type |
---|---|
text |
string |
changes |
StringChange [] |
string
▸ convertNxExecutor(executor
): any
Convert an Nx Executor into an Angular Devkit Builder
Use this to expose a compatible Angular Builder
Name | Type |
---|---|
executor |
Executor |
any
▸ convertNxGenerator<T
>(generator
): (options
: T
) => (tree
: any
, context
: any
) => Promise
<any
>
Convert an Nx Generator into an Angular Devkit Schematic
Name | Type |
---|---|
T |
any |
Name | Type |
---|---|
generator |
Generator <T > |
fn
▸ (options
): (tree
: any
, context
: any
) => Promise
<any
>
Name | Type |
---|---|
options |
T |
fn
▸ (tree
, context
): Promise
<any
>
Name | Type |
---|---|
tree |
any |
context |
any |
Promise
<any
>
▸ detectPackageManager(dir?
): PackageManager
Detects which package manager is used in the workspace based on the lock file.
Name | Type | Default value |
---|---|---|
dir |
string |
'' |
▸ formatFiles(host
): Promise
<void
>
Formats all the created or updated files using Prettier
Name | Type | Description |
---|---|---|
host |
Tree |
the file system tree |
Promise
<void
>
▸ generateFiles(host
, srcFolder
, target
, substitutions
): void
Generates a folder of files based on provided templates.
While doing so it performs two substitutions:
- Substitutes segments of file names surrounded by __
- Uses ejs to substitute values in templates
Examples:
generateFiles(host, path.join(__dirname, 'files'), './tools/scripts', {
tmpl: '',
name: 'myscript',
});
This command will take all the files from the files
directory next to the place where the command is invoked from.
It will replace all __tmpl__
with '' and all __name__
with 'myscript' in the file names, and will replace all
<%= name %>
with myscript
in the files themselves.
tmpl: ''
is a common pattern. With it you can name files like this: index.ts__tmpl__
, so your editor
doesn't get confused about incorrect TypeScript files.
Name | Type | Description |
---|---|---|
host |
Tree |
the file system tree |
srcFolder |
string |
the source folder of files (absolute path) |
target |
string |
the target folder (relative to the host root) |
substitutions |
Object |
an object of key-value pairs |
void
▸ getPackageManagerCommand(packageManager?
): PackageManagerCommands
Returns commands for the package manager used in the workspace. By default, the package manager is derived based on the lock file, but it can also be passed in explicitly.
Example:
execSync(`${getPackageManagerCommand().addDev} my-dev-package`);
Name | Type |
---|---|
packageManager |
PackageManager |
PackageManagerCommands
▸ getPackageManagerVersion(packageManager?
): string
Returns the version of the package manager used in the workspace. By default, the package manager is derived based on the lock file, but it can also be passed in explicitly.
Name | Type |
---|---|
packageManager |
PackageManager |
string
▸ getProjects(host
): Map
<string
, ProjectConfiguration
& NxJsonProjectConfiguration
>
Get a map of all projects in a workspace.
Use readProjectConfiguration if only one project is needed.
Name | Type |
---|---|
host |
Tree |
Map
<string
, ProjectConfiguration
& NxJsonProjectConfiguration
>
▸ getWorkspaceLayout(host
): Object
Returns workspace defaults. It includes defaults folders for apps and libs, and the default scope.
Example:
{ appsDir: 'apps', libsDir: 'libs', npmScope: 'myorg' }
Name | Type | Description |
---|---|---|
host |
Tree |
file system tree |
Object
Name | Type |
---|---|
appsDir |
string |
libsDir |
string |
npmScope |
string |
standaloneAsDefault |
boolean |
▸ getWorkspacePath(host
): string
Name | Type |
---|---|
host |
Tree |
string
▸ installPackagesTask(host
, alwaysRun?
, cwd?
, packageManager?
): void
Runs npm install
or yarn install
. It will skip running the install if
package.json
hasn't changed at all or it hasn't changed since the last invocation.
Name | Type | Default value | Description |
---|---|---|---|
host |
Tree |
undefined |
the file system tree |
alwaysRun |
boolean |
false |
always run the command even if package.json hasn't changed. |
cwd |
string |
'' |
- |
packageManager |
PackageManager |
undefined |
- |
void
▸ isStandaloneProject(host
, project
): boolean
Returns if a project has a standalone configuration (project.json).
Name | Type | Description |
---|---|---|
host |
Tree |
the file system tree |
project |
string |
the project name |
boolean
▸ joinPathFragments(...fragments
): string
Normalized path fragments and joins them
Name | Type |
---|---|
...fragments |
string [] |
string
▸ moveFilesToNewDirectory(host
, oldDir
, newDir
): void
Name | Type |
---|---|
host |
Tree |
oldDir |
string |
newDir |
string |
void
▸ names(name
): Object
Util function to generate different strings based off the provided name.
Examples:
names('my-name'); // {name: 'my-name', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
names('myName'); // {name: 'my-name', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
Name | Type |
---|---|
name |
string |
Object
Name | Type |
---|---|
className |
string |
constantName |
string |
fileName |
string |
name |
string |
propertyName |
string |
▸ normalizePath(osSpecificPath
): string
Coverts an os specific path to a unix style path
Name | Type |
---|---|
osSpecificPath |
string |
string
▸ offsetFromRoot(fullPathToDir
): string
Calculates an offset from the root of the workspace, which is useful for constructing relative URLs.
Examples:
offsetFromRoot('apps/mydir/myapp/'); // returns "../../../"
Name | Type | Description |
---|---|---|
fullPathToDir |
string |
directory path |
string
▸ parseJson<T
>(input
, options?
): T
Parses the given JSON string and returns the object the JSON content represents. By default javascript-style comments are allowed.
Name | Type |
---|---|
T |
extends object``any |
Name | Type | Description |
---|---|---|
input |
string |
JSON content as string |
options? |
JsonParseOptions |
JSON parse options |
T
Object the JSON content represents
▸ parseTargetString(targetString
): Target
Parses a target string into {project, target, configuration}
Examples:
parseTargetString('proj:test'); // returns { project: "proj", target: "test" }
parseTargetString('proj:test:production'); // returns { project: "proj", target: "test", configuration: "production" }
Name | Type | Description |
---|---|---|
targetString |
string |
target reference |
▸ readJson<T
>(host
, path
, options?
): T
Reads a document for host, removes all comments and parses JSON.
Name | Type |
---|---|
T |
extends object``any |
Name | Type | Description |
---|---|---|
host |
Tree |
file system tree |
path |
string |
file path |
options? |
JsonParseOptions |
Optional JSON Parse Options |
T
▸ readJsonFile<T
>(path
, options?
): T
Reads a JSON file and returns the object the JSON content represents.
Name | Type |
---|---|
T |
extends object``any |
Name | Type | Description |
---|---|---|
path |
string |
A path to a file. |
options? |
JsonReadOptions |
JSON parse options |
T
Object the JSON content of the file represents
▸ readProjectConfiguration(host
, projectName
): ProjectConfiguration
& NxJsonProjectConfiguration
Reads a project configuration.
The project configuration is stored in workspace.json and nx.json. The utility will read both files.
throws
If supplied projectName cannot be found
Name | Type | Description |
---|---|---|
host |
Tree |
the file system tree |
projectName |
string |
unique name. Often directories are part of the name (e.g., mydir-mylib) |
ProjectConfiguration
& NxJsonProjectConfiguration
▸ readTargetOptions<T
>(__namedParameters
, context
): T
Reads and combines options for a given target.
Works as if you invoked the target yourself without passing any command lint overrides.
Name | Type |
---|---|
T |
any |
Name | Type |
---|---|
__namedParameters |
Target |
context |
ExecutorContext |
T
▸ readWorkspaceConfiguration(host
): WorkspaceConfiguration
Read general workspace configuration such as the default project or cli settings
This does not provide projects configuration, use readProjectConfiguration instead.
Name | Type |
---|---|
host |
Tree |
▸ removeDependenciesFromPackageJson(host
, dependencies
, devDependencies
, packageJsonPath?
): GeneratorCallback
Remove Dependencies and Dev Dependencies from package.json
For example:
removeDependenciesFromPackageJson(host, ['react'], ['jest']);
This will remove react
and jest
from the dependencies and devDependencies sections of package.json respectively.
Name | Type | Default value | Description |
---|---|---|---|
host |
Tree |
undefined |
- |
dependencies |
string [] |
undefined |
Dependencies to be removed from the dependencies section of package.json |
devDependencies |
string [] |
undefined |
Dependencies to be removed from the devDependencies section of package.json |
packageJsonPath |
string |
'package.json' |
- |
Callback to uninstall dependencies only if necessary. undefined is returned if changes are not necessary.
▸ removeProjectConfiguration(host
, projectName
): void
Removes the configuration of an existing project.
The project configuration is stored in workspace.json and nx.json. The utility will update both files.
Name | Type |
---|---|
host |
Tree |
projectName |
string |
void
▸ runExecutor<T
>(targetDescription
, options
, context
): Promise
<AsyncIterableIterator
<T
>>
Loads and invokes executor.
This is analogous to invoking executor from the terminal, with the exception that the params aren't parsed from the string, but instead provided parsed already.
Apart from that, it works the same way:
- it will load the workspace configuration
- it will resolve the target
- it will load the executor and the schema
- it will load the options for the appropriate configuration
- it will run the validations and will set the default
- and, of course, it will invoke the executor
Example:
for await (const s of await runExecutor(
{ project: 'myproj', target: 'serve' },
{ watch: true },
context
)) {
// s.success
}
Note that the return value is a promise of an iterator, so you need to await before iterating over it.
Name | Type |
---|---|
T |
extends Object |
Name | Type |
---|---|
targetDescription |
Object |
targetDescription.configuration? |
string |
targetDescription.project |
string |
targetDescription.target |
string |
options |
Object |
context |
ExecutorContext |
Promise
<AsyncIterableIterator
<T
>>
▸ serializeJson<T
>(input
, options?
): string
Serializes the given data to a JSON string. By default the JSON string is formatted with a 2 space intendation to be easy readable.
Name | Type |
---|---|
T |
extends object``object |
Name | Type | Description |
---|---|---|
input |
T |
Object which should be serialized to JSON |
options? |
JsonSerializeOptions |
JSON serialize options |
string
the formatted JSON representation of the object
▸ stripIndents(strings
, ...values
): string
Removes indents, which is useful for printing warning and messages.
Example:
stripIndents`
Options:
- option1
- option2
`;
Name | Type |
---|---|
strings |
TemplateStringsArray |
...values |
any [] |
string
▸ Const
stripJsonComments(text
, replaceCh?
): string
Takes JSON with JavaScript-style comments and remove them. Optionally replaces every none-newline character of comments with a replaceCharacter
Name | Type |
---|---|
text |
string |
replaceCh? |
string |
string
▸ targetToTargetString(__namedParameters
): string
Returns a string in the format "project:target[:configuration]" for the target
Name | Type |
---|---|
__namedParameters |
Target |
string
▸ toJS(tree
): void
Rename and transpile any new typescript files created to javascript files
Name | Type |
---|---|
tree |
Tree |
void
▸ updateJson<T
, U
>(host
, path
, updater
, options?
): void
Updates a JSON value to the file system tree
Name | Type |
---|---|
T |
extends object``any |
U |
extends object``T |
Name | Type | Description |
---|---|---|
host |
Tree |
File system tree |
path |
string |
Path of JSON file in the Tree |
updater |
(value : T ) => U |
Function that maps the current value of a JSON document to a new value to be written to the document |
options? |
JsonParseOptions & JsonSerializeOptions |
Optional JSON Parse and Serialize Options |
void
▸ updateProjectConfiguration(host
, projectName
, projectConfiguration
): void
Updates the configuration of an existing project.
The project configuration is stored in workspace.json and nx.json. The utility will update both files.
Name | Type | Description |
---|---|---|
host |
Tree |
the file system tree |
projectName |
string |
unique name. Often directories are part of the name (e.g., mydir-mylib) |
projectConfiguration |
ProjectConfiguration & NxJsonProjectConfiguration |
project configuration |
void
▸ updateTsConfigsToJs(host
, options
): void
Name | Type |
---|---|
host |
Tree |
options |
Object |
options.projectRoot |
string |
void
▸ updateWorkspaceConfiguration(host
, workspaceConfig
): void
Update general workspace configuration such as the default project or cli settings.
This does not update projects configuration, use updateProjectConfiguration or addProjectConfiguration instead.
Name | Type |
---|---|
host |
Tree |
workspaceConfig |
WorkspaceConfiguration |
void
▸ visitNotIgnoredFiles(tree
, dirPath?
, visitor
): void
Utility to act on all files in a tree that are not ignored by git.
Name | Type |
---|---|
tree |
Tree |
dirPath |
string |
visitor |
(path : string ) => void |
void
▸ writeJson<T
>(host
, path
, value
, options?
): void
Writes a JSON value to the file system tree
Name | Type |
---|---|
T |
extends object``object |
Name | Type | Description |
---|---|---|
host |
Tree |
File system tree |
path |
string |
Path of JSON file in the Tree |
value |
T |
Serializable value to write |
options? |
JsonSerializeOptions |
Optional JSON Serialize Options |
void
▸ writeJsonFile<T
>(path
, data
, options?
): void
Serializes the given data to JSON and writes it to a file.
Name | Type |
---|---|
T |
extends object``object |
Name | Type | Description |
---|---|---|
path |
string |
A path to a file. |
data |
T |
data which should be serialized to JSON and written to the file |
options? |
JsonWriteOptions |
JSON serialize options |
void