Fix dirname for Node 18

c67c0cbf7e8acf06af1b668b7080d3a2e44920ae

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +6 -3Ignore whitespace
plugins.js+4 -2
@@ -3,12 +3,14 @@
3// 1. node plugins.js update3// 1. node plugins.js update
4// 2. node plugins.js install <plugin-git-url>4// 2. node plugins.js install <plugin-git-url>
5// More operations coming soon.5// More operations coming soon.
6import { default as git } from 'simple-git';
7import * as fs from 'node:fs';6import * as fs from 'node:fs';
8import * as path from 'node:path';7import * as path from 'node:path';
8import { fileURLToPath } from 'node:url';
9
10import { default as git } from 'simple-git';
9import { color } from './src/util.js';11import { color } from './src/util.js';
1012
11const __dirname = import.meta.dirname;13const __dirname = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
12process.chdir(__dirname);14process.chdir(__dirname);
13const pluginsPath = './plugins';15const pluginsPath = './plugins';
1416
server.js+2 -1
@@ -8,6 +8,7 @@ import * as path from 'node:path';
8import * as util from 'node:util';8import * as util from 'node:util';
9import * as net from 'node:net';9import * as net from 'node:net';
10import * as dns from 'node:dns';10import * as dns from 'node:dns';
11import { fileURLToPath } from 'node:url';
1112
12// cli/fs related library imports13// cli/fs related library imports
13import open from 'open';14import open from 'open';
@@ -214,7 +215,7 @@ const cliArguments = yargs(hideBin(process.argv))
214 }).parseSync();215 }).parseSync();
215216
216// change all relative paths217// change all relative paths
217const serverDirectory = import.meta.dirname;218const serverDirectory = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
218console.log(`Node version: ${process.version}. Running in ${process.env.NODE_ENV} environment. Server directory: ${serverDirectory}`);219console.log(`Node version: ${process.version}. Running in ${process.env.NODE_ENV} environment. Server directory: ${serverDirectory}`);
219process.chdir(serverDirectory);220process.chdir(serverDirectory);
220221