Skip to content

release: v3.5.1 - #89

Merged
Shinrai merged 17 commits into
masterfrom
release/3.5.1
May 18, 2026
Merged

Shinrai merged 17 commits into
masterfrom
release/3.5.1

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

  • fix(handlers): make util.inspect.custom hook non-enumerable on prototype (db1849b)
  • fix(typescript): mask regex literals to avoid comment mis-scans (48cc90a)
  • fix(typescript): point remapped relative imports at the resolved path (8e4a8ef)
  • fix(build): skip slothlet export patch when tsc emits a named export (7d38f79)
  • fix(typescript): rewrite relative import specifiers separated by comments (f9979e8)
  • fix(types): emit named slothlet export and drop bogus UnifiedWrapper index signature (76c1668)
  • fix(typescript): resolve relative imports between .ts/.mts modules (efa4305)
  • fix(typescript): anchor relative TS import specifiers at the source dir (7629973)
  • fix(runtime): exclude TypedArray/Buffer/DataView from class-instance wrapper (1caf6ca)

🔧 Other Changes

  • perf(typescript): slice identifier runs in maskStringsAndComments (1d9cefc)
  • docs(typescript): mark formatDiagnostics @public (13882b6)
  • chore: add file headers to typescript-relative test fixtures (04ecede)
  • docs: update v3.5.1 changelog and docs for relative TS-to-TS imports (70d133d)
  • docs: add v3.5.1 changelog and sync docs for the v3.5.1 fixes (4e6857c)
  • build(types): regenerate declarations for rewriteRelativeSpecifiers export (25f731b)
  • chore: bump version to 3.5.1 (0f29331)
👥 Contributors

coverage

Metric Coverage
Statements 100.0%
Branches 100.0%
Functions 100.0%
Lines 100.0%

Avg: 100.0% · 22a51c3 · Node lts/*

Shinrai and others added 2 commits May 17, 2026 20:15
…wrapper

A Buffer (or any TypedArray view / DataView) returned across the `self`
boundary was detected by runtime_isClassInstance as a wrappable class
instance and proxy-wrapped. The proxy breaks intrinsic accessors such as
TypedArray `.length`/`.byteLength`, which rely on the value's internal
slots being read directly off the receiver.

Add the abstract %TypedArray% base constructor (covers Buffer and every
numeric view) and DataView to EXCLUDED_INSTANCEOF_CLASSES so binary
buffers cross `self` untouched, alongside the already-excluded
ArrayBuffer.
@cldmv-bot cldmv-bot Bot added release Marks a pull request as a pending release — merge to publish a new version semver: patch This release contains only backwards-compatible bug fixes type: bug Something is broken or not behaving as expected labels May 18, 2026
@Shinrai
Shinrai requested a review from Copilot May 18, 2026 04:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This release PR bumps to v3.5.1 and fixes a runtime wrapping edge case by ensuring binary buffer/view objects (TypedArrays/Buffer/DataView) are excluded from the class-instance proxy wrapper, preventing broken intrinsic accessors (e.g., Buffer.length).

Changes:

  • Exclude %TypedArray% (covering Buffer and all TypedArray views) and DataView from runtime_isClassInstance wrapping logic.
  • Add vitest coverage to assert Buffer, TypedArray views, DataView, and ArrayBuffer are not treated as wrappable class instances.
  • Bump package version to 3.5.1 (and update lockfile/types sourcemap output).

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/lib/helpers/class-instance-wrapper.mjs Updates exclusion logic to prevent proxy-wrapping TypedArrays/Buffer/DataView.
tests/vitests/suites/helpers/class-instance-wrapper-proxy.test.vitest.mjs Adds regression tests ensuring binary buffers/views are not wrapped.
package.json Bumps version to 3.5.1 for the release.
package-lock.json Updates lockfile version fields to 3.5.1.
types/src/lib/helpers/class-instance-wrapper.d.mts.map Regenerated types sourcemap reflecting the code change.

Transformed .ts/.mts modules are written to a cache file under
.slothlet-cache/ and imported from there. esbuild/tsc transform the code
but never rewrite import specifiers, so a relative specifier
(`./sibling.mjs`, `../shared/util.mjs`) resolved against the cache
directory instead of the original source tree and failed with
`Cannot find module`. The 3.5.0 fix moved TS modules off `data:` URLs to
real cache files — fixing bare specifiers — but left relative ones broken.

Add rewriteRelativeSpecifiers(): before the transformed code is hashed
and cached, every relative import/export/dynamic-import specifier is
resolved against the original source directory and emitted as an
absolute file:// URL, which resolves identically regardless of where the
importing cache file lives. Bare specifiers and absolute URLs are left
untouched. Covers static `import`/`export … from` (incl. multi-line
binding lists and `export *`), bare side-effect `import "…"`, and dynamic
`import("…")` with a static string literal.

Relative imports that resolve to another .ts/.mts file are rewritten too
but still won't load — Node has no loader for those extensions; slothlet
wires TS modules together via self.* at runtime.

This comment was marked as resolved.

…xport

The new rewriteRelativeSpecifiers export was tagged `@internal`, which
tsc strips from `.d.mts` output under `stripInternal: true` — so the
published declarations omitted it and still described relative imports
as out-of-scope. Retag it `@private` (matching the exported-for-testing
`formatDiagnostics` helper in the same module, which is not stripped) so
runtime exports and type declarations stay in sync for TS consumers.

Regenerate types/ via `npm run build:types`:
- typescript.d.mts: adds rewriteRelativeSpecifiers; refreshes the
  writeTransformedToCache doc (relative imports are now anchored, not
  out-of-scope).
- index.d.mts, unified-wrapper.d.mts: pre-existing drift the committed
  declarations had accumulated relative to source — corrected by the
  same regeneration.

Validated with `npm run test:types` (43 exports).

This comment was marked as resolved.

Shinrai added 4 commits May 17, 2026 23:40
- docs/changelog/v3/v3.5.1.md: new patch-release changelog covering the
  Buffer/TypedArray/DataView class-instance-wrapper exclusion and the
  relative-import anchoring for .ts/.mts modules.
- README.md: promote v3.5.1 to "Latest"; move v3.5.0 into Recent Releases
  and drop v3.3.1 to keep the list at 4 entries.
- MODULE-STRUCTURE.md / TYPESCRIPT.md: relative imports to plain
  .mjs/.cjs/.js files now resolve from TS modules; only relative imports
  targeting another .ts/.mts file remain unsupported.
- CONTEXT-PROPAGATION.md: the built-in exclusion list now names
  ArrayBuffer, DataView, Buffer, and typed-array views explicitly.
Completes the relative-import fix from earlier in this release: a
.ts/.mts module can now relatively import another .ts/.mts module, not
just plain .mjs/.cjs/.js files.

writeTransformedToCache() follows the transitive graph of relative
.ts/.mts imports — each dependency is transpiled and cached, and the
importing specifier is rewritten to the dependency's cache file. Import
cycles are handled; each cache file is named by a content hash over its
whole relative-.ts/.mts closure, so editing any module in the graph
busts every importer's URL on reload. The TypeScript source-extension
convention is respected (a `./x.mjs` specifier may resolve to `x.mts`).

rewriteRelativeSpecifiers() now skips matches inside string literals and
comments (via the new maskStringsAndComments scanner), so import-shaped
text in string data — e.g. `const s = "import('./x')"` — is never
mutated.

The loader threads a transpiler callback through to the cache writer in
both fast and strict modes; strict-mode type errors in a relatively
imported module surface the same way as for the entry module.
…index signature

Two declaration-emit defects in the published types/, surfaced while
regenerating declarations for this release:

- index.mjs exports `slothlet` as both the default and a named alias,
  but tsc emitted only the default — `import { slothlet }` failed type
  checking despite working at runtime. Declaring the entry point as a
  `const` (not `export default function`) makes tsc emit the named
  `export { slothlet }` alongside the default.

- UnifiedWrapper's `util.inspect.custom` handler was a computed-key
  class member, which tsc emits as a spurious `[x: number]` index
  signature that makes the type look array-like. The handler is now an
  ordinary named method wired to the symbol via a prototype assignment
  after the class, so the generated declaration is clean.

Runtime behavior is unchanged; both fixes only affect declaration emit.
- changelog: relative imports now reach other .ts/.mts modules (not just
  plain .mjs/.cjs/.js); document the recursive transpile/link behavior,
  string/comment-skipping, and the two type-declaration fixes.
- MODULE-STRUCTURE.md / TYPESCRIPT.md / README.md: relative imports of
  other .ts/.mts modules are transpiled and linked automatically.

This comment was marked as resolved.

Shinrai added 3 commits May 18, 2026 07:03
…ents

rewriteRelativeSpecifiers only allowed plain whitespace between the
`from`/`import` keyword and the module string. JavaScript permits
comments between those tokens, and the transpilers preserve them:
tsc keeps comments by default, and esbuild deliberately retains magic
comments inside `import()` (e.g. `import(/* webpackIgnore: true */
"./x.mjs")`). A comment in that gap defeated the match, so the relative
specifier was left unrewritten — it then resolved against the
`.slothlet-cache/` directory instead of the original source and failed
at runtime with `Cannot find module`.

Two agent reports flagged this: one for the static `import`/`export …
from` pattern, one for the dynamic `import()` pattern. Both were
accurate. The reports did not mention that a comment between the closing
quote and `)` in a dynamic import has the same root cause; that case is
also covered here.

Introduce a `TOKEN_GAP` sub-pattern matching whitespace and/or line and
block comments — every inter-token gap JavaScript allows — and use it in
all three rewrite patterns wherever they previously hard-coded `\s*`.
The patterns are hoisted to module-scope constants. String/comment
masking still skips import-shaped text in string data and comments, so
the broadened gap does not widen what gets mutated.
build-exports.mjs patches `types/index.d.mts` to add a named
`export { slothlet }` for source shapes where tsc emits `slothlet`
only as the default export. The guard checked solely for the literal
string `export { slothlet }`.

tsc renders the JSDoc-annotated entry point as `export function
slothlet(...)` — a declaration that already IS the named export. That
string does not contain `export { slothlet }`, so the patch fired and
appended a second named export of `slothlet`, producing a TS2484
declaration conflict that failed `build:types`/`test:types` and the
whole `build:dev` pipeline.

Detect an existing named `slothlet` export in any form — an
`export function`/`const`/`class slothlet` declaration or an
`export { slothlet }` statement — and skip the patch when one is
present. `export default slothlet` and `export { slothlet as default }`
are the default export and correctly do not count.
`npm run fix:headers` adds the standard project header to three
external-module fixtures under api_tests/api_test_typescript_relative/
that were missing it. Committed so the header check no longer reports
them as dirty.

This comment was marked as resolved.

writeTransformedToCache's Phase-3 rewrite callback handled a relative
`.ts`/`.mts` import that was followed (Case A → cache file) but its
fallback emitted `pathToFileURL(absoluteTarget)` — the specifier path
exactly as written. When `resolveModuleFile` had remapped the target
via the TS source-extension convention (specifier `./dep.js`, on-disk
source `dep.ts`), `absoluteTarget` is a non-existent `dep.js`, so the
fallback produced a `file://…/dep.js` URL pointing at nothing.

The agent report was accurate about the cause and the fix. Scope note:
in production `loader.mjs` always passes a `transform` callback, so
Phase 1 transpiles every relative `.ts`/`.mts` dependency into
`transformed` and Case A handles them all — the fallback is reached for
a TS target only in the no-`transform` mode (tests / a documented
degraded path the JSDoc already describes as non-loading). The fix is
still correct: it makes the code match its JSDoc ("left at its source
path") and emit a URL for a file that exists.

Use `resolved.path` instead of `absoluteTarget` in the fallback.
`resolveModuleFile` only ever returns `resolved.path !== absoluteTarget`
when it remapped to a `.ts`/`.mts` source (`isTS` true); for plain
`.mjs`/`.cjs`/`.js` targets `resolved.path === absoluteTarget`, so the
change is identical for them and only corrects the TS-remap case.

This comment was marked as resolved.

Shinrai added 2 commits May 18, 2026 08:07
maskStringsAndComments treated every `//` and `/*` as a comment start
with no awareness of regular-expression literals. A regex whose body
contains comment-shaped text — e.g. `/\/\//` — was scanned character by
character, and the `//` inside it was mistaken for a line comment, so
the scanner masked the rest of the physical line. When a real dynamic
`import("./dep.mjs")` appeared later on that same line, its match offset
landed in the spuriously-masked region and `rewriteRelativeSpecifiers`
skipped it — leaving the relative specifier to resolve against the
`.slothlet-cache/` directory and fail at runtime.

The agent report was accurate. Fix: scan regex literals as first-class
tokens and mask them whole, so comment-shaped text in a regex body is
never re-interpreted. Telling a regex literal apart from the division
operator needs the preceding token, so the scanner now tracks whether
the last significant token expects an expression (a `/` then opens a
regex) or is a value (a `/` is then division), including a keyword set
for `return`/`typeof`/`await`/etc. The known imperfect case — a `/`
directly after the `)` of an `if`/`for`/`while` header — is documented;
a full tokenizer is deliberately not pulled in for this.

Adds unit tests for regex masking (incl. a `/` inside a `[...]` class)
and a rewrite test for the report's exact scenario: a regex containing
`//` followed by a relative `import()` on the same line.
UnifiedWrapper wires Node's `util.inspect.custom` hook by assigning
`UnifiedWrapper.prototype[util.inspect.custom] = …` after the class
body (kept off the class body so tsc does not emit a spurious numeric
index signature). A plain assignment creates the property as
enumerable, whereas a computed `[util.inspect.custom]()` method
declared in the class body would be non-enumerable — so the prototype
property diverged from the class-method semantics the surrounding code
documents it should match.

The agent report was accurate. Replace the assignment with
`Object.defineProperty` using `{ writable: true, enumerable: false,
configurable: true }` — the exact descriptor a class-body method
produces — so the hook is wired with identical runtime attributes while
still keeping the symbol off the class body.

This comment was marked as resolved.

formatDiagnostics is exported and consumed by loader.mjs in the same
import as the @public transformTypeScriptStrict and writeTransformedToCache,
yet it alone among the loader-facing exports was tagged @Private — an
inconsistency flagged in review.

Tag it @public to match the other functions that form this module's
internal API surface. resolveModuleFile, maskStringsAndComments and
rewriteRelativeSpecifiers stay @Private deliberately: they are exported
only so unit tests can reach them, not as an API.

This comment was marked as resolved.

The identifier/keyword scan built its word with `word += code[i++]`
per character. Slice the run out once with `code.slice(start, i)`
instead, so scanning an identifier is linear in its length rather than
relying on the engine to optimize repeated concatenation. maskStrings-
AndComments runs over every transformed module before caching.

Behavior is unchanged — the sliced string is the same word the
concatenation produced; only the keyword-set lookup consumes it.

This comment was marked as resolved.

The Type Declarations section described two fixes in terms a later
commit on this branch superseded:

- The named `slothlet` export is emitted by tsc as `export function
  slothlet(…)`, not an `export { slothlet }` statement. Document that,
  and the accompanying `build-exports.mjs` correction that stopped it
  appending a duplicate `export { slothlet }` (a TS2484 conflict).
- The `util.inspect.custom` handler is wired with `Object.defineProperty`
  (non-enumerable), not a plain prototype assignment.

Also note the relative-specifier rewrite tolerates comments between
import tokens and skips regex-literal bodies, and list the matching new
test cases under Test Coverage.
@Shinrai
Shinrai merged commit 9ecb887 into master May 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release Marks a pull request as a pending release — merge to publish a new version semver: patch This release contains only backwards-compatible bug fixes type: bug Something is broken or not behaving as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants