Skip to content

Commit 56bc72d

Browse files
committed
gltfpack: Restore automatic initialization in node.js
This improves compatibility when the package is used through node; we used to automatically init the package using synchronous file loads. To do that, we need to dynamically import node's fs module to avoid taking a bundle-time dependency on it in browser builds.
1 parent a4e39ac commit 56bc72d

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
run: |
9494
npm install -g es-check@7.2.1
9595
npx es-check --module es5 js/meshopt_decoder.js js/meshopt_encoder.js js/meshopt_simplifier.js js/meshopt_clusterizer.js
96-
npx es-check --module es5 gltf/library.js
96+
npx es-check --module es2020 gltf/library.js
9797
9898
gltfpack:
9999
runs-on: ubuntu-latest

‎gltf/cli.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env node
22
// This file is part of gltfpack and is distributed under the terms of MIT License.
3-
import { init, pack } from './library.js';
3+
import { pack } from './library.js';
44
import fs from 'fs';
55

6-
init(fs.readFileSync(new URL('./library.wasm', import.meta.url)));
7-
86
var args = process.argv.slice(2);
97

108
var iface = {

‎gltf/library.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,13 @@ function uploadArgv(argv) {
344344
return buf;
345345
}
346346

347+
// Automatic initialization for node.js
348+
if (typeof process !== 'undefined' && process.release && process.release.name === 'node') {
349+
init(
350+
import('node:fs').then(function (fs) {
351+
return fs.readFileSync(new URL('./library.wasm', import.meta.url));
352+
})
353+
);
354+
}
355+
347356
export { init, pack };

0 commit comments

Comments
 (0)