Package Exports
- modify-json-file
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (modify-json-file) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Modify JSON
Simplest way to modify JSON files
Why?
Becaues I got tired of writing read/write function for JSON files, especially when I need to change dozens of files.
Usage
- Only async use
Let's say we package.json file:
// 📁package.json
{
"name": "package",
"main": "index.js",
"author": "eldar",
"dependencies": {
"type-fest": "*",
"fdir": ">=2"
}
}
And this code:
import { modifyJsonFile } from "@zardoy/modify-json";
// of course, you should use path module here
await modifyJsonFile("package.json", {
name: s => `super ${s}`,
main: "build/electron.js",
dependencies: {
"type-fest": "^1.0.0"
}
})
After running this code, we'll get this package.json:
{
"name": "super package",
"main": "build/electron.js",
"author": "eldar",
"dependencies": {
"type-fest": "^1.0.0"
}
}
As you can see above, modifyJsonFile
only merges fields on 1 level depth. Currently, we don't support merging in nested fields.
We're using detect-indent to preserve the tab size in .json
files.
TODO
- Strip bom option
- Fix double tsc compilation (and test actual build/)
- transformer for paths (most likely babel plugin):
await fs.promises.readFile(./package.json, "utf8");
Into this:
await fs.promises.readFile(path.join(__dirname, "package.json"), "utf8");
- find a way to use FS in builder-way (like fdir does) and deprecate this module
Related
- jsonfile: simple reading / writing for json files
- immer ?