Skip to content

Commit dbe5b3b

Browse files
authored
Merge pull request #480 from blackflux/dev
[Gally]: master <- dev
2 parents 8cf4223 + e9f4d80 commit dbe5b3b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ To ignore file extension and force treat the file as a certain type, you can pas
5656

5757
To simply load yml files without resolving them pass `resolve` as `false`
5858

59-
### smartWrite(filepath. content, options = { treatAs = null, mergeStrategy = (existing, changeset) => changeset, create = true, pretty = false, keepOrder = true })
59+
### smartWrite(filepath. content, options = { treatAs = null, mergeStrategy = (existing, changeset) => changeset, create = true, pretty = false, keepOrder = true, resolve = false })
6060

6161
Serialize and write content to file based on file extension.
6262

@@ -84,6 +84,8 @@ When `pretty` is set to `true`, the output is formatted more compact.
8484
When `keepOrder` is set to `true` and a file is overwritten,
8585
the new content is ordered according to the existing content (e.g. for `json` and `yml`)
8686

87+
To `resolve` the original file before overwrite merging pass the option as `true`.
88+
8789
## Important
8890

8991
Do not use this library for loading if you don't trust the source of the files you are loading!

src/logic/smart-write.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ module.exports = (filepath, content, options = {}) => {
2222
create: true,
2323
pretty: false,
2424
keepOrder: true,
25+
resolve: false,
2526
...options
2627
};
27-
assert(Object.keys(ctx).length === 5, 'Unexpected Option provided!');
28+
assert(Object.keys(ctx).length === 6, 'Unexpected Option provided!');
2829
assert(ctx.treatAs === null || typeof ctx.treatAs === 'string');
2930
assert(typeof ctx.mergeStrategy === 'function');
3031
assert(typeof ctx.create === 'boolean');
3132
assert(typeof ctx.pretty === 'boolean');
33+
assert(typeof ctx.keepOrder === 'boolean');
34+
assert(typeof ctx.resolve === 'boolean');
3235

3336
const targetExists = fs.existsSync(filepath);
3437
if (ctx.create !== true && !targetExists) {
@@ -38,7 +41,8 @@ module.exports = (filepath, content, options = {}) => {
3841
const ext = getExt(filepath);
3942
const currentContent = targetExists
4043
? smartRead(filepath, {
41-
treatAs: ctx.treatAs === null && ext === 'js' ? 'txt' : ctx.treatAs
44+
treatAs: ctx.treatAs === null && ext === 'js' ? 'txt' : ctx.treatAs,
45+
resolve: ctx.resolve
4246
})
4347
: null;
4448

0 commit comments

Comments
 (0)