Skip to content

Commit

Permalink
Fix EntryResolver.resolveEntry infinite loop when entries look like g…
Browse files Browse the repository at this point in the history
…lobs (#9020)
  • Loading branch information
hacknlove authored Jun 3, 2023
1 parent 2a73cd2 commit 0645f64
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/core/core/src/requests/EntryRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,17 @@ export class EntryResolver {
}

async resolveEntry(entry: FilePath): Promise<EntryResult> {
if (isGlob(entry)) {
let stat;
try {
stat = await this.options.inputFS.stat(entry);
} catch (err) {
if (!isGlob(entry)) {
throw new ThrowableDiagnostic({
diagnostic: {
message: md`Entry ${entry} does not exist`,
},
});
}
let files = await glob(entry, this.options.inputFS, {
absolute: true,
onlyFiles: false,
Expand All @@ -171,17 +181,6 @@ export class EntryResolver {
);
}

let stat;
try {
stat = await this.options.inputFS.stat(entry);
} catch (err) {
throw new ThrowableDiagnostic({
diagnostic: {
message: md`Entry ${entry} does not exist`,
},
});
}

if (stat.isDirectory()) {
let pkg = await this.readPackage(entry);

Expand Down
9 changes: 9 additions & 0 deletions packages/core/core/test/EntryRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const INVALID_TARGET_SOURCE_NOT_FILE_FIXTURE_PATH = path.join(
'fixtures/invalid-target-source-not-file',
);

const GLOB_LIKE_FIXTURE_PATH = path.join(
__dirname,
'fixtures/glob-like/[entry].js',
);

describe('EntryResolver', function () {
let entryResolver = new EntryResolver({...DEFAULT_OPTIONS});

Expand Down Expand Up @@ -203,4 +208,8 @@ describe('EntryResolver', function () {
},
);
});
it('does not time out on glob-like entry', async function () {
this.timeout(10000);
await entryResolver.resolveEntry(GLOB_LIKE_FIXTURE_PATH);
});
});
Empty file.

0 comments on commit 0645f64

Please sign in to comment.