-
Notifications
You must be signed in to change notification settings - Fork 5.1k
loader: document the empty --loader extension, accept it in bunfig too
#36904
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { mkdirSync, writeFileSync } from "fs"; | ||
| import { bunEnv, bunExe, isWindows, tmpdirSync } from "harness"; | ||
| import { bunEnv, bunExe, isWindows, tempDirWithFiles, tmpdirSync } from "harness"; | ||
| import { join } from "path"; | ||
|
|
||
| describe.concurrent("run-extensionless", () => { | ||
|
|
@@ -32,4 +32,51 @@ describe.concurrent("run-extensionless", () => { | |
| const stdout = await proc.stdout.text(); | ||
| expect(stdout).toEqual("hello world\n"); | ||
| }); | ||
|
|
||
| // `--loader` takes an empty extension, which maps files that have none. `<T>(x: T) => x` | ||
| // is a generic arrow to the ts loader and an unclosed tag to the tsx loader, so it parses | ||
| // only when the mapping took effect. | ||
| test("--loader with an empty extension sets the loader for extensionless files", async () => { | ||
| const dir = tmpdirSync(); | ||
| mkdirSync(dir, { recursive: true }); | ||
| await Bun.write(join(dir, "cool"), "const id = <T>(x: T) => x; console.log(id('hello world'));"); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "--loader=:ts", join(dir, "./cool")], | ||
| cwd: dir, | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| }); | ||
| const stdout = await proc.stdout.text(); | ||
| expect(stdout).toEqual("hello world\n"); | ||
|
Comment on lines
+43
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
echo "== locate file =="
git ls-files | rg '^test/cli/run/run-extensionless\.test\.ts$' || true
echo "== file excerpt =="
if [ -f test/cli/run/run-extensionless.test.ts ]; then
nl -ba test/cli/run/run-extensionless.test.ts | sed -n '1,120p'
fi
echo "== subprocess tests in file =="
rg -n 'Bun\.spawn|await proc\.exited|exitCode|stdout\.text|expect\(stdout\)' test/cli/run/run-extensionless.test.ts || true
echo "== git status/stat (context only) =="
git status --short || true
git diff --stat || trueRepository: oven-sh/bun Length of output: 265 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
echo "== file excerpt =="
if [ -f test/cli/run/run-extensionless.test.ts ]; then
awk '{ printf "%5d %s\n", NR, $0 }' test/cli/run/run-extensionless.test.ts | sed -n '1,120p'
fi
echo "== subprocess patterns in file =="
grep -nE 'Bun\.spawn|await proc\.exited|exitCode|stdout\.text|expect\(stdout\)' test/cli/run/run-extensionless.test.ts || trueRepository: oven-sh/bun Length of output: 4565 Assert the subprocess exit code in the new subprocess tests. Each test reads only 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| }); | ||
|
|
||
| test("[loader] with an empty extension sets the loader for extensionless files", async () => { | ||
| const dir = tempDirWithFiles("bunfig-loader-extensionless", { | ||
| cool: "const id = <T>(x: T) => x; console.log(id('hello world'));", | ||
| "bunfig.toml": '[loader]\n"" = "ts"\n', | ||
| }); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), join(dir, "./cool")], | ||
| cwd: dir, | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| }); | ||
| const stdout = await proc.stdout.text(); | ||
| expect(stdout).toEqual("hello world\n"); | ||
| }); | ||
|
|
||
| test("--loader with an empty extension applies to imported extensionless files", async () => { | ||
| const dir = tmpdirSync(); | ||
| mkdirSync(dir, { recursive: true }); | ||
| await Bun.write(join(dir, "dep"), "export const id = <T>(x: T) => x;"); | ||
| await Bun.write(join(dir, "main.ts"), "import { id } from './dep'; console.log(id('hello world'));"); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "--loader=:ts", join(dir, "./main.ts")], | ||
| cwd: dir, | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| }); | ||
| const stdout = await proc.stdout.text(); | ||
| expect(stdout).toEqual("hello world\n"); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: oven-sh/bun
Length of output: 11122
Use
tempDirfor the new temporary directories.The new tests call
tmpdirSync()and create directories manually. Use thetempDirhelper fromharnessinstead.Proposed change
As per coding guidelines, test files must use
tempDirfromharnessand must not usetmpdirSync.Also applies to: 40-41, 69-70
🤖 Prompt for AI Agents
Source: Coding guidelines