From 1f4dc85637b7330e315da1e6a297fb68137a55a0 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Mon, 22 Jul 2024 19:42:49 -0400 Subject: [PATCH 1/6] updating libheif to 1.18.0 --- package.json | 2 +- scripts/install.js | 2 +- test/libheif.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b790790..cb3c06e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libheif-js", - "version": "1.17.1", + "version": "1.18.0", "description": "Emscripten distribution of libheif for Node.JS and the browser", "main": "index.js", "scripts": { diff --git a/scripts/install.js b/scripts/install.js index 408e9cb..dd109dc 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -8,7 +8,7 @@ const gunzip = require('gunzip-maybe'); const esbuild = require('esbuild'); -const version = 'v1.17.1'; +const version = 'v1.18.0'; const base = `https://github.com/catdad-experiments/libheif-emscripten/releases/download/${version}`; const tarball = `${base}/libheif.tar.gz`; diff --git a/test/libheif.test.js b/test/libheif.test.js index ae8e694..733fd0c 100644 --- a/test/libheif.test.js +++ b/test/libheif.test.js @@ -87,7 +87,7 @@ function runTests(libheif) { it('is the correct version', () => { expect(libheif).to.have.property('heif_get_version') .and.to.be.a('function'); - expect(libheif.heif_get_version()).to.equal('1.17.1') + expect(libheif.heif_get_version()).to.equal('1.18.0') .and.to.equal(pkg.version); }); From 409e4fc80397a0a1d81f6e54d4bdf17131e15c69 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Mon, 22 Jul 2024 19:54:29 -0400 Subject: [PATCH 2/6] removing unsupported node version by upstream libheif --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac0966e..3068d1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12, 14, 16, 18, 20] + node-version: [16, 18, 20] steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} @@ -33,10 +33,10 @@ jobs: needs: test steps: - uses: actions/checkout@v4 - - name: Use Node.js 14 + - name: Use Node.js 18 uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 18 registry-url: https://registry.npmjs.org/ - run: npm install - run: npm run fetch From ee17fbd8f45f242b2adbb2f1e854c91add65e8c4 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Mon, 22 Jul 2024 19:57:41 -0400 Subject: [PATCH 3/6] updating setup-node action to latest version --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3068d1d..2476223 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install @@ -34,7 +34,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Use Node.js 18 - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 registry-url: https://registry.npmjs.org/ From eada8af03c4197f82b2adcb20304fbf71d46d5df Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Tue, 23 Jul 2024 00:39:31 -0400 Subject: [PATCH 4/6] transforming original libheif files so that they can run on older versions of node --- .github/workflows/ci.yml | 2 +- scripts/install.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2476223..afbdb66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [16, 18, 20] + node-version: [12, 14, 16, 18, 20] steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} diff --git a/scripts/install.js b/scripts/install.js index dd109dc..70fc619 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -43,7 +43,23 @@ const autoReadStream = async stream => { if (entry.header.type === 'file' && ['libheif', 'libheif-wasm'].includes(basedir)) { const outfile = path.resolve(root, entry.header.name); console.log(` writing "${outfile}"`); - await fs.outputFile(outfile, await autoReadStream(entry)); + + let file = await autoReadStream(entry); + + if (path.extname(outfile) === '.js') { + // libheif started using optional chaining, which is not + // supported in older versions of node, but we'd like to + // support them here, so transform to a target from before + // https://esbuild.github.io/content-types/#javascript + const result = await esbuild.transform(file, { + target: 'es2019', + minify: true + }); + + file = result.code; + } + + await fs.outputFile(outfile, file); } else { await autoReadStream(entry); } From 6de3a53dc191790e8c55e40f5fef857c2c2c6c09 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Tue, 23 Jul 2024 00:46:20 -0400 Subject: [PATCH 5/6] let's try es2018 as the target --- scripts/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install.js b/scripts/install.js index 70fc619..63a22d5 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -52,7 +52,7 @@ const autoReadStream = async stream => { // support them here, so transform to a target from before // https://esbuild.github.io/content-types/#javascript const result = await esbuild.transform(file, { - target: 'es2019', + target: 'es2018', minify: true }); From 5373d25cbcab2143041bacc90ffeaa9354bcea05 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Tue, 23 Jul 2024 00:55:19 -0400 Subject: [PATCH 6/6] the wasm bundle itself doesn't run on node 12, so looks like 14 is the new minimum --- .github/workflows/ci.yml | 2 +- scripts/install.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index afbdb66..7bbd4b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12, 14, 16, 18, 20] + node-version: [14, 16, 18, 20] steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} diff --git a/scripts/install.js b/scripts/install.js index 63a22d5..c298e60 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -37,6 +37,12 @@ const autoReadStream = async stream => { await fs.remove(path.resolve(root, 'libheif')); await fs.remove(path.resolve(root, 'libheif-wasm')); + // libheif started using optional chaining, which is not + // supported in older versions of node, but we'd like to + // support them here, so transform to a target from before + // https://esbuild.github.io/content-types/#javascript + const target = 'es2019'; + for await (const entry of (await getStream(tarball)).pipe(gunzip()).pipe(tar.extract())) { const basedir = entry.header.name.split('/')[0]; @@ -47,12 +53,8 @@ const autoReadStream = async stream => { let file = await autoReadStream(entry); if (path.extname(outfile) === '.js') { - // libheif started using optional chaining, which is not - // supported in older versions of node, but we'd like to - // support them here, so transform to a target from before - // https://esbuild.github.io/content-types/#javascript const result = await esbuild.transform(file, { - target: 'es2018', + target, minify: true }); @@ -69,6 +71,7 @@ const autoReadStream = async stream => { entryPoints: [path.resolve(root, 'scripts/bundle.js')], bundle: true, minify: true, + target, external: ['fs', 'path', 'require'], loader: { '.wasm': 'binary'