Skip to content

Commit

Permalink
fix(add): Use proper export names when adding adapters (#11935)
Browse files Browse the repository at this point in the history
* fix(add): Use proper export names when adding adapters

* chore: changeset
  • Loading branch information
Princesseuh authored Sep 6, 2024
1 parent 65bfefb commit c58193a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-bulldogs-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes `astro add` not using the proper export point when adding certain adapters
10 changes: 7 additions & 3 deletions packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export async function add(names: string[], { flags }: AddOptions) {
if (isAdapter(integration)) {
const officialExportName = OFFICIAL_ADAPTER_TO_IMPORT_MAP[integration.id];
if (officialExportName) {
setAdapter(mod, integration);
setAdapter(mod, integration, officialExportName);
} else {
logger.info(
'SKIP_FORMAT',
Expand Down Expand Up @@ -447,15 +447,19 @@ function addIntegration(mod: ProxifiedModule<any>, integration: IntegrationInfo)
}
}

export function setAdapter(mod: ProxifiedModule<any>, adapter: IntegrationInfo) {
export function setAdapter(
mod: ProxifiedModule<any>,
adapter: IntegrationInfo,
exportName: string,
) {
const config = getDefaultExportOptions(mod);
const adapterId = toIdent(adapter.id);

if (!mod.imports.$items.some((imp) => imp.local === adapterId)) {
mod.imports.$append({
imported: 'default',
local: adapterId,
from: adapter.packageName,
from: exportName,
});
}

Expand Down

0 comments on commit c58193a

Please sign in to comment.