Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Sep 14, 2024
1 parent d2fd327 commit dcd8752
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 6 additions & 5 deletions packages/core/src/virtual-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,21 @@ function decodeVirtualPairComponent(
};
}

const appJsMatchPrefix = '/embroider_appjs_match/';
const appJsMatchPattern = /\/embroider_appjs_match\/(?<original>.+)$/;
const appJsMatchMarker = '__embroider_appjs_match__';
const appJsMatchPattern = /(?<from>.+)__embroider_appjs_match__(?<to>.+)$/;
export function encodeAppJsMatch(specifier: string, fromFile: string): string {
return `${appJsMatchPrefix}${fromFile}::${specifier}`;
return `${fromFile}${appJsMatchMarker}${encodeURIComponent(specifier)}`;
}

export function decodeAppJsMatch(filename: string) {
// Performance: avoid paying regex exec cost unless needed
if (!filename.includes(appJsMatchPrefix)) {
if (!filename.includes(appJsMatchMarker)) {
return;
}
let match = appJsMatchPattern.exec(filename);
if (match) {
let [from, to] = match.groups!.original.split('::');
let from = match.groups!.from;
let to = decodeURIComponent(match.groups!.to);
console.log('from', from, to);
return {
filename: require.resolve(to, {
Expand Down
14 changes: 7 additions & 7 deletions tests/scenarios/core-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ Scenarios.fromProject(() => new Project())
expectAudit
.module('./app.js')
.resolves('my-app/hello-world')
.to('./package.json::my-addon/_app_/hello-world.js/embroider_appjs_match');
.to('./package.json__embroider_appjs_match__my-addon%2F_app_%2Fhello-world.js');
});

test('app-js module in addon can still do relative imports that escape its package', async function () {
Expand All @@ -527,7 +527,7 @@ Scenarios.fromProject(() => new Project())
});

expectAudit
.module('./package.json::my-addon/_app_/hello-world.js/embroider_appjs_match')
.module('./package.json__embroider_appjs_match__my-addon%2F_app_%2Fhello-world.js')
.resolves('../../extra.js')
.to('./node_modules/extra.js');
});
Expand All @@ -547,7 +547,7 @@ Scenarios.fromProject(() => new Project())
expectAudit
.module('./app.js')
.resolves('my-app/templates/hello-world')
.to('./package.json::my-addon/_app_/templates/hello-world.hbs/embroider_appjs_match');
.to('./package.json__embroider_appjs_match__my-addon%2F_app_%2Ftemplates%2Fhello-world.hbs');
});

test(`relative import in addon's app tree resolves to app`, async function () {
Expand All @@ -564,7 +564,7 @@ Scenarios.fromProject(() => new Project())
});

expectAudit
.module('./package.json::my-addon/_app_/hello-world.js/embroider_appjs_match')
.module('./package.json__embroider_appjs_match__my-addon%2F_app_%2Fhello-world.js')
.resolves('./secondary')
.to('./secondary.js');
});
Expand All @@ -584,7 +584,7 @@ Scenarios.fromProject(() => new Project())
});

expectAudit
.module('./package.json::my-addon/_app_/hello-world.js/embroider_appjs_match')
.module('./package.json__embroider_appjs_match__my-addon%2F_app_%2Fhello-world.js')
.resolves('./secondary')
.to('./secondary.js');
});
Expand All @@ -602,7 +602,7 @@ Scenarios.fromProject(() => new Project())
});

expectAudit
.module('./package.json::my-addon/_app_/hello-world.js/embroider_appjs_match')
.module('./package.json__embroider_appjs_match__my-addon%2F_app_%2Fhello-world.js')
.resolves('the-apps-dep')
.to('./node_modules/the-apps-dep/index.js');
});
Expand All @@ -621,7 +621,7 @@ Scenarios.fromProject(() => new Project())
});

expectAudit
.module('./package.json::my-addon/_app_/hello-world.js/embroider_appjs_match')
.module('./package.json__embroider_appjs_match__my-addon%2F_app_%2Fhello-world.js')
.resolves('my-app/secondary')
.to('./secondary.js');
});
Expand Down

0 comments on commit dcd8752

Please sign in to comment.