v0.0.4
Node.js + Gjs + Deno module that returns the current script dirname. Similar to __dirname but also works in CommonJs and ES modules.
Repository
Current version released
4 years ago
cross-dirname
Node.js / Gjs / Deno module that returns the current script dirname. Similar to __dirname but also works in CommonJs and ES modules.
Installation
On Node.js you can install the package as usual with NPM:
npm install cross-dirname --saveOn Deno you just need to import this package:
import dirname from "https://deno.land/x/cross_dirname/mod.ts";Usage
/path/to/the/script.mjs
import dirname from 'cross-dirname'
console.log(dirname()) // outputs "/path/to/the"CommonJs
console.log(require('cross-dirname')() === __dirname) // trueContributions
Contributions for more platforms are welcome :)
Tests
This module has been tested on the following platforms:
| Runtime | Type | Platform | State |
|---|---|---|---|
| Node.js | CJS | Linux | β |
| Node.js | CJS | MacOS | β |
| Node.js | CJS | Windows | β |
| Node.js | ESM | Linux | β |
| Node.js | ESM | MacOS | β |
| Node.js | ESM | Windows | β |
| Deno | ESM | Linux | β |
| Deno | ESM | MacOS | β |
| Deno | ESM | Windows | β |
| Gjs | ESM | Linux | β |
| Gjs | ESM | MacOS | UNTESTED |
| Gjs | ESM | Windows | UNTESTED |
| Gjs | NO-ESM | Linux | TODO |
| Gjs | NO-ESM | MacOS | TODO |
| Gjs | NO-ESM | Windows | TODO |
You can run all tests with:
npm run testOr the tests for a special runtime:
npm run test:node
npm run test:deno
npm run test:gjs