Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lix-js/fs

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lix-js/fs - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

2

dist/index.d.ts
export type { NodeishFilesystem } from "./NodeishFilesystemApi.js";
export { createNodeishMemoryFs, toSnapshot, fromSnapshot } from "./memoryFs.js";
export { createNodeishMemoryFs, toSnapshot, fromSnapshot, type Snapshot } from "./memoryFs.js";
export { normalizePath, normalPath, // FIXME: unify with normalizePath
getBasename, getDirname, assertIsAbsolutePath, } from "./utilities/helpers.js";
//# sourceMappingURL=index.d.ts.map
import type { NodeishFilesystem } from "./NodeishFilesystemApi.js";
export type Snapshot = {
fsMap: {
[key: string]: string[] | string;
};
fsStats: {
[key: string]: {
ctimeMs: number;
mtimeMs: number;
dev: number;
mode: number;
uid: number;
gid: number;
size: number;
_kind: number;
};
};
};
export declare function toSnapshot(fs: NodeishFilesystem): {

@@ -9,4 +26,6 @@ fsMap: any;

fsStats: any;
}, { pathPrefix }?: {
pathPrefix?: string | undefined;
}): void;
export declare function createNodeishMemoryFs(): NodeishFilesystem;
//# sourceMappingURL=memoryFs.d.ts.map

@@ -33,3 +33,4 @@ import { FilesystemError } from "./errors/FilesystemError.js";

}
export function fromSnapshot(fs, snapshot) {
export function fromSnapshot(fs, snapshot, { pathPrefix = "" } = {}) {
// TODO: windows withothout repo will hang tests. fix this with windows vm¯
fs._state.lastIno = 1;

@@ -43,5 +44,5 @@ fs._state.fsMap = new Map(

// new TextEncoder().encode(decodeURIComponent(escape(atob(content)))) Buffer.from()
return [path, data];
return [pathPrefix + path, data];
}
return [path, new Set(content)];
return [pathPrefix + path, new Set(content)];
}));

@@ -57,4 +58,13 @@ fs._state.fsStats = new Map(Object.entries(snapshot.fsStats).map(([path, rawStat]) => {

};
return [path, statsObj];
return [pathPrefix + path, statsObj];
}));
if (pathPrefix) {
const prefixParts = pathPrefix.split("/");
const rootStat = fs._state.fsStats.get(pathPrefix + "/");
for (let i = 1; i < prefixParts.length; i++) {
const path = prefixParts.slice(0, i).join("/") + "/";
fs._state.fsMap.set(path, new Set([prefixParts[i]]));
fs._state.fsStats.set(path, rootStat);
}
}
}

@@ -61,0 +71,0 @@ export function createNodeishMemoryFs() {

{
"name": "@lix-js/fs",
"version": "0.5.0",
"version": "0.6.0",
"type": "module",

@@ -5,0 +5,0 @@ "publishConfig": {

@@ -5,3 +5,3 @@ # @lix-js/fs

1. Use NodeJS 20 `fs.promises` API for the interface. See https://github.com/inlang/monorepo/pull/600#discussion_r1180103042.
2. Never use `any` in the filesystem interface. See https://github.com/inlang/monorepo/pull/600#discussion_r1180090230.
1. Use NodeJS 20 `fs.promises` API for the interface. See https://github.com/opral/monorepo/pull/600#discussion_r1180103042.
2. Never use `any` in the filesystem interface. See https://github.com/opral/monorepo/pull/600#discussion_r1180090230.

@@ -38,3 +38,3 @@ import { test, expect, afterAll, describe } from "vitest"

) => {
// testing characters is important. see bug https://github.com/inlang/monorepo/issues/785
// testing characters is important. see bug https://github.com/opral/monorepo/issues/785
const textInFirstFile = `

@@ -41,0 +41,0 @@ Testing a variety of characters.

export type { NodeishFilesystem } from "./NodeishFilesystemApi.js"
export { createNodeishMemoryFs, toSnapshot, fromSnapshot } from "./memoryFs.js"
export { createNodeishMemoryFs, toSnapshot, fromSnapshot, type Snapshot } from "./memoryFs.js"
export {

@@ -4,0 +4,0 @@ normalizePath,

@@ -7,2 +7,20 @@ import type { NodeishFilesystem, NodeishStats, FileChangeInfo } from "./NodeishFilesystemApi.js"

export type Snapshot = {
fsMap: {
[key: string]: string[] | string
}
fsStats: {
[key: string]: {
ctimeMs: number
mtimeMs: number
dev: number
mode: number
uid: number
gid: number
size: number
_kind: number
}
}
}
export function toSnapshot(fs: NodeishFilesystem) {

@@ -44,3 +62,9 @@ return {

export function fromSnapshot(fs: NodeishFilesystem, snapshot: { fsMap: any; fsStats: any }) {
export function fromSnapshot(
fs: NodeishFilesystem,
snapshot: { fsMap: any; fsStats: any },
{ pathPrefix = "" } = {}
) {
// TODO: windows withothout repo will hang tests. fix this with windows vm¯
fs._state.lastIno = 1

@@ -54,8 +78,9 @@ fs._state.fsMap = new Map(

// new TextEncoder().encode(decodeURIComponent(escape(atob(content)))) Buffer.from()
return [path, data]
return [pathPrefix + path, data]
}
return [path, new Set(content as string[])]
return [pathPrefix + path, new Set(content as string[])]
})
)
fs._state.fsStats = new Map(

@@ -76,5 +101,17 @@ Object.entries(snapshot.fsStats).map(([path, rawStat]) => {

return [path, statsObj]
return [pathPrefix + path, statsObj]
})
)
if (pathPrefix) {
const prefixParts = pathPrefix.split("/")
const rootStat = fs._state.fsStats.get(pathPrefix + "/")
for (let i = 1; i < prefixParts.length; i++) {
const path = prefixParts.slice(0, i).join("/") + "/"
fs._state.fsMap.set(path, new Set([prefixParts[i]]))
fs._state.fsStats.set(path, rootStat)
}
}
}

@@ -81,0 +118,0 @@

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