-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
When creating a new application, scoped package names (i.e. like @sveltejs/template-default) are not correctly handled, both with the CLI and when used programmatically.
When using the CLI, the result is that the package name resolves to just template-default, due to using only the path's basename.
In packages/create-svelte/bin.js:
await create(cwd, {
name: path.basename(path.resolve(cwd)),
template: /** @type {'default' | 'skeleton' | 'skeletonlib'} */ (options.template),
types: options.types,
prettier: options.features.includes('prettier'),
eslint: options.features.includes('eslint'),
playwright: options.features.includes('playwright'),
vitest: options.features.includes('vitest')
});When using the JS API, the result is that the package name resolves to -sveltejs-template-default, due to to_valid_package_name not handling the @scope/ prefix correctly.
In packages/create-svelte/index.js:
/** @param {string} name */
function to_valid_package_name(name) {
return name
.trim()
.toLowerCase()
.replace(/\s+/g, '-')
.replace(/^[._]/, '')
.replace(/[^a-z0-9~.-]+/g, '-');
}Reproduction
$ pnpm create svelte @sveltejs/template-default
-> inspect name field in the generated package.json:
$ cat @sveltejs/template-default/package.json | jq .name
or
#!/usr/bin/env node
import { create } from 'create-svelte';
const path = 'template-default';
const name = `@sveltejs/${path}`;
await create(path, { name, template: 'default', types: null });-> inspect name field in the generated package.json:
$ cat template-default/package.json | jq .name
Logs
No response
System Info
(system does not seem to be relevant, results are the same on Linux and WSL on Windows)
System:
OS: macOS 14.1
CPU: (8) arm64 Apple M2
Memory: 729.30 MB / 24.00 GB
Shell: 3.6.1 - /opt/homebrew/bin/fish
Binaries:
Node: 20.9.0 - ~/.local/share/pnpm/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 10.1.0 - ~/.local/share/pnpm/npm
pnpm: 8.10.2 - /opt/homebrew/bin/pnpm
bun: 1.0.7 - ~/.bun/bin/bun
Browsers:
Chrome: 119.0.6045.123
Safari: 17.1
Safari Technology Preview: 17.4Severity
annoyance
Additional Information
No response