Socket
Socket
Sign inDemoInstall

@file-services/memory

Package Overview
Dependencies
Maintainers
4
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@file-services/memory - npm Package Compare versions

Comparing version 9.1.0 to 9.2.0

2

dist/memory-fs.d.ts

@@ -1,2 +0,2 @@

import { IDirectoryContents } from "@file-services/types";
import { type IDirectoryContents } from "@file-services/types";
import type { IBaseMemFileSystem, IBaseMemFileSystemSync, IMemFileSystem } from "./types";

@@ -3,0 +3,0 @@ /**

{
"name": "@file-services/memory",
"description": "An in-memory, sync/async, file system implementation.",
"version": "9.1.0",
"version": "9.2.0",
"main": "./dist/fs-memory.cjs",

@@ -21,5 +21,5 @@ "types": "./dist/index.d.ts",

"dependencies": {
"@file-services/path": "^9.1.0",
"@file-services/types": "^9.1.0",
"@file-services/utils": "^9.1.0"
"@file-services/path": "^9.2.0",
"@file-services/types": "^9.2.0",
"@file-services/utils": "^9.2.0"
},

@@ -26,0 +26,0 @@ "files": [

import path from "@file-services/path";
import {
BufferEncoding,
FileSystemConstants,
IDirectoryContents,
IDirectoryEntry,
IFileSystemStats,
IWatchEvent,
RmOptions,
StatSyncOptions,
WatchEventListener,
type BufferEncoding,
type IDirectoryContents,
type IDirectoryEntry,
type IFileSystemStats,
type IWatchEvent,
type ReadFileOptions,
type RmOptions,
type StatSyncOptions,
type WatchEventListener,
type WatchChangeEventListener,
} from "@file-services/types";

@@ -64,2 +65,5 @@ import { SetMultiMap, createFileSystem, syncToAsyncFs } from "@file-services/utils";

const root: IFsMemDirectoryNode = createMemDirectory("memory-fs-root");
const changeListeners = new SetMultiMap<string, WatchChangeEventListener>();
const recursiveChangeListeners = new SetMultiMap<string, WatchChangeEventListener>();
const closeListeners = new SetMultiMap<string, () => void>();
const pathListeners = new SetMultiMap<string, WatchEventListener>();

@@ -122,2 +126,37 @@ const globalListeners = new Set<WatchEventListener>();

chmodSync: () => undefined,
watch: (path, options) => {
const recursive = options?.recursive;
return {
close() {
const listeners = closeListeners.get(path);
if (listeners) {
for (const listener of listeners) {
listener();
}
closeListeners.deleteKey(path);
}
},
on(event, listener) {
if (event === "change") {
if (recursive) {
recursiveChangeListeners.add(path, listener as WatchChangeEventListener);
} else {
changeListeners.add(path, listener as WatchChangeEventListener);
}
} else if (event === "close") {
closeListeners.add(path, listener as () => void);
}
return this;
},
off(event, listener) {
if (event === "change") {
changeListeners.delete(path, listener as WatchChangeEventListener);
recursiveChangeListeners.delete(path, listener as WatchChangeEventListener);
} else if (event === "close") {
closeListeners.delete(path, listener as () => void);
}
return this;
},
};
},
};

@@ -179,2 +218,3 @@

emitWatchEvent({ path: resolvedPath, stats: existingNode.entry });
emitChangeEvent("change", resolvedPath);
} else {

@@ -204,2 +244,3 @@ const parentPath = posixPath.dirname(resolvedPath);

emitWatchEvent({ path: resolvedPath, stats: newFileNode.entry });
emitChangeEvent("rename", resolvedPath);
}

@@ -228,2 +269,3 @@ }

emitWatchEvent({ path: resolvedPath, stats: null });
emitChangeEvent("rename", resolvedPath);
}

@@ -293,2 +335,3 @@

emitWatchEvent({ path: resolvedPath, stats: newDirNode.entry });
emitChangeEvent("rename", resolvedPath);
}

@@ -316,2 +359,3 @@

emitWatchEvent({ path: resolvedPath, stats: null });
emitChangeEvent("rename", resolvedPath);
}

@@ -348,2 +392,3 @@

emitWatchEvent({ path: resolvedPath, stats: null });
emitChangeEvent("rename", resolvedPath);
}

@@ -475,2 +520,4 @@

emitWatchEvent({ path: resolvedDestinationPath, stats: sourceNode.entry });
emitChangeEvent("rename", resolvedSourcePath);
emitChangeEvent("rename", resolvedDestinationPath);
}

@@ -520,2 +567,3 @@

emitWatchEvent({ path: resolvedDestinationPath, stats: newFileNode.entry });
emitChangeEvent("rename", resolvedDestinationPath);
}

@@ -555,2 +603,3 @@

emitWatchEvent({ path: resolvedLinkPath, stats: symlinkNode.entry });
emitChangeEvent("rename", resolvedLinkPath);
}

@@ -592,2 +641,29 @@

function emitChangeEvent(type: "change" | "rename", changedPath: string): void {
const listenersOnPath = changeListeners.get(changedPath);
if (listenersOnPath) {
for (const listener of listenersOnPath) {
listener(type, posixPath.relative("/", changedPath));
}
}
const parentPath = posixPath.dirname(changedPath);
const baseName = posixPath.basename(changedPath);
const listenersOnParent = changeListeners.get(parentPath);
if (listenersOnParent) {
for (const listener of listenersOnParent) {
listener(type, baseName);
}
}
for (const watchedPath of recursiveChangeListeners.keys()) {
const watchedWithSep = watchedPath.endsWith("/") ? watchedPath : watchedPath + posixPath.sep;
if (changedPath === watchedPath || changedPath.startsWith(watchedWithSep)) {
const listeners = recursiveChangeListeners.get(watchedPath)!;
for (const listener of listeners) {
listener(type, posixPath.relative(watchedPath, changedPath));
}
}
}
}
function emitWatchEvent(watchEvent: IWatchEvent): void {

@@ -594,0 +670,0 @@ for (const listener of globalListeners) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc