Registry / devops / esbuild-plugin-fileloc

esbuild-plugin-fileloc

JSON →
library0.0.6jsnpmunverified

An esbuild plugin that replaces __dirname, __filename, __line, __relativedirname, and __relativefilename with actual source file metadata at build time. Version 0.0.6, no release cadence documented. Unlike Node.js's __dirname (which resolves to the output file), this plugin provides the original source path, and the __line variable is unique among Node-like bundlers. Ships TypeScript declarations. Lightweight, no dependencies. Suitable for esbuild bundling projects that need source-level location globals.

devops
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESM default import is the correct way. CJS require with destructuring of default fails because the package is ESM.

import filelocPlugin from 'esbuild-plugin-fileloc'

The default export is a factory function that must be called (with no arguments) to create the plugin instance.

import filelocPlugin from 'esbuild-plugin-fileloc'; esbuild.build({ plugins: [filelocPlugin()], })

Types are declared as ambient globals via a triple-slash reference. Direct import of types is not supported.

/// <reference types="esbuild-plugin-fileloc" />

Build a TypeScript file with esbuild and replace __dirname, __filename, __line, etc. with source location values.

import esbuild from 'esbuild'; import filelocPlugin from 'esbuild-plugin-fileloc'; await esbuild.build({ entryPoints: ['src/index.ts'], outfile: 'dist/bundle.js', bundle: true, plugins: [filelocPlugin()], });
Debug
Known footguns
gotchaPlugin must be called as a function: filelocPlugin() not filelocPlugin
gotchaGlobal variables are only replaced in files processed by esbuild; they are not polyfilled at runtime
gotchaType declarations require triple-slash reference; importing the module does not augment global scope
deprecatedNo known deprecations as of v0.0.6.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
12 hits · last 30 days
gptbot
4
ahrefsbot
4
claudebot
3
script
1
Resources