diff --git a/.mocharc.json b/.mocharc.json index 1d7aafc..ac6b5ab 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -3,5 +3,5 @@ "extension": ["js", "ts"], "enable-source-maps": true, "watchFiles": ["src/**/*.ts"], - "require": ["./esbuild-register", "mocha-snap"] + "require": ["esbuild-register", "mocha-snap"] } diff --git a/build.ts b/build.ts index 58f289e..8e3d4d6 100644 --- a/build.ts +++ b/build.ts @@ -33,7 +33,6 @@ import { build, BuildOptions } from "esbuild"; build({ ...opts, format: "cjs", - define: { "import.meta.url": "__filename" }, }), build({ ...opts, diff --git a/esbuild-register.js b/esbuild-register.js deleted file mode 100644 index 315c5ba..0000000 --- a/esbuild-register.js +++ /dev/null @@ -1,4 +0,0 @@ -require("esbuild-register/dist/node").register({ - target: ["node14"], - define: { "import.meta.url": "__filename" }, -}); diff --git a/src/index.ts b/src/index.ts index 3d9c638..915dd6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,8 +5,8 @@ import os from "os"; import fs from "fs"; import path from "path"; import crypto from "crypto"; -import { pathToFileURL } from "url"; import anyMatch from "anymatch"; +import { pathToFileURL, fileURLToPath } from "url"; import getServerEntryTemplate from "./server-entry-template"; import { generateInputDoc, @@ -46,6 +46,8 @@ const virtualFileQuery = "?marko-virtual"; const markoExt = ".marko"; const htmlExt = ".html"; const resolveOpts = { skipSelf: true }; +const thisFile = + typeof __filename === "string" ? __filename : fileURLToPath(import.meta.url); let tempDir: Promise | undefined; export default function markoPlugin(opts: Options = {}): vite.Plugin[] { @@ -125,11 +127,11 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] { if (!registeredTag) { // Here we inject either the watchMode vite tag, or the build one. const transformer = path.resolve( - import.meta.url, + thisFile, "../render-assets-transform" ); registeredTag = path.resolve( - import.meta.url, + thisFile, "../components", isBuild ? "vite.marko" : "vite-watch.marko" );