From 8a584b3fa1eb20fa24912cccb17c815c92cf0830 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Fri, 13 Dec 2024 16:22:43 -0700 Subject: [PATCH] fix: issue with tags api detection (#179) --- .changeset/healthy-bees-burn.md | 5 +++++ src/index.ts | 27 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 .changeset/healthy-bees-burn.md diff --git a/.changeset/healthy-bees-burn.md b/.changeset/healthy-bees-burn.md new file mode 100644 index 0000000..1f1f804 --- /dev/null +++ b/.changeset/healthy-bees-burn.md @@ -0,0 +1,5 @@ +--- +"@marko/vite": patch +--- + +Fix tags api detection diff --git a/src/index.ts b/src/index.ts index 22a6414..67f01bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -151,11 +151,7 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] { let serverManifest: ServerManifest | undefined; let basePath = "/"; let getMarkoAssetFns: undefined | API.getMarkoAssetCodeForEntry[]; - const tagsAPI = !/^@marko\/translator-(?:default|interop-class-tags)$/.test( - opts.translator || - compiler.globalConfig?.translator || - "@marko/translator-default", - ); + let tagsAPI: undefined | boolean; const entryIds = new Set(); const cachedSources = new Map(); const transformWatchFiles = new Map(); @@ -652,6 +648,27 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] { } } + if (tagsAPI === undefined) { + const translatorPackage = + opts.translator || + compiler.globalConfig?.translator || + "marko/translator"; + if ( + /^@marko\/translator-(?:default|interop-class-tags)$/.test( + translatorPackage, + ) + ) { + tagsAPI = false; + } else { + try { + tagsAPI = + (await import(translatorPackage)).preferAPI !== "class"; + } catch { + tagsAPI = true; + } + } + } + source = await getServerEntryTemplate({ fileName, entryData,