@simplysf/simply-utam-core 0.1.3 → 0.3.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 +72 -14
- package/lib/forceignore/forceignore-manager.d.ts +30 -0
- package/lib/forceignore/forceignore-manager.js +30 -13
- package/lib/forceignore/forceignore-manager.js.map +1 -1
- package/lib/forceignore/index.d.ts +1 -1
- package/lib/forceignore/index.js +1 -1
- package/lib/forceignore/index.js.map +1 -1
- package/lib/gitignore/gitignore-manager.d.ts +64 -0
- package/lib/gitignore/gitignore-manager.js +96 -0
- package/lib/gitignore/gitignore-manager.js.map +1 -0
- package/lib/gitignore/index.d.ts +1 -0
- package/lib/gitignore/index.js +17 -0
- package/lib/gitignore/index.js.map +1 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/namespaces/namespace-map.d.ts +18 -0
- package/lib/namespaces/namespace-map.js +75 -0
- package/lib/namespaces/namespace-map.js.map +1 -0
- package/lib/namespaces/namespace-rewriter.js +2 -47
- package/lib/namespaces/namespace-rewriter.js.map +1 -1
- package/lib/path-utils.d.ts +8 -0
- package/lib/path-utils.js +10 -0
- package/lib/path-utils.js.map +1 -1
- package/lib/scaffold/project-scaffolder.d.ts +75 -1
- package/lib/scaffold/project-scaffolder.js +267 -19
- package/lib/scaffold/project-scaffolder.js.map +1 -1
- package/lib/snapshot/capture.d.ts +56 -0
- package/lib/snapshot/capture.js +115 -0
- package/lib/snapshot/capture.js.map +1 -0
- package/lib/snapshot/console.d.ts +25 -0
- package/lib/snapshot/console.js +74 -0
- package/lib/snapshot/console.js.map +1 -0
- package/lib/snapshot/describe.d.ts +27 -0
- package/lib/snapshot/describe.js +76 -0
- package/lib/snapshot/describe.js.map +1 -0
- package/lib/snapshot/files.d.ts +85 -0
- package/lib/snapshot/files.js +185 -0
- package/lib/snapshot/files.js.map +1 -0
- package/lib/snapshot/find.d.ts +36 -0
- package/lib/snapshot/find.js +186 -0
- package/lib/snapshot/find.js.map +1 -0
- package/lib/snapshot/format.d.ts +96 -0
- package/lib/snapshot/format.js +100 -0
- package/lib/snapshot/format.js.map +1 -0
- package/lib/snapshot/header.d.ts +38 -0
- package/lib/snapshot/header.js +120 -0
- package/lib/snapshot/header.js.map +1 -0
- package/lib/snapshot/index.d.ts +13 -0
- package/lib/snapshot/index.js +28 -0
- package/lib/snapshot/index.js.map +1 -0
- package/lib/snapshot/locate.d.ts +61 -0
- package/lib/snapshot/locate.js +110 -0
- package/lib/snapshot/locate.js.map +1 -0
- package/lib/snapshot/lookup.d.ts +53 -0
- package/lib/snapshot/lookup.js +188 -0
- package/lib/snapshot/lookup.js.map +1 -0
- package/lib/snapshot/page-object-index.d.ts +149 -0
- package/lib/snapshot/page-object-index.js +806 -0
- package/lib/snapshot/page-object-index.js.map +1 -0
- package/lib/snapshot/page-object-packages.d.ts +41 -0
- package/lib/snapshot/page-object-packages.js +115 -0
- package/lib/snapshot/page-object-packages.js.map +1 -0
- package/lib/snapshot/path.d.ts +102 -0
- package/lib/snapshot/path.js +381 -0
- package/lib/snapshot/path.js.map +1 -0
- package/lib/snapshot/query-result.d.ts +20 -0
- package/lib/snapshot/query-result.js +32 -0
- package/lib/snapshot/query-result.js.map +1 -0
- package/lib/snapshot/selector.d.ts +103 -0
- package/lib/snapshot/selector.js +280 -0
- package/lib/snapshot/selector.js.map +1 -0
- package/lib/snapshot/tree.d.ts +76 -0
- package/lib/snapshot/tree.js +201 -0
- package/lib/snapshot/tree.js.map +1 -0
- package/lib/snapshot/walker.js +532 -0
- package/package.json +11 -3
- package/templates/dom-snapshot.steps.mjs +34 -0
- package/templates/wdio.conf.mjs +81 -4
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026, SimplySF.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import { createRequire } from 'node:module';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import { discoverPageObjectPackages, packageDir, packageOf, readNamespaceConfig, } from './page-object-packages.js';
|
|
20
|
+
/** Split on a separator outside brackets, parentheses and quotes. */
|
|
21
|
+
function splitTopLevel(value, isSeparator) {
|
|
22
|
+
const parts = [];
|
|
23
|
+
let depth = 0;
|
|
24
|
+
let quote = '';
|
|
25
|
+
let current = '';
|
|
26
|
+
for (const char of value) {
|
|
27
|
+
if (quote) {
|
|
28
|
+
if (char === quote)
|
|
29
|
+
quote = '';
|
|
30
|
+
}
|
|
31
|
+
else if (char === '"' || char === "'")
|
|
32
|
+
quote = char;
|
|
33
|
+
else if (char === '[' || char === '(')
|
|
34
|
+
depth++;
|
|
35
|
+
else if (char === ']' || char === ')')
|
|
36
|
+
depth--;
|
|
37
|
+
else if (depth === 0 && isSeparator(char)) {
|
|
38
|
+
parts.push(current);
|
|
39
|
+
current = '';
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
current += char;
|
|
43
|
+
}
|
|
44
|
+
parts.push(current);
|
|
45
|
+
return parts.map((part) => part.trim()).filter((part) => part !== '');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The tags a CSS selector names: the tag of the last compound in each comma-separated alternative.
|
|
49
|
+
*
|
|
50
|
+
* @param selector A CSS selector, possibly with `%s` placeholders.
|
|
51
|
+
*/
|
|
52
|
+
export function selectorTags(selector) {
|
|
53
|
+
const tags = new Set();
|
|
54
|
+
for (const alternative of splitTopLevel(selector, (char) => char === ',')) {
|
|
55
|
+
const compounds = splitTopLevel(alternative, (char) => /[\s>+~]/.test(char));
|
|
56
|
+
const tag = /^[a-zA-Z][\w-]*/.exec(compounds.at(-1) ?? '')?.[0];
|
|
57
|
+
if (tag)
|
|
58
|
+
tags.add(tag.toLowerCase());
|
|
59
|
+
}
|
|
60
|
+
return [...tags];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The last compound of each comma-separated alternative: what the element itself must match.
|
|
64
|
+
*
|
|
65
|
+
* @param selector A CSS selector.
|
|
66
|
+
*/
|
|
67
|
+
export function selectorLastParts(selector) {
|
|
68
|
+
return splitTopLevel(selector, (char) => char === ',')
|
|
69
|
+
.map((alternative) => splitTopLevel(alternative, (char) => /[\s>+~]/.test(char)).at(-1) ?? '')
|
|
70
|
+
.filter((part) => part !== '');
|
|
71
|
+
}
|
|
72
|
+
function camelCase(value) {
|
|
73
|
+
return value.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase());
|
|
74
|
+
}
|
|
75
|
+
function readText(file) {
|
|
76
|
+
try {
|
|
77
|
+
return fs.readFileSync(file, 'utf8');
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function parseJson(text) {
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(text);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function readJson(file) {
|
|
92
|
+
const text = readText(file);
|
|
93
|
+
return text === undefined ? undefined : parseJson(text);
|
|
94
|
+
}
|
|
95
|
+
/** The element names a method's `compose` statements use on its own page object. */
|
|
96
|
+
function composeElements(statements, out) {
|
|
97
|
+
if (Array.isArray(statements)) {
|
|
98
|
+
for (const item of statements)
|
|
99
|
+
composeElements(item, out);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!statements || typeof statements !== 'object')
|
|
103
|
+
return;
|
|
104
|
+
const statement = statements;
|
|
105
|
+
// A chained statement's element belongs to the page object the previous statement returned.
|
|
106
|
+
if (typeof statement.element === 'string' && statement.chain !== true)
|
|
107
|
+
out.add(statement.element);
|
|
108
|
+
// An `elementReference` argument passes one of this page object's elements, so the method uses it.
|
|
109
|
+
if (statement.type === 'elementReference' && typeof statement.value === 'string')
|
|
110
|
+
out.add(statement.value);
|
|
111
|
+
for (const value of Object.values(statement))
|
|
112
|
+
if (typeof value === 'object')
|
|
113
|
+
composeElements(value, out);
|
|
114
|
+
}
|
|
115
|
+
/** Named arguments, in order, without repeats; literal values aren't parameters. */
|
|
116
|
+
function mergeArgs(...lists) {
|
|
117
|
+
const out = [];
|
|
118
|
+
for (const list of lists) {
|
|
119
|
+
for (const arg of list ?? []) {
|
|
120
|
+
if (!arg.name || ('value' in arg && arg.value !== undefined) || out.some((item) => item.name === arg.name))
|
|
121
|
+
continue;
|
|
122
|
+
out.push({ name: arg.name, type: arg.type ?? 'unknown' });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A method's parameters: its own `args`, then its statements' (an `applyExternal` call's included),
|
|
129
|
+
* then the selector arguments of the elements it uses.
|
|
130
|
+
*/
|
|
131
|
+
function methodArgs(own, composeList, used, elements) {
|
|
132
|
+
const named = (args) => Array.isArray(args)
|
|
133
|
+
? args.filter((arg) => typeof arg?.type === 'string' && arg.type !== 'function')
|
|
134
|
+
: [];
|
|
135
|
+
const statementArgs = composeList.flatMap((statement) => {
|
|
136
|
+
const { args, applyExternal } = (statement ?? {});
|
|
137
|
+
return [...named(args), ...named(applyExternal?.args)];
|
|
138
|
+
});
|
|
139
|
+
const elementArgs = elements
|
|
140
|
+
.filter((element) => used.has(element.name.split('.').at(-1) ?? ''))
|
|
141
|
+
.map((element) => element.args);
|
|
142
|
+
return mergeArgs(own, statementArgs, ...elementArgs);
|
|
143
|
+
}
|
|
144
|
+
function describe(description) {
|
|
145
|
+
let lines = [];
|
|
146
|
+
if (typeof description === 'string')
|
|
147
|
+
lines = [description];
|
|
148
|
+
else if (Array.isArray(description?.text))
|
|
149
|
+
lines = description.text;
|
|
150
|
+
const text = lines
|
|
151
|
+
.filter((line) => typeof line === 'string')
|
|
152
|
+
.join(' ')
|
|
153
|
+
.replace(/\s+/g, ' ')
|
|
154
|
+
.trim();
|
|
155
|
+
return text === '' ? undefined : text;
|
|
156
|
+
}
|
|
157
|
+
/** What a method returns, when its JSON says: a return type, an element it ends on, or its description. */
|
|
158
|
+
function methodReturns(method, composeList, elements) {
|
|
159
|
+
let last = composeList.at(-1);
|
|
160
|
+
if (method.returnType)
|
|
161
|
+
return method.returnType;
|
|
162
|
+
if (typeof last?.returnType === 'string')
|
|
163
|
+
return last.returnType;
|
|
164
|
+
// `waitFor` with a predicate that ends on an element returns that element.
|
|
165
|
+
if (last?.apply === 'waitFor')
|
|
166
|
+
last = last.args?.[0]?.predicate?.at(-1);
|
|
167
|
+
if (last?.element && !last.apply && !last.chain) {
|
|
168
|
+
const element = elements.find((item) => item.name.split('.').at(-1) === last.element);
|
|
169
|
+
if (element?.type?.includes('/'))
|
|
170
|
+
return element.type;
|
|
171
|
+
}
|
|
172
|
+
const described = method.description?.return;
|
|
173
|
+
return typeof described === 'string' ? /\(([\w-]+\/pageObjects\/\w+)\)/.exec(described)?.[1] : undefined;
|
|
174
|
+
}
|
|
175
|
+
/** A statement or matcher argument in short form: a parameter's name, or a literal value. */
|
|
176
|
+
function argText(arg) {
|
|
177
|
+
if (!arg || typeof arg !== 'object')
|
|
178
|
+
return undefined;
|
|
179
|
+
const { name, type, value } = arg;
|
|
180
|
+
if (typeof name === 'string')
|
|
181
|
+
return name;
|
|
182
|
+
if (type === 'pageObject' || type === 'rootPageObject')
|
|
183
|
+
return String(value).split('/').at(-1);
|
|
184
|
+
if (type === 'elementReference')
|
|
185
|
+
return String(value);
|
|
186
|
+
if (typeof value === 'string')
|
|
187
|
+
return `"${value.replace(/^"|"$/g, '')}"`;
|
|
188
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
189
|
+
return String(value);
|
|
190
|
+
const css = value?.css;
|
|
191
|
+
return typeof css === 'string' ? `"${css}"` : undefined;
|
|
192
|
+
}
|
|
193
|
+
function argList(args) {
|
|
194
|
+
return Array.isArray(args) ? args.map(argText).filter((text) => text !== undefined) : [];
|
|
195
|
+
}
|
|
196
|
+
/** Every element a nested statement list names, such as a `waitFor` predicate's. */
|
|
197
|
+
function namedElements(value, out) {
|
|
198
|
+
if (Array.isArray(value))
|
|
199
|
+
for (const item of value)
|
|
200
|
+
namedElements(item, out);
|
|
201
|
+
else if (value && typeof value === 'object') {
|
|
202
|
+
const element = value.element;
|
|
203
|
+
if (typeof element === 'string')
|
|
204
|
+
out.add(element);
|
|
205
|
+
for (const child of Object.values(value))
|
|
206
|
+
if (typeof child === 'object')
|
|
207
|
+
namedElements(child, out);
|
|
208
|
+
}
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
211
|
+
function composePiece(raw) {
|
|
212
|
+
const statement = (raw && typeof raw === 'object' ? raw : {});
|
|
213
|
+
const piece = { chain: statement.chain === true, verbs: [] };
|
|
214
|
+
if (typeof statement.element === 'string')
|
|
215
|
+
piece.element = statement.element;
|
|
216
|
+
const external = statement.applyExternal;
|
|
217
|
+
if (external && typeof external === 'object') {
|
|
218
|
+
const utility = typeof external.type === 'string' ? `${external.type.split('/').at(-1) ?? ''}.` : '';
|
|
219
|
+
piece.verbs.push(`${utility}${String(external.invoke)}(${argList(external.args).join(', ')})`);
|
|
220
|
+
}
|
|
221
|
+
const { apply } = statement;
|
|
222
|
+
if (apply === 'waitFor') {
|
|
223
|
+
// A predicate is its own statement list; the elements it names say what's waited for.
|
|
224
|
+
piece.verbs.push(`waitFor(${[...namedElements(statement.args, new Set())].join(', ')})`);
|
|
225
|
+
}
|
|
226
|
+
else if (apply === 'returnSelf') {
|
|
227
|
+
piece.verbs.push('returns self');
|
|
228
|
+
}
|
|
229
|
+
else if (typeof apply === 'string') {
|
|
230
|
+
const args = argList(statement.args);
|
|
231
|
+
// Without an element, `apply` calls a method: this page object's, or the chained one's.
|
|
232
|
+
piece.verbs.push(args.length > 0 || !piece.element ? `${apply}(${args.join(', ')})` : apply);
|
|
233
|
+
}
|
|
234
|
+
const matcher = statement.matcher;
|
|
235
|
+
if (matcher && typeof matcher.type === 'string') {
|
|
236
|
+
const args = argList(matcher.args);
|
|
237
|
+
piece.matcher = `${matcher.type}${args.length > 0 ? `(${args.join(', ')})` : ''}`;
|
|
238
|
+
}
|
|
239
|
+
return piece;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* A method's `compose` in one line: each statement's `apply` (or `returns` when it only names an
|
|
243
|
+
* element) on the element, with the element's selector when it's one of this page object's.
|
|
244
|
+
* Chained statements act on the previous statement's return value, written `→ chain …`.
|
|
245
|
+
*/
|
|
246
|
+
function summarizeCompose(composeList, elements) {
|
|
247
|
+
try {
|
|
248
|
+
const pieces = [];
|
|
249
|
+
for (const statement of composeList) {
|
|
250
|
+
const piece = composePiece(statement);
|
|
251
|
+
const previous = pieces.at(-1);
|
|
252
|
+
// Statements in a row on the same element read as one: `scrollToCenter, click on tab`.
|
|
253
|
+
if (previous &&
|
|
254
|
+
!piece.chain &&
|
|
255
|
+
!previous.chain &&
|
|
256
|
+
piece.element &&
|
|
257
|
+
previous.element === piece.element &&
|
|
258
|
+
piece.verbs.length > 0 &&
|
|
259
|
+
previous.verbs.length > 0 &&
|
|
260
|
+
!previous.matcher) {
|
|
261
|
+
previous.verbs.push(...piece.verbs);
|
|
262
|
+
previous.matcher = piece.matcher;
|
|
263
|
+
}
|
|
264
|
+
else
|
|
265
|
+
pieces.push(piece);
|
|
266
|
+
}
|
|
267
|
+
const shown = new Set();
|
|
268
|
+
const target = (name) => {
|
|
269
|
+
const element = elements.find((item) => item.name.split('.').at(-1) === name);
|
|
270
|
+
if (!element || shown.has(name))
|
|
271
|
+
return name;
|
|
272
|
+
shown.add(name);
|
|
273
|
+
return `${name} "${element.selector}"`;
|
|
274
|
+
};
|
|
275
|
+
const parts = pieces.map((piece, i) => {
|
|
276
|
+
// A chained element belongs to the page object the previous statement returned.
|
|
277
|
+
const on = piece.element ? (piece.chain ? piece.element : target(piece.element)) : undefined;
|
|
278
|
+
let text;
|
|
279
|
+
if (piece.verbs.length > 0)
|
|
280
|
+
text = `${piece.verbs.join(', ')}${on ? ` on ${on}` : ''}`;
|
|
281
|
+
else if (piece.chain || piece.matcher || pieces[i + 1]?.chain)
|
|
282
|
+
text = on ?? '?';
|
|
283
|
+
else
|
|
284
|
+
text = `returns ${on ?? '?'}`;
|
|
285
|
+
if (piece.matcher)
|
|
286
|
+
text += ` is ${piece.matcher}`;
|
|
287
|
+
return i === 0 ? text : `${piece.chain ? ' → chain ' : '; '}${text}`;
|
|
288
|
+
});
|
|
289
|
+
const line = parts.join('');
|
|
290
|
+
if (line === '')
|
|
291
|
+
return undefined;
|
|
292
|
+
return line;
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/** A public element's getter finds every element it's nested in first, so it uses them too. */
|
|
299
|
+
function addGetterUse(publicElements, privateElements) {
|
|
300
|
+
for (const element of publicElements) {
|
|
301
|
+
const last = element.name.split('.').at(-1) ?? element.name;
|
|
302
|
+
const title = `${last[0].toUpperCase()}${last.slice(1)}`;
|
|
303
|
+
const getters = [`get${title}`, ...(element.wait ? [`waitFor${title}`] : [])];
|
|
304
|
+
for (const outer of privateElements)
|
|
305
|
+
if (element.name.startsWith(`${outer.name}.`))
|
|
306
|
+
(outer.usedBy ??= []).push(...getters);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function readEntry(json, base) {
|
|
310
|
+
const publicElements = [];
|
|
311
|
+
const privateElements = [];
|
|
312
|
+
function walk(elements, scope, prefix, parentArgs) {
|
|
313
|
+
for (const element of elements ?? []) {
|
|
314
|
+
const selector = element.selector?.css;
|
|
315
|
+
const name = prefix + element.name;
|
|
316
|
+
const args = mergeArgs(parentArgs, element.selector?.args);
|
|
317
|
+
if (selector !== undefined) {
|
|
318
|
+
const item = {
|
|
319
|
+
name,
|
|
320
|
+
selector,
|
|
321
|
+
tags: selectorTags(selector),
|
|
322
|
+
lastParts: selectorLastParts(selector),
|
|
323
|
+
scope,
|
|
324
|
+
};
|
|
325
|
+
if (args.length > 0)
|
|
326
|
+
item.args = args;
|
|
327
|
+
if (element.type !== undefined)
|
|
328
|
+
item.type = typeof element.type === 'string' ? element.type : JSON.stringify(element.type);
|
|
329
|
+
if (element.selector?.returnAll)
|
|
330
|
+
item.list = true;
|
|
331
|
+
if (element.wait)
|
|
332
|
+
item.wait = true;
|
|
333
|
+
(element.public ? publicElements : privateElements).push(item);
|
|
334
|
+
}
|
|
335
|
+
walk(element.elements, 'light', `${name}.`, args);
|
|
336
|
+
walk(element.shadow?.elements, 'shadow', `${name}.`, args);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
walk(json.elements, 'light', '', []);
|
|
340
|
+
walk(json.shadow?.elements, 'shadow', '', []);
|
|
341
|
+
const allElements = [...publicElements, ...privateElements];
|
|
342
|
+
const methods = [];
|
|
343
|
+
for (const method of json.methods ?? []) {
|
|
344
|
+
const composeList = Array.isArray(method.compose) ? method.compose : [];
|
|
345
|
+
const returns = methodReturns(method, composeList, allElements);
|
|
346
|
+
const used = new Set();
|
|
347
|
+
composeElements(composeList, used);
|
|
348
|
+
const args = methodArgs(method.args, composeList, used, allElements);
|
|
349
|
+
const compose = summarizeCompose(composeList, allElements);
|
|
350
|
+
methods.push({
|
|
351
|
+
name: method.name,
|
|
352
|
+
...(returns ? { returns } : {}),
|
|
353
|
+
...(args.length > 0 ? { args } : {}),
|
|
354
|
+
...(compose ? { compose } : {}),
|
|
355
|
+
});
|
|
356
|
+
for (const element of privateElements) {
|
|
357
|
+
// `compose` names an element by its own name, even when it's nested in another; a method that
|
|
358
|
+
// uses an element nested in this one uses this one too.
|
|
359
|
+
const usesIt = allElements.some((other) => (other === element || other.name.startsWith(`${element.name}.`)) &&
|
|
360
|
+
used.has(other.name.split('.').at(-1) ?? other.name));
|
|
361
|
+
if (usesIt)
|
|
362
|
+
(element.usedBy ??= []).push(method.name);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
addGetterUse(publicElements, privateElements);
|
|
366
|
+
const description = describe(json.description);
|
|
367
|
+
return {
|
|
368
|
+
...base,
|
|
369
|
+
root: json.root === true,
|
|
370
|
+
interface: json.interface === true,
|
|
371
|
+
...(json.implements ? { implements: json.implements } : {}),
|
|
372
|
+
...(json.root && json.selector?.css ? { selector: json.selector.css } : {}),
|
|
373
|
+
...(description ? { description } : {}),
|
|
374
|
+
publicElements,
|
|
375
|
+
privateElements,
|
|
376
|
+
methods,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function globFiles(rootDir, masks) {
|
|
380
|
+
const files = new Set();
|
|
381
|
+
for (const mask of masks) {
|
|
382
|
+
for (const file of fs.globSync(mask, { cwd: rootDir, exclude: (name) => name === 'node_modules' })) {
|
|
383
|
+
files.add(path.join(rootDir, file));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return [...files].sort();
|
|
387
|
+
}
|
|
388
|
+
function addEntry(index, entry) {
|
|
389
|
+
index.entries.set(entry.name, entry);
|
|
390
|
+
index.aliases.set(entry.name, entry.name);
|
|
391
|
+
if (entry.importPath)
|
|
392
|
+
index.aliases.set(entry.importPath, entry.name);
|
|
393
|
+
}
|
|
394
|
+
/** The conditions an `import` from test code matches in an `exports` map; `default` always matches. */
|
|
395
|
+
const IMPORT_CONDITIONS = new Set(['import', 'node', 'default']);
|
|
396
|
+
/**
|
|
397
|
+
* Whether test code in the project can import `specifier`: `require` resolves it, or, for a package
|
|
398
|
+
* that maps it only under conditions `require` doesn't match (`import`), its `exports` map does and
|
|
399
|
+
* the file it maps to exists.
|
|
400
|
+
*/
|
|
401
|
+
function importable(projectDir) {
|
|
402
|
+
const require = createRequire(path.join(projectDir, 'package.json'));
|
|
403
|
+
return (specifier) => {
|
|
404
|
+
try {
|
|
405
|
+
require.resolve(specifier);
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
return importsThroughExports(projectDir, specifier);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
/** Whether `specifier`'s package maps it, under the import conditions, to a file that exists. */
|
|
414
|
+
function importsThroughExports(projectDir, specifier) {
|
|
415
|
+
const name = packageOf(specifier);
|
|
416
|
+
if (!name || specifier === name)
|
|
417
|
+
return false;
|
|
418
|
+
const dir = packageDir(projectDir, name);
|
|
419
|
+
if (!dir)
|
|
420
|
+
return false;
|
|
421
|
+
const exportsField = readJson(path.join(dir, 'package.json'))?.exports;
|
|
422
|
+
const target = exportsTarget(exportsField, `.${specifier.slice(name.length)}`);
|
|
423
|
+
return target?.startsWith('./') === true && fs.existsSync(path.join(dir, target));
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* The string an `exports` target picks under the import conditions: a string as it is, the first
|
|
427
|
+
* match in a fallback array, or the first key of a conditions object that's one of the conditions,
|
|
428
|
+
* nested conditions followed.
|
|
429
|
+
*/
|
|
430
|
+
function conditionalTarget(target) {
|
|
431
|
+
if (typeof target === 'string')
|
|
432
|
+
return target;
|
|
433
|
+
if (Array.isArray(target)) {
|
|
434
|
+
for (const item of target) {
|
|
435
|
+
const resolved = conditionalTarget(item);
|
|
436
|
+
if (resolved !== undefined)
|
|
437
|
+
return resolved;
|
|
438
|
+
}
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
441
|
+
if (!target || typeof target !== 'object')
|
|
442
|
+
return undefined;
|
|
443
|
+
for (const [condition, value] of Object.entries(target)) {
|
|
444
|
+
if (!IMPORT_CONDITIONS.has(condition))
|
|
445
|
+
continue;
|
|
446
|
+
const resolved = conditionalTarget(value);
|
|
447
|
+
if (resolved !== undefined)
|
|
448
|
+
return resolved;
|
|
449
|
+
}
|
|
450
|
+
return undefined;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* The file a subpath maps to through `exports`, matched as Node matches it for an `import`: the exact
|
|
454
|
+
* key, else the `*` pattern with the longest prefix, its target picked under the `import`, `node` and
|
|
455
|
+
* `default` conditions.
|
|
456
|
+
*/
|
|
457
|
+
function exportsTarget(exportsField, subpath) {
|
|
458
|
+
if (!exportsField || typeof exportsField !== 'object' || Array.isArray(exportsField))
|
|
459
|
+
return undefined;
|
|
460
|
+
const map = exportsField;
|
|
461
|
+
if (subpath in map)
|
|
462
|
+
return conditionalTarget(map[subpath]);
|
|
463
|
+
const pattern = Object.keys(map)
|
|
464
|
+
.filter((key) => {
|
|
465
|
+
const [before, after, extra] = key.split('*');
|
|
466
|
+
return (after !== undefined &&
|
|
467
|
+
extra === undefined &&
|
|
468
|
+
subpath.length > before.length + after.length &&
|
|
469
|
+
subpath.startsWith(before) &&
|
|
470
|
+
subpath.endsWith(after));
|
|
471
|
+
})
|
|
472
|
+
.sort((a, b) => b.indexOf('*') - a.indexOf('*'))[0];
|
|
473
|
+
const target = pattern === undefined ? undefined : conditionalTarget(map[pattern]);
|
|
474
|
+
if (target === undefined)
|
|
475
|
+
return undefined;
|
|
476
|
+
const [before, after] = pattern.split('*');
|
|
477
|
+
return target.replaceAll('*', subpath.slice(before.length, subpath.length - after.length));
|
|
478
|
+
}
|
|
479
|
+
/** Whether the project's package.json `exports` maps `importPath` to the compiled `outputFile`. */
|
|
480
|
+
function exportedAs(packageJson, importPath, outputFile) {
|
|
481
|
+
const name = packageJson?.name;
|
|
482
|
+
if (!name || !importPath.startsWith(`${name}/`))
|
|
483
|
+
return false;
|
|
484
|
+
const target = exportsTarget(packageJson.exports, `./${importPath.slice(name.length + 1)}`);
|
|
485
|
+
return target !== undefined && path.posix.normalize(target) === path.posix.normalize(outputFile);
|
|
486
|
+
}
|
|
487
|
+
/** An import prefix and a page object's name, joined the way `rewrite` and the generator write them. */
|
|
488
|
+
function joinPrefix(prefix, name) {
|
|
489
|
+
return prefix.endsWith('/') ? `${prefix}${name}` : `${prefix}/${name}`;
|
|
490
|
+
}
|
|
491
|
+
/** Register `name` as another name for `entryName`, unless it already names a page object. */
|
|
492
|
+
function addAlias(index, name, entryName) {
|
|
493
|
+
if (!index.aliases.has(name))
|
|
494
|
+
index.aliases.set(name, entryName);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* A package with `dist/utam.manifest.json`, read by manifest name. The import path is the source's
|
|
498
|
+
* folder under `dist/`, then `pageObjects/`, then its name, kept only when it resolves.
|
|
499
|
+
*/
|
|
500
|
+
function indexManifestPackage(index, pkg, manifest, resolves) {
|
|
501
|
+
for (const [name, source] of Object.entries(manifest)) {
|
|
502
|
+
const relative = source.replace(/^package\//, '');
|
|
503
|
+
const file = path.join(pkg.dir, relative);
|
|
504
|
+
const json = readJson(file);
|
|
505
|
+
if (!json)
|
|
506
|
+
continue;
|
|
507
|
+
const underDist = path.posix.relative('dist', relative);
|
|
508
|
+
const candidate = `${pkg.name}/${path.posix.dirname(underDist)}/pageObjects/${path.posix.basename(underDist, '.utam.json')}`;
|
|
509
|
+
const importPath = resolves(candidate) ? candidate : undefined;
|
|
510
|
+
addEntry(index, readEntry(json, { name, ...(importPath ? { importPath } : {}), source: pkg.name, file }));
|
|
511
|
+
if (!importPath)
|
|
512
|
+
addAlias(index, candidate, name);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/** `value` with the namespace map applied, longest prefix first, as `rewrite` applies it. */
|
|
516
|
+
function rewritten(value, namespaceMap) {
|
|
517
|
+
const mapping = namespaceMap.find(([from]) => value.startsWith(from));
|
|
518
|
+
return mapping ? `${mapping[1]}${value.slice(mapping[0].length)}` : undefined;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* A package without a manifest: every `.utam.json` in it, wherever its sources sit. Each one's import
|
|
522
|
+
* path is a prefix that names the package plus the file's name, or what the namespace map rewrites
|
|
523
|
+
* the project's import path for that name to, kept only when it resolves. A source whose import path
|
|
524
|
+
* doesn't resolve is still indexed, named by its file.
|
|
525
|
+
*/
|
|
526
|
+
function indexSourcesPackage(index, pkg, config, resolves) {
|
|
527
|
+
const seen = new Set();
|
|
528
|
+
let count = 0;
|
|
529
|
+
for (const file of globFiles(pkg.dir, ['**/*.utam.json'])) {
|
|
530
|
+
const text = readText(file);
|
|
531
|
+
const json = text === undefined ? undefined : parseJson(text);
|
|
532
|
+
// A package that ships its sources twice (`src/` and `dist/`) is indexed once.
|
|
533
|
+
if (!json || seen.has(text))
|
|
534
|
+
continue;
|
|
535
|
+
seen.add(text);
|
|
536
|
+
count++;
|
|
537
|
+
const base = path.basename(file, '.utam.json');
|
|
538
|
+
const viaMap = rewritten(`${config.projectPrefix}${base}`, config.namespaceMap);
|
|
539
|
+
const candidates = [
|
|
540
|
+
...new Set([
|
|
541
|
+
...pkg.prefixes.map((prefix) => joinPrefix(prefix, base)),
|
|
542
|
+
...(viaMap?.startsWith(`${pkg.name}/`) ? [viaMap] : []),
|
|
543
|
+
]),
|
|
544
|
+
];
|
|
545
|
+
const importPath = candidates.find((candidate) => !index.entries.has(candidate) && resolves(candidate));
|
|
546
|
+
const name = importPath ?? `${pkg.name}/${path.relative(pkg.dir, file).split(path.sep).join('/')}`;
|
|
547
|
+
addEntry(index, readEntry(json, { name, ...(importPath ? { importPath } : {}), source: pkg.name, file }));
|
|
548
|
+
if (!importPath)
|
|
549
|
+
for (const candidate of candidates)
|
|
550
|
+
addAlias(index, candidate, name);
|
|
551
|
+
}
|
|
552
|
+
return count;
|
|
553
|
+
}
|
|
554
|
+
/** One page-object package, in whichever layout it ships. */
|
|
555
|
+
function indexPackage(index, projectDir, config, pkg) {
|
|
556
|
+
const resolves = importable(projectDir);
|
|
557
|
+
const manifest = readJson(path.join(pkg.dir, 'dist', 'utam.manifest.json'))?.pageObjects;
|
|
558
|
+
if (manifest) {
|
|
559
|
+
indexManifestPackage(index, pkg, manifest, resolves);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (indexSourcesPackage(index, pkg, config, resolves) === 0)
|
|
563
|
+
index.warnings.push(`${pkg.name} has no readable .utam.json page objects; it isn't indexed.`);
|
|
564
|
+
}
|
|
565
|
+
/** The project's own page objects, from `utam.config.json` and the generator's `namespaces`. */
|
|
566
|
+
function indexProjectPageObjects(index, projectDir, config) {
|
|
567
|
+
const utamConfig = readJson(path.join(projectDir, 'utam.config.json'));
|
|
568
|
+
if (!utamConfig)
|
|
569
|
+
return;
|
|
570
|
+
const rootDir = path.resolve(projectDir, utamConfig.pageObjectsRootDir ?? '.');
|
|
571
|
+
const outputDir = utamConfig.pageObjectsOutputDir ?? 'pageObjects';
|
|
572
|
+
const packageJson = readJson(path.join(projectDir, 'package.json'));
|
|
573
|
+
for (const file of globFiles(rootDir, utamConfig.pageObjectsFileMask ?? ['**/__utam__/**/*.utam.json'])) {
|
|
574
|
+
const json = readJson(file);
|
|
575
|
+
if (!json) {
|
|
576
|
+
index.warnings.push(`Skipped ${path.relative(projectDir, file)}: not valid JSON.`);
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
const base = path.basename(file, '.utam.json');
|
|
580
|
+
const importPath = `${config.projectPrefix}${base}`;
|
|
581
|
+
const outputFile = path.posix.join(outputDir, `${base}.js`);
|
|
582
|
+
addEntry(index, readEntry(json, {
|
|
583
|
+
name: importPath,
|
|
584
|
+
importPath,
|
|
585
|
+
outputFile,
|
|
586
|
+
...(exportedAs(packageJson, importPath, outputFile) ? { exported: true } : {}),
|
|
587
|
+
source: 'project',
|
|
588
|
+
file,
|
|
589
|
+
}));
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Before the build's `rewrite` task runs, the project's sources still name a rewritten page object
|
|
594
|
+
* by its project prefix, so that name is registered for it too. The naming convention's candidates
|
|
595
|
+
* go through the same names.
|
|
596
|
+
*/
|
|
597
|
+
function addPreRewriteAliases(index, namespaceMap) {
|
|
598
|
+
for (const [alias, entryName] of [...index.aliases]) {
|
|
599
|
+
for (const [from, to] of namespaceMap) {
|
|
600
|
+
if (alias.startsWith(to))
|
|
601
|
+
addAlias(index, `${from}${alias.slice(to.length)}`, entryName);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/** Interfaces list their implementations; tags come from root selectors and typed elements. */
|
|
606
|
+
function linkEntries(index) {
|
|
607
|
+
for (const entry of index.entries.values()) {
|
|
608
|
+
if (!entry.implements)
|
|
609
|
+
continue;
|
|
610
|
+
const iface = index.entries.get(index.aliases.get(entry.implements) ?? entry.implements);
|
|
611
|
+
if (iface)
|
|
612
|
+
(iface.implementations ??= []).push(entry.name);
|
|
613
|
+
}
|
|
614
|
+
const addTag = (tag, value) => {
|
|
615
|
+
const list = index.tags.get(tag) ?? [];
|
|
616
|
+
list.push(value);
|
|
617
|
+
index.tags.set(tag, list);
|
|
618
|
+
};
|
|
619
|
+
for (const entry of index.entries.values()) {
|
|
620
|
+
if (entry.selector)
|
|
621
|
+
for (const tag of selectorTags(entry.selector))
|
|
622
|
+
addTag(tag, { name: entry.name, via: 'root selector' });
|
|
623
|
+
for (const element of [...entry.publicElements, ...entry.privateElements]) {
|
|
624
|
+
const target = element.type ? index.aliases.get(element.type) : undefined;
|
|
625
|
+
if (!target)
|
|
626
|
+
continue;
|
|
627
|
+
for (const tag of element.tags)
|
|
628
|
+
addTag(tag, { name: target, via: 'typed element', declaredBy: `${shortName(entry)}.${element.name}` });
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Index the project's own page objects, and the page-object packages its namespace configuration
|
|
634
|
+
* maps to, by the tags they cover.
|
|
635
|
+
*
|
|
636
|
+
* @param options Where the project is.
|
|
637
|
+
*/
|
|
638
|
+
export function buildPageObjectIndex(options = {}) {
|
|
639
|
+
const projectDir = path.resolve(options.projectDir ?? process.cwd());
|
|
640
|
+
const index = {
|
|
641
|
+
entries: new Map(),
|
|
642
|
+
aliases: new Map(),
|
|
643
|
+
tags: new Map(),
|
|
644
|
+
namespaces: {},
|
|
645
|
+
warnings: [],
|
|
646
|
+
};
|
|
647
|
+
const config = readNamespaceConfig(projectDir);
|
|
648
|
+
index.namespaces = config.namespaces;
|
|
649
|
+
const { packages, warnings } = discoverPageObjectPackages(projectDir, config);
|
|
650
|
+
index.warnings.push(...warnings);
|
|
651
|
+
for (const pkg of packages)
|
|
652
|
+
indexPackage(index, projectDir, config, pkg);
|
|
653
|
+
indexProjectPageObjects(index, projectDir, config);
|
|
654
|
+
addPreRewriteAliases(index, config.namespaceMap);
|
|
655
|
+
linkEntries(index);
|
|
656
|
+
return index;
|
|
657
|
+
}
|
|
658
|
+
/** A page object's last path segment, for compact output. */
|
|
659
|
+
export function shortName(entry) {
|
|
660
|
+
return (entry.importPath ?? entry.name).split('/').at(-1) ?? entry.name;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Resolve a page object by manifest name, import path, or its short name when that is unique.
|
|
664
|
+
*
|
|
665
|
+
* @param index The index.
|
|
666
|
+
* @param name Any of the names a page object goes by.
|
|
667
|
+
*/
|
|
668
|
+
export function resolvePageObject(index, name) {
|
|
669
|
+
const exact = index.aliases.get(name);
|
|
670
|
+
if (exact)
|
|
671
|
+
return [index.entries.get(exact)];
|
|
672
|
+
return [...index.entries.values()].filter((entry) => shortName(entry) === name);
|
|
673
|
+
}
|
|
674
|
+
/** What test code should use for an entry: the interface when it's an implementation. */
|
|
675
|
+
function preferInterface(index, entry) {
|
|
676
|
+
if (!entry.implements)
|
|
677
|
+
return { entry };
|
|
678
|
+
const iface = index.entries.get(index.aliases.get(entry.implements) ?? entry.implements);
|
|
679
|
+
return iface ? { entry: iface, implementation: entry.name } : { entry };
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* The page objects for a tag: by root selector, by typed element, or by naming convention. A query
|
|
683
|
+
* that isn't a tag (it has a `/`, or no `-`) is looked up as a page object's name, import path or
|
|
684
|
+
* short name.
|
|
685
|
+
*
|
|
686
|
+
* @param index The index.
|
|
687
|
+
* @param query A custom element's tag, or a page object's name.
|
|
688
|
+
*/
|
|
689
|
+
export function matchPageObjects(index, query) {
|
|
690
|
+
const isTag = query.includes('-') && !query.includes('/');
|
|
691
|
+
const matches = isTag ? matchTag(index, query) : [];
|
|
692
|
+
if (matches.length > 0 || isTag)
|
|
693
|
+
return matches;
|
|
694
|
+
return resolvePageObject(index, query).map((entry) => ({ entry, via: 'name' }));
|
|
695
|
+
}
|
|
696
|
+
/** `project` first, then each package in the order it was indexed. */
|
|
697
|
+
function sourceOrder(index) {
|
|
698
|
+
const order = new Map([['project', 0]]);
|
|
699
|
+
for (const entry of index.entries.values())
|
|
700
|
+
if (!order.has(entry.source))
|
|
701
|
+
order.set(entry.source, order.size);
|
|
702
|
+
return order;
|
|
703
|
+
}
|
|
704
|
+
function matchTag(index, tag) {
|
|
705
|
+
const matches = new Map();
|
|
706
|
+
for (const item of index.tags.get(tag.toLowerCase()) ?? []) {
|
|
707
|
+
const found = index.entries.get(item.name);
|
|
708
|
+
if (!found)
|
|
709
|
+
continue;
|
|
710
|
+
const { entry, implementation } = preferInterface(index, found);
|
|
711
|
+
const key = `${entry.name}|${item.via}`;
|
|
712
|
+
const existing = matches.get(key);
|
|
713
|
+
if (existing) {
|
|
714
|
+
if (item.declaredBy) {
|
|
715
|
+
existing.declaredByCount = (existing.declaredByCount ?? 0) + 1;
|
|
716
|
+
if ((existing.declaredBy ??= []).length < 3)
|
|
717
|
+
existing.declaredBy.push(item.declaredBy);
|
|
718
|
+
}
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
matches.set(key, {
|
|
722
|
+
entry,
|
|
723
|
+
via: item.via,
|
|
724
|
+
...(item.declaredBy ? { declaredBy: [item.declaredBy], declaredByCount: 1 } : {}),
|
|
725
|
+
...(implementation ? { matchedImplementation: implementation } : {}),
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
if (matches.size === 0) {
|
|
729
|
+
const [namespace, ...rest] = tag.toLowerCase().split('-');
|
|
730
|
+
const camel = camelCase(rest.join('-'));
|
|
731
|
+
const candidates = [`utam-${namespace}/pageObjects/${camel}`];
|
|
732
|
+
if (index.namespaces[namespace])
|
|
733
|
+
candidates.push(`${index.namespaces[namespace]}${camel}`);
|
|
734
|
+
for (const candidate of candidates) {
|
|
735
|
+
const name = index.aliases.get(candidate);
|
|
736
|
+
if (name) {
|
|
737
|
+
const { entry, implementation } = preferInterface(index, index.entries.get(name));
|
|
738
|
+
matches.set(entry.name, {
|
|
739
|
+
entry,
|
|
740
|
+
via: 'convention',
|
|
741
|
+
...(implementation ? { matchedImplementation: implementation } : {}),
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
// The project's own first, then packages in the order the configuration names them; within each,
|
|
747
|
+
// root selectors, then typed elements.
|
|
748
|
+
const order = sourceOrder(index);
|
|
749
|
+
const rank = (match) => (order.get(match.entry.source) ?? order.size) * 10 +
|
|
750
|
+
['root selector', 'typed element', 'convention'].indexOf(match.via);
|
|
751
|
+
return [...matches.values()].sort((a, b) => rank(a) - rank(b));
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Page objects whose name, import path, tags or description contain every word of `query`
|
|
755
|
+
* (case-insensitive). Name matches come first, then tag matches, then description matches.
|
|
756
|
+
*
|
|
757
|
+
* @param index The index.
|
|
758
|
+
* @param query One or more words.
|
|
759
|
+
*/
|
|
760
|
+
export function findPageObjects(index, query) {
|
|
761
|
+
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
762
|
+
const tagsByEntry = new Map();
|
|
763
|
+
for (const [tag, items] of index.tags) {
|
|
764
|
+
for (const item of items) {
|
|
765
|
+
const set = tagsByEntry.get(item.name) ?? new Set();
|
|
766
|
+
set.add(tag);
|
|
767
|
+
tagsByEntry.set(item.name, set);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
const scored = [];
|
|
771
|
+
for (const entry of index.entries.values()) {
|
|
772
|
+
const tags = [...(tagsByEntry.get(entry.name) ?? [])];
|
|
773
|
+
const names = `${entry.name} ${entry.importPath ?? ''}`.toLowerCase();
|
|
774
|
+
const tagText = tags.join(' ');
|
|
775
|
+
const description = (entry.description ?? '').toLowerCase();
|
|
776
|
+
let score = 0;
|
|
777
|
+
for (const word of words) {
|
|
778
|
+
if (names.includes(word))
|
|
779
|
+
score += 3;
|
|
780
|
+
else if (tagText.includes(word))
|
|
781
|
+
score += 2;
|
|
782
|
+
else if (description.includes(word))
|
|
783
|
+
score += 1;
|
|
784
|
+
else {
|
|
785
|
+
score = -1;
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (score > 0)
|
|
790
|
+
scored.push({ entry, tags, score });
|
|
791
|
+
}
|
|
792
|
+
return scored
|
|
793
|
+
.sort((a, b) => b.score - a.score || shortName(a.entry).localeCompare(shortName(b.entry)))
|
|
794
|
+
.map(({ entry, tags }) => ({ entry, tags }));
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Show a page object reference as test code would import it.
|
|
798
|
+
*
|
|
799
|
+
* @param index The index.
|
|
800
|
+
* @param name A manifest name or import path.
|
|
801
|
+
*/
|
|
802
|
+
export function displayName(index, name) {
|
|
803
|
+
const entry = index.entries.get(index.aliases.get(name) ?? '');
|
|
804
|
+
return entry?.importPath ?? name;
|
|
805
|
+
}
|
|
806
|
+
//# sourceMappingURL=page-object-index.js.map
|