Public commit

This commit is contained in:
Alex
2023-08-03 20:06:58 -04:00
commit d96c6c7caf
333 changed files with 44633 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import { basename, dirname } from "path"
import type { BabelPlugin } from "./esbuild-babel"
export const fileName =
({
hasFileName,
hasDirName,
path,
}: {
hasFileName: boolean
hasDirName: boolean
path: string
}): BabelPlugin =>
({ types: t }) => ({
name: "__filename polyfill",
visitor: {
Program(program) {
const assign = (id: string, value: string) =>
t.variableDeclaration("var", [
t.variableDeclarator(t.identifier(id), t.stringLiteral(value)),
])
if (hasFileName) {
program.node.body.unshift(assign("__filename", basename(path)))
}
if (hasDirName) {
program.node.body.unshift(assign("__dirname", dirname(path)))
}
},
},
})