@jsenv/core 39.7.2 → 39.7.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.
Files changed (2) hide show
  1. package/dist/jsenv_core.js +24 -0
  2. package/package.json +2 -2
@@ -3906,6 +3906,24 @@ const ensureEmptyDirectory = async (source) => {
3906
3906
  );
3907
3907
  };
3908
3908
 
3909
+ const callOnceIdlePerFile = (callback, idleMs) => {
3910
+ const timeoutIdMap = new Map();
3911
+ return (fileEvent) => {
3912
+ const { relativeUrl } = fileEvent;
3913
+ let timeoutId = timeoutIdMap.get(relativeUrl);
3914
+ if (timeoutId) {
3915
+ clearTimeout(timeoutId);
3916
+ }
3917
+ timeoutId = setTimeout(() => {
3918
+ callback(fileEvent);
3919
+ }, idleMs);
3920
+ if (timeoutId.unref) {
3921
+ timeoutId.unref();
3922
+ }
3923
+ timeoutIdMap.set(relativeUrl, timeoutId);
3924
+ };
3925
+ };
3926
+
3909
3927
  const isWindows = process.platform === "win32";
3910
3928
 
3911
3929
  const createWatcher = (sourcePath, options) => {
@@ -4001,6 +4019,7 @@ const registerDirectoryLifecycle = (
4001
4019
  // For this reason"cooldownBetweenFileEvents" should be reserved to scenarios
4002
4020
  // like unit tests
4003
4021
  cooldownBetweenFileEvents = 0,
4022
+ idleMs = 50,
4004
4023
  },
4005
4024
  ) => {
4006
4025
  const sourceUrl = assertAndNormalizeDirectoryUrl(source);
@@ -4017,6 +4036,11 @@ const registerDirectoryLifecycle = (
4017
4036
  `removed must be a function or undefined, got ${removed}`,
4018
4037
  );
4019
4038
  }
4039
+ if (idleMs) {
4040
+ if (updated) {
4041
+ updated = callOnceIdlePerFile(updated, idleMs);
4042
+ }
4043
+ }
4020
4044
  if (cooldownBetweenFileEvents) {
4021
4045
  if (added) {
4022
4046
  added = guardTooFastSecondCallPerFile(added, cooldownBetweenFileEvents);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "39.7.2",
3
+ "version": "39.7.3",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -70,7 +70,7 @@
70
70
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
71
71
  "@jsenv/abort": "4.3.0",
72
72
  "@jsenv/ast": "6.4.0",
73
- "@jsenv/filesystem": "4.10.13",
73
+ "@jsenv/filesystem": "4.11.0",
74
74
  "@jsenv/humanize": "1.2.8",
75
75
  "@jsenv/importmap": "1.2.1",
76
76
  "@jsenv/integrity": "0.0.2",