Skip to content

Commit

Permalink
allow entrypoints to be referenced from outside
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed May 9, 2024
1 parent 11b4212 commit caf0337
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/compat/src/compat-app-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ let d = w.define;
import "ember-testing";
import "#embroider/core/entrypoint";
import "@embroider/core/entrypoint";
{{#each amdModules as |amdModule| ~}}
d("{{js-string-escape amdModule.runtime}}", function(){ return i("{{js-string-escape amdModule.buildtime}}");});
Expand Down
30 changes: 21 additions & 9 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,35 @@ export class Resolver {
// just like implicit-modules does.

//TODO move the extra forwardslash handling out into the vite plugin
const candidates = [
'#embroider/core/entrypoint',
'@embroider/core/entrypoint',
'/@embroider/core/entrypoint',
'./@embroider/core/entrypoint',
];
const candidates = ['@embroider/core/entrypoint', '/@embroider/core/entrypoint', './@embroider/core/entrypoint'];

if (!candidates.includes(request.specifier)) {
if (!candidates.some(c => request.specifier.startsWith(c + '/') || request.specifier === c)) {
return request;
}

let pkg = this.packageCache.ownerOfFile(request.fromFile);
const result = /\.?\/?@embroider\/core\/entrypoint(?:\/(?<packageName>.*))?/.exec(request.specifier);

if (!pkg?.isV2Ember()) {
if (!result) {
// TODO make a better error
throw new Error('entrypoint does not match pattern' + request.specifier);
}

const { packageName } = result.groups!;

const requestingPkg = this.packageCache.ownerOfFile(request.fromFile);

if (!requestingPkg?.isV2Ember()) {
throw new Error(`bug: found entrypoint import in non-ember package at ${request.fromFile}`);
}

let pkg;

if (packageName) {
pkg = this.packageCache.resolve(packageName, requestingPkg);
} else {
pkg = requestingPkg;
}

return logTransition('entrypoint', request, request.virtualize(resolve(pkg.root, '-embroider-entrypoint.js')));
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/virtual-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ export function renderEntrypoint(
let lazyEngines: { names: string[]; path: string }[] = [];

if (isApp) {
// deliberately ignoring the app
// deliberately ignoring the app (which is the first entry in the engines array)
let [, ...childEngines] = resolver.options.engines;
for (let childEngine of childEngines) {
let target = `${childEngine.packageName}/-embroider-entrypoint.js`;
let target = `@embroider/core/entrypoint/${childEngine.packageName}`;

if (childEngine.isLazy) {
lazyEngines.push({
Expand Down Expand Up @@ -276,7 +276,7 @@ export function importPaths(resolver: Resolver, { engine }: AppFiles, engineRela
let noHBS = engineRelativePath.replace(resolvableExtensionsPattern, '').replace(/\.hbs$/, '');
return {
runtime: `${engine.modulePrefix}/${noHBS}`,
buildtime: `@embroider-dep/${posix.join(engine.package.name, engineRelativePath)}`,
buildtime: `./${engineRelativePath}`,
};
}

Expand Down

0 comments on commit caf0337

Please sign in to comment.