nx 13.8.8 → 13.9.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/nx.d.ts +1 -0
- package/bin/nx.js +78 -1
- package/bin/nx.js.map +1 -1
- package/package.json +19 -2
- package/src/cli/decorate-cli.d.ts +1 -0
- package/src/cli/decorate-cli.js +19 -0
- package/src/cli/decorate-cli.js.map +1 -0
- package/src/cli/find-workspace-root.d.ts +8 -0
- package/src/cli/find-workspace-root.js +25 -0
- package/src/cli/find-workspace-root.js.map +1 -0
- package/src/cli/index.d.ts +3 -0
- package/src/cli/index.js +74 -0
- package/src/cli/index.js.map +1 -0
- package/src/cli/init-local.d.ts +2 -0
- package/src/cli/init-local.js +109 -0
- package/src/cli/init-local.js.map +1 -0
- package/src/cli/is_ci.d.ts +1 -0
- package/src/cli/is_ci.js +20 -0
- package/src/cli/is_ci.js.map +1 -0
- package/src/cli/output.d.ts +58 -0
- package/src/cli/output.js +129 -0
- package/src/cli/output.js.map +1 -0
- package/src/cli/parse-run-one-options.d.ts +6 -0
- package/src/cli/parse-run-one-options.js +139 -0
- package/src/cli/parse-run-one-options.js.map +1 -0
- package/src/cli/run-cli.d.ts +1 -0
- package/src/cli/run-cli.js +69 -0
- package/src/cli/run-cli.js.map +1 -0
- package/src/cli/workspace.d.ts +4 -0
- package/src/cli/workspace.js +3 -0
- package/src/cli/workspace.js.map +1 -0
- package/src/commands/generate.d.ts +15 -0
- package/src/commands/generate.js +170 -0
- package/src/commands/generate.js.map +1 -0
- package/src/commands/help.d.ts +1 -0
- package/src/commands/help.js +34 -0
- package/src/commands/help.js.map +1 -0
- package/src/commands/migrate.d.ts +77 -0
- package/src/commands/migrate.js +584 -0
- package/src/commands/migrate.js.map +1 -0
- package/src/commands/ngcli-adapter.d.ts +111 -0
- package/src/commands/ngcli-adapter.js +940 -0
- package/src/commands/ngcli-adapter.js.map +1 -0
- package/src/commands/run.d.ts +51 -0
- package/src/commands/run.js +224 -0
- package/src/commands/run.js.map +1 -0
- package/src/compat/compat.d.ts +1 -0
- package/src/compat/compat.js +86 -0
- package/src/compat/compat.js.map +1 -0
- package/src/shared/logger.d.ts +11 -0
- package/src/shared/logger.js +48 -0
- package/src/shared/logger.js.map +1 -0
- package/src/shared/nx-plugin.d.ts +18 -0
- package/src/shared/nx-plugin.js +53 -0
- package/src/shared/nx-plugin.js.map +1 -0
- package/src/shared/nx.d.ts +110 -0
- package/src/shared/nx.js +3 -0
- package/src/shared/nx.js.map +1 -0
- package/src/shared/package-json.d.ts +28 -0
- package/src/shared/package-json.js +10 -0
- package/src/shared/package-json.js.map +1 -0
- package/src/shared/package-manager.d.ts +32 -0
- package/src/shared/package-manager.js +83 -0
- package/src/shared/package-manager.js.map +1 -0
- package/src/shared/params.d.ts +113 -0
- package/src/shared/params.js +587 -0
- package/src/shared/params.js.map +1 -0
- package/src/shared/print-help.d.ts +2 -0
- package/src/shared/print-help.js +32 -0
- package/src/shared/print-help.js.map +1 -0
- package/src/shared/project-graph.d.ts +135 -0
- package/src/shared/project-graph.js +22 -0
- package/src/shared/project-graph.js.map +1 -0
- package/src/shared/tasks.d.ts +82 -0
- package/src/shared/tasks.js +3 -0
- package/src/shared/tasks.js.map +1 -0
- package/src/shared/tree.d.ts +115 -0
- package/src/shared/tree.js +259 -0
- package/src/shared/tree.js.map +1 -0
- package/src/shared/workspace.d.ts +257 -0
- package/src/shared/workspace.js +522 -0
- package/src/shared/workspace.js.map +1 -0
- package/src/utils/app-root.d.ts +2 -0
- package/src/utils/app-root.js +30 -0
- package/src/utils/app-root.js.map +1 -0
- package/src/utils/fileutils.d.ts +31 -0
- package/src/utils/fileutils.js +45 -0
- package/src/utils/fileutils.js.map +1 -0
- package/src/utils/json.d.ts +39 -0
- package/src/utils/json.js +48 -0
- package/src/utils/json.js.map +1 -0
- package/src/utils/object-sort.d.ts +1 -0
- package/src/utils/object-sort.js +12 -0
- package/src/utils/object-sort.js.map +1 -0
- package/src/utils/register.d.ts +9 -0
- package/src/utils/register.js +36 -0
- package/src/utils/register.js.map +1 -0
- package/src/utils/split-target.d.ts +1 -0
- package/src/utils/split-target.js +26 -0
- package/src/utils/split-target.js.map +1 -0
|
@@ -0,0 +1,940 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogger = exports.invokeNew = exports.wrapAngularDevkitSchematic = exports.mockSchematicsForTesting = exports.overrideCollectionResolutionForTesting = exports.runMigration = exports.generate = exports.NxScopeHostUsedForWrappedSchematics = exports.NxScopedHostForMigrations = exports.NxScopedHost = exports.scheduleTarget = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable no-restricted-imports */
|
|
6
|
+
const core_1 = require("@angular-devkit/core");
|
|
7
|
+
const chalk = require("chalk");
|
|
8
|
+
const node_1 = require("@angular-devkit/core/node");
|
|
9
|
+
const package_manager_1 = require("../shared/package-manager");
|
|
10
|
+
const workspace_1 = require("../shared/workspace");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const rxjs_1 = require("rxjs");
|
|
13
|
+
const operators_1 = require("rxjs/operators");
|
|
14
|
+
const logger_1 = require("../shared/logger");
|
|
15
|
+
const fileutils_1 = require("../utils/fileutils");
|
|
16
|
+
const json_1 = require("../utils/json");
|
|
17
|
+
function scheduleTarget(root, opts, verbose) {
|
|
18
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
19
|
+
const { Architect } = require('@angular-devkit/architect');
|
|
20
|
+
const { WorkspaceNodeModulesArchitectHost, } = require('@angular-devkit/architect/node');
|
|
21
|
+
const logger = getTargetLogger(opts.executor, verbose);
|
|
22
|
+
const fsHost = new NxScopedHost((0, core_1.normalize)(root));
|
|
23
|
+
const { workspace } = yield core_1.workspaces.readWorkspace((0, workspace_1.workspaceConfigName)(root), core_1.workspaces.createWorkspaceHost(fsHost));
|
|
24
|
+
const registry = new core_1.schema.CoreSchemaRegistry();
|
|
25
|
+
registry.addPostTransform(core_1.schema.transforms.addUndefinedDefaults);
|
|
26
|
+
const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, root);
|
|
27
|
+
const architect = new Architect(architectHost, registry);
|
|
28
|
+
const run = yield architect.scheduleTarget({
|
|
29
|
+
project: opts.project,
|
|
30
|
+
target: opts.target,
|
|
31
|
+
configuration: opts.configuration,
|
|
32
|
+
}, opts.runOptions, { logger });
|
|
33
|
+
let lastOutputError;
|
|
34
|
+
return run.output.pipe((0, operators_1.tap)((output) => (lastOutputError = !output.success ? output.error : undefined), (error) => { }, // do nothing, this could be an intentional error
|
|
35
|
+
() => {
|
|
36
|
+
lastOutputError ? logger.error(lastOutputError) : 0;
|
|
37
|
+
}));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.scheduleTarget = scheduleTarget;
|
|
41
|
+
function createWorkflow(fsHost, root, opts) {
|
|
42
|
+
const NodeWorkflow = require('@angular-devkit/schematics/tools').NodeWorkflow;
|
|
43
|
+
const workflow = new NodeWorkflow(fsHost, {
|
|
44
|
+
force: opts.force,
|
|
45
|
+
dryRun: opts.dryRun,
|
|
46
|
+
packageManager: (0, package_manager_1.detectPackageManager)(),
|
|
47
|
+
root: (0, core_1.normalize)(root),
|
|
48
|
+
registry: new core_1.schema.CoreSchemaRegistry(require('@angular-devkit/schematics').formats.standardFormats),
|
|
49
|
+
resolvePaths: [process.cwd(), root],
|
|
50
|
+
});
|
|
51
|
+
workflow.registry.addPostTransform(core_1.schema.transforms.addUndefinedDefaults);
|
|
52
|
+
workflow.engineHost.registerOptionsTransform(require('@angular-devkit/schematics/tools').validateOptionsWithSchema(workflow.registry));
|
|
53
|
+
if (opts.interactive) {
|
|
54
|
+
workflow.registry.usePromptProvider(createPromptProvider());
|
|
55
|
+
}
|
|
56
|
+
return workflow;
|
|
57
|
+
}
|
|
58
|
+
function getCollection(workflow, name) {
|
|
59
|
+
const collection = workflow.engine.createCollection(name);
|
|
60
|
+
if (!collection)
|
|
61
|
+
throw new Error(`Cannot find collection '${name}'`);
|
|
62
|
+
return collection;
|
|
63
|
+
}
|
|
64
|
+
function createRecorder(host, record, logger) {
|
|
65
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
66
|
+
const actualConfigName = yield host.workspaceConfigName();
|
|
67
|
+
return (event) => {
|
|
68
|
+
let eventPath = event.path.startsWith('/')
|
|
69
|
+
? event.path.substr(1)
|
|
70
|
+
: event.path;
|
|
71
|
+
if (eventPath === 'workspace.json' || eventPath === 'angular.json') {
|
|
72
|
+
eventPath = actualConfigName;
|
|
73
|
+
}
|
|
74
|
+
if (event.kind === 'error') {
|
|
75
|
+
record.error = true;
|
|
76
|
+
logger.warn(`ERROR! ${eventPath} ${event.description == 'alreadyExist'
|
|
77
|
+
? 'already exists'
|
|
78
|
+
: 'does not exist.'}.`);
|
|
79
|
+
}
|
|
80
|
+
else if (event.kind === 'update') {
|
|
81
|
+
record.loggingQueue.push(core_1.tags.oneLine `${chalk.white('UPDATE')} ${eventPath}`);
|
|
82
|
+
}
|
|
83
|
+
else if (event.kind === 'create') {
|
|
84
|
+
record.loggingQueue.push(core_1.tags.oneLine `${chalk.green('CREATE')} ${eventPath}`);
|
|
85
|
+
}
|
|
86
|
+
else if (event.kind === 'delete') {
|
|
87
|
+
record.loggingQueue.push(`${chalk.yellow('DELETE')} ${eventPath}`);
|
|
88
|
+
}
|
|
89
|
+
else if (event.kind === 'rename') {
|
|
90
|
+
record.loggingQueue.push(`${chalk.blue('RENAME')} ${eventPath} => ${event.to}`);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function runSchematic(host, root, workflow, logger, opts, schematic, printDryRunMessage = true, recorder = null) {
|
|
96
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
97
|
+
const record = { loggingQueue: [], error: false };
|
|
98
|
+
workflow.reporter.subscribe(recorder || (yield createRecorder(host, record, logger)));
|
|
99
|
+
try {
|
|
100
|
+
yield workflow
|
|
101
|
+
.execute({
|
|
102
|
+
collection: opts.collectionName,
|
|
103
|
+
schematic: opts.generatorName,
|
|
104
|
+
options: opts.generatorOptions,
|
|
105
|
+
debug: opts.debug,
|
|
106
|
+
logger,
|
|
107
|
+
})
|
|
108
|
+
.toPromise();
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
console.log(e);
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
if (!record.error) {
|
|
115
|
+
record.loggingQueue.forEach((log) => logger.info(log));
|
|
116
|
+
}
|
|
117
|
+
if (opts.dryRun && printDryRunMessage) {
|
|
118
|
+
logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`);
|
|
119
|
+
}
|
|
120
|
+
return { status: 0, loggingQueue: record.loggingQueue };
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
class NxScopedHost extends core_1.virtualFs.ScopedHost {
|
|
124
|
+
constructor(root) {
|
|
125
|
+
super(new node_1.NodeJsSyncHost(), root);
|
|
126
|
+
this.__readWorkspaceConfiguration = (configFileName, overrides) => {
|
|
127
|
+
const readJsonFile = (path) => super
|
|
128
|
+
.read(path)
|
|
129
|
+
.pipe((0, operators_1.map)((data) => JSON.parse(Buffer.from(data).toString())));
|
|
130
|
+
const readWorkspaceJsonFile = (nxJson) => {
|
|
131
|
+
if (overrides === null || overrides === void 0 ? void 0 : overrides.workspace) {
|
|
132
|
+
return overrides.workspace;
|
|
133
|
+
}
|
|
134
|
+
else if (this.__nxInMemoryWorkspace) {
|
|
135
|
+
return (0, rxjs_1.of)(this.__nxInMemoryWorkspace);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (configFileName) {
|
|
139
|
+
return super
|
|
140
|
+
.read(configFileName)
|
|
141
|
+
.pipe((0, operators_1.map)((data) => (0, json_1.parseJson)(Buffer.from(data).toString())));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const staticProjects = (0, workspace_1.globForProjectFiles)(this._root);
|
|
145
|
+
this.__nxInMemoryWorkspace = (0, workspace_1.buildWorkspaceConfigurationFromGlobs)(nxJson, staticProjects.filter((x) => (0, path_1.basename)(x) !== 'package.json'));
|
|
146
|
+
Object.entries(this.__nxInMemoryWorkspace.projects).forEach(([project, config]) => {
|
|
147
|
+
this.__nxInMemoryWorkspace.projects[project] = config.root;
|
|
148
|
+
});
|
|
149
|
+
return (0, rxjs_1.of)(this.__nxInMemoryWorkspace);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const readNxJsonFile = () => {
|
|
154
|
+
if (overrides === null || overrides === void 0 ? void 0 : overrides.nx) {
|
|
155
|
+
return overrides.nx;
|
|
156
|
+
}
|
|
157
|
+
return readJsonFile('nx.json');
|
|
158
|
+
};
|
|
159
|
+
return super.exists('nx.json').pipe((0, operators_1.switchMap)((nxJsonExists) => {
|
|
160
|
+
let nxJsonObservable = rxjs_1.NEVER;
|
|
161
|
+
if (nxJsonExists) {
|
|
162
|
+
nxJsonObservable = readNxJsonFile();
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
nxJsonObservable = (0, rxjs_1.of)({});
|
|
166
|
+
}
|
|
167
|
+
const workspaceJsonObservable = nxJsonObservable.pipe((0, operators_1.switchMap)((x) => readWorkspaceJsonFile(x)));
|
|
168
|
+
return (0, rxjs_1.forkJoin)([nxJsonObservable, workspaceJsonObservable]);
|
|
169
|
+
}), (0, operators_1.switchMap)(([nxJson, workspaceJson]) => {
|
|
170
|
+
try {
|
|
171
|
+
// resolve inline configurations and downlevel format
|
|
172
|
+
return this.resolveInlineProjectConfigurations(workspaceJson).pipe((0, operators_1.map)((x) => {
|
|
173
|
+
var _a, _b, _c;
|
|
174
|
+
const angularJson = x;
|
|
175
|
+
// assign props ng cli expects from nx json, if it exists
|
|
176
|
+
(_a = angularJson.cli) !== null && _a !== void 0 ? _a : (angularJson.cli = nxJson === null || nxJson === void 0 ? void 0 : nxJson.cli);
|
|
177
|
+
(_b = angularJson.generators) !== null && _b !== void 0 ? _b : (angularJson.generators = nxJson === null || nxJson === void 0 ? void 0 : nxJson.generators);
|
|
178
|
+
(_c = angularJson.defaultProject) !== null && _c !== void 0 ? _c : (angularJson.defaultProject = nxJson === null || nxJson === void 0 ? void 0 : nxJson.defaultProject);
|
|
179
|
+
if (workspaceJson.version === 2) {
|
|
180
|
+
const formatted = (0, workspace_1.toOldFormatOrNull)(workspaceJson);
|
|
181
|
+
return formatted
|
|
182
|
+
? Buffer.from((0, json_1.serializeJson)(formatted))
|
|
183
|
+
: Buffer.from((0, json_1.serializeJson)(x));
|
|
184
|
+
}
|
|
185
|
+
return Buffer.from((0, json_1.serializeJson)(x));
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
catch (_a) {
|
|
189
|
+
return (0, rxjs_1.of)(Buffer.from((0, json_1.serializeJson)(workspaceJson)));
|
|
190
|
+
}
|
|
191
|
+
}));
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
read(path) {
|
|
195
|
+
return this.context(path).pipe((0, operators_1.switchMap)((r) => {
|
|
196
|
+
if (r.isWorkspaceConfig) {
|
|
197
|
+
return this.__readWorkspaceConfiguration(r.actualConfigFileName);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return super.read(path);
|
|
201
|
+
}
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
write(path, content) {
|
|
205
|
+
return this.context(path).pipe((0, operators_1.switchMap)((r) => {
|
|
206
|
+
if (r.isWorkspaceConfig) {
|
|
207
|
+
return this.writeWorkspaceConfiguration(r, content);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
return super.write(path, content);
|
|
211
|
+
}
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
isFile(path) {
|
|
215
|
+
return this.context(path).pipe((0, operators_1.switchMap)((r) => {
|
|
216
|
+
if (r.isWorkspaceConfig) {
|
|
217
|
+
return (0, rxjs_1.of)(true); // isWorkspaceConfig means its a file
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
return super.isFile(path);
|
|
221
|
+
}
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
exists(path) {
|
|
225
|
+
return this.context(path).pipe((0, operators_1.switchMap)((r) => {
|
|
226
|
+
if (r.isWorkspaceConfig) {
|
|
227
|
+
return (0, rxjs_1.of)(true);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
return super.exists(path);
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
workspaceConfigName() {
|
|
235
|
+
return super
|
|
236
|
+
.exists('/angular.json')
|
|
237
|
+
.pipe((0, operators_1.map)((hasAngularJson) => hasAngularJson ? 'angular.json' : 'workspace.json'))
|
|
238
|
+
.toPromise();
|
|
239
|
+
}
|
|
240
|
+
context(path) {
|
|
241
|
+
if (isWorkspaceConfigPath(path)) {
|
|
242
|
+
return (0, rxjs_1.forkJoin)([
|
|
243
|
+
super.exists('/angular.json'),
|
|
244
|
+
super.exists('/workspace.json'),
|
|
245
|
+
]).pipe((0, operators_1.switchMap)(([isAngularJson, isWorkspaceJson]) => {
|
|
246
|
+
if (!isAngularJson && !isWorkspaceJson) {
|
|
247
|
+
return (0, rxjs_1.of)({
|
|
248
|
+
isWorkspaceConfig: true,
|
|
249
|
+
actualConfigFileName: null,
|
|
250
|
+
// AngularJson / WorkspaceJson v2 is always used for standalone project config
|
|
251
|
+
isNewFormat: true,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const actualConfigFileName = isAngularJson
|
|
255
|
+
? '/angular.json'
|
|
256
|
+
: '/workspace.json';
|
|
257
|
+
return super.read(actualConfigFileName).pipe((0, operators_1.map)((r) => {
|
|
258
|
+
try {
|
|
259
|
+
const w = (0, json_1.parseJson)(Buffer.from(r).toString());
|
|
260
|
+
return {
|
|
261
|
+
isWorkspaceConfig: true,
|
|
262
|
+
actualConfigFileName,
|
|
263
|
+
isNewFormat: w.version === 2,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
catch (_a) {
|
|
267
|
+
return {
|
|
268
|
+
isWorkspaceConfig: true,
|
|
269
|
+
actualConfigFileName,
|
|
270
|
+
isNewFormat: false,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}));
|
|
274
|
+
}));
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
return (0, rxjs_1.of)({
|
|
278
|
+
isWorkspaceConfig: false,
|
|
279
|
+
actualConfigFileName: null,
|
|
280
|
+
isNewFormat: false,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
writeWorkspaceConfiguration(context, content) {
|
|
285
|
+
const config = (0, json_1.parseJson)(Buffer.from(content).toString());
|
|
286
|
+
if (context.isNewFormat) {
|
|
287
|
+
try {
|
|
288
|
+
const w = (0, json_1.parseJson)(Buffer.from(content).toString());
|
|
289
|
+
const formatted = (0, workspace_1.toNewFormatOrNull)(w);
|
|
290
|
+
if (formatted) {
|
|
291
|
+
const { cli, generators, defaultProject } = formatted, workspaceJson = (0, tslib_1.__rest)(formatted, ["cli", "generators", "defaultProject"]);
|
|
292
|
+
return (0, rxjs_1.merge)(this.writeWorkspaceConfigFiles(context, workspaceJson), cli || generators || defaultProject
|
|
293
|
+
? this.__saveNxJsonProps({ cli, generators, defaultProject })
|
|
294
|
+
: (0, rxjs_1.of)(null));
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
const { cli, schematics, generators, defaultProject } = w, angularJson = (0, tslib_1.__rest)(w, ["cli", "schematics", "generators", "defaultProject"]);
|
|
298
|
+
return (0, rxjs_1.merge)(this.writeWorkspaceConfigFiles(context, angularJson), cli || schematics
|
|
299
|
+
? this.__saveNxJsonProps({
|
|
300
|
+
cli,
|
|
301
|
+
defaultProject,
|
|
302
|
+
generators: schematics || generators,
|
|
303
|
+
})
|
|
304
|
+
: (0, rxjs_1.of)(null));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (e) { }
|
|
308
|
+
}
|
|
309
|
+
const { cli, schematics, generators, defaultProject } = config, angularJson = (0, tslib_1.__rest)(config, ["cli", "schematics", "generators", "defaultProject"]);
|
|
310
|
+
return (0, rxjs_1.merge)(this.writeWorkspaceConfigFiles(context, angularJson), this.__saveNxJsonProps({
|
|
311
|
+
cli,
|
|
312
|
+
defaultProject,
|
|
313
|
+
generators: schematics || generators,
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
__saveNxJsonProps(props) {
|
|
317
|
+
const nxJsonPath = 'nx.json';
|
|
318
|
+
return super.read(nxJsonPath).pipe((0, operators_1.switchMap)((buf) => {
|
|
319
|
+
const nxJson = (0, json_1.parseJson)(Buffer.from(buf).toString());
|
|
320
|
+
Object.assign(nxJson, props);
|
|
321
|
+
return super.write(nxJsonPath, Buffer.from((0, json_1.serializeJson)(nxJson)));
|
|
322
|
+
}));
|
|
323
|
+
}
|
|
324
|
+
writeWorkspaceConfigFiles({ actualConfigFileName: workspaceFileName, isNewFormat }, config) {
|
|
325
|
+
// copy to avoid removing inlined config files.
|
|
326
|
+
const writeObservables = [];
|
|
327
|
+
const configToWrite = Object.assign(Object.assign({}, config), { projects: Object.assign({}, config.projects) });
|
|
328
|
+
const projects = Object.entries(configToWrite.projects);
|
|
329
|
+
for (const [project, projectConfig] of projects) {
|
|
330
|
+
if (projectConfig.configFilePath) {
|
|
331
|
+
if (workspaceFileName && !isNewFormat) {
|
|
332
|
+
throw new Error('Attempted to write standalone project configuration into a v1 workspace');
|
|
333
|
+
}
|
|
334
|
+
// project was read from a project.json file
|
|
335
|
+
const configPath = projectConfig.configFilePath;
|
|
336
|
+
const fileConfigObject = Object.assign({}, projectConfig);
|
|
337
|
+
delete fileConfigObject.configFilePath; // remove the configFilePath before writing
|
|
338
|
+
const projectJsonWrite = super.write(configPath, Buffer.from((0, json_1.serializeJson)(fileConfigObject))); // write back to the project.json file
|
|
339
|
+
writeObservables.push(projectJsonWrite);
|
|
340
|
+
configToWrite.projects[project] = (0, core_1.normalize)((0, path_1.dirname)(configPath)); // update the config object to point to the written file.
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (workspaceFileName) {
|
|
344
|
+
const workspaceJsonWrite = super.write(workspaceFileName, Buffer.from((0, json_1.serializeJson)(configToWrite)));
|
|
345
|
+
writeObservables.push(workspaceJsonWrite);
|
|
346
|
+
}
|
|
347
|
+
return (0, rxjs_1.merge)(...writeObservables);
|
|
348
|
+
}
|
|
349
|
+
resolveInlineProjectConfigurations(config) {
|
|
350
|
+
var _a;
|
|
351
|
+
// Creates an observable where each emission is a project configuration
|
|
352
|
+
// that is not listed inside workspace.json. Each time it encounters a
|
|
353
|
+
// standalone config, observable is updated by concatenating the new
|
|
354
|
+
// config read operation.
|
|
355
|
+
const observables = [];
|
|
356
|
+
Object.entries((_a = config.projects) !== null && _a !== void 0 ? _a : {}).forEach(([project, projectConfig]) => {
|
|
357
|
+
if (typeof projectConfig === 'string') {
|
|
358
|
+
// configFilePath is not written to files, but is stored on the config object
|
|
359
|
+
// so that we know where to save the project's configuration if it was updated
|
|
360
|
+
// by another angular schematic.
|
|
361
|
+
const configFilePath = (0, path_1.join)(projectConfig, 'project.json');
|
|
362
|
+
const next = this.read(configFilePath).pipe((0, operators_1.map)((x) => ({
|
|
363
|
+
project,
|
|
364
|
+
projectConfig: Object.assign(Object.assign({}, (0, json_1.parseJson)(Buffer.from(x).toString())), { configFilePath }),
|
|
365
|
+
})));
|
|
366
|
+
observables.push(next);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
return (0, rxjs_1.merge)(...observables).pipe((0, operators_1.toArray)(), (0, operators_1.map)((configs) => {
|
|
370
|
+
configs.forEach(({ project, projectConfig }) => {
|
|
371
|
+
config.projects[project] = projectConfig;
|
|
372
|
+
});
|
|
373
|
+
return config;
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
exports.NxScopedHost = NxScopedHost;
|
|
378
|
+
/**
|
|
379
|
+
* This host contains the workaround needed to run Angular migrations
|
|
380
|
+
*/
|
|
381
|
+
class NxScopedHostForMigrations extends NxScopedHost {
|
|
382
|
+
constructor(root) {
|
|
383
|
+
super(root);
|
|
384
|
+
}
|
|
385
|
+
read(path) {
|
|
386
|
+
if (isWorkspaceConfigPath(path)) {
|
|
387
|
+
return super.read(path).pipe((0, operators_1.map)(processConfigWhenReading));
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
return super.read(path);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
write(path, content) {
|
|
394
|
+
if (isWorkspaceConfigPath(path)) {
|
|
395
|
+
return super.write(path, processConfigWhenWriting(content));
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
return super.write(path, content);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
exports.NxScopedHostForMigrations = NxScopedHostForMigrations;
|
|
403
|
+
class NxScopeHostUsedForWrappedSchematics extends NxScopedHost {
|
|
404
|
+
constructor(root, host) {
|
|
405
|
+
super(root);
|
|
406
|
+
this.host = host;
|
|
407
|
+
}
|
|
408
|
+
read(path) {
|
|
409
|
+
if (isWorkspaceConfigPath(path)) {
|
|
410
|
+
const nxJsonChange = findMatchingFileChange(this.host, 'nx.json');
|
|
411
|
+
const match = findWorkspaceConfigFileChange(this.host);
|
|
412
|
+
let workspaceJsonOverride;
|
|
413
|
+
let actualConfigFileName = [
|
|
414
|
+
'/workspace.json',
|
|
415
|
+
'/angular.json',
|
|
416
|
+
].filter((f) => this.host.exists(f))[0];
|
|
417
|
+
if (actualConfigFileName) {
|
|
418
|
+
if (match) {
|
|
419
|
+
workspaceJsonOverride = (0, rxjs_1.of)((0, json_1.parseJson)(match.content.toString()));
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else if (!this.__nxInMemoryWorkspace) {
|
|
423
|
+
// if we've already dealt with this, let NxScopedHost read the cache...
|
|
424
|
+
// projects created inside a generator will not be visible
|
|
425
|
+
// to glob when it runs in nx/shared/workspace, so
|
|
426
|
+
// we have to add them into the file.
|
|
427
|
+
const createdProjectFiles = findCreatedProjects(this.host);
|
|
428
|
+
const deletedProjectFiles = findDeletedProjects(this.host);
|
|
429
|
+
const nxJsonInTree = nxJsonChange
|
|
430
|
+
? (0, json_1.parseJson)(nxJsonChange.content.toString())
|
|
431
|
+
: (0, json_1.parseJson)(this.host.read('nx.json').toString());
|
|
432
|
+
const readJsonWithHost = (file) => (0, json_1.parseJson)(this.host.read(file).toString());
|
|
433
|
+
const staticProjects = (0, workspace_1.buildWorkspaceConfigurationFromGlobs)(nxJsonInTree, (0, workspace_1.globForProjectFiles)(this.host.root).filter((x) => (0, path_1.basename)(x) !== 'package.json'), readJsonWithHost);
|
|
434
|
+
const createdProjects = (0, workspace_1.buildWorkspaceConfigurationFromGlobs)(nxJsonInTree, createdProjectFiles.map((x) => x.path), readJsonWithHost).projects;
|
|
435
|
+
deletedProjectFiles.forEach((file) => {
|
|
436
|
+
const matchingStaticProject = Object.entries(staticProjects.projects).find(([, config]) => config.root === (0, path_1.dirname)(file.path));
|
|
437
|
+
if (matchingStaticProject) {
|
|
438
|
+
delete staticProjects.projects[matchingStaticProject[0]];
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
const workspace = Object.assign(Object.assign({}, staticProjects), { projects: Object.assign(Object.assign({}, staticProjects.projects), createdProjects) });
|
|
442
|
+
workspaceJsonOverride = (0, rxjs_1.of)(Object.assign(Object.assign({}, workspace), {
|
|
443
|
+
// all projects **must** be standalone if workspace.json doesn't exist
|
|
444
|
+
// since the NxScopedHost already handles the standalone config case,
|
|
445
|
+
// lets pass them as standalone.
|
|
446
|
+
projects: Object.fromEntries(Object.entries(workspace.projects).map(([project, config]) => [
|
|
447
|
+
project,
|
|
448
|
+
config.root,
|
|
449
|
+
])) }));
|
|
450
|
+
}
|
|
451
|
+
// no match, default to existing behavior
|
|
452
|
+
if (!workspaceJsonOverride && !nxJsonChange) {
|
|
453
|
+
return super.read(path);
|
|
454
|
+
}
|
|
455
|
+
// we try to format it, if it changes, return it, otherwise return the original change
|
|
456
|
+
try {
|
|
457
|
+
return this.__readWorkspaceConfiguration(actualConfigFileName, {
|
|
458
|
+
// we are overriding workspaceJson + nxJson,
|
|
459
|
+
workspace: workspaceJsonOverride,
|
|
460
|
+
nx: nxJsonChange
|
|
461
|
+
? (0, rxjs_1.of)((0, json_1.parseJson)(nxJsonChange.content.toString()))
|
|
462
|
+
: null,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
catch (e) {
|
|
466
|
+
return super.read(path);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
const match = findMatchingFileChange(this.host, path);
|
|
471
|
+
if (match) {
|
|
472
|
+
// found a matching change in the host
|
|
473
|
+
return (0, rxjs_1.of)(Buffer.from(match.content));
|
|
474
|
+
}
|
|
475
|
+
else if (
|
|
476
|
+
// found a change to workspace config, and reading a project config file
|
|
477
|
+
(0, path_1.basename)(path) === 'project.json' &&
|
|
478
|
+
findWorkspaceConfigFileChange(this.host)) {
|
|
479
|
+
return (0, rxjs_1.of)(this.host.read(path));
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
// found neither, use default read method
|
|
483
|
+
return super.read(path);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
exists(path) {
|
|
488
|
+
if (isWorkspaceConfigPath(path)) {
|
|
489
|
+
return findWorkspaceConfigFileChange(this.host)
|
|
490
|
+
? (0, rxjs_1.of)(true)
|
|
491
|
+
: super.exists(path);
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
return findMatchingFileChange(this.host, path)
|
|
495
|
+
? (0, rxjs_1.of)(true)
|
|
496
|
+
: super.exists(path);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
isDirectory(path) {
|
|
500
|
+
return super.isDirectory(path).pipe((0, operators_1.catchError)(() => (0, rxjs_1.of)(false)), (0, operators_1.switchMap)((isDirectory) => isDirectory
|
|
501
|
+
? (0, rxjs_1.of)(true)
|
|
502
|
+
: (0, rxjs_1.of)(this.host.exists(path) && !this.host.isFile(path))));
|
|
503
|
+
}
|
|
504
|
+
isFile(path) {
|
|
505
|
+
if (isWorkspaceConfigPath(path)) {
|
|
506
|
+
return findWorkspaceConfigFileChange(this.host)
|
|
507
|
+
? (0, rxjs_1.of)(true)
|
|
508
|
+
: super.isFile(path);
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
return findMatchingFileChange(this.host, path)
|
|
512
|
+
? (0, rxjs_1.of)(true)
|
|
513
|
+
: super.isFile(path);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
list(path) {
|
|
517
|
+
const fragments = this.host.children(path).map((child) => (0, core_1.fragment)(child));
|
|
518
|
+
return (0, rxjs_1.of)(fragments);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
exports.NxScopeHostUsedForWrappedSchematics = NxScopeHostUsedForWrappedSchematics;
|
|
522
|
+
function findWorkspaceConfigFileChange(host) {
|
|
523
|
+
return host
|
|
524
|
+
.listChanges()
|
|
525
|
+
.find((f) => f.path == 'workspace.json' || f.path == 'angular.json');
|
|
526
|
+
}
|
|
527
|
+
function findCreatedProjects(host) {
|
|
528
|
+
return host
|
|
529
|
+
.listChanges()
|
|
530
|
+
.filter((f) => ((0, path_1.basename)(f.path) === 'project.json' ||
|
|
531
|
+
(0, path_1.basename)(f.path) === 'package.json') &&
|
|
532
|
+
f.type === 'CREATE');
|
|
533
|
+
}
|
|
534
|
+
function findDeletedProjects(host) {
|
|
535
|
+
return host
|
|
536
|
+
.listChanges()
|
|
537
|
+
.filter((f) => (0, path_1.basename)(f.path) === 'project.json' && f.type === 'DELETE');
|
|
538
|
+
}
|
|
539
|
+
function findMatchingFileChange(host, path) {
|
|
540
|
+
const targetPath = path.startsWith('/') ? path.substring(1) : path.toString();
|
|
541
|
+
return host
|
|
542
|
+
.listChanges()
|
|
543
|
+
.find((f) => f.path === targetPath && f.type !== 'DELETE');
|
|
544
|
+
}
|
|
545
|
+
function isWorkspaceConfigPath(p) {
|
|
546
|
+
return (p === 'angular.json' ||
|
|
547
|
+
p === '/angular.json' ||
|
|
548
|
+
p === 'workspace.json' ||
|
|
549
|
+
p === '/workspace.json');
|
|
550
|
+
}
|
|
551
|
+
function processConfigWhenReading(content) {
|
|
552
|
+
try {
|
|
553
|
+
const json = (0, json_1.parseJson)(Buffer.from(content).toString());
|
|
554
|
+
Object.values(json.projects).forEach((p) => {
|
|
555
|
+
try {
|
|
556
|
+
Object.values(p.architect || p.targets).forEach((e) => {
|
|
557
|
+
if ((e.builder === '@nrwl/jest:jest' ||
|
|
558
|
+
e.executor === '@nrwl/jest:jest') &&
|
|
559
|
+
!e.options.tsConfig) {
|
|
560
|
+
e.options.tsConfig = `${p.root}/tsconfig.spec.json`;
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
catch (e) { }
|
|
565
|
+
});
|
|
566
|
+
return Buffer.from((0, json_1.serializeJson)(json));
|
|
567
|
+
}
|
|
568
|
+
catch (e) {
|
|
569
|
+
return content;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function processConfigWhenWriting(content) {
|
|
573
|
+
try {
|
|
574
|
+
const json = (0, json_1.parseJson)(Buffer.from(content).toString());
|
|
575
|
+
Object.values(json.projects).forEach((p) => {
|
|
576
|
+
try {
|
|
577
|
+
Object.values(p.architect || p.targets).forEach((e) => {
|
|
578
|
+
if ((e.builder === '@nrwl/jest:jest' ||
|
|
579
|
+
e.executor === '@nrwl/jest:jest') &&
|
|
580
|
+
e.options.tsConfig) {
|
|
581
|
+
delete e.options.tsConfig;
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
catch (e) { }
|
|
586
|
+
});
|
|
587
|
+
return Buffer.from((0, json_1.serializeJson)(json));
|
|
588
|
+
}
|
|
589
|
+
catch (e) {
|
|
590
|
+
return content;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function generate(root, opts, verbose) {
|
|
594
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
595
|
+
const logger = (0, exports.getLogger)(verbose);
|
|
596
|
+
const fsHost = new NxScopedHost((0, core_1.normalize)(root));
|
|
597
|
+
const workflow = createWorkflow(fsHost, root, opts);
|
|
598
|
+
const collection = getCollection(workflow, opts.collectionName);
|
|
599
|
+
const schematic = collection.createSchematic(opts.generatorName, true);
|
|
600
|
+
return (yield runSchematic(fsHost, root, workflow, logger, Object.assign(Object.assign({}, opts), { generatorName: schematic.description.name }), schematic)).status;
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
exports.generate = generate;
|
|
604
|
+
function createPromptProvider() {
|
|
605
|
+
return (definitions) => {
|
|
606
|
+
const questions = definitions.map((definition) => {
|
|
607
|
+
const question = {
|
|
608
|
+
name: definition.id,
|
|
609
|
+
message: definition.message,
|
|
610
|
+
};
|
|
611
|
+
if (definition.default) {
|
|
612
|
+
question.initial = definition.default;
|
|
613
|
+
}
|
|
614
|
+
const validator = definition.validator;
|
|
615
|
+
if (validator) {
|
|
616
|
+
question.validate = (input) => validator(input);
|
|
617
|
+
}
|
|
618
|
+
switch (definition.type) {
|
|
619
|
+
case 'string':
|
|
620
|
+
case 'input':
|
|
621
|
+
return Object.assign(Object.assign({}, question), { type: 'input' });
|
|
622
|
+
case 'boolean':
|
|
623
|
+
case 'confirmation':
|
|
624
|
+
case 'confirm':
|
|
625
|
+
return Object.assign(Object.assign({}, question), { type: 'confirm' });
|
|
626
|
+
case 'number':
|
|
627
|
+
case 'numeral':
|
|
628
|
+
return Object.assign(Object.assign({}, question), { type: 'numeral' });
|
|
629
|
+
case 'list':
|
|
630
|
+
return Object.assign(Object.assign({}, question), { type: !!definition.multiselect ? 'multiselect' : 'select', choices: definition.items &&
|
|
631
|
+
definition.items.map((item) => {
|
|
632
|
+
if (typeof item == 'string') {
|
|
633
|
+
return item;
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
return {
|
|
637
|
+
message: item.label,
|
|
638
|
+
name: item.value,
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
}) });
|
|
642
|
+
default:
|
|
643
|
+
return Object.assign(Object.assign({}, question), { type: definition.type });
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
return require('enquirer').prompt(questions);
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
function runMigration(root, packageName, migrationName, isVerbose) {
|
|
650
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
651
|
+
const logger = (0, exports.getLogger)(isVerbose);
|
|
652
|
+
const fsHost = new NxScopedHost((0, core_1.normalize)(root));
|
|
653
|
+
const workflow = createWorkflow(fsHost, root, {});
|
|
654
|
+
const collection = resolveMigrationsCollection(packageName);
|
|
655
|
+
return workflow
|
|
656
|
+
.execute({
|
|
657
|
+
collection,
|
|
658
|
+
schematic: migrationName,
|
|
659
|
+
options: {},
|
|
660
|
+
debug: false,
|
|
661
|
+
logger: logger,
|
|
662
|
+
})
|
|
663
|
+
.toPromise();
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
exports.runMigration = runMigration;
|
|
667
|
+
function resolveMigrationsCollection(name) {
|
|
668
|
+
var _a;
|
|
669
|
+
let collectionPath = undefined;
|
|
670
|
+
if (name.startsWith('.') || name.startsWith('/')) {
|
|
671
|
+
name = (0, path_1.resolve)(name);
|
|
672
|
+
}
|
|
673
|
+
if ((0, path_1.extname)(name)) {
|
|
674
|
+
collectionPath = require.resolve(name);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
let packageJsonPath;
|
|
678
|
+
try {
|
|
679
|
+
packageJsonPath = require.resolve((0, path_1.join)(name, 'package.json'), {
|
|
680
|
+
paths: [process.cwd()],
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
catch (e) {
|
|
684
|
+
// workaround for a bug in node 12
|
|
685
|
+
packageJsonPath = require.resolve((0, path_1.join)(process.cwd(), name, 'package.json'));
|
|
686
|
+
}
|
|
687
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
688
|
+
const packageJson = require(packageJsonPath);
|
|
689
|
+
let pkgJsonSchematics = (_a = packageJson['nx-migrations']) !== null && _a !== void 0 ? _a : packageJson['ng-update'];
|
|
690
|
+
if (!pkgJsonSchematics) {
|
|
691
|
+
throw new Error(`Could not find migrations in package: "${name}"`);
|
|
692
|
+
}
|
|
693
|
+
if (typeof pkgJsonSchematics != 'string') {
|
|
694
|
+
pkgJsonSchematics = pkgJsonSchematics.migrations;
|
|
695
|
+
}
|
|
696
|
+
collectionPath = require.resolve(pkgJsonSchematics, {
|
|
697
|
+
paths: [(0, path_1.dirname)(packageJsonPath)],
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
try {
|
|
701
|
+
if (collectionPath) {
|
|
702
|
+
(0, fileutils_1.readJsonFile)(collectionPath);
|
|
703
|
+
return collectionPath;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
catch (_b) {
|
|
707
|
+
throw new Error(`Invalid migration file in package: "${name}"`);
|
|
708
|
+
}
|
|
709
|
+
throw new Error(`Collection cannot be resolved: "${name}"`);
|
|
710
|
+
}
|
|
711
|
+
function convertEventTypeToHandleMultipleConfigNames(host, eventPath, content) {
|
|
712
|
+
const actualConfigName = host.exists('/angular.json')
|
|
713
|
+
? 'angular.json'
|
|
714
|
+
: 'workspace.json';
|
|
715
|
+
const isWorkspaceConfig = eventPath === 'angular.json' || eventPath === 'workspace.json';
|
|
716
|
+
if (isWorkspaceConfig) {
|
|
717
|
+
let isNewFormat = true;
|
|
718
|
+
try {
|
|
719
|
+
isNewFormat =
|
|
720
|
+
(0, json_1.parseJson)(host.read(actualConfigName, 'utf-8')).version === 2;
|
|
721
|
+
}
|
|
722
|
+
catch (e) { }
|
|
723
|
+
if (content && isNewFormat) {
|
|
724
|
+
const formatted = (0, workspace_1.toNewFormat)((0, json_1.parseJson)(content.toString()));
|
|
725
|
+
if (formatted) {
|
|
726
|
+
return {
|
|
727
|
+
eventPath: actualConfigName,
|
|
728
|
+
content: Buffer.from((0, json_1.serializeJson)(formatted)),
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
return { eventPath: actualConfigName, content };
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
else {
|
|
736
|
+
return { eventPath: actualConfigName, content };
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
return { eventPath, content };
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
let collectionResolutionOverrides = null;
|
|
744
|
+
let mockedSchematics = null;
|
|
745
|
+
/**
|
|
746
|
+
* By default, Angular Devkit schematic collections will be resolved using the Node resolution.
|
|
747
|
+
* This doesn't work if you are testing schematics that refer to other schematics in the
|
|
748
|
+
* same repo.
|
|
749
|
+
*
|
|
750
|
+
* This function can can be used to override the resolution behaviour.
|
|
751
|
+
*
|
|
752
|
+
* Example:
|
|
753
|
+
*
|
|
754
|
+
* ```typescript
|
|
755
|
+
* overrideCollectionResolutionForTesting({
|
|
756
|
+
* '@nrwl/workspace': path.join(__dirname, '../../../../workspace/generators.json'),
|
|
757
|
+
* '@nrwl/angular': path.join(__dirname, '../../../../angular/generators.json'),
|
|
758
|
+
* '@nrwl/linter': path.join(__dirname, '../../../../linter/generators.json')
|
|
759
|
+
* });
|
|
760
|
+
*
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
function overrideCollectionResolutionForTesting(collections) {
|
|
764
|
+
collectionResolutionOverrides = collections;
|
|
765
|
+
}
|
|
766
|
+
exports.overrideCollectionResolutionForTesting = overrideCollectionResolutionForTesting;
|
|
767
|
+
/**
|
|
768
|
+
* If you have an Nx Devkit generator invoking the wrapped Angular Devkit schematic,
|
|
769
|
+
* and you don't want the Angular Devkit schematic to run, you can mock it up using this function.
|
|
770
|
+
*
|
|
771
|
+
* Unfortunately, there are some edge cases in the Nx-Angular devkit integration that
|
|
772
|
+
* can be seen in the unit tests context. This function is useful for handling that as well.
|
|
773
|
+
*
|
|
774
|
+
* In this case, you can mock it up.
|
|
775
|
+
*
|
|
776
|
+
* Example:
|
|
777
|
+
*
|
|
778
|
+
* ```typescript
|
|
779
|
+
* mockSchematicsForTesting({
|
|
780
|
+
* 'mycollection:myschematic': (tree, params) => {
|
|
781
|
+
* tree.write('README.md');
|
|
782
|
+
* }
|
|
783
|
+
* });
|
|
784
|
+
*
|
|
785
|
+
* ```
|
|
786
|
+
*/
|
|
787
|
+
function mockSchematicsForTesting(schematics) {
|
|
788
|
+
mockedSchematics = schematics;
|
|
789
|
+
}
|
|
790
|
+
exports.mockSchematicsForTesting = mockSchematicsForTesting;
|
|
791
|
+
function wrapAngularDevkitSchematic(collectionName, generatorName) {
|
|
792
|
+
return (host, generatorOptions) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
793
|
+
if (mockedSchematics &&
|
|
794
|
+
mockedSchematics[`${collectionName}:${generatorName}`]) {
|
|
795
|
+
return yield mockedSchematics[`${collectionName}:${generatorName}`](host, generatorOptions);
|
|
796
|
+
}
|
|
797
|
+
const emptyLogger = {
|
|
798
|
+
log: (e) => { },
|
|
799
|
+
info: (e) => { },
|
|
800
|
+
warn: (e) => { },
|
|
801
|
+
debug: () => { },
|
|
802
|
+
error: (e) => { },
|
|
803
|
+
fatal: (e) => { },
|
|
804
|
+
};
|
|
805
|
+
emptyLogger.createChild = () => emptyLogger;
|
|
806
|
+
const recorder = (event) => {
|
|
807
|
+
let eventPath = event.path.startsWith('/')
|
|
808
|
+
? event.path.substr(1)
|
|
809
|
+
: event.path;
|
|
810
|
+
const r = convertEventTypeToHandleMultipleConfigNames(host, eventPath, event.content);
|
|
811
|
+
if (event.kind === 'error') {
|
|
812
|
+
}
|
|
813
|
+
else if (event.kind === 'update') {
|
|
814
|
+
if (r.eventPath === 'angular.json' ||
|
|
815
|
+
r.eventPath === 'workspace.json') {
|
|
816
|
+
saveWorkspaceConfigurationInWrappedSchematic(host, r);
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
host.write(r.eventPath, r.content);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
else if (event.kind === 'create') {
|
|
823
|
+
host.write(r.eventPath, r.content);
|
|
824
|
+
}
|
|
825
|
+
else if (event.kind === 'delete') {
|
|
826
|
+
host.delete(r.eventPath);
|
|
827
|
+
}
|
|
828
|
+
else if (event.kind === 'rename') {
|
|
829
|
+
host.rename(r.eventPath, event.to);
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
const fsHost = new NxScopeHostUsedForWrappedSchematics((0, core_1.normalize)(host.root), host);
|
|
833
|
+
const options = {
|
|
834
|
+
generatorOptions,
|
|
835
|
+
dryRun: true,
|
|
836
|
+
interactive: false,
|
|
837
|
+
help: false,
|
|
838
|
+
debug: false,
|
|
839
|
+
collectionName,
|
|
840
|
+
generatorName,
|
|
841
|
+
force: false,
|
|
842
|
+
defaults: false,
|
|
843
|
+
};
|
|
844
|
+
const workflow = createWorkflow(fsHost, host.root, options);
|
|
845
|
+
// used for testing
|
|
846
|
+
if (collectionResolutionOverrides) {
|
|
847
|
+
const r = workflow.engineHost.resolve;
|
|
848
|
+
workflow.engineHost.resolve = (collection, b, c) => {
|
|
849
|
+
if (collectionResolutionOverrides[collection]) {
|
|
850
|
+
return collectionResolutionOverrides[collection];
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
return r.apply(workflow.engineHost, [collection, b, c]);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
const collection = getCollection(workflow, collectionName);
|
|
858
|
+
const schematic = collection.createSchematic(generatorName, true);
|
|
859
|
+
const res = yield runSchematic(fsHost, host.root, workflow, emptyLogger, options, schematic, false, recorder);
|
|
860
|
+
if (res.status !== 0) {
|
|
861
|
+
throw new Error(res.loggingQueue.join('\n'));
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
exports.wrapAngularDevkitSchematic = wrapAngularDevkitSchematic;
|
|
866
|
+
function invokeNew(root, opts, verbose) {
|
|
867
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
868
|
+
const logger = (0, exports.getLogger)(verbose);
|
|
869
|
+
const fsHost = new NxScopedHost((0, core_1.normalize)(root));
|
|
870
|
+
const workflow = createWorkflow(fsHost, root, opts);
|
|
871
|
+
const collection = getCollection(workflow, opts.collectionName);
|
|
872
|
+
const schematic = collection.createSchematic('new', true);
|
|
873
|
+
return (yield runSchematic(fsHost, root, workflow, logger, Object.assign(Object.assign({}, opts), { generatorName: schematic.description.name }), schematic)).status;
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
exports.invokeNew = invokeNew;
|
|
877
|
+
let logger;
|
|
878
|
+
const loggerColors = {
|
|
879
|
+
warn: (s) => chalk.bold(chalk.yellow(s)),
|
|
880
|
+
error: (s) => {
|
|
881
|
+
if (s.startsWith('NX ')) {
|
|
882
|
+
return `\n${logger_1.NX_ERROR} ${chalk.bold(chalk.red(s.substr(3)))}\n`;
|
|
883
|
+
}
|
|
884
|
+
return chalk.bold(chalk.red(s));
|
|
885
|
+
},
|
|
886
|
+
info: (s) => {
|
|
887
|
+
if (s.startsWith('NX ')) {
|
|
888
|
+
return `\n${logger_1.NX_PREFIX} ${chalk.bold(s.substr(3))}\n`;
|
|
889
|
+
}
|
|
890
|
+
return chalk.white(s);
|
|
891
|
+
},
|
|
892
|
+
};
|
|
893
|
+
const getLogger = (isVerbose = false) => {
|
|
894
|
+
if (!logger) {
|
|
895
|
+
logger = (0, node_1.createConsoleLogger)(isVerbose, process.stdout, process.stderr, loggerColors);
|
|
896
|
+
}
|
|
897
|
+
return logger;
|
|
898
|
+
};
|
|
899
|
+
exports.getLogger = getLogger;
|
|
900
|
+
const getTargetLogger = (executor, isVerbose = false) => {
|
|
901
|
+
if (executor !== '@angular-devkit/build-angular:tslint') {
|
|
902
|
+
return (0, exports.getLogger)(isVerbose);
|
|
903
|
+
}
|
|
904
|
+
const tslintExecutorLogger = (0, node_1.createConsoleLogger)(isVerbose, process.stdout, process.stderr, Object.assign(Object.assign({}, loggerColors), { warn: (s) => {
|
|
905
|
+
if (s.startsWith(`TSLint's support is discontinued and we're deprecating its support in Angular CLI.`)) {
|
|
906
|
+
s =
|
|
907
|
+
`TSLint's support is discontinued and the @angular-devkit/build-angular:tslint executor is deprecated.\n` +
|
|
908
|
+
'To start using a modern linter tool, please consider replacing TSLint with ESLint. ' +
|
|
909
|
+
'You can use the "@nrwl/angular:convert-tslint-to-eslint" generator to automatically convert your projects.\n' +
|
|
910
|
+
'For more info, visit https://nx.dev/latest/angular/angular/convert-tslint-to-eslint.';
|
|
911
|
+
}
|
|
912
|
+
return chalk.bold(chalk.yellow(s));
|
|
913
|
+
} }));
|
|
914
|
+
return tslintExecutorLogger;
|
|
915
|
+
};
|
|
916
|
+
function saveWorkspaceConfigurationInWrappedSchematic(host, r) {
|
|
917
|
+
const workspaceJsonExists = host.exists(r.eventPath);
|
|
918
|
+
const workspace = (0, json_1.parseJson)(r.content.toString());
|
|
919
|
+
for (const [project, config] of Object.entries(workspace.projects)) {
|
|
920
|
+
if (typeof config === 'object' &&
|
|
921
|
+
(!workspaceJsonExists || config.configFilePath)) {
|
|
922
|
+
const path = config.configFilePath || (0, path_1.join)(config.root, 'project.json');
|
|
923
|
+
workspace.projects[project] = (0, core_1.normalize)((0, path_1.dirname)(path));
|
|
924
|
+
delete config.configFilePath;
|
|
925
|
+
host.write(path, (0, json_1.serializeJson)(config));
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
const nxJson = (0, json_1.parseJson)(host.read('nx.json').toString());
|
|
929
|
+
nxJson.generators = workspace.generators || workspace.schematics;
|
|
930
|
+
nxJson.cli = workspace.cli || nxJson.cli;
|
|
931
|
+
nxJson.defaultProject = workspace.defaultProject;
|
|
932
|
+
delete workspace.cli;
|
|
933
|
+
delete workspace.generators;
|
|
934
|
+
delete workspace.schematics;
|
|
935
|
+
if (workspaceJsonExists) {
|
|
936
|
+
r.content = Buffer.from((0, json_1.serializeJson)(workspace));
|
|
937
|
+
host.write(r.eventPath, r.content);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
//# sourceMappingURL=ngcli-adapter.js.map
|