Skip to content

Commit

Permalink
debug logging for module-resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Feb 1, 2023
1 parent 4f4f811 commit d5609bc
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { emberVirtualPackages, emberVirtualPeerDeps, packageName as getPackageNa
import { dirname, resolve } from 'path';
import { PackageCache, Package, V2Package, explicitRelative } from '@embroider/shared-internals';
import { compile } from './js-handlebars';
import makeDebug from 'debug';
import assertNever from 'assert-never';

export interface Options {
renamePackages: {
Expand Down Expand Up @@ -47,6 +49,12 @@ export class Resolver {
constructor(private options: Options) {}

beforeResolve(specifier: string, fromFile: string): Resolution {
let resolution = this.internalBeforeResolve(specifier, fromFile);
debug('[%s] %s %s => %r', 'before', specifier, fromFile, resolution);
return resolution;
}

private internalBeforeResolve(specifier: string, fromFile: string): Resolution {
if (specifier === '@embroider/macros') {
// the macros package is always handled directly within babel (not
// necessarily as a real resolvable package), so we should not mess with it.
Expand All @@ -64,7 +72,9 @@ export class Resolver {
}

fallbackResolve(specifier: string, fromFile: string): Resolution {
return this.postHandleExternal(specifier, fromFile);
let resolution = this.postHandleExternal(specifier, fromFile);
debug('[%s] %s %s => %r', 'fallback', specifier, fromFile, resolution);
return resolution;
}

private owningPackage(fromFile: string): Package | undefined {
Expand Down Expand Up @@ -320,3 +330,23 @@ if (m.default && !m.__esModule) {
}
module.exports = m;
`) as (params: { moduleName: string }) => string;

const debug = makeDebug('embroider:resolver');
makeDebug.formatters.r = (r: Resolution) => {
switch (r.result) {
case 'alias':
if (r.fromFile) {
return `alias:${r.specifier} from ${r.fromFile}`;
} else {
return `alias:${r.specifier}`;
}
case 'rehome':
return `rehome:${r.fromFile}`;
case 'continue':
return 'continue';
case 'virtual':
return 'virtual';
default:
throw assertNever(r);
}
};

0 comments on commit d5609bc

Please sign in to comment.