Skip to content

Commit

Permalink
compiling fs and path modules out of the wasm bundle versions
Browse files Browse the repository at this point in the history
  • Loading branch information
catdad committed Oct 7, 2024
1 parent bf311a9 commit 66bf5df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"babel-eslint": "^10.1.0",
"chai": "^4.2.0",
"esbuild": "^0.19.5",
"esbuild-plugins-node-modules-polyfill": "^1.6.7",
"eslint": "^5.16.0",
"fs-extra": "^8.1.0",
"gunzip-maybe": "^1.4.2",
Expand Down
18 changes: 15 additions & 3 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const tar = require('tar-stream');
const gunzip = require('gunzip-maybe');

const esbuild = require('esbuild');
const { nodeModulesPolyfillPlugin } = require('esbuild-plugins-node-modules-polyfill');

const version = 'v1.18.2';

Expand Down Expand Up @@ -79,6 +80,15 @@ const autoReadStream = async stream => {
platform: 'neutral'
};

const plugins = () => [
nodeModulesPolyfillPlugin({
modules: {
fs: 'empty',
path: 'empty'
}
})
];

await esbuild.build({
...buildOptions,
outfile: path.resolve(root, 'libheif-wasm/libheif-bundle.js'),
Expand All @@ -92,7 +102,8 @@ libheif = libheif.default;
if (typeof exports === 'object' && typeof module === 'object') {
module.exports = libheif;
}`
}
},
plugins: plugins(),
});

await esbuild.build({
Expand All @@ -102,8 +113,9 @@ if (typeof exports === 'object' && typeof module === 'object') {
banner: {
// hack to avoid the ENVIRONMENT_IS_NODE detection
// the binary is built in, so the environment doesn't matter
js: 'var process;'
}
js: 'var process, __dirname;'
},
plugins: plugins(),
});
})().then(() => {
console.log(`fetched libheif ${version}`);
Expand Down

0 comments on commit 66bf5df

Please sign in to comment.