Skip to content

Commit

Permalink
Avoid redeclaration of reserved __dirname (#809)
Browse files Browse the repository at this point in the history
* no redeclaration of reserved __dirname

* Update comment

---------

Co-authored-by: Joshua Lochner <[email protected]>
  • Loading branch information
vlinder and xenova committed Sep 3, 2024
1 parent 7f5081d commit 50d5620
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ const PATH_AVAILABLE = !isEmpty(path); // check if path is available

const RUNNING_LOCALLY = FS_AVAILABLE && PATH_AVAILABLE;

const __dirname = RUNNING_LOCALLY
// __dirname is reserved so we use dirname__ instead.
const dirname__ = RUNNING_LOCALLY
? path.dirname(path.dirname(url.fileURLToPath(import.meta.url)))
: './';

// Only used for environments with access to file system
const DEFAULT_CACHE_DIR = RUNNING_LOCALLY
? path.join(__dirname, '/.cache/')
? path.join(dirname__, '/.cache/')
: null;

// Set local model path, based on available APIs
const DEFAULT_LOCAL_MODEL_PATH = '/models/';
const localModelPath = RUNNING_LOCALLY
? path.join(__dirname, DEFAULT_LOCAL_MODEL_PATH)
? path.join(dirname__, DEFAULT_LOCAL_MODEL_PATH)
: DEFAULT_LOCAL_MODEL_PATH;

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

Expand Down Expand Up @@ -94,7 +95,7 @@ export const env = {
tfjs: {},
},

__dirname,
__dirname: dirname__,
version: VERSION,

/////////////////// Model settings ///////////////////
Expand Down

0 comments on commit 50d5620

Please sign in to comment.