From 2b702d6abaa296c0eb77d3fd1a8231a186341b1f Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Fri, 22 Apr 2022 15:17:16 -0400 Subject: [PATCH] Fix: `astro add` generating config outside project root (#3186) * fix: astro.config generated outside project dir * chore: changeset --- .changeset/warm-days-wash.md | 5 +++++ packages/astro/src/core/add/index.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/warm-days-wash.md diff --git a/.changeset/warm-days-wash.md b/.changeset/warm-days-wash.md new file mode 100644 index 000000000..1786fa814 --- /dev/null +++ b/.changeset/warm-days-wash.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix: astro add generating "astro.config.mjs" outside project root diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index 5de4cf2c2..5dd6b5caa 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -19,6 +19,7 @@ import { parseNpmName } from '../util.js'; import { wrapDefaultExport } from './wrapper.js'; import { ensureImport } from './imports.js'; import { t, parse, visit, generate } from './babel.js'; +import { appendForwardSlash } from '../path.js'; export interface AddOptions { logging: LogOptions; @@ -91,7 +92,7 @@ export default async function add(names: string[], { cwd, flags, logging }: AddO debug('add', `Found config at ${configURL}`); } else { info(logging, 'add', `Unable to locate a config file, generating one for you.`); - configURL = new URL('./astro.config.mjs', root); + configURL = new URL('./astro.config.mjs', appendForwardSlash(root.href)); await fs.writeFile(fileURLToPath(configURL), CONSTS.CONFIG_STUB, { encoding: 'utf-8' }); }