Skip to content

fix(create-astro): make --add stricter#15419

Open
ematipico wants to merge 3 commits intomainfrom
fix/create-astro-add
Open

fix(create-astro): make --add stricter#15419
ematipico wants to merge 3 commits intomainfrom
fix/create-astro-add

Conversation

@ematipico
Copy link
Member

@ematipico ematipico commented Feb 5, 2026

Changes

Closes #15420

I refactored the solution to make more generic and apply it to --add and astro add. We have a generic regex that checks wether the name follows the npmjs naming convention. If not, we throw an error.

I preferred to have this regex inside the internal helpers, so both create-astro and astro can use the same source of truth.

Note

Solution designed by me. Code and tests generated via AI. I checked all the code

Testing

Added various tests.

Added new tests. Tested manually

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

🦋 Changeset detected

Latest commit: c9499a1

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: create-astro Related to the `create-astro` package (scope) label Feb 5, 2026
@ematipico ematipico force-pushed the fix/create-astro-add branch from f1e6142 to e502924 Compare February 5, 2026 15:21
@ematipico ematipico self-assigned this Feb 5, 2026
ctx.add = ctx.add?.reduce<string[]>((acc, item) => acc.concat(item.split(',')), []);
if (ctx.add) {
for (const addValue of ctx.add) {
if (!KNOWN_LIBS.includes(addValue)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to break 3rd party integrations being added this way. I think what we want to do is run the string through some sort of bash sanitizer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some pseudo-code of what I mean:

const parts = sanitize(ctx.add);
// [ 'db', '{ bash_stuff_here }' ]

then we can decide what we do in this situation, maybe it's erroring if its more than just a package name.

Copy link
Member Author

@ematipico ematipico Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to break 3rd party integrations being added this way.

Ok I didn't know that third party packages were supposed to be supported. Maybe a KISS heuristic is check for spaces. Packages don't have them, while bash commands must have them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me, but I would check with other people on the team, they probably know usage of this feature more than me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do support astro add <third party instegration> and create-astro --add <third party integration>.

Some integrations (mine, for example) even show those commands on their README/docs.

@ematipico ematipico force-pushed the fix/create-astro-add branch from e502924 to fff4113 Compare February 6, 2026 14:12
@matthewp
Copy link
Contributor

matthewp commented Feb 6, 2026

I don't think this will work, I didn't realize it but we support passing multiple integrations: https://docs.astro.build/en/guides/integrations-guide/#automatic-integration-setup

I think we'll need to do some sort of escaping.

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 6, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing fix/create-astro-add (c9499a1) with main (3928b87)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (68770ef) during the generation of this report, so 3928b87 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me!

child = spawn(command, flags, {
cwd: opts.cwd,
shell: true,
shell: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'd check if there isn't a Windows nonsense that could happen here. I feel like I remember some Node update requiring shell true in some contexts on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope) pkg: create-astro Related to the `create-astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-astro: --add input is interpreted as shell syntax

4 participants