@jsenv/filesystem 4.7.4 → 4.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/filesystem",
3
- "version": "4.7.4",
3
+ "version": "4.8.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,8 +12,7 @@
12
12
  },
13
13
  "author": {
14
14
  "name": "dmail",
15
- "email": "dmaillard06@gmail.com",
16
- "url": "https://twitter.com/damienmaillard"
15
+ "email": "dmaillard06@gmail.com"
17
16
  },
18
17
  "type": "module",
19
18
  "engines": {
@@ -32,7 +31,7 @@
32
31
  "test": "node --conditions=development ./scripts/test.mjs"
33
32
  },
34
33
  "dependencies": {
35
- "@jsenv/urls": "2.2.9",
34
+ "@jsenv/urls": "2.2.11",
36
35
  "@jsenv/url-meta": "8.4.2",
37
36
  "@jsenv/abort": "4.3.0",
38
37
  "@jsenv/utils": "2.1.1"
@@ -65,7 +65,6 @@ export const collectFiles = async ({
65
65
  associations,
66
66
  });
67
67
  if (!predicate(meta)) return;
68
-
69
68
  const relativeUrl = urlToRelativeUrl(
70
69
  directoryChildNodeUrl,
71
70
  rootDirectoryUrl,
@@ -10,7 +10,8 @@ export const visitStructureSync = ({
10
10
  directoryUrl,
11
11
  associations,
12
12
  predicate,
13
- callback = () => {},
13
+ onDirectory = () => {},
14
+ onMatch = () => {},
14
15
  }) => {
15
16
  const rootDirectoryUrl = assertAndNormalizeDirectoryUrl(directoryUrl);
16
17
  if (typeof predicate !== "function") {
@@ -20,6 +21,7 @@ export const visitStructureSync = ({
20
21
  const matchingFileResultArray = [];
21
22
  const visitDirectory = (directoryUrl) => {
22
23
  const directoryItems = readDirectorySync(directoryUrl);
24
+ const matchingFileInfoArray = [];
23
25
  for (const directoryItem of directoryItems) {
24
26
  const directoryChildNodeUrl = `${directoryUrl}${directoryItem}`;
25
27
  let directoryChildNodeStats;
@@ -50,7 +52,7 @@ export const visitStructureSync = ({
50
52
  ) {
51
53
  continue;
52
54
  }
53
- callback({
55
+ onDirectory({
54
56
  url: subDirectoryUrl,
55
57
  relativeUrl: urlToRelativeUrl(subDirectoryUrl, rootDirectoryUrl),
56
58
  stats: directoryChildNodeStats,
@@ -77,15 +79,26 @@ export const visitStructureSync = ({
77
79
  meta,
78
80
  fileStats: directoryChildNodeStats,
79
81
  });
80
- callback({
82
+ matchingFileInfoArray.push({
81
83
  url: directoryChildNodeUrl,
82
84
  relativeUrl,
83
85
  stats: directoryChildNodeStats,
84
- isDirectory: false,
85
86
  });
86
87
  continue;
87
88
  }
88
89
  }
90
+ let i = 0;
91
+ while (i < matchingFileInfoArray.length) {
92
+ const matchingFileInfo = matchingFileInfoArray[i];
93
+ onMatch(matchingFileInfo, {
94
+ prev: i === 0 ? null : matchingFileInfoArray[i - 1],
95
+ next:
96
+ i === matchingFileInfoArray.length - 1
97
+ ? null
98
+ : matchingFileInfoArray[i + 1],
99
+ });
100
+ i++;
101
+ }
89
102
  };
90
103
  visitDirectory(rootDirectoryUrl);
91
104
  // When we operate on thoose files later it feels more natural
package/src/main.js CHANGED
@@ -80,6 +80,9 @@ export { removeDirectorySync } from "./remove/remove_directory_sync.js";
80
80
  export { removeFileSync } from "./remove/remove_file_sync.js";
81
81
  export { removeEntrySync } from "./remove/remove_entry_sync.js";
82
82
 
83
+ // replace
84
+ export { replaceFileSync } from "./replace/replace_file_sync.js";
85
+
83
86
  // lifecycle
84
87
  export { registerDirectoryLifecycle } from "./lifecycle/register_directory_lifecycle.js";
85
88
  export { registerFileLifecycle } from "./lifecycle/register_file_lifecycle.js";
@@ -0,0 +1,8 @@
1
+ import { copyEntrySync } from "../copy/copy_entry_sync.js";
2
+
3
+ export const replaceFileSync = (from, to) =>
4
+ copyEntrySync({
5
+ from,
6
+ to,
7
+ overwrite: true,
8
+ });