Repository navigation
fix(@angular/cli): support resolving subproject dependencies in bun workspaces #34533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alan-agius4
merged 2 commits into
angular:main
from
clydin:fix/bun-workspace-dependencies
Oct 27, 2026
+616
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
193 changes: 193 additions & 0 deletions
193
packages/angular/cli/src/package-managers/manifest-dependencies.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { dirname, join } from 'node:path'; | ||
| import type { Host } from './host'; | ||
| import type { InstalledPackage } from './package-tree'; | ||
|
|
||
| /** | ||
| * Maximum number of concurrent file system read operations to prevent OS file descriptor exhaustion. | ||
| */ | ||
| const MAX_CONCURRENT_READS = 16; | ||
|
|
||
| /** | ||
| * Maps each item to a result using an asynchronous function, running at most `limit` operations | ||
| * concurrently. Results are returned in the same order as the input items. | ||
| */ | ||
| async function mapConcurrent<T, R>( | ||
| items: readonly T[], | ||
| limit: number, | ||
| fn: (item: T) => Promise<R>, | ||
| ): Promise<R[]> { | ||
| const results = new Array<R>(items.length); | ||
| let index = 0; | ||
|
|
||
| const worker = async () => { | ||
| while (index < items.length) { | ||
| const i = index++; | ||
| results[i] = await fn(items[i]); | ||
| } | ||
| }; | ||
|
|
||
| await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker)); | ||
|
|
||
| return results; | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether a path exists and matches the expected type. | ||
| */ | ||
| async function isPathOfType( | ||
| host: Host, | ||
| path: string, | ||
| type: 'file' | 'directory' | 'any', | ||
| ): Promise<boolean> { | ||
| try { | ||
| const stats = await host.stat(path); | ||
|
|
||
| switch (type) { | ||
| case 'file': | ||
| return stats.isFile(); | ||
| case 'directory': | ||
| return stats.isDirectory(); | ||
| case 'any': | ||
| return true; | ||
| } | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Finds existing `node_modules` directories starting from `startDir` and walking up | ||
| * ancestor directories until reaching a directory with one of `lockfiles` or the git repository root. | ||
| */ | ||
| async function findNodeModulesDirectories( | ||
| host: Host, | ||
| startDir: string, | ||
| lockfiles: readonly string[], | ||
| ): Promise<string[]> { | ||
| const directories: string[] = []; | ||
| let currentDir = startDir; | ||
|
|
||
| while (true) { | ||
| const nodeModulesPath = join(currentDir, 'node_modules'); | ||
| const [hasNodeModules, isGitRoot, ...lockfileChecks] = await Promise.all([ | ||
| isPathOfType(host, nodeModulesPath, 'directory'), | ||
| // `.git` is a file (not a directory) in git worktrees and submodules. | ||
| isPathOfType(host, join(currentDir, '.git'), 'any'), | ||
| ...lockfiles.map((lockfile) => isPathOfType(host, join(currentDir, lockfile), 'file')), | ||
| ]); | ||
|
|
||
| if (hasNodeModules) { | ||
| directories.push(nodeModulesPath); | ||
| } | ||
|
|
||
| // Stop walking up once we reach a directory containing the package manager's lockfile | ||
| // or the git repository root. | ||
| if (isGitRoot || lockfileChecks.some(Boolean)) { | ||
| break; | ||
| } | ||
|
|
||
| const parentDir = dirname(currentDir); | ||
| if (parentDir === currentDir) { | ||
| break; | ||
| } | ||
| currentDir = parentDir; | ||
| } | ||
|
|
||
| return directories; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the installed manifest of a package by searching the given `node_modules` | ||
| * directories in order. | ||
| */ | ||
| async function resolveInstalledPackage( | ||
| host: Host, | ||
| packageName: string, | ||
| nodeModulesDirs: readonly string[], | ||
| ): Promise<InstalledPackage | undefined> { | ||
| for (const nodeModulesDir of nodeModulesDirs) { | ||
| const packagePath = join(nodeModulesDir, packageName); | ||
| try { | ||
| const pkgContent = await host.readFile(join(packagePath, 'package.json')); | ||
| const { version } = JSON.parse(pkgContent) as { version?: unknown }; | ||
| if (typeof version === 'string') { | ||
| return { name: packageName, version, path: packagePath }; | ||
| } | ||
| } catch { | ||
| // Continue searching ancestor node_modules directories. | ||
| } | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves installed versions of dependencies declared in the given directory's `package.json` | ||
| * by searching ancestor `node_modules` directories starting from `cwd`. | ||
| * | ||
| * The returned map preserves the declaration order of the manifest. | ||
| */ | ||
| export async function resolveManifestDependencies( | ||
| host: Host, | ||
| cwd: string, | ||
| lockfiles: readonly string[], | ||
| ): Promise<Map<string, InstalledPackage>> { | ||
| const resolvedDependencies = new Map<string, InstalledPackage>(); | ||
|
|
||
| let manifest: { | ||
| dependencies?: Record<string, string>; | ||
| devDependencies?: Record<string, string>; | ||
| }; | ||
| try { | ||
| manifest = JSON.parse(await host.readFile(join(cwd, 'package.json'))); | ||
| } catch { | ||
| return resolvedDependencies; | ||
| } | ||
|
|
||
| if (!manifest || typeof manifest !== 'object') { | ||
| return resolvedDependencies; | ||
| } | ||
|
|
||
| const declaredPackages = new Set<string>(); | ||
| for (const depMap of [manifest.dependencies, manifest.devDependencies]) { | ||
| if (!depMap || typeof depMap !== 'object') { | ||
| continue; | ||
| } | ||
| for (const [name, specifier] of Object.entries(depMap)) { | ||
| if (typeof specifier === 'string' && !specifier.startsWith('workspace:')) { | ||
| declaredPackages.add(name); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (declaredPackages.size === 0) { | ||
| return resolvedDependencies; | ||
| } | ||
|
|
||
| const nodeModulesDirs = await findNodeModulesDirectories(host, cwd, lockfiles); | ||
| if (nodeModulesDirs.length === 0) { | ||
| return resolvedDependencies; | ||
| } | ||
|
|
||
| const installedPackages = await mapConcurrent( | ||
| [...declaredPackages], | ||
| MAX_CONCURRENT_READS, | ||
| (packageName) => resolveInstalledPackage(host, packageName, nodeModulesDirs), | ||
| ); | ||
|
|
||
| for (const installedPackage of installedPackages) { | ||
| if (installedPackage) { | ||
| resolvedDependencies.set(installedPackage.name, installedPackage); | ||
| } | ||
| } | ||
|
|
||
| return resolvedDependencies; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.