Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes withastro/astro#7793 astro add cli pass down arguments to install cmd #7794

Closed
wants to merge 2 commits into from

Conversation

Elod-T
Copy link
Contributor

@Elod-T Elod-T commented Jul 25, 2023

Changes

  • get arguments from the astro add cli
  • pass them down to the actual package manager

Testing

I tested it locally, running astro add astro-compress -D ran pnpm add astro-compress -D true

Docs

I think it should be in the docs

/cc @withastro/maintainers-docs for feedback!

@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2023

🦋 Changeset detected

Latest commit: 613cad9

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: astro Related to the core `astro` package (scope) label Jul 25, 2023
@ematipico
Copy link
Member

ematipico commented Jul 25, 2023

No tests, I didn't find any tests for the astro add cli

You could test locally and see if it works as expected:

  • build your branch with pnpm build
  • create an empty astro project in another directory
  • use your package manager to run pnpm link ../astro/packages/astro (path to your internal fork of astro)
  • run pnpm astro add command (or create a script) with the flags that needs to be passed

That's how I usually test the CLI

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you for your fix! The changelog is missing and should be added

@@ -18666,7 +18666,6 @@ packages:
resolution: {directory: packages/astro, type: directory}
Copy link
Member

Choose a reason for hiding this comment

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

These changes should be reverted.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's caused by the latest pnpm version

Comment on lines +644 to +651
const inheritedFlags = Object.entries(flags)
.map(([flag, value]) => {
if (flag == '_') return;

return [`-${flag}`, value.toString()];
})
.filter(Boolean)
.flat();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should pass everything down. To be safe, we can scope to --save-dev, -D etc only. In case we support more options in the future, this part won't be glossed over.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't get why we should only pass those down. It's essentially giving back the normal functionality with flags to the cli. It will work as pnpm without the astro add wrapper. Please let me know if I am missing something

Copy link
Member

Choose a reason for hiding this comment

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

I think astro add shouldn't be seen as pnpm add but smarter. It does a lot more like editing configs, adding integration-specific configs etc. The installation phase is one of the steps for astro add. So passing the args directly to that single step is a bit off to me.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @bluwy that we should only support --save-dev and -D for now.

@Elod-T
Copy link
Contributor Author

Elod-T commented Jul 25, 2023

@ematipico Yes I did test it locally, sorry I wasn't clear enough, I meant no unit tests. I'll make the changelog tomorrow

@ematipico
Copy link
Member

@ematipico Yes I did test it locally, sorry I wasn't clear enough, I meant no unit tests. I'll make the changelog tomorrow

Could you please update the template, then? It's important to state that you tested the feature. Even a manual test is important.

@natemoo-re natemoo-re linked an issue Aug 1, 2023 that may be closed by this pull request
1 task
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Code looks good but I'd also like to reduce the scope of this change to only allow -D and --save-dev for now.

Also if you could remove/resolve the lockfile changes, that would be great.

Comment on lines +644 to +651
const inheritedFlags = Object.entries(flags)
.map(([flag, value]) => {
if (flag == '_') return;

return [`-${flag}`, value.toString()];
})
.filter(Boolean)
.flat();
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @bluwy that we should only support --save-dev and -D for now.

@Elod-T
Copy link
Contributor Author

Elod-T commented Aug 2, 2023

I'm working on the pr, and I'm thinking that we could allow all flags supported by npm install.

-P, --save-prod: Package will appear in your dependencies. This is the default unless -D or -O are present.

-D, --save-dev: Package will appear in your devDependencies.

-O, --save-optional: Package will appear in your optionalDependencies.

--no-save: Prevents saving to dependencies.

When using any of the above options to save dependencies to your package.json, there are two additional, optional flags:

-E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm's default semver range operator.

-B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.

Source

@natemoo-re
Copy link
Member

Closing in favor of #8032 so we can get this merged! Unfortunately I wasn't able to push to your fork so I had to push your commits to one of our branches.

@natemoo-re natemoo-re closed this Aug 10, 2023
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

astro add cli doesn't inherit flags
4 participants