Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Yarn's workspaces being an object with a packages array #33

Closed
gustavopch opened this issue Apr 30, 2020 · 2 comments
Closed

Support Yarn's workspaces being an object with a packages array #33

gustavopch opened this issue Apr 30, 2020 · 2 comments

Comments

@gustavopch
Copy link

Problem

Currently, syncpack only understands the following syntax for Yarn Workspaces:

{
  "workspaces": ["packages/*"]
}

Desired behavior

But is should also support:

{
  "workspaces": {
    "packages": ["packages/*"]
  }
}

Proposed solution

AFAICT, the getYarnPatterns function in the get-wrappers.ts file should be modified to something like:

const getYarnPatterns = () => {
  const workspaces = getPatternsFromConfig('package.json', 'workspaces');
  return Array.isArray(workspaces) ? workspaces : workspaces.packages;
};
@gustavopch
Copy link
Author

Actually, my proposed solution above won't work because getPatternsFromConfig will return null in case the property is not a non-empty array, which will be the case when workspaces is an object.

Instead, something like the following would do the job:

import get from 'lodash.get'
// ...
const getPatternsFromConfig = (fileName: string, propPath: string): string[] | null => {
  // ...
  const propValue = get(config, propPath);
  const isNonEmptyArray = config && propValue && propValue.length > 0;
  return isNonEmptyArray
    ? [process.cwd()].concat(propValue).map((dirPath: string) => join(dirPath, 'package.json'))
    : null;
};
// ...
const getYarnPatterns = () => getPatternsFromConfig('package.json', 'workspaces') || getPatternsFromConfig('package.json', 'workspaces.packages');

@JamieMason
Copy link
Owner

Released in 5.5.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants