update-workspaces.js 626 B

1234567891011121314151617181920212223242526
  1. const updateWorkspaces = ({ content, originalContent = {} }) => {
  2. const newWorkspaces = content.workspaces
  3. if (!newWorkspaces) {
  4. return originalContent
  5. }
  6. // validate workspaces content being appended
  7. const hasInvalidWorkspaces = () =>
  8. newWorkspaces.some(w => !(typeof w === 'string'))
  9. if (!newWorkspaces.length || hasInvalidWorkspaces()) {
  10. throw Object.assign(
  11. new TypeError('workspaces should be an array of strings.'),
  12. { code: 'EWORKSPACESINVALID' }
  13. )
  14. }
  15. return {
  16. ...originalContent,
  17. workspaces: [
  18. ...newWorkspaces,
  19. ],
  20. }
  21. }
  22. module.exports = updateWorkspaces