@component-compass/cli 0.0.2 → 0.0.3
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/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/no-deps-diagnostic.d.ts +15 -0
- package/dist/commands/no-deps-diagnostic.js +23 -0
- package/dist/commands/no-deps-diagnostic.js.map +1 -0
- package/dist/commands/scan.d.ts +1 -0
- package/dist/commands/scan.js +69 -52
- package/dist/commands/scan.js.map +1 -1
- package/dist/composition-rollup.d.ts +16 -14
- package/dist/composition-rollup.js +33 -43
- package/dist/composition-rollup.js.map +1 -1
- package/dist/identity.d.ts +9 -3
- package/dist/identity.js +15 -3
- package/dist/identity.js.map +1 -1
- package/dist/local-index/detect-react.js +224 -47
- package/dist/local-index/detect-react.js.map +1 -1
- package/dist/local-index/index.d.ts +4 -1
- package/dist/local-index/index.js +30 -13
- package/dist/local-index/index.js.map +1 -1
- package/dist/manifest/derived-manifest-stub.d.ts +2 -2
- package/dist/manifest/diagnostic-filter.d.ts +4 -3
- package/dist/manifest/diagnostic-filter.js +15 -2
- package/dist/manifest/diagnostic-filter.js.map +1 -1
- package/dist/manifest/lazy-resolver.d.ts +17 -25
- package/dist/manifest/lazy-resolver.js +175 -48
- package/dist/manifest/lazy-resolver.js.map +1 -1
- package/dist/occurrences.d.ts +4 -4
- package/dist/occurrences.js +29 -5
- package/dist/occurrences.js.map +1 -1
- package/dist/reporter/index.d.ts +27 -12
- package/dist/reporter/index.js +105 -18
- package/dist/reporter/index.js.map +1 -1
- package/dist/rollup.d.ts +8 -2
- package/dist/rollup.js +2 -2
- package/dist/rollup.js.map +1 -1
- package/dist/seeds.d.ts +3 -2
- package/dist/seeds.js +61 -30
- package/dist/seeds.js.map +1 -1
- package/dist/workspace/build-graph.d.ts +2 -0
- package/dist/workspace/build-graph.js +117 -0
- package/dist/workspace/build-graph.js.map +1 -0
- package/dist/workspace/declared-deps.d.ts +5 -0
- package/dist/workspace/declared-deps.js +42 -0
- package/dist/workspace/declared-deps.js.map +1 -0
- package/dist/workspace/find-owning-package.d.ts +2 -0
- package/dist/workspace/find-owning-package.js +49 -0
- package/dist/workspace/find-owning-package.js.map +1 -0
- package/dist/workspace/index.d.ts +4 -0
- package/dist/workspace/index.js +4 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/types.d.ts +46 -0
- package/dist/workspace/types.js +13 -0
- package/dist/workspace/types.js.map +1 -0
- package/package.json +9 -7
package/dist/reporter/index.js
CHANGED
|
@@ -25,17 +25,18 @@ import { rollupOccurrencesToComponents } from "../rollup.js";
|
|
|
25
25
|
* counts are computed against the full occurrence graph. The scope
|
|
26
26
|
* filter then drops out-of-scope components, their occurrences, and —
|
|
27
27
|
* by transitive consequence — their composition rollup. Running
|
|
28
|
-
* composition AFTER the filter would let a child's
|
|
29
|
-
*
|
|
30
|
-
* artifact
|
|
28
|
+
* composition AFTER the filter would let a child's parent
|
|
29
|
+
* `occurrenceId` resolve to a dropped component, leaving a dangling
|
|
30
|
+
* reference in the artifact's `renderedByCount`.
|
|
31
31
|
*
|
|
32
32
|
* The filter runs AFTER rollup so the per-component stats already reflect
|
|
33
33
|
* the data the consumer will see in the artifact.
|
|
34
34
|
*/
|
|
35
|
-
export function buildScanOutput(envelope, manifests, partialStats, seeds, occurrences, packageScopes) {
|
|
35
|
+
export function buildScanOutput(envelope, manifests, partialStats, seeds, occurrences, packageScopes, diagnostics) {
|
|
36
36
|
const rolled = rollupOccurrencesToComponents(occurrences, seeds);
|
|
37
37
|
const withComposition = applyCompositionRollup(rolled, occurrences);
|
|
38
|
-
const
|
|
38
|
+
const pruned = dropUnreachableLocalSeeds(withComposition);
|
|
39
|
+
const filtered = applyScopeFilter(pruned, occurrences, packageScopes);
|
|
39
40
|
const stats = {
|
|
40
41
|
...partialStats,
|
|
41
42
|
componentsDetected: filtered.components.length,
|
|
@@ -47,8 +48,34 @@ export function buildScanOutput(envelope, manifests, partialStats, seeds, occurr
|
|
|
47
48
|
stats,
|
|
48
49
|
components: filtered.components,
|
|
49
50
|
occurrences: filtered.occurrences,
|
|
51
|
+
diagnostics,
|
|
50
52
|
};
|
|
51
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Drops local components that contribute no information to the artifact:
|
|
56
|
+
* no occurrences AND not referenced as parent or child in any composition
|
|
57
|
+
* edge. Workspace-scoped scans accumulate thousands of these — every
|
|
58
|
+
* locally-defined component the include glob walks past, regardless of
|
|
59
|
+
* whether anything in scope renders it. Under the exports-only owner
|
|
60
|
+
* attribution invariant, a local seed that's neither rendered nor owns
|
|
61
|
+
* rendering is unreachable in the dependency graph by construction, so
|
|
62
|
+
* dropping it is lossless.
|
|
63
|
+
*
|
|
64
|
+
* Non-local seeds (ds / external) are preserved unconditionally — they
|
|
65
|
+
* represent identity attribution work the resolver did, not local-index
|
|
66
|
+
* walk-through.
|
|
67
|
+
*/
|
|
68
|
+
function dropUnreachableLocalSeeds(components) {
|
|
69
|
+
return components.filter((c) => {
|
|
70
|
+
if (c.identity.scope !== "local")
|
|
71
|
+
return true;
|
|
72
|
+
if (c.stats.occurrenceCount > 0)
|
|
73
|
+
return true;
|
|
74
|
+
const rendersN = Object.keys(c.composition?.rendersByCount ?? {}).length;
|
|
75
|
+
const renderedByN = Object.keys(c.composition?.renderedByCount ?? {}).length;
|
|
76
|
+
return rendersN > 0 || renderedByN > 0;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
52
79
|
/**
|
|
53
80
|
* Drops components whose `identity.packageName` matches none of the scope
|
|
54
81
|
* patterns and every occurrence pointing at a dropped component. Local
|
|
@@ -79,12 +106,17 @@ function applyScopeFilter(components, occurrences, packageScopes) {
|
|
|
79
106
|
return { components: allowedComponents, occurrences: allowedOccurrences };
|
|
80
107
|
}
|
|
81
108
|
/**
|
|
82
|
-
* Pure converter: project a rich `ManifestComponent` (
|
|
83
|
-
* model) onto the artifact-shape `
|
|
84
|
-
* report.
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
109
|
+
* Pure converter: project a rich `ManifestComponent` (resolver-side domain
|
|
110
|
+
* model) onto the artifact-shape envelope `{ source, data }` consumed by the
|
|
111
|
+
* JSON report. The `data` payload is `AuthoredManifestData` (or its
|
|
112
|
+
* structural twin `DerivedManifestData`) — Phase 3's per-component manifest
|
|
113
|
+
* shape: optional `description`, `lifecycle`, and per-feature record maps
|
|
114
|
+
* (`props`, `slots`, `invocable`). Optional fields are omitted from the
|
|
115
|
+
* payload entirely when the input does not carry them (no `null` synth, no
|
|
116
|
+
* empty maps).
|
|
117
|
+
*
|
|
118
|
+
* Slots and events are CEM-shape only — react/vue ManifestComponents have no
|
|
119
|
+
* `events`/`slots` arrays — so we discriminate on `kind` before reading them.
|
|
88
120
|
*
|
|
89
121
|
* Returns `null` when no manifest entry was matched for the component, so
|
|
90
122
|
* downstream `OutputComponent.manifest` can be set directly.
|
|
@@ -92,14 +124,69 @@ function applyScopeFilter(components, occurrences, packageScopes) {
|
|
|
92
124
|
export function manifestComponentToOutput(m, source) {
|
|
93
125
|
if (!m)
|
|
94
126
|
return null;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
props[p.name] = { default: p.default };
|
|
99
|
-
}
|
|
100
|
-
const out = { source, props };
|
|
127
|
+
const data = {};
|
|
128
|
+
if (m.description !== undefined)
|
|
129
|
+
data.description = m.description;
|
|
101
130
|
if (m.lifecycle !== undefined)
|
|
102
|
-
|
|
131
|
+
data.lifecycle = m.lifecycle;
|
|
132
|
+
if (m.props.length > 0) {
|
|
133
|
+
const props = {};
|
|
134
|
+
for (const p of m.props)
|
|
135
|
+
props[p.name] = projectProp(p);
|
|
136
|
+
data.props = props;
|
|
137
|
+
}
|
|
138
|
+
// Slots and events are CEM-shape only — react/vue ManifestComponents have no
|
|
139
|
+
// events/slots arrays. Discriminate by kind.
|
|
140
|
+
if (m.kind === "custom-element") {
|
|
141
|
+
if (m.slots && m.slots.length > 0) {
|
|
142
|
+
const slots = {};
|
|
143
|
+
for (const s of m.slots)
|
|
144
|
+
slots[s.name] = projectSlot(s);
|
|
145
|
+
data.slots = slots;
|
|
146
|
+
}
|
|
147
|
+
if (m.events && m.events.length > 0) {
|
|
148
|
+
const invocable = {};
|
|
149
|
+
for (const e of m.events)
|
|
150
|
+
invocable[e.name] = projectEventAsInvocable(e);
|
|
151
|
+
data.invocable = invocable;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return source === "authored"
|
|
155
|
+
? { source: "authored", data }
|
|
156
|
+
: { source: "derived", data };
|
|
157
|
+
}
|
|
158
|
+
function projectProp(p) {
|
|
159
|
+
const out = {};
|
|
160
|
+
if (p.type !== undefined)
|
|
161
|
+
out.type = p.type;
|
|
162
|
+
if (p.default !== undefined)
|
|
163
|
+
out.default = p.default;
|
|
164
|
+
if (p.values !== undefined)
|
|
165
|
+
out.values = p.values;
|
|
166
|
+
if (p.required !== undefined)
|
|
167
|
+
out.required = p.required;
|
|
168
|
+
if (p.description !== undefined)
|
|
169
|
+
out.description = p.description;
|
|
170
|
+
if (p.lifecycle !== undefined)
|
|
171
|
+
out.lifecycle = p.lifecycle;
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
function projectSlot(s) {
|
|
175
|
+
const out = {};
|
|
176
|
+
if (s.description !== undefined)
|
|
177
|
+
out.description = s.description;
|
|
178
|
+
if (s.lifecycle !== undefined)
|
|
179
|
+
out.lifecycle = s.lifecycle;
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
function projectEventAsInvocable(e) {
|
|
183
|
+
const out = { kind: "dom-event" };
|
|
184
|
+
if (e.payloadType !== undefined)
|
|
185
|
+
out.payloadType = e.payloadType;
|
|
186
|
+
if (e.description !== undefined)
|
|
187
|
+
out.description = e.description;
|
|
188
|
+
if (e.lifecycle !== undefined)
|
|
189
|
+
out.lifecycle = e.lifecycle;
|
|
103
190
|
return out;
|
|
104
191
|
}
|
|
105
192
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reporter/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,SAAS,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reporter/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,SAAS,MAAM,WAAW,CAAC;AAmBlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,6BAA6B,EAAsB,MAAM,cAAc,CAAC;AAOjF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAsB,EACtB,SAAwB,EACxB,YAA8B,EAC9B,KAAsB,EACtB,WAA+B,EAC/B,aAAuB,EACvB,WAAyB;IAEzB,MAAM,MAAM,GAAG,6BAA6B,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACjE,MAAM,eAAe,GAAG,sBAAsB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,yBAAyB,CAAC,eAAe,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IACtE,MAAM,KAAK,GAAc;QACvB,GAAG,YAAY;QACf,kBAAkB,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;QAC9C,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAAC,MAAM;KAC9C,CAAC;IACF,OAAO;QACL,QAAQ;QACR,SAAS;QACT,KAAK;QACL,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,WAAW;KACZ,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,yBAAyB,CAAC,UAA6B;IAC9D,OAAO,UAAU,CAAC,M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AAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;IACjE,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS;QAAE,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;IAC3D,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,WAAW,CAAC,CAAe;IAClC,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAAE,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;IACjE,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS;QAAE,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;IAC3D,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,uBAAuB,CAAC,CAAgB;IAC/C,MAAM,GAAG,GAAkB,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IACjD,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAAE,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;IACjE,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAAE,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;IACjE,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS;QAAE,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;IAC3D,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/rollup.d.ts
CHANGED
|
@@ -11,11 +11,17 @@
|
|
|
11
11
|
* design-system components present in the repo via `tagRules` surface even
|
|
12
12
|
* when not yet used.
|
|
13
13
|
*/
|
|
14
|
-
import type { OutputComponent, OutputIdentity,
|
|
14
|
+
import type { AuthoredManifestData, DerivedManifestData, OutputComponent, OutputIdentity, OutputOccurrence } from "@component-compass/plugin-core";
|
|
15
15
|
export type ComponentSeed = {
|
|
16
16
|
id: string;
|
|
17
17
|
identity: OutputIdentity;
|
|
18
18
|
derivedTags: string[];
|
|
19
|
-
manifest:
|
|
19
|
+
manifest: {
|
|
20
|
+
source: "authored";
|
|
21
|
+
data: AuthoredManifestData;
|
|
22
|
+
} | {
|
|
23
|
+
source: "derived";
|
|
24
|
+
data: DerivedManifestData;
|
|
25
|
+
} | null;
|
|
20
26
|
};
|
|
21
27
|
export declare function rollupOccurrencesToComponents(occurrences: OutputOccurrence[], seeds: ComponentSeed[]): OutputComponent[];
|
package/dist/rollup.js
CHANGED
|
@@ -41,12 +41,12 @@ export function rollupOccurrencesToComponents(occurrences, seeds) {
|
|
|
41
41
|
}
|
|
42
42
|
// Manifest-declared props with no occurrence usage still need a slot so
|
|
43
43
|
// the rollup can surface "prop X is universally unused / always defaulted".
|
|
44
|
-
for (const name of Object.keys(seed.manifest?.props ?? {}))
|
|
44
|
+
for (const name of Object.keys(seed.manifest?.data?.props ?? {}))
|
|
45
45
|
propsSeen.add(name);
|
|
46
46
|
const props = {};
|
|
47
47
|
for (const name of propsSeen) {
|
|
48
48
|
const dist = emptyDist();
|
|
49
|
-
const hasDefault = seed.manifest?.props?.[name]?.default !== undefined;
|
|
49
|
+
const hasDefault = seed.manifest?.data?.props?.[name]?.default !== undefined;
|
|
50
50
|
for (const o of occs) {
|
|
51
51
|
if (!(name in o.props)) {
|
|
52
52
|
dist.omitted += 1;
|
package/dist/rollup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.js","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"rollup.js","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAyBH,MAAM,gBAAgB,GAAG,CAAC,CAAmB,EAAU,EAAE,CACvD,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAElC,MAAM,SAAS,GAAG,CAAC,CAAi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,CAAC,WAAW;YAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE;YAChE,KAAK;SACN,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/seeds.d.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Pure function; no I/O.
|
|
9
9
|
*/
|
|
10
|
-
import type { IndexedComponent, ParseResult } from "@component-compass/plugin-core";
|
|
10
|
+
import type { IndexedComponent, LocalDefinitionIndex, ParseResult } from "@component-compass/plugin-core";
|
|
11
11
|
import type { TagRule } from "./config/schema.js";
|
|
12
12
|
import type { ComponentSeed } from "./rollup.js";
|
|
13
|
+
import type { WorkspaceGraph } from "./workspace/types.js";
|
|
13
14
|
/**
|
|
14
15
|
* One entry in the resolver snapshot. Each entry pairs an `IndexedComponent`
|
|
15
16
|
* (the manifest-shaped record) with an `enrichmentSource` label distinguishing
|
|
@@ -37,4 +38,4 @@ export type SnapshotEntry = {
|
|
|
37
38
|
* - ds → external + derivedTags.length > 0
|
|
38
39
|
* - external → external + no matching tag rules
|
|
39
40
|
*/
|
|
40
|
-
export declare function buildComponentSeeds(snapshot: SnapshotEntry[], parseResults: ParseResult[], tagRules: TagRule[] | undefined): ComponentSeed[];
|
|
41
|
+
export declare function buildComponentSeeds(snapshot: SnapshotEntry[], parseResults: ParseResult[], tagRules: TagRule[] | undefined, localIndex?: LocalDefinitionIndex, repoRoot?: string, workspaceGraph?: WorkspaceGraph): ComponentSeed[];
|
package/dist/seeds.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Pure function; no I/O.
|
|
9
9
|
*/
|
|
10
|
+
import { relative, isAbsolute } from "node:path";
|
|
10
11
|
import { evaluateTagRules } from "./config/tag-rules.js";
|
|
11
12
|
import { manifestComponentToOutput } from "./reporter/index.js";
|
|
12
13
|
import { computeOutputIdentity, computeStableId, computeStableIdFromComponentId, } from "./identity.js";
|
|
@@ -28,7 +29,7 @@ import { computeOutputIdentity, computeStableId, computeStableIdFromComponentId,
|
|
|
28
29
|
* - ds → external + derivedTags.length > 0
|
|
29
30
|
* - external → external + no matching tag rules
|
|
30
31
|
*/
|
|
31
|
-
export function buildComponentSeeds(snapshot, parseResults, tagRules) {
|
|
32
|
+
export function buildComponentSeeds(snapshot, parseResults, tagRules, localIndex, repoRoot, workspaceGraph) {
|
|
32
33
|
const seedsById = new Map();
|
|
33
34
|
// 1. Resolver-snapshotted components first (so they win on dedupe).
|
|
34
35
|
for (const entry of snapshot) {
|
|
@@ -37,12 +38,11 @@ export function buildComponentSeeds(snapshot, parseResults, tagRules) {
|
|
|
37
38
|
? entry.component.source.package
|
|
38
39
|
: null;
|
|
39
40
|
const derivedTags = evaluateTagRules(packageName, tagRules);
|
|
40
|
-
const via = defaultVia(entry.component);
|
|
41
41
|
const identity = computeOutputIdentity({
|
|
42
42
|
componentId,
|
|
43
|
-
via,
|
|
44
43
|
derivedTags,
|
|
45
44
|
repoId: "",
|
|
45
|
+
...(workspaceGraph !== undefined ? { workspaceGraph } : {}),
|
|
46
46
|
});
|
|
47
47
|
const id = computeStableId(identity);
|
|
48
48
|
const manifest = manifestComponentToOutput(entry.component, entry.enrichmentSource);
|
|
@@ -52,22 +52,75 @@ export function buildComponentSeeds(snapshot, parseResults, tagRules) {
|
|
|
52
52
|
// Emitted with manifest: null per the realignment principle.
|
|
53
53
|
for (const result of parseResults) {
|
|
54
54
|
for (const occ of result.occurrences) {
|
|
55
|
-
|
|
55
|
+
// Normalise local filePaths: parsers emit absolute paths; the local index
|
|
56
|
+
// uses repo-root-relative POSIX paths. Relativise here so the stable id
|
|
57
|
+
// matches the one produced for seeds built from the local index.
|
|
58
|
+
const componentId = repoRoot && occ.componentId.source.type === "local" && isAbsolute(occ.componentId.source.filePath)
|
|
59
|
+
? {
|
|
60
|
+
...occ.componentId,
|
|
61
|
+
source: {
|
|
62
|
+
type: "local",
|
|
63
|
+
filePath: relative(repoRoot, occ.componentId.source.filePath).replace(/\\/g, "/"),
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
: occ.componentId;
|
|
67
|
+
const id = computeStableIdFromComponentId(componentId);
|
|
56
68
|
if (seedsById.has(id))
|
|
57
69
|
continue;
|
|
58
|
-
const packageName =
|
|
59
|
-
?
|
|
70
|
+
const packageName = componentId.source.type === "external"
|
|
71
|
+
? componentId.source.package
|
|
60
72
|
: null;
|
|
61
73
|
const derivedTags = evaluateTagRules(packageName, tagRules);
|
|
74
|
+
const isLocal = componentId.source.type === "local";
|
|
75
|
+
let definitionLoc;
|
|
76
|
+
if (isLocal && localIndex) {
|
|
77
|
+
let match;
|
|
78
|
+
if (componentId.kind === "custom-element") {
|
|
79
|
+
match = localIndex.byTag.get(componentId.tagName);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const path = componentId.source.type === "local" ? componentId.source.filePath : "";
|
|
83
|
+
const defs = localIndex.byPath.get(path) ?? [];
|
|
84
|
+
const exportName = componentId.export;
|
|
85
|
+
match = defs.find((d) => d.exportName === exportName);
|
|
86
|
+
}
|
|
87
|
+
if (match?.loc) {
|
|
88
|
+
definitionLoc = { line: match.loc.line, column: match.loc.column };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
62
91
|
const identity = computeOutputIdentity({
|
|
63
|
-
componentId
|
|
64
|
-
via: defaultViaForKind(occ.componentId),
|
|
92
|
+
componentId,
|
|
65
93
|
derivedTags,
|
|
66
94
|
repoId: "",
|
|
95
|
+
...(workspaceGraph !== undefined ? { workspaceGraph } : {}),
|
|
96
|
+
...(definitionLoc !== undefined ? { definitionLoc } : {}),
|
|
67
97
|
});
|
|
68
98
|
seedsById.set(id, { id, identity, derivedTags, manifest: null });
|
|
69
99
|
}
|
|
70
100
|
}
|
|
101
|
+
// 3. Local definitions that were never referenced in any occurrence.
|
|
102
|
+
// These must still appear in components[] so they can serve as
|
|
103
|
+
// owner-edge targets in the composition graph.
|
|
104
|
+
if (localIndex) {
|
|
105
|
+
for (const [, defs] of localIndex.byPath) {
|
|
106
|
+
for (const def of defs) {
|
|
107
|
+
const id = computeStableIdFromComponentId(def.componentId);
|
|
108
|
+
if (seedsById.has(id))
|
|
109
|
+
continue;
|
|
110
|
+
const definitionLoc = def.loc !== undefined
|
|
111
|
+
? { line: def.loc.line, column: def.loc.column }
|
|
112
|
+
: undefined;
|
|
113
|
+
const identity = computeOutputIdentity({
|
|
114
|
+
componentId: def.componentId,
|
|
115
|
+
derivedTags: [],
|
|
116
|
+
repoId: "",
|
|
117
|
+
...(workspaceGraph !== undefined ? { workspaceGraph } : {}),
|
|
118
|
+
...(definitionLoc !== undefined ? { definitionLoc } : {}),
|
|
119
|
+
});
|
|
120
|
+
seedsById.set(id, { id, identity, derivedTags: [], manifest: null });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
71
124
|
return [...seedsById.values()];
|
|
72
125
|
}
|
|
73
126
|
/**
|
|
@@ -89,26 +142,4 @@ function indexedToComponentId(c) {
|
|
|
89
142
|
source: c.source,
|
|
90
143
|
};
|
|
91
144
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Infer a default `via` for a snapshotted seed based on component kind.
|
|
94
|
-
* Only `via.kind` is consumed by `computeOutputIdentity`; the required
|
|
95
|
-
* `specifier`/`import` fields on `direct-import` are not meaningful for
|
|
96
|
-
* zero-occurrence seeds and are left as empty strings.
|
|
97
|
-
*/
|
|
98
|
-
function defaultVia(c) {
|
|
99
|
-
if (c.kind === "custom-element") {
|
|
100
|
-
return { kind: "html-tag" };
|
|
101
|
-
}
|
|
102
|
-
return { kind: "direct-import", specifier: "", import: "" };
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Infer a default `via` for an occurrence-observed seed based on the
|
|
106
|
-
* component's kind. Used when seeding a component that has no snapshot entry.
|
|
107
|
-
*/
|
|
108
|
-
function defaultViaForKind(c) {
|
|
109
|
-
if (c.kind === "custom-element") {
|
|
110
|
-
return { kind: "html-tag" };
|
|
111
|
-
}
|
|
112
|
-
return { kind: "direct-import", specifier: "", import: "" };
|
|
113
|
-
}
|
|
114
145
|
//# sourceMappingURL=seeds.js.map
|
package/dist/seeds.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seeds.js","sourceRoot":"","sources":["../src/seeds.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"seeds.js","sourceRoot":"","sources":["../src/seeds.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AASjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AAevB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAyB,EACzB,YAA2B,EAC3B,QAA+B,EAC/B,UAAiC,EACjC,QAAiB,EACjB,cAA+B;IAE/B,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEnD,oEAAoE;IACpE,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC7B,MAAM,WAAW,GAAG,oBAAoB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC1D,MAAM,WAAW,GACf,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU;YACxC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO;YAChC,CAAC,CAAC,IAAI,CAAC;QACX,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAE5D,M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CAAC,CAAC,EAAE,CAAC;iBAC1D,CAAC,CAAC;gBAEH,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,CAAmB;IAC/C,IAAI,CAAC,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QAChC,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,MAAM,EAAE,CAAC,CAAC,MAAM;SACjB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,MAAM,EAAE,CAAC,CAAC,MAAM;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a workspace graph from a repository root.
|
|
3
|
+
*
|
|
4
|
+
* Two independent steps:
|
|
5
|
+
* - sniffPackageManager: lockfile-based; sets graph.packageManager. Always
|
|
6
|
+
* runs; returns "unknown" when no lockfile is found.
|
|
7
|
+
* - detectWorkspacePackages: pnpm-workspace.yaml → package.json#workspaces →
|
|
8
|
+
* empty array. Independent of step 1.
|
|
9
|
+
*
|
|
10
|
+
* Glob expansion uses globby (already a CLI dep).
|
|
11
|
+
* Pure; no I/O beyond config-file reads.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { join, resolve } from "node:path";
|
|
15
|
+
import { globbySync } from "globby";
|
|
16
|
+
import * as yaml from "js-yaml";
|
|
17
|
+
export function buildWorkspaceGraph(rootPath) {
|
|
18
|
+
const absRoot = resolve(rootPath);
|
|
19
|
+
const rootPkgJsonPath = join(absRoot, "package.json");
|
|
20
|
+
const rootPkg = readJsonSafely(rootPkgJsonPath) ?? {};
|
|
21
|
+
const rootPackageName = typeof rootPkg.name === "string" ? rootPkg.name : "<unnamed>";
|
|
22
|
+
return {
|
|
23
|
+
packageManager: sniffPackageManager(absRoot),
|
|
24
|
+
rootPath: absRoot,
|
|
25
|
+
rootPackageName,
|
|
26
|
+
packages: detectWorkspacePackages(absRoot, rootPkg),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function sniffPackageManager(absRoot) {
|
|
30
|
+
if (existsSync(join(absRoot, "pnpm-lock.yaml")))
|
|
31
|
+
return "pnpm";
|
|
32
|
+
if (existsSync(join(absRoot, "package-lock.json")))
|
|
33
|
+
return "npm";
|
|
34
|
+
if (existsSync(join(absRoot, "yarn.lock")))
|
|
35
|
+
return "yarn";
|
|
36
|
+
return "unknown";
|
|
37
|
+
}
|
|
38
|
+
function detectWorkspacePackages(absRoot, rootPkg) {
|
|
39
|
+
// pnpm-workspace.yaml wins when both configs present.
|
|
40
|
+
const pnpmYamlPath = join(absRoot, "pnpm-workspace.yaml");
|
|
41
|
+
if (existsSync(pnpmYamlPath)) {
|
|
42
|
+
const yamlContent = readFileSync(pnpmYamlPath, "utf8");
|
|
43
|
+
let parsed;
|
|
44
|
+
try {
|
|
45
|
+
parsed = yaml.load(yamlContent);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
parsed = null;
|
|
49
|
+
}
|
|
50
|
+
const globs = isWorkspaceYaml(parsed) ? parsed.packages : [];
|
|
51
|
+
return expandPackages(absRoot, globs);
|
|
52
|
+
}
|
|
53
|
+
// package.json#workspaces (array or object form).
|
|
54
|
+
const workspaces = rootPkg.workspaces;
|
|
55
|
+
if (Array.isArray(workspaces)) {
|
|
56
|
+
return expandPackages(absRoot, workspaces);
|
|
57
|
+
}
|
|
58
|
+
if (workspaces &&
|
|
59
|
+
typeof workspaces === "object" &&
|
|
60
|
+
Array.isArray(workspaces.packages)) {
|
|
61
|
+
return expandPackages(absRoot, workspaces.packages);
|
|
62
|
+
}
|
|
63
|
+
// No workspace config → single-package repo.
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
function expandPackages(absRoot, entries) {
|
|
67
|
+
if (entries.length === 0)
|
|
68
|
+
return [];
|
|
69
|
+
// Split literal paths from globs: globby (fast-glob) treats a bare "foo"
|
|
70
|
+
// as "foo/**" and returns subdirectories instead of foo itself, so literal
|
|
71
|
+
// workspace entries must be resolved directly.
|
|
72
|
+
const literals = [];
|
|
73
|
+
const globs = [];
|
|
74
|
+
for (const e of entries) {
|
|
75
|
+
if (/[*?[\]{}]/.test(e))
|
|
76
|
+
globs.push(e);
|
|
77
|
+
else
|
|
78
|
+
literals.push(e);
|
|
79
|
+
}
|
|
80
|
+
const matched = literals.map((p) => resolve(absRoot, p));
|
|
81
|
+
if (globs.length > 0) {
|
|
82
|
+
matched.push(...globbySync(globs, {
|
|
83
|
+
cwd: absRoot,
|
|
84
|
+
onlyDirectories: true,
|
|
85
|
+
absolute: true,
|
|
86
|
+
suppressErrors: true,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
const packages = [];
|
|
90
|
+
const seenNames = new Set();
|
|
91
|
+
for (const dir of matched) {
|
|
92
|
+
const pkgJson = readJsonSafely(join(dir, "package.json"));
|
|
93
|
+
if (!pkgJson)
|
|
94
|
+
continue;
|
|
95
|
+
if (typeof pkgJson.name !== "string" || pkgJson.name.length === 0)
|
|
96
|
+
continue;
|
|
97
|
+
if (seenNames.has(pkgJson.name))
|
|
98
|
+
continue;
|
|
99
|
+
seenNames.add(pkgJson.name);
|
|
100
|
+
packages.push({ name: pkgJson.name, absolutePath: dir, packageJson: pkgJson });
|
|
101
|
+
}
|
|
102
|
+
return packages;
|
|
103
|
+
}
|
|
104
|
+
function readJsonSafely(path) {
|
|
105
|
+
try {
|
|
106
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function isWorkspaceYaml(p) {
|
|
113
|
+
return (typeof p === "object" &&
|
|
114
|
+
p !== null &&
|
|
115
|
+
Array.isArray(p.packages));
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=build-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-graph.js","sourceRoot":"","sources":["../../src/workspace/build-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAGhC,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,cAAc,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IACtD,MAAM,eAAe,GACnB,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;IAEhE,OAAO;QACL,cAAc,EAAE,mBAAmB,CAAC,OAAO,CAAC;QAC5C,QAAQ,EAAE,OAAO;QACjB,eAAe;QACf,QAAQ,EAAE,uBAAuB,CAAC,OAAO,EAAE,OAAO,CAAC;KACpD,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAe;IAC1C,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAAE,OAAO,MAAM,C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,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,SAAS;QAC1C,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAClC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,CAAU;IACjC,OAAO,CACL,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACV,KAAK,CAAC,OAAO,CAAE,CAA4B,CAAC,QAAQ,CAAC,CACtD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { WorkspaceGraph, WorkspacePackage } from "./types.js";
|
|
2
|
+
type PkgJson = WorkspacePackage["packageJson"];
|
|
3
|
+
type ReadPkgJson = (path: string) => PkgJson | null;
|
|
4
|
+
export declare function declaredDeps(graph: WorkspaceGraph, read?: ReadPkgJson): string[];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Union of declared dependencies across the workspace root + every workspace
|
|
3
|
+
* package. Used to warm the lazy resolver's by-tag cache so the resolver knows
|
|
4
|
+
* about every package in the consumer's monorepo, not just the root's deps.
|
|
5
|
+
*
|
|
6
|
+
* Pure; the JSON-read side-effect is injected so tests can drive it without
|
|
7
|
+
* filesystem fixtures.
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
const defaultReader = (path) => {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export function declaredDeps(graph, read = defaultReader) {
|
|
20
|
+
const all = new Set();
|
|
21
|
+
collect(read(join(graph.rootPath, "package.json")), all);
|
|
22
|
+
for (const pkg of graph.packages) {
|
|
23
|
+
collect(pkg.packageJson, all);
|
|
24
|
+
}
|
|
25
|
+
return [...all];
|
|
26
|
+
}
|
|
27
|
+
function collect(pkg, into) {
|
|
28
|
+
if (!pkg)
|
|
29
|
+
return;
|
|
30
|
+
for (const bucket of [
|
|
31
|
+
pkg.dependencies,
|
|
32
|
+
pkg.devDependencies,
|
|
33
|
+
pkg.peerDependencies,
|
|
34
|
+
pkg.optionalDependencies,
|
|
35
|
+
]) {
|
|
36
|
+
if (!bucket)
|
|
37
|
+
continue;
|
|
38
|
+
for (const name of Object.keys(bucket))
|
|
39
|
+
into.add(name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=declared-deps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declared-deps.js","sourceRoot":"","sources":["../../src/workspace/declared-deps.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC,MAAM,aAAa,GAAgB,CAAC,IAAI,EAAE,EAAE;IAC1C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,YAAY,CAC1B,KAAqB,EACrB,OAAoB,aAAa;IAEjC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAE9B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEzD,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;AAClB,CAAC;AAED,SAAS,OAAO,CAAC,GAAmB,EAAE,IAAiB;IACrD,IAAI,CAAC,GAAG;QAAE,OAAO;IACjB,KAAK,MAAM,MAAM,IAAI;QACnB,GAAG,CAAC,YAAY;QAChB,GAAG,CAAC,eAAe;QACnB,GAAG,CAAC,gBAAgB;QACpB,GAAG,CAAC,oBAAoB;KACzB,EAAE,CAAC;QACF,IAAI,CAAC,MAAM;YAAE,SAAS;QACtB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Realpath-aware workspace-membership check. Resolves the input path via
|
|
3
|
+
* realpath so node_modules symlinks (yarn/pnpm's usual layout) match their
|
|
4
|
+
* underlying workspace package directories.
|
|
5
|
+
*
|
|
6
|
+
* Returns the WorkspacePackage with the longest absolutePath that is a path
|
|
7
|
+
* prefix of the resolved input. Null when no package owns the file.
|
|
8
|
+
*/
|
|
9
|
+
import { realpathSync } from "node:fs";
|
|
10
|
+
export function findOwningPackage(graph, filePath) {
|
|
11
|
+
if (graph.packages.length === 0)
|
|
12
|
+
return null;
|
|
13
|
+
const resolved = resolveRealpath(filePath);
|
|
14
|
+
let best = null;
|
|
15
|
+
let bestPrefixLen = -1;
|
|
16
|
+
for (const pkg of graph.packages) {
|
|
17
|
+
// Realpath the package root too: on macOS tmpdir resolves through
|
|
18
|
+
// /var -> /private/var, and consumers may pass either form into the graph.
|
|
19
|
+
const pkgPath = resolveRealpath(pkg.absolutePath);
|
|
20
|
+
if (!isPathPrefix(pkgPath, resolved))
|
|
21
|
+
continue;
|
|
22
|
+
// Reject paths that fall inside a node_modules under the workspace
|
|
23
|
+
// package: those are vendor packages installed within the workspace
|
|
24
|
+
// (e.g. <app>/node_modules/@vendor/foo), not the workspace's own source.
|
|
25
|
+
// Symlinked sibling workspaces have already collapsed away via realpath.
|
|
26
|
+
if (resolved.slice(pkgPath.length).includes("/node_modules/"))
|
|
27
|
+
continue;
|
|
28
|
+
if (pkgPath.length > bestPrefixLen) {
|
|
29
|
+
best = pkg;
|
|
30
|
+
bestPrefixLen = pkgPath.length;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return best;
|
|
34
|
+
}
|
|
35
|
+
function resolveRealpath(filePath) {
|
|
36
|
+
try {
|
|
37
|
+
return realpathSync(filePath);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return filePath;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function isPathPrefix(prefix, candidate) {
|
|
44
|
+
if (candidate === prefix)
|
|
45
|
+
return true;
|
|
46
|
+
const withSep = prefix.endsWith("/") ? prefix : `${prefix}/`;
|
|
47
|
+
return candidate.startsWith(withSep);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=find-owning-package.js.map
|