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 authored Apr 6, 2024
1 parent 19f7d83 commit 8989131
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
26 changes: 10 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 8989131

Please sign in to comment.