Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/cli/src/create/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ describe('formatTargetDir', () => {
expect(formatTargetDir('../../foo/bar')).matchSnapshot();
});

it.skipIf(process.platform === 'win32')('should format target dir with valid input', () => {
// Should work on all platforms (including Windows) - directory must always use forward slashes
it('should format target dir with valid input', () => {
expect(formatTargetDir('./my-package')).matchSnapshot();
expect(formatTargetDir('my-package')).matchSnapshot();
expect(formatTargetDir('@my-scope/my-package')).matchSnapshot();
Expand All @@ -28,6 +29,17 @@ describe('formatTargetDir', () => {
expect(formatTargetDir('./foo/bar/@scope/my-package/sub-package')).matchSnapshot();
});

// Regression test for https://github.com/voidzero-dev/vite-plus/issues/938
// On Windows, path.join/normalize produce backslashes which break when passed as CLI args.
// Nested paths are the critical cases since they involve path separators.
it('should always use forward slashes in directory (issue #938)', () => {
expect(formatTargetDir('foo/@my-scope/my-package').directory).toBe('foo/my-package');
expect(formatTargetDir('./foo/bar/@scope/my-package').directory).toBe('foo/bar/my-package');
expect(formatTargetDir('./foo/bar/@scope/my-package/sub-package').directory).toBe(
'foo/bar/@scope/my-package/sub-package',
);
});

it('should format target dir with invalid package name', () => {
expect(formatTargetDir('my-package@').error).matchSnapshot();
expect(formatTargetDir('my-package@1.0.0').error).matchSnapshot();
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/create/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
const selected = await promptPackageNameAndTargetDir(defaultPackageName, options.interactive);
packageName = selected.packageName;
targetDir = selectedParentDir
? path.join(selectedParentDir, selected.targetDir)
? path.join(selectedParentDir, selected.targetDir).split(path.sep).join('/')
: selected.targetDir;
}
}
Expand Down Expand Up @@ -782,7 +782,7 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
const selected = await promptPackageNameAndTargetDir(defaultPackageName, options.interactive);
packageName = selected.packageName;
targetDir = templateInfo.parentDir
? path.join(templateInfo.parentDir, selected.targetDir)
? path.join(templateInfo.parentDir, selected.targetDir).split(path.sep).join('/')
: selected.targetDir;
}
pauseCreateProgress();
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/create/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function formatTargetDir(input: string): {
error: `Parsed package name "${packageName}" is invalid: ${message}`,
};
}
return { directory: targetDir, packageName };
return { directory: targetDir.split(path.sep).join('/'), packageName };
}

// Get the project directory from the project name
Expand Down
Loading