A micro helper for import.meta
data.
This module is currently redundant thanks to import.meta.dirname
and import.meta.filename
landed in NodeJS LTS.
In Bun those would be the equivalent of import.meta.dir
and import.meta.dir + '/' + import.meta.file
.
I think it'd be rather better to normalize Bun than keep parsing import.meta.url
but basically all I am saying is that this module is dead for good.
const {
dirname = import.meta.dir,
filename = `${import.meta.dir}/${import.meta.file}`,
} = import.meta;
console.log(dirname);
console.log(filename);
import umeta from 'umeta';
const {dirName, fileName, require} = umeta(import.meta);
The dirName
and fileName
respectively represent __dirname
and __filename
, while the require
utility helps importing conditionally, or on demand, CommonJS friendly modules.
There are at least two options: