Skip to content

Commit

Permalink
transforming original libheif files so that they can run on older ver…
Browse files Browse the repository at this point in the history
…sions of node
  • Loading branch information
catdad committed Jul 23, 2024
1 parent ee17fbd commit eada8af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
18 changes: 17 additions & 1 deletion scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit eada8af

Please sign in to comment.