@naturalcycles/nodejs-lib 12.64.0 → 12.64.1
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 +4 -4
- package/dist/got/getGot.js +19 -2
- package/package.json +1 -1
- package/src/fs/del.ts +8 -12
- package/src/got/getGot.ts +21 -2
package/dist/fs/del.js
CHANGED
|
@@ -55,14 +55,14 @@ async function del(_opt) {
|
|
|
55
55
|
}));
|
|
56
56
|
const dirnamesSorted = dirnames.sort().reverse();
|
|
57
57
|
// console.log({ dirnamesSorted })
|
|
58
|
-
const deletedDirs =
|
|
58
|
+
const deletedDirs = [];
|
|
59
|
+
for await (const dirpath of dirnamesSorted) {
|
|
59
60
|
if (await isEmptyDir(dirpath)) {
|
|
60
61
|
// console.log(`empty dir: ${dirpath}`)
|
|
61
62
|
await fs.remove(dirpath);
|
|
62
|
-
|
|
63
|
+
deletedDirs.push(dirpath);
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
}, { concurrency: 1 });
|
|
65
|
+
}
|
|
66
66
|
if (verbose || debug)
|
|
67
67
|
console.log({ deletedDirs });
|
|
68
68
|
if (!silent) {
|
package/dist/got/getGot.js
CHANGED
|
@@ -135,7 +135,23 @@ function gotErrorHook(opt = {}) {
|
|
|
135
135
|
.join('\n');
|
|
136
136
|
const stack = err.options.context?.err?.stack;
|
|
137
137
|
if (stack) {
|
|
138
|
-
|
|
138
|
+
const originalStack = err.stack.split('\n');
|
|
139
|
+
let originalStackIndex = originalStack.findIndex(line => line.includes(' at '));
|
|
140
|
+
if (originalStackIndex === -1)
|
|
141
|
+
originalStackIndex = originalStack.length - 1;
|
|
142
|
+
// Skipping first line as it has RequestError: ...
|
|
143
|
+
// Skipping second line as it's known to be from e.g at got_1.default.extend.handlers
|
|
144
|
+
const syntheticStack = stack.split('\n').slice(2);
|
|
145
|
+
let firstNonNodeModulesIndex = syntheticStack.findIndex(line => !line.includes('node_modules'));
|
|
146
|
+
if (firstNonNodeModulesIndex === -1)
|
|
147
|
+
firstNonNodeModulesIndex = 0;
|
|
148
|
+
err.stack = [
|
|
149
|
+
// First lines of original error
|
|
150
|
+
...originalStack.slice(0, originalStackIndex),
|
|
151
|
+
// Other lines from "Synthetic error"
|
|
152
|
+
...syntheticStack.slice(firstNonNodeModulesIndex),
|
|
153
|
+
].join('\n');
|
|
154
|
+
// err.stack += '\n --' + stack.replace('Error: RequestError', '')
|
|
139
155
|
}
|
|
140
156
|
return err;
|
|
141
157
|
};
|
|
@@ -196,7 +212,8 @@ function gotBeforeRetryHook(opt) {
|
|
|
196
212
|
function gotAfterResponseHook(opt = {}) {
|
|
197
213
|
return resp => {
|
|
198
214
|
const success = resp.statusCode >= 200 && resp.statusCode < 400;
|
|
199
|
-
|
|
215
|
+
// Errors are not logged here, as they're logged by gotErrorHook
|
|
216
|
+
if (opt.logFinished && success) {
|
|
200
217
|
const { started, retryCount } = resp.request.options.context;
|
|
201
218
|
const { url, prefixUrl, method } = resp.request.options;
|
|
202
219
|
const shortUrl = getShortUrl(opt, url, prefixUrl);
|
package/package.json
CHANGED
package/src/fs/del.ts
CHANGED
|
@@ -90,18 +90,14 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
|
|
|
90
90
|
|
|
91
91
|
// console.log({ dirnamesSorted })
|
|
92
92
|
|
|
93
|
-
const deletedDirs =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return false
|
|
102
|
-
},
|
|
103
|
-
{ concurrency: 1 },
|
|
104
|
-
)
|
|
93
|
+
const deletedDirs: string[] = []
|
|
94
|
+
for await (const dirpath of dirnamesSorted) {
|
|
95
|
+
if (await isEmptyDir(dirpath)) {
|
|
96
|
+
// console.log(`empty dir: ${dirpath}`)
|
|
97
|
+
await fs.remove(dirpath)
|
|
98
|
+
deletedDirs.push(dirpath)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
105
101
|
|
|
106
102
|
if (verbose || debug) console.log({ deletedDirs })
|
|
107
103
|
|
package/src/got/getGot.ts
CHANGED
|
@@ -151,7 +151,25 @@ function gotErrorHook(opt: GetGotOptions = {}): BeforeErrorHook {
|
|
|
151
151
|
|
|
152
152
|
const stack = (err.options.context as GotRequestContext)?.err?.stack
|
|
153
153
|
if (stack) {
|
|
154
|
-
|
|
154
|
+
const originalStack = err.stack.split('\n')
|
|
155
|
+
let originalStackIndex = originalStack.findIndex(line => line.includes(' at '))
|
|
156
|
+
if (originalStackIndex === -1) originalStackIndex = originalStack.length - 1
|
|
157
|
+
|
|
158
|
+
// Skipping first line as it has RequestError: ...
|
|
159
|
+
// Skipping second line as it's known to be from e.g at got_1.default.extend.handlers
|
|
160
|
+
const syntheticStack = stack.split('\n').slice(2)
|
|
161
|
+
let firstNonNodeModulesIndex = syntheticStack.findIndex(
|
|
162
|
+
line => !line.includes('node_modules'),
|
|
163
|
+
)
|
|
164
|
+
if (firstNonNodeModulesIndex === -1) firstNonNodeModulesIndex = 0
|
|
165
|
+
|
|
166
|
+
err.stack = [
|
|
167
|
+
// First lines of original error
|
|
168
|
+
...originalStack.slice(0, originalStackIndex),
|
|
169
|
+
// Other lines from "Synthetic error"
|
|
170
|
+
...syntheticStack.slice(firstNonNodeModulesIndex),
|
|
171
|
+
].join('\n')
|
|
172
|
+
// err.stack += '\n --' + stack.replace('Error: RequestError', '')
|
|
155
173
|
}
|
|
156
174
|
|
|
157
175
|
return err
|
|
@@ -226,7 +244,8 @@ function gotAfterResponseHook(opt: GetGotOptions = {}): AfterResponseHook {
|
|
|
226
244
|
return resp => {
|
|
227
245
|
const success = resp.statusCode >= 200 && resp.statusCode < 400
|
|
228
246
|
|
|
229
|
-
|
|
247
|
+
// Errors are not logged here, as they're logged by gotErrorHook
|
|
248
|
+
if (opt.logFinished && success) {
|
|
230
249
|
const { started, retryCount } = resp.request.options.context as GotRequestContext
|
|
231
250
|
const { url, prefixUrl, method } = resp.request.options
|
|
232
251
|
const shortUrl = getShortUrl(opt, url, prefixUrl)
|