From 6900c2d90ae0aab1f65af4bf25ba74ee81edf27e Mon Sep 17 00:00:00 2001 From: Okiki Ojo Date: Thu, 12 Feb 2026 05:02:46 -0500 Subject: [PATCH] docs: update plugin pipeline order and enhance tarball extraction documentation Signed-off-by: Okiki Ojo --- core/tests/15-plugin-pipeline.test.ts | 2 +- docs/architecture.md | 14 +++++++---- docs/scenarios/15-plugin-pipeline.md | 4 +-- docs/scenarios/README.md | 36 ++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/core/tests/15-plugin-pipeline.test.ts b/core/tests/15-plugin-pipeline.test.ts index ae55ddc..1bdc298 100644 --- a/core/tests/15-plugin-pipeline.test.ts +++ b/core/tests/15-plugin-pipeline.test.ts @@ -3,7 +3,7 @@ * * Tests the correctness of the 6-plugin esbuild pipeline: * - * AliasPlugin → ExternalPlugin → VFSPlugin → TarballPlugin → HttpPlugin → CdnPlugin + * AliasPlugin → ExternalPlugin → TarballPlugin → VFSPlugin → HttpPlugin → CdnPlugin * * Three layers of coverage: * diff --git a/docs/architecture.md b/docs/architecture.md index 70ca797..70ad484 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -760,9 +760,13 @@ When bundlejs encounters `import "react"`, the AliasPlugin (or CdnPlugin's depen bundlejs supports tarball extraction through a **two-layer architecture**: -1. **Routing layer** — `getCDNStyle()` in [core/utils/cdn-format.ts](../core/utils/cdn-format.ts) classifies URL origins. Currently, `pkg.pr.new` is the only origin routed as `"tarball"` by default. This is the *narrow gate* — it determines which URLs the TarballPlugin intercepts. +1. **Routing layer** — Two detection methods work together: + - `getCDNStyle()` in [core/utils/cdn-format.ts](../core/utils/cdn-format.ts) classifies CDN-style origins (e.g., `pkg.pr.new` → `"tarball"`) + - `isTarballUrl()` and `isTarballPath()` delegate to `archive-detect`'s `detectArchiveFromPathHint()` to recognize any URL or VFS path containing a tarball extension (`.tgz`, `.tar.gz`, `.tar.zst`, etc.) -2. **Detection and extraction layer** — the [utils/archive-detect.ts](../utils/archive-detect.ts) module is *far* more capable than the routing layer implies. It uses a multi-signal pipeline to identify archives from any source: + Together, these catch tarballs from *any* origin — npm registry, GitHub releases, custom servers, local VFS — without per-origin configuration. + +2. **Detection and extraction layer** — the [utils/archive-detect.ts](../utils/archive-detect.ts) module uses a multi-signal pipeline to identify archives from any source: | Signal | Source | Examples detected | |:-------|:-------|:-----------------| @@ -823,7 +827,7 @@ The TarballPlugin also handles **self-reference imports**. If code *inside* the > **Current extraction limits:** While the detection layer recognizes *many* compression formats, the extraction path currently supports only **gzip-compressed** tars (`.tgz`, `.tar.gz`) and **uncompressed** tars (`.tar`). Other formats (zstd, xz, bzip2, lz4) are detected and produce a clear error with a suggestion to add the corresponding decompressor. This is a reasonable trade-off — npm tarballs are *always* gzip-compressed (`application/tar+gzip`), so every real npm dependency works. The detection infrastructure is intentionally over-capable to make adding new formats straightforward when the need arises. > -> **Routing limits:** Only `pkg.pr.new` URLs are routed to the TarballPlugin by default. Arbitrary `.tgz` URLs from other hosts (e.g., GitHub release assets, private registries) are *not* auto-detected — they pass through to the HttpPlugin, which treats them as regular HTTP fetches. Expanding this is a matter of adding origin patterns to `getCDNStyle()`, not architectural change. +> **VFS tarballs:** The TarballPlugin also handles tarballs stored directly in the VFS (e.g., `/packages/my-lib.tgz`). `fetchAndExtractTarball()` reads the raw bytes via `getFile()` and wraps them in a `new Response()`, feeding into the same detection → decompress → untar pipeline as HTTP tarballs. This is why TarballPlugin must be registered before VFSPlugin — see [Plugin Pipeline](#the-plugin-pipeline). ``` /?q=@tanstack/react-query&config={"package.json":{"dependencies":{"@tanstack/react-query":"https://pkg.pr.new/@tanstack/react-query@7988"}}} @@ -983,7 +987,7 @@ The unsupported types all require local filesystem access or git operations — > import entry from "/index.tsx"; // Absolute paths resolve against VFS too > ``` > -> These schemes are handled by the VirtualFileSystemPlugin (see [Plugin 3](#3-virtualfilesystemplugin--in-memory-file-layer) above). You can pre-populate the VFS at build time with `setFile()`, making `vfs:` a practical alternative to `file:` for injecting local content into a build. The prefixes are configurable via `opts.prefixes` — the defaults are `["vfs:", "virtual:"]`. +> These schemes are handled by the VirtualFileSystemPlugin (see [Plugin 4](#4-virtualfilesystemplugin--in-memory-file-layer) above). You can pre-populate the VFS at build time with `setFile()`, making `vfs:` a practical alternative to `file:` for injecting local content into a build. The prefixes are configurable via `opts.prefixes` — the defaults are `["vfs:", "virtual:"]`. That covers the full resolution picture — from bare npm imports through JSR, tarballs, aliases, and builtins. What makes all of this work *across* plugins is a shared data layer that every plugin reads and writes during a build. @@ -1329,7 +1333,7 @@ The event system (in [core/configs/events.ts](../core/configs/events.ts)) uses t | **WASM esbuild is slower** | ~2–5× slower than native Go binary. | Acceptable for infrequent size checks; too slow for build-on-save workflows. The portability trade-off (runs everywhere JS runs) is the core design choice. | | **CDN dependency** | If unpkg.com goes down, resolution fails. | Configurable CDN origin mitigates this (`cdn: "esm.sh"`), but there is *no automatic failover* between CDNs. | | **Extension probing = many HTTP requests** | Up to 18 URL probes per extensionless import. | HTTP/2 multiplexing and `failedExtensionChecks` caching help. This is a necessary deviation from Node.js (which does not probe) because many CDN-served packages were built for bundlers that do. | -| **No git/workspace/link deps** | `git+https://`, `workspace:*`, `link:../path` all produce explicit errors. | These require local filesystem or git — neither exists in a CDN/edge environment. `file:` specs can use `vfs:`/`virtual:` equivalents instead (see [VFS plugin](#3-virtualfilesystemplugin--in-memory-file-layer)). | +| **No git/workspace/link deps** | `git+https://`, `workspace:*`, `link:../path` all produce explicit errors. | These require local filesystem or git — neither exists in a CDN/edge environment. `file:` specs can use `vfs:`/`virtual:` equivalents instead (see [VFS plugin](#4-virtualfilesystemplugin--in-memory-file-layer)). | | **Browser field inconsistency** | The dual-form `browser` field is one of npm's most inconsistent conventions. | bundlejs follows the Node.js spec and esbuild's behavior — some packages that "work" in webpack may resolve differently. The [Legacy Resolution](#legacy-resolution--packages-without-exports) section details the exact semantics. | | **No dynamic import resolution** | Static `import("react")` works (esbuild handles code splitting), but `import(someVariable)` cannot be resolved. | This is an esbuild limitation, not bundlejs-specific. No bundler can resolve truly dynamic specifiers at build time. | | **Tarball routing is extension-based** | The TarballPlugin intercepts any URL or VFS path whose pathname contains a tarball extension (`.tgz`, `.tar.gz`, `.tar.zst`, etc.), plus CDN-style origins like `pkg.pr.new`. Detection is delegated to `archive-detect`'s `detectArchiveFromPathHint()`. | This means any tarball from any origin is automatically recognized — npm registry, GitHub releases, custom servers, local VFS paths. No per-origin configuration needed. | diff --git a/docs/scenarios/15-plugin-pipeline.md b/docs/scenarios/15-plugin-pipeline.md index c1b41da..c08470a 100644 --- a/docs/scenarios/15-plugin-pipeline.md +++ b/docs/scenarios/15-plugin-pipeline.md @@ -5,7 +5,7 @@ The bundlejs esbuild pipeline registers **six plugins in a fixed order**: ``` -AliasPlugin → ExternalPlugin → VFSPlugin → TarballPlugin → HttpPlugin → CdnPlugin +AliasPlugin → ExternalPlugin → TarballPlugin → VFSPlugin → HttpPlugin → CdnPlugin ``` Registration order is load-bearing: esbuild calls `onResolve` / `onLoad` handlers @@ -18,8 +18,8 @@ document explains the key invariants each plugin must uphold and how they intera |---|---|---| | **AliasPlugin** | `alias-globals` | Rewrites import paths before any other resolution. Strips `node:` prefix, checks `isAlias()`. | | **ExternalPlugin** | `external-globals` | Marks Node.js builtins as external (empty export) or redirects to polyfills when `polyfill: true`. | +| **TarballPlugin** | `tarball-url` | Detects and extracts tarball archives (HTTP URLs, VFS paths) via `archive-detect` delegation. Handles pkg.pr.new, registry tarballs, GitHub releases, and VFS `.tgz` files. Must run before VFS. | | **VFSPlugin** | `virtual-filesystem` | Serves in-memory files (entry points, user code). Scoped handlers prevent accidental VFS intercepts of HTTP-relative imports. | -| **TarballPlugin** | `tarball-url` | Fetches and extracts `.tgz` archives (pkg.pr.new). Handles self-reference imports inside extracted packages. | | **HttpPlugin** | `http-url` | Fetches HTTP URLs, probes extensions, applies browser-field / manifest remapping on relative imports. | | **CdnPlugin** | `cdn-url` | Catch-all for bare npm imports. Resolves versions, fetches package.json, computes entry point, and hands off to HttpPlugin. | diff --git a/docs/scenarios/README.md b/docs/scenarios/README.md index 336c923..a700126 100644 --- a/docs/scenarios/README.md +++ b/docs/scenarios/README.md @@ -238,6 +238,34 @@ curl "http://localhost:8000/?q=solid-js@1.9.4&config={\"resolve\":{\"runtime\":\ | 15.10 | Plugin namespace uniqueness | all plugins | [15-plugin-pipeline.md](15-plugin-pipeline.md) | | 15.11 | Integration: VFS→CDN, alias, external, polyfill, format | full pipeline | [15-plugin-pipeline.md](15-plugin-pipeline.md) | +### GitHub Issue Regression + +| # | Scenario | Key modules | File | +|:--|:---------|:------------|:-----| +| 16 | Regression tests for specific GitHub issues | various | [16-github-issue-regression.md](16-github-issue-regression.md) | + +### JSX in `.js` Files + +| # | Scenario | Key modules | File | +|:--|:---------|:------------|:-----| +| 18.1 | JSX in `.js` file gets `tsx` loader | `loader.ts` | [18-jsx-in-js-files.md](18-jsx-in-js-files.md) | +| 18.2 | Non-JSX `.js` file stays `ts` loader | `loader.ts` | [18-jsx-in-js-files.md](18-jsx-in-js-files.md) | +| 18.3 | `.ts` files never upgraded | `loader.ts` | [18-jsx-in-js-files.md](18-jsx-in-js-files.md) | +| 18.4 | `containsJSX` byte-level detection | `loader.ts` | [18-jsx-in-js-files.md](18-jsx-in-js-files.md) | + +### Registry Tarballs & VFS Tarballs + +| # | Scenario | Key modules | File | +|:--|:---------|:------------|:-----| +| 19.1 | isTarballUrl detection (CDN + extension) | `plugins/tar.ts` | [19-registry-tarballs.md](19-registry-tarballs.md) | +| 19.2 | parseGenericTarballUrl (split URL/subpath) | `plugins/tar.ts` | [19-registry-tarballs.md](19-registry-tarballs.md) | +| 19.3 | parseTarballUrl (pkg.pr.new) unchanged | `plugins/tar.ts` | [19-registry-tarballs.md](19-registry-tarballs.md) | +| 19.4 | TarResolution routing (pkg.pr.new vs registry) | `plugins/tar.ts` | [19-registry-tarballs.md](19-registry-tarballs.md) | +| 19.5 | resolvePackageEntry with subpaths | `plugins/tar.ts` | [19-registry-tarballs.md](19-registry-tarballs.md) | +| 19.6 | stripPackagePrefix | `plugins/tar.ts` | [19-registry-tarballs.md](19-registry-tarballs.md) | +| 19.7 | Edge cases (case-insensitive, multi-ext, archive-detect) | `plugins/tar.ts`, `archive-detect.ts` | [19-registry-tarballs.md](19-registry-tarballs.md) | +| 19.8 | VFS tarball path detection (isTarballPath) | `plugins/tar.ts` | [19-registry-tarballs.md](19-registry-tarballs.md) | + ## Coverage Map @@ -266,7 +294,13 @@ This table maps each scenario to the source file and function it exercises: | Loader inference | `loader.ts` | `inferLoader()` | 13.7 | | CDN style detection | `cdn-format.ts` | `getCDNStyle()` | 13.1 | | JSR specifiers | `cdn-format.ts` | `parseJSRSpecifier()` | 13.5–13.6 | -| Tarball parsing | `tar.ts` | `parseTarballUrl()` | 13.16 | +| Tarball parsing | `tar.ts` | `parseTarballUrl()` | 13.16, 19.3 | +| Tarball URL detection | `tar.ts` | `isTarballUrl()`, `isTarballPath()` | 19.1, 19.7, 19.8 | +| Tarball URL splitting | `tar.ts` | `findTarballSplitInPathname()` | 19.2, 19.7, 19.8 | +| Tarball subpath resolution | `tar.ts` | `resolvePackageEntry()` (tar) | 19.5 | +| VFS tarball detection | `tar.ts` | `isTarballPath()` | 19.8 | +| JSX content detection | `loader.ts` | `containsJSX()` | 18.1–18.4 | +| Loader upgrade (JSX in JS) | `loader.ts` | `inferLoader()` | 18.1–18.3 | | URL utilities | `url.ts` | `encodeWhitespace()`, `urlJoin()` | 13.17 | | Bare import detection | `path.ts` | `isBareImport()` | 13.18 | | Extension probing variants | `http.ts` | `AllEndingVariants` | 15.1 | -- knotmirror 0.0.1