@naturalcycles/nodejs-lib 12.92.0 → 12.93.0

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.
package/dist/fs/del.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.delSync = exports.del = void 0;
4
+ const fs = require("node:fs");
5
+ const fsp = require("node:fs/promises");
4
6
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const fs = require("fs-extra");
6
7
  const colors_1 = require("../colors");
7
8
  const index_1 = require("../index");
8
9
  const DEF_OPT = {
@@ -42,7 +43,7 @@ async function del(_opt) {
42
43
  }
43
44
  if (dry)
44
45
  return;
45
- await (0, js_lib_1.pMap)(filenames, filepath => fs.remove(filepath), { concurrency });
46
+ await (0, js_lib_1.pMap)(filenames, filepath => fsp.unlink(filepath), { concurrency });
46
47
  // 2. glob only dirs, expand, delete only empty!
47
48
  let dirnames = await (0, index_1.globby)(patterns, {
48
49
  dot: true,
@@ -51,7 +52,7 @@ async function del(_opt) {
51
52
  });
52
53
  // Add original patterns (if any of them are dirs)
53
54
  dirnames = dirnames.concat(await (0, js_lib_1.pFilter)(patterns, async (pattern) => {
54
- return (await fs.pathExists(pattern)) && (await fs.lstat(pattern)).isDirectory();
55
+ return (await (0, index_1._pathExists)(pattern)) && (await fsp.lstat(pattern)).isDirectory();
55
56
  }));
56
57
  const dirnamesSorted = dirnames.sort().reverse();
57
58
  // console.log({ dirnamesSorted })
@@ -59,7 +60,7 @@ async function del(_opt) {
59
60
  for await (const dirpath of dirnamesSorted) {
60
61
  if (await isEmptyDir(dirpath)) {
61
62
  // console.log(`empty dir: ${dirpath}`)
62
- await fs.remove(dirpath);
63
+ await fsp.unlink(dirpath);
63
64
  deletedDirs.push(dirpath);
64
65
  }
65
66
  }
@@ -97,7 +98,7 @@ function delSync(_opt) {
97
98
  }
98
99
  if (dry)
99
100
  return;
100
- filenames.forEach(filepath => fs.removeSync(filepath));
101
+ filenames.forEach(filepath => fs.unlinkSync(filepath));
101
102
  // 2. glob only dirs, expand, delete only empty!
102
103
  let dirnames = index_1.globby.sync(patterns, {
103
104
  dot: true,
@@ -105,14 +106,14 @@ function delSync(_opt) {
105
106
  onlyDirectories: true,
106
107
  });
107
108
  // Add original patterns (if any of them are dirs)
108
- dirnames = dirnames.concat(patterns.filter(p => fs.pathExistsSync(p) && fs.lstatSync(p).isDirectory()));
109
+ dirnames = dirnames.concat(patterns.filter(p => (0, index_1._pathExistsSync)(p) && fs.lstatSync(p).isDirectory()));
109
110
  const dirnamesSorted = dirnames.sort().reverse();
110
111
  // console.log({ dirnamesSorted })
111
112
  const deletedDirs = [];
112
113
  for (const dirpath of dirnamesSorted) {
113
114
  if (isEmptyDirSync(dirpath)) {
114
115
  // console.log(`empty dir: ${dirpath}`)
115
- fs.removeSync(dirpath);
116
+ fs.unlinkSync(dirpath);
116
117
  deletedDirs.push(dirpath);
117
118
  }
118
119
  }
@@ -128,7 +129,7 @@ exports.delSync = delSync;
128
129
  // 2. glob only dirs, expand, delete only empty!
129
130
  // 3. test each original pattern, if it exists and is directory and is empty - delete
130
131
  async function isEmptyDir(dir) {
131
- return (await fs.readdir(dir)).length === 0;
132
+ return (await fsp.readdir(dir)).length === 0;
132
133
  }
133
134
  function isEmptyDirSync(dir) {
134
135
  return fs.readdirSync(dir).length === 0;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import type { CopyOptions, CopyOptionsSync, MoveOptions } from 'fs-extra';
2
+ /// <reference types="node" />
3
+ import * as fs from 'node:fs';
3
4
  export interface JsonOptions {
4
5
  spaces?: number;
5
6
  }
@@ -31,7 +32,13 @@ export declare function _removePath(fileOrDirPath: string): Promise<void>;
31
32
  export declare function _removePathSync(fileOrDirPath: string): void;
32
33
  export declare function _emptyDir(dirPath: string): Promise<void>;
33
34
  export declare function _emptyDirSync(dirPath: string): void;
34
- export declare function _copyPath(src: string, dest: string, opt?: CopyOptions): Promise<void>;
35
- export declare function _copyPathSync(src: string, dest: string, opt?: CopyOptionsSync): void;
36
- export declare function _movePath(src: string, dest: string, opt?: MoveOptions): Promise<void>;
37
- export declare function _movePathSync(src: string, dest: string, opt?: MoveOptions): void;
35
+ /**
36
+ * Cautious, underlying Node function is currently Experimental.
37
+ */
38
+ export declare function _copyPath(src: string, dest: string, opt?: fs.CopyOptions): Promise<void>;
39
+ /**
40
+ * Cautious, underlying Node function is currently Experimental.
41
+ */
42
+ export declare function _copyPathSync(src: string, dest: string, opt?: fs.CopySyncOptions): void;
43
+ export declare function _movePath(src: string, dest: string, opt?: fs.CopyOptions): Promise<void>;
44
+ export declare function _movePathSync(src: string, dest: string, opt?: fs.CopySyncOptions): void;
@@ -20,7 +20,6 @@ const fs = require("node:fs");
20
20
  const fsp = require("node:fs/promises");
21
21
  const path = require("node:path");
22
22
  const js_lib_1 = require("@naturalcycles/js-lib");
23
- const fse = require("fs-extra");
24
23
  /**
25
24
  * Convenience wrapper that defaults to utf-8 string output.
26
25
  */
@@ -197,20 +196,33 @@ function _emptyDirSync(dirPath) {
197
196
  items.forEach(item => _removePathSync(path.join(dirPath, item)));
198
197
  }
199
198
  exports._emptyDirSync = _emptyDirSync;
200
- // copyFile/moveFile - let's keep using fs-extra for now
199
+ /**
200
+ * Cautious, underlying Node function is currently Experimental.
201
+ */
201
202
  async function _copyPath(src, dest, opt) {
202
- await fse.copy(src, dest, opt);
203
+ await fsp.cp(src, dest, {
204
+ recursive: true,
205
+ ...opt,
206
+ });
203
207
  }
204
208
  exports._copyPath = _copyPath;
209
+ /**
210
+ * Cautious, underlying Node function is currently Experimental.
211
+ */
205
212
  function _copyPathSync(src, dest, opt) {
206
- fse.copySync(src, dest, opt);
213
+ fs.cpSync(src, dest, {
214
+ recursive: true,
215
+ ...opt,
216
+ });
207
217
  }
208
218
  exports._copyPathSync = _copyPathSync;
209
219
  async function _movePath(src, dest, opt) {
210
- await fse.move(src, dest, opt);
220
+ await _copyPath(src, dest, opt);
221
+ await _removePath(src);
211
222
  }
212
223
  exports._movePath = _movePath;
213
224
  function _movePathSync(src, dest, opt) {
214
- fse.moveSync(src, dest, opt);
225
+ _copyPathSync(src, dest, opt);
226
+ _removePathSync(src);
215
227
  }
216
228
  exports._movePathSync = _movePathSync;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.objectToGithubActionsEnv = exports.objectToShellExport = exports.json2env = void 0;
4
- const fs = require("fs-extra");
4
+ const fs = require("node:fs");
5
5
  const colors_1 = require("../colors");
6
+ const fs_util_1 = require("./fs.util");
6
7
  const JSON2ENV_OPT_DEF = {
7
8
  saveEnvFile: true,
8
9
  bashEnv: true,
@@ -14,7 +15,7 @@ function json2env(opt) {
14
15
  ...JSON2ENV_OPT_DEF,
15
16
  ...opt,
16
17
  };
17
- if (!fs.pathExistsSync(jsonPath)) {
18
+ if (!(0, fs_util_1._pathExistsSync)(jsonPath)) {
18
19
  if (fail) {
19
20
  throw new Error(`Path doesn't exist: ${jsonPath}`);
20
21
  }
@@ -27,7 +28,7 @@ function json2env(opt) {
27
28
  return;
28
29
  }
29
30
  // read file
30
- const json = fs.readJsonSync(jsonPath);
31
+ const json = (0, fs_util_1._readJsonFileSync)(jsonPath);
31
32
  const exportStr = objectToShellExport(json, prefix);
32
33
  const githubStr = objectToGithubActionsEnv(json, prefix);
33
34
  if (debug) {
@@ -35,7 +36,7 @@ function json2env(opt) {
35
36
  }
36
37
  if (saveEnvFile) {
37
38
  const shPath = `${jsonPath}.sh`;
38
- fs.writeFileSync(shPath, exportStr);
39
+ (0, fs_util_1._writeFileSync)(shPath, exportStr);
39
40
  if (!silent) {
40
41
  console.log(`json2env created ${(0, colors_1.dimGrey)(shPath)}:`);
41
42
  console.log(exportStr);
package/dist/fs/kpy.js CHANGED
@@ -20,10 +20,12 @@ async function kpy(opt) {
20
20
  const destFilename = path.resolve(opt.outputDir, opt.flat ? basename : filename);
21
21
  if (!opt.dry) {
22
22
  if (opt.move) {
23
- await (0, index_1._movePath)(srcFilename, destFilename, { overwrite });
23
+ await (0, index_1._movePath)(srcFilename, destFilename, {
24
+ force: overwrite,
25
+ });
24
26
  }
25
27
  else {
26
- await (0, index_1._copyPath)(srcFilename, destFilename, { overwrite });
28
+ await (0, index_1._copyPath)(srcFilename, destFilename, { force: overwrite });
27
29
  }
28
30
  }
29
31
  if (opt.verbose) {
@@ -48,10 +50,10 @@ function kpySync(opt) {
48
50
  const destFilename = path.resolve(opt.outputDir, opt.flat ? basename : filename);
49
51
  if (!opt.dry) {
50
52
  if (opt.move) {
51
- (0, index_1._movePathSync)(srcFilename, destFilename, { overwrite });
53
+ (0, index_1._movePathSync)(srcFilename, destFilename, { force: overwrite });
52
54
  }
53
55
  else {
54
- (0, index_1._copyPathSync)(srcFilename, destFilename, { overwrite });
56
+ (0, index_1._copyPathSync)(srcFilename, destFilename, { force: overwrite });
55
57
  }
56
58
  }
57
59
  if (opt.verbose) {
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.secretsDecrypt = void 0;
4
4
  const path = require("node:path");
5
+ const fs = require("node:fs");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
- const fs = require("fs-extra");
7
7
  const colors_1 = require("../colors");
8
8
  const index_1 = require("../index");
9
9
  const crypto_util_1 = require("../security/crypto.util");
@@ -24,8 +24,8 @@ function secretsDecrypt(dir, file, encKey, del = false, jsonMode = false) {
24
24
  (0, js_lib_1._assert)(filename.endsWith('.json'), `${path.basename(filename)} MUST end with '.json'`);
25
25
  (0, js_lib_1._assert)(!filename.endsWith('.plain.json'), `${path.basename(filename)} MUST NOT end with '.plain.json'`);
26
26
  plainFilename = filename.replace('.json', '.plain.json');
27
- const json = (0, crypto_util_1.decryptObject)(JSON.parse(fs.readFileSync(filename, 'utf8')), encKey);
28
- fs.writeFileSync(plainFilename, JSON.stringify(json, null, 2));
27
+ const json = (0, crypto_util_1.decryptObject)((0, index_1._readJsonFileSync)(filename), encKey);
28
+ (0, index_1._writeJsonFileSync)(plainFilename, json, { spaces: 2 });
29
29
  }
30
30
  else {
31
31
  const enc = fs.readFileSync(filename);
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.secretsEncrypt = void 0;
4
+ const fs = require("node:fs");
4
5
  const path = require("node:path");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
- const fs = require("fs-extra");
7
7
  const colors_1 = require("../colors");
8
8
  const index_1 = require("../index");
9
9
  const crypto_util_1 = require("../security/crypto.util");
@@ -24,8 +24,8 @@ function secretsEncrypt(pattern, file, encKey, del = false, jsonMode = false) {
24
24
  if (jsonMode) {
25
25
  (0, js_lib_1._assert)(filename.endsWith('.plain.json'), `${path.basename(filename)} MUST end with '.plain.json'`);
26
26
  encFilename = filename.replace('.plain', '');
27
- const json = (0, crypto_util_1.encryptObject)(JSON.parse(fs.readFileSync(filename, 'utf8')), encKey);
28
- fs.writeFileSync(encFilename, JSON.stringify(json, null, 2));
27
+ const json = (0, crypto_util_1.encryptObject)((0, index_1._readJsonFileSync)(filename), encKey);
28
+ (0, index_1._writeJsonFileSync)(encFilename, json, { spaces: 2 });
29
29
  }
30
30
  else {
31
31
  const plain = fs.readFileSync(filename);
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pipelineFromNDJsonFile = void 0;
4
4
  const node_zlib_1 = require("node:zlib");
5
+ const fs = require("node:fs");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
- const fs = require("fs-extra");
7
7
  const __1 = require("../..");
8
8
  const colors_1 = require("../../colors");
9
9
  const ndjson_model_1 = require("./ndjson.model");
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pipelineToNDJsonFile = void 0;
4
4
  const node_zlib_1 = require("node:zlib");
5
+ const fs = require("node:fs");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
- const fs = require("fs-extra");
7
7
  const __1 = require("../..");
8
8
  const colors_1 = require("../../colors");
9
9
  const ndjson_model_1 = require("./ndjson.model");
@@ -15,12 +15,12 @@ const transformToNDJson_1 = require("./transformToNDJson");
15
15
  */
16
16
  async function pipelineToNDJsonFile(streams, opt) {
17
17
  const { filePath, gzip, protectFromOverwrite = false } = opt;
18
- if (protectFromOverwrite && fs.pathExistsSync(filePath)) {
18
+ if (protectFromOverwrite && (0, __1._pathExistsSync)(filePath)) {
19
19
  throw new js_lib_1.AppError(`pipelineToNDJsonFile: output file exists: ${filePath}`);
20
20
  }
21
21
  const started = Date.now();
22
22
  let rows = 0;
23
- fs.ensureFileSync(filePath);
23
+ (0, __1._ensureFileSync)(filePath);
24
24
  console.log(`>> ${(0, colors_1.grey)(filePath)} started...`);
25
25
  await (0, __1._pipeline)([
26
26
  ...streams,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.92.0",
3
+ "version": "12.93.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@naturalcycles/js-lib": "^14.0.0",
18
- "@types/fs-extra": "^11.0.1",
19
18
  "@types/jsonwebtoken": "^9.0.0",
20
19
  "@types/through2-concurrent": "^2.0.0",
21
20
  "ajv": "^8.6.2",
@@ -28,7 +27,6 @@
28
27
  "dotenv": "^16.0.0",
29
28
  "execa": "^5.0.0",
30
29
  "fast-glob": "^3.2.11",
31
- "fs-extra": "^11.0.0",
32
30
  "globby": "^11.0.0",
33
31
  "got": "^11.0.1",
34
32
  "joi": "17.4.2",
package/src/fs/del.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import * as fs from 'node:fs'
2
+ import * as fsp from 'node:fs/promises'
1
3
  import { pFilter, pMap, _since } from '@naturalcycles/js-lib'
2
- import * as fs from 'fs-extra'
3
4
  import { dimGrey, yellow } from '../colors'
4
- import { globby } from '../index'
5
+ import { _pathExists, _pathExistsSync, globby } from '../index'
5
6
 
6
7
  export interface DelOptions {
7
8
  /**
@@ -70,7 +71,7 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
70
71
 
71
72
  if (dry) return
72
73
 
73
- await pMap(filenames, filepath => fs.remove(filepath), { concurrency })
74
+ await pMap(filenames, filepath => fsp.unlink(filepath), { concurrency })
74
75
 
75
76
  // 2. glob only dirs, expand, delete only empty!
76
77
  let dirnames = await globby(patterns, {
@@ -82,7 +83,7 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
82
83
  // Add original patterns (if any of them are dirs)
83
84
  dirnames = dirnames.concat(
84
85
  await pFilter(patterns, async pattern => {
85
- return (await fs.pathExists(pattern)) && (await fs.lstat(pattern)).isDirectory()
86
+ return (await _pathExists(pattern)) && (await fsp.lstat(pattern)).isDirectory()
86
87
  }),
87
88
  )
88
89
 
@@ -94,7 +95,7 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
94
95
  for await (const dirpath of dirnamesSorted) {
95
96
  if (await isEmptyDir(dirpath)) {
96
97
  // console.log(`empty dir: ${dirpath}`)
97
- await fs.remove(dirpath)
98
+ await fsp.unlink(dirpath)
98
99
  deletedDirs.push(dirpath)
99
100
  }
100
101
  }
@@ -144,7 +145,7 @@ export function delSync(_opt: DelOptions | DelSingleOption): void {
144
145
 
145
146
  if (dry) return
146
147
 
147
- filenames.forEach(filepath => fs.removeSync(filepath))
148
+ filenames.forEach(filepath => fs.unlinkSync(filepath))
148
149
 
149
150
  // 2. glob only dirs, expand, delete only empty!
150
151
  let dirnames = globby.sync(patterns, {
@@ -155,7 +156,7 @@ export function delSync(_opt: DelOptions | DelSingleOption): void {
155
156
 
156
157
  // Add original patterns (if any of them are dirs)
157
158
  dirnames = dirnames.concat(
158
- patterns.filter(p => fs.pathExistsSync(p) && fs.lstatSync(p).isDirectory()),
159
+ patterns.filter(p => _pathExistsSync(p) && fs.lstatSync(p).isDirectory()),
159
160
  )
160
161
 
161
162
  const dirnamesSorted = dirnames.sort().reverse()
@@ -166,7 +167,7 @@ export function delSync(_opt: DelOptions | DelSingleOption): void {
166
167
  for (const dirpath of dirnamesSorted) {
167
168
  if (isEmptyDirSync(dirpath)) {
168
169
  // console.log(`empty dir: ${dirpath}`)
169
- fs.removeSync(dirpath)
170
+ fs.unlinkSync(dirpath)
170
171
  deletedDirs.push(dirpath)
171
172
  }
172
173
  }
@@ -188,7 +189,7 @@ export function delSync(_opt: DelOptions | DelSingleOption): void {
188
189
  // 3. test each original pattern, if it exists and is directory and is empty - delete
189
190
 
190
191
  async function isEmptyDir(dir: string): Promise<boolean> {
191
- return (await fs.readdir(dir)).length === 0
192
+ return (await fsp.readdir(dir)).length === 0
192
193
  }
193
194
 
194
195
  function isEmptyDirSync(dir: string): boolean {
package/src/fs/fs.util.ts CHANGED
@@ -18,8 +18,6 @@ import * as fs from 'node:fs'
18
18
  import * as fsp from 'node:fs/promises'
19
19
  import * as path from 'node:path'
20
20
  import { _jsonParse } from '@naturalcycles/js-lib'
21
- import type { CopyOptions, CopyOptionsSync, MoveOptions } from 'fs-extra'
22
- import * as fse from 'fs-extra'
23
21
 
24
22
  export interface JsonOptions {
25
23
  spaces?: number
@@ -206,20 +204,32 @@ export function _emptyDirSync(dirPath: string): void {
206
204
  items.forEach(item => _removePathSync(path.join(dirPath, item)))
207
205
  }
208
206
 
209
- // copyFile/moveFile - let's keep using fs-extra for now
210
-
211
- export async function _copyPath(src: string, dest: string, opt?: CopyOptions): Promise<void> {
212
- await fse.copy(src, dest, opt)
207
+ /**
208
+ * Cautious, underlying Node function is currently Experimental.
209
+ */
210
+ export async function _copyPath(src: string, dest: string, opt?: fs.CopyOptions): Promise<void> {
211
+ await fsp.cp(src, dest, {
212
+ recursive: true,
213
+ ...opt,
214
+ })
213
215
  }
214
216
 
215
- export function _copyPathSync(src: string, dest: string, opt?: CopyOptionsSync): void {
216
- fse.copySync(src, dest, opt)
217
+ /**
218
+ * Cautious, underlying Node function is currently Experimental.
219
+ */
220
+ export function _copyPathSync(src: string, dest: string, opt?: fs.CopySyncOptions): void {
221
+ fs.cpSync(src, dest, {
222
+ recursive: true,
223
+ ...opt,
224
+ })
217
225
  }
218
226
 
219
- export async function _movePath(src: string, dest: string, opt?: MoveOptions): Promise<void> {
220
- await fse.move(src, dest, opt)
227
+ export async function _movePath(src: string, dest: string, opt?: fs.CopyOptions): Promise<void> {
228
+ await _copyPath(src, dest, opt)
229
+ await _removePath(src)
221
230
  }
222
231
 
223
- export function _movePathSync(src: string, dest: string, opt?: MoveOptions): void {
224
- fse.moveSync(src, dest, opt)
232
+ export function _movePathSync(src: string, dest: string, opt?: fs.CopySyncOptions): void {
233
+ _copyPathSync(src, dest, opt)
234
+ _removePathSync(src)
225
235
  }
@@ -1,5 +1,6 @@
1
- import * as fs from 'fs-extra'
1
+ import * as fs from 'node:fs'
2
2
  import { dimGrey } from '../colors'
3
+ import { _pathExistsSync, _readJsonFileSync, _writeFileSync } from './fs.util'
3
4
 
4
5
  export interface Json2EnvOptions {
5
6
  jsonPath: string
@@ -42,7 +43,7 @@ export function json2env(opt: Json2EnvOptions): void {
42
43
  ...opt,
43
44
  }
44
45
 
45
- if (!fs.pathExistsSync(jsonPath)) {
46
+ if (!_pathExistsSync(jsonPath)) {
46
47
  if (fail) {
47
48
  throw new Error(`Path doesn't exist: ${jsonPath}`)
48
49
  }
@@ -59,7 +60,7 @@ export function json2env(opt: Json2EnvOptions): void {
59
60
  }
60
61
 
61
62
  // read file
62
- const json = fs.readJsonSync(jsonPath)
63
+ const json = _readJsonFileSync(jsonPath)
63
64
 
64
65
  const exportStr = objectToShellExport(json, prefix)
65
66
  const githubStr = objectToGithubActionsEnv(json, prefix)
@@ -70,7 +71,7 @@ export function json2env(opt: Json2EnvOptions): void {
70
71
 
71
72
  if (saveEnvFile) {
72
73
  const shPath = `${jsonPath}.sh`
73
- fs.writeFileSync(shPath, exportStr)
74
+ _writeFileSync(shPath, exportStr)
74
75
 
75
76
  if (!silent) {
76
77
  console.log(`json2env created ${dimGrey(shPath)}:`)
package/src/fs/kpy.ts CHANGED
@@ -72,9 +72,11 @@ export async function kpy(opt: KpyOptions): Promise<void> {
72
72
 
73
73
  if (!opt.dry) {
74
74
  if (opt.move) {
75
- await _movePath(srcFilename, destFilename, { overwrite })
75
+ await _movePath(srcFilename, destFilename, {
76
+ force: overwrite,
77
+ })
76
78
  } else {
77
- await _copyPath(srcFilename, destFilename, { overwrite })
79
+ await _copyPath(srcFilename, destFilename, { force: overwrite })
78
80
  }
79
81
  }
80
82
 
@@ -108,9 +110,9 @@ export function kpySync(opt: KpyOptions): void {
108
110
 
109
111
  if (!opt.dry) {
110
112
  if (opt.move) {
111
- _movePathSync(srcFilename, destFilename, { overwrite })
113
+ _movePathSync(srcFilename, destFilename, { force: overwrite })
112
114
  } else {
113
- _copyPathSync(srcFilename, destFilename, { overwrite })
115
+ _copyPathSync(srcFilename, destFilename, { force: overwrite })
114
116
  }
115
117
  }
116
118
 
@@ -1,8 +1,8 @@
1
1
  import * as path from 'node:path'
2
+ import * as fs from 'node:fs'
2
3
  import { _assert } from '@naturalcycles/js-lib'
3
- import * as fs from 'fs-extra'
4
4
  import { dimGrey, yellow } from '../colors'
5
- import { fastGlob } from '../index'
5
+ import { _readJsonFileSync, _writeJsonFileSync, fastGlob } from '../index'
6
6
  import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util'
7
7
 
8
8
  export interface DecryptCLIOptions {
@@ -44,9 +44,9 @@ export function secretsDecrypt(
44
44
  )
45
45
  plainFilename = filename.replace('.json', '.plain.json')
46
46
 
47
- const json = decryptObject(JSON.parse(fs.readFileSync(filename, 'utf8')), encKey)
47
+ const json = decryptObject(_readJsonFileSync(filename), encKey)
48
48
 
49
- fs.writeFileSync(plainFilename, JSON.stringify(json, null, 2))
49
+ _writeJsonFileSync(plainFilename, json, { spaces: 2 })
50
50
  } else {
51
51
  const enc = fs.readFileSync(filename)
52
52
  const plain = decryptRandomIVBuffer(enc, encKey)
@@ -1,8 +1,8 @@
1
+ import * as fs from 'node:fs'
1
2
  import * as path from 'node:path'
2
3
  import { _assert } from '@naturalcycles/js-lib'
3
- import * as fs from 'fs-extra'
4
4
  import { dimGrey, yellow } from '../colors'
5
- import { fastGlob } from '../index'
5
+ import { _readJsonFileSync, _writeJsonFileSync, fastGlob } from '../index'
6
6
  import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util'
7
7
 
8
8
  export interface EncryptCLIOptions {
@@ -41,9 +41,9 @@ export function secretsEncrypt(
41
41
  )
42
42
  encFilename = filename.replace('.plain', '')
43
43
 
44
- const json = encryptObject(JSON.parse(fs.readFileSync(filename, 'utf8')), encKey)
44
+ const json = encryptObject(_readJsonFileSync(filename), encKey)
45
45
 
46
- fs.writeFileSync(encFilename, JSON.stringify(json, null, 2))
46
+ _writeJsonFileSync(encFilename, json, { spaces: 2 })
47
47
  } else {
48
48
  const plain = fs.readFileSync(filename)
49
49
  const enc = encryptRandomIVBuffer(plain, encKey)
@@ -122,7 +122,7 @@ export function secretOptional<T = string>(k: string, parseJson = false): T | un
122
122
  if (!v) return
123
123
 
124
124
  if (parseJson) {
125
- v = _jsonParseIfPossible(v) as any
125
+ v = _jsonParseIfPossible(v)
126
126
  }
127
127
 
128
128
  return v as T
@@ -1,6 +1,6 @@
1
1
  import { createUnzip, ZlibOptions } from 'node:zlib'
2
+ import * as fs from 'node:fs'
2
3
  import { _hb } from '@naturalcycles/js-lib'
3
- import * as fs from 'fs-extra'
4
4
  import { transformTap, _pipeline, transformSplit } from '../..'
5
5
  import { dimWhite, grey } from '../../colors'
6
6
  import { NDJsonStats } from './ndjson.model'
@@ -1,7 +1,7 @@
1
1
  import { createGzip, ZlibOptions } from 'node:zlib'
2
+ import * as fs from 'node:fs'
2
3
  import { AppError } from '@naturalcycles/js-lib'
3
- import * as fs from 'fs-extra'
4
- import { transformTap, _pipeline } from '../..'
4
+ import { transformTap, _pipeline, _pathExistsSync, _ensureFileSync } from '../..'
5
5
  import { grey } from '../../colors'
6
6
  import { NDJsonStats } from './ndjson.model'
7
7
  import { transformToNDJson, TransformToNDJsonOptions } from './transformToNDJson'
@@ -37,14 +37,14 @@ export async function pipelineToNDJsonFile(
37
37
  ): Promise<NDJsonStats> {
38
38
  const { filePath, gzip, protectFromOverwrite = false } = opt
39
39
 
40
- if (protectFromOverwrite && fs.pathExistsSync(filePath)) {
40
+ if (protectFromOverwrite && _pathExistsSync(filePath)) {
41
41
  throw new AppError(`pipelineToNDJsonFile: output file exists: ${filePath}`)
42
42
  }
43
43
 
44
44
  const started = Date.now()
45
45
  let rows = 0
46
46
 
47
- fs.ensureFileSync(filePath)
47
+ _ensureFileSync(filePath)
48
48
 
49
49
  console.log(`>> ${grey(filePath)} started...`)
50
50