@mizchi/bit 0.43.2 → 0.49.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/lib.js CHANGED
@@ -131,7 +131,8 @@ const isBackendObject = (value) => (
131
131
  typeof value.readFile === "function" &&
132
132
  typeof value.readdir === "function" &&
133
133
  typeof value.isDir === "function" &&
134
- typeof value.isFile === "function"
134
+ typeof value.isFile === "function" &&
135
+ typeof value.mtime === "function"
135
136
  );
136
137
 
137
138
  const isTransportObject = (value) => (
@@ -509,6 +510,7 @@ const createMemoryBackendImpl = () => {
509
510
  const encoder = new TextEncoder();
510
511
  const decoder = new TextDecoder();
511
512
  const files = new Map();
513
+ const mtimes = new Map();
512
514
  const dirs = new Set(["/"]);
513
515
 
514
516
  const normalizePath = (path) => {
@@ -557,6 +559,11 @@ const createMemoryBackendImpl = () => {
557
559
  const normalized = normalizePath(path);
558
560
  ensureDirs(parentDir(normalized));
559
561
  files.set(normalized, Uint8Array.from(content));
562
+ const now = Date.now();
563
+ mtimes.set(normalized, [
564
+ Math.floor(now / 1000),
565
+ (now % 1000) * 1_000_000,
566
+ ]);
560
567
  },
561
568
  writeString(path, content) {
562
569
  this.writeFile(path, encoder.encode(String(content)));
@@ -566,6 +573,7 @@ const createMemoryBackendImpl = () => {
566
573
  if (!files.delete(normalized)) {
567
574
  throw new Error(`File not found: ${normalized}`);
568
575
  }
576
+ mtimes.delete(normalized);
569
577
  },
570
578
  removeDir(path) {
571
579
  const normalized = normalizePath(path);
@@ -616,6 +624,14 @@ const createMemoryBackendImpl = () => {
616
624
  isFile(path) {
617
625
  return files.has(normalizePath(path));
618
626
  },
627
+ mtime(path) {
628
+ const normalized = normalizePath(path);
629
+ const value = mtimes.get(normalized);
630
+ if (!value) {
631
+ throw new Error(`File not found: ${normalized}`);
632
+ }
633
+ return value;
634
+ },
619
635
  readString(path) {
620
636
  return decoder.decode(this.readFile(path));
621
637
  },