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:
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user