@jsenv/filesystem 4.12.0 → 4.13.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/package.json
CHANGED
|
@@ -339,7 +339,8 @@ export const registerDirectoryLifecycle = (
|
|
|
339
339
|
}
|
|
340
340
|
};
|
|
341
341
|
|
|
342
|
-
readdirSync(new URL(sourceUrl))
|
|
342
|
+
const entries = readdirSync(new URL(sourceUrl));
|
|
343
|
+
for (const entry of entries) {
|
|
343
344
|
const entryUrl = new URL(entry, sourceUrl).href;
|
|
344
345
|
const entryInfo = readEntryInfo(entryUrl);
|
|
345
346
|
if (entryInfo.type !== null && entryInfo.patternValue) {
|
|
@@ -347,7 +348,7 @@ export const registerDirectoryLifecycle = (
|
|
|
347
348
|
notify: notifyExistent,
|
|
348
349
|
});
|
|
349
350
|
}
|
|
350
|
-
}
|
|
351
|
+
}
|
|
351
352
|
if (debug) {
|
|
352
353
|
const relativeUrls = Array.from(infoMap.keys());
|
|
353
354
|
if (relativeUrls.length === 0) {
|
|
@@ -381,11 +382,11 @@ const shouldCallUpdated = (entryInfo) => {
|
|
|
381
382
|
if (!stat.atimeMs) {
|
|
382
383
|
return true;
|
|
383
384
|
}
|
|
384
|
-
if (stat.atimeMs
|
|
385
|
+
if (stat.atimeMs <= stat.mtimeMs) {
|
|
385
386
|
return true;
|
|
386
387
|
}
|
|
387
|
-
if (
|
|
388
|
-
return
|
|
388
|
+
if (stat.mtimeMs !== previousInfo.stat.mtimeMs) {
|
|
389
|
+
return true;
|
|
389
390
|
}
|
|
390
391
|
return true;
|
|
391
392
|
};
|
|
@@ -8,6 +8,10 @@ import { createWatcher } from "./create_watcher.js";
|
|
|
8
8
|
import { guardTooFastSecondCall } from "./guard_second_call.js";
|
|
9
9
|
import { trackResources } from "./track_resources.js";
|
|
10
10
|
|
|
11
|
+
const isMacos = process.platform === "darwin";
|
|
12
|
+
const isLinux = process.platform === "linux";
|
|
13
|
+
const isFreeBSD = process.platform === "freebsd";
|
|
14
|
+
|
|
11
15
|
export const registerFileLifecycle = (
|
|
12
16
|
source,
|
|
13
17
|
{
|
|
@@ -171,16 +175,13 @@ const watchFileMutation = (
|
|
|
171
175
|
{ updated, removed, keepProcessAlive, stat },
|
|
172
176
|
) => {
|
|
173
177
|
let prevStat = stat;
|
|
174
|
-
let watcher
|
|
175
|
-
persistent: keepProcessAlive,
|
|
176
|
-
});
|
|
178
|
+
let watcher;
|
|
177
179
|
|
|
178
|
-
|
|
180
|
+
const onChange = () => {
|
|
179
181
|
const { type, stat } = readFileInfo(sourceUrl);
|
|
180
182
|
|
|
181
183
|
if (type === null) {
|
|
182
|
-
|
|
183
|
-
watcher = undefined;
|
|
184
|
+
stopWatching();
|
|
184
185
|
if (removed) {
|
|
185
186
|
removed();
|
|
186
187
|
}
|
|
@@ -188,25 +189,38 @@ const watchFileMutation = (
|
|
|
188
189
|
if (updated && shouldCallUpdated(stat, prevStat)) {
|
|
189
190
|
updated();
|
|
190
191
|
}
|
|
192
|
+
if ((isMacos || isLinux || isFreeBSD) && prevStat.ino !== stat.ino) {
|
|
193
|
+
stopWatching();
|
|
194
|
+
watch();
|
|
195
|
+
}
|
|
191
196
|
}
|
|
192
197
|
prevStat = stat;
|
|
193
|
-
}
|
|
198
|
+
};
|
|
194
199
|
|
|
195
|
-
|
|
200
|
+
const watch = () => {
|
|
201
|
+
watcher = createWatcher(urlToFileSystemPath(sourceUrl), {
|
|
202
|
+
persistent: keepProcessAlive,
|
|
203
|
+
});
|
|
204
|
+
watcher.on("change", onChange);
|
|
205
|
+
};
|
|
206
|
+
const stopWatching = () => {
|
|
196
207
|
if (watcher) {
|
|
197
208
|
watcher.close();
|
|
209
|
+
watcher = undefined;
|
|
198
210
|
}
|
|
199
211
|
};
|
|
212
|
+
watch();
|
|
213
|
+
return stopWatching;
|
|
200
214
|
};
|
|
201
215
|
|
|
202
216
|
const shouldCallUpdated = (stat, prevStat) => {
|
|
203
217
|
if (!stat.atimeMs) {
|
|
204
218
|
return true;
|
|
205
219
|
}
|
|
206
|
-
if (stat.atimeMs
|
|
220
|
+
if (stat.atimeMs <= stat.mtimeMs) {
|
|
207
221
|
return true;
|
|
208
222
|
}
|
|
209
|
-
if (stat.mtimeMs
|
|
223
|
+
if (stat.mtimeMs !== prevStat.mtimeMs) {
|
|
210
224
|
return true;
|
|
211
225
|
}
|
|
212
226
|
return false;
|
|
@@ -43,6 +43,7 @@ export const writeDirectorySync = (
|
|
|
43
43
|
.slice(0, -1),
|
|
44
44
|
),
|
|
45
45
|
);
|
|
46
|
+
destinationStats = null;
|
|
46
47
|
} else {
|
|
47
48
|
throw new Error(
|
|
48
49
|
`cannot write directory at ${destinationPath} because there is a file at ${urlToFileSystemPath(
|
|
@@ -62,10 +63,14 @@ export const writeDirectorySync = (
|
|
|
62
63
|
}
|
|
63
64
|
throw new Error(`directory already exists at ${destinationPath}`);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
if (force) {
|
|
67
|
+
unlinkSync(destinationPath);
|
|
68
|
+
} else {
|
|
69
|
+
const destinationType = statsToType(destinationStats);
|
|
70
|
+
throw new Error(
|
|
71
|
+
`cannot write directory at ${destinationPath} because there is a ${destinationType}`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
try {
|