-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathnode-workflow.ts
92 lines (80 loc) · 2.98 KB
/
node-workflow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @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 { Path, getSystemPath, normalize, schema, virtualFs } from '@angular-devkit/core';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
import { workflow } from '@angular-devkit/schematics';
import { BuiltinTaskExecutor } from '../../tasks/node';
import { FileSystemEngine } from '../description';
import { OptionTransform } from '../file-system-engine-host-base';
import { NodeModulesEngineHost } from '../node-module-engine-host';
import { validateOptionsWithSchema } from '../schema-option-transform';
export interface NodeWorkflowOptions {
force?: boolean;
dryRun?: boolean;
packageManager?: string;
packageManagerForce?: boolean;
packageRegistry?: string;
registry?: schema.CoreSchemaRegistry;
resolvePaths?: string[];
schemaValidation?: boolean;
optionTransforms?: OptionTransform<Record<string, unknown> | null, object>[];
engineHostCreator?: (options: NodeWorkflowOptions) => NodeModulesEngineHost;
}
/**
* A workflow specifically for Node tools.
*/
export class NodeWorkflow extends workflow.BaseWorkflow {
constructor(root: string, options: NodeWorkflowOptions);
constructor(host: virtualFs.Host, options: NodeWorkflowOptions & { root?: Path });
constructor(hostOrRoot: virtualFs.Host | string, options: NodeWorkflowOptions & { root?: Path }) {
let host;
let root;
if (typeof hostOrRoot === 'string') {
root = normalize(hostOrRoot);
host = new virtualFs.ScopedHost(new NodeJsSyncHost(), root);
} else {
host = hostOrRoot;
root = options.root;
}
const engineHost =
options.engineHostCreator?.(options) || new NodeModulesEngineHost(options.resolvePaths);
super({
host,
engineHost,
force: options.force,
dryRun: options.dryRun,
registry: options.registry,
});
engineHost.registerTaskExecutor(BuiltinTaskExecutor.NodePackage, {
allowPackageManagerOverride: true,
packageManager: options.packageManager,
force: options.packageManagerForce,
rootDirectory: root && getSystemPath(root),
registry: options.packageRegistry,
});
engineHost.registerTaskExecutor(BuiltinTaskExecutor.RepositoryInitializer, {
rootDirectory: root && getSystemPath(root),
});
engineHost.registerTaskExecutor(BuiltinTaskExecutor.RunSchematic);
if (options.optionTransforms) {
for (const transform of options.optionTransforms) {
engineHost.registerOptionsTransform(transform);
}
}
if (options.schemaValidation) {
engineHost.registerOptionsTransform(validateOptionsWithSchema(this.registry));
}
this._context = [];
}
override get engine(): FileSystemEngine {
return this._engine as FileSystemEngine;
}
override get engineHost(): NodeModulesEngineHost {
return this._engineHost as NodeModulesEngineHost;
}
}