@nx/workspace
Version:
25 lines (24 loc) • 819 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updatePackageJson = updatePackageJson;
const tslib_1 = require("tslib");
const devkit_1 = require("@nx/devkit");
const path = tslib_1.__importStar(require("path"));
/**
* Updates the name in the package.json if it exists.
*
* @param schema The options provided to the schematic
*/
function updatePackageJson(tree, schema) {
if (!schema.importPath) {
return;
}
const packageJsonPath = path.join(schema.relativeToRootDestination, 'package.json');
if (!tree.exists(packageJsonPath)) {
// nothing to do
return;
}
const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
packageJson.name = schema.importPath;
tree.write(packageJsonPath, JSON.stringify(packageJson));
}