singularity-forge/packages/native/package.json
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

92 lines
2.7 KiB
JSON

{
"name": "@gsd/native",
"version": "0.1.0",
"description": "Native Rust bindings for GSD \u2014 high-performance native modules via N-API",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.json",
"build:native": "node ../../native/scripts/build.js",
"build:native:dev": "node ../../native/scripts/build.js --dev",
"test": "npm run build:native:dev && node --test src/__tests__/grep.test.mjs src/__tests__/ps.test.mjs src/__tests__/glob.test.mjs src/__tests__/clipboard.test.mjs src/__tests__/highlight.test.mjs src/__tests__/html.test.mjs src/__tests__/text.test.mjs src/__tests__/fd.test.mjs src/__tests__/image.test.mjs"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./grep": {
"types": "./dist/grep/index.d.ts",
"default": "./dist/grep/index.js"
},
"./ps": {
"types": "./dist/ps/index.d.ts",
"default": "./dist/ps/index.js"
},
"./glob": {
"types": "./dist/glob/index.d.ts",
"default": "./dist/glob/index.js"
},
"./clipboard": {
"types": "./dist/clipboard/index.d.ts",
"default": "./dist/clipboard/index.js"
},
"./ast": {
"types": "./dist/ast/index.d.ts",
"default": "./dist/ast/index.js"
},
"./html": {
"types": "./dist/html/index.d.ts",
"default": "./dist/html/index.js"
},
"./text": {
"types": "./dist/text/index.d.ts",
"default": "./dist/text/index.js"
},
"./fd": {
"types": "./dist/fd/index.d.ts",
"default": "./dist/fd/index.js"
},
"./image": {
"types": "./dist/image/index.d.ts",
"default": "./dist/image/index.js"
},
"./xxhash": {
"types": "./dist/xxhash/index.d.ts",
"default": "./dist/xxhash/index.js"
},
"./diff": {
"types": "./dist/diff/index.d.ts",
"default": "./dist/diff/index.js"
},
"./gsd-parser": {
"types": "./dist/gsd-parser/index.d.ts",
"default": "./dist/gsd-parser/index.js"
},
"./highlight": {
"types": "./dist/highlight/index.d.ts",
"default": "./dist/highlight/index.js"
},
"./json-parse": {
"types": "./dist/json-parse/index.d.ts",
"default": "./dist/json-parse/index.js"
},
"./stream-process": {
"types": "./dist/stream-process/index.d.ts",
"default": "./dist/stream-process/index.js"
},
"./truncate": {
"types": "./dist/truncate/index.d.ts",
"default": "./dist/truncate/index.js"
},
"./ttsr": {
"types": "./dist/ttsr/index.d.ts",
"default": "./dist/ttsr/index.js"
}
},
"files": [
"dist"
],
"license": "MIT"
}