Skip to content

WebReflection/umeta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

µmeta

Build Status Coverage Status

A micro helper for import.meta data.

Announcement

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.

normalization for both NodeJS and Bun

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.

How to transform import.meta for CommonJS ?

There are at least two options:

  • ascjs, based on @babel/parser
  • ucjs, based on @babel/core and with minimal dependencies (compatible with dynamic import(...) too)

About

A micro helper for import.meta data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published