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

Optional dev dependencies #8171

Open
lgarron opened this issue Jan 15, 2024 · 2 comments
Open

Optional dev dependencies #8171

lgarron opened this issue Jan 15, 2024 · 2 comments
Labels
bun install Something that relates to the npm-compatible client enhancement New feature or request

Comments

@lgarron
Copy link
Contributor

lgarron commented Jan 15, 2024

What is the problem this feature would solve?

Now that it's practical to use Playwright with bun (#2492), it's possible to move fairly complicated web projects entirely to bun. This presents an opportunity to implement a feature that npm declined to implement: optional dev dependencies.

Dependencies like Playwright can be fairly large. They are valuable in CI or for thorough testing, but not needed for everyday development or a small PR. The same applies to special tools that are only run when deploying or publishing code.

I would love to avoid making everyone download these large dependencies and potentially save significant:

  • bandwidth,
  • download time, and
  • disk space

when these are not needed.

What is the feature you are proposing to solve the problem?

  1. Support an optionalDevDependencies field in package.json.
  2. In the bun install configuration, add an optionalDev field.
  • If optionalDev is not specified:
    • Fall back to true when optional and dev are both true.
    • Fall back to false if either optional or dev is false.

This allows projects to have a "quick start" dev process without any hacks, by using setup steps with different bun install config files:

# Get started quickly
git clone https://github.com/cubing/cubing.js && cd cubing.js
make quick-setup dev
make test-fast # Run a large range of quick tests

# Install all dev dependencies to run browser tests
make setup test-all
# Potential Makefile example

.PHONY: quick-setup:
quick-setup:
	bun install --config bunfig-quick.toml

.PHONY: setup:
setup:
	bun install # default config

What alternatives have you considered?

In theory it's possible to use a library for this, but that would require either:

  1. vendoring the library code (a maintenance and security liability), or
  2. installing the library (requires two separate install steps, likely to be slower and still kind of complicated).

By contrast, it would be really valuable as built-in functionality for the package manager so that projects can hit the ground running.

@lgarron lgarron added the enhancement New feature or request label Jan 15, 2024
@lgarron
Copy link
Contributor Author

lgarron commented Jan 15, 2024

This allows projects to have a "quick start" dev process without any hacks by using setup steps with different bun install config files:

In particular, cubing.js already does this by manually emulating optional dev dependency functionality.

If I set Network Link Conditioner to 20mbps, then I see a significant difference when installing all dev dependencies using bun install:

git clone https://github.com/cubing/cubing.js && cd cubing.js
make clean && rm -rf node_modules && bun pm cache rm
time make quick-setup test-fast # ≈ 12 seconds
git clone https://github.com/cubing/cubing.js && cd cubing.js
make clean && rm -rf node_modules && bun pm cache rm
time make setup test-fast # ≈ 120 seconds

This shows that someone can get started in the project about 10× as fast using optional dev dependencies if they have no dependencies cached. 😱
With a slower connection (say, 3G connection speed, or slow shared Wi-Fi), this can make a huge difference — even if some dependencies are already cached, it could be a difference of many minutes.

bun already makes the local operations fast 1, but this would help make the overall experience of project development faster starting from right after checkout.

Footnotes

  1. And I must commend bun install on being wicked fast when the dependencies are already cached.

@Electroid Electroid added the bun install Something that relates to the npm-compatible client label Jan 15, 2024
@dsogari
Copy link

dsogari commented Feb 4, 2024

The workaround for this would be a git branch, but it'd be very cumbersome to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bun install Something that relates to the npm-compatible client enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants