diff --git a/index.js b/index.js index 24962d8..2c2b022 100644 --- a/index.js +++ b/index.js @@ -1,23 +1,17 @@ #!/usr/bin/env node -// SUPER IMPORTANT: -// Node is extremely annoying and refuses to allow ESM imports in -// CLI tools, so we have to use require here. Do not change to import. -const fs = require('node:fs').promises; -const path = require('node:path'); - -let https; -try { - https = require('node:https'); -} catch (error) { - console.error('https support is disabled!'); -} +import fs from 'node:fs'; +import https from 'node:https'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); let originalManifestIndentation = 2; let originalManifestEOL = '\n'; function fileExists (file) { - return require('node:fs').existsSync(file); + return fs.existsSync(file); } function getVersions () { @@ -66,7 +60,7 @@ function getLocalNwManifest () { return new Promise(async (resolve, reject) => { try { const nwManifest = await getLocalNwManifestPath(); - let data = await fs.readFile(nwManifest, 'binary'); + let data = await fs.promises.readFile(nwManifest, { encoding: 'binary' }); data = JSON.parse(data); resolve(data); } catch (error) { @@ -166,7 +160,7 @@ function getManifest () { return new Promise(async (resolve, reject) => { try { const manifest = await getManifestPath(); - let data = await fs.readFile(manifest, 'binary'); + let data = await fs.promises.readFile(manifest, { encoding: 'binary' }); determineOriginalManifestIndentation(String(data)); determinOriginalEOL(String(data)); data = JSON.parse(data); @@ -200,7 +194,7 @@ async function run () { mutatedManifest = mutatedManifest.replaceAll('\r\n', '\n').replaceAll('\n', originalManifestEOL); mutatedManifest = mutatedManifest + originalManifestEOL; - await fs.writeFile(manifestPath, mutatedManifest); + await fs.promises.writeFile(manifestPath, mutatedManifest); } catch (error) { console.error(error); } diff --git a/package-lock.json b/package-lock.json index b5c4cb9..6c9379f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "base-volta-off-of-nwjs", - "version": "1.0.0", + "version": "1.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "base-volta-off-of-nwjs", - "version": "1.0.0", + "version": "1.0.4", "license": "MIT", "bin": { "base-volta-off-of-nwjs": "index.js" diff --git a/package.json b/package.json index 4881c7a..510f4a3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "base-volta-off-of-nwjs", - "version": "1.0.3", + "version": "1.0.4", "main": "index.js", + "type": "module", "bin": "./index.js", "license": "MIT", "description": "Updates Volta config in package.json so Node match's what your NW.js version uses",