From 0d17843251eafd48452301e9799aed9e38c0becf Mon Sep 17 00:00:00 2001 From: pfg Date: Fri, 17 Jan 2025 22:08:07 -0800 Subject: [PATCH] Fix bun run folder (#15117) Co-authored-by: pfgithub --- docs/api/transpiler.md | 6 +- docs/bundler/index.md | 3 +- docs/cli/run.md | 15 +- .../src/modules/bun/transpiler.ts | 17 +- packages/bun-types/bun.d.ts | 3 +- src/bake/production.zig | 2 +- src/bun.js/bindings/bindings.cpp | 2 +- src/bundler/bundle_v2.zig | 2 +- src/cli.zig | 173 +------ src/cli/exec_command.zig | 2 +- src/cli/run_command.zig | 441 +++++++++--------- src/codegen/replacements.ts | 3 +- src/css/targets.zig | 5 +- src/import_record.zig | 28 +- src/js_printer.zig | 1 + src/options.zig | 2 +- src/resolver/package_json.zig | 288 ++++++------ src/resolver/resolver.zig | 8 +- src/shell/interpreter.zig | 4 +- src/transpiler.zig | 6 +- test/cli/install/bun-run.test.ts | 338 +++++++++++++- test/cli/run/if-present.test.ts | 2 +- test/js/bun/wasm/wasi.test.js | 14 +- test/regression/issue/10132.test.ts | 4 +- 24 files changed, 795 insertions(+), 574 deletions(-) diff --git a/docs/api/transpiler.md b/docs/api/transpiler.md index 308a4e152d..d24eb4ac2c 100644 --- a/docs/api/transpiler.md +++ b/docs/api/transpiler.md @@ -137,7 +137,8 @@ Each import in the `imports` array has a `path` and `kind`. Bun categories impor - `import-rule`: `@import 'foo.css'` - `url-token`: `url('./foo.png')` +- `entry-point-build`: `import {foo} from 'bun:entry'` +- `entry-point-run`: `bun ./mymodule` --> ## `.scanImports()` @@ -267,7 +268,8 @@ type Import = { // The import was injected by Bun | "internal"  // Entry point (not common) - | "entry-point" + | "entry-point-build" + | "entry-point-run" } const transpiler = new Bun.Transpiler({ loader: "jsx" }); diff --git a/docs/bundler/index.md b/docs/bundler/index.md index dbb7a95038..8ada85b24c 100644 --- a/docs/bundler/index.md +++ b/docs/bundler/index.md @@ -533,7 +533,8 @@ export type BuildManifest = { }; export type ImportKind = - | "entry-point" + | "entry-point-build" + | "entry-point-run" | "import-statement" | "require-call" | "dynamic-import" diff --git a/docs/cli/run.md b/docs/cli/run.md index b1a7891140..cc4ae91751 100644 --- a/docs/cli/run.md +++ b/docs/cli/run.md @@ -106,13 +106,13 @@ $ bun run clean Done. ``` -Bun executes the script command in a subshell. It checks for the following shells in order, using the first one it finds: `bash`, `sh`, `zsh`. +Bun executes the script command in a subshell. On Linux & macOS, it checks for the following shells in order, using the first one it finds: `bash`, `sh`, `zsh`. On windows, it uses [bun shell](https://bun.sh/docs/runtime/shell) to support bash-like syntax and many common commands. {% callout %} ⚡️ The startup time for `npm run` on Linux is roughly 170ms; with Bun it is `6ms`. {% /callout %} -If there is a name conflict between a `package.json` script and a built-in `bun` command (`install`, `dev`, `upgrade`, etc.) Bun's built-in command takes precedence. In this case, use the more explicit `bun run` command to execute your package script. +Scripts can also be run with the shorter command `bun