@component-compass/cli 0.0.0-pr-3-8916f3c-20260507145532
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 +5 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +110 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.js +61 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/scan.d.ts +12 -0
- package/dist/commands/scan.js +147 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/config/loader.d.ts +6 -0
- package/dist/config/loader.js +62 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +32 -0
- package/dist/config/schema.js +15 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/tag-rules.d.ts +2 -0
- package/dist/config/tag-rules.js +34 -0
- package/dist/config/tag-rules.js.map +1 -0
- package/dist/dispatcher.d.ts +8 -0
- package/dist/dispatcher.js +22 -0
- package/dist/dispatcher.js.map +1 -0
- package/dist/envelope/git.d.ts +13 -0
- package/dist/envelope/git.js +69 -0
- package/dist/envelope/git.js.map +1 -0
- package/dist/envelope/index.d.ts +10 -0
- package/dist/envelope/index.js +57 -0
- package/dist/envelope/index.js.map +1 -0
- package/dist/envelope/repo-id.d.ts +16 -0
- package/dist/envelope/repo-id.js +40 -0
- package/dist/envelope/repo-id.js.map +1 -0
- package/dist/identity.d.ts +46 -0
- package/dist/identity.js +92 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/local-index/detect-react.d.ts +2 -0
- package/dist/local-index/detect-react.js +128 -0
- package/dist/local-index/detect-react.js.map +1 -0
- package/dist/local-index/detect-vue.d.ts +2 -0
- package/dist/local-index/detect-vue.js +164 -0
- package/dist/local-index/detect-vue.js.map +1 -0
- package/dist/local-index/detect-wc.d.ts +2 -0
- package/dist/local-index/detect-wc.js +74 -0
- package/dist/local-index/detect-wc.js.map +1 -0
- package/dist/local-index/index.d.ts +6 -0
- package/dist/local-index/index.js +31 -0
- package/dist/local-index/index.js.map +1 -0
- package/dist/local-index/types.d.ts +2 -0
- package/dist/local-index/types.js +2 -0
- package/dist/local-index/types.js.map +1 -0
- package/dist/local-index/walker.d.ts +11 -0
- package/dist/local-index/walker.js +47 -0
- package/dist/local-index/walker.js.map +1 -0
- package/dist/manifest/barrel-parser.d.ts +22 -0
- package/dist/manifest/barrel-parser.js +62 -0
- package/dist/manifest/barrel-parser.js.map +1 -0
- package/dist/manifest/discovery.d.ts +24 -0
- package/dist/manifest/discovery.js +194 -0
- package/dist/manifest/discovery.js.map +1 -0
- package/dist/manifest/index.d.ts +6 -0
- package/dist/manifest/index.js +98 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/resolver.d.ts +30 -0
- package/dist/manifest/resolver.js +136 -0
- package/dist/manifest/resolver.js.map +1 -0
- package/dist/manifest/run-discovery.d.ts +12 -0
- package/dist/manifest/run-discovery.js +46 -0
- package/dist/manifest/run-discovery.js.map +1 -0
- package/dist/manifest/types.d.ts +3 -0
- package/dist/manifest/types.js +2 -0
- package/dist/manifest/types.js.map +1 -0
- package/dist/occurrences.d.ts +12 -0
- package/dist/occurrences.js +42 -0
- package/dist/occurrences.js.map +1 -0
- package/dist/reporter/index.d.ts +25 -0
- package/dist/reporter/index.js +50 -0
- package/dist/reporter/index.js.map +1 -0
- package/dist/reporter/json.d.ts +6 -0
- package/dist/reporter/json.js +11 -0
- package/dist/reporter/json.js.map +1 -0
- package/dist/reporter/stdout.d.ts +2 -0
- package/dist/reporter/stdout.js +40 -0
- package/dist/reporter/stdout.js.map +1 -0
- package/dist/rollup.d.ts +21 -0
- package/dist/rollup.js +78 -0
- package/dist/rollup.js.map +1 -0
- package/dist/seeds.d.ts +28 -0
- package/dist/seeds.js +109 -0
- package/dist/seeds.js.map +1 -0
- package/dist/types/brand.d.ts +11 -0
- package/dist/types/brand.js +5 -0
- package/dist/types/brand.js.map +1 -0
- package/dist/types/component-id.d.ts +2 -0
- package/dist/types/component-id.js +2 -0
- package/dist/types/component-id.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util/git.d.ts +1 -0
- package/dist/util/git.js +13 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/log.d.ts +7 -0
- package/dist/util/log.js +17 -0
- package/dist/util/log.js.map +1 -0
- package/dist/util/pkg.d.ts +1 -0
- package/dist/util/pkg.js +13 -0
- package/dist/util/pkg.js.map +1 -0
- package/dist/util/pnp-check.d.ts +1 -0
- package/dist/util/pnp-check.js +6 -0
- package/dist/util/pnp-check.js.map +1 -0
- package/dist/util/posix.d.ts +2 -0
- package/dist/util/posix.js +18 -0
- package/dist/util/posix.js.map +1 -0
- package/dist/walker/files.d.ts +6 -0
- package/dist/walker/files.js +12 -0
- package/dist/walker/files.js.map +1 -0
- package/dist/walker/resolve-import.d.ts +9 -0
- package/dist/walker/resolve-import.js +119 -0
- package/dist/walker/resolve-import.js.map +1 -0
- package/examples/github-actions-workflow.yml +20 -0
- package/package.json +63 -0
- package/schema/config.schema.json +61 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { parse as parseSfc } from "@vue/compiler-sfc";
|
|
2
|
+
import { parse as parseScript } from "@babel/parser";
|
|
3
|
+
import { traverse } from "@component-compass/ast-utils";
|
|
4
|
+
import { basename, extname } from "node:path";
|
|
5
|
+
export function detectVueComponents(source, filePath, extension) {
|
|
6
|
+
if (extension === ".vue") {
|
|
7
|
+
const def = detectSfc(source, filePath);
|
|
8
|
+
return def ? [def] : [];
|
|
9
|
+
}
|
|
10
|
+
if (extension === ".ts" || extension === ".js")
|
|
11
|
+
return detectScriptDefineComponent(source, filePath);
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
function detectSfc(source, filePath) {
|
|
15
|
+
let descriptor;
|
|
16
|
+
try {
|
|
17
|
+
descriptor = parseSfc(source).descriptor;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const exportName = resolveSfcName(descriptor, filePath);
|
|
23
|
+
return {
|
|
24
|
+
componentId: {
|
|
25
|
+
kind: "vue-component",
|
|
26
|
+
export: exportName,
|
|
27
|
+
source: { type: "local", filePath },
|
|
28
|
+
},
|
|
29
|
+
exportName,
|
|
30
|
+
isDefault: true,
|
|
31
|
+
detector: "vue-sfc",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function resolveSfcName(descriptor, filePath) {
|
|
35
|
+
const scriptSetupSrc = descriptor.scriptSetup?.content ?? "";
|
|
36
|
+
const scriptSrc = descriptor.script?.content ?? "";
|
|
37
|
+
const fromDefineOptions = extractDefineOptionsName(scriptSetupSrc);
|
|
38
|
+
if (fromDefineOptions)
|
|
39
|
+
return fromDefineOptions;
|
|
40
|
+
const fromOptionsObject = extractOptionsObjectName(scriptSrc);
|
|
41
|
+
if (fromOptionsObject)
|
|
42
|
+
return fromOptionsObject;
|
|
43
|
+
return pascalFromFilename(filePath);
|
|
44
|
+
}
|
|
45
|
+
function extractDefineOptionsName(src) {
|
|
46
|
+
if (!src.includes("defineOptions"))
|
|
47
|
+
return null;
|
|
48
|
+
const ast = tryParse(src);
|
|
49
|
+
if (!ast)
|
|
50
|
+
return null;
|
|
51
|
+
let found = null;
|
|
52
|
+
traverse(ast, {
|
|
53
|
+
CallExpression(path) {
|
|
54
|
+
if (found)
|
|
55
|
+
return;
|
|
56
|
+
const { callee, arguments: args } = path.node;
|
|
57
|
+
if (callee.type !== "Identifier" || callee.name !== "defineOptions")
|
|
58
|
+
return;
|
|
59
|
+
const arg = args[0];
|
|
60
|
+
if (!arg || arg.type !== "ObjectExpression")
|
|
61
|
+
return;
|
|
62
|
+
found = readNameProperty(arg);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
function extractOptionsObjectName(src) {
|
|
68
|
+
if (!src)
|
|
69
|
+
return null;
|
|
70
|
+
const ast = tryParse(src);
|
|
71
|
+
if (!ast)
|
|
72
|
+
return null;
|
|
73
|
+
let found = null;
|
|
74
|
+
traverse(ast, {
|
|
75
|
+
ExportDefaultDeclaration(path) {
|
|
76
|
+
if (found)
|
|
77
|
+
return;
|
|
78
|
+
const decl = path.node.declaration;
|
|
79
|
+
if (decl.type === "ObjectExpression") {
|
|
80
|
+
found = readNameProperty(decl);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (decl.type === "CallExpression" && decl.callee.type === "Identifier" && decl.callee.name === "defineComponent") {
|
|
84
|
+
const arg = decl.arguments[0];
|
|
85
|
+
if (arg && arg.type === "ObjectExpression")
|
|
86
|
+
found = readNameProperty(arg);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
return found;
|
|
91
|
+
}
|
|
92
|
+
function readNameProperty(obj) {
|
|
93
|
+
for (const p of obj.properties) {
|
|
94
|
+
const prop = p;
|
|
95
|
+
if (prop.type !== "ObjectProperty")
|
|
96
|
+
continue;
|
|
97
|
+
if (prop.key?.type !== "Identifier" || prop.key.name !== "name")
|
|
98
|
+
continue;
|
|
99
|
+
if (prop.value?.type !== "StringLiteral")
|
|
100
|
+
continue;
|
|
101
|
+
if (typeof prop.value.value === "string")
|
|
102
|
+
return prop.value.value;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
function tryParse(src) {
|
|
107
|
+
try {
|
|
108
|
+
return parseScript(src, { sourceType: "module", plugins: ["typescript"] });
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function pascalFromFilename(filePath) {
|
|
115
|
+
const stem = basename(filePath, extname(filePath));
|
|
116
|
+
return stem.replace(/(^|[-_])(.)/g, (_, _sep, c) => c.toUpperCase());
|
|
117
|
+
}
|
|
118
|
+
function detectScriptDefineComponent(source, filePath) {
|
|
119
|
+
const ast = tryParse(source);
|
|
120
|
+
if (!ast)
|
|
121
|
+
return [];
|
|
122
|
+
const out = [];
|
|
123
|
+
traverse(ast, {
|
|
124
|
+
ExportDefaultDeclaration(path) {
|
|
125
|
+
const decl = path.node.declaration;
|
|
126
|
+
if (decl.type === "CallExpression" && decl.callee.type === "Identifier" && decl.callee.name === "defineComponent") {
|
|
127
|
+
out.push({
|
|
128
|
+
componentId: {
|
|
129
|
+
kind: "vue-component",
|
|
130
|
+
export: pascalFromFilename(filePath),
|
|
131
|
+
source: { type: "local", filePath },
|
|
132
|
+
},
|
|
133
|
+
exportName: pascalFromFilename(filePath),
|
|
134
|
+
isDefault: true,
|
|
135
|
+
detector: "vue-define-component",
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (decl.type === "ObjectExpression" && hasSetupOrRender(decl)) {
|
|
139
|
+
out.push({
|
|
140
|
+
componentId: {
|
|
141
|
+
kind: "vue-component",
|
|
142
|
+
export: pascalFromFilename(filePath),
|
|
143
|
+
source: { type: "local", filePath },
|
|
144
|
+
},
|
|
145
|
+
exportName: pascalFromFilename(filePath),
|
|
146
|
+
isDefault: true,
|
|
147
|
+
detector: "vue-functional",
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
function hasSetupOrRender(obj) {
|
|
155
|
+
return obj.properties.some((p) => {
|
|
156
|
+
const prop = p;
|
|
157
|
+
if (prop.type !== "ObjectProperty" && prop.type !== "ObjectMethod")
|
|
158
|
+
return false;
|
|
159
|
+
if (prop.key?.type !== "Identifier")
|
|
160
|
+
return false;
|
|
161
|
+
return prop.key.name === "setup" || prop.key.name === "render";
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=detect-vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-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"@babel/parser";
|
|
2
|
+
import { traverse } from "@component-compass/ast-utils";
|
|
3
|
+
const WC_EXTS = new Set([".ts", ".js"]);
|
|
4
|
+
export function detectWebComponents(source, filePath, extension) {
|
|
5
|
+
if (!WC_EXTS.has(extension))
|
|
6
|
+
return [];
|
|
7
|
+
const ast = (() => {
|
|
8
|
+
try {
|
|
9
|
+
return parse(source, {
|
|
10
|
+
sourceType: "module",
|
|
11
|
+
plugins: ["typescript", "decorators-legacy", "classProperties"],
|
|
12
|
+
errorRecovery: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
})();
|
|
19
|
+
if (!ast)
|
|
20
|
+
return [];
|
|
21
|
+
const out = [];
|
|
22
|
+
traverse(ast, {
|
|
23
|
+
ClassDeclaration(path) {
|
|
24
|
+
const dec = path.node.decorators?.find((d) => {
|
|
25
|
+
const expr = d.expression;
|
|
26
|
+
if (expr.type !== "CallExpression")
|
|
27
|
+
return false;
|
|
28
|
+
if (expr.callee.type !== "Identifier")
|
|
29
|
+
return false;
|
|
30
|
+
return expr.callee.name === "customElement";
|
|
31
|
+
});
|
|
32
|
+
if (dec && dec.expression.type === "CallExpression") {
|
|
33
|
+
const arg = dec.expression.arguments[0];
|
|
34
|
+
if (arg?.type === "StringLiteral" && typeof arg.value === "string" && arg.value.includes("-")) {
|
|
35
|
+
const tag = arg.value;
|
|
36
|
+
out.push({
|
|
37
|
+
componentId: { kind: "custom-element", tagName: tag, source: { type: "local", filePath } },
|
|
38
|
+
exportName: path.node.id?.name ?? tag,
|
|
39
|
+
isDefault: false,
|
|
40
|
+
detector: "wc-decorator",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
CallExpression(path) {
|
|
46
|
+
const callee = path.node.callee;
|
|
47
|
+
const isDefine = callee.type === "MemberExpression" &&
|
|
48
|
+
callee.object.type === "Identifier" &&
|
|
49
|
+
callee.object.name === "customElements" &&
|
|
50
|
+
callee.property.type === "Identifier" &&
|
|
51
|
+
callee.property.name === "define";
|
|
52
|
+
if (!isDefine)
|
|
53
|
+
return;
|
|
54
|
+
const [tagArg, classArg] = path.node.arguments;
|
|
55
|
+
if (tagArg?.type === "StringLiteral" &&
|
|
56
|
+
typeof tagArg.value === "string" &&
|
|
57
|
+
tagArg.value.includes("-")) {
|
|
58
|
+
const exportName = classArg?.type === "Identifier" ? classArg.name : tagArg.value;
|
|
59
|
+
out.push({
|
|
60
|
+
componentId: {
|
|
61
|
+
kind: "custom-element",
|
|
62
|
+
tagName: tagArg.value,
|
|
63
|
+
source: { type: "local", filePath },
|
|
64
|
+
},
|
|
65
|
+
exportName,
|
|
66
|
+
isDefault: false,
|
|
67
|
+
detector: "wc-customelements-define",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=detect-wc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-wc.js","sourceRoot":"","sources":["../../src/local-index/detect-wc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAExC,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,QAAgB,EAAE,SAAiB;IACrF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE;QAChB,IAAI,CAAC;YACH,OAAO,KAAK,CAAC,MAAM,EAAE;gBACnB,UAAU,EAAE,QAAQ;gBACpB,OAAO,EAAE,CAAC,YAAY,EAAE,mBAAmB,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C;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type WalkOptions } from "./walker.js";
|
|
2
|
+
import type { LocalDefinitionIndex } from "./types.js";
|
|
3
|
+
export type BuildLocalIndexOptions = WalkOptions;
|
|
4
|
+
export declare function buildLocalIndex(opts: BuildLocalIndexOptions): Promise<LocalDefinitionIndex>;
|
|
5
|
+
export type { LocalDefinition, LocalDefinitionIndex, DetectorId } from "./types.js";
|
|
6
|
+
export { emptyLocalIndex } from "./types.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { walkLocalSources } from "./walker.js";
|
|
2
|
+
import { detectReactComponents } from "./detect-react.js";
|
|
3
|
+
import { detectVueComponents } from "./detect-vue.js";
|
|
4
|
+
import { detectWebComponents } from "./detect-wc.js";
|
|
5
|
+
export async function buildLocalIndex(opts) {
|
|
6
|
+
const files = await walkLocalSources(opts);
|
|
7
|
+
const index = { byPath: new Map(), byTag: new Map() };
|
|
8
|
+
for (const file of files) {
|
|
9
|
+
const found = [
|
|
10
|
+
...detectReactComponents(file.source, file.filePath, file.extension),
|
|
11
|
+
...detectVueComponents(file.source, file.filePath, file.extension),
|
|
12
|
+
...detectWebComponents(file.source, file.filePath, file.extension),
|
|
13
|
+
];
|
|
14
|
+
if (found.length === 0)
|
|
15
|
+
continue;
|
|
16
|
+
index.byPath.set(file.filePath, found);
|
|
17
|
+
for (const def of found) {
|
|
18
|
+
if (def.componentId.kind === "custom-element") {
|
|
19
|
+
const existing = index.byTag.get(def.componentId.tagName);
|
|
20
|
+
if (existing && existing.componentId.kind === "custom-element" && existing.componentId.source.type === "local" && existing.componentId.source.filePath !== file.filePath) {
|
|
21
|
+
console.warn(`[component-compass] duplicate local custom-element <${def.componentId.tagName}> in ${file.filePath} (already registered from ${existing.componentId.source.filePath}); keeping first.`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
index.byTag.set(def.componentId.tagName, def);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return index;
|
|
29
|
+
}
|
|
30
|
+
export { emptyLocalIndex } from "./types.js";
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/local-index/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAoB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAKrD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAA4B;IAChE,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAyB,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;IAE5E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAsB;YAC/B,GAAG,qBAAqB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;YACpE,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;YAClE,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;SACnE,CAAC;QACF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACjC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACvC,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,IAAI,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;gBAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBAC1D,IAAI,QAAQ,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,KAAK,gBAAgB,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACzK,OAAO,CAAC,IAAI,CAAC,uDAAuD,GAAG,CAAC,WAAW,CAAC,OAAO,QAAQ,IAAI,CAAC,QAAQ,6BAA6B,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,mBAAmB,CAAC,CAAC;oBACtM,SAAS;gBACX,CAAC;gBACD,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAGD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/local-index/types.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type WalkedFile = {
|
|
2
|
+
absolutePath: string;
|
|
3
|
+
filePath: string;
|
|
4
|
+
extension: string;
|
|
5
|
+
source: string;
|
|
6
|
+
};
|
|
7
|
+
export type WalkOptions = {
|
|
8
|
+
repoRoot: string;
|
|
9
|
+
extraIgnoreGlobs?: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function walkLocalSources(opts: WalkOptions): Promise<WalkedFile[]>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { extname, relative } from "node:path";
|
|
3
|
+
import { posixPath } from "@component-compass/ast-utils";
|
|
4
|
+
import { globby } from "globby";
|
|
5
|
+
const DEFAULT_IGNORES = [
|
|
6
|
+
"**/node_modules/**",
|
|
7
|
+
"**/dist/**",
|
|
8
|
+
"**/build/**",
|
|
9
|
+
"**/.next/**",
|
|
10
|
+
"**/.nuxt/**",
|
|
11
|
+
"**/coverage/**",
|
|
12
|
+
"**/*.test.*",
|
|
13
|
+
"**/*.spec.*",
|
|
14
|
+
"**/__tests__/**",
|
|
15
|
+
"**/*.stories.*",
|
|
16
|
+
];
|
|
17
|
+
const DEFAULT_EXTENSIONS = [".tsx", ".jsx", ".ts", ".js", ".vue"];
|
|
18
|
+
export async function walkLocalSources(opts) {
|
|
19
|
+
const ignore = [...DEFAULT_IGNORES, ...(opts.extraIgnoreGlobs ?? [])];
|
|
20
|
+
const matched = await globby(["**/*"], {
|
|
21
|
+
cwd: opts.repoRoot,
|
|
22
|
+
gitignore: true,
|
|
23
|
+
ignore,
|
|
24
|
+
absolute: true,
|
|
25
|
+
onlyFiles: true,
|
|
26
|
+
});
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const abs of matched) {
|
|
29
|
+
if (!DEFAULT_EXTENSIONS.includes(extname(abs)))
|
|
30
|
+
continue;
|
|
31
|
+
let source;
|
|
32
|
+
try {
|
|
33
|
+
source = readFileSync(abs, "utf8");
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
out.push({
|
|
39
|
+
absolutePath: abs,
|
|
40
|
+
filePath: posixPath(relative(opts.repoRoot, abs)),
|
|
41
|
+
extension: extname(abs),
|
|
42
|
+
source,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
//#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QACrC,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;QACD,GAAG,CAAC,IAAI,CAAC;YACP,YAAY,EAAE,GAAG;YACjB,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YACjD,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC;YACvB,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type BarrelReExport = {
|
|
2
|
+
kind: "star";
|
|
3
|
+
from: string;
|
|
4
|
+
} | {
|
|
5
|
+
kind: "named";
|
|
6
|
+
from: string;
|
|
7
|
+
names: Array<{
|
|
8
|
+
local: string;
|
|
9
|
+
exported: string;
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Extract top-level re-exports from a JS/TS source file. Returns only
|
|
14
|
+
* `export * from "X"`, `export * as NS from "X"`, and
|
|
15
|
+
* `export { ... } from "X"` declarations.
|
|
16
|
+
*
|
|
17
|
+
* Type-only re-exports (`export type { ... } from`) are skipped.
|
|
18
|
+
* Local declarations, side-effect imports, and dynamic exports are skipped.
|
|
19
|
+
*
|
|
20
|
+
* Returns [] on parse failure rather than throwing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseBarrelTopLevel(source: string): BarrelReExport[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
/**
|
|
3
|
+
* Extract top-level re-exports from a JS/TS source file. Returns only
|
|
4
|
+
* `export * from "X"`, `export * as NS from "X"`, and
|
|
5
|
+
* `export { ... } from "X"` declarations.
|
|
6
|
+
*
|
|
7
|
+
* Type-only re-exports (`export type { ... } from`) are skipped.
|
|
8
|
+
* Local declarations, side-effect imports, and dynamic exports are skipped.
|
|
9
|
+
*
|
|
10
|
+
* Returns [] on parse failure rather than throwing.
|
|
11
|
+
*/
|
|
12
|
+
export function parseBarrelTopLevel(source) {
|
|
13
|
+
let ast;
|
|
14
|
+
try {
|
|
15
|
+
ast = parse(source, {
|
|
16
|
+
sourceType: "module",
|
|
17
|
+
plugins: ["typescript", "jsx"],
|
|
18
|
+
errorRecovery: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const out = [];
|
|
25
|
+
for (const node of ast.program.body) {
|
|
26
|
+
if (node.type === "ExportAllDeclaration") {
|
|
27
|
+
out.push({ kind: "star", from: node.source.value });
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
31
|
+
// export { local } — no `from` clause, ignore (not a re-export).
|
|
32
|
+
if (!node.source)
|
|
33
|
+
continue;
|
|
34
|
+
// export type { ... } from — strip.
|
|
35
|
+
if (node.exportKind === "type")
|
|
36
|
+
continue;
|
|
37
|
+
// export * as NS from "X" — Babel parses this as ExportNamedDeclaration
|
|
38
|
+
// with a single ExportNamespaceSpecifier; treat it as a star re-export.
|
|
39
|
+
const onlySpec = node.specifiers[0];
|
|
40
|
+
if (node.specifiers.length === 1 && onlySpec?.type === "ExportNamespaceSpecifier") {
|
|
41
|
+
out.push({ kind: "star", from: node.source.value });
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const namesPart = [];
|
|
45
|
+
for (const spec of node.specifiers) {
|
|
46
|
+
if (spec.type !== "ExportSpecifier")
|
|
47
|
+
continue;
|
|
48
|
+
// Strip per-specifier `export type { Foo }`.
|
|
49
|
+
if (spec.exportKind === "type")
|
|
50
|
+
continue;
|
|
51
|
+
const local = spec.local.name;
|
|
52
|
+
const exported = spec.exported.type === "Identifier" ? spec.exported.name : spec.exported.value;
|
|
53
|
+
namesPart.push({ local, exported });
|
|
54
|
+
}
|
|
55
|
+
if (namesPart.length === 0)
|
|
56
|
+
continue;
|
|
57
|
+
out.push({ kind: "named", from: node.source.value, names: namesPart });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=barrel-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel-parser.js","sourceRoot":"","sources":["../../src/manifest/barrel-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAUtC;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,IAAI,GAA6B,CAAC;IAClC,IAAI,CAAC;QACH,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE;YAClB,UAAU,EAAE,QAAQ;YACpB,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC;YAC9B,aAAa,EAAE,IAAI;SACpB,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,GAAG,GAAqB,EAAE,CAAC;IACjC,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACpC,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;YACzC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YACpD,SAAS;QACX,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,wBAAwB,EAAE,CAAC;YAC3C,iEAAiE;YACjE,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,SAAS;YAC3B,oCAAoC;YACpC,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM;gBAAE,SAAS;YACzC,wEAAwE;YACxE,wEAAwE;YACxE,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACpC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,EAAE,IAAI,KAAK,0BAA0B,EAAE,CAAC;gBAClF,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;gBACpD,SAAS;YACX,CAAC;YACD,MAAM,SAAS,GAA+C,EAAE,CAAC;YACjE,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACnC,IAAI,IAAI,CAAC,IAAI,KAAK,iBAAiB;oBAAE,SAAS;gBAC9C,6CAA6C;gBAC7C,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM;oBAAE,SAAS;gBACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBAC9B,MAAM,QAAQ,GACZ,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;gBACjF,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;YACtC,CAAC;YACD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YACrC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ResolvedManifest } from "./resolver.js";
|
|
2
|
+
export type DiscoverManifestOptions = {
|
|
3
|
+
repoRoot: string;
|
|
4
|
+
packageName: string;
|
|
5
|
+
manifestSources: Record<string, string[]>;
|
|
6
|
+
};
|
|
7
|
+
export type DiscoveryDiagnostic = {
|
|
8
|
+
code: "no-manifest-found";
|
|
9
|
+
packageName: string;
|
|
10
|
+
} | {
|
|
11
|
+
code: "untraceable-barrel";
|
|
12
|
+
packageName: string;
|
|
13
|
+
resolvedFile: string;
|
|
14
|
+
} | {
|
|
15
|
+
code: "cycle-detected";
|
|
16
|
+
packageName: string;
|
|
17
|
+
file: string;
|
|
18
|
+
};
|
|
19
|
+
export type DiscoveryResult = {
|
|
20
|
+
manifest: ResolvedManifest | null;
|
|
21
|
+
diagnostics: DiscoveryDiagnostic[];
|
|
22
|
+
};
|
|
23
|
+
export declare function discoverManifest(opts: DiscoverManifestOptions): ResolvedManifest | null;
|
|
24
|
+
export declare function discoverManifestWithDiagnostics(opts: DiscoverManifestOptions): DiscoveryResult;
|