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