From 847ade399f5f845f066d5d73bd05e4dc32698e2d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 25 Jun 2023 17:08:35 -0400 Subject: [PATCH] refactor: move dir check to separate file to be dynamically loaded if esm --- src/index.ts | 6 ++---- src/path.ts | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 src/path.ts diff --git a/src/index.ts b/src/index.ts index 6abadfd..da8cb5b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,11 @@ -import { dirname, resolve } from "node:path"; -import { fileURLToPath } from "node:url"; +import { resolve } from "node:path"; import type { PresetAsset } from "presetter-types"; let DIR: string; if (typeof __dirname === "undefined") { - // @ts-ignore - DIR = dirname(fileURLToPath(import.meta.url)); + DIR = (await import("./path.js")).default(); } else { DIR = __dirname; } diff --git a/src/path.ts b/src/path.ts new file mode 100644 index 0000000..11d9426 --- /dev/null +++ b/src/path.ts @@ -0,0 +1,6 @@ +import { dirname } from "node:path"; +import { fileURLToPath } from "node:url"; + +export default function () { + return dirname(fileURLToPath(import.meta.url)); +}