fix(tools): make cli available even conficts exist (#9678)

This commit is contained in:
forehalo
2025-01-14 09:31:23 +00:00
parent e418465c0c
commit 13d40e5f52
5 changed files with 48 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
import { PackageList, type PackageName } from './workspace.gen';
import { PackageList, type PackageName } from './yarn';
export const PackageToDistribution = new Map<
PackageName,

View File

@@ -4,7 +4,7 @@ import { parse } from 'node:path';
import { type Path, ProjectRoot } from './path';
import type { CommonPackageJsonContent, YarnWorkspaceItem } from './types';
import type { Workspace } from './workspace';
import { PackageList, type PackageName } from './workspace.gen';
import { PackageList, type PackageName } from './yarn';
export function readPackageJson(path: Path): CommonPackageJsonContent {
const content = readFileSync(path.join('package.json').toString(), 'utf-8');

View File

@@ -1,11 +1,8 @@
import { once } from 'lodash-es';
import { Logger } from './logger';
import { Package, readPackageJson } from './package';
import { ProjectRoot } from './path';
import { exec } from './process';
import type { CommonPackageJsonContent, YarnWorkspaceItem } from './types';
import { PackageList, type PackageName } from './workspace.gen';
import type { CommonPackageJsonContent } from './types';
import { PackageList, type PackageName, yarnList } from './yarn';
class CircularDependenciesError extends Error {
constructor(public currentName: string) {
@@ -147,25 +144,9 @@ export class Workspace {
building.delete(pkg.name);
}
yarnList = once(() => {
const output = exec('', 'yarn workspaces list -v --json', { silent: true });
let packageList = JSON.parse(
`[${output.trim().replace(/\r\n|\n/g, ',')}]`
) as YarnWorkspaceItem[];
packageList.forEach(p => {
p.location = p.location.replaceAll(/\\/g, '/');
delete p['mismatchedWorkspaceDependencies'];
});
// ignore root package
return packageList.filter(p => p.location !== '.');
});
forEach(callback: (pkg: Package) => void) {
this.packages.forEach(callback);
}
}
export { Package, type PackageName };
export { Package, type PackageName, yarnList };

36
tools/utils/src/yarn.ts Normal file
View File

@@ -0,0 +1,36 @@
import { once } from 'lodash-es';
import { Logger } from './logger';
import { exec } from './process';
import type { YarnWorkspaceItem } from './types';
import type { PackageName } from './workspace.gen';
async function loadPackageList() {
try {
const packageList = await import('./workspace.gen');
return packageList.PackageList;
} catch (e) {
console.log(e);
new Logger('yarn').error('Failed to load package list');
return [];
}
}
export const PackageList = await loadPackageList();
export type { PackageName };
export const yarnList = once(() => {
const output = exec('', 'yarn workspaces list -v --json', { silent: true });
let packageList = JSON.parse(
`[${output.trim().replace(/\r\n|\n/g, ',')}]`
) as YarnWorkspaceItem[];
packageList.forEach(p => {
p.location = p.location.replaceAll(/\\/g, '/');
delete p['mismatchedWorkspaceDependencies'];
});
// ignore root package
return packageList.filter(p => p.location !== '.');
});