Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EntryResolver.resolveEntry infinite loop when entries look like globs #9020

Merged
merged 6 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.