Skip to content

Commit 50d5620

Browse files
vlinderxenova
andauthored
Avoid redeclaration of reserved __dirname (#809)
* no redeclaration of reserved __dirname * Update comment --------- Co-authored-by: Joshua Lochner <[email protected]>
1 parent 7f5081d commit 50d5620

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/env.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ const PATH_AVAILABLE = !isEmpty(path); // check if path is available
3838

3939
const RUNNING_LOCALLY = FS_AVAILABLE && PATH_AVAILABLE;
4040

41-
const __dirname = RUNNING_LOCALLY
41+
// __dirname is reserved so we use dirname__ instead.
42+
const dirname__ = RUNNING_LOCALLY
4243
? path.dirname(path.dirname(url.fileURLToPath(import.meta.url)))
4344
: './';
4445

4546
// Only used for environments with access to file system
4647
const DEFAULT_CACHE_DIR = RUNNING_LOCALLY
47-
? path.join(__dirname, '/.cache/')
48+
? path.join(dirname__, '/.cache/')
4849
: null;
4950

5051
// Set local model path, based on available APIs
5152
const DEFAULT_LOCAL_MODEL_PATH = '/models/';
5253
const localModelPath = RUNNING_LOCALLY
53-
? path.join(__dirname, DEFAULT_LOCAL_MODEL_PATH)
54+
? path.join(dirname__, DEFAULT_LOCAL_MODEL_PATH)
5455
: DEFAULT_LOCAL_MODEL_PATH;
5556

5657
if (onnx_env?.wasm) {
@@ -59,7 +60,7 @@ if (onnx_env?.wasm) {
5960
// We use remote wasm files by default to make it easier for newer users.
6061
// In practice, users should probably self-host the necessary .wasm files.
6162
onnx_env.wasm.wasmPaths = RUNNING_LOCALLY
62-
? path.join(__dirname, '/dist/')
63+
? path.join(dirname__, '/dist/')
6364
: `https://cdn.jsdelivr.net/npm/@xenova/transformers@${VERSION}/dist/`;
6465
}
6566

@@ -94,7 +95,7 @@ export const env = {
9495
tfjs: {},
9596
},
9697

97-
__dirname,
98+
__dirname: dirname__,
9899
version: VERSION,
99100

100101
/////////////////// Model settings ///////////////////

0 commit comments

Comments
 (0)