@layerzerolabs/deterministic-zip 4.0.8 → 4.0.10
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,8DAA8D;AAC9D,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjE,oBAAY,YAAY;IACpB,IAAI,SAAS;IACb,SAAS,cAAc;CAC1B;AAED,MAAM,WAAW,YAAY;IACzB,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAChC,mEAAmE;IACnE,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,sDAAsD;IACtD,KAAK,CAAC,EAAE,IAAI,CAAC;IACb;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,8DAA8D;AAC9D,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjE,oBAAY,YAAY;IACpB,IAAI,SAAS;IACb,SAAS,cAAc;CAC1B;AAED,MAAM,WAAW,YAAY;IACzB,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAChC,mEAAmE;IACnE,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,sDAAsD;IACtD,KAAK,CAAC,EAAE,IAAI,CAAC;IACb;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,MAAiC,CAAC;AA6D9E;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,cACtB,MAAM,YACP,mBAAmB,KAC9B,OAAO,CAAC,UAAU,CAqBpB,CAAC;AAEF,eAAO,MAAM,oBAAoB,cAClB,MAAM,YACP,mBAAmB,KAC9B,OAAO,CAAC,MAAM,CAAoE,CAAC;AAEtF,eAAO,MAAM,oBAAoB,cAClB,MAAM,YACP,mBAAmB,KAC9B,OAAO,CAAC,MAAM,CAAwE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -59,10 +59,18 @@ var collectSortedEntries = /* @__PURE__ */ __name(async (root, includeEntry) =>
|
|
|
59
59
|
return omitEmptyDirectories(zipEntries).sort((a, b) => a.relPath < b.relPath ? -1 : a.relPath > b.relPath ? 1 : 0);
|
|
60
60
|
}, "collectSortedEntries");
|
|
61
61
|
var zipDirectoryToUint8Array = /* @__PURE__ */ __name(async (sourceDir, options) => {
|
|
62
|
-
const
|
|
62
|
+
const predicate = options?.pathInclusionPredicate ?? INCLUDE_EVERYTHING;
|
|
63
|
+
const prefix = options?.rootName === void 0 ? "" : `${options.rootName}/`;
|
|
64
|
+
const entries = await collectSortedEntries(sourceDir, (entry) => predicate({
|
|
65
|
+
...entry,
|
|
66
|
+
relPath: `${prefix}${entry.relPath}`
|
|
67
|
+
}));
|
|
63
68
|
const fileMap = {};
|
|
69
|
+
if (prefix !== "" && entries.length > 0) {
|
|
70
|
+
fileMap[prefix] = new Uint8Array(0);
|
|
71
|
+
}
|
|
64
72
|
for (const entry of entries) {
|
|
65
|
-
fileMap[entry.relPath] = entry.isDirectory ? new Uint8Array(0) : new Uint8Array(await fs.readFile(path.join(sourceDir, entry.relPath)));
|
|
73
|
+
fileMap[`${prefix}${entry.relPath}`] = entry.isDirectory ? new Uint8Array(0) : new Uint8Array(await fs.readFile(path.join(sourceDir, entry.relPath)));
|
|
66
74
|
}
|
|
67
75
|
return zipSync(fileMap, {
|
|
68
76
|
level: options?.level ?? 6,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["ZipEntryType","DEFAULT_DETERMINISTIC_ZIP_MTIME","Date","INCLUDE_EVERYTHING","omitEmptyDirectories","entries","dirsWithFiles","Set","entry","isDirectory","dir","path","posix","dirname","relPath","add","filter","has","collectSortedEntries","root","includeEntry","zipEntries","walk","rel","fs","readdir","join","withFileTypes","childRel","name","type","push","isFile","isSymbolicLink","Error","sort","a","b","zipDirectoryToUint8Array","sourceDir","options","pathInclusionPredicate","fileMap","Uint8Array","readFile","zipSync","level","mtime","zipDirectoryToBuffer","Buffer","from","zipDirectoryToBase64","toString"],"mappings":";;;;;;AAOO,IAAKA,YAAAA,6BAAAA,aAAAA,EAAAA;;;AAAAA,EAAAA,OAAAA,aAAAA;;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["ZipEntryType","DEFAULT_DETERMINISTIC_ZIP_MTIME","Date","INCLUDE_EVERYTHING","omitEmptyDirectories","entries","dirsWithFiles","Set","entry","isDirectory","dir","path","posix","dirname","relPath","add","filter","has","collectSortedEntries","root","includeEntry","zipEntries","walk","rel","fs","readdir","join","withFileTypes","childRel","name","type","push","isFile","isSymbolicLink","Error","sort","a","b","zipDirectoryToUint8Array","sourceDir","options","predicate","pathInclusionPredicate","prefix","rootName","undefined","fileMap","length","Uint8Array","readFile","zipSync","level","mtime","zipDirectoryToBuffer","Buffer","from","zipDirectoryToBase64","toString"],"mappings":";;;;;;AAOO,IAAKA,YAAAA,6BAAAA,aAAAA,EAAAA;;;AAAAA,EAAAA,OAAAA,aAAAA;;AAmCL,IAAMC,+BAAAA,GAAkC,IAAIC,IAAAA,CAAK,IAAA,EAAM,GAAG,EAAA,EAAI,CAAA,EAAG,GAAG,CAAA;AAE3E,IAAMC,kBAAAA,gCAAmD,IAAA,EAAN,oBAAA,CAAA;AAQnD,IAAMC,oBAAAA,2BAAwBC,OAAAA,KAAAA;AAC1B,EAAA,MAAMC,aAAAA,uBAAoBC,GAAAA,EAAAA;AAC1B,EAAA,KAAA,MAAWC,SAASH,OAAAA,EAAS;AACzB,IAAA,IAAIG,MAAMC,WAAAA,EAAa;AACvB,IAAA,IAAIC,GAAAA,GAAMC,IAAAA,CAAKC,KAAAA,CAAMC,OAAAA,CAAQL,MAAMM,OAAO,CAAA;AAC1C,IAAA,OAAOJ,GAAAA,KAAQ,EAAA,IAAMA,GAAAA,KAAQ,GAAA,EAAK;AAC9BJ,MAAAA,aAAAA,CAAcS,GAAAA,CAAI,CAAA,EAAGL,GAAAA,CAAAA,CAAAA,CAAM,CAAA;AAC3BA,MAAAA,GAAAA,GAAMC,IAAAA,CAAKC,KAAAA,CAAMC,OAAAA,CAAQH,GAAAA,CAAAA;AAC7B,IAAA;AACJ,EAAA;AACA,EAAA,OAAOL,OAAAA,CAAQW,MAAAA,CAAO,CAACR,KAAAA,KAAU,CAACA,KAAAA,CAAMC,WAAAA,IAAeH,aAAAA,CAAcW,GAAAA,CAAIT,KAAAA,CAAMM,OAAO,CAAA,CAAA;AAC1F,CAAA,EAX6B,sBAAA,CAAA;AAqB7B,IAAMI,oBAAAA,mBAAuB,MAAA,CAAA,OACzBC,IAAAA,EACAC,YAAAA,KAAAA;AA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CAAA,IACf,IAAIA,UAAAA,CAAW,MAAMxB,EAAAA,CAAGyB,QAAAA,CAAStC,IAAAA,CAAKe,KAAKa,SAAAA,EAAW/B,KAAAA,CAAMM,OAAO,CAAA,CAAA,CAAA;AAC7E,EAAA;AAEA,EAAA,OAAOoC,QAAQJ,OAAAA,EAAS;AACpBK,IAAAA,KAAAA,EAAOX,SAASW,KAAAA,IAAS,CAAA;AACzBC,IAAAA,KAAAA,EAAOZ,SAASY,KAAAA,IAASnD;GAC7B,CAAA;AACJ,CAAA,EAxBwC,0BAAA;AA0BjC,IAAMoD,oBAAAA,mBAAuB,MAAA,CAAA,OAChCd,SAAAA,EACAC,OAAAA,KACkBc,MAAAA,CAAOC,IAAAA,CAAK,MAAMjB,wBAAAA,CAAyBC,SAAAA,EAAWC,OAAAA,CAAAA,CAAAA,EAHxC,sBAAA;AAK7B,IAAMgB,oBAAAA,mBAAuB,MAAA,CAAA,OAChCjB,SAAAA,EACAC,OAAAA,KAAAA,CACmB,MAAMa,oBAAAA,CAAqBd,SAAAA,EAAWC,OAAAA,CAAAA,EAAUiB,QAAAA,CAAS,QAAA,CAAA,EAH5C,sBAAA","file":"index.js","sourcesContent":["import { type Zippable, zipSync } from 'fflate';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\n/** fflate deflate compression levels (0 = store, 9 = max). */\nexport type DeflateLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;\n\nexport enum ZipEntryType {\n File = 'file',\n Directory = 'directory',\n}\n\nexport interface ZipEntryInfo {\n /** POSIX-relative path from the zip root, no trailing slash. */\n relPath: string;\n type: ZipEntryType;\n}\n\nexport type PathInclusionPredicate = (entry: ZipEntryInfo) => boolean;\n\nexport interface ZipDirectoryOptions {\n /** Deflate compression level passed to fflate. Defaults to `6`. */\n level?: DeflateLevel;\n /** Modification time stamped onto every ZIP entry. */\n mtime?: Date;\n /**\n * Called for every file and directory. Return `false` to drop the entry;\n * `false` on a directory prunes its entire subtree (children are never\n * visited). Omitted = include everything.\n *\n * Symlinks are not supported and always throw.\n */\n pathInclusionPredicate?: PathInclusionPredicate;\n rootName?: string;\n}\n\n/**\n * Fixed modification time stamped onto every archive entry.\n *\n * fflate writes ZIP timestamps from local date fields, so this value is built\n * with local fields to keep the encoded timestamp stable across timezones.\n */\nexport const DEFAULT_DETERMINISTIC_ZIP_MTIME = new Date(2026, 5, 15, 0, 0, 0);\n\nconst INCLUDE_EVERYTHING: PathInclusionPredicate = () => true;\n\ntype DeterministicZipEntry = { relPath: string; isDirectory: boolean };\n\n/**\n * Drop directory entries that have no included descendant file. Empty dirs (or dirs whose files\n * were all filtered out) must not affect archive bytes / hashes.\n */\nconst omitEmptyDirectories = (entries: DeterministicZipEntry[]): DeterministicZipEntry[] => {\n const dirsWithFiles = new Set<string>();\n for (const entry of entries) {\n if (entry.isDirectory) continue;\n let dir = path.posix.dirname(entry.relPath);\n while (dir !== '' && dir !== '.') {\n dirsWithFiles.add(`${dir}/`);\n dir = path.posix.dirname(dir);\n }\n }\n return entries.filter((entry) => !entry.isDirectory || dirsWithFiles.has(entry.relPath));\n};\n\n/**\n * Recursively collect every included file and directory under `root`, sorted\n * by POSIX-relative path (UTF-16 code unit order). Directories with no included\n * child files are omitted.\n *\n * Filesystem `readdir` order varies by platform, so sorting is required for\n * reproducible archives.\n */\nconst collectSortedEntries = async (\n root: string,\n includeEntry: PathInclusionPredicate,\n): Promise<DeterministicZipEntry[]> => {\n const zipEntries: DeterministicZipEntry[] = [];\n\n const walk = async (rel: string): Promise<void> => {\n const entries = await fs.readdir(path.join(root, rel), { withFileTypes: true });\n for (const entry of entries) {\n const childRel = rel ? path.posix.join(rel, entry.name) : entry.name;\n if (entry.isDirectory()) {\n if (!includeEntry({ relPath: childRel, type: ZipEntryType.Directory })) continue;\n // fflate treats trailing-slash zero-length entries as directories.\n zipEntries.push({ relPath: `${childRel}/`, isDirectory: true });\n await walk(childRel);\n } else if (entry.isFile()) {\n if (!includeEntry({ relPath: childRel, type: ZipEntryType.File })) continue;\n zipEntries.push({ relPath: childRel, isDirectory: false });\n } else if (entry.isSymbolicLink()) {\n throw new Error(`symlink entries are not supported: ${childRel}`);\n }\n }\n };\n\n await walk('');\n return omitEmptyDirectories(zipEntries).sort((a, b) =>\n a.relPath < b.relPath ? -1 : a.relPath > b.relPath ? 1 : 0,\n );\n};\n\n/**\n * Build a byte-deterministic ZIP of `sourceDir`.\n *\n * Entry order and timestamps are normalized so equivalent directories produce\n * stable archive bytes. Directory entries with no included child files are\n * omitted so empty folders cannot change the archive hash.\n */\nexport const zipDirectoryToUint8Array = async (\n sourceDir: string,\n options?: ZipDirectoryOptions,\n): Promise<Uint8Array> => {\n const predicate = options?.pathInclusionPredicate ?? INCLUDE_EVERYTHING;\n const prefix = options?.rootName === undefined ? '' : `${options.rootName}/`;\n const entries = await collectSortedEntries(sourceDir, (entry) =>\n predicate({ ...entry, relPath: `${prefix}${entry.relPath}` }),\n );\n const fileMap: Zippable = {};\n if (prefix !== '' && entries.length > 0) {\n fileMap[prefix] = new Uint8Array(0);\n }\n\n for (const entry of entries) {\n fileMap[`${prefix}${entry.relPath}`] = entry.isDirectory\n ? new Uint8Array(0)\n : new Uint8Array(await fs.readFile(path.join(sourceDir, entry.relPath)));\n }\n\n return zipSync(fileMap, {\n level: options?.level ?? 6,\n mtime: options?.mtime ?? DEFAULT_DETERMINISTIC_ZIP_MTIME,\n });\n};\n\nexport const zipDirectoryToBuffer = async (\n sourceDir: string,\n options?: ZipDirectoryOptions,\n): Promise<Buffer> => Buffer.from(await zipDirectoryToUint8Array(sourceDir, options));\n\nexport const zipDirectoryToBase64 = async (\n sourceDir: string,\n options?: ZipDirectoryOptions,\n): Promise<string> => (await zipDirectoryToBuffer(sourceDir, options)).toString('base64');\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/deterministic-zip",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"fflate": "^0.8.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@layerzerolabs/tsup-configuration": "4.0.
|
|
23
|
-
"@layerzerolabs/typescript-configuration": "4.0.
|
|
22
|
+
"@layerzerolabs/tsup-configuration": "4.0.10",
|
|
23
|
+
"@layerzerolabs/typescript-configuration": "4.0.10",
|
|
24
24
|
"tsup": "^8.4.0",
|
|
25
25
|
"vitest": "^4.1.10"
|
|
26
26
|
},
|