Fix dirname for Node 18
| @@ -3,12 +3,14 @@ | |||
| 3 | // 1. node plugins.js update | 3 | // 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. |
| 6 | import { default as git } from 'simple-git'; | ||
| 7 | import * as fs from 'node:fs'; | 6 | import * as fs from 'node:fs'; |
| 8 | import * as path from 'node:path'; | 7 | import * as path from 'node:path'; |
| 8 | import { fileURLToPath } from 'node:url'; | ||
| 9 | |||
| 10 | import { default as git } from 'simple-git'; | ||
| 9 | import { color } from './src/util.js'; | 11 | import { color } from './src/util.js'; |
| 10 | 12 | ||
| 11 | const __dirname = import.meta.dirname; | 13 | const __dirname = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url)); |
| 12 | process.chdir(__dirname); | 14 | process.chdir(__dirname); |
| 13 | const pluginsPath = './plugins'; | 15 | const pluginsPath = './plugins'; |
| 14 | 16 | ||
| @@ -8,6 +8,7 @@ import * as path from 'node:path'; | |||
| 8 | import * as util from 'node:util'; | 8 | import * as util from 'node:util'; |
| 9 | import * as net from 'node:net'; | 9 | import * as net from 'node:net'; |
| 10 | import * as dns from 'node:dns'; | 10 | import * as dns from 'node:dns'; |
| 11 | import { fileURLToPath } from 'node:url'; | ||
| 11 | 12 | ||
| 12 | // cli/fs related library imports | 13 | // cli/fs related library imports |
| 13 | import open from 'open'; | 14 | import open from 'open'; |
| @@ -214,7 +215,7 @@ const cliArguments = yargs(hideBin(process.argv)) | |||
| 214 | }).parseSync(); | 215 | }).parseSync(); |
| 215 | 216 | ||
| 216 | // change all relative paths | 217 | // change all relative paths |
| 217 | const serverDirectory = import.meta.dirname; | 218 | const serverDirectory = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url)); |
| 218 | console.log(`Node version: ${process.version}. Running in ${process.env.NODE_ENV} environment. Server directory: ${serverDirectory}`); | 219 | console.log(`Node version: ${process.version}. Running in ${process.env.NODE_ENV} environment. Server directory: ${serverDirectory}`); |
| 219 | process.chdir(serverDirectory); | 220 | process.chdir(serverDirectory); |
| 220 | 221 | ||