@jsenv/filesystem 4.9.1 → 4.9.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/filesystem",
3
- "version": "4.9.1",
3
+ "version": "4.9.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,9 +31,9 @@
31
31
  "test": "node --conditions=development ./scripts/test.mjs"
32
32
  },
33
33
  "dependencies": {
34
- "@jsenv/urls": "2.3.1",
34
+ "@jsenv/urls": "2.3.2",
35
35
  "@jsenv/url-meta": "8.4.2",
36
36
  "@jsenv/abort": "4.3.0",
37
- "@jsenv/utils": "2.1.1"
37
+ "@jsenv/utils": "2.1.2"
38
38
  }
39
39
  }
@@ -1,4 +1,3 @@
1
- import { Abort } from "@jsenv/abort";
2
1
  import {
3
2
  ensurePathnameTrailingSlash,
4
3
  resolveUrl,
@@ -18,7 +17,6 @@ import { readEntryStatSync } from "../read_write/stat/read_entry_stat_sync.js";
18
17
  export const removeEntrySync = (
19
18
  source,
20
19
  {
21
- signal = new AbortController().signal,
22
20
  allowUseless = false,
23
21
  recursive = false,
24
22
  maxRetries = 3,
@@ -27,51 +25,41 @@ export const removeEntrySync = (
27
25
  } = {},
28
26
  ) => {
29
27
  const sourceUrl = assertAndNormalizeFileUrl(source);
30
-
31
- const removeOperation = Abort.startOperation();
32
- removeOperation.addAbortSignal(signal);
33
-
34
- try {
35
- removeOperation.throwIfAborted();
36
- const sourceStats = readEntryStatSync(sourceUrl, {
37
- nullIfNotFound: true,
38
- followLink: false,
39
- });
40
- if (!sourceStats) {
41
- if (allowUseless) {
42
- return;
43
- }
44
- throw new Error(`nothing to remove at ${urlToFileSystemPath(sourceUrl)}`);
28
+ const sourceStats = readEntryStatSync(sourceUrl, {
29
+ nullIfNotFound: true,
30
+ followLink: false,
31
+ });
32
+ if (!sourceStats) {
33
+ if (allowUseless) {
34
+ return;
45
35
  }
36
+ throw new Error(`nothing to remove at ${urlToFileSystemPath(sourceUrl)}`);
37
+ }
46
38
 
47
- // https://nodejs.org/dist/latest-v13.x/docs/api/fs.html#fs_class_fs_stats
48
- // FIFO and socket are ignored, not sure what they are exactly and what to do with them
49
- // other libraries ignore them, let's do the same.
50
- if (
51
- sourceStats.isFile() ||
52
- sourceStats.isSymbolicLink() ||
53
- sourceStats.isCharacterDevice() ||
54
- sourceStats.isBlockDevice()
55
- ) {
56
- removeNonDirectory(
57
- sourceUrl.endsWith("/") ? sourceUrl.slice(0, -1) : sourceUrl,
58
- {
59
- maxRetries,
60
- retryDelay,
61
- },
62
- );
63
- } else if (sourceStats.isDirectory()) {
64
- const directoryUrl = ensurePathnameTrailingSlash(sourceUrl);
65
- removeDirectorySync(directoryUrl, {
66
- signal: removeOperation.signal,
67
- recursive,
39
+ // https://nodejs.org/dist/latest-v13.x/docs/api/fs.html#fs_class_fs_stats
40
+ // FIFO and socket are ignored, not sure what they are exactly and what to do with them
41
+ // other libraries ignore them, let's do the same.
42
+ if (
43
+ sourceStats.isFile() ||
44
+ sourceStats.isSymbolicLink() ||
45
+ sourceStats.isCharacterDevice() ||
46
+ sourceStats.isBlockDevice()
47
+ ) {
48
+ removeNonDirectory(
49
+ sourceUrl.endsWith("/") ? sourceUrl.slice(0, -1) : sourceUrl,
50
+ {
68
51
  maxRetries,
69
52
  retryDelay,
70
- onlyContent,
71
- });
72
- }
73
- } finally {
74
- removeOperation.end();
53
+ },
54
+ );
55
+ } else if (sourceStats.isDirectory()) {
56
+ const directoryUrl = ensurePathnameTrailingSlash(sourceUrl);
57
+ removeDirectorySync(directoryUrl, {
58
+ recursive,
59
+ maxRetries,
60
+ retryDelay,
61
+ onlyContent,
62
+ });
75
63
  }
76
64
  };
77
65
 
@@ -106,13 +94,9 @@ const unlinkSyncNaive = (sourcePath, { handleTemporaryError = null } = {}) => {
106
94
 
107
95
  const removeDirectorySync = (
108
96
  rootDirectoryUrl,
109
- { signal, maxRetries, retryDelay, recursive, onlyContent },
97
+ { maxRetries, retryDelay, recursive, onlyContent },
110
98
  ) => {
111
- const removeDirectoryOperation = Abort.startOperation();
112
- removeDirectoryOperation.addAbortSignal(signal);
113
-
114
99
  const visit = (sourceUrl) => {
115
- removeDirectoryOperation.throwIfAborted();
116
100
  const sourceStats = readEntryStatSync(sourceUrl, {
117
101
  nullIfNotFound: true,
118
102
  followLink: false,
@@ -146,7 +130,6 @@ const removeDirectorySync = (
146
130
  },
147
131
  }
148
132
  : {};
149
- removeDirectoryOperation.throwIfAborted();
150
133
  removeDirectorySyncNaive(directoryPath, {
151
134
  ...optionsFromRecursive,
152
135
  // Workaround for https://github.com/joyent/node/issues/4337
@@ -184,7 +167,6 @@ const removeDirectorySync = (
184
167
  };
185
168
 
186
169
  const removeDirectoryContent = (directoryUrl) => {
187
- removeDirectoryOperation.throwIfAborted();
188
170
  const entryNames = readdirSync(new URL(directoryUrl));
189
171
  for (const entryName of entryNames) {
190
172
  const url = resolveUrl(entryName, directoryUrl);
@@ -200,14 +182,10 @@ const removeDirectorySync = (
200
182
  removeNonDirectory(symbolicLinkUrl, { maxRetries, retryDelay });
201
183
  };
202
184
 
203
- try {
204
- if (onlyContent) {
205
- removeDirectoryContent(rootDirectoryUrl);
206
- } else {
207
- visitDirectory(rootDirectoryUrl);
208
- }
209
- } finally {
210
- removeDirectoryOperation.end();
185
+ if (onlyContent) {
186
+ removeDirectoryContent(rootDirectoryUrl);
187
+ } else {
188
+ visitDirectory(rootDirectoryUrl);
211
189
  }
212
190
  };
213
191