Skip to content

Commit

Permalink
fix rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Sep 12, 2024
1 parent a40e0d8 commit 9c9c6c6
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 560 deletions.
32 changes: 7 additions & 25 deletions packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
packageName as getPackageName,
packageName,
} from '@embroider/shared-internals';
import { dirname, resolve, posix, extname } from 'path';
import { dirname, resolve, posix } from 'path';
import type { Package, V2Package } from '@embroider/shared-internals';
import { explicitRelative, RewrittenPackageCache } from '@embroider/shared-internals';
import makeDebug from 'debug';
Expand Down Expand Up @@ -194,7 +194,6 @@ export class Resolver {
return this.external('early require', request, request.specifier);
}

request = this.decodeEncodedRequest(request);
request = this.handleFastbootSwitch(request);
request = await this.handleGlobalsCompat(request);
request = this.handleImplicitModules(request);
Expand Down Expand Up @@ -283,22 +282,6 @@ export class Resolver {
return RewrittenPackageCache.shared('embroider', this.options.appRoot);
}

generateEncodedRequest<R extends ModuleRequest>(request: R): R {
let prefix = '@embroider/encoded-request/';
let specifier = `${prefix}${request.fromFile}/-embroider-to-/${request.specifier}`;
return request.alias(specifier);
}

decodeEncodedRequest<R extends ModuleRequest>(request: R): R {
let prefix = '@embroider/encoded-request/';
if (request.specifier.startsWith(prefix)) {
let specifier = request.specifier.slice(prefix.length);
let [from, to] = specifier.split('/-embroider-to-/');
return request.alias(to).rehome(from);
}
return request;
}

private logicalPackage(owningPackage: V2Package, file: string): V2Package {
let logicalLocation = this.reverseSearchAppTree(owningPackage, file);
if (logicalLocation) {
Expand Down Expand Up @@ -1410,11 +1393,8 @@ export class Resolver {
if (pkg.needsLooseResolving()) {
let activeAddon = this.maybeFallbackToActiveAddon(request, packageName);
if (activeAddon) {
const rehomed = request.rehome(activeAddon.canResolveFromFile);
if (rehomed !== request) {
let newRequest = this.makeResolvable(rehomed);
return logTransition(`activeAddons`, request, newRequest);
}
let newRequest = this.makeResolvable(activeAddon);
return logTransition(`activeAddons`, request, newRequest);
}
}

Expand All @@ -1440,7 +1420,8 @@ export class Resolver {
if (targetingEngine) {
let appJSMatch = await this.searchAppTree(request, targetingEngine, request.specifier.replace(packageName, '.'));
if (appJSMatch) {
return logTransition('fallbackResolve: non-relative appJsMatch', request, appJSMatch);
let resolvable = this.makeResolvable(appJSMatch);
return logTransition('fallbackResolve: non-relative appJsMatch', request, resolvable);
}
}

Expand Down Expand Up @@ -1495,7 +1476,8 @@ export class Resolver {
}
let appJSMatch = await this.searchAppTree(request, withinEngine, logicalName);
if (appJSMatch) {
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch);
let resolvable = this.makeResolvable(appJSMatch);
return logTransition('fallbackResolve: relative appJsMatch', request, resolvable);
} else {
return logTransition('fallbackResolve: relative appJs search failure', request);
}
Expand Down
30 changes: 0 additions & 30 deletions packages/vite/src/esbuild-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ export function esBuildResolver(): EsBuildPlugin {
switch (resolution.type) {
case 'found':
case 'ignored':
// _app_ files in addons are part of the app, they should not be externalized
if (resolution.result.path) {
let pkg = resolverLoader.resolver.packageCache.ownerOfFile(resolution.result.path);
if (pkg?.isV2Addon()) {
resolverLoader.resolver.reverseSearchAppTree(pkg, resolution.result.path);
if (resolution.result.path?.includes('_app_')) {
resolution.result.external = false;
}
}
}
return resolution.result;
case 'not_found':
return resolution.err;
Expand Down Expand Up @@ -146,26 +136,6 @@ export function esBuildResolver(): EsBuildPlugin {
return firstResult;
});
}
const extensions = ['', '.hbs'];
for (const extension of extensions) {
let result = await build.resolve(path + extension, {
namespace,
resolveDir,
importer,
kind,
// avoid reentrance
pluginData: { ...pluginData, embroiderExtensionResolving: true },
});
if (result.errors.length) continue;
if (result.errors.length === 0 && !result.external) {
let syntheticPath = needsSyntheticComponentJS(path, result.path, resolverLoader.resolver.packageCache);
if (syntheticPath) {
return { path: syntheticPath, namespace: 'embroider-template-only-component' };
}
}
return result;
}
});

// we need to handle everything from one of our three special namespaces:
build.onLoad({ namespace: 'embroider-template-only-component', filter: /./ }, onLoad);
Expand Down
Loading

0 comments on commit 9c9c6c6

Please sign in to comment.