createPackageJson(dirPath, newJson)
Creates a package.json file in the specified directory. If the file already exists, it will not overwrite it.
Parameters:
dirPath(string) – Path to the directory wherepackage.jsonshould be created.newJson(object, optional) – Overrides or additional fields for thepackage.json.
Returns:
- JSON string of the final package content.
Example:
1createPackageJson("./my-lib", {2 name: "my-lib",3 version: "1.0.0",4 author: "HBH"5});
Edge Cases:
- If a
package.jsonalready exists, it is not overwritten. - Default fields are merged with any custom fields provided.