| 56 | } |
| 57 | |
| 58 | async get (args, { path, workspace }) { |
| 59 | this.npm.config.set('json', true) |
| 60 | const pkgJson = await PackageJson.load(path) |
| 61 | |
| 62 | let result = pkgJson.content |
| 63 | |
| 64 | if (args.length) { |
| 65 | result = new Queryable(result).query(args) |
| 66 | // in case there's only a single argument and a single result from the query just prints that one element to stdout. |
| 67 | // TODO(BREAKING_CHANGE): much like other places where we unwrap single item arrays this should go away. |
| 68 | // it makes the behavior unknown for users who don't already know the shape of the data. |
| 69 | if (Object.keys(result).length === 1 && args.length === 1) { |
| 70 | result = result[args] |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // The display layer is responsible for calling JSON.stringify on the result |
| 75 | // TODO: https://github.com/npm/cli/issues/5508 a raw mode has been requested similar to jq -r. |
| 76 | // If that was added then this method should no longer set `json:true` all the time |
| 77 | output.buffer(workspace ? { [workspace]: result } : result) |
| 78 | } |
| 79 | |
| 80 | async set (args, { path }) { |
| 81 | const setError = () => |