Skip to content

Commit 664b7d3

Browse files
committed
feat: components update
Component dependencies should link to components in the workspace
1 parent 4204d11 commit 664b7d3

File tree

3 files changed

+119
-15
lines changed

3 files changed

+119
-15
lines changed

scopes/dependencies/pnpm/lynx.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ export async function install(
291291
disableRelinkLocalDirDeps: true,
292292
hoistPattern,
293293
virtualStoreDirMaxLength: VIRTUAL_STORE_DIR_MAX_LENGTH,
294+
linkWorkspacePackagesDepth: Infinity, // Does this ignore range?
294295
};
295296

296297
let dependenciesChanged = false;

scopes/dependencies/pnpm/pnpm.package-manager.ts

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
createPackagesSearcher,
3131
PackageNode,
3232
} from '@pnpm/reviewing.dependencies-hierarchy';
33+
import * as dp from '@pnpm/dependency-path';
3334
import { renderTree } from '@pnpm/list';
3435
import {
3536
readWantedLockfile,
@@ -126,19 +127,45 @@ export class PnpmPackageManager implements PackageManager {
126127
const proxyConfig = await this.depResolver.getProxyConfig();
127128
const networkConfig = await this.depResolver.getNetworkConfig();
128129
const { config } = await this.readConfig(installOptions.packageManagerConfigRootDir);
129-
if (
130-
installOptions.dependenciesGraph &&
131-
isFeatureEnabled(DEPS_GRAPH) &&
132-
(installOptions.rootComponents || installOptions.rootComponentsForCapsules)
133-
) {
134-
await this.dependenciesGraphToLockfile(installOptions.dependenciesGraph, {
135-
manifests,
136-
rootDir,
137-
registries,
138-
proxyConfig,
139-
networkConfig,
140-
cacheDir: config.cacheDir,
141-
});
130+
const overrides = { ...installOptions.overrides };
131+
console.log(installOptions.dependenciesGraph != null)
132+
if (installOptions.dependenciesGraph) {
133+
if (
134+
isFeatureEnabled(DEPS_GRAPH) &&
135+
(installOptions.rootComponents || installOptions.rootComponentsForCapsules)
136+
) {
137+
try {
138+
await this.dependenciesGraphToLockfile(installOptions.dependenciesGraph, {
139+
manifests,
140+
rootDir,
141+
registries,
142+
proxyConfig,
143+
networkConfig,
144+
cacheDir: config.cacheDir,
145+
});
146+
} catch (err) {
147+
console.log(err)
148+
}
149+
}
150+
const allPackageNames: string[] = [];
151+
for (const manifest of Object.values(manifests)) {
152+
if (manifest.name != null && manifest.name !== 'workspace') {
153+
allPackageNames.push(manifest.name);
154+
}
155+
}
156+
const paths = installOptions.dependenciesGraph.findPathsToPackages(allPackageNames);
157+
console.log(paths)
158+
for (const allEdgeIds of Object.values(paths)) {
159+
for (const edgeIds of allEdgeIds) {
160+
for (const edgeId of edgeIds.slice(0, edgeIds.length - 1)) {
161+
const parsed = dp.parse(edgeId);
162+
if (parsed.name) {
163+
overrides[parsed.name] = 'latest';
164+
}
165+
}
166+
}
167+
}
168+
console.log(overrides)
142169
}
143170

144171
this.logger.debug(`running installation in root dir ${rootDir}`);
@@ -184,7 +211,7 @@ export class PnpmPackageManager implements PackageManager {
184211
ignorePackageManifest: installOptions.ignorePackageManifest,
185212
dedupeInjectedDeps: installOptions.dedupeInjectedDeps ?? false,
186213
dryRun: installOptions.dependenciesGraph == null && installOptions.dryRun,
187-
overrides: installOptions.overrides,
214+
overrides,
188215
hoistPattern: installOptions.hoistPatterns ?? config.hoistPattern,
189216
publicHoistPattern: config.shamefullyHoist
190217
? ['*']

scopes/scope/objects/models/dependencies-graph.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,83 @@ export class DependenciesGraph {
107107
* Returns the edge related to the root component
108108
*/
109109
findRootEdge(): DependencyEdge | undefined {
110-
return this.edges.find(({ id }) => id === DependenciesGraph.ROOT_EDGE_ID);
110+
return this.findEdgeById(DependenciesGraph.ROOT_EDGE_ID);
111+
}
112+
113+
findEdgeById(edgeId: string): DependencyEdge | undefined {
114+
return this.edges.find(({ id }) => id === edgeId);
115+
}
116+
117+
/**
118+
* Finds all possible paths from the root to the specified package names
119+
* @param targetPackageNames Array of package names to find paths to
120+
* @returns An object mapping each target package name to an array of paths,
121+
* where each path is an array of node IDs representing the traversal from root to target
122+
*/
123+
findPathsToPackages(targetPackageNames: string[]): Record<string, string[][]> {
124+
const result: Record<string, string[][]> = {};
125+
const rootEdge = this.findRootEdge();
126+
127+
// Initialize result object with empty arrays for each target package
128+
for (const packageName of targetPackageNames) {
129+
result[packageName] = [];
130+
}
131+
132+
if (!rootEdge) {
133+
return result; // Return empty result if no root edge found
134+
}
135+
136+
// Helper function to perform depth-first search
137+
const dfs = (
138+
currentEdgeId: string,
139+
currentPath: string[],
140+
visited: Set<string>
141+
) => {
142+
// Avoid cycles by checking if we've already visited this node
143+
if (visited.has(currentEdgeId)) {
144+
return;
145+
}
146+
147+
visited.add(currentEdgeId);
148+
currentPath.push(currentEdgeId);
149+
150+
// Find the current edge
151+
const currentEdge = this.findEdgeById(currentEdgeId);
152+
// console.log(currentEdge)
153+
if (!currentEdge) {
154+
// Remove the node from path and visited if it doesn't exist
155+
currentPath.pop();
156+
visited.delete(currentEdgeId);
157+
return;
158+
}
159+
160+
// Check if the current edge represents a package in our target list
161+
// const packageAttr = this.packages.get(currentEdge.attr?.pkgId ?? currentEdge.id);
162+
// console.log(currentEdge)
163+
// console.log(packageAttr)
164+
const parsed = dp.parse(currentEdgeId);
165+
if (parsed.name) {
166+
// console.log(packageAttr.name)
167+
if (targetPackageNames.includes(parsed.name)) {
168+
// Found a path to a target package, add it to results
169+
result[parsed.name].push([...currentPath]);
170+
}
171+
}
172+
173+
// Visit all neighbors
174+
for (const neighbor of currentEdge.neighbours) {
175+
dfs(neighbor.id, [...currentPath], new Set(visited));
176+
}
177+
178+
// Backtrack
179+
currentPath.pop();
180+
visited.delete(currentEdgeId);
181+
};
182+
183+
// Start DFS from the root edge
184+
dfs(rootEdge.id, [], new Set());
185+
186+
return result;
111187
}
112188
}
113189

0 commit comments

Comments
 (0)