geopilot 0.0.0-stage → 0.0.1-bootstrap.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/LICENSE +202 -0
- package/README.md +72 -2
- package/dist/agent/install.d.ts +23 -0
- package/dist/agent/install.js +75 -0
- package/dist/agent/install.js.map +1 -0
- package/dist/cache/runs.d.ts +18 -0
- package/dist/cache/runs.js +91 -0
- package/dist/cache/runs.js.map +1 -0
- package/dist/cli/args.d.ts +20 -0
- package/dist/cli/args.js +116 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/commands/agent.d.ts +2 -0
- package/dist/cli/commands/agent.js +48 -0
- package/dist/cli/commands/agent.js.map +1 -0
- package/dist/cli/commands/fix.d.ts +2 -0
- package/dist/cli/commands/fix.js +284 -0
- package/dist/cli/commands/fix.js.map +1 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +62 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/insights.d.ts +17 -0
- package/dist/cli/commands/insights.js +143 -0
- package/dist/cli/commands/insights.js.map +1 -0
- package/dist/cli/commands/rules.d.ts +5 -0
- package/dist/cli/commands/rules.js +86 -0
- package/dist/cli/commands/rules.js.map +1 -0
- package/dist/cli/commands/scan.d.ts +14 -0
- package/dist/cli/commands/scan.js +127 -0
- package/dist/cli/commands/scan.js.map +1 -0
- package/dist/cli/commands-list.d.ts +6 -0
- package/dist/cli/commands-list.js +15 -0
- package/dist/cli/commands-list.js.map +1 -0
- package/dist/cli/context.d.ts +26 -0
- package/dist/cli/context.js +108 -0
- package/dist/cli/context.js.map +1 -0
- package/dist/cli/io.d.ts +16 -0
- package/dist/cli/io.js +28 -0
- package/dist/cli/io.js.map +1 -0
- package/dist/cli/main.d.ts +15 -0
- package/dist/cli/main.js +118 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/collect/crawl.d.ts +51 -0
- package/dist/collect/crawl.js +187 -0
- package/dist/collect/crawl.js.map +1 -0
- package/dist/config/config.d.ts +86 -0
- package/dist/config/config.js +396 -0
- package/dist/config/config.js.map +1 -0
- package/dist/core/errors.d.ts +20 -0
- package/dist/core/errors.js +32 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/hash.d.ts +7 -0
- package/dist/core/hash.js +28 -0
- package/dist/core/hash.js.map +1 -0
- package/dist/core/redact.d.ts +3 -0
- package/dist/core/redact.js +23 -0
- package/dist/core/redact.js.map +1 -0
- package/dist/core/tty.d.ts +12 -0
- package/dist/core/tty.js +33 -0
- package/dist/core/tty.js.map +1 -0
- package/dist/core/version.d.ts +6 -0
- package/dist/core/version.js +10 -0
- package/dist/core/version.js.map +1 -0
- package/dist/fix/apply.d.ts +119 -0
- package/dist/fix/apply.js +334 -0
- package/dist/fix/apply.js.map +1 -0
- package/dist/fix/diff.d.ts +1 -0
- package/dist/fix/diff.js +35 -0
- package/dist/fix/diff.js.map +1 -0
- package/dist/fix/plan.d.ts +42 -0
- package/dist/fix/plan.js +385 -0
- package/dist/fix/plan.js.map +1 -0
- package/dist/fix/serve.d.ts +13 -0
- package/dist/fix/serve.js +112 -0
- package/dist/fix/serve.js.map +1 -0
- package/dist/fix/variants.d.ts +13 -0
- package/dist/fix/variants.js +8 -0
- package/dist/fix/variants.js.map +1 -0
- package/dist/frameworks/ast.d.ts +84 -0
- package/dist/frameworks/ast.js +231 -0
- package/dist/frameworks/ast.js.map +1 -0
- package/dist/frameworks/nextjs-app/analyze.d.ts +92 -0
- package/dist/frameworks/nextjs-app/analyze.js +350 -0
- package/dist/frameworks/nextjs-app/analyze.js.map +1 -0
- package/dist/frameworks/static/analyze.d.ts +18 -0
- package/dist/frameworks/static/analyze.js +66 -0
- package/dist/frameworks/static/analyze.js.map +1 -0
- package/dist/html/parse.d.ts +50 -0
- package/dist/html/parse.js +205 -0
- package/dist/html/parse.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/insights/validate.d.ts +74 -0
- package/dist/insights/validate.js +213 -0
- package/dist/insights/validate.js.map +1 -0
- package/dist/net/address.d.ts +10 -0
- package/dist/net/address.js +116 -0
- package/dist/net/address.js.map +1 -0
- package/dist/net/fetch.d.ts +53 -0
- package/dist/net/fetch.js +281 -0
- package/dist/net/fetch.js.map +1 -0
- package/dist/repo/detect.d.ts +3 -0
- package/dist/repo/detect.js +92 -0
- package/dist/repo/detect.js.map +1 -0
- package/dist/repo/reader.d.ts +12 -0
- package/dist/repo/reader.js +97 -0
- package/dist/repo/reader.js.map +1 -0
- package/dist/report/render.d.ts +20 -0
- package/dist/report/render.js +176 -0
- package/dist/report/render.js.map +1 -0
- package/dist/robots/crawlers.d.ts +10 -0
- package/dist/robots/crawlers.js +20 -0
- package/dist/robots/crawlers.js.map +1 -0
- package/dist/robots/robots.d.ts +33 -0
- package/dist/robots/robots.js +133 -0
- package/dist/robots/robots.js.map +1 -0
- package/dist/rules/catalogue.d.ts +43 -0
- package/dist/rules/catalogue.js +361 -0
- package/dist/rules/catalogue.js.map +1 -0
- package/dist/rules/context.d.ts +36 -0
- package/dist/rules/context.js +129 -0
- package/dist/rules/context.js.map +1 -0
- package/dist/rules/evaluate.d.ts +11 -0
- package/dist/rules/evaluate.js +1070 -0
- package/dist/rules/evaluate.js.map +1 -0
- package/dist/rules/finalize.d.ts +34 -0
- package/dist/rules/finalize.js +93 -0
- package/dist/rules/finalize.js.map +1 -0
- package/dist/scan.d.ts +27 -0
- package/dist/scan.js +147 -0
- package/dist/scan.js.map +1 -0
- package/dist/scoring/compare.d.ts +21 -0
- package/dist/scoring/compare.js +47 -0
- package/dist/scoring/compare.js.map +1 -0
- package/dist/scoring/score.d.ts +21 -0
- package/dist/scoring/score.js +112 -0
- package/dist/scoring/score.js.map +1 -0
- package/dist/sitemap/sitemap.d.ts +10 -0
- package/dist/sitemap/sitemap.js +48 -0
- package/dist/sitemap/sitemap.js.map +1 -0
- package/dist/types.d.ts +155 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/hosts/claude-project/.claude/agents/geopilot-explainer.md +36 -0
- package/hosts/claude-project/.claude/agents/geopilot-fixer.md +42 -0
- package/hosts/claude-project/.claude/agents/geopilot-investigator.md +45 -0
- package/hosts/claude-project/.claude/agents/geopilot-reviewer.md +41 -0
- package/hosts/claude-project/.claude/agents/geopilot-scanner.md +47 -0
- package/hosts/claude-project/.claude/skills/geo/SKILL.md +95 -0
- package/hosts/claude-project/.claude/skills/geo/references/frameworks.md +20 -0
- package/hosts/claude-project/.claude/skills/geo/references/insight-contract.md +42 -0
- package/hosts/claude-project/.claude/skills/geo/references/safety.md +30 -0
- package/hosts/claude-project/.claude/skills/geo/references/workflow-explain.md +8 -0
- package/hosts/claude-project/.claude/skills/geo/references/workflow-fix.md +20 -0
- package/hosts/claude-project/.claude/skills/geo/references/workflow-init.md +6 -0
- package/hosts/claude-project/.claude/skills/geo/references/workflow-insights.md +13 -0
- package/hosts/claude-project/.claude/skills/geo/references/workflow-plan.md +13 -0
- package/hosts/claude-project/.claude/skills/geo/references/workflow-review.md +8 -0
- package/hosts/claude-project/.claude/skills/geo/references/workflow-scan.md +18 -0
- package/hosts/claude-project/.claude/skills/geo/schemas/insights.schema.json +255 -0
- package/hosts/claude-project/.claude/skills/geo/scripts/geo.ps1 +11 -0
- package/hosts/claude-project/.claude/skills/geo/scripts/geo.sh +11 -0
- package/hosts/claude-project/.claude/skills/geopilot-explain/SKILL.md +9 -0
- package/hosts/claude-project/.claude/skills/geopilot-fix/SKILL.md +12 -0
- package/hosts/claude-project/.claude/skills/geopilot-init/SKILL.md +15 -0
- package/hosts/claude-project/.claude/skills/geopilot-insights/SKILL.md +11 -0
- package/hosts/claude-project/.claude/skills/geopilot-review/SKILL.md +11 -0
- package/hosts/claude-project/.claude/skills/geopilot-scan/SKILL.md +11 -0
- package/hosts/geopilot/.claude-plugin/plugin.json +22 -0
- package/hosts/geopilot/README.md +25 -0
- package/hosts/geopilot/agents/explainer.agent.md +36 -0
- package/hosts/geopilot/agents/fixer.agent.md +42 -0
- package/hosts/geopilot/agents/investigator.agent.md +45 -0
- package/hosts/geopilot/agents/reviewer.agent.md +41 -0
- package/hosts/geopilot/agents/scanner.agent.md +47 -0
- package/hosts/geopilot/assets/icon.png +0 -0
- package/hosts/geopilot/skills/explain/SKILL.md +9 -0
- package/hosts/geopilot/skills/fix/SKILL.md +12 -0
- package/hosts/geopilot/skills/geo/SKILL.md +95 -0
- package/hosts/geopilot/skills/geo/references/frameworks.md +20 -0
- package/hosts/geopilot/skills/geo/references/insight-contract.md +42 -0
- package/hosts/geopilot/skills/geo/references/safety.md +30 -0
- package/hosts/geopilot/skills/geo/references/workflow-explain.md +8 -0
- package/hosts/geopilot/skills/geo/references/workflow-fix.md +20 -0
- package/hosts/geopilot/skills/geo/references/workflow-init.md +6 -0
- package/hosts/geopilot/skills/geo/references/workflow-insights.md +13 -0
- package/hosts/geopilot/skills/geo/references/workflow-plan.md +13 -0
- package/hosts/geopilot/skills/geo/references/workflow-review.md +8 -0
- package/hosts/geopilot/skills/geo/references/workflow-scan.md +18 -0
- package/hosts/geopilot/skills/geo/schemas/insights.schema.json +255 -0
- package/hosts/geopilot/skills/geo/scripts/geo.ps1 +11 -0
- package/hosts/geopilot/skills/geo/scripts/geo.sh +11 -0
- package/hosts/geopilot/skills/init/SKILL.md +15 -0
- package/hosts/geopilot/skills/insights/SKILL.md +11 -0
- package/hosts/geopilot/skills/review/SKILL.md +11 -0
- package/hosts/geopilot/skills/scan/SKILL.md +11 -0
- package/hosts/opencode/.opencode/agents/geopilot-explainer.md +39 -0
- package/hosts/opencode/.opencode/agents/geopilot-fixer.md +45 -0
- package/hosts/opencode/.opencode/agents/geopilot-investigator.md +48 -0
- package/hosts/opencode/.opencode/agents/geopilot-reviewer.md +44 -0
- package/hosts/opencode/.opencode/agents/geopilot-scanner.md +50 -0
- package/hosts/opencode/.opencode/commands/geopilot-explain.md +8 -0
- package/hosts/opencode/.opencode/commands/geopilot-fix.md +10 -0
- package/hosts/opencode/.opencode/commands/geopilot-init.md +12 -0
- package/hosts/opencode/.opencode/commands/geopilot-insights.md +10 -0
- package/hosts/opencode/.opencode/commands/geopilot-review.md +10 -0
- package/hosts/opencode/.opencode/commands/geopilot-scan.md +10 -0
- package/hosts/opencode/.opencode/skills/geo/SKILL.md +95 -0
- package/hosts/opencode/.opencode/skills/geo/references/frameworks.md +20 -0
- package/hosts/opencode/.opencode/skills/geo/references/insight-contract.md +42 -0
- package/hosts/opencode/.opencode/skills/geo/references/safety.md +30 -0
- package/hosts/opencode/.opencode/skills/geo/references/workflow-explain.md +8 -0
- package/hosts/opencode/.opencode/skills/geo/references/workflow-fix.md +20 -0
- package/hosts/opencode/.opencode/skills/geo/references/workflow-init.md +6 -0
- package/hosts/opencode/.opencode/skills/geo/references/workflow-insights.md +13 -0
- package/hosts/opencode/.opencode/skills/geo/references/workflow-plan.md +13 -0
- package/hosts/opencode/.opencode/skills/geo/references/workflow-review.md +8 -0
- package/hosts/opencode/.opencode/skills/geo/references/workflow-scan.md +18 -0
- package/hosts/opencode/.opencode/skills/geo/schemas/insights.schema.json +255 -0
- package/hosts/opencode/.opencode/skills/geo/scripts/geo.ps1 +11 -0
- package/hosts/opencode/.opencode/skills/geo/scripts/geo.sh +11 -0
- package/package.json +65 -4
- package/schemas/config-v1.json +392 -0
- package/schemas/insights-v1.json +255 -0
- package/schemas/merged-v1.json +71 -0
- package/schemas/report-v1.json +836 -0
- package/skill/geo/SKILL.md +95 -0
- package/skill/geo/references/frameworks.md +20 -0
- package/skill/geo/references/insight-contract.md +42 -0
- package/skill/geo/references/safety.md +30 -0
- package/skill/geo/references/workflow-explain.md +8 -0
- package/skill/geo/references/workflow-fix.md +20 -0
- package/skill/geo/references/workflow-init.md +6 -0
- package/skill/geo/references/workflow-insights.md +13 -0
- package/skill/geo/references/workflow-plan.md +13 -0
- package/skill/geo/references/workflow-review.md +8 -0
- package/skill/geo/references/workflow-scan.md +18 -0
- package/skill/geo/schemas/insights.schema.json +255 -0
- package/skill/geo/scripts/geo.ps1 +11 -0
- package/skill/geo/scripts/geo.sh +11 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type * as t from '@babel/types';
|
|
2
|
+
export type StaticValue = {
|
|
3
|
+
readonly kind: 'string';
|
|
4
|
+
readonly value: string;
|
|
5
|
+
readonly node: t.Node;
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: 'number';
|
|
8
|
+
readonly value: number;
|
|
9
|
+
readonly node: t.Node;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'boolean';
|
|
12
|
+
readonly value: boolean;
|
|
13
|
+
readonly node: t.Node;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'null';
|
|
16
|
+
readonly node: t.Node;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: 'object';
|
|
19
|
+
readonly props: ReadonlyMap<string, StaticProp>;
|
|
20
|
+
readonly dynamicKeys: boolean;
|
|
21
|
+
readonly node: t.ObjectExpression;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'array';
|
|
24
|
+
readonly items: readonly StaticValue[];
|
|
25
|
+
readonly node: t.Node;
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'dynamic';
|
|
28
|
+
readonly reason: string;
|
|
29
|
+
readonly node: t.Node;
|
|
30
|
+
};
|
|
31
|
+
export interface StaticProp {
|
|
32
|
+
readonly key: string;
|
|
33
|
+
readonly value: StaticValue;
|
|
34
|
+
readonly node: t.ObjectProperty | t.ObjectMethod;
|
|
35
|
+
}
|
|
36
|
+
export interface ParsedModule {
|
|
37
|
+
readonly file: string;
|
|
38
|
+
readonly source: string;
|
|
39
|
+
readonly ast: t.File;
|
|
40
|
+
}
|
|
41
|
+
export declare function parseModule(file: string, source: string): ParsedModule | {
|
|
42
|
+
error: string;
|
|
43
|
+
};
|
|
44
|
+
/** Strip TS wrappers that do not change the runtime value: `x as T`, `x satisfies T`, `x!`, `(x)`. */
|
|
45
|
+
export declare function unwrap(node: t.Node): t.Node;
|
|
46
|
+
export declare function staticValue(input: t.Node): StaticValue;
|
|
47
|
+
export interface ExportInfo {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly kind: 'const' | 'function' | 'reexport';
|
|
50
|
+
readonly init: t.Node | null;
|
|
51
|
+
readonly node: t.Node;
|
|
52
|
+
readonly from?: string;
|
|
53
|
+
}
|
|
54
|
+
/** Top-level named exports: `export const x = …`, `export function x`, `export { x } from`, `export { x }`. */
|
|
55
|
+
export declare function exportsOf(mod: ParsedModule): Map<string, ExportInfo>;
|
|
56
|
+
/** Map of local binding name → import source, for following in-repo imports. */
|
|
57
|
+
export declare function importsOf(mod: ParsedModule): Map<string, {
|
|
58
|
+
from: string;
|
|
59
|
+
imported: string;
|
|
60
|
+
}>;
|
|
61
|
+
export declare function hasDirective(mod: ParsedModule, directive: string): boolean;
|
|
62
|
+
export declare function lineCol(node: t.Node): {
|
|
63
|
+
line: number;
|
|
64
|
+
column: number;
|
|
65
|
+
};
|
|
66
|
+
/** Depth-first walk over every AST node. */
|
|
67
|
+
export declare function walk(node: t.Node, visit: (n: t.Node) => void): void;
|
|
68
|
+
export interface JsxHtml {
|
|
69
|
+
readonly node: t.JSXOpeningElement;
|
|
70
|
+
readonly lang: {
|
|
71
|
+
readonly kind: 'literal';
|
|
72
|
+
readonly value: string;
|
|
73
|
+
readonly node: t.Node;
|
|
74
|
+
} | {
|
|
75
|
+
readonly kind: 'expression';
|
|
76
|
+
readonly node: t.Node;
|
|
77
|
+
} | null;
|
|
78
|
+
readonly hasSpread: boolean;
|
|
79
|
+
readonly count: number;
|
|
80
|
+
}
|
|
81
|
+
/** The `<html>` JSX opening element(s) in a module, as root layouts render them. */
|
|
82
|
+
export declare function findJsxHtml(mod: ParsedModule): JsxHtml | null;
|
|
83
|
+
/** Whether a source text contains an ObjectProperty key with one of these names, by AST. */
|
|
84
|
+
export declare function hasObjectKey(mod: ParsedModule, names: ReadonlySet<string>): string[];
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { parse } from '@babel/parser';
|
|
2
|
+
export function parseModule(file, source) {
|
|
3
|
+
const plugins = ['jsx'];
|
|
4
|
+
if (/\.(ts|tsx|mts|cts)$/.test(file))
|
|
5
|
+
plugins.push('typescript');
|
|
6
|
+
try {
|
|
7
|
+
const ast = parse(source, { sourceType: 'module', plugins, errorRecovery: false });
|
|
8
|
+
return { file, source, ast };
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
return { error: e.message };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Strip TS wrappers that do not change the runtime value: `x as T`, `x satisfies T`, `x!`, `(x)`. */
|
|
15
|
+
export function unwrap(node) {
|
|
16
|
+
let n = node;
|
|
17
|
+
for (;;) {
|
|
18
|
+
if (n.type === 'TSAsExpression' || n.type === 'TSSatisfiesExpression' || n.type === 'TSNonNullExpression' || n.type === 'TSTypeAssertion') {
|
|
19
|
+
n = n.expression;
|
|
20
|
+
}
|
|
21
|
+
else if (n.type === 'ParenthesizedExpression') {
|
|
22
|
+
n = n.expression;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return n;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function keyName(prop) {
|
|
30
|
+
if (prop.computed)
|
|
31
|
+
return prop.key.type === 'StringLiteral' ? prop.key.value : null;
|
|
32
|
+
if (prop.key.type === 'Identifier')
|
|
33
|
+
return prop.key.name;
|
|
34
|
+
if (prop.key.type === 'StringLiteral')
|
|
35
|
+
return prop.key.value;
|
|
36
|
+
if (prop.key.type === 'NumericLiteral')
|
|
37
|
+
return String(prop.key.value);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
export function staticValue(input) {
|
|
41
|
+
const node = unwrap(input);
|
|
42
|
+
switch (node.type) {
|
|
43
|
+
case 'StringLiteral':
|
|
44
|
+
return { kind: 'string', value: node.value, node };
|
|
45
|
+
case 'TemplateLiteral':
|
|
46
|
+
if (node.expressions.length === 0)
|
|
47
|
+
return { kind: 'string', value: node.quasis.map((q) => q.value.cooked ?? q.value.raw).join(''), node };
|
|
48
|
+
return { kind: 'dynamic', reason: 'template literal with expressions', node };
|
|
49
|
+
case 'NumericLiteral':
|
|
50
|
+
return { kind: 'number', value: node.value, node };
|
|
51
|
+
case 'BooleanLiteral':
|
|
52
|
+
return { kind: 'boolean', value: node.value, node };
|
|
53
|
+
case 'NullLiteral':
|
|
54
|
+
return { kind: 'null', node };
|
|
55
|
+
case 'ArrayExpression': {
|
|
56
|
+
const items = [];
|
|
57
|
+
for (const el of node.elements) {
|
|
58
|
+
if (!el || el.type === 'SpreadElement')
|
|
59
|
+
return { kind: 'dynamic', reason: 'array spread or hole', node };
|
|
60
|
+
items.push(staticValue(el));
|
|
61
|
+
}
|
|
62
|
+
return { kind: 'array', items, node };
|
|
63
|
+
}
|
|
64
|
+
case 'ObjectExpression': {
|
|
65
|
+
const props = new Map();
|
|
66
|
+
let dynamicKeys = false;
|
|
67
|
+
for (const p of node.properties) {
|
|
68
|
+
if (p.type === 'SpreadElement') {
|
|
69
|
+
dynamicKeys = true;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const key = keyName(p);
|
|
73
|
+
if (key === null) {
|
|
74
|
+
dynamicKeys = true;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const value = p.type === 'ObjectMethod' ? { kind: 'dynamic', reason: 'method', node: p } : staticValue(p.value);
|
|
78
|
+
props.set(key, { key, value, node: p });
|
|
79
|
+
}
|
|
80
|
+
return { kind: 'object', props, dynamicKeys, node };
|
|
81
|
+
}
|
|
82
|
+
case 'NewExpression': {
|
|
83
|
+
// `new URL('https://…')` is how metadataBase is written; with one literal
|
|
84
|
+
// argument its value is that literal.
|
|
85
|
+
const arg = node.arguments[0];
|
|
86
|
+
if (node.callee.type === 'Identifier' && node.callee.name === 'URL' && node.arguments.length === 1 && arg && arg.type !== 'SpreadElement' && arg.type !== 'ArgumentPlaceholder') {
|
|
87
|
+
const inner = staticValue(arg);
|
|
88
|
+
if (inner.kind === 'string')
|
|
89
|
+
return { kind: 'string', value: inner.value, node };
|
|
90
|
+
}
|
|
91
|
+
return { kind: 'dynamic', reason: 'constructor call', node };
|
|
92
|
+
}
|
|
93
|
+
case 'Identifier':
|
|
94
|
+
if (node.name === 'undefined')
|
|
95
|
+
return { kind: 'null', node };
|
|
96
|
+
return { kind: 'dynamic', reason: `identifier ${node.name}`, node };
|
|
97
|
+
default:
|
|
98
|
+
return { kind: 'dynamic', reason: node.type, node };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Top-level named exports: `export const x = …`, `export function x`, `export { x } from`, `export { x }`. */
|
|
102
|
+
export function exportsOf(mod) {
|
|
103
|
+
const out = new Map();
|
|
104
|
+
const locals = new Map();
|
|
105
|
+
for (const stmt of mod.ast.program.body) {
|
|
106
|
+
const decl = stmt.type === 'ExportNamedDeclaration' ? stmt.declaration : stmt;
|
|
107
|
+
if (decl && decl.type === 'VariableDeclaration') {
|
|
108
|
+
for (const d of decl.declarations) {
|
|
109
|
+
if (d.id.type === 'Identifier')
|
|
110
|
+
locals.set(d.id.name, { init: d.init ?? null, node: d, kind: 'const' });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else if (decl && decl.type === 'FunctionDeclaration' && decl.id) {
|
|
114
|
+
locals.set(decl.id.name, { init: decl, node: decl, kind: 'function' });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const stmt of mod.ast.program.body) {
|
|
118
|
+
if (stmt.type !== 'ExportNamedDeclaration')
|
|
119
|
+
continue;
|
|
120
|
+
if (stmt.declaration) {
|
|
121
|
+
const decl = stmt.declaration;
|
|
122
|
+
if (decl.type === 'VariableDeclaration') {
|
|
123
|
+
for (const d of decl.declarations) {
|
|
124
|
+
if (d.id.type === 'Identifier')
|
|
125
|
+
out.set(d.id.name, { name: d.id.name, kind: 'const', init: d.init ?? null, node: d });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (decl.type === 'FunctionDeclaration' && decl.id) {
|
|
129
|
+
out.set(decl.id.name, { name: decl.id.name, kind: 'function', init: decl, node: decl });
|
|
130
|
+
}
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
for (const spec of stmt.specifiers) {
|
|
134
|
+
if (spec.type !== 'ExportSpecifier')
|
|
135
|
+
continue;
|
|
136
|
+
const exported = spec.exported.type === 'Identifier' ? spec.exported.name : spec.exported.value;
|
|
137
|
+
if (stmt.source) {
|
|
138
|
+
out.set(exported, { name: exported, kind: 'reexport', init: null, node: spec, from: stmt.source.value });
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const local = locals.get(spec.local.type === 'Identifier' ? spec.local.name : spec.local.value);
|
|
142
|
+
if (local)
|
|
143
|
+
out.set(exported, { name: exported, kind: local.kind, init: local.init, node: local.node });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
/** Map of local binding name → import source, for following in-repo imports. */
|
|
150
|
+
export function importsOf(mod) {
|
|
151
|
+
const out = new Map();
|
|
152
|
+
for (const stmt of mod.ast.program.body) {
|
|
153
|
+
if (stmt.type !== 'ImportDeclaration')
|
|
154
|
+
continue;
|
|
155
|
+
for (const spec of stmt.specifiers) {
|
|
156
|
+
if (spec.type === 'ImportSpecifier') {
|
|
157
|
+
out.set(spec.local.name, { from: stmt.source.value, imported: spec.imported.type === 'Identifier' ? spec.imported.name : spec.imported.value });
|
|
158
|
+
}
|
|
159
|
+
else if (spec.type === 'ImportDefaultSpecifier') {
|
|
160
|
+
out.set(spec.local.name, { from: stmt.source.value, imported: 'default' });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
export function hasDirective(mod, directive) {
|
|
167
|
+
return mod.ast.program.directives.some((d) => d.value.value === directive);
|
|
168
|
+
}
|
|
169
|
+
export function lineCol(node) {
|
|
170
|
+
return { line: node.loc?.start.line ?? 1, column: (node.loc?.start.column ?? 0) + 1 };
|
|
171
|
+
}
|
|
172
|
+
/** Depth-first walk over every AST node. */
|
|
173
|
+
export function walk(node, visit) {
|
|
174
|
+
visit(node);
|
|
175
|
+
for (const key of Object.keys(node)) {
|
|
176
|
+
if (key === 'loc' || key === 'leadingComments' || key === 'trailingComments' || key === 'innerComments')
|
|
177
|
+
continue;
|
|
178
|
+
const value = node[key];
|
|
179
|
+
if (Array.isArray(value)) {
|
|
180
|
+
for (const v of value)
|
|
181
|
+
if (v && typeof v === 'object' && typeof v.type === 'string')
|
|
182
|
+
walk(v, visit);
|
|
183
|
+
}
|
|
184
|
+
else if (value && typeof value === 'object' && typeof value.type === 'string') {
|
|
185
|
+
walk(value, visit);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/** The `<html>` JSX opening element(s) in a module, as root layouts render them. */
|
|
190
|
+
export function findJsxHtml(mod) {
|
|
191
|
+
const found = [];
|
|
192
|
+
walk(mod.ast, (n) => {
|
|
193
|
+
if (n.type === 'JSXOpeningElement' && n.name.type === 'JSXIdentifier' && n.name.name === 'html')
|
|
194
|
+
found.push(n);
|
|
195
|
+
});
|
|
196
|
+
const first = found[0];
|
|
197
|
+
if (!first)
|
|
198
|
+
return null;
|
|
199
|
+
let lang = null;
|
|
200
|
+
let hasSpread = false;
|
|
201
|
+
for (const attr of first.attributes) {
|
|
202
|
+
if (attr.type === 'JSXSpreadAttribute') {
|
|
203
|
+
hasSpread = true;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
if (attr.name.type === 'JSXIdentifier' && attr.name.name === 'lang') {
|
|
207
|
+
if (attr.value?.type === 'StringLiteral')
|
|
208
|
+
lang = { kind: 'literal', value: attr.value.value, node: attr };
|
|
209
|
+
else if (attr.value?.type === 'JSXExpressionContainer') {
|
|
210
|
+
const sv = attr.value.expression.type === 'JSXEmptyExpression' ? null : staticValue(attr.value.expression);
|
|
211
|
+
lang = sv && sv.kind === 'string' ? { kind: 'literal', value: sv.value, node: attr } : { kind: 'expression', node: attr };
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
lang = { kind: 'expression', node: attr };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return { node: first, lang, hasSpread, count: found.length };
|
|
218
|
+
}
|
|
219
|
+
/** Whether a source text contains an ObjectProperty key with one of these names, by AST. */
|
|
220
|
+
export function hasObjectKey(mod, names) {
|
|
221
|
+
const hits = new Set();
|
|
222
|
+
walk(mod.ast, (n) => {
|
|
223
|
+
if ((n.type === 'ObjectProperty' || n.type === 'ObjectMethod') && !n.computed) {
|
|
224
|
+
const k = n.key.type === 'Identifier' ? n.key.name : n.key.type === 'StringLiteral' ? n.key.value : null;
|
|
225
|
+
if (k && names.has(k))
|
|
226
|
+
hits.add(k);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return [...hits].sort();
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/frameworks/ast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAC;AA4BzD,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,MAAc;IACtD,MAAM,OAAO,GAAmB,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAsB,CAAC;QACxG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE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,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type * as t from '@babel/types';
|
|
2
|
+
import type { RepoReader } from '../../repo/reader.ts';
|
|
3
|
+
import type { ProvenanceLevel, SourceLocation } from '../../types.ts';
|
|
4
|
+
import { type JsxHtml, type ParsedModule, type StaticValue } from '../ast.ts';
|
|
5
|
+
export declare const SUPPORTED_NEXT_MAJORS: readonly number[];
|
|
6
|
+
export interface NextRoute {
|
|
7
|
+
readonly route: string;
|
|
8
|
+
readonly pageFile: string;
|
|
9
|
+
/** Root layout first. */
|
|
10
|
+
readonly layoutFiles: readonly string[];
|
|
11
|
+
readonly dynamic: boolean;
|
|
12
|
+
readonly uncertain: readonly string[];
|
|
13
|
+
readonly clientPage: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type MetaSource = {
|
|
16
|
+
readonly kind: 'literal';
|
|
17
|
+
readonly file: string;
|
|
18
|
+
readonly value: Extract<StaticValue, {
|
|
19
|
+
kind: 'object';
|
|
20
|
+
}>;
|
|
21
|
+
readonly declaredIn: string;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'generate';
|
|
24
|
+
readonly file: string;
|
|
25
|
+
readonly line: number;
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'opaque';
|
|
28
|
+
readonly file: string;
|
|
29
|
+
readonly line: number;
|
|
30
|
+
readonly reason: string;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: 'none';
|
|
33
|
+
readonly file: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: 'parse_error';
|
|
36
|
+
readonly file: string;
|
|
37
|
+
readonly reason: string;
|
|
38
|
+
};
|
|
39
|
+
export interface NextAnalysis {
|
|
40
|
+
readonly appDir: string;
|
|
41
|
+
readonly routes: readonly NextRoute[];
|
|
42
|
+
readonly meta: ReadonlyMap<string, MetaSource>;
|
|
43
|
+
readonly modules: ReadonlyMap<string, ParsedModule>;
|
|
44
|
+
readonly rootLayout: string | null;
|
|
45
|
+
readonly html: JsxHtml | null;
|
|
46
|
+
readonly robots: {
|
|
47
|
+
readonly publicTxt: string | null;
|
|
48
|
+
readonly appTxt: string | null;
|
|
49
|
+
readonly appCode: string | null;
|
|
50
|
+
};
|
|
51
|
+
readonly sitemap: {
|
|
52
|
+
readonly publicXml: readonly string[];
|
|
53
|
+
readonly appXml: string | null;
|
|
54
|
+
readonly appCode: readonly string[];
|
|
55
|
+
};
|
|
56
|
+
readonly middleware: string | null;
|
|
57
|
+
readonly nextConfig: {
|
|
58
|
+
readonly file: string;
|
|
59
|
+
readonly keys: readonly string[];
|
|
60
|
+
} | null;
|
|
61
|
+
readonly i18n: readonly string[];
|
|
62
|
+
readonly nextMajor: number | null;
|
|
63
|
+
readonly supportedMajor: boolean;
|
|
64
|
+
readonly parseErrors: readonly {
|
|
65
|
+
readonly file: string;
|
|
66
|
+
readonly reason: string;
|
|
67
|
+
}[];
|
|
68
|
+
}
|
|
69
|
+
export declare function findAppDir(repo: RepoReader): string | null;
|
|
70
|
+
export declare function nextMajorOf(repo: RepoReader): number | null;
|
|
71
|
+
export declare function analyzeNextApp(repo: RepoReader): NextAnalysis | null;
|
|
72
|
+
export interface ResolvedKey {
|
|
73
|
+
readonly level: ProvenanceLevel;
|
|
74
|
+
readonly value: StaticValue | null;
|
|
75
|
+
readonly locations: readonly SourceLocation[];
|
|
76
|
+
readonly reason: string;
|
|
77
|
+
/** True when no segment defines the key: the value is proven missing even if the insertion point is not. */
|
|
78
|
+
readonly missing?: boolean;
|
|
79
|
+
/** The file whose metadata object holds the key, when it is a literal. */
|
|
80
|
+
readonly literalFile: string | null;
|
|
81
|
+
readonly prop: t.ObjectProperty | t.ObjectMethod | null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolve one top-level metadata key for a route by Next's shallow per-key
|
|
85
|
+
* precedence: the nearest segment that defines the key wins outright.
|
|
86
|
+
*/
|
|
87
|
+
export declare function resolveMetaKey(a: NextAnalysis, route: NextRoute, key: string): ResolvedKey;
|
|
88
|
+
/** Global and per-route conditions that cap provenance below exact (spec 11). */
|
|
89
|
+
export declare function provenanceCaps(a: NextAnalysis, route: NextRoute | null, concern: 'html' | 'headers' | 'files'): string[];
|
|
90
|
+
export declare function capLevel(level: ProvenanceLevel, caps: readonly string[]): ProvenanceLevel;
|
|
91
|
+
/** Match a URL path to the most specific route (static segments beat dynamic). */
|
|
92
|
+
export declare function matchRoute(routes: readonly NextRoute[], pathname: string): NextRoute | null;
|