Replace findPaths with targetPaths and findOwnPaths
Split the path resolution API in @backstage/cli-common into targetPaths (cwd-based singleton) and findOwnPaths (package-relative). Migrate all consumers across the repo away from the deprecated findPaths. Rename TargetPaths/OwnPaths properties to resolve/resolveRoot, removing the redundant type prefix from property names. Make findOwnPaths calls lazy in modules - called inside functions rather than at module scope. Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -19,7 +19,7 @@ import { spawn, SpawnOptionsWithoutStdio } from 'node:child_process';
|
||||
import fs from 'fs-extra';
|
||||
import yaml from 'yaml';
|
||||
import { buildDepTreeFromFiles } from 'snyk-nodejs-lockfile-parser';
|
||||
import { findPaths } from '@backstage/cli-common';
|
||||
import { targetPaths } from '@backstage/cli-common';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
|
||||
jest.setTimeout(30_000);
|
||||
@@ -86,7 +86,7 @@ describe('Backstage yarn plugin', () => {
|
||||
let initialLockFileContent: string | undefined;
|
||||
|
||||
beforeAll(async () => {
|
||||
const { targetRoot } = findPaths(process.cwd());
|
||||
const targetRoot = targetPaths.resolveRoot();
|
||||
await executeCommand('yarn', ['build'], {
|
||||
cwd: joinPath(targetRoot, 'packages/yarn-plugin'),
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { findPaths, Paths } from '@backstage/cli-common';
|
||||
import { targetPaths } from '@backstage/cli-common';
|
||||
|
||||
const setPlatform = (platform: string) => {
|
||||
Object.defineProperty(process, `platform`, {
|
||||
@@ -37,7 +37,7 @@ describe('getWorkspaceRoot', () => {
|
||||
`('platform: $platform', ({ platform, native, portable }) => {
|
||||
let realPlatform: string;
|
||||
let getWorkspaceRoot: () => string;
|
||||
let mockFindPaths: jest.MockedFunction<typeof findPaths>;
|
||||
let mockResolveRoot: jest.MockedFunction<typeof targetPaths.resolveRoot>;
|
||||
|
||||
beforeEach(() => {
|
||||
realPlatform = process.platform;
|
||||
@@ -45,11 +45,13 @@ describe('getWorkspaceRoot', () => {
|
||||
|
||||
jest.resetModules();
|
||||
|
||||
mockFindPaths = jest.fn();
|
||||
mockResolveRoot = jest.fn();
|
||||
|
||||
jest.doMock('@backstage/cli-common', () => ({
|
||||
...jest.requireActual('@backstage/cli-common'),
|
||||
findPaths: mockFindPaths,
|
||||
targetPaths: {
|
||||
resolveRoot: mockResolveRoot,
|
||||
},
|
||||
}));
|
||||
|
||||
getWorkspaceRoot = require('./getWorkspaceRoot').getWorkspaceRoot;
|
||||
@@ -60,9 +62,7 @@ describe('getWorkspaceRoot', () => {
|
||||
});
|
||||
|
||||
it('returns an appropriately-formatted workspace root path', () => {
|
||||
mockFindPaths.mockReturnValue({
|
||||
targetRoot: native,
|
||||
} as Paths);
|
||||
mockResolveRoot.mockReturnValue(native);
|
||||
|
||||
expect(getWorkspaceRoot()).toEqual(portable);
|
||||
});
|
||||
|
||||
@@ -14,11 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { npath, ppath } from '@yarnpkg/fslib';
|
||||
import { findPaths } from '@backstage/cli-common';
|
||||
import { npath } from '@yarnpkg/fslib';
|
||||
import { targetPaths } from '@backstage/cli-common';
|
||||
|
||||
export const getWorkspaceRoot = () => {
|
||||
return npath.toPortablePath(
|
||||
findPaths(npath.fromPortablePath(ppath.cwd())).targetRoot,
|
||||
);
|
||||
return npath.toPortablePath(targetPaths.resolveRoot());
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user