fix: Support workspaces in CLIs

Signed-off-by: Gabriel Dugny <gabriel.dugny@believe.com>
This commit is contained in:
Gabriel Dugny
2026-01-29 10:24:31 +01:00
parent ebd4630702
commit a9d23c4a32
13 changed files with 79 additions and 62 deletions
+3 -3
View File
@@ -20,6 +20,7 @@ const crypto = require('node:crypto');
const glob = require('node:util').promisify(require('glob'));
const { version } = require('../package.json');
const paths = require('@backstage/cli-common').findPaths(process.cwd());
const { getWorkspacesPatterns } = require('@backstage/cli-common');
const {
getJestEnvironment,
getJestMajorVersion,
@@ -336,11 +337,10 @@ async function getRootConfig() {
rejectFrontendNetworkRequests,
};
const workspacePatterns =
rootPkgJson.workspaces && rootPkgJson.workspaces.packages;
const workspacePatterns = getWorkspacesPatterns(rootPkgJson);
// Check if we're running within a specific monorepo package. In that case just get the single project config.
if (!workspacePatterns || paths.targetRoot !== paths.targetDir) {
if (workspacePatterns.length === 0 || paths.targetRoot !== paths.targetDir) {
return getProjectConfig(
paths.targetDir,
{
@@ -104,9 +104,7 @@ describe('mapDependencies', () => {
it('should read dependencies', async () => {
mockDir.setContent({
'package.json': JSON.stringify({
workspaces: {
packages: ['pkgs/*'],
},
workspaces: ['pkgs/*'],
}),
pkgs: {
a: {
@@ -160,9 +160,7 @@ describe('bump', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -255,9 +253,7 @@ describe('bump', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -353,9 +349,7 @@ describe('bump', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -459,9 +453,7 @@ describe('bump', () => {
'.yarnrc.yml': yarnRcMock,
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -572,9 +564,7 @@ describe('bump', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -644,9 +634,7 @@ describe('bump', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -750,9 +738,7 @@ describe('bump', () => {
mockDir.setContent({
'yarn.lock': customLockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -865,9 +851,7 @@ describe('bump', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -1099,9 +1083,7 @@ describe('environment variables', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -1192,9 +1174,7 @@ describe('environment variables', () => {
'custom-manifest.json': JSON.stringify(customManifest),
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -1262,9 +1242,7 @@ describe('environment variables', () => {
'.yarnrc.yml': yarnRcMock,
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -1337,9 +1315,7 @@ describe('environment variables', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -1362,9 +1338,7 @@ describe('environment variables', () => {
mockDir.setContent({
'yarn.lock': lockfileMock,
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
packages: {
a: {
@@ -73,9 +73,7 @@ describe('versions:migrate', () => {
it('should bump to the moved version when the package is moved', async () => {
mockDir.setContent({
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
node_modules: {
'@backstage': {
@@ -177,9 +175,7 @@ describe('versions:migrate', () => {
it('should replace the occurrences of the moved package in files inside the correct package', async () => {
mockDir.setContent({
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
node_modules: {
'@backstage': {
@@ -264,9 +260,7 @@ describe('versions:migrate', () => {
it('should replace occurrences of changed packages, and is careful', async () => {
mockDir.setContent({
'package.json': JSON.stringify({
workspaces: {
packages: ['packages/*'],
},
workspaces: ['packages/*'],
}),
node_modules: {
'@backstage': {