@component-compass/cli 0.1.22 → 0.1.24

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.
Files changed (217) hide show
  1. package/dist/cli.js +103503 -104
  2. package/package.json +21 -25
  3. package/dist/auth/browser.d.ts +0 -13
  4. package/dist/auth/browser.js +0 -21
  5. package/dist/auth/browser.js.map +0 -1
  6. package/dist/auth/client.d.ts +0 -48
  7. package/dist/auth/client.js +0 -89
  8. package/dist/auth/client.js.map +0 -1
  9. package/dist/auth/paths.d.ts +0 -2
  10. package/dist/auth/paths.js +0 -14
  11. package/dist/auth/paths.js.map +0 -1
  12. package/dist/auth/session.d.ts +0 -38
  13. package/dist/auth/session.js +0 -88
  14. package/dist/auth/session.js.map +0 -1
  15. package/dist/auth/store.d.ts +0 -16
  16. package/dist/auth/store.js +0 -37
  17. package/dist/auth/store.js.map +0 -1
  18. package/dist/auth/upload-auth.d.ts +0 -22
  19. package/dist/auth/upload-auth.js +0 -51
  20. package/dist/auth/upload-auth.js.map +0 -1
  21. package/dist/cli/help.d.ts +0 -4
  22. package/dist/cli/help.js +0 -52
  23. package/dist/cli/help.js.map +0 -1
  24. package/dist/cli/parse.d.ts +0 -14
  25. package/dist/cli/parse.js +0 -75
  26. package/dist/cli/parse.js.map +0 -1
  27. package/dist/cli/suggest.d.ts +0 -4
  28. package/dist/cli/suggest.js +0 -38
  29. package/dist/cli/suggest.js.map +0 -1
  30. package/dist/cli.d.ts +0 -2
  31. package/dist/cli.js.map +0 -1
  32. package/dist/commands/auth.d.ts +0 -33
  33. package/dist/commands/auth.js +0 -248
  34. package/dist/commands/auth.js.map +0 -1
  35. package/dist/commands/init.d.ts +0 -11
  36. package/dist/commands/init.js +0 -112
  37. package/dist/commands/init.js.map +0 -1
  38. package/dist/commands/scan.d.ts +0 -33
  39. package/dist/commands/scan.js +0 -745
  40. package/dist/commands/scan.js.map +0 -1
  41. package/dist/composition-rollup.d.ts +0 -23
  42. package/dist/composition-rollup.js +0 -64
  43. package/dist/composition-rollup.js.map +0 -1
  44. package/dist/config/loader.d.ts +0 -6
  45. package/dist/config/loader.js +0 -71
  46. package/dist/config/loader.js.map +0 -1
  47. package/dist/config/schema.d.ts +0 -18
  48. package/dist/config/schema.js +0 -15
  49. package/dist/config/schema.js.map +0 -1
  50. package/dist/dispatcher.d.ts +0 -8
  51. package/dist/dispatcher.js +0 -22
  52. package/dist/dispatcher.js.map +0 -1
  53. package/dist/envelope/git.d.ts +0 -13
  54. package/dist/envelope/git.js +0 -69
  55. package/dist/envelope/git.js.map +0 -1
  56. package/dist/envelope/index.d.ts +0 -1
  57. package/dist/envelope/index.js +0 -12
  58. package/dist/envelope/index.js.map +0 -1
  59. package/dist/envelope/repo-id.d.ts +0 -16
  60. package/dist/envelope/repo-id.js +0 -40
  61. package/dist/envelope/repo-id.js.map +0 -1
  62. package/dist/identity.d.ts +0 -56
  63. package/dist/identity.js +0 -115
  64. package/dist/identity.js.map +0 -1
  65. package/dist/index.d.ts +0 -3
  66. package/dist/index.js +0 -3
  67. package/dist/index.js.map +0 -1
  68. package/dist/local-index/declared-props.d.ts +0 -15
  69. package/dist/local-index/declared-props.js +0 -101
  70. package/dist/local-index/declared-props.js.map +0 -1
  71. package/dist/local-index/detect-react.d.ts +0 -3
  72. package/dist/local-index/detect-react.js +0 -378
  73. package/dist/local-index/detect-react.js.map +0 -1
  74. package/dist/local-index/detect-vue.d.ts +0 -16
  75. package/dist/local-index/detect-vue.js +0 -284
  76. package/dist/local-index/detect-vue.js.map +0 -1
  77. package/dist/local-index/detect-wc.d.ts +0 -8
  78. package/dist/local-index/detect-wc.js +0 -70
  79. package/dist/local-index/detect-wc.js.map +0 -1
  80. package/dist/local-index/index.d.ts +0 -14
  81. package/dist/local-index/index.js +0 -46
  82. package/dist/local-index/index.js.map +0 -1
  83. package/dist/local-index/types.d.ts +0 -2
  84. package/dist/local-index/types.js +0 -2
  85. package/dist/local-index/types.js.map +0 -1
  86. package/dist/manifest/barrel-parser.d.ts +0 -35
  87. package/dist/manifest/barrel-parser.js +0 -76
  88. package/dist/manifest/barrel-parser.js.map +0 -1
  89. package/dist/manifest/lazy-resolver.d.ts +0 -123
  90. package/dist/manifest/lazy-resolver.js +0 -712
  91. package/dist/manifest/lazy-resolver.js.map +0 -1
  92. package/dist/occurrences.d.ts +0 -15
  93. package/dist/occurrences.js +0 -101
  94. package/dist/occurrences.js.map +0 -1
  95. package/dist/parse-by-ext.d.ts +0 -21
  96. package/dist/parse-by-ext.js +0 -53
  97. package/dist/parse-by-ext.js.map +0 -1
  98. package/dist/prompts/adapter.d.ts +0 -43
  99. package/dist/prompts/adapter.js +0 -32
  100. package/dist/prompts/adapter.js.map +0 -1
  101. package/dist/reporter/index.d.ts +0 -39
  102. package/dist/reporter/index.js +0 -144
  103. package/dist/reporter/index.js.map +0 -1
  104. package/dist/reporter/json.d.ts +0 -6
  105. package/dist/reporter/json.js +0 -11
  106. package/dist/reporter/json.js.map +0 -1
  107. package/dist/reporter/stdout.d.ts +0 -3
  108. package/dist/reporter/stdout.js +0 -41
  109. package/dist/reporter/stdout.js.map +0 -1
  110. package/dist/rollup.d.ts +0 -26
  111. package/dist/rollup.js +0 -135
  112. package/dist/rollup.js.map +0 -1
  113. package/dist/scan/cem-index.d.ts +0 -38
  114. package/dist/scan/cem-index.js +0 -139
  115. package/dist/scan/cem-index.js.map +0 -1
  116. package/dist/scan/entry-packages.d.ts +0 -42
  117. package/dist/scan/entry-packages.js +0 -87
  118. package/dist/scan/entry-packages.js.map +0 -1
  119. package/dist/scan/framework-root.d.ts +0 -1
  120. package/dist/scan/framework-root.js +0 -22
  121. package/dist/scan/framework-root.js.map +0 -1
  122. package/dist/scan/git-mtime.d.ts +0 -2
  123. package/dist/scan/git-mtime.js +0 -22
  124. package/dist/scan/git-mtime.js.map +0 -1
  125. package/dist/scan/global-components.d.ts +0 -37
  126. package/dist/scan/global-components.js +0 -228
  127. package/dist/scan/global-components.js.map +0 -1
  128. package/dist/scan/meta.d.ts +0 -5
  129. package/dist/scan/meta.js +0 -58
  130. package/dist/scan/meta.js.map +0 -1
  131. package/dist/scan/stamp-version.d.ts +0 -18
  132. package/dist/scan/stamp-version.js +0 -94
  133. package/dist/scan/stamp-version.js.map +0 -1
  134. package/dist/scan/wrap-relationships.d.ts +0 -12
  135. package/dist/scan/wrap-relationships.js +0 -38
  136. package/dist/scan/wrap-relationships.js.map +0 -1
  137. package/dist/seeds.d.ts +0 -81
  138. package/dist/seeds.js +0 -258
  139. package/dist/seeds.js.map +0 -1
  140. package/dist/types/brand.d.ts +0 -11
  141. package/dist/types/brand.js +0 -5
  142. package/dist/types/brand.js.map +0 -1
  143. package/dist/types/component-id.d.ts +0 -2
  144. package/dist/types/component-id.js +0 -2
  145. package/dist/types/component-id.js.map +0 -1
  146. package/dist/types.d.ts +0 -13
  147. package/dist/types.js +0 -2
  148. package/dist/types.js.map +0 -1
  149. package/dist/upload.d.ts +0 -18
  150. package/dist/upload.js +0 -34
  151. package/dist/upload.js.map +0 -1
  152. package/dist/util/color.d.ts +0 -24
  153. package/dist/util/color.js +0 -45
  154. package/dist/util/color.js.map +0 -1
  155. package/dist/util/git.d.ts +0 -10
  156. package/dist/util/git.js +0 -95
  157. package/dist/util/git.js.map +0 -1
  158. package/dist/util/interactive.d.ts +0 -17
  159. package/dist/util/interactive.js +0 -19
  160. package/dist/util/interactive.js.map +0 -1
  161. package/dist/util/log.d.ts +0 -9
  162. package/dist/util/log.js +0 -20
  163. package/dist/util/log.js.map +0 -1
  164. package/dist/util/pkg.d.ts +0 -1
  165. package/dist/util/pkg.js +0 -13
  166. package/dist/util/pkg.js.map +0 -1
  167. package/dist/util/pnp-check.d.ts +0 -1
  168. package/dist/util/pnp-check.js +0 -6
  169. package/dist/util/pnp-check.js.map +0 -1
  170. package/dist/util/posix.d.ts +0 -2
  171. package/dist/util/posix.js +0 -15
  172. package/dist/util/posix.js.map +0 -1
  173. package/dist/util/progress.d.ts +0 -21
  174. package/dist/util/progress.js +0 -54
  175. package/dist/util/progress.js.map +0 -1
  176. package/dist/util/version.d.ts +0 -7
  177. package/dist/util/version.js +0 -13
  178. package/dist/util/version.js.map +0 -1
  179. package/dist/walker/bounded-definition-resolver.d.ts +0 -9
  180. package/dist/walker/bounded-definition-resolver.js +0 -125
  181. package/dist/walker/bounded-definition-resolver.js.map +0 -1
  182. package/dist/walker/files.d.ts +0 -7
  183. package/dist/walker/files.js +0 -24
  184. package/dist/walker/files.js.map +0 -1
  185. package/dist/walker/package-alias-layers.d.ts +0 -7
  186. package/dist/walker/package-alias-layers.js +0 -40
  187. package/dist/walker/package-alias-layers.js.map +0 -1
  188. package/dist/walker/resolve-import.d.ts +0 -25
  189. package/dist/walker/resolve-import.js +0 -243
  190. package/dist/walker/resolve-import.js.map +0 -1
  191. package/dist/walker/tsconfig-discovery.d.ts +0 -36
  192. package/dist/walker/tsconfig-discovery.js +0 -52
  193. package/dist/walker/tsconfig-discovery.js.map +0 -1
  194. package/dist/walker/tsconfig-loader.d.ts +0 -35
  195. package/dist/walker/tsconfig-loader.js +0 -138
  196. package/dist/walker/tsconfig-loader.js.map +0 -1
  197. package/dist/walker/workspace-exports.d.ts +0 -3
  198. package/dist/walker/workspace-exports.js +0 -120
  199. package/dist/walker/workspace-exports.js.map +0 -1
  200. package/dist/workspace/build-graph.d.ts +0 -15
  201. package/dist/workspace/build-graph.js +0 -120
  202. package/dist/workspace/build-graph.js.map +0 -1
  203. package/dist/workspace/declared-deps.d.ts +0 -5
  204. package/dist/workspace/declared-deps.js +0 -42
  205. package/dist/workspace/declared-deps.js.map +0 -1
  206. package/dist/workspace/find-owning-package.d.ts +0 -8
  207. package/dist/workspace/find-owning-package.js +0 -69
  208. package/dist/workspace/find-owning-package.js.map +0 -1
  209. package/dist/workspace/find-workspace-root.d.ts +0 -1
  210. package/dist/workspace/find-workspace-root.js +0 -60
  211. package/dist/workspace/find-workspace-root.js.map +0 -1
  212. package/dist/workspace/index.d.ts +0 -4
  213. package/dist/workspace/index.js +0 -4
  214. package/dist/workspace/index.js.map +0 -1
  215. package/dist/workspace/types.d.ts +0 -49
  216. package/dist/workspace/types.js +0 -13
  217. package/dist/workspace/types.js.map +0 -1
package/dist/identity.js DELETED
@@ -1,115 +0,0 @@
1
- /**
2
- * Two-lane identity derivation + stable id keying.
3
- *
4
- * Two pure functions that translate a per-occurrence `ComponentId + repoId`
5
- * tuple into the rolled-up `OutputIdentity` and a deterministic short hash
6
- * used as the component's `id` in the emitted artifact.
7
- *
8
- * Lanes (scope):
9
- * - "local" — `componentId.source.type === "local"`. Siloed per
10
- * `{repoId, filePath, exportName, kind}` so two consumer
11
- * repos with locally-named components don't collide.
12
- * - "external" — externally-sourced (ds/external grouping is the web app's
13
- * responsibility, not CC's).
14
- *
15
- * Stable-id key composition:
16
- * - local → `local::<repoId>::<filePath>::<exportName>::<kind>`
17
- * - custom-element, no modulePath (byTag) → `ce::<packageName>::<tagName>`
18
- * - custom-element, with modulePath (resolver folded WC) → `ce::<packageName>::<modulePath>::<tagName>`
19
- * - react/vue, no modulePath (from import specifier) → `rc::<packageName>::<exportName>`
20
- * - react/vue, with modulePath (resolver-driven) → `rc::<packageName>::<modulePath>::<exportName>`
21
- * Hashed with SHA-1, truncated to 16 hex chars.
22
- */
23
- import { createHash } from "node:crypto";
24
- import { join } from "node:path";
25
- import { findOwningPackage } from "./workspace/find-owning-package.js";
26
- export function computeOutputIdentity(inputs) {
27
- const { componentId, repoId, definitionLoc } = inputs;
28
- const { source, kind } = componentId;
29
- const isLocal = source.type === "local";
30
- const scope = isLocal ? "local" : "external";
31
- const identity = {
32
- scope,
33
- kind,
34
- };
35
- if (source.type === "external") {
36
- identity.packageName = source.package;
37
- if (source.modulePath !== undefined) {
38
- identity.modulePath = source.modulePath;
39
- }
40
- }
41
- if (componentId.kind === "custom-element") {
42
- identity.tagName = componentId.tagName;
43
- }
44
- else {
45
- // react-component | vue-component
46
- identity.exportName = componentId.export;
47
- }
48
- if (isLocal && source.type === "local") {
49
- identity.repoId = repoId;
50
- identity.filePath = source.filePath;
51
- if (inputs.workspaceGraph) {
52
- // findOwningPackage operates on absolute paths; source.filePath is
53
- // outputRoot-relative, so resolve against outputRoot (falling back to
54
- // workspaceGraph.rootPath for callers that haven't threaded it yet).
55
- const joinRoot = inputs.outputRoot ?? inputs.workspaceGraph.rootPath;
56
- const abs = join(joinRoot, source.filePath);
57
- const owning = findOwningPackage(inputs.workspaceGraph, abs);
58
- if (owning)
59
- identity.packageName = owning.name;
60
- }
61
- if (definitionLoc !== undefined) {
62
- identity.definition = definitionLoc;
63
- }
64
- }
65
- return identity;
66
- }
67
- const sha1Short = (s) => createHash("sha1").update(s).digest("hex").slice(0, 16);
68
- export function computeStableId(identity) {
69
- if (identity.scope === "local") {
70
- // `repoId` is descriptive, not part of the id: an id is scoped to one
71
- // artefact, whose `meta.repo.id` already names the repo. Must hash the
72
- // same string as `computeStableIdFromComponentId`.
73
- return sha1Short(`local::::${identity.filePath}::${identity.exportName}::${identity.kind}`);
74
- }
75
- if (identity.kind === "custom-element") {
76
- if (identity.modulePath !== undefined) {
77
- return sha1Short(`ce::${identity.packageName}::${identity.modulePath}::${identity.tagName}`);
78
- }
79
- return sha1Short(`ce::${identity.packageName}::${identity.tagName}`);
80
- }
81
- if (identity.modulePath !== undefined) {
82
- return sha1Short(`rc::${identity.packageName}::${identity.modulePath}::${identity.exportName}`);
83
- }
84
- return sha1Short(`rc::${identity.packageName}::${identity.exportName}`);
85
- }
86
- /**
87
- * Produce the same stable id as `computeStableId` from a raw `ComponentId`
88
- * (as emitted by parsers), without needing to first build an `OutputIdentity`.
89
- *
90
- * This is used in `occurrences.ts` so that occurrence `componentId` fields
91
- * hash-match the `id` values produced by `buildComponentSeeds` → `rollupOccurrencesToComponents`
92
- * can correctly correlate occurrences to seeds.
93
- *
94
- * For local components `repoId` is not part of the id (see `computeStableId`);
95
- * the empty slot in `local::::…` is kept so existing ids stay stable.
96
- */
97
- export function computeStableIdFromComponentId(c) {
98
- if (c.source.type === "local") {
99
- const exportOrTag = c.kind === "custom-element" ? c.tagName : c.export;
100
- return sha1Short(`local::::${c.source.filePath}::${exportOrTag}::${c.kind}`);
101
- }
102
- const pkg = c.source.type === "external" ? c.source.package : "unknown";
103
- const modulePath = c.source.type === "external" ? c.source.modulePath : undefined;
104
- if (c.kind === "custom-element") {
105
- if (modulePath !== undefined) {
106
- return sha1Short(`ce::${pkg}::${modulePath}::${c.tagName}`);
107
- }
108
- return sha1Short(`ce::${pkg}::${c.tagName}`);
109
- }
110
- if (modulePath !== undefined) {
111
- return sha1Short(`rc::${pkg}::${modulePath}::${c.export}`);
112
- }
113
- return sha1Short(`rc::${pkg}::${c.export}`);
114
- }
115
- //# sourceMappingURL=identity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAkBvE,MAAM,UAAU,qBAAqB,CAAC,MAAsB;IAC1D,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IACtD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC;IACxC,MAAM,KAAK,GAA4B,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC;IAEtE,MAAM,QAAQ,GAAmB;QAC/B,KAAK;QACL,IAAI;KACL,CAAC;IAEF,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;QACtC,IAA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AC,MAAM,CAAC,QAAQ,KAAK,WAAW,KAAK,CAAC,CAAC,IAAI,EAAE,CAC3D,CAAC;IACJ,CAAC;IACD,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,MAAM,UAAU,GACd,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,IAAI,CAAC,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QAChC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,SAAS,CAAC,OAAO,GAAG,KAAK,UAAU,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAC,OAAO,GAAG,KAAK,UAAU,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9C,CAAC"}
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare const VERSION = "0.1.0";
2
- export { runScan } from "./commands/scan.js";
3
- export type { ScanOptions, ScanResult } from "./commands/scan.js";
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- export const VERSION = "0.1.0";
2
- export { runScan } from "./commands/scan.js";
3
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,15 +0,0 @@
1
- import type { ObjectPattern, ObjectExpression, TSTypeLiteral, Expression, Node } from "@oxc-project/types";
2
- import type { DeclaredPropApi } from "@component-compass/plugin-core";
3
- /** Read a literal expression node into its JS value, or undefined if non-literal.
4
- * oxc uses a unified ESTree `Literal` node; the value lives on `.value`. */
5
- export declare function readLiteralValue(node: Expression | Node): string | number | boolean | null | undefined;
6
- /** Object-destructure pattern → declared API. Shared by React destructuring
7
- * params and Vue reactive-props destructure (identical oxc shape). oxc emits
8
- * `type: "Property"` for binding properties and `type: "RestElement"` for rest. */
9
- export declare function objectPatternToDeclared(pattern: ObjectPattern): DeclaredPropApi;
10
- /** Vue inline type-literal `defineProps<{ ... }>()` → declared API. Names +
11
- * required (from `?`) + verbatim type text. An index signature → hasRest. */
12
- export declare function typeLiteralToDeclared(typeLit: TSTypeLiteral, scriptSource: string): DeclaredPropApi;
13
- /** Vue object-runtime `defineProps({ ... })` → declared API. Reads each key's
14
- * descriptor (`{ type, required, default }`) or shorthand constructor. */
15
- export declare function objectRuntimeToDeclared(obj: ObjectExpression): DeclaredPropApi;
@@ -1,101 +0,0 @@
1
- /** Read a literal expression node into its JS value, or undefined if non-literal.
2
- * oxc uses a unified ESTree `Literal` node; the value lives on `.value`. */
3
- export function readLiteralValue(node) {
4
- if (node.type === "Literal") {
5
- const v = node.value;
6
- if (v === null || typeof v === "string" || typeof v === "number" || typeof v === "boolean") {
7
- return v;
8
- }
9
- }
10
- return undefined;
11
- }
12
- /** Object-destructure pattern → declared API. Shared by React destructuring
13
- * params and Vue reactive-props destructure (identical oxc shape). oxc emits
14
- * `type: "Property"` for binding properties and `type: "RestElement"` for rest. */
15
- export function objectPatternToDeclared(pattern) {
16
- const props = {};
17
- let hasRest = false;
18
- for (const p of pattern.properties) {
19
- if (p.type === "RestElement") {
20
- hasRest = true;
21
- continue;
22
- }
23
- if (p.type !== "Property")
24
- continue;
25
- if (p.key.type !== "Identifier")
26
- continue; // skip computed / string keys
27
- const name = p.key.name;
28
- if (p.value.type === "AssignmentPattern") {
29
- const decl = { required: false };
30
- const lit = readLiteralValue(p.value.right);
31
- if (lit !== undefined)
32
- decl.default = lit;
33
- props[name] = decl;
34
- }
35
- else {
36
- props[name] = {};
37
- }
38
- }
39
- return { props, hasRest };
40
- }
41
- /** Vue inline type-literal `defineProps<{ ... }>()` → declared API. Names +
42
- * required (from `?`) + verbatim type text. An index signature → hasRest. */
43
- export function typeLiteralToDeclared(typeLit, scriptSource) {
44
- const props = {};
45
- let hasRest = false;
46
- for (const m of typeLit.members) {
47
- if (m.type === "TSIndexSignature") {
48
- hasRest = true;
49
- continue;
50
- }
51
- if (m.type !== "TSPropertySignature")
52
- continue;
53
- if (m.key.type !== "Identifier")
54
- continue;
55
- const decl = { required: !m.optional };
56
- if (m.typeAnnotation) {
57
- const t = m.typeAnnotation.typeAnnotation;
58
- decl.type = scriptSource.slice(t.start, t.end);
59
- }
60
- props[m.key.name] = decl;
61
- }
62
- return { props, hasRest };
63
- }
64
- /** Vue object-runtime `defineProps({ ... })` → declared API. Reads each key's
65
- * descriptor (`{ type, required, default }`) or shorthand constructor. */
66
- export function objectRuntimeToDeclared(obj) {
67
- const props = {};
68
- for (const p of obj.properties) {
69
- if (p.type !== "Property")
70
- continue;
71
- if (p.key.type !== "Identifier")
72
- continue;
73
- const decl = {};
74
- const val = p.value;
75
- if (val.type === "ObjectExpression") {
76
- for (const d of val.properties) {
77
- if (d.type !== "Property" || d.key.type !== "Identifier")
78
- continue;
79
- if (d.key.name === "type" && d.value.type === "Identifier") {
80
- decl.type = d.value.name;
81
- }
82
- else if (d.key.name === "required") {
83
- const r = readLiteralValue(d.value);
84
- if (typeof r === "boolean")
85
- decl.required = r;
86
- }
87
- else if (d.key.name === "default") {
88
- const lit = readLiteralValue(d.value);
89
- if (lit !== undefined)
90
- decl.default = lit;
91
- }
92
- }
93
- }
94
- else if (val.type === "Identifier") {
95
- decl.type = val.name; // shorthand: `variant: String`
96
- }
97
- props[p.key.name] = decl;
98
- }
99
- return { props, hasRest: false };
100
- }
101
- //# sourceMappingURL=declared-props.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"declared-props.js","sourceRoot":"","sources":["../../src/local-index/declared-props.ts"],"names":[],"mappings":"AASA;6EAC6E;AAC7E,MAAM,UAAU,gBAAgB,CAC9B,IAAuB;IAEvB,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAI,IAAsC,CAAC,KAAK,CAAC;QACxD,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;YAC3F,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;oFAEoF;AACpF,MAAM,UAAU,uBAAuB,CAAC,OAAsB;IAC5D,MAAM,KAAK,GAAiC,EAAE,CAAC;IAC/C,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YAC7B,OAAO,GAAG,IAAI,CAAC;YACf,SAAS;QACX,CAAC;QACD,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU;YAAE,SAAS;QACpC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,YAAY;YAAE,SAAS,CAAC,8BAA8B;QACzE,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACzC,MAAM,IAAI,GAAiB,EAAE,QAAQ,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I,CAAC,OAAO,GAAG,GAAG,CAAC;gBAC5C,CAAC;YACH,CAAC;QACH,CAAC;aAAM,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACrC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,+BAA+B;QACvD,CAAC;QACD,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3B,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACnC,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { Program } from "@oxc-project/types";
2
- import type { LocalDefinition } from "./types.js";
3
- export declare function detectReactComponents(program: Program, filePath: string, source?: string): LocalDefinition[];
@@ -1,378 +0,0 @@
1
- import { objectPatternToDeclared } from "./declared-props.js";
2
- export function detectReactComponents(program, filePath, source) {
3
- const found = [];
4
- const filePathSource = { type: "local", filePath };
5
- // Bound helper — closes over filePath and source so call sites are concise.
6
- const loc = (node) => nodeLoc(node, filePath, source);
7
- // ── Pass 1: collect top-level PascalCase declarations as candidates ──────
8
- // "Top-level" = direct child of Program, or inline declaration inside an
9
- // Export*Declaration that is a direct child of Program.
10
- const candidates = new Map();
11
- for (const stmt of program.body) {
12
- // Unwrap export wrappers to get the inner declaration (if any).
13
- // Use Node so that all member types stay structurally compatible.
14
- let inner = null;
15
- if (stmt.type === "ExportNamedDeclaration" && stmt.declaration) {
16
- inner = stmt.declaration;
17
- }
18
- else if (stmt.type === "ExportDefaultDeclaration" && isDeclaration(stmt.declaration)) {
19
- inner = stmt.declaration;
20
- }
21
- else {
22
- inner = stmt;
23
- }
24
- if (inner.type === "FunctionDeclaration") {
25
- const fn = inner;
26
- if (fn.id && isPascalCase(fn.id.name) && returnsJsx(fn)) {
27
- const name = fn.id.name;
28
- candidates.set(name, {
29
- componentId: { kind: "react-component", export: name, source: filePathSource },
30
- detector: "react-default-fn",
31
- loc: loc(fn),
32
- declared: declaredFromFn(fn),
33
- });
34
- }
35
- }
36
- else if (inner.type === "ClassDeclaration") {
37
- const cls = inner;
38
- if (cls.id && isPascalCase(cls.id.name) && hasRenderMethod(cls)) {
39
- const name = cls.id.name;
40
- candidates.set(name, {
41
- componentId: { kind: "react-component", export: name, source: filePathSource },
42
- detector: "react-class",
43
- loc: loc(cls),
44
- declared: undefined,
45
- });
46
- }
47
- }
48
- else if (inner.type === "VariableDeclaration") {
49
- for (const d of inner.declarations) {
50
- if (d.id.type !== "Identifier" || !isPascalCase(d.id.name) || !d.init)
51
- continue;
52
- const detector = classifyVariableInit(d.init);
53
- if (detector) {
54
- const name = d.id.name;
55
- const fnNode = functionFromInit(d.init);
56
- candidates.set(name, {
57
- componentId: { kind: "react-component", export: name, source: filePathSource },
58
- detector,
59
- loc: loc(d),
60
- declared: fnNode ? declaredFromFn(fnNode) : undefined,
61
- });
62
- }
63
- }
64
- }
65
- }
66
- // ── Pass 2: walk exports and emit LocalDefinitions ───────────────────────
67
- // Track what we've already emitted to avoid double-emission.
68
- // Key = `${exportName}:${isDefault}` for deduplication.
69
- const emitted = new Set();
70
- function emitKey(exportName, isDefault) {
71
- return `${exportName}:${isDefault}`;
72
- }
73
- function emit(def) {
74
- const key = emitKey(def.exportName, def.isDefault);
75
- if (emitted.has(key))
76
- return;
77
- emitted.add(key);
78
- found.push(def);
79
- }
80
- for (const stmt of program.body) {
81
- // ── ExportDefaultDeclaration ──────────────────────────────────────────
82
- if (stmt.type === "ExportDefaultDeclaration") {
83
- const decl = stmt.declaration;
84
- // Named function declaration: `export default function Foo() {}`
85
- if (decl.type === "FunctionDeclaration") {
86
- const fn = decl;
87
- if (fn.id && isPascalCase(fn.id.name) && returnsJsx(fn)) {
88
- const d = declaredFromFn(fn);
89
- emit({
90
- componentId: { kind: "react-component", export: fn.id.name, source: filePathSource },
91
- exportName: fn.id.name,
92
- isDefault: true,
93
- detector: "react-default-fn",
94
- ...withLoc(loc(fn)),
95
- ...(d ? { declared: d } : {}),
96
- });
97
- continue;
98
- }
99
- // Anonymous function-declaration default: `export default function() {}`
100
- if (returnsJsx(fn)) {
101
- const d = declaredFromFn(fn);
102
- emit({
103
- componentId: { kind: "react-component", export: "default", source: filePathSource },
104
- exportName: "default",
105
- isDefault: true,
106
- detector: "react-default-fn",
107
- ...withLoc(loc(fn)),
108
- ...(d ? { declared: d } : {}),
109
- });
110
- continue;
111
- }
112
- continue;
113
- }
114
- // Anonymous arrow / function expression default: `export default () => <Foo/>`
115
- if (decl.type === "ArrowFunctionExpression" || decl.type === "FunctionExpression") {
116
- const fn = decl;
117
- if (returnsJsx(fn)) {
118
- const d = declaredFromFn(fn);
119
- emit({
120
- componentId: { kind: "react-component", export: "default", source: filePathSource },
121
- exportName: "default",
122
- isDefault: true,
123
- detector: "react-arrow",
124
- ...withLoc(loc(fn)),
125
- ...(d ? { declared: d } : {}),
126
- });
127
- }
128
- continue;
129
- }
130
- // Class component default: `export default class Foo extends Component { render() {} }`
131
- if (decl.type === "ClassDeclaration") {
132
- const cls = decl;
133
- if (cls.id && isPascalCase(cls.id.name) && hasRenderMethod(cls)) {
134
- emit({
135
- componentId: { kind: "react-component", export: cls.id.name, source: filePathSource },
136
- exportName: cls.id.name,
137
- isDefault: true,
138
- detector: "react-class",
139
- ...withLoc(loc(cls)),
140
- });
141
- }
142
- continue;
143
- }
144
- // `export default Identifier` — look up in candidates
145
- if (decl.type === "Identifier") {
146
- const candidate = candidates.get(decl.name);
147
- if (candidate) {
148
- emit({
149
- componentId: candidate.componentId,
150
- exportName: candidate.componentId.kind === "react-component" ? candidate.componentId.export : decl.name,
151
- isDefault: true,
152
- detector: candidate.detector,
153
- ...withLoc(candidate.loc),
154
- ...(candidate.declared ? { declared: candidate.declared } : {}),
155
- });
156
- }
157
- continue;
158
- }
159
- // `export default memo(Foo)` / `export default forwardRef(Foo)` etc.
160
- if (decl.type === "CallExpression") {
161
- const call = decl;
162
- const callee = call.callee;
163
- let calleeName;
164
- if (callee.type === "Identifier")
165
- calleeName = callee.name;
166
- else if (callee.type === "MemberExpression" && callee.property.type === "Identifier")
167
- calleeName = callee.property.name;
168
- const isHoc = calleeName === "memo" || calleeName === "forwardRef" || calleeName === "observer";
169
- if (isHoc && call.arguments.length > 0) {
170
- const firstArg = call.arguments[0];
171
- if (firstArg && firstArg.type === "Identifier") {
172
- const candidate = candidates.get(firstArg.name);
173
- if (candidate) {
174
- const detector = calleeName === "forwardRef" ? "react-forward-ref" :
175
- calleeName === "memo" ? "react-memo" :
176
- "react-arrow";
177
- emit({
178
- componentId: candidate.componentId,
179
- exportName: candidate.componentId.kind === "react-component" ? candidate.componentId.export : firstArg.name,
180
- isDefault: true,
181
- detector,
182
- ...withLoc(candidate.loc),
183
- ...(candidate.declared ? { declared: candidate.declared } : {}),
184
- });
185
- }
186
- }
187
- }
188
- continue;
189
- }
190
- continue;
191
- }
192
- // ── ExportNamedDeclaration ────────────────────────────────────────────
193
- if (stmt.type === "ExportNamedDeclaration") {
194
- const decl = stmt.declaration;
195
- // Inline declaration: `export function Foo() {}`, `export const Foo = ...`, etc.
196
- if (decl) {
197
- if (decl.type === "FunctionDeclaration") {
198
- const fn = decl;
199
- if (fn.id && isPascalCase(fn.id.name) && returnsJsx(fn)) {
200
- const d = declaredFromFn(fn);
201
- emit({
202
- componentId: { kind: "react-component", export: fn.id.name, source: filePathSource },
203
- exportName: fn.id.name,
204
- isDefault: false,
205
- detector: "react-default-fn",
206
- ...withLoc(loc(fn)),
207
- ...(d ? { declared: d } : {}),
208
- });
209
- }
210
- }
211
- if (decl.type === "ClassDeclaration") {
212
- const cls = decl;
213
- if (cls.id && isPascalCase(cls.id.name) && hasRenderMethod(cls)) {
214
- emit({
215
- componentId: { kind: "react-component", export: cls.id.name, source: filePathSource },
216
- exportName: cls.id.name,
217
- isDefault: false,
218
- detector: "react-class",
219
- ...withLoc(loc(cls)),
220
- });
221
- }
222
- }
223
- if (decl.type === "VariableDeclaration") {
224
- for (const d of decl.declarations) {
225
- if (d.id.type !== "Identifier" || !isPascalCase(d.id.name) || !d.init)
226
- continue;
227
- const detector = classifyVariableInit(d.init);
228
- if (detector) {
229
- const fnNode = functionFromInit(d.init);
230
- const dApi = fnNode ? declaredFromFn(fnNode) : undefined;
231
- emit({
232
- componentId: { kind: "react-component", export: d.id.name, source: filePathSource },
233
- exportName: d.id.name,
234
- isDefault: false,
235
- detector,
236
- ...withLoc(loc(d)),
237
- ...(dApi ? { declared: dApi } : {}),
238
- });
239
- }
240
- }
241
- }
242
- continue;
243
- }
244
- // `export { X }` or `export { X as Y }` — local re-exports (no source).
245
- // Skip if this is a re-export from another module (`stmt.source` is non-null).
246
- if (!stmt.source && stmt.specifiers.length > 0) {
247
- for (const specifier of stmt.specifiers) {
248
- if (specifier.type !== "ExportSpecifier")
249
- continue;
250
- const localNode = specifier.local;
251
- // ModuleExportName can be IdentifierName | IdentifierReference | StringLiteral;
252
- // only Identifier-typed nodes carry a usable binding name.
253
- if (localNode.type !== "Identifier")
254
- continue;
255
- const localName = localNode.name;
256
- const exportedNode = specifier.exported;
257
- const exportedName = exportedNode.type === "Identifier"
258
- ? exportedNode.name
259
- : exportedNode.value;
260
- const isDefault = exportedName === "default";
261
- const candidate = candidates.get(localName);
262
- if (!candidate)
263
- continue;
264
- emit({
265
- componentId: candidate.componentId,
266
- exportName: isDefault ? "default" : exportedName,
267
- isDefault,
268
- detector: candidate.detector,
269
- ...withLoc(candidate.loc),
270
- ...(candidate.declared ? { declared: candidate.declared } : {}),
271
- });
272
- }
273
- }
274
- }
275
- }
276
- return found;
277
- }
278
- // ── Helpers ────────────────────────────────────────────────────────────────
279
- /** Narrow whether an ExportDefaultDeclaration's `.declaration` is a function or class node */
280
- function isDeclaration(node) {
281
- return node.type === "FunctionDeclaration" || node.type === "ClassDeclaration";
282
- }
283
- function isPascalCase(name) {
284
- return /^[A-Z]/.test(name);
285
- }
286
- function returnsJsx(fn) {
287
- if (fn.type === "ArrowFunctionExpression" && fn.body.type !== "BlockStatement") {
288
- return isJsxNode(fn.body);
289
- }
290
- const block = fn.body;
291
- if (!block || block.type !== "BlockStatement")
292
- return false;
293
- return block.body.some((stmt) => stmt.type === "ReturnStatement" &&
294
- stmt.argument != null &&
295
- (isJsxNode(stmt.argument) || stmt.argument.type === "CallExpression"));
296
- }
297
- function isJsxNode(node) {
298
- if (node.type === "JSXElement" || node.type === "JSXFragment")
299
- return true;
300
- // OXC preserves parentheses as ParenthesizedExpression nodes; Babel strips them.
301
- if (node.type === "ParenthesizedExpression")
302
- return isJsxNode(node.expression);
303
- if (node.type === "ConditionalExpression")
304
- return isJsxNode(node.consequent) || isJsxNode(node.alternate);
305
- if (node.type === "LogicalExpression")
306
- return isJsxNode(node.right);
307
- return false;
308
- }
309
- function hasRenderMethod(decl) {
310
- return decl.body.body.some((m) => (m.type === "MethodDefinition" || m.type === "PropertyDefinition") &&
311
- m.key.type === "Identifier" &&
312
- m.key.name === "render");
313
- }
314
- function nodeLoc(node, filePath, source) {
315
- // oxc nodes carry byte offsets (start/end), not loc objects.
316
- // Compute line/column by counting newlines in the source prefix.
317
- if (source !== undefined && typeof node.start === "number") {
318
- const before = source.slice(0, node.start);
319
- const lines = before.split("\n");
320
- return { file: filePath, line: lines.length, column: (lines[lines.length - 1] ?? "").length };
321
- }
322
- return undefined;
323
- }
324
- function withLoc(loc) {
325
- return loc !== undefined ? { loc } : {};
326
- }
327
- function classifyVariableInit(init) {
328
- if (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression")
329
- return "react-arrow";
330
- if (init.type === "CallExpression") {
331
- const callee = init.callee;
332
- let calleeName;
333
- if (callee.type === "Identifier")
334
- calleeName = callee.name;
335
- else if (callee.type === "MemberExpression" && callee.property.type === "Identifier")
336
- calleeName = callee.property.name;
337
- if (calleeName === "forwardRef")
338
- return "react-forward-ref";
339
- if (calleeName === "memo")
340
- return "react-memo";
341
- }
342
- return null;
343
- }
344
- /** The underlying component function for a variable init: an arrow/fn-expr, or
345
- * the first arg of a memo/forwardRef/observer wrapper. */
346
- function functionFromInit(init) {
347
- if (init.type === "ArrowFunctionExpression" || init.type === "FunctionExpression") {
348
- return init;
349
- }
350
- if (init.type === "CallExpression") {
351
- const c = init;
352
- let name;
353
- if (c.callee.type === "Identifier")
354
- name = c.callee.name;
355
- else if (c.callee.type === "MemberExpression" && c.callee.property.type === "Identifier")
356
- name = c.callee.property.name;
357
- if ((name === "memo" || name === "forwardRef" || name === "observer") && c.arguments[0]) {
358
- const a = c.arguments[0];
359
- if (a.type === "ArrowFunctionExpression" || a.type === "FunctionExpression") {
360
- return a;
361
- }
362
- }
363
- }
364
- return null;
365
- }
366
- /** Declared API from a component function's first param, when it is an object
367
- * destructure with ≥1 named prop. `({...}= {})` default-param form is unwrapped. */
368
- function declaredFromFn(fn) {
369
- const first = fn.params[0];
370
- if (!first)
371
- return undefined;
372
- const pat = first.type === "AssignmentPattern" ? first.left : first;
373
- if (pat.type !== "ObjectPattern")
374
- return undefined;
375
- const declared = objectPatternToDeclared(pat);
376
- return Object.keys(declared.props).length > 0 ? declared : undefined;
377
- }
378
- //# sourceMappingURL=detect-react.js.map