From 3ca905174967d6339ba90aa5bc1756fbe2fafdb0 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Fri, 12 Aug 2022 12:16:19 -0500 Subject: [PATCH] [astro add] Set `output: 'server'` when adding adapter (#4289) * fix: add `output: 'server'` when setting adapter * chore: changeset --- .changeset/witty-bears-joke.md | 5 +++++ packages/astro/src/core/add/index.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 .changeset/witty-bears-joke.md diff --git a/.changeset/witty-bears-joke.md b/.changeset/witty-bears-joke.md new file mode 100644 index 000000000..65b04583d --- /dev/null +++ b/.changeset/witty-bears-joke.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +[astro add] Set `output: 'server'` when adding adapter diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index a9152654e..280c16db3 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -396,6 +396,23 @@ async function setAdapter(ast: t.File, adapter: IntegrationInfo, exportName: str const configObject = path.node.declaration.arguments[0]; if (!t.isObjectExpression(configObject)) return; + let outputProp = configObject.properties.find((prop) => { + if (prop.type !== 'ObjectProperty') return false; + if (prop.key.type === 'Identifier') { + if (prop.key.name === 'output') return true; + } + if (prop.key.type === 'StringLiteral') { + if (prop.key.value === 'output') return true; + } + return false; + }) as t.ObjectProperty | undefined; + + if (!outputProp) { + configObject.properties.push( + t.objectProperty(t.identifier('output'), t.stringLiteral('server')) + ); + } + let adapterProp = configObject.properties.find((prop) => { if (prop.type !== 'ObjectProperty') return false; if (prop.key.type === 'Identifier') {