Skip to content

Commit 4e6552b

Browse files
fix: ignore path prompt if user provided path in create (#292)
Co-authored-by: AdrianGonz97 <[email protected]>
1 parent 9857030 commit 4e6552b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

.changeset/popular-cows-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
fix: ignore path prompt if user provided path in `create`

packages/cli/commands/create.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const templateOption = new Option('--template <type>', 'template to scaffold').c
2727
templateChoices
2828
);
2929

30-
const ProjectPathSchema = v.string();
30+
const ProjectPathSchema = v.optional(v.string());
3131
const OptionsSchema = v.strictObject({
3232
types: v.pipe(
3333
v.optional(v.union([v.picklist(langs), v.boolean()])),
@@ -38,10 +38,11 @@ const OptionsSchema = v.strictObject({
3838
template: v.optional(v.picklist(templateChoices))
3939
});
4040
type Options = v.InferOutput<typeof OptionsSchema>;
41+
type ProjectPath = v.InferOutput<typeof ProjectPathSchema>;
4142

4243
export const create = new Command('create')
4344
.description('scaffolds a new SvelteKit project')
44-
.argument('[path]', 'where the project will be created', process.cwd())
45+
.argument('[path]', 'where the project will be created')
4546
.addOption(templateOption)
4647
.addOption(langOption)
4748
.option('--no-types')
@@ -58,7 +59,8 @@ export const create = new Command('create')
5859
let i = 1;
5960
const initialSteps: string[] = [];
6061
const relative = path.relative(process.cwd(), directory);
61-
const pm = packageManager ?? detectSync({ cwd })?.name ?? common.getUserAgent() ?? 'npm';
62+
const pm =
63+
packageManager ?? detectSync({ cwd: directory })?.name ?? common.getUserAgent() ?? 'npm';
6264
if (relative !== '') {
6365
const pathHasSpaces = relative.includes(' ');
6466
initialSteps.push(
@@ -85,12 +87,13 @@ export const create = new Command('create')
8587
});
8688
});
8789

88-
async function createProject(cwd: string, options: Options) {
90+
async function createProject(cwd: ProjectPath, options: Options) {
8991
const { directory, template, language } = await p.group(
9092
{
9193
directory: () => {
92-
const relativePath = path.relative(process.cwd(), cwd);
93-
if (relativePath) return Promise.resolve(relativePath);
94+
if (cwd) {
95+
return Promise.resolve(path.resolve(cwd));
96+
}
9497
const defaultPath = './';
9598
return p.text({
9699
message: 'Where would you like your project to be created?',

0 commit comments

Comments
 (0)