@lix-js/fs
Advanced tools
Comparing version 0.5.0 to 0.6.0
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
66331
1636
0