Skip to content

Commit

Permalink
Merge pull request #76 from mhassan1/yarn-workspaces-alternate-config
Browse files Browse the repository at this point in the history
feat: add support for yarn workspaces pattern in workspaces.packages
  • Loading branch information
gitphill committed Jun 30, 2020
2 parents b05dc23 + 6b84fb0 commit f8814e0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ export interface Dep {
dev?: boolean;
}

interface WorkspacesAlternateConfig {
packages?: string[];
}

export interface ManifestFile {
name: string;
private?: string;
engines?: {
node?: string;
};
workspaces?: string[];
workspaces?: string[] | WorkspacesAlternateConfig;
dependencies?: {
[dep: string]: string;
};
Expand Down Expand Up @@ -126,7 +130,10 @@ export function getYarnWorkspaces(targetFile: string): string[] | false {
try {
const packageJson: ManifestFile = parseManifestFile(targetFile);
if (!!packageJson.workspaces && !!packageJson.private) {
return [...packageJson.workspaces];
const workspacesPackages = packageJson.workspaces as string[];
const workspacesAlternateConfigPackages = (packageJson.workspaces as WorkspacesAlternateConfig)
.packages;
return [...(workspacesAlternateConfigPackages || workspacesPackages)];
}
return false;
} catch (e) {
Expand Down
12 changes: 12 additions & 0 deletions test/lib/fixtures/yarn-workspace-alternate-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"private": true,
"name": "jest",
"devDependencies": {
"chalk": "^2.0.1"
},
"workspaces": {
"packages": [
"packages/*"
]
}
}
8 changes: 8 additions & 0 deletions test/lib/yarn-workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ test('Identify package.json as a yarn workspace', async (t) => {
);
});

test('Identify package.json as a yarn workspace when using alternate configuration format', async (t) => {
const workspaces = getYarnWorkspacesFromFiles(
`${__dirname}/fixtures/yarn-workspace-alternate-config/`,
'package.json',
);
t.deepEqual(workspaces, ['packages/*'], 'Workspaces identified as expected');
});

test('identify package.json as Not a workspace project', async (t) => {
const workspaces = getYarnWorkspacesFromFiles(
`${__dirname}/fixtures/external-tarball/`,
Expand Down

0 comments on commit f8814e0

Please sign in to comment.