• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const updateScripts = ({ content, originalContent = {} }) => {
2  const newScripts = content.scripts
3
4  if (!newScripts) {
5    return originalContent
6  }
7
8  // validate scripts content being appended
9  const hasInvalidScripts = () =>
10    Object.entries(newScripts)
11      .some(([key, value]) =>
12        typeof key !== 'string' || typeof value !== 'string')
13  if (hasInvalidScripts()) {
14    throw Object.assign(
15      new TypeError(
16        'package.json scripts should be a key-value pair of strings.'),
17      { code: 'ESCRIPTSINVALID' }
18    )
19  }
20
21  return {
22    ...originalContent,
23    scripts: {
24      ...newScripts,
25    },
26  }
27}
28
29module.exports = updateScripts
30