mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
fix(tools): make cli available even conficts exist (#9678)
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
import { readFileSync, writeFileSync } from 'node:fs';
|
import { readFileSync, writeFileSync } from 'node:fs';
|
||||||
|
|
||||||
import type { Path } from '@affine-tools/utils/path';
|
import type { Path } from '@affine-tools/utils/path';
|
||||||
import { type Package, Workspace } from '@affine-tools/utils/workspace';
|
import {
|
||||||
|
type Package,
|
||||||
|
Workspace,
|
||||||
|
yarnList,
|
||||||
|
} from '@affine-tools/utils/workspace';
|
||||||
import { applyEdits, modify } from 'jsonc-parser';
|
import { applyEdits, modify } from 'jsonc-parser';
|
||||||
import { type BuiltInParserName, format } from 'prettier';
|
import { type BuiltInParserName, format } from 'prettier';
|
||||||
|
|
||||||
@@ -17,7 +21,7 @@ export class InitCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async generateWorkspaceFiles() {
|
async generateWorkspaceFiles() {
|
||||||
this.workspace = new Workspace(this.workspace.yarnList());
|
this.workspace = new Workspace(yarnList());
|
||||||
const filesToGenerate: [
|
const filesToGenerate: [
|
||||||
Path,
|
Path,
|
||||||
(prev: string) => string,
|
(prev: string) => string,
|
||||||
@@ -80,7 +84,7 @@ export class InitCommand extends Command {
|
|||||||
};
|
};
|
||||||
|
|
||||||
genWorkspaceInfo = () => {
|
genWorkspaceInfo = () => {
|
||||||
const list = this.workspace.yarnList();
|
const list = yarnList();
|
||||||
|
|
||||||
const names = list.map(p => p.name);
|
const names = list.map(p => p.name);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { PackageList, type PackageName } from './workspace.gen';
|
import { PackageList, type PackageName } from './yarn';
|
||||||
|
|
||||||
export const PackageToDistribution = new Map<
|
export const PackageToDistribution = new Map<
|
||||||
PackageName,
|
PackageName,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { parse } from 'node:path';
|
|||||||
import { type Path, ProjectRoot } from './path';
|
import { type Path, ProjectRoot } from './path';
|
||||||
import type { CommonPackageJsonContent, YarnWorkspaceItem } from './types';
|
import type { CommonPackageJsonContent, YarnWorkspaceItem } from './types';
|
||||||
import type { Workspace } from './workspace';
|
import type { Workspace } from './workspace';
|
||||||
import { PackageList, type PackageName } from './workspace.gen';
|
import { PackageList, type PackageName } from './yarn';
|
||||||
|
|
||||||
export function readPackageJson(path: Path): CommonPackageJsonContent {
|
export function readPackageJson(path: Path): CommonPackageJsonContent {
|
||||||
const content = readFileSync(path.join('package.json').toString(), 'utf-8');
|
const content = readFileSync(path.join('package.json').toString(), 'utf-8');
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import { once } from 'lodash-es';
|
|
||||||
|
|
||||||
import { Logger } from './logger';
|
import { Logger } from './logger';
|
||||||
import { Package, readPackageJson } from './package';
|
import { Package, readPackageJson } from './package';
|
||||||
import { ProjectRoot } from './path';
|
import { ProjectRoot } from './path';
|
||||||
import { exec } from './process';
|
import type { CommonPackageJsonContent } from './types';
|
||||||
import type { CommonPackageJsonContent, YarnWorkspaceItem } from './types';
|
import { PackageList, type PackageName, yarnList } from './yarn';
|
||||||
import { PackageList, type PackageName } from './workspace.gen';
|
|
||||||
|
|
||||||
class CircularDependenciesError extends Error {
|
class CircularDependenciesError extends Error {
|
||||||
constructor(public currentName: string) {
|
constructor(public currentName: string) {
|
||||||
@@ -147,25 +144,9 @@ export class Workspace {
|
|||||||
building.delete(pkg.name);
|
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) {
|
forEach(callback: (pkg: Package) => void) {
|
||||||
this.packages.forEach(callback);
|
this.packages.forEach(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Package, type PackageName };
|
export { Package, type PackageName, yarnList };
|
||||||
|
|||||||
@@ -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 !== '.');
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user