Skip to content

Commit aea2ccf

Browse files
committed
Normalize getProject interface to be like other functions
1 parent 806d0ff commit aea2ccf

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

‎src/functions/__tests__/getProject.test.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('function/getProject', () => {
99
it('should return path to a project root folder from a workspace', async () => {
1010
const projectRoot = await getFixturePath(__dirname, 'simple-project');
1111
const workspacePath = path.join(projectRoot, 'packages', 'bar');
12-
return getProject(workspacePath).then(pr =>
12+
return getProject({ cwd: workspacePath }).then(pr =>
1313
expect(pr.dir).toBe(projectRoot)
1414
);
1515
});
@@ -19,7 +19,7 @@ describe('function/getProject', () => {
1919
it('should return path to a project root folder from a workspace', async () => {
2020
const projectRoot = await getFixturePath(__dirname, 'nested-workspaces');
2121
const workspacePath = path.join(projectRoot, 'packages', 'foo');
22-
return getProject(workspacePath).then(pr =>
22+
return getProject({ cwd: workspacePath }).then(pr =>
2323
expect(pr.dir).toBe(projectRoot)
2424
);
2525
});
@@ -33,7 +33,7 @@ describe('function/getProject', () => {
3333
'packages',
3434
'baz'
3535
);
36-
return getProject(workspacePath).then(pr =>
36+
return getProject({ cwd: workspacePath }).then(pr =>
3737
expect(pr.dir).toBe(projectRoot)
3838
);
3939
});

‎src/functions/getProject.js‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
/* @flow */
2-
3-
import path from 'path';
1+
// @flow
2+
import * as path from 'path';
43
import Project from '../Project';
4+
import type { JSONValue } from '../types';
5+
6+
type Options = {
7+
cwd?: string
8+
};
9+
10+
type Package = {
11+
dir: string,
12+
name: string,
13+
config: JSONValue
14+
};
15+
16+
export default async function getProject(opts: Options = {}): Promise<Package> {
17+
let cwd = opts.cwd || process.cwd();
18+
let project = await Project.init(cwd);
519

6-
export default async function getProject(dir: string) {
7-
const project = await Project.init(dir);
820
return {
921
dir: project.pkg.dir,
1022
name: project.pkg.config.getName(),

0 commit comments

Comments
 (0)