@willbooster/shared-lib-node 2.5.1 → 2.6.0
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/cjs/hash.cjs +1 -1
- package/dist/cjs/hash.cjs.map +1 -1
- package/dist/cjs/hash.d.cts +11 -0
- package/dist/esm/hash.d.ts +11 -0
- package/dist/esm/hash.js +1 -1
- package/dist/esm/hash.js.map +1 -1
- package/package.json +2 -1
package/dist/cjs/hash.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("node:crypto"),t=require("node:fs"),s=require("node:path");async function
|
|
1
|
+
"use strict";var e=require("node:crypto"),t=require("node:fs"),s=require("node:path");async function a(...a){const r=e.createHash("sha512");for(const e of a.sort()){const a=await t.promises.stat(e);if(a.isDirectory()){const a=await t.promises.readdir(e,{withFileTypes:!0,recursive:!0});for(const e of a.sort(((e,t)=>e.name.localeCompare(t.name))))e.isFile()&&r.update(await t.promises.readFile(s.join(e.path,e.name),"utf8"))}else a.isFile()&&r.update(await t.promises.readFile(e,"utf8"))}return r.digest("hex")}exports.calculateHashFromFiles=a,exports.updateHashFromFiles=async function(e,...s){let r="";try{r=await t.promises.readFile(e,"utf8")}catch{}const i=await a(...s);return r!==i&&(await t.promises.writeFile(e,i,"utf8"),!0)};
|
|
2
2
|
//# sourceMappingURL=hash.cjs.map
|
package/dist/cjs/hash.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.cjs","sources":["../../src/hash.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nexport async function calculateHashFromFiles(...paths: string[]): Promise<string> {\n const hash = crypto.createHash('sha512');\n for (const fileOrDirPath of paths.sort()) {\n const stat = await fs.promises.stat(fileOrDirPath);\n if (stat.isDirectory()) {\n // Get all files in the directory\n const dirents = await fs.promises.readdir(fileOrDirPath, { withFileTypes: true, recursive: true });\n for (const dirent of dirents.sort((d1, d2) => d1.name.localeCompare(d2.name))) {\n if (dirent.isFile()) {\n hash.update(await fs.promises.readFile(path.join(
|
|
1
|
+
{"version":3,"file":"hash.cjs","sources":["../../src/hash.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\n/**\n * Calculate hash from files.\n * @param paths Paths to the files or directories.\n * @returns Hash string.\n */\nexport async function calculateHashFromFiles(...paths: string[]): Promise<string> {\n const hash = crypto.createHash('sha512');\n for (const fileOrDirPath of paths.sort()) {\n const stat = await fs.promises.stat(fileOrDirPath);\n if (stat.isDirectory()) {\n // Get all files in the directory\n const dirents = await fs.promises.readdir(fileOrDirPath, { withFileTypes: true, recursive: true });\n for (const dirent of dirents.sort((d1, d2) => d1.name.localeCompare(d2.name))) {\n if (dirent.isFile()) {\n // Node.js 18.17.0 or later has `dirent.path`\n hash.update(\n await fs.promises.readFile(\n path.join((dirent as unknown as Record<'path', string>).path, dirent.name),\n 'utf8'\n )\n );\n }\n }\n } else if (stat.isFile()) {\n hash.update(await fs.promises.readFile(fileOrDirPath, 'utf8'));\n }\n }\n return hash.digest('hex');\n}\n\n/**\n * Update hash file if the hash is different from the current one.\n * @param hashFilePath Path to the hash file.\n * @param paths Paths to the files or directories.\n * @returns Whether the hash file was updated.\n */\nexport async function updateHashFromFiles(hashFilePath: string, ...paths: string[]): Promise<boolean> {\n let oldHash = '';\n try {\n oldHash = await fs.promises.readFile(hashFilePath, 'utf8');\n } catch {\n // do nothing\n }\n const newHash = await calculateHashFromFiles(...paths);\n if (oldHash === newHash) return false;\n\n await fs.promises.writeFile(hashFilePath, newHash, 'utf8');\n return true;\n}\n"],"names":["async","calculateHashFromFiles","paths","hash","crypto","createHash","fileOrDirPath","sort","stat","fs","promises","isDirectory","dirents","readdir","withFileTypes","recursive","dirent","d1","d2","name","localeCompare","isFile","update","readFile","path","join","digest","hashFilePath","oldHash","newHash","writeFile"],"mappings":"sFASOA,eAAeC,KAA0BC,GAC9C,MAAMC,EAAOC,EAAOC,WAAW,UAC/B,IAAK,MAAMC,KAAiBJ,EAAMK,OAAQ,CACxC,MAAMC,QAAaC,EAAGC,SAASF,KAAKF,GACpC,GAAIE,EAAKG,cAAe,CAEtB,MAAMC,QAAgBH,EAAGC,SAASG,QAAQP,EAAe,CAAEQ,eAAe,EAAMC,WAAW,IAC3F,IAAK,MAAMC,KAAUJ,EAAQL,MAAK,CAACU,EAAIC,IAAOD,EAAGE,KAAKC,cAAcF,EAAGC,QACjEH,EAAOK,UAETlB,EAAKmB,aACGb,EAAGC,SAASa,SAChBC,EAAKC,KAAMT,EAA6CQ,KAAMR,EAAOG,MACrE,QAKV,MAAWX,EAAKa,UACdlB,EAAKmB,aAAab,EAAGC,SAASa,SAASjB,EAAe,QAE1D,CACA,OAAOH,EAAKuB,OAAO,MACrB,8DAQO1B,eAAmC2B,KAAyBzB,GACjE,IAAI0B,EAAU,GACd,IACEA,QAAgBnB,EAAGC,SAASa,SAASI,EAAc,OACrD,CAAE,MACA,CAEF,MAAME,QAAgB5B,KAA0BC,GAChD,OAAI0B,IAAYC,UAEVpB,EAAGC,SAASoB,UAAUH,EAAcE,EAAS,SAC5C,EACT"}
|
package/dist/cjs/hash.d.cts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate hash from files.
|
|
3
|
+
* @param paths Paths to the files or directories.
|
|
4
|
+
* @returns Hash string.
|
|
5
|
+
*/
|
|
1
6
|
declare function calculateHashFromFiles(...paths: string[]): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Update hash file if the hash is different from the current one.
|
|
9
|
+
* @param hashFilePath Path to the hash file.
|
|
10
|
+
* @param paths Paths to the files or directories.
|
|
11
|
+
* @returns Whether the hash file was updated.
|
|
12
|
+
*/
|
|
2
13
|
declare function updateHashFromFiles(hashFilePath: string, ...paths: string[]): Promise<boolean>;
|
|
3
14
|
export { calculateHashFromFiles, updateHashFromFiles };
|
package/dist/esm/hash.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate hash from files.
|
|
3
|
+
* @param paths Paths to the files or directories.
|
|
4
|
+
* @returns Hash string.
|
|
5
|
+
*/
|
|
1
6
|
declare function calculateHashFromFiles(...paths: string[]): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Update hash file if the hash is different from the current one.
|
|
9
|
+
* @param hashFilePath Path to the hash file.
|
|
10
|
+
* @param paths Paths to the files or directories.
|
|
11
|
+
* @returns Whether the hash file was updated.
|
|
12
|
+
*/
|
|
2
13
|
declare function updateHashFromFiles(hashFilePath: string, ...paths: string[]): Promise<boolean>;
|
|
3
14
|
export { calculateHashFromFiles, updateHashFromFiles };
|
package/dist/esm/hash.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"node:crypto";import t from"node:fs";import i from"node:path";async function o(...o){const r=e.createHash("sha512");for(const e of o.sort()){const o=await t.promises.stat(e);if(o.isDirectory()){const o=await t.promises.readdir(e,{withFileTypes:!0,recursive:!0});for(const
|
|
1
|
+
import e from"node:crypto";import t from"node:fs";import i from"node:path";async function o(...o){const r=e.createHash("sha512");for(const e of o.sort()){const o=await t.promises.stat(e);if(o.isDirectory()){const o=await t.promises.readdir(e,{withFileTypes:!0,recursive:!0});for(const e of o.sort(((e,t)=>e.name.localeCompare(t.name))))e.isFile()&&r.update(await t.promises.readFile(i.join(e.path,e.name),"utf8"))}else o.isFile()&&r.update(await t.promises.readFile(e,"utf8"))}return r.digest("hex")}async function r(e,...i){let r="";try{r=await t.promises.readFile(e,"utf8")}catch{}const a=await o(...i);return r!==a&&(await t.promises.writeFile(e,a,"utf8"),!0)}export{o as calculateHashFromFiles,r as updateHashFromFiles};
|
|
2
2
|
//# sourceMappingURL=hash.js.map
|
package/dist/esm/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sources":["../../src/hash.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nexport async function calculateHashFromFiles(...paths: string[]): Promise<string> {\n const hash = crypto.createHash('sha512');\n for (const fileOrDirPath of paths.sort()) {\n const stat = await fs.promises.stat(fileOrDirPath);\n if (stat.isDirectory()) {\n // Get all files in the directory\n const dirents = await fs.promises.readdir(fileOrDirPath, { withFileTypes: true, recursive: true });\n for (const dirent of dirents.sort((d1, d2) => d1.name.localeCompare(d2.name))) {\n if (dirent.isFile()) {\n hash.update(await fs.promises.readFile(path.join(
|
|
1
|
+
{"version":3,"file":"hash.js","sources":["../../src/hash.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\n/**\n * Calculate hash from files.\n * @param paths Paths to the files or directories.\n * @returns Hash string.\n */\nexport async function calculateHashFromFiles(...paths: string[]): Promise<string> {\n const hash = crypto.createHash('sha512');\n for (const fileOrDirPath of paths.sort()) {\n const stat = await fs.promises.stat(fileOrDirPath);\n if (stat.isDirectory()) {\n // Get all files in the directory\n const dirents = await fs.promises.readdir(fileOrDirPath, { withFileTypes: true, recursive: true });\n for (const dirent of dirents.sort((d1, d2) => d1.name.localeCompare(d2.name))) {\n if (dirent.isFile()) {\n // Node.js 18.17.0 or later has `dirent.path`\n hash.update(\n await fs.promises.readFile(\n path.join((dirent as unknown as Record<'path', string>).path, dirent.name),\n 'utf8'\n )\n );\n }\n }\n } else if (stat.isFile()) {\n hash.update(await fs.promises.readFile(fileOrDirPath, 'utf8'));\n }\n }\n return hash.digest('hex');\n}\n\n/**\n * Update hash file if the hash is different from the current one.\n * @param hashFilePath Path to the hash file.\n * @param paths Paths to the files or directories.\n * @returns Whether the hash file was updated.\n */\nexport async function updateHashFromFiles(hashFilePath: string, ...paths: string[]): Promise<boolean> {\n let oldHash = '';\n try {\n oldHash = await fs.promises.readFile(hashFilePath, 'utf8');\n } catch {\n // do nothing\n }\n const newHash = await calculateHashFromFiles(...paths);\n if (oldHash === newHash) return false;\n\n await fs.promises.writeFile(hashFilePath, newHash, 'utf8');\n return true;\n}\n"],"names":["async","calculateHashFromFiles","paths","hash","crypto","createHash","fileOrDirPath","sort","stat","fs","promises","isDirectory","dirents","readdir","withFileTypes","recursive","dirent","d1","d2","name","localeCompare","isFile","update","readFile","path","join","digest","updateHashFromFiles","hashFilePath","oldHash","newHash","writeFile"],"mappings":"2EASOA,eAAeC,KAA0BC,GAC9C,MAAMC,EAAOC,EAAOC,WAAW,UAC/B,IAAK,MAAMC,KAAiBJ,EAAMK,OAAQ,CACxC,MAAMC,QAAaC,EAAGC,SAASF,KAAKF,GACpC,GAAIE,EAAKG,cAAe,CAEtB,MAAMC,QAAgBH,EAAGC,SAASG,QAAQP,EAAe,CAAEQ,eAAe,EAAMC,WAAW,IAC3F,IAAK,MAAMC,KAAUJ,EAAQL,MAAK,CAACU,EAAIC,IAAOD,EAAGE,KAAKC,cAAcF,EAAGC,QACjEH,EAAOK,UAETlB,EAAKmB,aACGb,EAAGC,SAASa,SAChBC,EAAKC,KAAMT,EAA6CQ,KAAMR,EAAOG,MACrE,QAKV,MAAWX,EAAKa,UACdlB,EAAKmB,aAAab,EAAGC,SAASa,SAASjB,EAAe,QAE1D,CACA,OAAOH,EAAKuB,OAAO,MACrB,CAQO1B,eAAe2B,EAAoBC,KAAyB1B,GACjE,IAAI2B,EAAU,GACd,IACEA,QAAgBpB,EAAGC,SAASa,SAASK,EAAc,OACrD,CAAE,MACA,CAEF,MAAME,QAAgB7B,KAA0BC,GAChD,OAAI2B,IAAYC,UAEVrB,EAAGC,SAASqB,UAAUH,EAAcE,EAAS,SAC5C,EACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/shared-lib-node",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "WillBooster Inc.",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/eslint": "8.44.1",
|
|
44
44
|
"@types/micromatch": "4.0.2",
|
|
45
|
+
"@types/node": "18.17.1",
|
|
45
46
|
"@types/prettier": "2.7.3",
|
|
46
47
|
"@typescript-eslint/eslint-plugin": "6.2.1",
|
|
47
48
|
"@typescript-eslint/parser": "6.2.1",
|