cli-common: fix workspace check
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli-common': patch
|
||||
---
|
||||
|
||||
The monorepo root check in `findPaths` will now accept a shorthand `workspaces` config in `package.json`, no longer requiring `workspaces.packages`.
|
||||
@@ -19,6 +19,10 @@ import { resolve as resolvePath } from 'path';
|
||||
import { findPaths, findRootPath, findOwnDir, findOwnRootDir } from './paths';
|
||||
|
||||
describe('paths', () => {
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('findOwnDir and findOwnRootDir should find owns paths', () => {
|
||||
const dir = findOwnDir(__dirname);
|
||||
const root = findOwnRootDir(dir);
|
||||
@@ -92,4 +96,28 @@ describe('paths', () => {
|
||||
resolvePath(root, 'derp.txt'),
|
||||
);
|
||||
});
|
||||
|
||||
it('findPaths should find workspace root with object', () => {
|
||||
jest.spyOn(JSON, 'parse').mockReturnValue({ workspaces: { packages: [] } });
|
||||
jest.spyOn(process, 'cwd').mockReturnValue(__dirname);
|
||||
|
||||
const paths = findPaths(__dirname);
|
||||
|
||||
expect(paths.targetDir).toBe(
|
||||
resolvePath(__dirname, '../../cli-common/src'),
|
||||
);
|
||||
expect(paths.targetRoot).toBe(resolvePath(__dirname, '../../cli-common'));
|
||||
});
|
||||
|
||||
it('findPaths should find workspace root with array', () => {
|
||||
jest.spyOn(JSON, 'parse').mockReturnValue({ workspaces: [] });
|
||||
jest.spyOn(process, 'cwd').mockReturnValue(__dirname);
|
||||
|
||||
const paths = findPaths(__dirname);
|
||||
|
||||
expect(paths.targetDir).toBe(
|
||||
resolvePath(__dirname, '../../cli-common/src'),
|
||||
);
|
||||
expect(paths.targetRoot).toBe(resolvePath(__dirname, '../../cli-common'));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -141,7 +141,7 @@ export function findPaths(searchDir: string): Paths {
|
||||
try {
|
||||
const content = fs.readFileSync(path, 'utf8');
|
||||
const data = JSON.parse(content);
|
||||
return Boolean(data.workspaces?.packages);
|
||||
return Boolean(data.workspaces);
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Failed to parse package.json file while searching for root, ${error}`,
|
||||
|
||||
Reference in New Issue
Block a user