From 8fea53fee83e01f292ae639b20eb02af9ae9cb96 Mon Sep 17 00:00:00 2001 From: dpiercey Date: Thu, 11 Apr 2024 08:45:50 -0700 Subject: [PATCH] fix: avoid asset transforms when not in linked mode --- .changeset/proud-spiders-applaud.md | 5 +++++ src/index.ts | 4 ++++ src/render-assets-transform.ts | 10 ++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .changeset/proud-spiders-applaud.md diff --git a/.changeset/proud-spiders-applaud.md b/.changeset/proud-spiders-applaud.md new file mode 100644 index 0000000..0b499f0 --- /dev/null +++ b/.changeset/proud-spiders-applaud.md @@ -0,0 +1,5 @@ +--- +"@marko/vite": patch +--- + +Fix issue where asset related Marko taglibs / transforms were registered when not in linked mode (eg in tests) diff --git a/src/index.ts b/src/index.ts index 6a8788c..8844afd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -209,6 +209,10 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] { output: "html", }; + if (linked) { + (ssrConfig as any).markoViteLinked = linked; + } + ssrCjsServeConfig = { ...ssrConfig, ast: true, diff --git a/src/render-assets-transform.ts b/src/render-assets-transform.ts index afc9b0f..54d61fe 100644 --- a/src/render-assets-transform.ts +++ b/src/render-assets-transform.ts @@ -1,9 +1,11 @@ import type { types } from "@marko/compiler"; export default (tag: types.NodePath, t: typeof types) => { - const body = tag.get("body"); - const tagName = (tag.get("name").node as types.StringLiteral).value; - body.unshiftContainer("body", renderAssetsCall(t, `${tagName}-prepend`)); - body.pushContainer("body", renderAssetsCall(t, tagName)); + if ((tag.hub.file.markoOpts as any).markoViteLinked) { + const body = tag.get("body"); + const tagName = (tag.get("name").node as types.StringLiteral).value; + body.unshiftContainer("body", renderAssetsCall(t, `${tagName}-prepend`)); + body.pushContainer("body", renderAssetsCall(t, tagName)); + } }; function renderAssetsCall(t: typeof types, slot: string) {