Skip to content

Commit

Permalink
make sure / and ./ can match when comparing assets URL, "normalize" t…
Browse files Browse the repository at this point in the history
…he dest path of the emitted file
  • Loading branch information
BlueCutOfficial committed Mar 26, 2024
1 parent 659abf2 commit 45e96e5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vite/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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),
});
});
});
Expand Down

0 comments on commit 45e96e5

Please sign in to comment.