@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,69 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
export function resolveCommitSha(cwd) {
|
|
3
|
+
try {
|
|
4
|
+
return execFileSync("git", ["rev-parse", "HEAD"], {
|
|
5
|
+
cwd,
|
|
6
|
+
encoding: "utf8",
|
|
7
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
8
|
+
}).trim();
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function resolveBranch(cwd) {
|
|
15
|
+
try {
|
|
16
|
+
const branch = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
17
|
+
cwd,
|
|
18
|
+
encoding: "utf8",
|
|
19
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
20
|
+
}).trim();
|
|
21
|
+
if (branch === "HEAD")
|
|
22
|
+
return null;
|
|
23
|
+
return branch;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function resolveOriginRemote(cwd) {
|
|
30
|
+
try {
|
|
31
|
+
const url = execFileSync("git", ["remote", "get-url", "origin"], {
|
|
32
|
+
cwd,
|
|
33
|
+
encoding: "utf8",
|
|
34
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
35
|
+
}).trim();
|
|
36
|
+
return parseRemoteUrl(url);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Normalise a git remote URL to `host/owner/repo` form (no `.git` suffix).
|
|
44
|
+
* Accepts:
|
|
45
|
+
* - https://github.com/owner/repo.git
|
|
46
|
+
* - https://github.com/owner/repo
|
|
47
|
+
* - git@github.com:owner/repo.git
|
|
48
|
+
* - ssh://git@github.com/owner/repo.git
|
|
49
|
+
* - ssh://git@github.com:22/owner/repo.git
|
|
50
|
+
*/
|
|
51
|
+
export function parseRemoteUrl(url) {
|
|
52
|
+
const trimmed = url.trim();
|
|
53
|
+
if (!trimmed)
|
|
54
|
+
return null;
|
|
55
|
+
// ssh://git@host[:port]/owner/repo(.git)?
|
|
56
|
+
const sshProto = trimmed.match(/^ssh:\/\/(?:[^@]+@)?([^/:]+)(?::\d+)?\/([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
57
|
+
if (sshProto)
|
|
58
|
+
return `${sshProto[1]}/${sshProto[2]}/${sshProto[3]}`;
|
|
59
|
+
// https://host/owner/repo(.git)?
|
|
60
|
+
const https = trimmed.match(/^https?:\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
61
|
+
if (https)
|
|
62
|
+
return `${https[1]}/${https[2]}/${https[3]}`;
|
|
63
|
+
// git@host:owner/repo(.git)?
|
|
64
|
+
const scp = trimmed.match(/^[^@]+@([^/:]+):([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
65
|
+
if (scp)
|
|
66
|
+
return `${scp[1]}/${scp[2]}/${scp[3]}`;
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/envelope/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE;YAChD,GAAG;YACH,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC;SACpC,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE;YACxE,GAAG;YACH,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC;SACpC,CAAC,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,MAAM,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QACnC,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAW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 -0,0 +1,10 @@
|
|
|
1
|
+
import type { ScanEnvelope } from "@component-compass/plugin-core";
|
|
2
|
+
export type BuildEnvelopeOptions = {
|
|
3
|
+
cwd: string;
|
|
4
|
+
cliRepoIdFlag?: string | undefined;
|
|
5
|
+
/** Path to @component-compass/cli's own package.json directory. Optional;
|
|
6
|
+
* defaults to the CLI package root resolved via `import.meta.url`. */
|
|
7
|
+
packageRoot?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function buildScanEnvelope(opts: BuildEnvelopeOptions): ScanEnvelope;
|
|
10
|
+
export declare function readToolVersion(packageRoot: string): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { ulid } from "ulid";
|
|
5
|
+
import { resolveBranch, resolveCommitSha } from "./git.js";
|
|
6
|
+
import { resolveRepoId } from "./repo-id.js";
|
|
7
|
+
export function buildScanEnvelope(opts) {
|
|
8
|
+
const { value: repoId } = resolveRepoId({
|
|
9
|
+
cwd: opts.cwd,
|
|
10
|
+
cliFlag: opts.cliRepoIdFlag,
|
|
11
|
+
// biome-ignore lint/complexity/useLiteralKeys: tsconfig noPropertyAccessFromIndexSignature requires bracket access on process.env
|
|
12
|
+
envOverride: process.env["COMPONENT_COMPASS_REPO_ID"],
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
scanId: ulid(),
|
|
16
|
+
repoId,
|
|
17
|
+
commitSha: resolveCommitSha(opts.cwd),
|
|
18
|
+
branch: resolveBranch(opts.cwd),
|
|
19
|
+
timestamp: new Date().toISOString(),
|
|
20
|
+
toolVersion: readToolVersion(opts.packageRoot ?? defaultPackageRoot()),
|
|
21
|
+
cwd: opts.cwd,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function readToolVersion(packageRoot) {
|
|
25
|
+
try {
|
|
26
|
+
const pkg = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
27
|
+
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return "0.0.0";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Walk up from this module's directory until we find a `package.json` whose
|
|
35
|
+
* `name` is `@component-compass/cli`. Robust to running from `dist/` or `src/`
|
|
36
|
+
* (vitest) without hardcoding a relative depth.
|
|
37
|
+
*/
|
|
38
|
+
function defaultPackageRoot() {
|
|
39
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
40
|
+
for (let i = 0; i < 6; i++) {
|
|
41
|
+
const candidate = join(dir, "package.json");
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(readFileSync(candidate, "utf8"));
|
|
44
|
+
if (parsed.name === "@component-compass/cli")
|
|
45
|
+
return dir;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// continue walking
|
|
49
|
+
}
|
|
50
|
+
const parent = resolve(dir, "..");
|
|
51
|
+
if (parent === dir)
|
|
52
|
+
break;
|
|
53
|
+
dir = parent;
|
|
54
|
+
}
|
|
55
|
+
return dirname(fileURLToPath(import.meta.url));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/envelope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM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AAS,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAuB,CAAC;YACjF,IAAI,MAAM,CAAC,IAAI,KAAK,wBAAwB;gBAAE,OAAO,GAAG,CAAC;QAC3D,CAAC;QAAC,MAAM,CAAC;YACP,mBAAmB;QACrB,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,MAAM,KAAK,GAAG;YAAE,MAAM;QAC1B,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;IACD,OAAO,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type RepoIdSource = "flag" | "env" | "git" | "package" | "hash";
|
|
2
|
+
export type ResolveRepoIdOptions = {
|
|
3
|
+
cwd: string;
|
|
4
|
+
cliFlag?: string | undefined;
|
|
5
|
+
envOverride?: string | undefined;
|
|
6
|
+
};
|
|
7
|
+
export type ResolvedRepoId = {
|
|
8
|
+
value: string;
|
|
9
|
+
source: RepoIdSource;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the repository identifier used in the scan envelope.
|
|
13
|
+
* Priority: CLI flag > env var > git origin remote > package.json name >
|
|
14
|
+
* deterministic hash of `cwd`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveRepoId(opts: ResolveRepoIdOptions): ResolvedRepoId;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { resolveOriginRemote } from "./git.js";
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the repository identifier used in the scan envelope.
|
|
7
|
+
* Priority: CLI flag > env var > git origin remote > package.json name >
|
|
8
|
+
* deterministic hash of `cwd`.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveRepoId(opts) {
|
|
11
|
+
if (opts.cliFlag && opts.cliFlag.length > 0) {
|
|
12
|
+
return { value: opts.cliFlag, source: "flag" };
|
|
13
|
+
}
|
|
14
|
+
if (opts.envOverride && opts.envOverride.length > 0) {
|
|
15
|
+
return { value: opts.envOverride, source: "env" };
|
|
16
|
+
}
|
|
17
|
+
const remote = resolveOriginRemote(opts.cwd);
|
|
18
|
+
if (remote)
|
|
19
|
+
return { value: remote, source: "git" };
|
|
20
|
+
const pkgName = readPackageName(opts.cwd);
|
|
21
|
+
if (pkgName)
|
|
22
|
+
return { value: pkgName, source: "package" };
|
|
23
|
+
const hash = createHash("sha1").update(opts.cwd).digest("hex").slice(0, 12);
|
|
24
|
+
return { value: `repo-hash-${hash}`, source: "hash" };
|
|
25
|
+
}
|
|
26
|
+
function readPackageName(cwd) {
|
|
27
|
+
const pkgPath = join(cwd, "package.json");
|
|
28
|
+
if (!existsSync(pkgPath))
|
|
29
|
+
return null;
|
|
30
|
+
try {
|
|
31
|
+
const parsed = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
32
|
+
if (typeof parsed.name === "string" && parsed.name.length > 0)
|
|
33
|
+
return parsed.name;
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=repo-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-id.js","sourceRoot":"","sources":["../../src/envelope/repo-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC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AI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAuB,CAAC;QAC/E,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,MAAM,CAAC,IAAI,CAAC;QAClF,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three-lane identity derivation + stable id keying.
|
|
3
|
+
*
|
|
4
|
+
* Two pure functions that translate a per-occurrence `ComponentId + via +
|
|
5
|
+
* derivedTags + repoId` tuple into the rolled-up `OutputIdentity` and a
|
|
6
|
+
* deterministic short hash used as the component's `id` in the emitted
|
|
7
|
+
* artifact.
|
|
8
|
+
*
|
|
9
|
+
* Lanes (scope):
|
|
10
|
+
* - "local" — `componentId.source.type === "local"`. Siloed per
|
|
11
|
+
* `{repoId, filePath, exportName, kind}` so two consumer
|
|
12
|
+
* repos with locally-named components don't collide.
|
|
13
|
+
* - "ds" — externally-sourced AND `derivedTags.length > 0` (i.e.
|
|
14
|
+
* matched the workspace's tag rules — the "design system"
|
|
15
|
+
* you're tracking).
|
|
16
|
+
* - "external" — externally-sourced with no tag matches (third-party noise).
|
|
17
|
+
*
|
|
18
|
+
* Stable-id key composition:
|
|
19
|
+
* - local → `local::<repoId>::<filePath>::<exportName>::<kind>`
|
|
20
|
+
* - ds | external custom-element → `ce::<packageName>::<tagName>`
|
|
21
|
+
* - ds | external react/vue → `rc::<packageName>::<exportName>`
|
|
22
|
+
* Hashed with SHA-1, truncated to 16 hex chars.
|
|
23
|
+
*
|
|
24
|
+
* NOT yet wired into the scan pipeline — wiring is a separate task.
|
|
25
|
+
*/
|
|
26
|
+
import type { ComponentId, OccurrenceVia, OutputIdentity } from "@component-compass/plugin-core";
|
|
27
|
+
export type IdentityInputs = {
|
|
28
|
+
componentId: ComponentId;
|
|
29
|
+
via: OccurrenceVia;
|
|
30
|
+
derivedTags: readonly string[];
|
|
31
|
+
repoId: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function computeOutputIdentity(inputs: IdentityInputs): OutputIdentity;
|
|
34
|
+
export declare function computeStableId(identity: OutputIdentity): string;
|
|
35
|
+
/**
|
|
36
|
+
* Produce the same stable id as `computeStableId` from a raw `ComponentId`
|
|
37
|
+
* (as emitted by parsers), without needing to first build an `OutputIdentity`.
|
|
38
|
+
*
|
|
39
|
+
* This is used in `occurrences.ts` so that occurrence `componentId` fields
|
|
40
|
+
* hash-match the `id` values produced by `buildComponentSeeds` → `rollupOccurrencesToComponents`
|
|
41
|
+
* can correctly correlate occurrences to seeds.
|
|
42
|
+
*
|
|
43
|
+
* For local components, `repoId` is absent from the `ComponentId` source, so
|
|
44
|
+
* we use `""` — matching the `repoId: ""` convention in `buildComponentSeeds`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function computeStableIdFromComponentId(c: ComponentId): string;
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three-lane identity derivation + stable id keying.
|
|
3
|
+
*
|
|
4
|
+
* Two pure functions that translate a per-occurrence `ComponentId + via +
|
|
5
|
+
* derivedTags + repoId` tuple into the rolled-up `OutputIdentity` and a
|
|
6
|
+
* deterministic short hash used as the component's `id` in the emitted
|
|
7
|
+
* artifact.
|
|
8
|
+
*
|
|
9
|
+
* Lanes (scope):
|
|
10
|
+
* - "local" — `componentId.source.type === "local"`. Siloed per
|
|
11
|
+
* `{repoId, filePath, exportName, kind}` so two consumer
|
|
12
|
+
* repos with locally-named components don't collide.
|
|
13
|
+
* - "ds" — externally-sourced AND `derivedTags.length > 0` (i.e.
|
|
14
|
+
* matched the workspace's tag rules — the "design system"
|
|
15
|
+
* you're tracking).
|
|
16
|
+
* - "external" — externally-sourced with no tag matches (third-party noise).
|
|
17
|
+
*
|
|
18
|
+
* Stable-id key composition:
|
|
19
|
+
* - local → `local::<repoId>::<filePath>::<exportName>::<kind>`
|
|
20
|
+
* - ds | external custom-element → `ce::<packageName>::<tagName>`
|
|
21
|
+
* - ds | external react/vue → `rc::<packageName>::<exportName>`
|
|
22
|
+
* Hashed with SHA-1, truncated to 16 hex chars.
|
|
23
|
+
*
|
|
24
|
+
* NOT yet wired into the scan pipeline — wiring is a separate task.
|
|
25
|
+
*/
|
|
26
|
+
import { createHash } from "node:crypto";
|
|
27
|
+
export function computeOutputIdentity(inputs) {
|
|
28
|
+
const { componentId, via, derivedTags, repoId } = inputs;
|
|
29
|
+
const { source, kind } = componentId;
|
|
30
|
+
const isLocal = source.type === "local";
|
|
31
|
+
const scope = isLocal
|
|
32
|
+
? "local"
|
|
33
|
+
: derivedTags.length > 0
|
|
34
|
+
? "ds"
|
|
35
|
+
: "external";
|
|
36
|
+
const identity = {
|
|
37
|
+
scope,
|
|
38
|
+
kind,
|
|
39
|
+
via: { kind: via.kind },
|
|
40
|
+
};
|
|
41
|
+
if (source.type === "external") {
|
|
42
|
+
identity.packageName = source.package;
|
|
43
|
+
}
|
|
44
|
+
if (componentId.kind === "custom-element") {
|
|
45
|
+
identity.tagName = componentId.tagName;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// react-component | vue-component
|
|
49
|
+
identity.exportName = componentId.export;
|
|
50
|
+
}
|
|
51
|
+
if (isLocal && source.type === "local") {
|
|
52
|
+
identity.repoId = repoId;
|
|
53
|
+
identity.filePath = source.filePath;
|
|
54
|
+
}
|
|
55
|
+
return identity;
|
|
56
|
+
}
|
|
57
|
+
const sha1Short = (s) => createHash("sha1").update(s).digest("hex").slice(0, 16);
|
|
58
|
+
export function computeStableId(identity) {
|
|
59
|
+
if (identity.scope === "local") {
|
|
60
|
+
return sha1Short(`local::${identity.repoId}::${identity.filePath}::${identity.exportName}::${identity.kind}`);
|
|
61
|
+
}
|
|
62
|
+
if (identity.kind === "custom-element") {
|
|
63
|
+
return sha1Short(`ce::${identity.packageName}::${identity.tagName}`);
|
|
64
|
+
}
|
|
65
|
+
return sha1Short(`rc::${identity.packageName}::${identity.exportName}`);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Produce the same stable id as `computeStableId` from a raw `ComponentId`
|
|
69
|
+
* (as emitted by parsers), without needing to first build an `OutputIdentity`.
|
|
70
|
+
*
|
|
71
|
+
* This is used in `occurrences.ts` so that occurrence `componentId` fields
|
|
72
|
+
* hash-match the `id` values produced by `buildComponentSeeds` → `rollupOccurrencesToComponents`
|
|
73
|
+
* can correctly correlate occurrences to seeds.
|
|
74
|
+
*
|
|
75
|
+
* For local components, `repoId` is absent from the `ComponentId` source, so
|
|
76
|
+
* we use `""` — matching the `repoId: ""` convention in `buildComponentSeeds`.
|
|
77
|
+
*/
|
|
78
|
+
export function computeStableIdFromComponentId(c) {
|
|
79
|
+
if (c.source.type === "local") {
|
|
80
|
+
const exportOrTag = c.kind === "custom-element" ? c.tagName : c.export;
|
|
81
|
+
// repoId is not carried on ComponentId.source; use "" to match the
|
|
82
|
+
// repoId: "" convention in buildComponentSeeds (seeds for local
|
|
83
|
+
// components are keyed the same way).
|
|
84
|
+
return sha1Short(`local::::${c.source.filePath}::${exportOrTag}::${c.kind}`);
|
|
85
|
+
}
|
|
86
|
+
const pkg = c.source.type === "external" ? c.source.package : "unknown";
|
|
87
|
+
if (c.kind === "custom-element") {
|
|
88
|
+
return sha1Short(`ce::${pkg}::${c.tagName}`);
|
|
89
|
+
}
|
|
90
|
+
return sha1Short(`rc::${pkg}::${c.export}`);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAA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S,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
import { traverse } from "@component-compass/ast-utils";
|
|
3
|
+
const REACT_EXTS = new Set([".tsx", ".jsx", ".ts", ".js"]);
|
|
4
|
+
export function detectReactComponents(source, filePath, extension) {
|
|
5
|
+
if (!REACT_EXTS.has(extension))
|
|
6
|
+
return [];
|
|
7
|
+
const ast = (() => {
|
|
8
|
+
try {
|
|
9
|
+
return parse(source, {
|
|
10
|
+
sourceType: "module",
|
|
11
|
+
plugins: ["typescript", "jsx", "decorators-legacy", "classProperties"],
|
|
12
|
+
errorRecovery: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
})();
|
|
19
|
+
if (!ast)
|
|
20
|
+
return [];
|
|
21
|
+
const found = [];
|
|
22
|
+
const filePathSource = { type: "local", filePath };
|
|
23
|
+
traverse(ast, {
|
|
24
|
+
ExportDefaultDeclaration(path) {
|
|
25
|
+
const decl = path.node.declaration;
|
|
26
|
+
if (decl.type === "FunctionDeclaration" && decl.id && isPascalCase(decl.id.name) && returnsJsx(decl)) {
|
|
27
|
+
found.push({
|
|
28
|
+
componentId: { kind: "react-component", export: decl.id.name, source: filePathSource },
|
|
29
|
+
exportName: decl.id.name,
|
|
30
|
+
isDefault: true,
|
|
31
|
+
detector: "react-default-fn",
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (decl.type === "ClassDeclaration" &&
|
|
35
|
+
decl.id &&
|
|
36
|
+
isPascalCase(decl.id.name) &&
|
|
37
|
+
extendsReactClass(decl)) {
|
|
38
|
+
found.push({
|
|
39
|
+
componentId: { kind: "react-component", export: decl.id.name, source: filePathSource },
|
|
40
|
+
exportName: decl.id.name,
|
|
41
|
+
isDefault: true,
|
|
42
|
+
detector: "react-class",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
ExportNamedDeclaration(path) {
|
|
47
|
+
const decl = path.node.declaration;
|
|
48
|
+
if (!decl)
|
|
49
|
+
return;
|
|
50
|
+
if (decl.type === "FunctionDeclaration" && decl.id && isPascalCase(decl.id.name) && returnsJsx(decl)) {
|
|
51
|
+
found.push({
|
|
52
|
+
componentId: { kind: "react-component", export: decl.id.name, source: filePathSource },
|
|
53
|
+
exportName: decl.id.name,
|
|
54
|
+
isDefault: false,
|
|
55
|
+
detector: "react-default-fn",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (decl.type === "VariableDeclaration") {
|
|
59
|
+
for (const d of decl.declarations) {
|
|
60
|
+
if (d.id.type !== "Identifier" || !isPascalCase(d.id.name) || !d.init)
|
|
61
|
+
continue;
|
|
62
|
+
const detector = classifyVariableInit(d.init);
|
|
63
|
+
if (detector) {
|
|
64
|
+
found.push({
|
|
65
|
+
componentId: { kind: "react-component", export: d.id.name, source: filePathSource },
|
|
66
|
+
exportName: d.id.name,
|
|
67
|
+
isDefault: false,
|
|
68
|
+
detector,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
function isPascalCase(name) {
|
|
78
|
+
return /^[A-Z]/.test(name);
|
|
79
|
+
}
|
|
80
|
+
function returnsJsx(fn) {
|
|
81
|
+
if (fn.type === "ArrowFunctionExpression" && fn.body.type !== "BlockStatement") {
|
|
82
|
+
return isJsxNode(fn.body);
|
|
83
|
+
}
|
|
84
|
+
const block = fn.body;
|
|
85
|
+
if (!block || block.type !== "BlockStatement")
|
|
86
|
+
return false;
|
|
87
|
+
return block.body.some((stmt) => stmt.type === "ReturnStatement" && stmt.argument != null && isJsxNode(stmt.argument));
|
|
88
|
+
}
|
|
89
|
+
function isJsxNode(node) {
|
|
90
|
+
if (node.type === "JSXElement" || node.type === "JSXFragment")
|
|
91
|
+
return true;
|
|
92
|
+
if (node.type === "ConditionalExpression")
|
|
93
|
+
return isJsxNode(node.consequent) || isJsxNode(node.alternate);
|
|
94
|
+
if (node.type === "LogicalExpression")
|
|
95
|
+
return isJsxNode(node.right);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
function extendsReactClass(decl) {
|
|
99
|
+
const sup = decl.superClass;
|
|
100
|
+
if (!sup)
|
|
101
|
+
return false;
|
|
102
|
+
if (sup.type === "Identifier") {
|
|
103
|
+
return sup.name === "Component" || sup.name === "PureComponent";
|
|
104
|
+
}
|
|
105
|
+
if (sup.type === "MemberExpression" && sup.object.type === "Identifier" && sup.object.name === "React") {
|
|
106
|
+
return (sup.property.type === "Identifier" &&
|
|
107
|
+
(sup.property.name === "Component" || sup.property.name === "PureComponent"));
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
function classifyVariableInit(init) {
|
|
112
|
+
if (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression")
|
|
113
|
+
return "react-arrow";
|
|
114
|
+
if (init.type === "CallExpression") {
|
|
115
|
+
const callee = init.callee;
|
|
116
|
+
let calleeName;
|
|
117
|
+
if (callee.type === "Identifier")
|
|
118
|
+
calleeName = callee.name;
|
|
119
|
+
else if (callee.type === "MemberExpression" && callee.property.type === "Identifier")
|
|
120
|
+
calleeName = callee.property.name;
|
|
121
|
+
if (calleeName === "forwardRef")
|
|
122
|
+
return "react-forward-ref";
|
|
123
|
+
if (calleeName === "memo")
|
|
124
|
+
return "react-memo";
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=detect-react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-react.js","sourceRoot":"","sources":["../../src/local-index/detect-react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAE3D,MAAM,UAAU,qBAAqB,CAAC,MAAc,EAAE,QAAgB,EAAE,SAAiB;IACvF,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC;QAAE,OAAO,EAAE,CAAC;IAC1C,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,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,CAAC;gBACtE,aAAa,EAAE,IAAI;aACpB,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IACL,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IAEpB,MAAM,KAAK,GAAsB,EAAE,CAAC;IACpC,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,OAAgB,EAAE,QAAQ,EAAE,CAAC;IAE5D,QAAQ,CAAC,GAAG,EAAE;QACZ,wBAAwB,CAAC,IAAI;YAC3B,MAAM,IAAI,GAAG,IAAI,CAA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