Skip to content

Commit

Permalink
fix: esbuild discovery can't find module installed in project (#234)
Browse files Browse the repository at this point in the history
Fixes #233
  • Loading branch information
mrgrain authored Aug 24, 2022
1 parent 4811172 commit 58d7604
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/dynamic-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,43 @@ export class DynamicPackage {
}
}

public auto() {
public auto(): string {
return this.tryResolve() || this.findInPaths() || this.install();
}

public nodeJs() {
public nodeJs(): string {
return this.name;
}

public findIn(paths: string[]) {
public findIn(paths: string[]): string | undefined {
paths.forEach((p) => process.stderr.write('trying... '+p+'\n'));
process.stderr.write('\n');

return this.tryResolve([...paths].filter(Boolean) as string[]);
}

public findInPaths() {
public findInPaths(): string | undefined {
return (
this.findInSearchPaths() ||
this.findInLocalPaths() ||
this.findInGlobalPaths()
);
}

public findInSearchPaths() {
public findInSearchPaths(): string | undefined {
return this.findIn(this.searchPaths);
}

public findInLocalPaths() {
this.findIn([process.cwd(), process.env.PWD].filter(Boolean) as string[]);
public findInLocalPaths(): string | undefined {
return this.findIn([
process.cwd(),
process.env.PWD,
resolve(process.env.PWD || process.cwd(), 'node_modules'),
resolve(process.cwd(), 'node_modules'),
].filter(Boolean) as string[]);
}

public findInGlobalPaths() {
public findInGlobalPaths(): string | undefined {
return this.findIn([
process.execPath,
resolve(process.execPath, '../..'),
Expand All @@ -104,7 +112,7 @@ export class DynamicPackage {
}

private static installedPackagePath = new Map();
public install() {
public install(): string {
return Lazy.string({
produce: () => {
if (!DynamicPackage.installedPackagePath.has(this.spec)) {
Expand Down

0 comments on commit 58d7604

Please sign in to comment.