layermap 0.1.29 → 0.1.31
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 +4 -3
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/analyzers/project-map-worker.mjs +187 -57
- package/dist/cli.mjs +507 -292
- package/package.json +1 -1
- package/pi/layermap.mjs +1 -1
package/README.md
CHANGED
|
@@ -30,8 +30,8 @@ with dozens of searches:
|
|
|
30
30
|
It maps **TypeScript, JavaScript, Go, Python and Java** with each language's own compiler, so calls
|
|
31
31
|
through interfaces, base classes, templates and decorators resolve as the compiler resolves them,
|
|
32
32
|
including the ones text search misses. In WeChat mini-programs, it also links each page's and
|
|
33
|
-
component's template (`.wxml`) to the methods it binds and the components it shows,
|
|
34
|
-
the pages.
|
|
33
|
+
component's template (`.wxml`) to the methods it binds and the components it shows, and each event a
|
|
34
|
+
component emits to the handlers the pages bind to it, so callers reach the pages.
|
|
35
35
|
|
|
36
36
|
## Example
|
|
37
37
|
|
|
@@ -206,7 +206,7 @@ nothing anywhere ([privacy](https://github.com/coffeecoproject/layermap/blob/mai
|
|
|
206
206
|
| `project_explore_map` | A directory, a file, or a declaration's callers and callees (`direction` INCOMING or OUTGOING, `depth` up to 8). |
|
|
207
207
|
| `project_search_map` | Find declarations by words in their names, paths or documentation. |
|
|
208
208
|
| `project_find_references` | Every usage of a declaration, compiled from current source. |
|
|
209
|
-
| `project_check_changes` | What the uncommitted changes (or those since `base`) affect: changed and removed declarations, the routes, jobs and commands they reach, the areas that share the changed code, environment variables and configuration keys it removed that other files still use, code and templates that request the affected routes, new dependencies between modules and the cycles they close, new code that repeats existing code, what to check by hand, and related tests. |
|
|
209
|
+
| `project_check_changes` | What the uncommitted changes (or those since `base`) affect: changed and removed declarations, the routes, jobs and commands they reach, the areas that share the changed code, environment variables and configuration keys it removed that other files still use, code and templates that request the affected routes, new dependencies between modules and the cycles they close, new code that repeats existing code, what to check by hand, and related tests. Given `tests`, also the changed code none of those test files calls or requests through a route, and the entry points above it. |
|
|
210
210
|
|
|
211
211
|
The same from the command line:
|
|
212
212
|
|
|
@@ -215,6 +215,7 @@ npx layermap explore src/api/users.ts --name createUser --direction INCOMING --d
|
|
|
215
215
|
npx layermap search "invoice total"
|
|
216
216
|
npx layermap refs src/billing/tax.ts calculateTax
|
|
217
217
|
npx layermap check --base main
|
|
218
|
+
npx layermap check test/billing.test.ts # also: what of the change this test does not run
|
|
218
219
|
```
|
|
219
220
|
|
|
220
221
|
## FAQ
|
|
Binary file
|
|
@@ -16069,32 +16069,81 @@ var propertyName = (member) => {
|
|
|
16069
16069
|
const name = member.name;
|
|
16070
16070
|
return name && (isIdentifier(name) || isStringLiteral(name)) ? name.text : void 0;
|
|
16071
16071
|
};
|
|
16072
|
-
function
|
|
16072
|
+
function registration(file2) {
|
|
16073
16073
|
for (const statement of file2.statements) {
|
|
16074
16074
|
if (!isExpressionStatement(statement)) continue;
|
|
16075
16075
|
const call = statement.expression;
|
|
16076
16076
|
if (!isCallExpression(call) || !isIdentifier(call.expression)) continue;
|
|
16077
|
-
const
|
|
16077
|
+
const kind = call.expression.text;
|
|
16078
16078
|
const options = call.arguments[0];
|
|
16079
|
-
if (
|
|
16080
|
-
|
|
16081
|
-
let members = options.properties;
|
|
16082
|
-
if (registration === "Component") {
|
|
16083
|
-
const methods = options.properties.find((member) => propertyName(member) === "methods");
|
|
16084
|
-
const value = methods && isPropertyAssignment(methods) ? methods.initializer : void 0;
|
|
16085
|
-
members = value && isObjectLiteralExpression(value) ? value.properties : [];
|
|
16086
|
-
}
|
|
16087
|
-
const found = /* @__PURE__ */ new Map();
|
|
16088
|
-
for (const member of members) {
|
|
16089
|
-
const name = propertyName(member);
|
|
16090
|
-
if (name !== void 0 && (isMethodDeclaration(member) || isPropertyAssignment(member)))
|
|
16091
|
-
found.set(name, member);
|
|
16092
|
-
}
|
|
16093
|
-
return found;
|
|
16079
|
+
if ((kind === "Page" || kind === "Component") && options && isObjectLiteralExpression(options))
|
|
16080
|
+
return { kind, options };
|
|
16094
16081
|
}
|
|
16095
16082
|
return void 0;
|
|
16096
16083
|
}
|
|
16084
|
+
function miniprogramMethods(file2) {
|
|
16085
|
+
const registered = registration(file2);
|
|
16086
|
+
if (!registered) return void 0;
|
|
16087
|
+
const { kind, options } = registered;
|
|
16088
|
+
let members = options.properties;
|
|
16089
|
+
if (kind === "Component") {
|
|
16090
|
+
const methods = options.properties.find((member) => propertyName(member) === "methods");
|
|
16091
|
+
const value = methods && isPropertyAssignment(methods) ? methods.initializer : void 0;
|
|
16092
|
+
members = value && isObjectLiteralExpression(value) ? value.properties : [];
|
|
16093
|
+
}
|
|
16094
|
+
const found = /* @__PURE__ */ new Map();
|
|
16095
|
+
for (const member of members) {
|
|
16096
|
+
const name = propertyName(member);
|
|
16097
|
+
if (name !== void 0 && (isMethodDeclaration(member) || isPropertyAssignment(member)))
|
|
16098
|
+
found.set(name, member);
|
|
16099
|
+
}
|
|
16100
|
+
return found;
|
|
16101
|
+
}
|
|
16102
|
+
var composedEvent = (options) => {
|
|
16103
|
+
if (!options) return false;
|
|
16104
|
+
if (!isObjectLiteralExpression(options)) return true;
|
|
16105
|
+
const composed = options.properties.find(
|
|
16106
|
+
(member) => propertyName(member) === "composed"
|
|
16107
|
+
);
|
|
16108
|
+
if (!composed) return false;
|
|
16109
|
+
return !(isPropertyAssignment(composed) && composed.initializer.kind === SyntaxKind.FalseKeyword);
|
|
16110
|
+
};
|
|
16111
|
+
function miniprogramEmits(file2) {
|
|
16112
|
+
const registered = registration(file2);
|
|
16113
|
+
if (registered?.kind !== "Component" || registered.options.properties.some((member) => propertyName(member) === "behaviors"))
|
|
16114
|
+
return void 0;
|
|
16115
|
+
const emits = [];
|
|
16116
|
+
let readable = true;
|
|
16117
|
+
const visit = (node) => {
|
|
16118
|
+
if (isCallExpression(node) && isPropertyAccessExpression(node.expression) && node.expression.name.text === "triggerEvent") {
|
|
16119
|
+
const [name, , options] = node.arguments;
|
|
16120
|
+
if (node.expression.expression.kind !== SyntaxKind.ThisKeyword || !name || node.arguments.some((argument) => argument.kind === SyntaxKind.SpreadElement))
|
|
16121
|
+
readable = false;
|
|
16122
|
+
else emits.push({ call: node, name, composed: composedEvent(options) });
|
|
16123
|
+
}
|
|
16124
|
+
node.forEachChild(visit);
|
|
16125
|
+
return void 0;
|
|
16126
|
+
};
|
|
16127
|
+
visit(file2);
|
|
16128
|
+
return readable ? emits : void 0;
|
|
16129
|
+
}
|
|
16130
|
+
var miniprogramEventTarget = (tag, event) => `<${tag}> ${event} event`;
|
|
16131
|
+
var NATIVE_EVENTS = /* @__PURE__ */ new Set([
|
|
16132
|
+
"touchstart",
|
|
16133
|
+
"touchmove",
|
|
16134
|
+
"touchcancel",
|
|
16135
|
+
"touchend",
|
|
16136
|
+
"touchforcechange",
|
|
16137
|
+
"tap",
|
|
16138
|
+
"longpress",
|
|
16139
|
+
"longtap",
|
|
16140
|
+
"transitionend",
|
|
16141
|
+
"animationstart",
|
|
16142
|
+
"animationiteration",
|
|
16143
|
+
"animationend"
|
|
16144
|
+
]);
|
|
16097
16145
|
var BINDING = /^(?:(?:capture-)?(?:bind|catch)|mut-bind):?[a-z][\w-]*$/iu;
|
|
16146
|
+
var BINDING_PREFIX = /^(?:(?:capture-)?(?:bind|catch)|mut-bind):?/iu;
|
|
16098
16147
|
var METHOD = /^[A-Za-z_$][\w$]*$/u;
|
|
16099
16148
|
var TAG = /<([A-Za-z][\w.:-]*)/uy;
|
|
16100
16149
|
var ATTRIBUTE = /\s*([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'<>]+)))?/uy;
|
|
@@ -16137,12 +16186,19 @@ function parseMiniprogramTemplate(text2) {
|
|
|
16137
16186
|
}
|
|
16138
16187
|
at = ATTRIBUTE.lastIndex;
|
|
16139
16188
|
const value = attribute[2] ?? attribute[3] ?? attribute[4];
|
|
16140
|
-
|
|
16189
|
+
const attributeName = attribute[1] ?? "";
|
|
16190
|
+
if (value === void 0 || !BINDING.test(attributeName)) continue;
|
|
16141
16191
|
const end = at - (attribute[4] === void 0 ? 1 : 0);
|
|
16142
16192
|
const start = end - value.length;
|
|
16143
16193
|
const method = value.trim();
|
|
16144
|
-
|
|
16145
|
-
|
|
16194
|
+
const binding = {
|
|
16195
|
+
event: attributeName.replace(BINDING_PREFIX, ""),
|
|
16196
|
+
tag: tags.length - 1,
|
|
16197
|
+
start,
|
|
16198
|
+
end
|
|
16199
|
+
};
|
|
16200
|
+
if (METHOD.test(method)) bindings.push({ ...binding, method });
|
|
16201
|
+
else if (method.includes("{{")) bindings.push(binding);
|
|
16146
16202
|
}
|
|
16147
16203
|
index = text2[at] === ">" ? at + 1 : at + 2;
|
|
16148
16204
|
if (name === "wxs" && text2[at] === ">") index = skip(index, "</wxs>");
|
|
@@ -16200,28 +16256,65 @@ function linkMiniprogramTemplates(scripts, context) {
|
|
|
16200
16256
|
links.objects.push(object2);
|
|
16201
16257
|
return object2;
|
|
16202
16258
|
};
|
|
16203
|
-
const owned = scripts.flatMap((
|
|
16204
|
-
const object2 = module2(template, "DEFAULT");
|
|
16205
|
-
return object2 ? [{
|
|
16259
|
+
const owned = scripts.flatMap((script) => {
|
|
16260
|
+
const object2 = module2(script.template, "DEFAULT");
|
|
16261
|
+
return object2 ? [{ ...script, object: object2 }] : [];
|
|
16206
16262
|
});
|
|
16263
|
+
const events = new Map(owned.map((script) => [script.template, script.events]));
|
|
16264
|
+
const emitted = /* @__PURE__ */ new Set();
|
|
16207
16265
|
for (const { template, methods, object: object2 } of owned) {
|
|
16208
16266
|
links.parsedFiles.push(template);
|
|
16209
16267
|
const parsed = parseMiniprogramTemplate(context.read(template) ?? "");
|
|
16268
|
+
const registered = /* @__PURE__ */ new Map();
|
|
16269
|
+
if (parsed.tags.length) {
|
|
16270
|
+
const { own, app, root } = miniprogramConfiguration(template, context.inventory);
|
|
16271
|
+
for (const file2 of [app, own])
|
|
16272
|
+
if (file2 !== void 0)
|
|
16273
|
+
for (const [tag, value] of Object.entries(usingComponents(context.read(file2))))
|
|
16274
|
+
registered.set(tag, componentTemplate(value, file2, root, context.inventory));
|
|
16275
|
+
}
|
|
16210
16276
|
let computed = 0;
|
|
16211
16277
|
for (const binding of parsed.bindings) {
|
|
16212
|
-
|
|
16213
|
-
|
|
16214
|
-
continue;
|
|
16215
|
-
}
|
|
16216
|
-
const method = methods.get(binding.method);
|
|
16278
|
+
const anchor = context.span(template, binding.start, binding.end);
|
|
16279
|
+
const method = binding.method === void 0 ? void 0 : methods.get(binding.method);
|
|
16217
16280
|
const target = method && context.materialize(method);
|
|
16218
|
-
|
|
16219
|
-
|
|
16220
|
-
|
|
16221
|
-
|
|
16222
|
-
|
|
16223
|
-
|
|
16224
|
-
|
|
16281
|
+
if (binding.method === void 0) computed++;
|
|
16282
|
+
else
|
|
16283
|
+
links.relations.push({
|
|
16284
|
+
from: object2.id,
|
|
16285
|
+
kind: "CALLS",
|
|
16286
|
+
anchor,
|
|
16287
|
+
target: binding.method,
|
|
16288
|
+
...target ? { to: target.id, basis: "SYNTAX_DECLARED" } : { basis: "UNRESOLVED", unresolvedReason: "SYMBOL_NOT_RESOLVED" }
|
|
16289
|
+
});
|
|
16290
|
+
const tag = parsed.tags[binding.tag]?.name;
|
|
16291
|
+
const component = tag === void 0 ? void 0 : registered.get(tag);
|
|
16292
|
+
const known = component === void 0 ? void 0 : events.get(component);
|
|
16293
|
+
if (tag === void 0 || !known) continue;
|
|
16294
|
+
const emits = known.get(binding.event);
|
|
16295
|
+
if (emits) {
|
|
16296
|
+
for (const emit of emits) {
|
|
16297
|
+
const link = `${emit.emitter.id}\0${target?.id}\0${emit.anchor.start}`;
|
|
16298
|
+
if (!target || emitted.has(link)) continue;
|
|
16299
|
+
emitted.add(link);
|
|
16300
|
+
links.relations.push({
|
|
16301
|
+
from: emit.emitter.id,
|
|
16302
|
+
to: target.id,
|
|
16303
|
+
kind: "CALLS",
|
|
16304
|
+
anchor: emit.anchor,
|
|
16305
|
+
target: target.name,
|
|
16306
|
+
basis: "SYNTAX_DECLARED"
|
|
16307
|
+
});
|
|
16308
|
+
}
|
|
16309
|
+
} else if (!NATIVE_EVENTS.has(binding.event) && context.composed && !context.composed.has(binding.event))
|
|
16310
|
+
links.relations.push({
|
|
16311
|
+
from: object2.id,
|
|
16312
|
+
kind: "CALLS",
|
|
16313
|
+
anchor,
|
|
16314
|
+
target: miniprogramEventTarget(tag, binding.event),
|
|
16315
|
+
basis: "UNRESOLVED",
|
|
16316
|
+
unresolvedReason: "SYMBOL_NOT_RESOLVED"
|
|
16317
|
+
});
|
|
16225
16318
|
}
|
|
16226
16319
|
if (computed)
|
|
16227
16320
|
links.gaps.push({
|
|
@@ -16229,13 +16322,6 @@ function linkMiniprogramTemplates(scripts, context) {
|
|
|
16229
16322
|
path: template,
|
|
16230
16323
|
count: computed
|
|
16231
16324
|
});
|
|
16232
|
-
if (!parsed.tags.length) continue;
|
|
16233
|
-
const { own, app, root } = miniprogramConfiguration(template, context.inventory);
|
|
16234
|
-
const registered = /* @__PURE__ */ new Map();
|
|
16235
|
-
for (const file2 of [app, own])
|
|
16236
|
-
if (file2 !== void 0)
|
|
16237
|
-
for (const [tag, value] of Object.entries(usingComponents(context.read(file2))))
|
|
16238
|
-
registered.set(tag, componentTemplate(value, file2, root, context.inventory));
|
|
16239
16325
|
for (const tag of parsed.tags) {
|
|
16240
16326
|
if (!registered.has(tag.name)) continue;
|
|
16241
16327
|
const component = registered.get(tag.name);
|
|
@@ -16404,9 +16490,9 @@ var httpMethod = (name) => HTTP_METHODS.has(name.toUpperCase()) ? name.toUpperCa
|
|
|
16404
16490
|
function registeredRoute(node, kind) {
|
|
16405
16491
|
for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent) {
|
|
16406
16492
|
if (isCallExpression(parent) && parent.arguments.includes(child)) {
|
|
16407
|
-
const
|
|
16408
|
-
const direct = child === node && (kind === "REFERENCES" ||
|
|
16409
|
-
if (
|
|
16493
|
+
const registration2 = routeOf(parent, parent.arguments.indexOf(child));
|
|
16494
|
+
const direct = child === node && (kind === "REFERENCES" || registration2?.method);
|
|
16495
|
+
if (registration2 && (isFunction(child) || direct)) return registration2.label;
|
|
16410
16496
|
}
|
|
16411
16497
|
if (isDeclaration(parent)) return void 0;
|
|
16412
16498
|
}
|
|
@@ -31692,19 +31778,63 @@ async function extractProjectMap(project, input, trace, read) {
|
|
|
31692
31778
|
return object2;
|
|
31693
31779
|
};
|
|
31694
31780
|
trace.phase = "MINIPROGRAM_TEMPLATES";
|
|
31695
|
-
const
|
|
31696
|
-
|
|
31697
|
-
|
|
31698
|
-
|
|
31699
|
-
|
|
31700
|
-
|
|
31701
|
-
|
|
31702
|
-
inventory,
|
|
31703
|
-
read,
|
|
31704
|
-
span: (path8, start, end) => positions.span(path8, start, end),
|
|
31705
|
-
materialize
|
|
31781
|
+
const enclosing = (node) => {
|
|
31782
|
+
for (let at = node.parent; at; at = at.parent) {
|
|
31783
|
+
if (at.kind === SyntaxKind.SourceFile) return declared.get(key(at));
|
|
31784
|
+
if (declared.has(key(at)) || mapDeclarationKind(at) && mapDeclarationName(at) || mapExecutionDeclaration(at)) {
|
|
31785
|
+
const object2 = materialize(at);
|
|
31786
|
+
if (object2) return object2;
|
|
31787
|
+
}
|
|
31706
31788
|
}
|
|
31707
|
-
|
|
31789
|
+
return void 0;
|
|
31790
|
+
};
|
|
31791
|
+
const scripts = pages.flatMap(({ file: file2, template }) => {
|
|
31792
|
+
const methods = miniprogramMethods(file2);
|
|
31793
|
+
return methods ? [{ file: file2, template, methods, emits: miniprogramEmits(file2) }] : [];
|
|
31794
|
+
});
|
|
31795
|
+
const emits = scripts.flatMap((script) => script.emits ?? []);
|
|
31796
|
+
const nameTypes = emits.length ? await project.checker.getTypeAtLocation(emits.map((emit) => emit.name)) : [];
|
|
31797
|
+
const names = /* @__PURE__ */ new Map();
|
|
31798
|
+
for (const [index, emit] of emits.entries()) {
|
|
31799
|
+
const type = nameTypes[index];
|
|
31800
|
+
const types = type?.isUnionType() ? await type.getTypes() ?? [] : type ? [type] : [];
|
|
31801
|
+
names.set(
|
|
31802
|
+
emit,
|
|
31803
|
+
types.length && types.every((each) => each.isStringLiteralType()) ? types.map((each) => each.value) : void 0
|
|
31804
|
+
);
|
|
31805
|
+
}
|
|
31806
|
+
let composed = /* @__PURE__ */ new Set();
|
|
31807
|
+
const linked = scripts.map(({ file: file2, template, methods, emits: calls }) => {
|
|
31808
|
+
if (!calls) return { template, methods };
|
|
31809
|
+
const events = /* @__PURE__ */ new Map();
|
|
31810
|
+
let readable = true;
|
|
31811
|
+
for (const emit of calls) {
|
|
31812
|
+
const emitted = names.get(emit);
|
|
31813
|
+
const emitter = enclosing(emit.call);
|
|
31814
|
+
if (!emitted || !emitter) {
|
|
31815
|
+
if (emit.composed) composed = void 0;
|
|
31816
|
+
readable = false;
|
|
31817
|
+
continue;
|
|
31818
|
+
}
|
|
31819
|
+
for (const event of emitted) {
|
|
31820
|
+
if (emit.composed) composed?.add(event);
|
|
31821
|
+
const known = events.get(event) ?? [];
|
|
31822
|
+
known.push({ emitter, anchor: anchor(emit.call, file2) });
|
|
31823
|
+
events.set(event, known);
|
|
31824
|
+
}
|
|
31825
|
+
}
|
|
31826
|
+
if (readable) return { template, methods, events };
|
|
31827
|
+
gap("MINIPROGRAM_COMPUTED_EVENT_NAMES", mapRelativePath(file2.fileName));
|
|
31828
|
+
return { template, methods };
|
|
31829
|
+
});
|
|
31830
|
+
const templates = linkMiniprogramTemplates(linked, {
|
|
31831
|
+
contextRef: input.contextRef,
|
|
31832
|
+
inventory,
|
|
31833
|
+
read,
|
|
31834
|
+
span: (path8, start, end) => positions.span(path8, start, end),
|
|
31835
|
+
materialize,
|
|
31836
|
+
composed
|
|
31837
|
+
});
|
|
31708
31838
|
for (const object2 of templates.objects) collect.object(object2);
|
|
31709
31839
|
for (const relation of templates.relations) collect.relation(relation);
|
|
31710
31840
|
output.gaps.push(...templates.gaps);
|