From 45e96e5a419493a1fa36ae797af413299b54cbb9 Mon Sep 17 00:00:00 2001 From: Marine Dunstetter Date: Tue, 19 Mar 2024 17:45:59 +0100 Subject: [PATCH] make sure / and ./ can match when comparing assets URL, "normalize" the dest path of the emitted file --- packages/vite/src/assets.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/assets.ts b/packages/vite/src/assets.ts index 4f4957ad4..6d733f2a3 100644 --- a/packages/vite/src/assets.ts +++ b/packages/vite/src/assets.ts @@ -2,7 +2,7 @@ import type { Resolver } from '@embroider/core'; import { ResolverLoader } from '@embroider/core'; import type { Plugin } from 'vite'; import * as process from 'process'; -import { join } from 'path'; +import { join, posix } from 'path'; import { existsSync, readFileSync } from 'fs-extra'; import send from 'send'; import type { Readable } from 'stream'; @@ -15,7 +15,9 @@ function findPublicAsset(relativePath: string, resolver: Resolver) { for (const addon of engine.activeAddons) { pkg = packageCache.ownerOfFile(addon.root); if (pkg && pkg.meta && pkg.isV2Addon() && pkg.meta['public-assets']) { - const asset = Object.entries(pkg.meta['public-assets']).find(([_key, a]) => a === relativePath)?.[0]; + const asset = Object.entries(pkg.meta['public-assets']).find( + ([_key, a]) => posix.resolve('/', a) === relativePath + )?.[0]; let local = asset ? join(addon.root, asset) : null; if (local && existsSync(local)) { return local; @@ -66,7 +68,7 @@ export function assets(): Plugin { this.emitFile({ type: 'asset', source: readFileSync(join(pkg.root, path)), - fileName: dest.slice(1), + fileName: posix.resolve('/', dest).slice(1), }); }); });