@nrwl/workspace 15.8.6 → 15.9.0-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/index.d.ts +3 -8
- package/index.js +2 -36
- package/index.js.map +1 -1
- package/package.json +30 -39
- package/src/generators/library/library.js +1 -2
- package/src/generators/library/library.js.map +1 -1
- package/src/generators/move/lib/update-cypress-config.js +8 -2
- package/src/generators/move/lib/update-cypress-config.js.map +1 -1
- package/src/generators/new/files-integrated-repo/package.json__tmpl__ +1 -2
- package/src/generators/new/files-package-based-repo/__dot__vscode/extensions.json__tmpl__ +1 -2
- package/src/generators/new/files-package-based-repo/package.json__tmpl__ +1 -2
- package/src/generators/new/files-root-app/__dot__vscode/extensions.json__tmpl__ +1 -2
- package/src/generators/new/files-root-app/package.json__tmpl__ +1 -2
- package/src/generators/new/generate-preset.js +32 -8
- package/src/generators/new/generate-preset.js.map +1 -1
- package/src/generators/new/generate-workspace-files.d.ts +0 -3
- package/src/generators/new/generate-workspace-files.js +4 -10
- package/src/generators/new/generate-workspace-files.js.map +1 -1
- package/src/generators/new/new.d.ts +2 -1
- package/src/generators/new/new.js +10 -10
- package/src/generators/new/new.js.map +1 -1
- package/src/generators/new/schema.json +1 -1
- package/src/generators/preset/preset.d.ts +1 -1
- package/src/generators/preset/preset.js +18 -15
- package/src/generators/preset/preset.js.map +1 -1
- package/src/generators/preset/schema.json +1 -1
- package/src/generators/remove/lib/check-project-is-safe-to-remove.js +1 -1
- package/src/generators/remove/lib/check-project-is-safe-to-remove.js.map +1 -1
- package/src/migrations/update-14-0-0/change-npm-script-executor.js +1 -1
- package/src/migrations/update-14-0-0/change-npm-script-executor.js.map +1 -1
- package/src/migrations/update-14-8-0/change-run-commands-executor.js +1 -1
- package/src/migrations/update-14-8-0/change-run-commands-executor.js.map +1 -1
- package/src/utilities/buildable-libs-utils.d.ts +17 -6
- package/src/utilities/buildable-libs-utils.js +17 -8
- package/src/utilities/buildable-libs-utils.js.map +1 -1
- package/src/utilities/run-tasks-in-serial.d.ts +6 -0
- package/src/utilities/run-tasks-in-serial.js +6 -0
- package/src/utilities/run-tasks-in-serial.js.map +1 -1
- package/src/utilities/typescript/get-source-nodes.d.ts +3 -0
- package/src/utilities/typescript/get-source-nodes.js +3 -0
- package/src/utilities/typescript/get-source-nodes.js.map +1 -1
- package/src/utilities/version-utils.d.ts +3 -0
- package/src/utilities/version-utils.js +7 -12
- package/src/utilities/version-utils.js.map +1 -1
- package/src/utils/ast-utils.d.ts +0 -118
- package/src/utils/ast-utils.js +3 -543
- package/src/utils/ast-utils.js.map +1 -1
- package/src/utils/cli-config-utils.d.ts +0 -2
- package/src/utils/cli-config-utils.js +1 -47
- package/src/utils/cli-config-utils.js.map +1 -1
- package/src/utils/lint.d.ts +0 -22
- package/src/utils/lint.js +0 -164
- package/src/utils/lint.js.map +1 -1
- package/src/utils/project-type.d.ts +1 -3
- package/src/utils/project-type.js +1 -8
- package/src/utils/project-type.js.map +1 -1
- package/src/utils/strings.d.ts +12 -0
- package/src/utils/strings.js +12 -0
- package/src/utils/strings.js.map +1 -1
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +5 -3
- package/src/utils/versions.js.map +1 -1
- package/src/generators/new/files-integrated-repo/__dot__prettierignore +0 -4
- package/src/generators/new/files-package-based-repo/__dot__prettierignore +0 -4
- package/src/generators/new/files-root-app/__dot__prettierignore +0 -4
- package/src/utilities/ast-utils.d.ts +0 -22
- package/src/utilities/ast-utils.js +0 -197
- package/src/utilities/ast-utils.js.map +0 -1
- package/src/utilities/executor-options-utils.d.ts +0 -20
- package/src/utilities/executor-options-utils.js +0 -49
- package/src/utilities/executor-options-utils.js.map +0 -1
- package/src/utilities/generate-globs.d.ts +0 -6
- package/src/utilities/generate-globs.js +0 -81
- package/src/utilities/generate-globs.js.map +0 -1
- package/src/utilities/prettier.d.ts +0 -6
- package/src/utilities/prettier.js +0 -38
- package/src/utilities/prettier.js.map +0 -1
- package/src/utils/rules/move-npm-packages.d.ts +0 -11
- package/src/utils/rules/move-npm-packages.js +0 -76
- package/src/utils/rules/move-npm-packages.js.map +0 -1
- package/src/utils/rules/to-js.d.ts +0 -8
- package/src/utils/rules/to-js.js +0 -82
- package/src/utils/rules/to-js.js.map +0 -1
- package/src/utils/rules/update-karma-conf.d.ts +0 -8
- package/src/utils/rules/update-karma-conf.js +0 -36
- package/src/utils/rules/update-karma-conf.js.map +0 -1
- package/src/utils/update-packages-in-package-json.d.ts +0 -3
- package/src/utils/update-packages-in-package-json.js +0 -56
- package/src/utils/update-packages-in-package-json.js.map +0 -1
- package/src/utils/update-task.d.ts +0 -2
- package/src/utils/update-task.js +0 -83
- package/src/utils/update-task.js.map +0 -1
package/src/utils/ast-utils.d.ts
CHANGED
@@ -1,120 +1,2 @@
|
|
1
|
-
/**
|
2
|
-
* @license
|
3
|
-
* Copyright Google Inc. All Rights Reserved.
|
4
|
-
*
|
5
|
-
* Use of this source code is governed by an MIT- style license that can be
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
7
|
-
*/
|
8
|
-
import type { Rule, SchematicContext, Source, Tree } from '@angular-devkit/schematics';
|
9
|
-
import type * as ts from 'typescript';
|
10
|
-
import type { Path } from '@angular-devkit/core';
|
11
|
-
import type { NxJsonConfiguration } from '@nrwl/devkit';
|
12
|
-
export declare function sortObjectByKeys(obj: unknown): {};
|
13
1
|
export { findNodes } from '../utilities/typescript/find-nodes';
|
14
2
|
export { getSourceNodes } from '../utilities/typescript/get-source-nodes';
|
15
|
-
export interface Change {
|
16
|
-
apply(host: any): Promise<void>;
|
17
|
-
readonly type: string;
|
18
|
-
readonly path: string | null;
|
19
|
-
readonly order: number;
|
20
|
-
readonly description: string;
|
21
|
-
}
|
22
|
-
export declare class NoopChange implements Change {
|
23
|
-
type: string;
|
24
|
-
description: string;
|
25
|
-
order: number;
|
26
|
-
path: any;
|
27
|
-
apply(): Promise<void>;
|
28
|
-
}
|
29
|
-
export declare class InsertChange implements Change {
|
30
|
-
path: string;
|
31
|
-
pos: number;
|
32
|
-
toAdd: string;
|
33
|
-
type: string;
|
34
|
-
order: number;
|
35
|
-
description: string;
|
36
|
-
constructor(path: string, pos: number, toAdd: string);
|
37
|
-
apply(host: any): any;
|
38
|
-
}
|
39
|
-
export declare class RemoveChange implements Change {
|
40
|
-
path: string;
|
41
|
-
pos: number;
|
42
|
-
toRemove: string;
|
43
|
-
type: string;
|
44
|
-
order: number;
|
45
|
-
description: string;
|
46
|
-
constructor(path: string, pos: number, toRemove: string);
|
47
|
-
apply(host: any): Promise<void>;
|
48
|
-
}
|
49
|
-
export declare class ReplaceChange implements Change {
|
50
|
-
path: string;
|
51
|
-
pos: number;
|
52
|
-
oldText: string;
|
53
|
-
newText: string;
|
54
|
-
type: string;
|
55
|
-
order: number;
|
56
|
-
description: string;
|
57
|
-
constructor(path: string, pos: number, oldText: string, newText: string);
|
58
|
-
apply(host: any): Promise<void>;
|
59
|
-
}
|
60
|
-
export declare function addParameterToConstructor(source: ts.SourceFile, modulePath: string, opts: {
|
61
|
-
className: string;
|
62
|
-
param: string;
|
63
|
-
}): Change[];
|
64
|
-
export declare function addMethod(source: ts.SourceFile, modulePath: string, opts: {
|
65
|
-
className: string;
|
66
|
-
methodHeader: string;
|
67
|
-
body: string;
|
68
|
-
}): Change[];
|
69
|
-
export declare function findClass(source: ts.SourceFile, className: string, silent?: boolean): ts.ClassDeclaration;
|
70
|
-
export declare function offset(text: string, numberOfTabs: number, wrap: boolean): string;
|
71
|
-
export declare function addIncludeToTsConfig(tsConfigPath: string, source: ts.SourceFile, include: string): Change[];
|
72
|
-
export declare function getImport(source: ts.SourceFile, predicate: (a: any) => boolean): {
|
73
|
-
moduleSpec: string;
|
74
|
-
bindings: string[];
|
75
|
-
}[];
|
76
|
-
export declare function addGlobal(source: ts.SourceFile, modulePath: string, statement: string): Change[];
|
77
|
-
export declare function insert(host: Tree, modulePath: string, changes: Change[]): void;
|
78
|
-
/**
|
79
|
-
* This method is specifically for reading JSON files in a Tree
|
80
|
-
* @param host The host tree
|
81
|
-
* @param path The path to the JSON file
|
82
|
-
* @returns The JSON data in the file.
|
83
|
-
*/
|
84
|
-
export declare function readJsonInTree<T extends object = any>(host: Tree, path: string): T;
|
85
|
-
export declare function allFilesInDirInHost(host: Tree, path: Path, options?: {
|
86
|
-
recursive: boolean;
|
87
|
-
}): Path[];
|
88
|
-
/**
|
89
|
-
* This method is specifically for updating JSON in a Tree
|
90
|
-
* @param path Path of JSON file in the Tree
|
91
|
-
* @param callback Manipulation of the JSON data
|
92
|
-
* @returns A rule which updates a JSON file file in a Tree
|
93
|
-
*/
|
94
|
-
export declare function updateJsonInTree<T extends object = any, O extends object = T>(path: string, callback: (json: T, context: SchematicContext) => O): Rule;
|
95
|
-
export declare function updateWorkspaceInTree<T extends object = any, O extends object = T>(callback: (json: T, context: SchematicContext, host: Tree) => O): Rule;
|
96
|
-
export declare function readNxJsonInTree(host: Tree): NxJsonConfiguration<string[] | "*">;
|
97
|
-
export declare function libsDir(host: Tree): string;
|
98
|
-
export declare function appsDir(host: Tree): string;
|
99
|
-
export declare function updateNxJsonInTree(callback: (json: NxJsonConfiguration, context: SchematicContext) => NxJsonConfiguration): Rule;
|
100
|
-
export declare function readWorkspace(host: Tree): any;
|
101
|
-
/**
|
102
|
-
* Updates the package.json given the passed deps and/or devDeps. Only updates
|
103
|
-
* if the packages are not yet present
|
104
|
-
*
|
105
|
-
* @param deps the package.json dependencies to add
|
106
|
-
* @param devDeps the package.json devDependencies to add
|
107
|
-
* @param addInstall default `true`; set to false to avoid installs
|
108
|
-
*/
|
109
|
-
export declare function addDepsToPackageJson(deps: any, devDeps: any, addInstall?: boolean): Rule;
|
110
|
-
export declare function updatePackageJsonDependencies(deps: any, devDeps: any, addInstall?: boolean): Rule;
|
111
|
-
export declare function getProjectConfig(host: Tree, name: string): any;
|
112
|
-
export declare function createOrUpdate(host: Tree, path: string, content: string): void;
|
113
|
-
export declare function insertImport(source: ts.SourceFile, fileToEdit: string, symbolName: string, fileName: string, isDefault?: boolean): Change;
|
114
|
-
export declare function replaceNodeValue(host: Tree, modulePath: string, node: ts.Node, content: string): void;
|
115
|
-
export declare function renameSyncInTree(tree: Tree, from: string, to: string, cb: (err: string) => void): void;
|
116
|
-
export declare function renameDirSyncInTree(tree: Tree, from: string, to: string, cb: (err: string) => void): void;
|
117
|
-
/**
|
118
|
-
* Applies a template merge but skips for already existing entries
|
119
|
-
*/
|
120
|
-
export declare function applyWithSkipExisting(source: Source, rules: Rule[]): Rule;
|
package/src/utils/ast-utils.js
CHANGED
@@ -1,548 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
const devkit_1 = require("@nrwl/devkit");
|
5
|
-
const cli_config_utils_1 = require("./cli-config-utils");
|
6
|
-
const add_install_task_1 = require("./rules/add-install-task");
|
7
|
-
const typescript_1 = require("nx/src/utils/typescript");
|
8
|
-
const get_source_nodes_1 = require("../utilities/typescript/get-source-nodes");
|
9
|
-
const typescript_2 = require("../utilities/typescript");
|
10
|
-
let tsModule;
|
11
|
-
function nodesByPosition(first, second) {
|
12
|
-
return first.getStart() - second.getStart();
|
13
|
-
}
|
14
|
-
function insertAfterLastOccurrence(nodes, toInsert, file, fallbackPos, syntaxKind) {
|
15
|
-
// sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
|
16
|
-
let lastItem = [...nodes].sort(nodesByPosition).pop();
|
17
|
-
if (!lastItem) {
|
18
|
-
throw new Error();
|
19
|
-
}
|
20
|
-
if (syntaxKind) {
|
21
|
-
lastItem = (0, typescript_1.findNodes)(lastItem, syntaxKind).sort(nodesByPosition).pop();
|
22
|
-
}
|
23
|
-
if (!lastItem && fallbackPos == undefined) {
|
24
|
-
throw new Error(`tried to insert ${toInsert} as first occurrence with no fallback position`);
|
25
|
-
}
|
26
|
-
const lastItemPosition = lastItem ? lastItem.getEnd() : fallbackPos;
|
27
|
-
return new InsertChange(file, lastItemPosition, toInsert);
|
28
|
-
}
|
29
|
-
function sortObjectByKeys(obj) {
|
30
|
-
return Object.keys(obj)
|
31
|
-
.sort()
|
32
|
-
.reduce((result, key) => {
|
33
|
-
return Object.assign(Object.assign({}, result), { [key]: obj[key] });
|
34
|
-
}, {});
|
35
|
-
}
|
36
|
-
exports.sortObjectByKeys = sortObjectByKeys;
|
3
|
+
exports.getSourceNodes = exports.findNodes = void 0;
|
37
4
|
var find_nodes_1 = require("../utilities/typescript/find-nodes"); // TODO(v16): Remove this
|
38
5
|
Object.defineProperty(exports, "findNodes", { enumerable: true, get: function () { return find_nodes_1.findNodes; } });
|
39
|
-
var
|
40
|
-
Object.defineProperty(exports, "getSourceNodes", { enumerable: true, get: function () { return
|
41
|
-
class NoopChange {
|
42
|
-
constructor() {
|
43
|
-
this.type = 'noop';
|
44
|
-
this.description = 'No operation.';
|
45
|
-
this.order = Infinity;
|
46
|
-
this.path = null;
|
47
|
-
}
|
48
|
-
apply() {
|
49
|
-
return Promise.resolve();
|
50
|
-
}
|
51
|
-
}
|
52
|
-
exports.NoopChange = NoopChange;
|
53
|
-
class InsertChange {
|
54
|
-
constructor(path, pos, toAdd) {
|
55
|
-
this.path = path;
|
56
|
-
this.pos = pos;
|
57
|
-
this.toAdd = toAdd;
|
58
|
-
this.type = 'insert';
|
59
|
-
if (pos < 0) {
|
60
|
-
throw new Error('Negative positions are invalid');
|
61
|
-
}
|
62
|
-
this.description = `Inserted ${toAdd} into position ${pos} of ${path}`;
|
63
|
-
this.order = pos;
|
64
|
-
}
|
65
|
-
apply(host) {
|
66
|
-
return host.read(this.path).then((content) => {
|
67
|
-
const prefix = content.substring(0, this.pos);
|
68
|
-
const suffix = content.substring(this.pos);
|
69
|
-
return host.write(this.path, `${prefix}${this.toAdd}${suffix}`);
|
70
|
-
});
|
71
|
-
}
|
72
|
-
}
|
73
|
-
exports.InsertChange = InsertChange;
|
74
|
-
class RemoveChange {
|
75
|
-
constructor(path, pos, toRemove) {
|
76
|
-
this.path = path;
|
77
|
-
this.pos = pos;
|
78
|
-
this.toRemove = toRemove;
|
79
|
-
this.type = 'remove';
|
80
|
-
if (pos < 0) {
|
81
|
-
throw new Error('Negative positions are invalid');
|
82
|
-
}
|
83
|
-
this.description = `Removed ${toRemove} into position ${pos} of ${path}`;
|
84
|
-
this.order = pos;
|
85
|
-
}
|
86
|
-
apply(host) {
|
87
|
-
return host.read(this.path).then((content) => {
|
88
|
-
const prefix = content.substring(0, this.pos);
|
89
|
-
const suffix = content.substring(this.pos + this.toRemove.length);
|
90
|
-
return host.write(this.path, `${prefix}${suffix}`);
|
91
|
-
});
|
92
|
-
}
|
93
|
-
}
|
94
|
-
exports.RemoveChange = RemoveChange;
|
95
|
-
class ReplaceChange {
|
96
|
-
constructor(path, pos, oldText, newText) {
|
97
|
-
this.path = path;
|
98
|
-
this.pos = pos;
|
99
|
-
this.oldText = oldText;
|
100
|
-
this.newText = newText;
|
101
|
-
this.type = 'replace';
|
102
|
-
if (pos < 0) {
|
103
|
-
throw new Error('Negative positions are invalid');
|
104
|
-
}
|
105
|
-
this.description = `Replaced ${oldText} into position ${pos} of ${path} with ${newText}`;
|
106
|
-
this.order = pos;
|
107
|
-
}
|
108
|
-
apply(host) {
|
109
|
-
return host.read(this.path).then((content) => {
|
110
|
-
const prefix = content.substring(0, this.pos);
|
111
|
-
const suffix = content.substring(this.pos + this.oldText.length);
|
112
|
-
const text = content.substring(this.pos, this.pos + this.oldText.length);
|
113
|
-
if (text !== this.oldText) {
|
114
|
-
return Promise.reject(new Error(`Invalid replace: "${text}" != "${this.oldText}".`));
|
115
|
-
}
|
116
|
-
return host.write(this.path, `${prefix}${this.newText}${suffix}`);
|
117
|
-
});
|
118
|
-
}
|
119
|
-
}
|
120
|
-
exports.ReplaceChange = ReplaceChange;
|
121
|
-
function addParameterToConstructor(source, modulePath, opts) {
|
122
|
-
if (!tsModule) {
|
123
|
-
tsModule = (0, typescript_2.ensureTypescript)();
|
124
|
-
}
|
125
|
-
const clazz = findClass(source, opts.className);
|
126
|
-
const constructor = clazz.members.filter((m) => m.kind === tsModule.SyntaxKind.Constructor)[0];
|
127
|
-
if (constructor) {
|
128
|
-
throw new Error('Should be tested');
|
129
|
-
}
|
130
|
-
else {
|
131
|
-
const methodHeader = `constructor(${opts.param})`;
|
132
|
-
return addMethod(source, modulePath, {
|
133
|
-
className: opts.className,
|
134
|
-
methodHeader,
|
135
|
-
body: null,
|
136
|
-
});
|
137
|
-
}
|
138
|
-
}
|
139
|
-
exports.addParameterToConstructor = addParameterToConstructor;
|
140
|
-
function addMethod(source, modulePath, opts) {
|
141
|
-
const clazz = findClass(source, opts.className);
|
142
|
-
const body = opts.body
|
143
|
-
? `
|
144
|
-
${opts.methodHeader} {
|
145
|
-
${offset(opts.body, 1, false)}
|
146
|
-
}
|
147
|
-
`
|
148
|
-
: `
|
149
|
-
${opts.methodHeader} {}
|
150
|
-
`;
|
151
|
-
return [new InsertChange(modulePath, clazz.end - 1, offset(body, 1, true))];
|
152
|
-
}
|
153
|
-
exports.addMethod = addMethod;
|
154
|
-
function findClass(source, className, silent = false) {
|
155
|
-
if (!tsModule) {
|
156
|
-
tsModule = (0, typescript_2.ensureTypescript)();
|
157
|
-
}
|
158
|
-
const nodes = (0, get_source_nodes_1.getSourceNodes)(source);
|
159
|
-
const clazz = (nodes.filter((n) => n.kind === tsModule.SyntaxKind.ClassDeclaration &&
|
160
|
-
n.name.text === className)[0]);
|
161
|
-
if (!clazz && !silent) {
|
162
|
-
throw new Error(`Cannot find class '${className}'`);
|
163
|
-
}
|
164
|
-
return clazz;
|
165
|
-
}
|
166
|
-
exports.findClass = findClass;
|
167
|
-
function offset(text, numberOfTabs, wrap) {
|
168
|
-
const lines = text
|
169
|
-
.trim()
|
170
|
-
.split('\n')
|
171
|
-
.map((line) => {
|
172
|
-
let tabs = '';
|
173
|
-
for (let c = 0; c < numberOfTabs; ++c) {
|
174
|
-
tabs += ' ';
|
175
|
-
}
|
176
|
-
return `${tabs}${line}`;
|
177
|
-
})
|
178
|
-
.join('\n');
|
179
|
-
return wrap ? `\n${lines}\n` : lines;
|
180
|
-
}
|
181
|
-
exports.offset = offset;
|
182
|
-
function addIncludeToTsConfig(tsConfigPath, source, include) {
|
183
|
-
const includeKeywordPos = source.text.indexOf('"include":');
|
184
|
-
if (includeKeywordPos > -1) {
|
185
|
-
const includeArrayEndPos = source.text.indexOf(']', includeKeywordPos);
|
186
|
-
return [new InsertChange(tsConfigPath, includeArrayEndPos, include)];
|
187
|
-
}
|
188
|
-
else {
|
189
|
-
return [];
|
190
|
-
}
|
191
|
-
}
|
192
|
-
exports.addIncludeToTsConfig = addIncludeToTsConfig;
|
193
|
-
function getImport(source, predicate) {
|
194
|
-
if (!tsModule) {
|
195
|
-
tsModule = (0, typescript_2.ensureTypescript)();
|
196
|
-
}
|
197
|
-
const allImports = (0, typescript_1.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration);
|
198
|
-
const matching = allImports.filter((i) => predicate(i.moduleSpecifier.getText()));
|
199
|
-
return matching.map((i) => {
|
200
|
-
const moduleSpec = i.moduleSpecifier
|
201
|
-
.getText()
|
202
|
-
.substring(1, i.moduleSpecifier.getText().length - 1);
|
203
|
-
const t = i.importClause.namedBindings.getText();
|
204
|
-
const bindings = t
|
205
|
-
.replace('{', '')
|
206
|
-
.replace('}', '')
|
207
|
-
.split(',')
|
208
|
-
.map((q) => q.trim());
|
209
|
-
return { moduleSpec, bindings };
|
210
|
-
});
|
211
|
-
}
|
212
|
-
exports.getImport = getImport;
|
213
|
-
function addGlobal(source, modulePath, statement) {
|
214
|
-
if (!tsModule) {
|
215
|
-
tsModule = (0, typescript_2.ensureTypescript)();
|
216
|
-
}
|
217
|
-
const allImports = (0, typescript_1.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration);
|
218
|
-
if (allImports.length > 0) {
|
219
|
-
const lastImport = allImports[allImports.length - 1];
|
220
|
-
return [
|
221
|
-
new InsertChange(modulePath, lastImport.end + 1, `\n${statement}\n`),
|
222
|
-
];
|
223
|
-
}
|
224
|
-
else {
|
225
|
-
return [new InsertChange(modulePath, 0, `${statement}\n`)];
|
226
|
-
}
|
227
|
-
}
|
228
|
-
exports.addGlobal = addGlobal;
|
229
|
-
function insert(host, modulePath, changes) {
|
230
|
-
if (changes.length < 1) {
|
231
|
-
return;
|
232
|
-
}
|
233
|
-
// sort changes so that the highest pos goes first
|
234
|
-
const orderedChanges = changes.sort((a, b) => b.order - a.order);
|
235
|
-
const recorder = host.beginUpdate(modulePath);
|
236
|
-
for (const change of orderedChanges) {
|
237
|
-
if (change.type == 'insert') {
|
238
|
-
recorder.insertLeft(change.pos, change.toAdd);
|
239
|
-
}
|
240
|
-
else if (change.type == 'remove') {
|
241
|
-
recorder.remove(change.pos - 1, change.toRemove.length + 1);
|
242
|
-
}
|
243
|
-
else if (change.type == 'replace') {
|
244
|
-
recorder.remove(change.pos, change.oldText.length);
|
245
|
-
recorder.insertLeft(change.pos, change.newText);
|
246
|
-
}
|
247
|
-
else if (change.type === 'noop') {
|
248
|
-
// do nothing
|
249
|
-
}
|
250
|
-
else {
|
251
|
-
throw new Error(`Unexpected Change '${change.constructor.name}'`);
|
252
|
-
}
|
253
|
-
}
|
254
|
-
host.commitUpdate(recorder);
|
255
|
-
}
|
256
|
-
exports.insert = insert;
|
257
|
-
/**
|
258
|
-
* This method is specifically for reading JSON files in a Tree
|
259
|
-
* @param host The host tree
|
260
|
-
* @param path The path to the JSON file
|
261
|
-
* @returns The JSON data in the file.
|
262
|
-
*/
|
263
|
-
function readJsonInTree(host, path) {
|
264
|
-
if (!host.exists(path)) {
|
265
|
-
throw new Error(`Cannot find ${path}`);
|
266
|
-
}
|
267
|
-
try {
|
268
|
-
return (0, devkit_1.parseJson)(host.read(path).toString('utf-8'));
|
269
|
-
}
|
270
|
-
catch (e) {
|
271
|
-
throw new Error(`Cannot parse ${path}: ${e.message}`);
|
272
|
-
}
|
273
|
-
}
|
274
|
-
exports.readJsonInTree = readJsonInTree;
|
275
|
-
function allFilesInDirInHost(host, path, options = { recursive: true }) {
|
276
|
-
const { join } = require('@angular-devkit/core');
|
277
|
-
const dir = host.getDir(path);
|
278
|
-
const res = [];
|
279
|
-
dir.subfiles.forEach((p) => {
|
280
|
-
res.push(join(path, p));
|
281
|
-
});
|
282
|
-
if (!options.recursive) {
|
283
|
-
return res;
|
284
|
-
}
|
285
|
-
dir.subdirs.forEach((p) => {
|
286
|
-
res.push(...allFilesInDirInHost(host, join(path, p)));
|
287
|
-
});
|
288
|
-
return res;
|
289
|
-
}
|
290
|
-
exports.allFilesInDirInHost = allFilesInDirInHost;
|
291
|
-
/**
|
292
|
-
* This method is specifically for updating JSON in a Tree
|
293
|
-
* @param path Path of JSON file in the Tree
|
294
|
-
* @param callback Manipulation of the JSON data
|
295
|
-
* @returns A rule which updates a JSON file file in a Tree
|
296
|
-
*/
|
297
|
-
function updateJsonInTree(path, callback) {
|
298
|
-
return (host, context) => {
|
299
|
-
if (!host.exists(path)) {
|
300
|
-
host.create(path, (0, devkit_1.serializeJson)(callback({}, context)));
|
301
|
-
return host;
|
302
|
-
}
|
303
|
-
host.overwrite(path, (0, devkit_1.serializeJson)(callback(readJsonInTree(host, path), context)));
|
304
|
-
return host;
|
305
|
-
};
|
306
|
-
}
|
307
|
-
exports.updateJsonInTree = updateJsonInTree;
|
308
|
-
function updateWorkspaceInTree(callback) {
|
309
|
-
return (host, context = undefined) => {
|
310
|
-
const path = (0, cli_config_utils_1.getWorkspacePath)(host);
|
311
|
-
host.overwrite(path, (0, devkit_1.serializeJson)(callback(readJsonInTree(host, path), context, host)));
|
312
|
-
return host;
|
313
|
-
};
|
314
|
-
}
|
315
|
-
exports.updateWorkspaceInTree = updateWorkspaceInTree;
|
316
|
-
function readNxJsonInTree(host) {
|
317
|
-
return readJsonInTree(host, 'nx.json');
|
318
|
-
}
|
319
|
-
exports.readNxJsonInTree = readNxJsonInTree;
|
320
|
-
function libsDir(host) {
|
321
|
-
var _a, _b;
|
322
|
-
const json = readJsonInTree(host, 'nx.json');
|
323
|
-
return (_b = (_a = json === null || json === void 0 ? void 0 : json.workspaceLayout) === null || _a === void 0 ? void 0 : _a.libsDir) !== null && _b !== void 0 ? _b : 'libs';
|
324
|
-
}
|
325
|
-
exports.libsDir = libsDir;
|
326
|
-
function appsDir(host) {
|
327
|
-
var _a, _b;
|
328
|
-
const json = readJsonInTree(host, 'nx.json');
|
329
|
-
return (_b = (_a = json === null || json === void 0 ? void 0 : json.workspaceLayout) === null || _a === void 0 ? void 0 : _a.appsDir) !== null && _b !== void 0 ? _b : 'apps';
|
330
|
-
}
|
331
|
-
exports.appsDir = appsDir;
|
332
|
-
function updateNxJsonInTree(callback) {
|
333
|
-
return (host, context) => {
|
334
|
-
host.overwrite('nx.json', (0, devkit_1.serializeJson)(callback(readJsonInTree(host, 'nx.json'), context)));
|
335
|
-
return host;
|
336
|
-
};
|
337
|
-
}
|
338
|
-
exports.updateNxJsonInTree = updateNxJsonInTree;
|
339
|
-
function readWorkspace(host) {
|
340
|
-
const path = (0, cli_config_utils_1.getWorkspacePath)(host);
|
341
|
-
return readJsonInTree(host, path);
|
342
|
-
}
|
343
|
-
exports.readWorkspace = readWorkspace;
|
344
|
-
/**
|
345
|
-
* verifies whether the given packageJson dependencies require an update
|
346
|
-
* given the deps & devDeps passed in
|
347
|
-
*/
|
348
|
-
function requiresAddingOfPackages(packageJsonFile, deps, devDeps) {
|
349
|
-
let needsDepsUpdate = false;
|
350
|
-
let needsDevDepsUpdate = false;
|
351
|
-
packageJsonFile.dependencies = packageJsonFile.dependencies || {};
|
352
|
-
packageJsonFile.devDependencies = packageJsonFile.devDependencies || {};
|
353
|
-
if (Object.keys(deps).length > 0) {
|
354
|
-
needsDepsUpdate = Object.keys(deps).some((entry) => !packageJsonFile.dependencies[entry]);
|
355
|
-
}
|
356
|
-
if (Object.keys(devDeps).length > 0) {
|
357
|
-
needsDevDepsUpdate = Object.keys(devDeps).some((entry) => !packageJsonFile.devDependencies[entry]);
|
358
|
-
}
|
359
|
-
return needsDepsUpdate || needsDevDepsUpdate;
|
360
|
-
}
|
361
|
-
/**
|
362
|
-
* Updates the package.json given the passed deps and/or devDeps. Only updates
|
363
|
-
* if the packages are not yet present
|
364
|
-
*
|
365
|
-
* @param deps the package.json dependencies to add
|
366
|
-
* @param devDeps the package.json devDependencies to add
|
367
|
-
* @param addInstall default `true`; set to false to avoid installs
|
368
|
-
*/
|
369
|
-
function addDepsToPackageJson(deps, devDeps, addInstall = true) {
|
370
|
-
const { chain, noop } = require('@angular-devkit/schematics');
|
371
|
-
return (host, context) => {
|
372
|
-
const currentPackageJson = readJsonInTree(host, 'package.json');
|
373
|
-
if (requiresAddingOfPackages(currentPackageJson, deps, devDeps)) {
|
374
|
-
return chain([
|
375
|
-
updateJsonInTree('package.json', (json, context) => {
|
376
|
-
json.dependencies = Object.assign(Object.assign(Object.assign({}, (json.dependencies || {})), deps), (json.dependencies || {}));
|
377
|
-
json.devDependencies = Object.assign(Object.assign(Object.assign({}, (json.devDependencies || {})), devDeps), (json.devDependencies || {}));
|
378
|
-
json.dependencies = sortObjectByKeys(json.dependencies);
|
379
|
-
json.devDependencies = sortObjectByKeys(json.devDependencies);
|
380
|
-
return json;
|
381
|
-
}),
|
382
|
-
(0, add_install_task_1.addInstallTask)({
|
383
|
-
skipInstall: !addInstall,
|
384
|
-
}),
|
385
|
-
]);
|
386
|
-
}
|
387
|
-
else {
|
388
|
-
return noop();
|
389
|
-
}
|
390
|
-
};
|
391
|
-
}
|
392
|
-
exports.addDepsToPackageJson = addDepsToPackageJson;
|
393
|
-
function updatePackageJsonDependencies(deps, devDeps, addInstall = true) {
|
394
|
-
const { chain } = require('@angular-devkit/schematics');
|
395
|
-
return chain([
|
396
|
-
updateJsonInTree('package.json', (json, context) => {
|
397
|
-
json.dependencies = Object.assign(Object.assign({}, (json.dependencies || {})), deps);
|
398
|
-
json.devDependencies = Object.assign(Object.assign({}, (json.devDependencies || {})), devDeps);
|
399
|
-
json.dependencies = sortObjectByKeys(json.dependencies);
|
400
|
-
json.devDependencies = sortObjectByKeys(json.devDependencies);
|
401
|
-
return json;
|
402
|
-
}),
|
403
|
-
(0, add_install_task_1.addInstallTask)({
|
404
|
-
skipInstall: !addInstall,
|
405
|
-
}),
|
406
|
-
]);
|
407
|
-
}
|
408
|
-
exports.updatePackageJsonDependencies = updatePackageJsonDependencies;
|
409
|
-
function getProjectConfig(host, name) {
|
410
|
-
const workspaceJson = readJsonInTree(host, (0, cli_config_utils_1.getWorkspacePath)(host));
|
411
|
-
const projectConfig = workspaceJson.projects[name];
|
412
|
-
if (!projectConfig) {
|
413
|
-
throw new Error(`Cannot find project '${name}'`);
|
414
|
-
}
|
415
|
-
else if (typeof projectConfig === 'string') {
|
416
|
-
return readJsonInTree(host, projectConfig);
|
417
|
-
}
|
418
|
-
else {
|
419
|
-
return projectConfig;
|
420
|
-
}
|
421
|
-
}
|
422
|
-
exports.getProjectConfig = getProjectConfig;
|
423
|
-
function createOrUpdate(host, path, content) {
|
424
|
-
if (host.exists(path)) {
|
425
|
-
host.overwrite(path, content);
|
426
|
-
}
|
427
|
-
else {
|
428
|
-
host.create(path, content);
|
429
|
-
}
|
430
|
-
}
|
431
|
-
exports.createOrUpdate = createOrUpdate;
|
432
|
-
function insertImport(source, fileToEdit, symbolName, fileName, isDefault = false) {
|
433
|
-
if (!tsModule) {
|
434
|
-
tsModule = (0, typescript_2.ensureTypescript)();
|
435
|
-
}
|
436
|
-
const rootNode = source;
|
437
|
-
const allImports = (0, typescript_1.findNodes)(rootNode, tsModule.SyntaxKind.ImportDeclaration);
|
438
|
-
// get nodes that map to import statements from the file fileName
|
439
|
-
const relevantImports = allImports.filter((node) => {
|
440
|
-
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
441
|
-
const importFiles = node
|
442
|
-
.getChildren()
|
443
|
-
.filter((child) => child.kind === tsModule.SyntaxKind.StringLiteral)
|
444
|
-
.map((n) => n.text);
|
445
|
-
return importFiles.filter((file) => file === fileName).length === 1;
|
446
|
-
});
|
447
|
-
if (relevantImports.length > 0) {
|
448
|
-
let importsAsterisk = false;
|
449
|
-
// imports from import file
|
450
|
-
const imports = [];
|
451
|
-
relevantImports.forEach((n) => {
|
452
|
-
Array.prototype.push.apply(imports, (0, typescript_1.findNodes)(n, tsModule.SyntaxKind.Identifier));
|
453
|
-
if ((0, typescript_1.findNodes)(n, tsModule.SyntaxKind.AsteriskToken).length > 0) {
|
454
|
-
importsAsterisk = true;
|
455
|
-
}
|
456
|
-
});
|
457
|
-
// if imports * from fileName, don't add symbolName
|
458
|
-
if (importsAsterisk) {
|
459
|
-
return new NoopChange();
|
460
|
-
}
|
461
|
-
const importTextNodes = imports.filter((n) => n.text === symbolName);
|
462
|
-
// insert import if it's not there
|
463
|
-
if (importTextNodes.length === 0) {
|
464
|
-
const fallbackPos = (0, typescript_1.findNodes)(relevantImports[0], tsModule.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
465
|
-
(0, typescript_1.findNodes)(relevantImports[0], tsModule.SyntaxKind.FromKeyword)[0].getStart();
|
466
|
-
return insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
467
|
-
}
|
468
|
-
return new NoopChange();
|
469
|
-
}
|
470
|
-
// no such import declaration exists
|
471
|
-
const useStrict = (0, typescript_1.findNodes)(rootNode, tsModule.SyntaxKind.StringLiteral).filter((n) => n.text === 'use strict');
|
472
|
-
let fallbackPos = 0;
|
473
|
-
if (useStrict.length > 0) {
|
474
|
-
fallbackPos = useStrict[0].end;
|
475
|
-
}
|
476
|
-
const open = isDefault ? '' : '{ ';
|
477
|
-
const close = isDefault ? '' : ' }';
|
478
|
-
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
479
|
-
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
480
|
-
const separator = insertAtBeginning ? '' : ';\n';
|
481
|
-
const toInsert = `${separator}import ${open}${symbolName}${close}` +
|
482
|
-
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
483
|
-
return insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, tsModule.SyntaxKind.StringLiteral);
|
484
|
-
}
|
485
|
-
exports.insertImport = insertImport;
|
486
|
-
function replaceNodeValue(host, modulePath, node, content) {
|
487
|
-
insert(host, modulePath, [
|
488
|
-
new ReplaceChange(modulePath, node.getStart(node.getSourceFile()), node.getFullText(), content),
|
489
|
-
]);
|
490
|
-
}
|
491
|
-
exports.replaceNodeValue = replaceNodeValue;
|
492
|
-
function renameSyncInTree(tree, from, to, cb) {
|
493
|
-
if (!tree.exists(from)) {
|
494
|
-
cb(`Path: ${from} does not exist`);
|
495
|
-
}
|
496
|
-
else if (tree.exists(to)) {
|
497
|
-
cb(`Path: ${to} already exists`);
|
498
|
-
}
|
499
|
-
else {
|
500
|
-
renameFile(tree, from, to);
|
501
|
-
cb(null);
|
502
|
-
}
|
503
|
-
}
|
504
|
-
exports.renameSyncInTree = renameSyncInTree;
|
505
|
-
function renameDirSyncInTree(tree, from, to, cb) {
|
506
|
-
const dir = tree.getDir(from);
|
507
|
-
if (!dirExists(dir)) {
|
508
|
-
cb(`Path: ${from} does not exist`);
|
509
|
-
return;
|
510
|
-
}
|
511
|
-
dir.visit((path) => {
|
512
|
-
const destination = path.replace(from, to);
|
513
|
-
renameFile(tree, path, destination);
|
514
|
-
});
|
515
|
-
cb(null);
|
516
|
-
}
|
517
|
-
exports.renameDirSyncInTree = renameDirSyncInTree;
|
518
|
-
function dirExists(dir) {
|
519
|
-
return dir.subdirs.length + dir.subfiles.length !== 0;
|
520
|
-
}
|
521
|
-
function renameFile(tree, from, to) {
|
522
|
-
const buffer = tree.read(from);
|
523
|
-
if (!buffer) {
|
524
|
-
return;
|
525
|
-
}
|
526
|
-
tree.create(to, buffer);
|
527
|
-
tree.delete(from);
|
528
|
-
}
|
529
|
-
/**
|
530
|
-
* Applies a template merge but skips for already existing entries
|
531
|
-
*/
|
532
|
-
function applyWithSkipExisting(source, rules) {
|
533
|
-
const { mergeWith, apply, forEach } = require('@angular-devkit/schematics');
|
534
|
-
return (tree, _context) => {
|
535
|
-
const rule = mergeWith(apply(source, [
|
536
|
-
...rules,
|
537
|
-
forEach((fileEntry) => {
|
538
|
-
if (tree.exists(fileEntry.path)) {
|
539
|
-
return null;
|
540
|
-
}
|
541
|
-
return fileEntry;
|
542
|
-
}),
|
543
|
-
]));
|
544
|
-
return rule(tree, _context);
|
545
|
-
};
|
546
|
-
}
|
547
|
-
exports.applyWithSkipExisting = applyWithSkipExisting;
|
6
|
+
var get_source_nodes_1 = require("../utilities/typescript/get-source-nodes");
|
7
|
+
Object.defineProperty(exports, "getSourceNodes", { enumerable: true, get: function () { return get_source_nodes_1.getSourceNodes; } });
|
548
8
|
//# sourceMappingURL=ast-utils.js.map
|