Skip to content

Commit

Permalink
Fix astro add generated import identifier (#12363)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni authored Nov 6, 2024
1 parent 493fe43 commit 222f718
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/five-maps-bake.md
Original file line number Diff line number Diff line change
@@ -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`.
7 changes: 6 additions & 1 deletion packages/astro/src/cli/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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)}`;
};

Expand Down

0 comments on commit 222f718

Please sign in to comment.