Skip to content

Conversation

@AdityaTeltia
Copy link

Fixes #24445

What does this PR do?

This change allows markdown files to be imported as text without requiring [loader] ".md" = "text" configuration in bunfig.toml. This is particularly useful for projects storing LLM prompts in markdown files.

Changes:

  • Added .md extension to default_loaders_posix mapped to text loader
  • Added .md to default_loader_ext and node_modules_default_loader_ext arrays
  • Updated documentation in docs/bundler/loaders.mdx and docs/runtime/file-types.mdx
  • Added comprehensive test suite in test/js/bun/util/text-loader-markdown.test.ts

How did you verify your code works?

Before the fix (Using System Bun)

import prompt from "./prompt.md";
console.log(prompt);
// Output: "/path/to/prompt.md" (file loader - returns path)

After the fix (Debug Build)

import prompt from "./prompt.md";
console.log(prompt);  
// Output: "# LLM Prompt\n\nYou are a helpful..." (text loader - returns content)

This change allows markdown files to be imported as text without requiring
[loader] ".md" = "text" configuration in bunfig.toml. This is particularly
useful for projects storing LLM prompts in markdown files.

Changes:
- Added .md extension to default_loaders_posix mapped to text loader
- Added .md to default_loader_ext and node_modules_default_loader_ext arrays
- Updated documentation in docs/bundler/loaders.mdx and docs/runtime/file-types.mdx
- Added comprehensive test suite in test/js/bun/util/text-loader-markdown.test.ts

Fixes oven-sh#24445
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2025

Walkthrough

This PR adds built-in support for loading Markdown files (.md) as text by default. Changes include updating documentation to reflect the new file type, implementing the loader mapping across three configuration sections, and adding tests for static imports, dynamic imports, and monorepo scenarios.

Changes

Cohort / File(s) Summary
Documentation updates
docs/bundler/loaders.mdx, docs/runtime/file-types.mdx
Updated default loader file extensions to include .md for text loading alongside existing supported formats
Loader configuration
src/options.zig
Added .md extension mapping to text loader in default_loaders_posix, default_loader_ext, and node_modules_default_loader_ext configurations
Test suite
test/js/bun/util/text-loader-markdown.test.ts
New test file with four test cases validating static imports, dynamic imports, behavior without bunfig.toml, and monorepo scenarios for Markdown text-loader functionality

Possibly related PRs

Pre-merge checks

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely describes the main change: adding default support for importing .md files as text.
Description check ✅ Passed The PR description follows the template with both required sections completed, explaining what the change does and how it was verified with clear before/after examples.
Linked Issues check ✅ Passed All code changes align with issue #24445: .md extension mapped to text loader in three configuration locations, documentation updated, and comprehensive tests added covering static/dynamic imports and monorepo scenarios.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the feature request in #24445; no unrelated modifications detected across documentation, implementation, and test files.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0db90b2 and 5967255.

📒 Files selected for processing (4)
  • docs/bundler/loaders.mdx (1 hunks)
  • docs/runtime/file-types.mdx (1 hunks)
  • src/options.zig (3 hunks)
  • test/js/bun/util/text-loader-markdown.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
test/**

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place all tests under the test/ directory

Files:

  • test/js/bun/util/text-loader-markdown.test.ts
test/js/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place JavaScript and TypeScript tests under test/js/

Files:

  • test/js/bun/util/text-loader-markdown.test.ts
test/js/bun/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place Bun API tests under test/js/bun/, separated by category (e.g., test/js/bun/glob/)

Files:

  • test/js/bun/util/text-loader-markdown.test.ts
test/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/**/*.{js,ts}: Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test
Prefer data-driven tests (e.g., test.each) to reduce boilerplate
Use shared utilities from test/harness.ts where applicable

Files:

  • test/js/bun/util/text-loader-markdown.test.ts
**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)

**/*.zig: Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Wrap the Bun____toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue

Files:

  • src/options.zig
src/**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)

When adding debug logs in Zig, create a scoped logger and log via Bun APIs: const log = bun.Output.scoped(.${SCOPE}, .hidden); then log("...", .{})

src/**/*.zig: Use Zig private fields with the # prefix for encapsulation (e.g., struct { #foo: u32 })
Prefer Decl literals for initialization (e.g., const decl: Decl = .{ .binding = 0, .value = 0 };)
Place @import statements at the bottom of the file (formatter will handle ordering)

Files:

  • src/options.zig
🧠 Learnings (18)
📚 Learning: 2025-10-19T02:44:46.354Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/context-propagation.test.ts:1-1
Timestamp: 2025-10-19T02:44:46.354Z
Learning: In the Bun repository, standalone packages under packages/ (e.g., bun-vscode, bun-inspector-protocol, bun-plugin-yaml, bun-plugin-svelte, bun-debug-adapter-protocol, bun-otel) co-locate their tests with package source code using *.test.ts files. This follows standard npm/monorepo patterns. The test/ directory hierarchy (test/js/bun/, test/cli/, test/js/node/) is reserved for testing Bun's core runtime APIs and built-in functionality, not standalone packages.

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/**/*.{js,ts} : Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/js/bun/**/*.{js,ts} : Place Bun API tests under test/js/bun/, separated by category (e.g., test/js/bun/glob/)

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/bundle.test.ts : bundle.test.ts should contain DevServer-specific bundling tests

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/css.test.ts : css.test.ts should contain CSS bundling tests in dev mode

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
  • docs/runtime/file-types.mdx
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/html.test.ts : html.test.ts should contain tests relating to HTML files themselves

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/{dev/*.test.ts,dev-and-prod.ts} : Import testing utilities (devTest, prodTest, devAndProductionTest, Dev, Client) from test/bake/bake-harness.ts

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/esm.test.ts : esm.test.ts should cover ESM feature behavior in development mode

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/cli/**/*.{js,ts} : When testing Bun as a CLI, use spawn with bunExe() and bunEnv from harness, and capture stdout/stderr via pipes

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/*.test.ts : Write Dev Server and HMR tests in test/bake/dev/*.test.ts using devTest from the shared harness

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
📚 Learning: 2025-10-26T01:32:04.844Z
Learnt from: Jarred-Sumner
Repo: oven-sh/bun PR: 24082
File: test/cli/test/coverage.test.ts:60-112
Timestamp: 2025-10-26T01:32:04.844Z
Learning: In the Bun repository test files (test/cli/test/*.test.ts), when spawning Bun CLI commands with Bun.spawnSync for testing, prefer using stdio: ["inherit", "inherit", "inherit"] to inherit stdio streams rather than piping them.

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
📚 Learning: 2025-09-20T03:39:41.770Z
Learnt from: pfgithub
Repo: oven-sh/bun PR: 22534
File: test/regression/issue/21830.fixture.ts:14-63
Timestamp: 2025-09-20T03:39:41.770Z
Learning: Bun's test runner supports async describe callbacks, unlike Jest/Vitest where describe callbacks must be synchronous. The syntax `describe("name", async () => { ... })` is valid in Bun.

Applied to files:

  • test/js/bun/util/text-loader-markdown.test.ts
📚 Learning: 2025-10-13T06:54:58.043Z
Learnt from: robobun
Repo: oven-sh/bun PR: 0
File: :0-0
Timestamp: 2025-10-13T06:54:58.043Z
Learning: File extensions in Bun's module resolution are case-sensitive by design, and there are no existing precedents in the codebase for case-insensitive HTML file detection.

Applied to files:

  • src/options.zig
  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-10-13T06:54:58.043Z
Learnt from: robobun
Repo: oven-sh/bun PR: 0
File: :0-0
Timestamp: 2025-10-13T06:54:58.043Z
Learning: Bun's HTML bundler only supports `.html` file extensions, not `.htm`. Adding `.htm` support would require a separate feature request.

Applied to files:

  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-10-19T02:52:37.412Z
Learnt from: theshadow27
Repo: oven-sh/bun PR: 23798
File: packages/bun-otel/tsconfig.json:1-15
Timestamp: 2025-10-19T02:52:37.412Z
Learning: In the Bun repository, packages under packages/ (e.g., bun-otel) can follow a TypeScript-first pattern where package.json exports point directly to .ts files (not compiled .js files). Bun natively runs TypeScript, so consumers import .ts sources directly and receive full type information without needing compiled .d.ts declaration files. For such packages, adding "declaration": true or "outDir" in tsconfig.json is unnecessary and would break the export structure.
<!-- [remove_learning]
ceedde95-980e-4898-a2c6-40ff73913664

Applied to files:

  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-10-04T09:52:49.414Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-10-04T09:52:49.414Z
Learning: Applies to src/js/bun/**/*.{ts,js} : Place Bun-specific modules (e.g., bun:ffi, bun:sqlite) under bun/

Applied to files:

  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-10-01T22:13:08.081Z
Learnt from: taylordotfish
Repo: oven-sh/bun PR: 23169
File: src/codegen/bindgenv2/internal/base.ts:120-125
Timestamp: 2025-10-01T22:13:08.081Z
Learning: Iterator.some() and other Iterator helper methods (map, filter, etc.) are supported in Bun and modern Node.js (22+) runtimes and can be safely used on string iterators and other iterator objects.

Applied to files:

  • docs/runtime/file-types.mdx
  • docs/bundler/loaders.mdx
📚 Learning: 2025-10-04T09:52:49.414Z
Learnt from: CR
Repo: oven-sh/bun PR: 0
File: src/js/CLAUDE.md:0-0
Timestamp: 2025-10-04T09:52:49.414Z
Learning: Applies to src/js/{builtins,node,bun,thirdparty,internal}/**/*.{ts,js} : Use process.platform and process.arch for platform detection (rely on inlining/dead-code elimination)

Applied to files:

  • docs/bundler/loaders.mdx
🧬 Code graph analysis (1)
test/js/bun/util/text-loader-markdown.test.ts (1)
test/harness.ts (2)
  • tempDirWithFiles (259-266)
  • bunExe (102-105)
🔇 Additional comments (2)
src/options.zig (1)

1112-1112: LGTM! Consistent .md extension mapping across loader configurations.

The .md extension is correctly mapped to the text loader in all three relevant configurations (default_loaders_posix, default_loader_ext, and node_modules_default_loader_ext). The placement is appropriate and consistent with other text-based extensions.

Also applies to: 1551-1551, 1579-1579

test/js/bun/util/text-loader-markdown.test.ts (1)

1-111: LGTM! Comprehensive test coverage for Markdown text-loader.

The test suite properly covers the main use cases:

  • Static imports of .md files as text
  • Dynamic imports with await import()
  • Default behavior without bunfig.toml configuration
  • Monorepo scenarios with multiple packages

The tests correctly use spawnSync with bunExe() and bunEnv from the test harness, and tempDirWithFiles for isolated test environments. The assertions verify both content correctness and successful execution.

As per coding guidelines


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AdityaTeltia
Copy link
Author

@Jarred-Sumner can you please have look? 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: support [loader] ".md" = "text" by default

1 participant