@naturalcycles/nodejs-lib 12.93.1 → 12.94.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/bin/del.js CHANGED
@@ -22,5 +22,5 @@ const script_1 = require("../script");
22
22
  type: 'number',
23
23
  },
24
24
  }).argv;
25
- await (0, del_1.del)({ patterns: patterns, ...opt });
25
+ (0, del_1.delSync)({ patterns: patterns, ...opt });
26
26
  });
package/dist/fs/del.js CHANGED
@@ -43,7 +43,9 @@ async function del(_opt) {
43
43
  }
44
44
  if (dry)
45
45
  return;
46
- await (0, js_lib_1.pMap)(filenames, filepath => fsp.unlink(filepath), { concurrency });
46
+ await (0, js_lib_1.pMap)(filenames, filepath => fsp.rm(filepath, {
47
+ force: true,
48
+ }), { concurrency });
47
49
  // 2. glob only dirs, expand, delete only empty!
48
50
  let dirnames = await (0, index_1.globby)(patterns, {
49
51
  dot: true,
@@ -60,7 +62,7 @@ async function del(_opt) {
60
62
  for await (const dirpath of dirnamesSorted) {
61
63
  if (await isEmptyDir(dirpath)) {
62
64
  // console.log(`empty dir: ${dirpath}`)
63
- await fsp.unlink(dirpath);
65
+ await fsp.rm(dirpath, { force: true, recursive: true });
64
66
  deletedDirs.push(dirpath);
65
67
  }
66
68
  }
@@ -98,7 +100,7 @@ function delSync(_opt) {
98
100
  }
99
101
  if (dry)
100
102
  return;
101
- filenames.forEach(filepath => fs.unlinkSync(filepath));
103
+ filenames.forEach(filepath => fs.rmSync(filepath, { force: true }));
102
104
  // 2. glob only dirs, expand, delete only empty!
103
105
  let dirnames = index_1.globby.sync(patterns, {
104
106
  dot: true,
@@ -113,7 +115,7 @@ function delSync(_opt) {
113
115
  for (const dirpath of dirnamesSorted) {
114
116
  if (isEmptyDirSync(dirpath)) {
115
117
  // console.log(`empty dir: ${dirpath}`)
116
- fs.unlinkSync(dirpath);
118
+ fs.rmSync(dirpath, { force: true, recursive: true });
117
119
  deletedDirs.push(dirpath);
118
120
  }
119
121
  }
@@ -110,17 +110,23 @@ function createError(value, err, objectName) {
110
110
  tokens.push('Invalid ' + [objectName, objectId].filter(Boolean).join('.'));
111
111
  }
112
112
  const annotation = err.annotate(stripColors);
113
- if (annotation.length > 4000) {
114
- // Annotation message is too big and will be replaced by stringified `error.details` instead
115
- tokens.push((0, js_lib_1._truncateMiddle)(annotation, 4000, `\n... ${(0, js_lib_1._hb)(annotation.length)} message truncated ...\n`));
113
+ if (annotation.length > 100) {
114
+ // For rather large annotations - we include up to 5 errors up front, before printing the whole object.
116
115
  // Up to 5 `details`
117
- tokens.push(...err.details.slice(0, 5).map(i => `${i.message} @ .${i.path.join('.')}`));
116
+ tokens.push(...err.details.slice(0, 5).map(i => {
117
+ return i.message;
118
+ // Currently not specifying the path, to not "overwhelm" the message
119
+ // Can be reverted if needed.
120
+ // let msg = i.message
121
+ // const paths = i.path.filter(Boolean).join('.')
122
+ // if (paths) msg += ` @ .${paths}`
123
+ // return msg
124
+ }));
118
125
  if (err.details.length > 5)
119
- tokens.push(`... ${err.details.length} errors`);
120
- }
121
- else {
122
- tokens.push(annotation);
126
+ tokens.push(`... ${err.details.length} errors in total`);
127
+ tokens.push('');
123
128
  }
129
+ tokens.push((0, js_lib_1._truncateMiddle)(annotation, 4000, `\n... ${(0, js_lib_1._hb)(annotation.length)} message truncated ...\n`));
124
130
  const msg = tokens.join('\n');
125
131
  const data = {
126
132
  joiValidationErrorItems: err.details,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.93.1",
3
+ "version": "12.94.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
package/src/bin/del.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import * as yargs from 'yargs'
4
- import { del } from '../fs/del'
4
+ import { delSync } from '../fs/del'
5
5
  import { runScript } from '../script'
6
6
 
7
7
  runScript(async () => {
@@ -23,5 +23,5 @@ runScript(async () => {
23
23
  },
24
24
  }).argv
25
25
 
26
- await del({ patterns: patterns as string[], ...opt })
26
+ delSync({ patterns: patterns as string[], ...opt })
27
27
  })
package/src/fs/del.ts CHANGED
@@ -71,7 +71,14 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
71
71
 
72
72
  if (dry) return
73
73
 
74
- await pMap(filenames, filepath => fsp.unlink(filepath), { concurrency })
74
+ await pMap(
75
+ filenames,
76
+ filepath =>
77
+ fsp.rm(filepath, {
78
+ force: true,
79
+ }),
80
+ { concurrency },
81
+ )
75
82
 
76
83
  // 2. glob only dirs, expand, delete only empty!
77
84
  let dirnames = await globby(patterns, {
@@ -95,7 +102,7 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
95
102
  for await (const dirpath of dirnamesSorted) {
96
103
  if (await isEmptyDir(dirpath)) {
97
104
  // console.log(`empty dir: ${dirpath}`)
98
- await fsp.unlink(dirpath)
105
+ await fsp.rm(dirpath, { force: true, recursive: true })
99
106
  deletedDirs.push(dirpath)
100
107
  }
101
108
  }
@@ -145,7 +152,7 @@ export function delSync(_opt: DelOptions | DelSingleOption): void {
145
152
 
146
153
  if (dry) return
147
154
 
148
- filenames.forEach(filepath => fs.unlinkSync(filepath))
155
+ filenames.forEach(filepath => fs.rmSync(filepath, { force: true }))
149
156
 
150
157
  // 2. glob only dirs, expand, delete only empty!
151
158
  let dirnames = globby.sync(patterns, {
@@ -167,7 +174,7 @@ export function delSync(_opt: DelOptions | DelSingleOption): void {
167
174
  for (const dirpath of dirnamesSorted) {
168
175
  if (isEmptyDirSync(dirpath)) {
169
176
  // console.log(`empty dir: ${dirpath}`)
170
- fs.unlinkSync(dirpath)
177
+ fs.rmSync(dirpath, { force: true, recursive: true })
171
178
  deletedDirs.push(dirpath)
172
179
  }
173
180
  }
@@ -146,21 +146,30 @@ function createError(value: any, err: ValidationError, objectName?: string): Joi
146
146
 
147
147
  const annotation = err.annotate(stripColors)
148
148
 
149
- if (annotation.length > 4000) {
150
- // Annotation message is too big and will be replaced by stringified `error.details` instead
149
+ if (annotation.length > 100) {
150
+ // For rather large annotations - we include up to 5 errors up front, before printing the whole object.
151
151
 
152
+ // Up to 5 `details`
152
153
  tokens.push(
153
- _truncateMiddle(annotation, 4000, `\n... ${_hb(annotation.length)} message truncated ...\n`),
154
+ ...err.details.slice(0, 5).map(i => {
155
+ return i.message
156
+ // Currently not specifying the path, to not "overwhelm" the message
157
+ // Can be reverted if needed.
158
+ // let msg = i.message
159
+ // const paths = i.path.filter(Boolean).join('.')
160
+ // if (paths) msg += ` @ .${paths}`
161
+ // return msg
162
+ }),
154
163
  )
155
164
 
156
- // Up to 5 `details`
157
- tokens.push(...err.details.slice(0, 5).map(i => `${i.message} @ .${i.path.join('.')}`))
158
-
159
- if (err.details.length > 5) tokens.push(`... ${err.details.length} errors`)
160
- } else {
161
- tokens.push(annotation)
165
+ if (err.details.length > 5) tokens.push(`... ${err.details.length} errors in total`)
166
+ tokens.push('')
162
167
  }
163
168
 
169
+ tokens.push(
170
+ _truncateMiddle(annotation, 4000, `\n... ${_hb(annotation.length)} message truncated ...\n`),
171
+ )
172
+
164
173
  const msg = tokens.join('\n')
165
174
 
166
175
  const data: JoiValidationErrorData = {