xcraft-core-utils 4.18.0 → 4.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  const watt = require('gigawatts');
4
4
  const crypto = require('crypto');
5
- const fs = require('fs');
5
+ const fse = require('fs-extra');
6
6
 
7
7
  /**
8
8
  * Compute the checksum of the file given as parameter using a specified algorithm.
@@ -23,7 +23,7 @@ exports.fileChecksum = watt(function* (filePath, options, next) {
23
23
  options.encoding = 'hex';
24
24
  }
25
25
 
26
- const stat = yield fs.stat(filePath, next);
26
+ const stat = yield fse.stat(filePath);
27
27
  if (!stat.isFile()) {
28
28
  throw new Error(`${filePath} is not a file`);
29
29
  }
@@ -31,7 +31,7 @@ exports.fileChecksum = watt(function* (filePath, options, next) {
31
31
  const hash = crypto.createHash(options.algorithm);
32
32
  hash.setEncoding(options.encoding);
33
33
 
34
- const fileStream = fs.createReadStream(filePath);
34
+ const fileStream = fse.createReadStream(filePath);
35
35
  fileStream.pipe(hash, {end: false});
36
36
  yield fileStream.once('end', next);
37
37
 
package/lib/json.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var fs = require('fs');
3
+ const fse = require('fs-extra');
4
4
  const traverse = require('xcraft-traverse');
5
5
 
6
6
  /**
@@ -9,8 +9,7 @@ const traverse = require('xcraft-traverse');
9
9
  * @returns {object}
10
10
  */
11
11
  exports.fromFile = function (jsonFile) {
12
- var data = fs.readFileSync(jsonFile, 'utf8');
13
- return JSON.parse(data);
12
+ return fse.readJSONSync(jsonFile);
14
13
  };
15
14
 
16
15
  /**
@@ -19,7 +18,7 @@ exports.fromFile = function (jsonFile) {
19
18
  * @param {*} destFile
20
19
  */
21
20
  exports.toFile = function (json, destFile) {
22
- fs.writeFileSync(destFile, JSON.stringify(json), 'utf8');
21
+ fse.writeJSONSync(destFile, json);
23
22
  };
24
23
 
25
24
  /**
package/lib/rest.js CHANGED
@@ -136,11 +136,15 @@ class RestAPI {
136
136
  /**
137
137
  * @param {string} query
138
138
  * @param {object} payload
139
+ * @param {object} [options]
139
140
  * @returns {object}
140
141
  */
141
- async _post(query, payload) {
142
+ async _post(query, payload, options = {}) {
142
143
  const {got} = await import('got');
143
- const result = await got.post(query, this.#buildOptions({json: payload}));
144
+ const result = await got.post(
145
+ query,
146
+ this.#buildOptions({json: payload, ...options})
147
+ );
144
148
  return result.body;
145
149
  }
146
150
 
package/lib/yaml.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var fs = require('fs');
3
+ const fse = require('fs-extra');
4
4
 
5
5
  exports.fromFile = function (yamlFile) {
6
- var yaml = require('js-yaml');
6
+ const yaml = require('js-yaml');
7
7
 
8
- var data = fs.readFileSync(yamlFile, 'utf8');
8
+ const data = fse.readFileSync(yamlFile, 'utf8');
9
9
  return yaml.safeLoad(data);
10
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcraft-core-utils",
3
- "version": "4.18.0",
3
+ "version": "4.18.2",
4
4
  "description": "Xcraft utils",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -25,7 +25,7 @@
25
25
  "escape-regexp": "0.0.1",
26
26
  "escape-string-regexp": "^1.0.5",
27
27
  "figlet": "^1.2.1",
28
- "fs-extra": "^9.1.0",
28
+ "fs-extra": "^11.3.0",
29
29
  "got": "^13.0.0",
30
30
  "gigawatts": "^4.0.1",
31
31
  "js-yaml": "^3.9.0",