Revert most changes

Signed-off-by: Gabriel Dugny <gabriel.dugny@believe.com>
This commit is contained in:
Gabriel Dugny
2026-02-22 17:00:06 +01:00
parent b2d9d78c27
commit 0e5fd0fd27
11 changed files with 18 additions and 152 deletions
+5 -3
View File
@@ -14,12 +14,14 @@
* limitations under the License.
*/
import { getWorkspacesPatterns } from '@backstage/cli-common';
import { paths } from '../paths';
import fs from 'fs-extra';
/**
* Returns try if the current project is a monorepo.
* Returns true if the current project is a monorepo.
*
* Uses a simple presence check on the `workspaces` field. Empty or invalid
* workspace config is treated as a monorepo; we do not validate patterns.
*
* @public
*/
@@ -27,7 +29,7 @@ export async function isMonoRepo(): Promise<boolean> {
const rootPackageJsonPath = paths.resolveTargetRoot('package.json');
try {
const pkg = await fs.readJson(rootPackageJsonPath);
return getWorkspacesPatterns(pkg).length > 0;
return Boolean(pkg?.workspaces);
} catch (error) {
return false;
}
@@ -43,19 +43,19 @@ describe('PackageManager', () => {
expect(mockYarnCreate).toHaveBeenCalled();
});
it('should detect via root package.json workspaces with legacy workspaces.packages field', async () => {
it('should detect via root package.json workspaces', async () => {
mockDir.setContent({
'package.json': JSON.stringify({
name: 'foo',
workspaces: {
packages: ['packages/*'],
packages: [],
},
}),
});
await detectPackageManager();
expect(mockYarnCreate).toHaveBeenCalled();
});
it('should detect via root package.json workspaces', async () => {
it('should detect via root package.json workspaces (array form)', async () => {
mockDir.setContent({
'package.json': JSON.stringify({
name: 'foo',
@@ -17,7 +17,7 @@
import { Yarn } from './yarn';
import { Lockfile } from './Lockfile';
import { paths } from '../paths';
import { getWorkspacesPatterns, RunOptions } from '@backstage/cli-common';
import { RunOptions } from '@backstage/cli-common';
import fs from 'fs-extra';
/**
@@ -101,7 +101,7 @@ export async function detectPackageManager(): Promise<PackageManager> {
const packageJson = await fs.readJson(
paths.resolveTargetRoot('package.json'),
);
if (getWorkspacesPatterns(packageJson).length > 0) {
if (packageJson.workspaces) {
// technically this could be NPM as well
return await Yarn.create();
}
+4 -2
View File
@@ -25,7 +25,6 @@ import { YarnVersion } from './types';
import fs from 'fs-extra';
import { paths } from '../../paths';
import { run, runOutput, RunOptions } from '@backstage/cli-common';
import { getWorkspacesPatterns } from '@backstage/cli-common';
export class Yarn implements PackageManager {
constructor(private readonly yarnVersion: YarnVersion) {}
@@ -51,7 +50,10 @@ export class Yarn implements PackageManager {
const rootPackageJsonPath = paths.resolveTargetRoot('package.json');
try {
const pkg = await fs.readJson(rootPackageJsonPath);
return getWorkspacesPatterns(pkg);
const workspaces = pkg?.workspaces;
return Array.isArray(workspaces)
? workspaces
: workspaces?.packages ?? [];
} catch (error) {
return [];
}