Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: privatenumber/tsx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.23.0
Choose a base ref
...
head repository: privatenumber/tsx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.23.1
Choose a head ref
  • 10 commits
  • 21 files changed
  • 1 contributor

Commits on Jul 3, 2026

  1. perf: use sync module hooks on Node v22.22.3+

    ## Problem
    
    tsx uses the sync `module.registerHooks()` path (no loader worker
    thread) only once Node can re-enter `Module._load` from sync hooks
    ([nodejs/node#59929](nodejs/node#59929)). That
    landed in v24.11.1 / v25.1.0 and was **also backported to v22.22.3**,
    but the gate had no 22.x entry — so v22.22.3+ kept taking the slower
    async `module.register()` path.
    
    ## Changes
    
    - Add `[22, 22, 3]` to the `moduleRegisterHooksCjsReload` gate. v22.22.2
    and earlier stay on the async path; v22.22.3+ now uses sync hooks.
    - Bump the 22.x CI matrix entry `22.22.2` → `22.22.3` so CI exercises
    the newly-enabled sync path on the 22 line.
    
    Verified the backport is behaviorally complete: the full suite (incl.
    CJS-interop, `require.cache`, watch, version-sensitive) passes with Node
    22.22.3 as the runner.
    
    Startup on Node 22.22.3, 1000 modules (min of 6 runs, M5 Pro):
    
    ```
                         async (before)   sync (this PR)
    hooks-passthrough    437ms            190ms
    esm-ts               694ms            337ms
    ```
    privatenumber authored Jul 3, 2026
    Configuration menu
    Copy the full SHA
    f8992f1 View commit details
    Browse the repository at this point in the history

Commits on Jul 4, 2026

  1. docs: document Node's public type-stripping API vs internal loader path

    ## Problem
    
    `notes/node/type-stripping.md` covers the loader pipeline but not the
    boundary that matters for integrating with it: the public
    `module.stripTypeScriptTypes()` API behaves differently from the
    internal loader path, and several load-bearing details (hook-chain
    ordering, typeless-package classification, compile-cache keying, output
    stability) were verified against source but undocumented.
    
    ## Changes
    
    - New section comparing the public API vs `stripTypeScriptModuleTypes`:
    node_modules restriction and compile-cache integration are
    internal-path-only; `mode: 'transform'` is accepted flaglessly through
    v25.x and removed from the public API at v26; the ExperimentalWarning
    survives into v26
    - Runtime pipeline additions: stripping runs *after* the module-hook
    chain (translators keyed on final format), typeless-package `.ts`
    classification follows the `.js` contract with detection at load time
    (resolve reports `null` format), and compile-cache/V8 code cache keying
    applies to hook-provided sources
    - Error-contract detail: `ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX` vs
    `ERR_INVALID_TYPESCRIPT_SYNTAX`; decorators pass through as JavaScript;
    `erasableSyntaxOnly` flags exactly the unsupported-syntax set
    - Output-stability warning from `module.md` (don't key caches/assertions
    on exact bytes)
    - Relationship-to-tsx: notes the module-classification difference for
    typeless packages (Node syntax-detects; tsx's detection predates
    detect-module and classifies as CommonJS)
    
    All line anchors verified against the nodejs/node clone at v24.15.0 /
    v26.4.0.
    privatenumber authored Jul 4, 2026
    Configuration menu
    Copy the full SHA
    f0e89b2 View commit details
    Browse the repository at this point in the history

Commits on Jul 12, 2026

  1. fix: support tsImport after global preload

    ## Summary
    
    - Fixes `tsImport()` failing to load CommonJS TypeScript when the host
    process already preloaded tsx.
    - Lets tools safely load `.cts` configuration files without asking users
    to remove their global `--import tsx` setup.
    
    ## Problem
    
    Libraries use `tsImport()` to load TypeScript configuration files
    without enabling TypeScript support for the entire process. If the host
    application already started Node with `--import tsx`, loading a `.cts`
    file could instead fail before user code ran with `__filename is not
    defined in ES module scope`, as reported in
    [#821](#821).
    
    Internally, `tsImport()` gives each call a unique `tsx-namespace` URL
    query and registers a scoped ESM hook. With the global preload already
    active, Node's hook chain contains both an unscoped global hook and this
    scoped hook. The scoped hook delegates through `nextLoad()` using its
    namespaced URL.
    
    The previous load gate only rejected a namespace mismatch when the
    current hook itself had a namespace. The unscoped global hook therefore
    accepted the scoped URL too. Both hooks transformed the same CommonJS
    TypeScript load, leaving code that expects CommonJS globals such as
    `__filename` to be evaluated as ESM.
    
    ## Changes
    
    - Treat namespaces as exact hook ownership: the global registration
    handles only unscoped URLs, while each scoped registration handles only
    its matching namespace.
    - Add the reported global-preload plus `tsImport('./config.cts')`
    regression to the version-sensitive Node matrix.
    privatenumber authored Jul 12, 2026
    Configuration menu
    Copy the full SHA
    8d4ffc2 View commit details
    Browse the repository at this point in the history
  2. docs: generate sitemap

    ## Problem
    
    Search results continue to surface the retired `tsx.is` domain, while
    the current documentation site returns 404 for `/sitemap.xml`. Search
    engines do not receive an explicit list of documentation URLs on the
    current hostname.
    
    ## Changes
    
    Enable VitePress's built-in sitemap generation for
    `https://tsx.hirok.io`. The existing `lastUpdated` setting adds per-page
    `<lastmod>` metadata to the generated sitemap.
    privatenumber authored Jul 12, 2026
    Configuration menu
    Copy the full SHA
    f4176d8 View commit details
    Browse the repository at this point in the history
  3. docs: add per-page metadata

    ## Problem
    
    Documentation pages do not declare canonical URLs, and every page
    currently reports site-wide Open Graph metadata with the homepage URL.
    Search and social crawlers cannot reliably associate each page with its
    actual `tsx.hirok.io` route and title.
    
    ## Changes
    
    Generate canonical links and page-specific Open Graph titles, URLs, and
    descriptions from VitePress page data. Descriptions fall back to the
    site description when a page does not define one.
    
    Clean URLs preserve trailing slashes for index routes, while the
    generated 404 page is excluded. The site origin remains shared with the
    sitemap and social-image configuration.
    privatenumber authored Jul 12, 2026
    Configuration menu
    Copy the full SHA
    6fd4607 View commit details
    Browse the repository at this point in the history
  4. fix(watch): avoid clearing piped output

    ## Problem
    
    Watch mode writes a terminal clear-screen escape sequence to stdout on
    every rerun, even when stdout is piped. This corrupts logs and
    machine-readable output for users composing `tsx watch` with another
    command, as reported in
    [#184](#184).
    
    ## Changes
    
    - Clear the screen only when stdout is a TTY, preserving the existing
    interactive behavior while keeping piped output clean.
    - Cover piped output and a real PTY independently.
    - Normalize bracketed-paste sequences in the PTY test helper so prompt
    detection remains stable across CI terminals.
    privatenumber authored Jul 12, 2026
    Configuration menu
    Copy the full SHA
    95d0672 View commit details
    Browse the repository at this point in the history
  5. perf: load esbuild lazily in CLI

    ## Problem
    
    Every tsx CLI invocation loads esbuild's JavaScript wrapper in the
    parent process, although only `--eval` and `--print` use it there.
    
    Importing the wrapper does not start esbuild's native binary. This is
    therefore a small fixed-cost cleanup, not a major startup optimization.
    Local paired runs showed roughly a 1-2ms median improvement, small
    enough to be lost in normal startup variance.
    
    ## Changes
    
    - Load esbuild dynamically when handling `--eval` or `--print`.
    - Preserve existing eval and print behavior.
    - Guard normal CLI startup against resolving esbuild in the parent
    process.
    privatenumber authored Jul 12, 2026
    Configuration menu
    Copy the full SHA
    d067938 View commit details
    Browse the repository at this point in the history

Commits on Jul 13, 2026

  1. perf: map Node TypeScript formats directly

    ## Problem
    
    Node's resolver already performs package-scope lookup for `.ts` files.
    When it finds `"type": "module"` or `"type": "commonjs"`, it encodes
    that decision as `module-typescript` or `commonjs-typescript`.
    
    tsx previously discarded that result and called
    `getFormatFromFileUrl()`. That parsed the file URL and invoked tsx's own
    package lookup, walking parent directories and consulting its separate
    `package.json` cache just to recover the same `module` or `commonjs`
    decision. This second traversal ran for every resolved TypeScript
    module.
    
    ## Changes
    
    - Map `module-typescript` directly to `module` and `commonjs-typescript`
    directly to `commonjs` in asynchronous and synchronous resolve hooks.
    - Run tsx's package lookup only when Node returns no format, including
    typeless `.ts` files whose type cannot be determined until source is
    loaded.
    - Cover both paths without requiring a valid `package.json` for explicit
    formats.
    - Link the behavior to Node's format-detection implementation.
    privatenumber authored Jul 13, 2026
    Configuration menu
    Copy the full SHA
    cdcc623 View commit details
    Browse the repository at this point in the history
  2. perf: index transform cache lazily

    ## Problem
    
    tsx's transform cache is shared across projects and retains entries for
    seven days. As users work across more projects, unrelated cache files
    accumulate in the same temporary directory.
    
    Every tsx process eagerly read that directory, even when it never needed
    to transform code. Processes that did transform code then scanned the
    full listing for every cache lookup. Users therefore paid a growing
    startup cost based on unrelated past work: with 10,000 unrelated
    entries, a 1,000-module run increased from 396ms to 717ms.
    
    ## Changes
    
    tsx now leaves the disk cache untouched until the first transform-cache
    operation. When the cache is needed, tsx indexes its entries once and
    reuses that index, so unrelated files no longer make every lookup or new
    write progressively slower.
    
    Existing recovery and cleanup behavior remains protected: expired and
    duplicate files are still removed, malformed files are ignored,
    concurrent writers remain supported, and an older valid result is used
    when the newest entry is corrupt. The benchmark uses isolated seeded
    caches, leaving the user's real cache untouched.
    
    Node 24.15, 1,000 TypeScript modules, 5 runs, minimum wall time:
    
    | Unrelated entries | Before | After |
    | ---: | ---: | ---: |
    | 0 | 396ms | 378ms |
    | 1,000 | 433ms | 400ms |
    | 10,000 | 717ms | 486ms |
    privatenumber authored Jul 13, 2026
    Configuration menu
    Copy the full SHA
    e818ad6 View commit details
    Browse the repository at this point in the history
  3. fix(watch): treat script and dependency paths literally

    ## Problem
    
    Projects commonly use braces or brackets in literal path names, such as
    a route named `[id].ts`. In watch mode, tsx sent script and runtime
    dependency paths through the same glob-aware watcher used by
    `--include`.
    
    Chokidar could interpret those literal characters as patterns, so
    editing the intended file might not rerun the process. Users could be
    left running stale code until they restarted tsx manually. Disabling
    globbing for the shared watcher would fix those paths but break
    `--include`, which intentionally accepts glob patterns.
    
    ## Changes
    
    tsx now watches script and runtime dependency paths literally, so files
    containing glob characters reliably trigger a rerun. `--include` uses a
    separate glob-aware watcher, preserving its existing include, exclude,
    and negation behavior.
    
    When both watchers cover the same file, tsx canonicalizes and suppresses
    the duplicate event so one edit still produces one rerun. Watchers also
    attach listeners and finish their initial scan before the child starts,
    preventing early dependency changes from being missed. The additional
    watcher is created only when `--include` is used.
    privatenumber authored Jul 13, 2026
    Configuration menu
    Copy the full SHA
    79fddde View commit details
    Browse the repository at this point in the history
Loading