Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/fuzzy-news-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Fixes a case where a deprecation warning would be shown on Node 24
4 changes: 2 additions & 2 deletions packages/create-astro/src/actions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getName, getVersion } from '../messages.js';
export interface Context {
help: boolean;
prompt: typeof prompt;
cwd: string;
cwd?: string;
packageManager: string;
username: Promise<string>;
version: Promise<string>;
Expand Down Expand Up @@ -75,7 +75,7 @@ export async function getContext(argv: string[]): Promise<Context> {
);

const packageManager = detectPackageManager() ?? 'npm';
let cwd = flags['_'][0];
let cwd = flags['_'].at(0);
let {
'--help': help = false,
'--template': template,
Expand Down
4 changes: 2 additions & 2 deletions packages/create-astro/src/actions/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function dependencies(
)} to install them manually after setup.`,
);
},
while: () => install({ packageManager: ctx.packageManager, cwd: ctx.cwd }),
while: () => install({ packageManager: ctx.packageManager, cwd: ctx.cwd! }),
});

let add = ctx.add;
Expand All @@ -65,7 +65,7 @@ export async function dependencies(
);
},
while: () =>
astroAdd({ integrations: add, packageManager: ctx.packageManager, cwd: ctx.cwd }),
astroAdd({ integrations: add, packageManager: ctx.packageManager, cwd: ctx.cwd! }),
});
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-astro/src/actions/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Context } from './context.js';
export async function git(
ctx: Pick<Context, 'cwd' | 'git' | 'yes' | 'prompt' | 'dryRun' | 'tasks'>,
) {
if (fs.existsSync(path.join(ctx.cwd, '.git'))) {
if (fs.existsSync(path.join(ctx.cwd!, '.git'))) {
await info('Nice!', `Git has already been initialized`);
return;
}
Expand All @@ -32,7 +32,7 @@ export async function git(
start: 'Git initializing...',
end: 'Git initialized',
while: () =>
init({ cwd: ctx.cwd }).catch((e) => {
init({ cwd: ctx.cwd! }).catch((e) => {
error('error', e);
process.exit(1);
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/create-astro/src/actions/next-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Context } from './context.js';
export async function next(
ctx: Pick<Context, 'hat' | 'tie' | 'cwd' | 'packageManager' | 'skipHouston'>,
) {
let projectDir = path.relative(process.cwd(), ctx.cwd);
let projectDir = path.relative(process.cwd(), ctx.cwd!);

const commandMap: { [key: string]: string } = {
npm: 'npm run dev',
Expand Down
2 changes: 1 addition & 1 deletion packages/create-astro/src/actions/project-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function projectName(
await checkCwd(ctx.cwd);

if (!ctx.cwd || !isEmpty(ctx.cwd)) {
if (!isEmpty(ctx.cwd)) {
if (ctx.cwd && !isEmpty(ctx.cwd)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix

await info('Hmm...', `${color.reset(`"${ctx.cwd}"`)}${color.dim(` is not empty!`)}`);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/create-astro/src/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ async function copyTemplate(tmpl: string, ctx: Context) {
});

// Process the README file to remove marked sections and update package manager
const readmePath = path.resolve(ctx.cwd, 'README.md');
const readmePath = path.resolve(ctx.cwd!, 'README.md');
if (fs.existsSync(readmePath)) {
const readme = fs.readFileSync(readmePath, 'utf8');
const processedReadme = processTemplateReadme(readme, ctx.packageManager);
fs.writeFileSync(readmePath, processedReadme);
}
} catch (err: any) {
// Only remove the directory if it's most likely created by us.
if (ctx.cwd !== '.' && ctx.cwd !== './' && !ctx.cwd.startsWith('../')) {
if (ctx.cwd !== '.' && ctx.cwd !== './' && !ctx.cwd!.startsWith('../')) {
try {
fs.rmdirSync(ctx.cwd);
fs.rmdirSync(ctx.cwd!);
} catch (_) {
// Ignore any errors from removing the directory,
// make sure we throw and display the original error.
Expand Down Expand Up @@ -185,13 +185,13 @@ async function copyTemplate(tmpl: string, ctx: Context) {

// Post-process in parallel
const removeFiles = FILES_TO_REMOVE.map(async (file) => {
const fileLoc = path.resolve(path.join(ctx.cwd, file));
const fileLoc = path.resolve(path.join(ctx.cwd!, file));
if (fs.existsSync(fileLoc)) {
return fs.promises.rm(fileLoc, { recursive: true });
}
});
const updateFiles = Object.entries(FILES_TO_UPDATE).map(async ([file, update]) => {
const fileLoc = path.resolve(path.join(ctx.cwd, file));
const fileLoc = path.resolve(path.join(ctx.cwd!, file));
if (fs.existsSync(fileLoc)) {
return update(fileLoc, { name: ctx.projectName! });
}
Expand Down
Loading