yarn-plugin: use findPaths from cli-common instead of custom findWorkspaceRoot implementation

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2024-06-04 17:01:59 +01:00
parent 95d7234e91
commit 573e98b352
5 changed files with 15 additions and 33 deletions
+1
View File
@@ -30,6 +30,7 @@
"watch": "./src"
},
"dependencies": {
"@backstage/cli-common": "workspace:^",
"@backstage/release-manifests": "workspace:^",
"@yarnpkg/core": "^4.0.3",
"@yarnpkg/fslib": "^3.0.2",
@@ -46,6 +46,10 @@ describe('beforeWorkspacePacking', () => {
.spyOn(ppath, 'cwd')
.mockReturnValue(npath.toPortablePath(mockDir.path));
jest
.spyOn(process, 'cwd')
.mockReturnValue(npath.toPortablePath(mockDir.path));
mockDir.setContent({
'backstage.json': JSON.stringify({
version: '1.23.45',
@@ -40,6 +40,10 @@ describe('BackstageResolver', () => {
.spyOn(ppath, 'cwd')
.mockReturnValue(npath.toPortablePath(mockDir.path));
jest
.spyOn(process, 'cwd')
.mockReturnValue(npath.toPortablePath(mockDir.path));
mockDir.setContent({
'backstage.json': JSON.stringify({
version: '1.23.45',
+5 -33
View File
@@ -14,46 +14,18 @@
* limitations under the License.
*/
import { PortablePath, ppath, xfs } from '@yarnpkg/fslib';
import { ppath, xfs } from '@yarnpkg/fslib';
import { valid as semverValid } from 'semver';
import { getManifestByVersion } from '@backstage/release-manifests';
import { BACKSTAGE_JSON, findPaths } from '@backstage/cli-common';
import { Descriptor, structUtils } from '@yarnpkg/core';
import { PROTOCOL } from './constants';
const isWorkspaceRoot = (dir: PortablePath) => {
const manifestPath = ppath.join(dir, 'package.json');
if (xfs.existsSync(manifestPath)) {
const manifest = xfs.readJsonSync(manifestPath);
if (manifest.workspaces) {
return true;
}
}
return false;
};
const findWorkspaceRoot = () => {
const cwd = ppath.cwd();
let currentDir = cwd;
while (!isWorkspaceRoot(currentDir)) {
const parentDir = ppath.dirname(currentDir);
if (parentDir === currentDir) {
throw new Error(`Workspace root not found from ${cwd}`);
}
currentDir = parentDir;
}
return currentDir;
};
export const getCurrentBackstageVersion = () => {
const workspaceRoot = ppath.resolve(findPaths(ppath.cwd()).targetRoot);
const backstageJson = xfs.readJsonSync(
ppath.join(findWorkspaceRoot(), 'backstage.json'),
ppath.join(workspaceRoot, BACKSTAGE_JSON),
);
const backstageVersion = semverValid(backstageJson.version);
+1
View File
@@ -45133,6 +45133,7 @@ __metadata:
dependencies:
"@backstage/backend-test-utils": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/cli-common": "workspace:^"
"@backstage/release-manifests": "workspace:^"
"@yarnpkg/builder": ^4.0.0
"@yarnpkg/core": ^4.0.3