diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9a14fddb..1badd084 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false # don't cancel all jobs if some of them failed matrix: - node: ["18", "20"] + node: ["20"] steps: - uses: actions/checkout@v4 - name: Setup node diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ef436025..31d99be4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,10 +12,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Node.js 18.x + - name: Set up Node.js 20.x uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x registry-url: https://registry.npmjs.org/ - name: Install dependencies diff --git a/.github/workflows/test-ga-build.yml b/.github/workflows/test-ga-build.yml index df104c63..8d29e144 100644 --- a/.github/workflows/test-ga-build.yml +++ b/.github/workflows/test-ga-build.yml @@ -10,6 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set up Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x - run: yarn install - run: yarn build diff --git a/.github/workflows/test-ga-bump-upstream-template.yml b/.github/workflows/test-ga-bump-upstream-template.yml index 0376d12a..a10a8bb5 100644 --- a/.github/workflows/test-ga-bump-upstream-template.yml +++ b/.github/workflows/test-ga-bump-upstream-template.yml @@ -14,6 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set up Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x - run: yarn install - run: yarn build diff --git a/.github/workflows/test-ga-bump-upstream.yml b/.github/workflows/test-ga-bump-upstream.yml index 09eca500..8b9f4276 100644 --- a/.github/workflows/test-ga-bump-upstream.yml +++ b/.github/workflows/test-ga-bump-upstream.yml @@ -14,6 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set up Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x - run: yarn install - run: yarn build diff --git a/.github/workflows/test-ga-end-to-end.yml b/.github/workflows/test-ga-end-to-end.yml index 5eba45fc..5a044c87 100644 --- a/.github/workflows/test-ga-end-to-end.yml +++ b/.github/workflows/test-ga-end-to-end.yml @@ -14,6 +14,10 @@ jobs: runs-on: packages steps: - uses: actions/checkout@v4 + - name: Set up Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x - run: yarn install - run: yarn build diff --git a/package.json b/package.json index 4f0576fa..bc6e03a9 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,7 @@ "description": "dappnodesdk is a tool to make the creation of new dappnode packages as simple as possible. It helps to initialize and publish in ethereum blockchain", "main": "dist/index.js", "types": "dist/index.d.ts", - "bin": { - "dappnodesdk": "dist/dappnodesdk.js" - }, + "bin": "dist/dappnodesdk.js", "scripts": { "tag-and-publish": "npm version patch && git push --follow-tags", "test": "mocha \"./{,!(node_modules)/**}/*.test.ts\"", @@ -78,7 +76,7 @@ "@types/lodash-es": "^4.17.7", "@types/mime-types": "^2.1.0", "@types/mocha": "^10.0.1", - "@types/node": "^18.15.11", + "@types/node": "^22.7.5", "@types/prettier": "^2.1.5", "@types/request": "^2.48.5", "@types/rimraf": "^3.0.0", @@ -91,9 +89,9 @@ "eslint": "^7.3.1", "mocha": "^10.2.0", "ts-node": "^10.9.1", - "typescript": "^4.7.3" + "typescript": "^5.6.3" }, "engines": { - "node": ">=18.0.0" + "node": ">=20.0.0" } } diff --git a/src/utils/getFileHash.ts b/src/utils/getFileHash.ts index 47bd6043..40ce2288 100644 --- a/src/utils/getFileHash.ts +++ b/src/utils/getFileHash.ts @@ -2,21 +2,31 @@ import fs from "fs"; import crypto from "crypto"; /** - * Hashes a file's buffer + * Hashes a file by reading it in chunks * * @param path - * @return file's sha3 hash: 0x36d2fe6d4582e8cc1e5ea4c6c05e44bc94b88f4567edca12ba5fd5745796edef + * @return file's sha256 hash */ export function getFileHash(path: string): Promise { - return fs.promises - .readFile(path) - .then(data => { - const hash = crypto.createHash("sha256"); - hash.update(data); - return hash.digest("hex"); - }) - .catch(e => { - if (e.code === "ENOENT") return null; - else throw e; + return new Promise((resolve, reject) => { + const hash = crypto.createHash("sha256"); + const stream = fs.createReadStream(path); + + stream.on("data", (chunk: Buffer) => { + hash.update(chunk); // Should now recognize Buffer correctly + }); + + stream.on("end", () => { + const fileHash = hash.digest("hex"); + resolve(fileHash); + }); + + stream.on("error", (err: NodeJS.ErrnoException) => { + if (err.code === "ENOENT") { + resolve(null); // file not found + } else { + reject(err); // other errors + } }); + }); } diff --git a/yarn.lock b/yarn.lock index 56f65df0..46eb1513 100644 --- a/yarn.lock +++ b/yarn.lock @@ -660,7 +660,7 @@ resolved "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.1.tgz" integrity sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q== -"@types/node@*", "@types/node@^18.11.18", "@types/node@^18.15.11": +"@types/node@*", "@types/node@^18.11.18": version "18.15.11" resolved "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz" integrity sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q== @@ -680,6 +680,13 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.16.14.tgz#ab67bb907f1146afc6fedb9ce60ae8a99c989631" integrity sha512-+ImzUB3mw2c5ISJUq0punjDilUQ5GnUim0ZRvchHIWJmOC0G+p0kzhXBqj6cDjK0QdPFwzrHWgrJp3RPvCG5qg== +"@types/node@^22.7.5": + version "22.7.5" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.7.5.tgz#cfde981727a7ab3611a481510b473ae54442b92b" + integrity sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ== + dependencies: + undici-types "~6.19.2" + "@types/prettier@^2.1.5": version "2.1.5" resolved "https://registry.npmjs.org/@types/prettier/-/prettier-2.1.5.tgz" @@ -3708,10 +3715,10 @@ type-fest@^0.8.1: resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== -typescript@^4.7.3: - version "4.7.3" - resolved "https://registry.npmjs.org/typescript/-/typescript-4.7.3.tgz" - integrity sha512-WOkT3XYvrpXx4vMMqlD+8R8R37fZkjyLGlxavMc4iB8lrl8L0DeTcHbYgw/v0N/z9wAFsgBhcsF0ruoySS22mA== +typescript@^5.6.3: + version "5.6.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b" + integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw== uint8arraylist@^2.1.2, uint8arraylist@^2.4.3: version "2.4.3" @@ -3734,6 +3741,11 @@ uint8arrays@^4.0.3: dependencies: multiformats "^11.0.0" +undici-types@~6.19.2: + version "6.19.8" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02" + integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw== + undici@^5.12.0: version "5.22.1" resolved "https://registry.yarnpkg.com/undici/-/undici-5.22.1.tgz#877d512effef2ac8be65e695f3586922e1a57d7b"