Skip to content

Commit

Permalink
fix hbs
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Mar 19, 2024
1 parent 0b1f6f7 commit 7bc2c27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 3 additions & 5 deletions packages/core/src/virtual-content.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { dirname, basename, resolve, posix, sep, join } from 'path';
import { Resolver, AddonPackage, Package, cleanUrl } from '.';
import type { Resolver, AddonPackage, Package } from '.';
import { explicitRelative, extensionsPattern } from '.';
import { compile } from './js-handlebars';
import { cleanUrl } from '.';

const externalESPrefix = '/@embroider/ext-es/';
const externalCJSPrefix = '/@embroider/ext-cjs/';
Expand Down Expand Up @@ -139,12 +138,11 @@ const pairComponentMarker = '-embroider-pair-component';
const pairComponentPattern = /^(?<hbsModule>.*)\/(?<jsModule>[^\/]*)-embroider-pair-component$/;

export function virtualPairComponent(hbsModule: string, jsModule: string | undefined): string {
let clearHbsModule = cleanUrl(hbsModule);
let relativeJSModule = '';
if (jsModule) {
relativeJSModule = explicitRelative(clearHbsModule, jsModule);
relativeJSModule = explicitRelative(hbsModule, jsModule);
}
return `${clearHbsModule}/${encodeURIComponent(relativeJSModule)}${pairComponentMarker}`;
return `${hbsModule}/${encodeURIComponent(relativeJSModule)}${pairComponentMarker}`;
}

function decodeVirtualPairComponent(
Expand Down
9 changes: 6 additions & 3 deletions packages/vite/src/hbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ async function maybeSynthesizeComponentJS(context: PluginContext, source: string
return null;
}

const pkg = resolverLoader.resolver.packageCache.ownerOfFile(templateResolution.id);
const isInComponents = pkg?.isV2App() && templateResolution.id.slice(pkg?.root.length).startsWith('/components');
const resolvedId = templateResolution.id.split('?')[0];
templateResolution.id = resolvedId;

if (templateResolution.id.endsWith('/template.hbs' || !isInComponents)) {
const pkg = resolverLoader.resolver.packageCache.ownerOfFile(resolvedId);
const isInComponents = pkg?.isV2App() && resolvedId.slice(pkg?.root.length).startsWith('/components');

if (resolvedId.endsWith('/template.hbs' || !isInComponents)) {
return {
...templateResolution,
meta: {
Expand Down

0 comments on commit 7bc2c27

Please sign in to comment.