singularity-forge/packages/native/src
Tom Boucher abd9be24e9 fix: align @gsd/native module type with compiled output (#3253)
* fix: align @gsd/native module type with compiled output (#2861)

The package declared "type": "module" and used "import"-only export
conditions, but the addon loader used import.meta.url which is
incompatible when the parent package enforces ESM resolution on
Node.js v24. Switch to "type": "commonjs" with "default" export
conditions and remove the import.meta.url/__dirname shim (CJS
provides both natively).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: restore dual CJS/ESM compat for native addon loader

The ESM-to-CJS conversion removed import.meta.url polyfills, but the CI
test loader (dist-redirect.mjs) transpiles this file to ESM via
ts.transpileModule — making __dirname and require unavailable at test time.

Add runtime typeof guards that use the CJS globals when available (compiled
output) and fall back to import.meta.url in ESM (test runner). Use
@ts-expect-error to suppress TS1470 for the import.meta branches that are
unreachable in the compiled CJS output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: use indirect eval for import.meta.url to avoid CJS parse-time error

import.meta is a parse-time syntax error in CJS — typeof guards don't
help because Node.js rejects the syntax before executing any code.
Wrapping in new Function("return import.meta.url") hides the syntax
from the CJS parser while still working when executed as ESM (test runner).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: replace new Function(import.meta.url) with loader-injected CJS globals

import.meta is static syntax unavailable in new Function() and eval()
scopes, causing rtk-portability CI failures across all platforms.

Instead of trying to access import.meta.url indirectly, the test loader
(dist-redirect.mjs) now injects __dirname, __filename, and require as a
preamble when transpiling workspace packages to ESM. This lets native.ts
use __dirname/require directly in both CJS (production) and ESM (CI test)
contexts without any import.meta.url fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-30 13:51:57 -06:00
..
__tests__ fix: align @gsd/native module type with compiled output (#3253) 2026-03-30 13:51:57 -06:00
ast feat: add native ast module with ast-grep structural search and rewrite 2026-03-13 13:02:29 -06:00
clipboard feat: add native clipboard module with arboard backend (#228) 2026-03-13 12:48:27 -06:00
diff feat: add native Rust diff engine for edit tool 2026-03-13 14:11:40 -06:00
fd perf: optimize discovery and interactive hot paths 2026-03-14 16:03:44 -05:00
glob fix: resolve TypeScript build errors in glob callback type and hashline test import 2026-03-13 13:47:33 -06:00
grep perf: optimize discovery and interactive hot paths 2026-03-14 16:03:44 -05:00
gsd-parser feat: add native Rust GSD file parser for .gsd/ directory parsing 2026-03-13 14:12:17 -06:00
highlight feat: add syntect-based syntax highlighting module to native engine (#227) 2026-03-13 12:47:02 -06:00
html feat: add html-to-markdown native module 2026-03-13 12:40:42 -06:00
image feat: add native image module — decode, encode, and resize via Rust image crate 2026-03-13 12:51:49 -06:00
json-parse feat: opus 4.6 1M default, model selector UX, Discord onboarding (#290) 2026-03-14 08:43:56 -06:00
ps feat: add cross-platform process tree kill module (ps) (#225) 2026-03-13 12:43:50 -06:00
stream-process fix: use Array.from instead of Buffer.from for native processStreamChunk state (#2348) 2026-03-25 00:08:11 -06:00
text feat: add ANSI-aware text measurement and slicing native module 2026-03-13 12:42:42 -06:00
truncate feat: native Rust output truncation module (#268) 2026-03-13 16:48:49 -06:00
ttsr feat: add native Rust TTSR regex engine via RegexSet 2026-03-13 13:57:12 -06:00
xxhash Fix execute-task loop detection: adaptive reconciliation instead of hard stop (#342) 2026-03-14 07:26:10 -06:00
index.ts Fix execute-task loop detection: adaptive reconciliation instead of hard stop (#342) 2026-03-14 07:26:10 -06:00
native.ts fix: align @gsd/native module type with compiled output (#3253) 2026-03-30 13:51:57 -06:00