Skip to content

Commit 2655218

Browse files
committed
Improve detection & usage of deno/bun
1 parent 4362237 commit 2655218

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@
8282
"README.md",
8383
"LICENSE"
8484
],
85-
"browser": {
86-
"fs": false,
87-
"path": false,
88-
"url": false,
89-
"sharp": false,
90-
"onnxruntime-node": false
91-
},
9285
"publishConfig": {
9386
"access": "public"
9487
},

src/env.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
* @module env
2323
*/
2424

25-
import fs from 'fs';
26-
import path from 'path';
27-
import url from 'url';
25+
import fs from 'node:fs';
26+
import path from 'node:path';
27+
import url from 'node:url';
2828

2929
const VERSION = '3.5.2';
3030

@@ -40,6 +40,10 @@ const IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === 'node';
4040
const IS_FS_AVAILABLE = !isEmpty(fs);
4141
const IS_PATH_AVAILABLE = !isEmpty(path);
4242

43+
// Runtime detection
44+
const IS_DENO_RUNTIME = typeof globalThis.Deno !== 'undefined';
45+
const IS_BUN_RUNTIME = typeof globalThis.Bun !== 'undefined';
46+
4347
/**
4448
* A read-only object containing information about the APIs available in the current environment.
4549
*/
@@ -62,7 +66,7 @@ export const apis = Object.freeze({
6266
/** Whether the Node.js process API is available */
6367
IS_PROCESS_AVAILABLE,
6468

65-
/** Whether we are running in a Node.js environment */
69+
/** Whether we are running in a Node.js-like environment (node, deno, bun) */
6670
IS_NODE_ENV,
6771

6872
/** Whether the filesystem API is available */
@@ -143,7 +147,7 @@ export const env = {
143147
useFS: IS_FS_AVAILABLE,
144148

145149
/////////////////// Cache settings ///////////////////
146-
useBrowserCache: IS_WEB_CACHE_AVAILABLE,
150+
useBrowserCache: IS_WEB_CACHE_AVAILABLE && !IS_DENO_RUNTIME,
147151

148152
useFSCache: IS_FS_AVAILABLE,
149153
cacheDir: DEFAULT_CACHE_DIR,

src/utils/audio.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ import {
1515
calculateReflectOffset, saveBlob,
1616
} from './core.js';
1717
import { apis } from '../env.js';
18-
import fs from 'fs';
1918
import { Tensor, matmul } from './tensor.js';
20-
19+
import fs from 'node:fs';
2120

2221
/**
2322
* Helper function to read audio from a path/URL.

src/utils/hub.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* @module utils/hub
66
*/
77

8-
import fs from 'fs';
9-
import path from 'path';
8+
import fs from 'node:fs';
9+
import path from 'node:path';
1010

1111
import { apis, env } from '../env.js';
1212
import { dispatchCallback } from './core.js';

webpack.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ const NODE_EXTERNAL_MODULES = [
137137
"onnxruntime-common",
138138
"onnxruntime-node",
139139
"sharp",
140-
"fs",
141-
"path",
142-
"url",
140+
"node:fs",
141+
"node:path",
142+
"node:url",
143143
];
144144

145145
// Do not bundle onnxruntime-node when packaging for the web.

0 commit comments

Comments
 (0)