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

fix: auto update field name in package.json #5763

Closed
wants to merge 2 commits into from

Conversation

ansidev
Copy link
Contributor

@ansidev ansidev commented Jan 5, 2023

Changes

Update field name in package.json while generating new project to match the user input.

  • NPM v6 and older: ignore updating the NPM package name.
  • NPM v7 and newer: supported.

The value for the new NPM package name is taken from:

  1. --package argument.
  2. projectDir if --package is not given.
  3. request user input if the --package or projectDir is an invalid NPM package name.
  4. ignore updating the NPM package name if user cancels the operation.

Test cases

  • should the package name is changed if no value is given by the user.
  • should the package name is not changed if the user cancels the operation.
  • should the package name matches the passed argument --package.
  • should the package name matches the user input.

@changeset-bot
Copy link

changeset-bot bot commented Jan 5, 2023

🦋 Changeset detected

Latest commit: ec420a4

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 Jan 5, 2023
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.

Looks good to me!

packages/create-astro/src/index.ts Outdated Show resolved Hide resolved
@ansidev ansidev force-pushed the fix/create-astro-package-name branch from e74d379 to 206a787 Compare January 6, 2023 09:58
@ansidev ansidev requested a review from natemoo-re January 6, 2023 12:19
@ansidev ansidev changed the title [WIP] fix: auto update field name in package.json fix: auto update field name in package.json Jan 6, 2023
packages/create-astro/src/index.ts Outdated Show resolved Hide resolved
packages/create-astro/test/utils.js Outdated Show resolved Hide resolved
@ansidev ansidev force-pushed the fix/create-astro-package-name branch 2 times, most recently from 4bdd510 to e75ea8a Compare January 9, 2023 19:04
@ansidev
Copy link
Contributor Author

ansidev commented Jan 9, 2023

@natemoo-re

I have tested the main branch using GitHub Codespaces.

Running pnpm run build: failed randomly.

Error message: command (packages/${random-package-name}) pnpm run build exited (1).

I don't know why. However, all test cases will pass if running pnpm run build && pnpm run test in the folder create-astro.

@ansidev ansidev force-pushed the fix/create-astro-package-name branch from f6e88be to 4dd36bf Compare January 10, 2023 08:05
@ansidev ansidev force-pushed the fix/create-astro-package-name branch from 4dd36bf to ec420a4 Compare January 10, 2023 19:11
@natemoo-re
Copy link
Member

Hey @ansidev thanks for this PR! I did some refactoring of create-astro for testability and made sure to include this feature! See #6082

@natemoo-re natemoo-re closed this Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: create-astro Related to the `create-astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants