UNPKG

642 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/**
4 * Adds a package to the package.json
5 */
6function addPackageToPackageJson(host, type, pkg, version) {
7 if (host.exists('package.json')) {
8 const sourceText = host.read('package.json').toString('utf-8');
9 const json = JSON.parse(sourceText);
10 if (!json[type]) {
11 json[type] = {};
12 }
13 if (!json[type][pkg]) {
14 json[type][pkg] = version;
15 }
16 host.overwrite('package.json', JSON.stringify(json, null, 2));
17 }
18 return host;
19}
20exports.addPackageToPackageJson = addPackageToPackageJson;