Resolved cross-format APP ROOT issue

This commit is contained in:
Cris Stringfellow 2023-01-15 15:07:51 +08:00
parent 4deb359af8
commit a386ec5bc9
No known key found for this signature in database
3 changed files with 31 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import path from 'path';
import {fileURLToPath} from 'url';
import fs from 'fs';
import os from 'os';
import root from './root.cjs';
import {APP_ROOT as __ROOT} from './root.js';
const DEEB = false;
@ -14,6 +14,10 @@ export const DEBUG = {
}
export const SHOW_FETCH = false;
if ( DEBUG.debug ) {
console.log({APP_ROOT});
}
// server related
export const PUBLIC_SERVER = true;
@ -75,9 +79,7 @@ export const SNIP_CONTEXT = 31;
export const NO_SANDBOX = (process.env.DEBUG_22120 && process.env.SET_22120_NO_SANDBOX) || false;
//export const APP_ROOT = '.';
export const APP_ROOT = root.APP_ROOT;
//export const APP_ROOT = path.dirname(fileURLToPath(import.meta.url));
export const APP_ROOT = __ROOT
export const sleep = ms => new Promise(res => setTimeout(res, ms));

View File

@ -3,11 +3,12 @@ const url = require('url');
const file = __filename;
const dir = path.dirname(file);
const APP_ROOT = dir;
console.log({file, dir});
console.log({APP_ROOT});
module.exports = {
APP_ROOT: dir,
APP_ROOT,
dir,
file
}

22
src/root.js Normal file
View File

@ -0,0 +1,22 @@
import path from 'path';
import url from 'url';
let root;
let esm = false;
try {
console.log(__dirname, __filename);
} catch(e) {
esm = true;
}
if ( ! esm ) {
root = require('./root.cjs').APP_ROOT;
} else {
root = path.dirname(url.fileURLToPath(import.meta.url));
}
console.log({root});
export const APP_ROOT = root;