From ac37e60559cf1c8e778a34dd594787076ebe49b1 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Tue, 15 Oct 2024 18:28:59 +0300 Subject: [PATCH] refactor(web): use fs/promises --- lib/binding_web/binding.js | 13 ++++--------- lib/binding_web/test/helper.js | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/binding_web/binding.js b/lib/binding_web/binding.js index a626aa01..0e84f741 100644 --- a/lib/binding_web/binding.js +++ b/lib/binding_web/binding.js @@ -1163,16 +1163,11 @@ class Language { if (input instanceof Uint8Array) { bytes = Promise.resolve(input); } else { - const url = input; - if ( - typeof process !== 'undefined' && - process.versions && - process.versions.node - ) { - const fs = require('fs'); - bytes = Promise.resolve(fs.readFileSync(url)); + if (globalThis.process?.versions?.node) { + const fs = require('fs/promises'); + bytes = fs.readFile(input); } else { - bytes = fetch(url) + bytes = fetch(input) .then((response) => response.arrayBuffer() .then((buffer) => { if (response.ok) { diff --git a/lib/binding_web/test/helper.js b/lib/binding_web/test/helper.js index 2847f5ab..9e0869d4 100644 --- a/lib/binding_web/test/helper.js +++ b/lib/binding_web/test/helper.js @@ -1,4 +1,4 @@ -const Parser = require(`..`); +const Parser = require('..'); function languageURL(name) { return require.resolve(`../../../target/release/tree-sitter-${name}.wasm`);