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

Detect Bun package manager in create-astro #7944

Merged
merged 6 commits into from
Aug 17, 2023

Conversation

colinhacks
Copy link
Contributor

Changes

Better support for Bun users when using create-astro.

  • Prints the correct command for starting dev server (bun run dev)
  • Add bunx create-astro to readme

Testing

I didn't see tests for pnpm or yarn. Bun sets npm_config_user_agent like Yarn/pnpm, and which-pm-runs detects this as expected. Here's a sample run showing everything working with Bun:

npm_config_user_agent=bun/1.0 node create-astro.mjs 

╭─────╮  Houston:
│ ◠ ◡ ◠  Let's build something great!
╰─────╯

 astro   v2.10.1 Launch sequence initiated.

   dir   Where should we create your new project?
         ./growing-gamma

  tmpl   How would you like to start your new project?
         Include sample files
      ✔  Template copied

  deps   Install dependencies?
         Yes
      ✔  Dependencies installed

    ts   Do you plan to write TypeScript?
         Yes

   use   How strict should TypeScript be?
         Strict
      ✔  TypeScript customized

   git   Initialize a new git repository?
         No
      ◼  Sounds good! You can always run git init manually.

  next   Liftoff confirmed. Explore your project!

         Enter your project directory using cd ./growing-gamma 
         Run bun run dev to start the dev server. CTRL+C to stop.
         Add frameworks like react or tailwind using astro add.

         Stuck? Join us at https://astro.build/chat

╭─────╮  Houston:
│ ◠ ◡ ◠  Good luck out there, astronaut! 🚀
╰─────╯

Docs

Sister documentation PR: withastro/docs#4052

@colinhacks colinhacks requested a review from a team as a code owner August 3, 2023 23:47
@changeset-bot
Copy link

changeset-bot bot commented Aug 3, 2023

🦋 Changeset detected

Latest commit: 3e8edde

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 Aug 3, 2023
@matthewp
Copy link
Contributor

matthewp commented Aug 4, 2023

Thanks! Not sure if will want the readme change, as that implies more support than I think we can offer at the moment. No issues with the code change though. Will discuss with the team and get back to you.

@kanashimia
Copy link
Contributor

Just noting that current bun support only uses bun as a package manager, partially too, at this moment this still requires to have node and npm !! installed.

@colinhacks
Copy link
Contributor Author

colinhacks commented Aug 4, 2023

@matthewp Yep, this is primarily aimed at users who are using Bun as a standalone package manager/script runner.

As @kanashimia says, this is only using Bun as a package manager. bunx respects the shebang line in the "bin" script so bunx astro dev still uses Node.js for the dev server. That's intentional and means that bunx create-astro and bun run dev will behave identically to the equivalents using other package managers.

Worth noting that post-1.0 bunx will (likely) use the Bun runtime to execute scripts marked with a node shebang. Though making Astro work with Bun is our responsibility and should require no code changes or work on your end.

@colinhacks colinhacks changed the title Support Bun in create-astro Support Bun package manager in create-astro Aug 7, 2023
@colinhacks
Copy link
Contributor Author

Removed the readme change.

Just to clarify w.r.t. @kanashimia's point, users do not need npm installed to use create-astro or astro itself.

$ alias npm=asdfasdf
$ npm_config_user_agent=bun/1.0 node create-astro.mjs

╭─────╮  Houston:
│ ◠ ◡ ◠  Let's make the web weird!
╰─────╯

 astro   v2.10.2 Launch sequence initiated.

   dir   Where should we create your new project?
         ./tested-transit

  tmpl   How would you like to start your new project?
         Include sample files
      ✔  Template copied

  deps   Install dependencies?
         Yes
      ✔  Dependencies installed

    ts   Do you plan to write TypeScript?
         Yes

   use   How strict should TypeScript be?
         Strict
      ✔  TypeScript customized

   git   Initialize a new git repository?
         Yes
      ✔  Git initialized

  next   Liftoff confirmed. Explore your project!

         Enter your project directory using cd ./tested-transit 
         Run bun run dev to start the dev server. CTRL+C to stop.
         Add frameworks like react or tailwind using astro add.

         Stuck? Join us at https://astro.build/chat

╭─────╮  Houston:
│ ◠ ◡ ◠  Good luck out there, astronaut! 🚀
╰─────╯
$ cd tested-transit 
$ bun run dev
$ astro dev
  🚀  astro  v2.10.2 started in 73ms
  
  ┃ Local    http://localhost:3000/
  ┃ Network  use --host to expose
 

@colinhacks colinhacks changed the title Support Bun package manager in create-astro Detetx Bun package manager in create-astro Aug 7, 2023
@colinhacks colinhacks changed the title Detetx Bun package manager in create-astro Detect Bun package manager in create-astro Aug 7, 2023
@kanashimia
Copy link
Contributor

alias npm=asdfasdf

This isn't a correct way to test this, aliases are shell specific, they do nothing inside of the command you are trying to execute, correct way would be to remove the path to the folder where the binary is located from the PATH environment variable.
I verified that with this change it executes bun, and doesn't touch npm

@kanashimia
Copy link
Contributor

kanashimia commented Aug 7, 2023

Also it seems that bun still tries to execute scripts when you do not have node installed, using its own runtime.

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.

I'm cool with this change, thanks for contributing.

Excited for the Astro × Bun story to evolve!

@ematipico ematipico merged commit dff0f0f into withastro:main Aug 17, 2023
13 checks passed
This was referenced Aug 17, 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.

None yet

5 participants