11cb0ef41Sopenharmony_ciconst { resolve } = require('path')
21cb0ef41Sopenharmony_ciconst { readFileSync } = require('fs')
31cb0ef41Sopenharmony_ciconst t = require('tap')
41cb0ef41Sopenharmony_ciconst _mockNpm = require('../../fixtures/mock-npm')
51cb0ef41Sopenharmony_ciconst { cleanCwd } = require('../../fixtures/clean-snapshot')
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cit.cleanSnapshot = (str) => cleanCwd(str)
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst mockNpm = async (t, { ...opts } = {}) => {
101cb0ef41Sopenharmony_ci  const res = await _mockNpm(t, opts)
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci  const readPackageJson = (dir = '') =>
131cb0ef41Sopenharmony_ci    JSON.parse(readFileSync(resolve(res.prefix, dir, 'package.json'), 'utf8'))
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  return {
161cb0ef41Sopenharmony_ci    ...res,
171cb0ef41Sopenharmony_ci    pkg: (...args) => res.npm.exec('pkg', args),
181cb0ef41Sopenharmony_ci    readPackageJson,
191cb0ef41Sopenharmony_ci    OUTPUT: () => res.joinedOutput(),
201cb0ef41Sopenharmony_ci  }
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cit.test('no args', async t => {
241cb0ef41Sopenharmony_ci  const { pkg } = await mockNpm(t)
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  await t.rejects(
271cb0ef41Sopenharmony_ci    pkg(),
281cb0ef41Sopenharmony_ci    { code: 'EUSAGE' },
291cb0ef41Sopenharmony_ci    'should throw usage error'
301cb0ef41Sopenharmony_ci  )
311cb0ef41Sopenharmony_ci})
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cit.test('no global mode', async t => {
341cb0ef41Sopenharmony_ci  const { pkg } = await mockNpm(t, {
351cb0ef41Sopenharmony_ci    config: { global: true },
361cb0ef41Sopenharmony_ci  })
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  await t.rejects(
391cb0ef41Sopenharmony_ci    pkg('get', 'foo'),
401cb0ef41Sopenharmony_ci    { code: 'EPKGGLOBAL' },
411cb0ef41Sopenharmony_ci    'should throw no global mode error'
421cb0ef41Sopenharmony_ci  )
431cb0ef41Sopenharmony_ci})
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_cit.test('get no args', async t => {
461cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
471cb0ef41Sopenharmony_ci    prefixDir: {
481cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
491cb0ef41Sopenharmony_ci        name: 'foo',
501cb0ef41Sopenharmony_ci        version: '1.1.1',
511cb0ef41Sopenharmony_ci      }),
521cb0ef41Sopenharmony_ci    },
531cb0ef41Sopenharmony_ci  })
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  await pkg('get')
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci  t.strictSame(
581cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
591cb0ef41Sopenharmony_ci    {
601cb0ef41Sopenharmony_ci      name: 'foo',
611cb0ef41Sopenharmony_ci      version: '1.1.1',
621cb0ef41Sopenharmony_ci    },
631cb0ef41Sopenharmony_ci    'should print package.json content'
641cb0ef41Sopenharmony_ci  )
651cb0ef41Sopenharmony_ci})
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_cit.test('get single arg', async t => {
681cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
691cb0ef41Sopenharmony_ci    prefixDir: {
701cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
711cb0ef41Sopenharmony_ci        name: 'foo',
721cb0ef41Sopenharmony_ci        version: '1.1.1',
731cb0ef41Sopenharmony_ci      }),
741cb0ef41Sopenharmony_ci    },
751cb0ef41Sopenharmony_ci  })
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  await pkg('get', 'version')
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci  t.strictSame(
801cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
811cb0ef41Sopenharmony_ci    '1.1.1',
821cb0ef41Sopenharmony_ci    'should print retrieved package.json field'
831cb0ef41Sopenharmony_ci  )
841cb0ef41Sopenharmony_ci})
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_cit.test('get multiple arg', async t => {
871cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
881cb0ef41Sopenharmony_ci    prefixDir: {
891cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
901cb0ef41Sopenharmony_ci        name: 'foo',
911cb0ef41Sopenharmony_ci        version: '1.1.1',
921cb0ef41Sopenharmony_ci      }),
931cb0ef41Sopenharmony_ci    },
941cb0ef41Sopenharmony_ci  })
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci  await pkg('get', 'name', 'version')
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci  t.strictSame(
991cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
1001cb0ef41Sopenharmony_ci    {
1011cb0ef41Sopenharmony_ci      name: 'foo',
1021cb0ef41Sopenharmony_ci      version: '1.1.1',
1031cb0ef41Sopenharmony_ci    },
1041cb0ef41Sopenharmony_ci    'should print retrieved package.json field'
1051cb0ef41Sopenharmony_ci  )
1061cb0ef41Sopenharmony_ci})
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_cit.test('get multiple arg with empty value', async t => {
1091cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
1101cb0ef41Sopenharmony_ci    prefixDir: {
1111cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
1121cb0ef41Sopenharmony_ci        name: 'foo',
1131cb0ef41Sopenharmony_ci        author: '',
1141cb0ef41Sopenharmony_ci      }),
1151cb0ef41Sopenharmony_ci    },
1161cb0ef41Sopenharmony_ci  })
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci  await pkg('get', 'name', 'author')
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_ci  t.strictSame(
1211cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
1221cb0ef41Sopenharmony_ci    {
1231cb0ef41Sopenharmony_ci      name: 'foo',
1241cb0ef41Sopenharmony_ci      author: '',
1251cb0ef41Sopenharmony_ci    },
1261cb0ef41Sopenharmony_ci    'should print retrieved package.json field regardless of empty value'
1271cb0ef41Sopenharmony_ci  )
1281cb0ef41Sopenharmony_ci})
1291cb0ef41Sopenharmony_ci
1301cb0ef41Sopenharmony_cit.test('get nested arg', async t => {
1311cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
1321cb0ef41Sopenharmony_ci    prefixDir: {
1331cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
1341cb0ef41Sopenharmony_ci        name: 'foo',
1351cb0ef41Sopenharmony_ci        version: '1.1.1',
1361cb0ef41Sopenharmony_ci        scripts: {
1371cb0ef41Sopenharmony_ci          test: 'node test.js',
1381cb0ef41Sopenharmony_ci        },
1391cb0ef41Sopenharmony_ci      }),
1401cb0ef41Sopenharmony_ci    },
1411cb0ef41Sopenharmony_ci  })
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ci  await pkg('get', 'scripts.test')
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci  t.strictSame(
1461cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
1471cb0ef41Sopenharmony_ci    'node test.js',
1481cb0ef41Sopenharmony_ci    'should print retrieved nested field'
1491cb0ef41Sopenharmony_ci  )
1501cb0ef41Sopenharmony_ci})
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_cit.test('get array field', async t => {
1531cb0ef41Sopenharmony_ci  const files = [
1541cb0ef41Sopenharmony_ci    'index.js',
1551cb0ef41Sopenharmony_ci    'cli.js',
1561cb0ef41Sopenharmony_ci  ]
1571cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
1581cb0ef41Sopenharmony_ci    prefixDir: {
1591cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
1601cb0ef41Sopenharmony_ci        name: 'foo',
1611cb0ef41Sopenharmony_ci        version: '1.1.1',
1621cb0ef41Sopenharmony_ci        files,
1631cb0ef41Sopenharmony_ci      }),
1641cb0ef41Sopenharmony_ci    },
1651cb0ef41Sopenharmony_ci  })
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci  await pkg('get', 'files')
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci  t.strictSame(
1701cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
1711cb0ef41Sopenharmony_ci    files,
1721cb0ef41Sopenharmony_ci    'should print retrieved array field'
1731cb0ef41Sopenharmony_ci  )
1741cb0ef41Sopenharmony_ci})
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_cit.test('get array item', async t => {
1771cb0ef41Sopenharmony_ci  const files = [
1781cb0ef41Sopenharmony_ci    'index.js',
1791cb0ef41Sopenharmony_ci    'cli.js',
1801cb0ef41Sopenharmony_ci  ]
1811cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
1821cb0ef41Sopenharmony_ci    prefixDir: {
1831cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
1841cb0ef41Sopenharmony_ci        name: 'foo',
1851cb0ef41Sopenharmony_ci        version: '1.1.1',
1861cb0ef41Sopenharmony_ci        files,
1871cb0ef41Sopenharmony_ci      }),
1881cb0ef41Sopenharmony_ci    },
1891cb0ef41Sopenharmony_ci  })
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ci  await pkg('get', 'files[0]')
1921cb0ef41Sopenharmony_ci
1931cb0ef41Sopenharmony_ci  t.strictSame(
1941cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
1951cb0ef41Sopenharmony_ci    'index.js',
1961cb0ef41Sopenharmony_ci    'should print retrieved array field'
1971cb0ef41Sopenharmony_ci  )
1981cb0ef41Sopenharmony_ci})
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_cit.test('get array nested items notation', async t => {
2011cb0ef41Sopenharmony_ci  const contributors = [
2021cb0ef41Sopenharmony_ci    {
2031cb0ef41Sopenharmony_ci      name: 'Ruy',
2041cb0ef41Sopenharmony_ci      url: 'http://example.com/ruy',
2051cb0ef41Sopenharmony_ci    },
2061cb0ef41Sopenharmony_ci    {
2071cb0ef41Sopenharmony_ci      name: 'Gar',
2081cb0ef41Sopenharmony_ci      url: 'http://example.com/gar',
2091cb0ef41Sopenharmony_ci    },
2101cb0ef41Sopenharmony_ci  ]
2111cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
2121cb0ef41Sopenharmony_ci    prefixDir: {
2131cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
2141cb0ef41Sopenharmony_ci        name: 'foo',
2151cb0ef41Sopenharmony_ci        version: '1.1.1',
2161cb0ef41Sopenharmony_ci        contributors,
2171cb0ef41Sopenharmony_ci      }),
2181cb0ef41Sopenharmony_ci    },
2191cb0ef41Sopenharmony_ci  })
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_ci  await pkg('get', 'contributors.name')
2221cb0ef41Sopenharmony_ci  t.strictSame(
2231cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
2241cb0ef41Sopenharmony_ci    {
2251cb0ef41Sopenharmony_ci      'contributors[0].name': 'Ruy',
2261cb0ef41Sopenharmony_ci      'contributors[1].name': 'Gar',
2271cb0ef41Sopenharmony_ci    },
2281cb0ef41Sopenharmony_ci    'should print json result containing matching results'
2291cb0ef41Sopenharmony_ci  )
2301cb0ef41Sopenharmony_ci})
2311cb0ef41Sopenharmony_ci
2321cb0ef41Sopenharmony_cit.test('set no args', async t => {
2331cb0ef41Sopenharmony_ci  const { pkg } = await mockNpm(t, {
2341cb0ef41Sopenharmony_ci    prefixDir: {
2351cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({ name: 'foo' }),
2361cb0ef41Sopenharmony_ci    },
2371cb0ef41Sopenharmony_ci  })
2381cb0ef41Sopenharmony_ci  await t.rejects(
2391cb0ef41Sopenharmony_ci    pkg('set'),
2401cb0ef41Sopenharmony_ci    { code: 'EUSAGE' },
2411cb0ef41Sopenharmony_ci    'should throw an error if no args'
2421cb0ef41Sopenharmony_ci  )
2431cb0ef41Sopenharmony_ci})
2441cb0ef41Sopenharmony_ci
2451cb0ef41Sopenharmony_cit.test('set missing value', async t => {
2461cb0ef41Sopenharmony_ci  const { pkg } = await mockNpm(t, {
2471cb0ef41Sopenharmony_ci    prefixDir: {
2481cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({ name: 'foo' }),
2491cb0ef41Sopenharmony_ci    },
2501cb0ef41Sopenharmony_ci  })
2511cb0ef41Sopenharmony_ci  await t.rejects(
2521cb0ef41Sopenharmony_ci    pkg('set', 'key='),
2531cb0ef41Sopenharmony_ci    { code: 'EUSAGE' },
2541cb0ef41Sopenharmony_ci    'should throw an error if missing value'
2551cb0ef41Sopenharmony_ci  )
2561cb0ef41Sopenharmony_ci})
2571cb0ef41Sopenharmony_ci
2581cb0ef41Sopenharmony_cit.test('set missing key', async t => {
2591cb0ef41Sopenharmony_ci  const { pkg } = await mockNpm(t, {
2601cb0ef41Sopenharmony_ci    prefixDir: {
2611cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({ name: 'foo' }),
2621cb0ef41Sopenharmony_ci    },
2631cb0ef41Sopenharmony_ci  })
2641cb0ef41Sopenharmony_ci  await t.rejects(
2651cb0ef41Sopenharmony_ci    pkg('set', '=value'),
2661cb0ef41Sopenharmony_ci    { code: 'EUSAGE' },
2671cb0ef41Sopenharmony_ci    'should throw an error if missing key'
2681cb0ef41Sopenharmony_ci  )
2691cb0ef41Sopenharmony_ci})
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_cit.test('set single field', async t => {
2721cb0ef41Sopenharmony_ci  const json = {
2731cb0ef41Sopenharmony_ci    name: 'foo',
2741cb0ef41Sopenharmony_ci    version: '1.1.1',
2751cb0ef41Sopenharmony_ci  }
2761cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
2771cb0ef41Sopenharmony_ci    prefixDir: {
2781cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(json),
2791cb0ef41Sopenharmony_ci    },
2801cb0ef41Sopenharmony_ci  })
2811cb0ef41Sopenharmony_ci
2821cb0ef41Sopenharmony_ci  await pkg('set', 'description=Awesome stuff')
2831cb0ef41Sopenharmony_ci  t.strictSame(
2841cb0ef41Sopenharmony_ci    readPackageJson(),
2851cb0ef41Sopenharmony_ci    {
2861cb0ef41Sopenharmony_ci      ...json,
2871cb0ef41Sopenharmony_ci      description: 'Awesome stuff',
2881cb0ef41Sopenharmony_ci    },
2891cb0ef41Sopenharmony_ci    'should add single field to package.json'
2901cb0ef41Sopenharmony_ci  )
2911cb0ef41Sopenharmony_ci})
2921cb0ef41Sopenharmony_ci
2931cb0ef41Sopenharmony_cit.test('push to array syntax', async t => {
2941cb0ef41Sopenharmony_ci  const json = {
2951cb0ef41Sopenharmony_ci    name: 'foo',
2961cb0ef41Sopenharmony_ci    version: '1.1.1',
2971cb0ef41Sopenharmony_ci    keywords: [
2981cb0ef41Sopenharmony_ci      'foo',
2991cb0ef41Sopenharmony_ci    ],
3001cb0ef41Sopenharmony_ci  }
3011cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
3021cb0ef41Sopenharmony_ci    prefixDir: {
3031cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(json),
3041cb0ef41Sopenharmony_ci    },
3051cb0ef41Sopenharmony_ci  })
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci  await pkg('set', 'keywords[]=bar', 'keywords[]=baz')
3081cb0ef41Sopenharmony_ci  t.strictSame(
3091cb0ef41Sopenharmony_ci    readPackageJson(),
3101cb0ef41Sopenharmony_ci    {
3111cb0ef41Sopenharmony_ci      ...json,
3121cb0ef41Sopenharmony_ci      keywords: [
3131cb0ef41Sopenharmony_ci        'foo',
3141cb0ef41Sopenharmony_ci        'bar',
3151cb0ef41Sopenharmony_ci        'baz',
3161cb0ef41Sopenharmony_ci      ],
3171cb0ef41Sopenharmony_ci    },
3181cb0ef41Sopenharmony_ci    'should append to arrays using empty bracket syntax'
3191cb0ef41Sopenharmony_ci  )
3201cb0ef41Sopenharmony_ci})
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_cit.test('set multiple fields', async t => {
3231cb0ef41Sopenharmony_ci  const json = {
3241cb0ef41Sopenharmony_ci    name: 'foo',
3251cb0ef41Sopenharmony_ci    version: '1.1.1',
3261cb0ef41Sopenharmony_ci  }
3271cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
3281cb0ef41Sopenharmony_ci    prefixDir: {
3291cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(json),
3301cb0ef41Sopenharmony_ci    },
3311cb0ef41Sopenharmony_ci  })
3321cb0ef41Sopenharmony_ci
3331cb0ef41Sopenharmony_ci  await pkg('set', 'bin.foo=foo.js', 'scripts.test=node test.js')
3341cb0ef41Sopenharmony_ci  t.strictSame(
3351cb0ef41Sopenharmony_ci    readPackageJson(),
3361cb0ef41Sopenharmony_ci    {
3371cb0ef41Sopenharmony_ci      ...json,
3381cb0ef41Sopenharmony_ci      bin: {
3391cb0ef41Sopenharmony_ci        foo: 'foo.js',
3401cb0ef41Sopenharmony_ci      },
3411cb0ef41Sopenharmony_ci      scripts: {
3421cb0ef41Sopenharmony_ci        test: 'node test.js',
3431cb0ef41Sopenharmony_ci      },
3441cb0ef41Sopenharmony_ci    },
3451cb0ef41Sopenharmony_ci    'should add single field to package.json'
3461cb0ef41Sopenharmony_ci  )
3471cb0ef41Sopenharmony_ci})
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_cit.test('set = separate value', async t => {
3501cb0ef41Sopenharmony_ci  const json = {
3511cb0ef41Sopenharmony_ci    name: 'foo',
3521cb0ef41Sopenharmony_ci    version: '1.1.1',
3531cb0ef41Sopenharmony_ci  }
3541cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
3551cb0ef41Sopenharmony_ci    prefixDir: {
3561cb0ef41Sopenharmony_ci      'package.json': JSON.stringify(json),
3571cb0ef41Sopenharmony_ci    },
3581cb0ef41Sopenharmony_ci  })
3591cb0ef41Sopenharmony_ci
3601cb0ef41Sopenharmony_ci  await pkg('set', 'tap[test-env][0]=LC_ALL=sk')
3611cb0ef41Sopenharmony_ci  t.strictSame(
3621cb0ef41Sopenharmony_ci    readPackageJson(),
3631cb0ef41Sopenharmony_ci    {
3641cb0ef41Sopenharmony_ci      ...json,
3651cb0ef41Sopenharmony_ci      tap: {
3661cb0ef41Sopenharmony_ci        'test-env': [
3671cb0ef41Sopenharmony_ci          'LC_ALL=sk',
3681cb0ef41Sopenharmony_ci        ],
3691cb0ef41Sopenharmony_ci      },
3701cb0ef41Sopenharmony_ci    },
3711cb0ef41Sopenharmony_ci    'should add single field to package.json'
3721cb0ef41Sopenharmony_ci  )
3731cb0ef41Sopenharmony_ci})
3741cb0ef41Sopenharmony_ci
3751cb0ef41Sopenharmony_cit.test('set --json', async t => {
3761cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
3771cb0ef41Sopenharmony_ci    prefixDir: {
3781cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
3791cb0ef41Sopenharmony_ci        name: 'foo',
3801cb0ef41Sopenharmony_ci        version: '1.1.1',
3811cb0ef41Sopenharmony_ci      }),
3821cb0ef41Sopenharmony_ci    },
3831cb0ef41Sopenharmony_ci    config: { json: true },
3841cb0ef41Sopenharmony_ci  })
3851cb0ef41Sopenharmony_ci
3861cb0ef41Sopenharmony_ci  await pkg('set', 'private=true')
3871cb0ef41Sopenharmony_ci  t.strictSame(
3881cb0ef41Sopenharmony_ci    readPackageJson(),
3891cb0ef41Sopenharmony_ci    {
3901cb0ef41Sopenharmony_ci      name: 'foo',
3911cb0ef41Sopenharmony_ci      version: '1.1.1',
3921cb0ef41Sopenharmony_ci      private: true,
3931cb0ef41Sopenharmony_ci    },
3941cb0ef41Sopenharmony_ci    'should add boolean field to package.json'
3951cb0ef41Sopenharmony_ci  )
3961cb0ef41Sopenharmony_ci
3971cb0ef41Sopenharmony_ci  await pkg('set', 'tap.timeout=60')
3981cb0ef41Sopenharmony_ci  t.strictSame(
3991cb0ef41Sopenharmony_ci    readPackageJson(),
4001cb0ef41Sopenharmony_ci    {
4011cb0ef41Sopenharmony_ci      name: 'foo',
4021cb0ef41Sopenharmony_ci      version: '1.1.1',
4031cb0ef41Sopenharmony_ci      private: true,
4041cb0ef41Sopenharmony_ci      tap: {
4051cb0ef41Sopenharmony_ci        timeout: 60,
4061cb0ef41Sopenharmony_ci      },
4071cb0ef41Sopenharmony_ci    },
4081cb0ef41Sopenharmony_ci    'should add number field to package.json'
4091cb0ef41Sopenharmony_ci  )
4101cb0ef41Sopenharmony_ci
4111cb0ef41Sopenharmony_ci  await pkg('set', 'foo={ "bar": { "baz": "BAZ" } }')
4121cb0ef41Sopenharmony_ci  t.strictSame(
4131cb0ef41Sopenharmony_ci    readPackageJson(),
4141cb0ef41Sopenharmony_ci    {
4151cb0ef41Sopenharmony_ci      name: 'foo',
4161cb0ef41Sopenharmony_ci      version: '1.1.1',
4171cb0ef41Sopenharmony_ci      private: true,
4181cb0ef41Sopenharmony_ci      tap: {
4191cb0ef41Sopenharmony_ci        timeout: 60,
4201cb0ef41Sopenharmony_ci      },
4211cb0ef41Sopenharmony_ci      foo: {
4221cb0ef41Sopenharmony_ci        bar: {
4231cb0ef41Sopenharmony_ci          baz: 'BAZ',
4241cb0ef41Sopenharmony_ci        },
4251cb0ef41Sopenharmony_ci      },
4261cb0ef41Sopenharmony_ci    },
4271cb0ef41Sopenharmony_ci    'should add object field to package.json'
4281cb0ef41Sopenharmony_ci  )
4291cb0ef41Sopenharmony_ci
4301cb0ef41Sopenharmony_ci  await pkg('set', 'workspaces=["packages/*"]')
4311cb0ef41Sopenharmony_ci  t.strictSame(
4321cb0ef41Sopenharmony_ci    readPackageJson(),
4331cb0ef41Sopenharmony_ci    {
4341cb0ef41Sopenharmony_ci      name: 'foo',
4351cb0ef41Sopenharmony_ci      version: '1.1.1',
4361cb0ef41Sopenharmony_ci      private: true,
4371cb0ef41Sopenharmony_ci      workspaces: [
4381cb0ef41Sopenharmony_ci        'packages/*',
4391cb0ef41Sopenharmony_ci      ],
4401cb0ef41Sopenharmony_ci      tap: {
4411cb0ef41Sopenharmony_ci        timeout: 60,
4421cb0ef41Sopenharmony_ci      },
4431cb0ef41Sopenharmony_ci      foo: {
4441cb0ef41Sopenharmony_ci        bar: {
4451cb0ef41Sopenharmony_ci          baz: 'BAZ',
4461cb0ef41Sopenharmony_ci        },
4471cb0ef41Sopenharmony_ci      },
4481cb0ef41Sopenharmony_ci    },
4491cb0ef41Sopenharmony_ci    'should add object field to package.json'
4501cb0ef41Sopenharmony_ci  )
4511cb0ef41Sopenharmony_ci
4521cb0ef41Sopenharmony_ci  await pkg('set', 'description="awesome"')
4531cb0ef41Sopenharmony_ci  t.strictSame(
4541cb0ef41Sopenharmony_ci    readPackageJson(),
4551cb0ef41Sopenharmony_ci    {
4561cb0ef41Sopenharmony_ci      name: 'foo',
4571cb0ef41Sopenharmony_ci      version: '1.1.1',
4581cb0ef41Sopenharmony_ci      description: 'awesome',
4591cb0ef41Sopenharmony_ci      private: true,
4601cb0ef41Sopenharmony_ci      workspaces: [
4611cb0ef41Sopenharmony_ci        'packages/*',
4621cb0ef41Sopenharmony_ci      ],
4631cb0ef41Sopenharmony_ci      tap: {
4641cb0ef41Sopenharmony_ci        timeout: 60,
4651cb0ef41Sopenharmony_ci      },
4661cb0ef41Sopenharmony_ci      foo: {
4671cb0ef41Sopenharmony_ci        bar: {
4681cb0ef41Sopenharmony_ci          baz: 'BAZ',
4691cb0ef41Sopenharmony_ci        },
4701cb0ef41Sopenharmony_ci      },
4711cb0ef41Sopenharmony_ci    },
4721cb0ef41Sopenharmony_ci    'should add object field to package.json'
4731cb0ef41Sopenharmony_ci  )
4741cb0ef41Sopenharmony_ci})
4751cb0ef41Sopenharmony_ci
4761cb0ef41Sopenharmony_cit.test('delete no args', async t => {
4771cb0ef41Sopenharmony_ci  const { pkg } = await mockNpm(t, {
4781cb0ef41Sopenharmony_ci    prefixDir: {
4791cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({ name: 'foo' }),
4801cb0ef41Sopenharmony_ci    },
4811cb0ef41Sopenharmony_ci  })
4821cb0ef41Sopenharmony_ci  await t.rejects(
4831cb0ef41Sopenharmony_ci    pkg('delete'),
4841cb0ef41Sopenharmony_ci    { code: 'EUSAGE' },
4851cb0ef41Sopenharmony_ci    'should throw an error if deleting no args'
4861cb0ef41Sopenharmony_ci  )
4871cb0ef41Sopenharmony_ci})
4881cb0ef41Sopenharmony_ci
4891cb0ef41Sopenharmony_cit.test('delete invalid key', async t => {
4901cb0ef41Sopenharmony_ci  const { pkg } = await mockNpm(t, {
4911cb0ef41Sopenharmony_ci    prefixDir: {
4921cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({ name: 'foo' }),
4931cb0ef41Sopenharmony_ci    },
4941cb0ef41Sopenharmony_ci  })
4951cb0ef41Sopenharmony_ci  await t.rejects(
4961cb0ef41Sopenharmony_ci    pkg('delete', ''),
4971cb0ef41Sopenharmony_ci    { code: 'EUSAGE' },
4981cb0ef41Sopenharmony_ci    'should throw an error if deleting invalid args'
4991cb0ef41Sopenharmony_ci  )
5001cb0ef41Sopenharmony_ci})
5011cb0ef41Sopenharmony_ci
5021cb0ef41Sopenharmony_cit.test('delete single field', async t => {
5031cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
5041cb0ef41Sopenharmony_ci    prefixDir: {
5051cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
5061cb0ef41Sopenharmony_ci        name: 'foo',
5071cb0ef41Sopenharmony_ci        version: '1.0.0',
5081cb0ef41Sopenharmony_ci      }),
5091cb0ef41Sopenharmony_ci    },
5101cb0ef41Sopenharmony_ci  })
5111cb0ef41Sopenharmony_ci  await pkg('delete', 'version')
5121cb0ef41Sopenharmony_ci  t.strictSame(
5131cb0ef41Sopenharmony_ci    readPackageJson(),
5141cb0ef41Sopenharmony_ci    {
5151cb0ef41Sopenharmony_ci      name: 'foo',
5161cb0ef41Sopenharmony_ci    },
5171cb0ef41Sopenharmony_ci    'should delete single field from package.json'
5181cb0ef41Sopenharmony_ci  )
5191cb0ef41Sopenharmony_ci})
5201cb0ef41Sopenharmony_ci
5211cb0ef41Sopenharmony_cit.test('delete multiple field', async t => {
5221cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
5231cb0ef41Sopenharmony_ci    prefixDir: {
5241cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
5251cb0ef41Sopenharmony_ci        name: 'foo',
5261cb0ef41Sopenharmony_ci        version: '1.0.0',
5271cb0ef41Sopenharmony_ci        description: 'awesome',
5281cb0ef41Sopenharmony_ci      }),
5291cb0ef41Sopenharmony_ci    },
5301cb0ef41Sopenharmony_ci  })
5311cb0ef41Sopenharmony_ci  await pkg('delete', 'version', 'description')
5321cb0ef41Sopenharmony_ci  t.strictSame(
5331cb0ef41Sopenharmony_ci    readPackageJson(),
5341cb0ef41Sopenharmony_ci    {
5351cb0ef41Sopenharmony_ci      name: 'foo',
5361cb0ef41Sopenharmony_ci    },
5371cb0ef41Sopenharmony_ci    'should delete multiple fields from package.json'
5381cb0ef41Sopenharmony_ci  )
5391cb0ef41Sopenharmony_ci})
5401cb0ef41Sopenharmony_ci
5411cb0ef41Sopenharmony_cit.test('delete nested field', async t => {
5421cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
5431cb0ef41Sopenharmony_ci    prefixDir: {
5441cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
5451cb0ef41Sopenharmony_ci        name: 'foo',
5461cb0ef41Sopenharmony_ci        version: '1.0.0',
5471cb0ef41Sopenharmony_ci        info: {
5481cb0ef41Sopenharmony_ci          foo: {
5491cb0ef41Sopenharmony_ci            bar: [
5501cb0ef41Sopenharmony_ci              {
5511cb0ef41Sopenharmony_ci                baz: 'deleteme',
5521cb0ef41Sopenharmony_ci              },
5531cb0ef41Sopenharmony_ci            ],
5541cb0ef41Sopenharmony_ci          },
5551cb0ef41Sopenharmony_ci        },
5561cb0ef41Sopenharmony_ci      }),
5571cb0ef41Sopenharmony_ci    },
5581cb0ef41Sopenharmony_ci  })
5591cb0ef41Sopenharmony_ci  await pkg('delete', 'info.foo.bar[0].baz')
5601cb0ef41Sopenharmony_ci  t.strictSame(
5611cb0ef41Sopenharmony_ci    readPackageJson(),
5621cb0ef41Sopenharmony_ci    {
5631cb0ef41Sopenharmony_ci      name: 'foo',
5641cb0ef41Sopenharmony_ci      version: '1.0.0',
5651cb0ef41Sopenharmony_ci      info: {
5661cb0ef41Sopenharmony_ci        foo: {
5671cb0ef41Sopenharmony_ci          bar: [
5681cb0ef41Sopenharmony_ci            {},
5691cb0ef41Sopenharmony_ci          ],
5701cb0ef41Sopenharmony_ci        },
5711cb0ef41Sopenharmony_ci      },
5721cb0ef41Sopenharmony_ci    },
5731cb0ef41Sopenharmony_ci    'should delete nested fields from package.json'
5741cb0ef41Sopenharmony_ci  )
5751cb0ef41Sopenharmony_ci})
5761cb0ef41Sopenharmony_ci
5771cb0ef41Sopenharmony_cit.test('workspaces', async t => {
5781cb0ef41Sopenharmony_ci  const { pkg, OUTPUT, readPackageJson } = await mockNpm(t, {
5791cb0ef41Sopenharmony_ci    prefixDir: {
5801cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
5811cb0ef41Sopenharmony_ci        name: 'root',
5821cb0ef41Sopenharmony_ci        version: '1.0.0',
5831cb0ef41Sopenharmony_ci        workspaces: [
5841cb0ef41Sopenharmony_ci          'packages/*',
5851cb0ef41Sopenharmony_ci        ],
5861cb0ef41Sopenharmony_ci      }),
5871cb0ef41Sopenharmony_ci      packages: {
5881cb0ef41Sopenharmony_ci        a: {
5891cb0ef41Sopenharmony_ci          'package.json': JSON.stringify({
5901cb0ef41Sopenharmony_ci            name: 'a',
5911cb0ef41Sopenharmony_ci            version: '1.0.0',
5921cb0ef41Sopenharmony_ci          }),
5931cb0ef41Sopenharmony_ci        },
5941cb0ef41Sopenharmony_ci        b: {
5951cb0ef41Sopenharmony_ci          'package.json': JSON.stringify({
5961cb0ef41Sopenharmony_ci            name: 'b',
5971cb0ef41Sopenharmony_ci            version: '1.2.3',
5981cb0ef41Sopenharmony_ci          }),
5991cb0ef41Sopenharmony_ci        },
6001cb0ef41Sopenharmony_ci      },
6011cb0ef41Sopenharmony_ci    },
6021cb0ef41Sopenharmony_ci    config: { workspaces: true },
6031cb0ef41Sopenharmony_ci  })
6041cb0ef41Sopenharmony_ci
6051cb0ef41Sopenharmony_ci  await pkg('get', 'name', 'version')
6061cb0ef41Sopenharmony_ci
6071cb0ef41Sopenharmony_ci  t.strictSame(
6081cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
6091cb0ef41Sopenharmony_ci    {
6101cb0ef41Sopenharmony_ci      a: {
6111cb0ef41Sopenharmony_ci        name: 'a',
6121cb0ef41Sopenharmony_ci        version: '1.0.0',
6131cb0ef41Sopenharmony_ci      },
6141cb0ef41Sopenharmony_ci      b: {
6151cb0ef41Sopenharmony_ci        name: 'b',
6161cb0ef41Sopenharmony_ci        version: '1.2.3',
6171cb0ef41Sopenharmony_ci      },
6181cb0ef41Sopenharmony_ci    },
6191cb0ef41Sopenharmony_ci    'should return expected result for configured workspaces'
6201cb0ef41Sopenharmony_ci  )
6211cb0ef41Sopenharmony_ci
6221cb0ef41Sopenharmony_ci  await pkg('set', 'funding=http://example.com')
6231cb0ef41Sopenharmony_ci
6241cb0ef41Sopenharmony_ci  t.strictSame(
6251cb0ef41Sopenharmony_ci    readPackageJson('packages/a'),
6261cb0ef41Sopenharmony_ci    {
6271cb0ef41Sopenharmony_ci      name: 'a',
6281cb0ef41Sopenharmony_ci      version: '1.0.0',
6291cb0ef41Sopenharmony_ci      funding: 'http://example.com',
6301cb0ef41Sopenharmony_ci    },
6311cb0ef41Sopenharmony_ci    'should add field to workspace a'
6321cb0ef41Sopenharmony_ci  )
6331cb0ef41Sopenharmony_ci
6341cb0ef41Sopenharmony_ci  t.strictSame(
6351cb0ef41Sopenharmony_ci    readPackageJson('packages/b'),
6361cb0ef41Sopenharmony_ci    {
6371cb0ef41Sopenharmony_ci      name: 'b',
6381cb0ef41Sopenharmony_ci      version: '1.2.3',
6391cb0ef41Sopenharmony_ci      funding: 'http://example.com',
6401cb0ef41Sopenharmony_ci    },
6411cb0ef41Sopenharmony_ci    'should add field to workspace b'
6421cb0ef41Sopenharmony_ci  )
6431cb0ef41Sopenharmony_ci
6441cb0ef41Sopenharmony_ci  await pkg('delete', 'version')
6451cb0ef41Sopenharmony_ci
6461cb0ef41Sopenharmony_ci  t.strictSame(
6471cb0ef41Sopenharmony_ci    readPackageJson('packages/a'),
6481cb0ef41Sopenharmony_ci    {
6491cb0ef41Sopenharmony_ci      name: 'a',
6501cb0ef41Sopenharmony_ci      funding: 'http://example.com',
6511cb0ef41Sopenharmony_ci    },
6521cb0ef41Sopenharmony_ci    'should delete version field from workspace a'
6531cb0ef41Sopenharmony_ci  )
6541cb0ef41Sopenharmony_ci
6551cb0ef41Sopenharmony_ci  t.strictSame(
6561cb0ef41Sopenharmony_ci    readPackageJson('packages/b'),
6571cb0ef41Sopenharmony_ci    {
6581cb0ef41Sopenharmony_ci      name: 'b',
6591cb0ef41Sopenharmony_ci      funding: 'http://example.com',
6601cb0ef41Sopenharmony_ci    },
6611cb0ef41Sopenharmony_ci    'should delete version field from workspace b'
6621cb0ef41Sopenharmony_ci  )
6631cb0ef41Sopenharmony_ci})
6641cb0ef41Sopenharmony_ci
6651cb0ef41Sopenharmony_cit.test('single workspace', async t => {
6661cb0ef41Sopenharmony_ci  const { pkg, OUTPUT } = await mockNpm(t, {
6671cb0ef41Sopenharmony_ci    prefixDir: {
6681cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
6691cb0ef41Sopenharmony_ci        name: 'root',
6701cb0ef41Sopenharmony_ci        version: '1.0.0',
6711cb0ef41Sopenharmony_ci        workspaces: [
6721cb0ef41Sopenharmony_ci          'packages/*',
6731cb0ef41Sopenharmony_ci        ],
6741cb0ef41Sopenharmony_ci      }),
6751cb0ef41Sopenharmony_ci      packages: {
6761cb0ef41Sopenharmony_ci        a: {
6771cb0ef41Sopenharmony_ci          'package.json': JSON.stringify({
6781cb0ef41Sopenharmony_ci            name: 'a',
6791cb0ef41Sopenharmony_ci            version: '1.0.0',
6801cb0ef41Sopenharmony_ci          }),
6811cb0ef41Sopenharmony_ci        },
6821cb0ef41Sopenharmony_ci        b: {
6831cb0ef41Sopenharmony_ci          'package.json': JSON.stringify({
6841cb0ef41Sopenharmony_ci            name: 'b',
6851cb0ef41Sopenharmony_ci            version: '1.2.3',
6861cb0ef41Sopenharmony_ci          }),
6871cb0ef41Sopenharmony_ci        },
6881cb0ef41Sopenharmony_ci      },
6891cb0ef41Sopenharmony_ci    },
6901cb0ef41Sopenharmony_ci    config: { workspace: ['packages/a'] },
6911cb0ef41Sopenharmony_ci  })
6921cb0ef41Sopenharmony_ci
6931cb0ef41Sopenharmony_ci  await pkg('get', 'name', 'version')
6941cb0ef41Sopenharmony_ci
6951cb0ef41Sopenharmony_ci  t.strictSame(
6961cb0ef41Sopenharmony_ci    JSON.parse(OUTPUT()),
6971cb0ef41Sopenharmony_ci    { a: { name: 'a', version: '1.0.0' } },
6981cb0ef41Sopenharmony_ci    'should only return info for one workspace'
6991cb0ef41Sopenharmony_ci  )
7001cb0ef41Sopenharmony_ci})
7011cb0ef41Sopenharmony_ci
7021cb0ef41Sopenharmony_cit.test('fix', async t => {
7031cb0ef41Sopenharmony_ci  const { pkg, readPackageJson } = await mockNpm(t, {
7041cb0ef41Sopenharmony_ci    prefixDir: {
7051cb0ef41Sopenharmony_ci      'package.json': JSON.stringify({
7061cb0ef41Sopenharmony_ci        name: 'foo ',
7071cb0ef41Sopenharmony_ci        version: 'v1.1.1',
7081cb0ef41Sopenharmony_ci      }),
7091cb0ef41Sopenharmony_ci    },
7101cb0ef41Sopenharmony_ci  })
7111cb0ef41Sopenharmony_ci
7121cb0ef41Sopenharmony_ci  await pkg('fix')
7131cb0ef41Sopenharmony_ci  t.strictSame(
7141cb0ef41Sopenharmony_ci    readPackageJson(),
7151cb0ef41Sopenharmony_ci    { name: 'foo', version: '1.1.1' },
7161cb0ef41Sopenharmony_ci    'fixes package.json issues'
7171cb0ef41Sopenharmony_ci  )
7181cb0ef41Sopenharmony_ci})
719