diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac0966e..7bbd4b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,11 +14,11 @@ 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 }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install @@ -33,10 +33,10 @@ jobs: needs: test steps: - uses: actions/checkout@v4 - - name: Use Node.js 14 - uses: actions/setup-node@v3 + - name: Use Node.js 18 + uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 18 registry-url: https://registry.npmjs.org/ - run: npm install - run: npm run fetch 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..c298e60 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`; @@ -37,13 +37,31 @@ 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]; 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') { + const result = await esbuild.transform(file, { + target, + minify: true + }); + + file = result.code; + } + + await fs.outputFile(outfile, file); } else { await autoReadStream(entry); } @@ -53,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' 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); });