UNPKG

787 BJavaScriptView Raw
1"use strict";
2exports.__esModule = true;
3exports.addPackageToPackageJson = void 0;
4/**
5 * Adds a package to the package.json
6 */
7function addPackageToPackageJson(host, type, pkg, version) {
8 var _a, _b;
9 if (host.exists('package.json')) {
10 var sourceText = (_b = (_a = host.read('package.json')) === null || _a === void 0 ? void 0 : _a.toString('utf-8')) !== null && _b !== void 0 ? _b : '{}';
11 var json = JSON.parse(sourceText);
12 if (!json[type]) {
13 json[type] = {};
14 }
15 if (!json[type][pkg]) {
16 json[type][pkg] = version;
17 }
18 host.overwrite('package.json', JSON.stringify(json, null, 2));
19 }
20 return host;
21}
22exports.addPackageToPackageJson = addPackageToPackageJson;
23//# sourceMappingURL=package.js.map
\No newline at end of file