Skip to content

Commit

Permalink
chore(cli): convert from cjs to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra committed Apr 6, 2024
1 parent 19f7d83 commit e28ffd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
23 changes: 7 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
#!/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';

let originalManifestIndentation = 2;
let originalManifestEOL = '\n';

function fileExists (file) {
return require('node:fs').existsSync(file);
return fs.existsSync(file);
}

function getVersions () {
Expand Down Expand Up @@ -66,7 +57,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) {
Expand Down Expand Up @@ -166,7 +157,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);
Expand Down Expand Up @@ -200,7 +191,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);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "base-volta-off-of-nwjs",
"version": "1.0.3",
"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",
Expand Down

0 comments on commit e28ffd7

Please sign in to comment.