Skip to content

Commit

Permalink
back out the vite-specific prefix matching hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Dec 19, 2024
1 parent cef16b4 commit e328a22
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 40 deletions.
36 changes: 4 additions & 32 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,7 @@ export class Resolver {
}

private handleImplicitTestScripts<R extends ModuleRequest>(request: R): R {
//TODO move the extra forwardslash handling out into the vite plugin
const candidates = [
'@embroider/virtual/test-support.js',
'/@embroider/virtual/test-support.js',
'./@embroider/virtual/test-support.js',
];

if (!candidates.includes(request.specifier)) {
if (request.specifier !== '@embroider/virtual/test-support.js') {
return request;
}

Expand All @@ -427,14 +420,7 @@ export class Resolver {
}

private handleTestSupportStyles<R extends ModuleRequest>(request: R): R {
//TODO move the extra forwardslash handling out into the vite plugin
const candidates = [
'@embroider/virtual/test-support.css',
'/@embroider/virtual/test-support.css',
'./@embroider/virtual/test-support.css',
];

if (!candidates.includes(request.specifier)) {
if (request.specifier !== '@embroider/virtual/test-support.css') {
return request;
}

Expand Down Expand Up @@ -485,14 +471,7 @@ export class Resolver {
}

private handleVendorStyles<R extends ModuleRequest>(request: R): R {
//TODO move the extra forwardslash handling out into the vite plugin
const candidates = [
'@embroider/virtual/vendor.css',
'/@embroider/virtual/vendor.css',
'./@embroider/virtual/vendor.css',
];

if (!candidates.includes(request.specifier)) {
if (request.specifier !== '@embroider/virtual/vendor.css') {
return request;
}

Expand Down Expand Up @@ -958,14 +937,7 @@ export class Resolver {
}

private handleVendor<R extends ModuleRequest>(request: R): R {
//TODO move the extra forwardslash handling out into the vite plugin
const candidates = [
'@embroider/virtual/vendor.js',
'/@embroider/virtual/vendor.js',
'./@embroider/virtual/vendor.js',
];

if (!candidates.includes(request.specifier)) {
if (request.specifier !== '@embroider/virtual/vendor.js') {
return request;
}

Expand Down
14 changes: 6 additions & 8 deletions packages/core/src/virtual-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ export function virtualEntrypoint(
request: ModuleRequest,
packageCache: PackageCachePublicAPI
): VirtualResponse | undefined {
//TODO move the extra forwardslash handling out into the vite plugin
const candidates = [
'@embroider/virtual/compat-modules',
'/@embroider/virtual/compat-modules',
'./@embroider/virtual/compat-modules',
];

if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) {
const compatModulesSpecifier = '@embroider/virtual/compat-modules';

let isCompatModules =
request.specifier === compatModulesSpecifier || request.specifier.startsWith(compatModulesSpecifier + '/');

if (!isCompatModules) {
return undefined;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/vite/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export class RollupRequestAdapter implements RequestAdapter<Resolution<ResolveId
let fromFile = cleanUrl(importer);
let importerQueryParams = getUrlQueryParams(importer);

if (source.startsWith('/@embroider/virtual/')) {
// when our virtual paths are used in HTML they come into here with a /
// prefix. We still want them to resolve like packages.
source = source.slice(1);
}

// strip query params off the source but keep track of them
// we use regexp-based methods over a URL object because the
// source can be a relative path.
Expand Down

0 comments on commit e328a22

Please sign in to comment.