diff options
author | 2024-11-06 03:16:34 -0300 | |
---|---|---|
committer | 2024-11-06 14:16:34 +0800 | |
commit | 222f71894cc7118319ce83b3b29fa61a9dbebb75 (patch) | |
tree | eeff0ec9443d6a3a0145b479ec7b913c08fd1a51 | |
parent | 493fe43cd3ef94b087b8958031ecc964ae73463b (diff) | |
download | astro-222f71894cc7118319ce83b3b29fa61a9dbebb75.tar.gz astro-222f71894cc7118319ce83b3b29fa61a9dbebb75.tar.zst astro-222f71894cc7118319ce83b3b29fa61a9dbebb75.zip |
Fix `astro add` generated import identifier (#12363)
-rw-r--r-- | .changeset/five-maps-bake.md | 5 | ||||
-rw-r--r-- | packages/astro/src/cli/add/index.ts | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/.changeset/five-maps-bake.md b/.changeset/five-maps-bake.md new file mode 100644 index 000000000..13bacbcdc --- /dev/null +++ b/.changeset/five-maps-bake.md @@ -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`. diff --git a/packages/astro/src/cli/add/index.ts b/packages/astro/src/cli/add/index.ts index 08c57dc04..2b4faa266 100644 --- a/packages/astro/src/cli/add/index.ts +++ b/packages/astro/src/cli/add/index.ts @@ -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)}`; }; |