0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Fix astro add generated import identifier (#12363)

This commit is contained in:
Luiz Ferraz 2024-11-06 03:16:34 -03:00 committed by GitHub
parent 493fe43cd3
commit 222f71894c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes code generated by `astro add` command when adding a version of an integration other than the default `latest`.

View file

@ -390,13 +390,16 @@ function isAdapter(
// Some examples:
// - @astrojs/image => image
// - @astrojs/markdown-component => markdownComponent
// - @astrojs/image@beta => image
// - astro-cast => cast
// - astro-cast@next => cast
// - markdown-astro => markdown
// - some-package => somePackage
// - example.com => exampleCom
// - under_score => underScore
// - 123numeric => numeric
// - @npm/thingy => npmThingy
// - @npm/thingy@1.2.3 => npmThingy
// - @jane/foo.js => janeFoo
// - @tokencss/astro => tokencss
const toIdent = (name: string) => {
@ -409,7 +412,9 @@ const toIdent = (name: string) => {
// convert to camel case
.replace(/[.\-_/]+([a-zA-Z])/g, (_, w) => w.toUpperCase())
// drop invalid first characters
.replace(/^[^a-zA-Z$_]+/, '');
.replace(/^[^a-zA-Z$_]+/, '')
// drop version or tag
.replace(/@.*$/, '');
return `${ident[0].toLowerCase()}${ident.slice(1)}`;
};