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: hardcode declaration extension check #456

Merged
merged 4 commits into from
Jul 10, 2023
Merged
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
19 changes: 14 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
context.debug(() => `${blue("generated declarations")} for '${key}'`);
}

/** common resolution check -- only resolve files that aren't declarations and pass `filter` */
const shouldResolve = (id: string): boolean => {
if (id.endsWith(".d.ts") || id.endsWith(".d.cts") || id.endsWith(".d.mts"))
return false;

if (!filter(id))
return false;

return true;
}

/** to be called at the end of Rollup's build phase, before output generation */
const buildDone = (): void =>
{
Expand Down Expand Up @@ -207,10 +218,7 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
if (!resolved)
return;

if (resolved.endsWith(".d.ts"))
return;

if (!filter(resolved))
if (!shouldResolve(resolved))
return;

cache.setDependency(resolved, importer);
Expand Down Expand Up @@ -277,7 +285,8 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
// Rollup can't see these otherwise, because they are "emit-less" and produce no JS
if (result.references && supportsThisLoad) {
for (const ref of result.references) {
if (!filter(ref))
// pre-emptively filter out files that we don't resolve ourselves (e.g. declarations). don't add new files to Rollup's pipeline if we can't resolve them
if (!shouldResolve(ref))
continue;

const module = await this.resolve(ref, id);
Expand Down