@ng-doc/add 22.0.0-beta.1 → 22.0.0
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/README.md +19 -29
- package/package.json +23 -21
- package/schematics/collection.json +14 -14
- package/schematics/ng-add/constants/modules.d.ts +22 -0
- package/schematics/ng-add/constants/modules.js +25 -11
- package/schematics/ng-add/constants/modules.js.map +1 -1
- package/schematics/ng-add/constants/styles.d.ts +4 -0
- package/schematics/ng-add/constants/styles.js +8 -1
- package/schematics/ng-add/constants/styles.js.map +1 -1
- package/schematics/ng-add/index.d.ts +5 -2
- package/schematics/ng-add/index.js +43 -14
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-add/schema.d.ts +8 -0
- package/schematics/ng-add/schema.json +19 -14
- package/schematics/ng-add/steps/add-assets.d.ts +2 -3
- package/schematics/ng-add/steps/add-assets.js +9 -4
- package/schematics/ng-add/steps/add-assets.js.map +1 -1
- package/schematics/ng-add/steps/add-git-ignore.d.ts +1 -3
- package/schematics/ng-add/steps/add-git-ignore.js +9 -4
- package/schematics/ng-add/steps/add-git-ignore.js.map +1 -1
- package/schematics/ng-add/steps/add-layout.d.ts +2 -2
- package/schematics/ng-add/steps/add-layout.js +8 -2
- package/schematics/ng-add/steps/add-layout.js.map +1 -1
- package/schematics/ng-add/steps/add-ng-doc-app-config.d.ts +5 -1
- package/schematics/ng-add/steps/add-ng-doc-app-config.js +200 -54
- package/schematics/ng-add/steps/add-ng-doc-app-config.js.map +1 -1
- package/schematics/ng-add/steps/add-tsconfig-paths.js +2 -1
- package/schematics/ng-add/steps/add-tsconfig-paths.js.map +1 -1
- package/schematics/ng-add/steps/post-install.d.ts +4 -2
- package/schematics/ng-add/steps/post-install.js +4 -3
- package/schematics/ng-add/steps/post-install.js.map +1 -1
- package/schematics/ng-add/steps/raise-initial-budget.d.ts +22 -0
- package/schematics/ng-add/steps/raise-initial-budget.js +70 -0
- package/schematics/ng-add/steps/raise-initial-budget.js.map +1 -0
- package/schematics/ng-add/steps/replace-builders.d.ts +2 -2
- package/schematics/ng-add/steps/replace-builders.js +12 -4
- package/schematics/ng-add/steps/replace-builders.js.map +1 -1
- package/schematics/ng-add/steps/update-app-ts-config.js +2 -1
- package/schematics/ng-add/steps/update-app-ts-config.js.map +1 -1
- package/schematics/ng-add/utils/add-array-entry.d.ts +56 -0
- package/schematics/ng-add/utils/add-array-entry.js +325 -0
- package/schematics/ng-add/utils/add-array-entry.js.map +1 -0
- package/schematics/ng-add/utils/add-unique-import.d.ts +7 -3
- package/schematics/ng-add/utils/add-unique-import.js +21 -16
- package/schematics/ng-add/utils/add-unique-import.js.map +1 -1
- package/schematics/ng-add/utils/get-app-component.d.ts +4 -3
- package/schematics/ng-add/utils/get-app-component.js +7 -5
- package/schematics/ng-add/utils/get-app-component.js.map +1 -1
- package/schematics/ng-add/utils/get-app-template-path.d.ts +4 -8
- package/schematics/ng-add/utils/get-app-template-path.js +4 -4
- package/schematics/ng-add/utils/get-app-template-path.js.map +1 -1
- package/schematics/ng-add/utils/get-build-options-target.d.ts +17 -0
- package/schematics/ng-add/utils/get-build-options-target.js +27 -0
- package/schematics/ng-add/utils/get-build-options-target.js.map +1 -0
- package/schematics/ng-add/utils/get-main-path.d.ts +2 -2
- package/schematics/ng-add/utils/get-main-path.js +4 -3
- package/schematics/ng-add/utils/get-main-path.js.map +1 -1
- package/schematics/ng-add/utils/get-root-module.d.ts +14 -0
- package/schematics/ng-add/utils/get-root-module.js +31 -0
- package/schematics/ng-add/utils/get-root-module.js.map +1 -0
- package/schematics/ng-add/utils/select-engine.d.ts +38 -0
- package/schematics/ng-add/utils/select-engine.js +97 -0
- package/schematics/ng-add/utils/select-engine.js.map +1 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { logging } from '@angular-devkit/core';
|
|
2
|
+
import { ArrayLiteralExpression, CallExpression, Expression, Node, ObjectLiteralExpression } from 'ng-morph';
|
|
3
|
+
import { ImportConstant } from '../constants/modules';
|
|
4
|
+
/** What `addArrayEntries` did with an entry. */
|
|
5
|
+
export type ArrayEntryResult = 'added' | 'extended' | 'unchanged' | 'skipped';
|
|
6
|
+
/** The part of the schematic logger that the helpers report to. */
|
|
7
|
+
export type EntryLogger = Pick<logging.LoggerApi, 'info' | 'warn'>;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the name that identifies an entry: the text of the initializer before its first `(`,
|
|
10
|
+
* for example `provideRouter`, `RouterModule.forRoot` or `NgDocRootComponent`.
|
|
11
|
+
* @param entry - The entry to name.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEntryName(entry: ImportConstant): string;
|
|
14
|
+
/**
|
|
15
|
+
* Tells whether an expression is a call of `name` or the identifier `name`. A call through a
|
|
16
|
+
* namespace import (`router.provideRouter(...)`) matches too.
|
|
17
|
+
* @param node - The expression to check.
|
|
18
|
+
* @param name - The function or identifier name, as returned by `getEntryName`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isEntry(node: Node, name: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Finds every element of an array that is a call of `name` or the identifier `name`.
|
|
23
|
+
* @param array - The array to search.
|
|
24
|
+
* @param name - The function or identifier name, as returned by `getEntryName`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function findArrayEntries(array: ArrayLiteralExpression, name: string): Expression[];
|
|
27
|
+
/**
|
|
28
|
+
* Adds entries to an `imports` or `providers` array, or extends the calls that are already there.
|
|
29
|
+
*
|
|
30
|
+
* An existing call keeps its own arguments; only the routes, features and options it lacks are
|
|
31
|
+
* added, so running `ng add` again, or on an application that already calls `provideRouter` or
|
|
32
|
+
* `provideHttpClient`, never registers them twice. Several calls of the same provider (as the
|
|
33
|
+
* previous `ng add` left them) are merged into the first one. New entries are appended in one
|
|
34
|
+
* edit, on separate lines when the array already spans several lines.
|
|
35
|
+
* @param array - The array literal to update.
|
|
36
|
+
* @param entries - The entries to add, in order.
|
|
37
|
+
* @param logger - Receives what was merged and what needs a manual change.
|
|
38
|
+
* @returns What happened to each entry, in the order of `entries`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function addArrayEntries(array: ArrayLiteralExpression, entries: ImportConstant[], logger: EntryLogger): ArrayEntryResult[];
|
|
41
|
+
/**
|
|
42
|
+
* Adds the routes, features and options of an entry that an existing call lacks.
|
|
43
|
+
* @param call - The existing call.
|
|
44
|
+
* @param entry - The entry that describes what the call needs.
|
|
45
|
+
* @param logger - Receives what needs a manual change.
|
|
46
|
+
* @returns Whether the call changed.
|
|
47
|
+
*/
|
|
48
|
+
export declare function extendCall(call: CallExpression, entry: ImportConstant, logger: EntryLogger): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the array literal of an object literal property, creating `name: []` when the property
|
|
51
|
+
* is missing. Returns `undefined` when the property is not an array literal (for example a
|
|
52
|
+
* variable), because it cannot be edited safely.
|
|
53
|
+
* @param objectLiteral - The object literal that owns the property.
|
|
54
|
+
* @param name - The property name.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getArrayProperty(objectLiteral: ObjectLiteralExpression, name: string): ArrayLiteralExpression | undefined;
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEntryName = getEntryName;
|
|
4
|
+
exports.isEntry = isEntry;
|
|
5
|
+
exports.findArrayEntries = findArrayEntries;
|
|
6
|
+
exports.addArrayEntries = addArrayEntries;
|
|
7
|
+
exports.extendCall = extendCall;
|
|
8
|
+
exports.getArrayProperty = getArrayProperty;
|
|
9
|
+
const ng_morph_1 = require("ng-morph");
|
|
10
|
+
const modules_1 = require("../constants/modules");
|
|
11
|
+
/**
|
|
12
|
+
* Returns the name that identifies an entry: the text of the initializer before its first `(`,
|
|
13
|
+
* for example `provideRouter`, `RouterModule.forRoot` or `NgDocRootComponent`.
|
|
14
|
+
* @param entry - The entry to name.
|
|
15
|
+
*/
|
|
16
|
+
function getEntryName(entry) {
|
|
17
|
+
return getCallName(entry.initializer);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Tells whether an expression is a call of `name` or the identifier `name`. A call through a
|
|
21
|
+
* namespace import (`router.provideRouter(...)`) matches too.
|
|
22
|
+
* @param node - The expression to check.
|
|
23
|
+
* @param name - The function or identifier name, as returned by `getEntryName`.
|
|
24
|
+
*/
|
|
25
|
+
function isEntry(node, name) {
|
|
26
|
+
const text = ng_morph_1.Node.isCallExpression(node)
|
|
27
|
+
? node.getExpression().getText()
|
|
28
|
+
: node.getText();
|
|
29
|
+
return text === name || text.endsWith(`.${name}`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Finds every element of an array that is a call of `name` or the identifier `name`.
|
|
33
|
+
* @param array - The array to search.
|
|
34
|
+
* @param name - The function or identifier name, as returned by `getEntryName`.
|
|
35
|
+
*/
|
|
36
|
+
function findArrayEntries(array, name) {
|
|
37
|
+
return array.getElements().filter((element) => isEntry(element, name));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Adds entries to an `imports` or `providers` array, or extends the calls that are already there.
|
|
41
|
+
*
|
|
42
|
+
* An existing call keeps its own arguments; only the routes, features and options it lacks are
|
|
43
|
+
* added, so running `ng add` again, or on an application that already calls `provideRouter` or
|
|
44
|
+
* `provideHttpClient`, never registers them twice. Several calls of the same provider (as the
|
|
45
|
+
* previous `ng add` left them) are merged into the first one. New entries are appended in one
|
|
46
|
+
* edit, on separate lines when the array already spans several lines.
|
|
47
|
+
* @param array - The array literal to update.
|
|
48
|
+
* @param entries - The entries to add, in order.
|
|
49
|
+
* @param logger - Receives what was merged and what needs a manual change.
|
|
50
|
+
* @returns What happened to each entry, in the order of `entries`.
|
|
51
|
+
*/
|
|
52
|
+
function addArrayEntries(array, entries, logger) {
|
|
53
|
+
// Decided before any call is extended, since extending a call may add line breaks inside it.
|
|
54
|
+
const multiline = array.getText().includes('\n');
|
|
55
|
+
const added = [];
|
|
56
|
+
const results = entries.map((entry) => {
|
|
57
|
+
const name = getEntryName(entry);
|
|
58
|
+
const existing = findArrayEntries(array, name);
|
|
59
|
+
if (!existing.length) {
|
|
60
|
+
added.push(entry.initializer);
|
|
61
|
+
return 'added';
|
|
62
|
+
}
|
|
63
|
+
const calls = existing.filter(ng_morph_1.Node.isCallExpression);
|
|
64
|
+
if (!calls.length) {
|
|
65
|
+
return 'unchanged';
|
|
66
|
+
}
|
|
67
|
+
if (calls.length > 1) {
|
|
68
|
+
if (entry.options) {
|
|
69
|
+
// Options objects cannot be merged safely; a second `forRoot` throws at startup anyway.
|
|
70
|
+
logger.warn(`⚠️ "${name}" is called ${calls.length} times. Keep one call and add "${entry.routes}" to it manually.`);
|
|
71
|
+
return 'skipped';
|
|
72
|
+
}
|
|
73
|
+
extendCall(mergeCalls(array, calls, entry, logger), entry, logger);
|
|
74
|
+
return 'extended';
|
|
75
|
+
}
|
|
76
|
+
return extendCall(calls[0], entry, logger) ? 'extended' : 'unchanged';
|
|
77
|
+
});
|
|
78
|
+
if (added.length) {
|
|
79
|
+
array.addElements(added, { useNewLines: multiline });
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Adds the routes, features and options of an entry that an existing call lacks.
|
|
85
|
+
* @param call - The existing call.
|
|
86
|
+
* @param entry - The entry that describes what the call needs.
|
|
87
|
+
* @param logger - Receives what needs a manual change.
|
|
88
|
+
* @returns Whether the call changed.
|
|
89
|
+
*/
|
|
90
|
+
function extendCall(call, entry, logger) {
|
|
91
|
+
const changes = [
|
|
92
|
+
entry.routes ? addRoutes(call, entry.routes, logger) : false,
|
|
93
|
+
...(entry.features ?? []).map((feature) => addFeature(call, feature)),
|
|
94
|
+
entry.options ? addOptions(call, getEntryName(entry), entry.options, logger) : false,
|
|
95
|
+
];
|
|
96
|
+
return changes.some(Boolean);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns the array literal of an object literal property, creating `name: []` when the property
|
|
100
|
+
* is missing. Returns `undefined` when the property is not an array literal (for example a
|
|
101
|
+
* variable), because it cannot be edited safely.
|
|
102
|
+
* @param objectLiteral - The object literal that owns the property.
|
|
103
|
+
* @param name - The property name.
|
|
104
|
+
*/
|
|
105
|
+
function getArrayProperty(objectLiteral, name) {
|
|
106
|
+
const property = objectLiteral.getProperty(name) ?? objectLiteral.addProperty(`${name}: []`);
|
|
107
|
+
if (!ng_morph_1.Node.isPropertyAssignment(property)) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const initializer = property.getInitializer();
|
|
111
|
+
return ng_morph_1.Node.isArrayLiteralExpression(initializer) ? initializer : undefined;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Merges several calls of one provider into the first. Routes are concatenated in call order,
|
|
115
|
+
* which is the order in which two `provideRouter` calls registered them. Features are kept once
|
|
116
|
+
* by name; when two calls pass the same feature, the later one wins, as it did in the injector.
|
|
117
|
+
* Deprecated features that the previous `ng add` added are dropped.
|
|
118
|
+
* @param array - The array that holds the calls.
|
|
119
|
+
* @param calls - The calls, in array order.
|
|
120
|
+
* @param entry - The entry the calls belong to.
|
|
121
|
+
* @param logger - Receives the merge.
|
|
122
|
+
* @returns The merged call.
|
|
123
|
+
*/
|
|
124
|
+
function mergeCalls(array, calls, entry, logger) {
|
|
125
|
+
const routes = [];
|
|
126
|
+
const features = new Map();
|
|
127
|
+
const dropped = [];
|
|
128
|
+
calls.forEach((call) => {
|
|
129
|
+
const args = call.getArguments();
|
|
130
|
+
if (entry.routes && args[0]) {
|
|
131
|
+
const [first] = args;
|
|
132
|
+
const parts = ng_morph_1.Node.isArrayLiteralExpression(first)
|
|
133
|
+
? first.getElements().map((element) => element.getText())
|
|
134
|
+
: [`...${first.getText()}`];
|
|
135
|
+
parts
|
|
136
|
+
.filter((part) => !routes.includes(part))
|
|
137
|
+
.forEach((part) => routes.push(part));
|
|
138
|
+
}
|
|
139
|
+
(entry.routes ? args.slice(1) : args).forEach((argument) => {
|
|
140
|
+
const text = argument.getText();
|
|
141
|
+
const name = ng_morph_1.Node.isCallExpression(argument) ? getCallName(text) : text;
|
|
142
|
+
if (modules_1.DROPPED_FEATURES.includes(name)) {
|
|
143
|
+
dropped.push(name);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
features.set(name, text);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
const [first, ...rest] = calls;
|
|
151
|
+
const callee = first.getExpression().getText();
|
|
152
|
+
const args = [
|
|
153
|
+
...(entry.routes ? [`[${routes.join(', ')}]`] : []),
|
|
154
|
+
...features.values(),
|
|
155
|
+
];
|
|
156
|
+
const sourceFile = array.getSourceFile();
|
|
157
|
+
rest.forEach((call) => array.removeElement(call));
|
|
158
|
+
const merged = first.replaceWithText(`${callee}(${args.join(', ')})`);
|
|
159
|
+
removeUnusedImports(sourceFile, dropped);
|
|
160
|
+
logger.info(`🔄 Merged ${calls.length} "${getEntryName(entry)}" calls into one.`);
|
|
161
|
+
return merged;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Makes the first argument of a router call include `routes`. The application's own routes stay
|
|
165
|
+
* first, which keeps their precedence the same as when the routes were registered by two calls,
|
|
166
|
+
* except that the routes go before a trailing wildcard (`**`) route, which would hide them.
|
|
167
|
+
* @param call - The router call.
|
|
168
|
+
* @param routes - The identifier of the routes to include.
|
|
169
|
+
* @param logger - Receives the wildcard warnings.
|
|
170
|
+
*/
|
|
171
|
+
function addRoutes(call, routes, logger) {
|
|
172
|
+
const [first] = call.getArguments();
|
|
173
|
+
if (!first) {
|
|
174
|
+
call.addArgument(routes);
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
const mentioned = [first, ...first.getDescendantsOfKind(ng_morph_1.SyntaxKind.Identifier)].some((node) => ng_morph_1.Node.isIdentifier(node) && node.getText() === routes);
|
|
178
|
+
if (mentioned) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
if (ng_morph_1.Node.isArrayLiteralExpression(first)) {
|
|
182
|
+
const wildcard = first.getElements().findIndex(isWildcardRoute);
|
|
183
|
+
if (wildcard === -1) {
|
|
184
|
+
first.addElement(`...${routes}`);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
first.insertElement(wildcard, `...${routes}`);
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
warnAboutWildcard(first, routes, logger);
|
|
192
|
+
first.replaceWithText(`[...${first.getText()}, ...${routes}]`);
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Warns when routes that are not written inline may end with a wildcard route, which would hide
|
|
197
|
+
* the routes appended after them.
|
|
198
|
+
* @param routesArgument - The routes argument of the router call.
|
|
199
|
+
* @param routes - The identifier of the routes that are appended.
|
|
200
|
+
* @param logger - Receives the warning.
|
|
201
|
+
*/
|
|
202
|
+
function warnAboutWildcard(routesArgument, routes, logger) {
|
|
203
|
+
const definition = ng_morph_1.Node.isIdentifier(routesArgument)
|
|
204
|
+
? routesArgument.getDefinitionNodes()[0]
|
|
205
|
+
: undefined;
|
|
206
|
+
const initializer = ng_morph_1.Node.isVariableDeclaration(definition)
|
|
207
|
+
? definition.getInitializer()
|
|
208
|
+
: undefined;
|
|
209
|
+
if (ng_morph_1.Node.isArrayLiteralExpression(initializer)) {
|
|
210
|
+
if (initializer.getElements().some(isWildcardRoute)) {
|
|
211
|
+
logger.warn(`⚠️ "${routesArgument.getText()}" has a wildcard ("**") route that hides "${routes}". Move it after "${routes}".`);
|
|
212
|
+
}
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
logger.warn(`⚠️ "${routes}" is added after "${routesArgument.getText()}". If those routes end with a wildcard ("**") route, move it after "${routes}".`);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Tells whether a route literal is a wildcard route (`{path: '**', ...}`).
|
|
219
|
+
* @param node - An element of a routes array.
|
|
220
|
+
*/
|
|
221
|
+
function isWildcardRoute(node) {
|
|
222
|
+
if (!ng_morph_1.Node.isObjectLiteralExpression(node)) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
const path = node.getProperty('path');
|
|
226
|
+
const value = ng_morph_1.Node.isPropertyAssignment(path)
|
|
227
|
+
? path.getInitializer()
|
|
228
|
+
: undefined;
|
|
229
|
+
return ng_morph_1.Node.isStringLiteral(value) || ng_morph_1.Node.isNoSubstitutionTemplateLiteral(value)
|
|
230
|
+
? value.getLiteralValue() === '**'
|
|
231
|
+
: false;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Appends a feature call unless the call already passes a feature with the same function name.
|
|
235
|
+
* @param call - The call to extend.
|
|
236
|
+
* @param feature - The feature call, for example `withInterceptorsFromDi()`.
|
|
237
|
+
*/
|
|
238
|
+
function addFeature(call, feature) {
|
|
239
|
+
const name = getCallName(feature);
|
|
240
|
+
const present = call
|
|
241
|
+
.getArguments()
|
|
242
|
+
.some((argument) => ng_morph_1.Node.isCallExpression(argument) && isEntry(argument, name));
|
|
243
|
+
if (present) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
call.addArgument(feature);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Adds the options a call does not set yet. An options object that is not an object literal is
|
|
251
|
+
* left alone, because its properties cannot be inspected; the logger says what to set.
|
|
252
|
+
* @param call - The call whose second argument holds the options.
|
|
253
|
+
* @param name - The name of the call, for the warning.
|
|
254
|
+
* @param options - The property names and initializers to set.
|
|
255
|
+
* @param logger - Receives the warning.
|
|
256
|
+
*/
|
|
257
|
+
function addOptions(call, name, options, logger) {
|
|
258
|
+
const [, current] = call.getArguments();
|
|
259
|
+
const text = options
|
|
260
|
+
.map(([property, initializer]) => `${property}: ${initializer}`)
|
|
261
|
+
.join(', ');
|
|
262
|
+
if (!current) {
|
|
263
|
+
call.addArgument(`{${text}}`);
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
if (!ng_morph_1.Node.isObjectLiteralExpression(current)) {
|
|
267
|
+
logger.warn(`⚠️ The options of "${name}" ("${current.getText()}") are not an object literal. Set {${text}} in them manually.`);
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
const missing = options.filter(([property]) => !current.getProperty(property));
|
|
271
|
+
if (!missing.length) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
const added = missing.map(([property, initializer]) => `${property}: ${initializer}`);
|
|
275
|
+
if (current.getText().includes('\n')) {
|
|
276
|
+
missing.forEach(([property, initializer]) => current.addPropertyAssignment({ name: property, initializer }));
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
// ts-morph puts every added property on a new line; a one-line object stays on one line.
|
|
280
|
+
const source = current.getText();
|
|
281
|
+
const body = source.slice(1, -1).trim().replace(/,$/, '');
|
|
282
|
+
const inner = [body, ...added].filter(Boolean).join(', ');
|
|
283
|
+
current.replaceWithText(/^\{\s/.test(source) ? `{ ${inner} }` : `{${inner}}`);
|
|
284
|
+
}
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Removes named imports that the file no longer uses (the features dropped by `mergeCalls`).
|
|
289
|
+
* @param sourceFile - The file to clean up.
|
|
290
|
+
* @param names - The imported names to check.
|
|
291
|
+
*/
|
|
292
|
+
function removeUnusedImports(sourceFile, names) {
|
|
293
|
+
names.forEach((name) => {
|
|
294
|
+
const used = sourceFile
|
|
295
|
+
.getDescendantsOfKind(ng_morph_1.SyntaxKind.Identifier)
|
|
296
|
+
.some((identifier) => identifier.getText() === name &&
|
|
297
|
+
!identifier.getFirstAncestorByKind(ng_morph_1.SyntaxKind.ImportDeclaration));
|
|
298
|
+
if (used) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
sourceFile.getImportDeclarations().forEach((declaration) => {
|
|
302
|
+
const specifier = declaration
|
|
303
|
+
.getNamedImports()
|
|
304
|
+
.find((named) => named.getName() === name && !named.getAliasNode());
|
|
305
|
+
if (!specifier) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
specifier.remove();
|
|
309
|
+
if (!declaration.getNamedImports().length &&
|
|
310
|
+
!declaration.getDefaultImport() &&
|
|
311
|
+
!declaration.getNamespaceImport()) {
|
|
312
|
+
declaration.remove();
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Returns the text of a call before its first `(`.
|
|
319
|
+
* @param text - The call, for example `withInterceptorsFromDi()`.
|
|
320
|
+
*/
|
|
321
|
+
function getCallName(text) {
|
|
322
|
+
const index = text.indexOf('(');
|
|
323
|
+
return index === -1 ? text : text.slice(0, index);
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=add-array-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-array-entry.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/utils/add-array-entry.ts"],"names":[],"mappings":";;AA0BA,oCAEC;AAQD,0BAMC;AAOD,4CAEC;AAeD,0CA+CC;AASD,gCAYC;AASD,4CAaC;AA3JD,uCAUkB;AAElB,kDAAwE;AAQxE;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAqB;IAChD,OAAO,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,IAAU,EAAE,IAAY;IAC9C,MAAM,IAAI,GAAW,eAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;QAC9C,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE;QAChC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAEnB,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,SAAgB,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AAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Adds a named import to a file unless the file already imports that name from the module.
|
|
2
3
|
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
*
|
|
4
|
+
* The name is added to an existing named-import declaration of the module. A namespace import
|
|
5
|
+
* (`import * as router from '@angular/router'`) or a type-only import cannot take it, so a
|
|
6
|
+
* separate declaration is added in that case.
|
|
7
|
+
* @param filePath - The file to update.
|
|
8
|
+
* @param namedImport - The exported name to import.
|
|
9
|
+
* @param moduleSpecifier - The module that exports it.
|
|
6
10
|
*/
|
|
7
11
|
export declare function addUniqueImport(filePath: string, namedImport: string, moduleSpecifier: string): void;
|
|
@@ -3,33 +3,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addUniqueImport = addUniqueImport;
|
|
4
4
|
const ng_morph_1 = require("ng-morph");
|
|
5
5
|
/**
|
|
6
|
+
* Adds a named import to a file unless the file already imports that name from the module.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
8
|
+
* The name is added to an existing named-import declaration of the module. A namespace import
|
|
9
|
+
* (`import * as router from '@angular/router'`) or a type-only import cannot take it, so a
|
|
10
|
+
* separate declaration is added in that case.
|
|
11
|
+
* @param filePath - The file to update.
|
|
12
|
+
* @param namedImport - The exported name to import.
|
|
13
|
+
* @param moduleSpecifier - The module that exports it.
|
|
10
14
|
*/
|
|
11
15
|
function addUniqueImport(filePath, namedImport, moduleSpecifier) {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const declarations = (0, ng_morph_1.getImports)(filePath, { moduleSpecifier });
|
|
17
|
+
const imported = declarations.some((declaration) => !declaration.isTypeOnly() &&
|
|
18
|
+
declaration
|
|
19
|
+
.getNamedImports()
|
|
20
|
+
.some((specifier) => !specifier.isTypeOnly() &&
|
|
21
|
+
specifier.getName() === namedImport &&
|
|
22
|
+
(specifier.getAliasNode()?.getText() ?? namedImport) === namedImport));
|
|
23
|
+
if (imported) {
|
|
17
24
|
return;
|
|
18
25
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (existingDeclaration.length) {
|
|
23
|
-
const modules = existingDeclaration[0]
|
|
26
|
+
const target = declarations.find((declaration) => !declaration.getNamespaceImport() && !declaration.isTypeOnly());
|
|
27
|
+
if (target) {
|
|
28
|
+
const modules = target
|
|
24
29
|
.getNamedImports()
|
|
25
|
-
.map((
|
|
26
|
-
(0, ng_morph_1.editImports)(
|
|
30
|
+
.map((specifier) => specifier.getText());
|
|
31
|
+
(0, ng_morph_1.editImports)(target, () => ({
|
|
27
32
|
namedImports: [...modules, namedImport],
|
|
28
33
|
}));
|
|
29
34
|
return;
|
|
30
35
|
}
|
|
31
36
|
(0, ng_morph_1.addImports)(filePath, {
|
|
32
|
-
moduleSpecifier
|
|
37
|
+
moduleSpecifier,
|
|
33
38
|
namedImports: [namedImport],
|
|
34
39
|
});
|
|
35
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-unique-import.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/utils/add-unique-import.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"add-unique-import.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/utils/add-unique-import.ts"],"names":[],"mappings":";;AAYA,0CA4CC;AAxDD,uCAAmG;AAEnG;;;;;;;;;GASG;AACH,SAAgB,eAAe,CAC7B,QAAgB,EAChB,WAAmB,EACnB,eAAuB;IAEvB,MAAM,YAAY,GAAwB,IAAA,qBAAU,EAAC,QAAQ,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;IACpF,MAAM,QAAQ,GAAY,YAAY,CAAC,IAAI,CACzC,CAAC,WAA8B,EAAE,EAAE,CACjC,CAAC,WAAW,CAAC,UAAU,EAAE;QACzB,WAAW;aACR,eAAe,EAAE;aACjB,IAAI,CACH,CAAC,SAA0B,EAAE,EAAE,CAC7B,CAAC,SAAS,CAAC,UAAU,EAAE;YACvB,SAAS,CAAC,OAAO,EAAE,KAAK,WAAW;YACnC,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,WAAW,CAAC,KAAK,WAAW,CACvE,CACN,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAkC,YAAY,CAAC,IAAI,CAC7D,CAAC,WAA8B,EAAE,EAAE,CACjC,CAAC,WAAW,CAAC,kBAAkB,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CACjE,CAAC;IAEF,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,OAAO,GAAa,MAAM;aAC7B,eAAe,EAAE;aACjB,GAAG,CAAC,CAAC,SAA0B,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;QAE5D,IAAA,sBAAW,EAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;YACzB,YAAY,EAAE,CAAC,GAAG,OAAO,EAAE,WAAW,CAAC;SACxC,CAAC,CAAC,CAAC;QAEJ,OAAO;IACT,CAAC;IAED,IAAA,qBAAU,EAAC,QAAQ,EAAE;QACnB,eAAe;QACf,YAAY,EAAE,CAAC,WAAW,CAAC;KAC5B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Tree } from '@angular-devkit/schematics';
|
|
2
2
|
import { ClassDeclaration } from 'ng-morph';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @param
|
|
4
|
+
* Returns the root component: the component passed to `bootstrapApplication`, or the first
|
|
5
|
+
* declaration of the module passed to `bootstrapModule`.
|
|
6
|
+
* @param tree - The workspace tree.
|
|
7
|
+
* @param mainPath - Path of the application's main file.
|
|
7
8
|
*/
|
|
8
9
|
export declare function getAppComponent(tree: Tree, mainPath: string): ClassDeclaration | undefined;
|
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAppComponent = getAppComponent;
|
|
4
4
|
const ng_morph_1 = require("ng-morph");
|
|
5
5
|
const get_initializer_1 = require("./get-initializer");
|
|
6
|
+
const get_root_module_1 = require("./get-root-module");
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param
|
|
8
|
+
* Returns the root component: the component passed to `bootstrapApplication`, or the first
|
|
9
|
+
* declaration of the module passed to `bootstrapModule`.
|
|
10
|
+
* @param tree - The workspace tree.
|
|
11
|
+
* @param mainPath - Path of the application's main file.
|
|
10
12
|
*/
|
|
11
13
|
function getAppComponent(tree, mainPath) {
|
|
12
14
|
const bootstrapApplicationFn = (0, ng_morph_1.getBootstrapApplicationFn)(mainPath);
|
|
@@ -20,8 +22,8 @@ function getAppComponent(tree, mainPath) {
|
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
else {
|
|
23
|
-
const mainModule = (0,
|
|
24
|
-
const mainInitializer = (0, get_initializer_1.getInitializer)(mainModule, 'NgModule', 'declarations');
|
|
25
|
+
const mainModule = (0, get_root_module_1.getRootModule)(mainPath);
|
|
26
|
+
const mainInitializer = mainModule && (0, get_initializer_1.getInitializer)(mainModule, 'NgModule', 'declarations');
|
|
25
27
|
if (ng_morph_1.Node.isArrayLiteralExpression(mainInitializer)) {
|
|
26
28
|
const appIdentifier = mainInitializer.getElements()[0];
|
|
27
29
|
if (ng_morph_1.Node.isIdentifier(appIdentifier)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-app-component.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/utils/get-app-component.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"get-app-component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,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param tree
|
|
4
|
-
* @param mainPath
|
|
5
|
-
*/
|
|
6
1
|
import { Tree } from '@angular-devkit/schematics';
|
|
7
2
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
3
|
+
* Returns the path of the root component's template (`templateUrl`, or `app.component.html` next
|
|
4
|
+
* to the component when it has none).
|
|
5
|
+
* @param tree - The workspace tree.
|
|
6
|
+
* @param mainPath - Path of the application's main file.
|
|
11
7
|
*/
|
|
12
8
|
export declare function getAppTemplatePath(tree: Tree, mainPath: string): string | undefined;
|
|
@@ -6,9 +6,10 @@ const path = require("path");
|
|
|
6
6
|
const get_app_component_1 = require("./get-app-component");
|
|
7
7
|
const get_initializer_1 = require("./get-initializer");
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
9
|
+
* Returns the path of the root component's template (`templateUrl`, or `app.component.html` next
|
|
10
|
+
* to the component when it has none).
|
|
11
|
+
* @param tree - The workspace tree.
|
|
12
|
+
* @param mainPath - Path of the application's main file.
|
|
12
13
|
*/
|
|
13
14
|
function getAppTemplatePath(tree, mainPath) {
|
|
14
15
|
const appComponent = (0, get_app_component_1.getAppComponent)(tree, mainPath);
|
|
@@ -18,7 +19,6 @@ function getAppTemplatePath(tree, mainPath) {
|
|
|
18
19
|
const templateInitializer = (0, get_initializer_1.getInitializer)(appComponent, 'Component', 'templateUrl');
|
|
19
20
|
const appComponentDir = appComponent.getSourceFile().getDirectoryPath();
|
|
20
21
|
const templateUrlPath = path.join(appComponentDir, templateInitializer?.getText().replace(/['"]/g, '') ?? 'app.component.html');
|
|
21
|
-
(0, ng_morph_1.saveActiveProject)();
|
|
22
22
|
return templateUrlPath;
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=get-app-template-path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-app-template-path.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/utils/get-app-template-path.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"get-app-template-path.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/utils/get-app-template-path.ts"],"names":[],"mappings":";;AAaA,gDAqBC;AAjCD,uCAA8D;AAC9D,6BAA6B;AAE7B,2DAAsD;AACtD,uDAAmD;AAEnD;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,IAAU,EAAE,QAAgB;IAC7D,MAAM,YAAY,GAAiC,IAAA,mCAAe,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEnF,IAAI,CAAC,eAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,OAAO;IACT,CAAC;IAED,MAAM,mBAAmB,GAA2B,IAAA,gCAAc,EAChE,YAAY,EACZ,WAAW,EACX,aAAa,CACd,CAAC;IAEF,MAAM,eAAe,GAAW,YAAY,CAAC,aAAa,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAEhF,MAAM,eAAe,GAAW,IAAI,CAAC,IAAI,CACvC,eAAe,EACf,mBAAmB,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,oBAAoB,CAC5E,CAAC;IAEF,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProjectDefinition } from '@angular-devkit/core/src/workspace';
|
|
2
|
+
/** The builder of the Vite engine's production build. */
|
|
3
|
+
export declare const VITE_APPLICATION_BUILDER = "@ng-doc/builder:vite-application";
|
|
4
|
+
/**
|
|
5
|
+
* The target the Vite setup keeps the Angular build options in, for the Angular builders that
|
|
6
|
+
* read them (`unit-test`, `extract-i18n`). `@ng-doc/builder:vite-setup` creates it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ANGULAR_BUILD_TARGET = "build-angular";
|
|
9
|
+
/** The target `migrate-to-vite` keeps the legacy build target in. */
|
|
10
|
+
export declare const LEGACY_BUILD_TARGET = "build-legacy";
|
|
11
|
+
/**
|
|
12
|
+
* The target that holds the application's Angular build options: `build`, or, once `build` runs
|
|
13
|
+
* the Vite engine (whose options are a Vite configuration file), `build-angular` of `ng add` or
|
|
14
|
+
* `build-legacy` of `migrate-to-vite`.
|
|
15
|
+
* @param project - The application project.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getBuildOptionsTarget(project: ProjectDefinition): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LEGACY_BUILD_TARGET = exports.ANGULAR_BUILD_TARGET = exports.VITE_APPLICATION_BUILDER = void 0;
|
|
4
|
+
exports.getBuildOptionsTarget = getBuildOptionsTarget;
|
|
5
|
+
/** The builder of the Vite engine's production build. */
|
|
6
|
+
exports.VITE_APPLICATION_BUILDER = '@ng-doc/builder:vite-application';
|
|
7
|
+
/**
|
|
8
|
+
* The target the Vite setup keeps the Angular build options in, for the Angular builders that
|
|
9
|
+
* read them (`unit-test`, `extract-i18n`). `@ng-doc/builder:vite-setup` creates it.
|
|
10
|
+
*/
|
|
11
|
+
exports.ANGULAR_BUILD_TARGET = 'build-angular';
|
|
12
|
+
/** The target `migrate-to-vite` keeps the legacy build target in. */
|
|
13
|
+
exports.LEGACY_BUILD_TARGET = 'build-legacy';
|
|
14
|
+
/**
|
|
15
|
+
* The target that holds the application's Angular build options: `build`, or, once `build` runs
|
|
16
|
+
* the Vite engine (whose options are a Vite configuration file), `build-angular` of `ng add` or
|
|
17
|
+
* `build-legacy` of `migrate-to-vite`.
|
|
18
|
+
* @param project - The application project.
|
|
19
|
+
*/
|
|
20
|
+
function getBuildOptionsTarget(project) {
|
|
21
|
+
if (project.targets.get('build')?.builder !== exports.VITE_APPLICATION_BUILDER) {
|
|
22
|
+
return 'build';
|
|
23
|
+
}
|
|
24
|
+
return ([exports.ANGULAR_BUILD_TARGET, exports.LEGACY_BUILD_TARGET].find((name) => project.targets.has(name)) ??
|
|
25
|
+
'build');
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=get-build-options-target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-build-options-target.js","sourceRoot":"","sources":["../../../../../../libs/add/schematics/ng-add/utils/get-build-options-target.ts"],"names":[],"mappings":";;;AAoBA,sDASC;AA3BD,yDAAyD;AAC5C,QAAA,wBAAwB,GAAG,kCAAkC,CAAC;AAE3E;;;GAGG;AACU,QAAA,oBAAoB,GAAG,eAAe,CAAC;AAEpD,qEAAqE;AACxD,QAAA,mBAAmB,GAAG,cAAc,CAAC;AAElD;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,OAA0B;IAC9D,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,gCAAwB,EAAE,CAAC;QACvE,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,CACL,CAAC,4BAAoB,EAAE,2BAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC7F,OAAO,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProjectDefinition } from '@angular-devkit/core/src/workspace';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param project
|
|
3
|
+
* Returns the browser entry of the application (`browser`, or `main` of older builders).
|
|
4
|
+
* @param project - The application project.
|
|
5
5
|
*/
|
|
6
6
|
export declare function getMainPath(project: ProjectDefinition): string;
|