{"name":"@swc-node/register","version":"1.12.0","keywords":["swc","babel","ts-node","napi-rs","uglify","node-rs","napi-rs","napi","n-api","esbuild","tsc","webpack"],"author":"LongYinan <github@lyn.one>","license":"MIT","_id":"@swc-node/register@1.12.0","maintainers":[{"name":"broooooklyn","email":"lynweklm@gmail.com"}],"homepage":"https://github.com/swc-project/swc-node","bugs":{"url":"https://github.com/swc-project/swc-node/issues"},"dist":{"shasum":"d406a041f32366a6d927158c4e50959ff9723d24","tarball":"http://registry-npm.ywwl.com/@swc-node/register/download/@swc-node/register-1.12.0.tgz","fileCount":29,"integrity":"sha512-RnkF4NOHqv3JAKJS9YguLeFH81NPv8VQKTXt5lMJfOujB7qvZXJRei5LJeulihF0ZMD1UIruIA0gm9it/bH37g==","signatures":[{"sig":"MEQCIBq3vxevJpSmGadQ0xwrRRe1uIfLussZqwNwyXQL2GhBAiArhKmINkdq2eEIbuJEl3y3ugVNgUguLbCsThLNPEygYg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@swc-node%2fregister@1.12.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":180354,"size":42723,"noattachment":false,"key":"/@swc-node/register/-/@swc-node/register-1.12.0.tgz"},"main":"index.js","exports":{".":{"node":"./index.js"},"./esm":{"import":"./esm/esm.mjs"},"./register":{"require":"./lib/register.js"},"./esm-register":{"import":"./esm/esm-register.mjs"},"./read-default-tsconfig":{"node":"./lib/read-default-tsconfig.js"}},"funding":{"url":"https://github.com/sponsors/Brooooooklyn","type":"github"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:802d631d-1bca-44ce-bef1-bd83d047ea19"}},"repository":{"url":"git+https://github.com/swc-project/swc-node.git","type":"git"},"description":"SWC node register","directories":{},"_nodeVersion":"24.18.0","dependencies":{"debug":"^4.4.1","tslib":"^2.8.1","pirates":"^4.0.7","colorette":"^2.0.20","oxc-resolver":"^11.6.1","@swc-node/core":"1.15.0","@node-rs/xxhash":"^1.7.6","json-stable-stringify":"^1.3.0","@swc-node/sourcemap-support":"^0.6.1"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"sinon":"^22.0.0","lodash":"^4.17.21","@swc/core":"^1.13.3","typescript":"^5.9.2","@swc/helpers":"^0.5.17","@types/debug":"^4.1.12"},"peerDependencies":{"@swc/core":">= 1.4.13","typescript":">= 4.3 < 7"},"_npmOperationalInternal":{"tmp":"tmp/register_1.12.0_1784191186060_0.6856004056861538","host":"s3://npm-registry-packages-npm-production"},"readme":"# `@swc-node/register`\n\n<a href=\"https://npmcharts.com/compare/@swc-node/register?minimal=true\"><img src=\"https://img.shields.io/npm/dm/@swc-node/register.svg?sanitize=true\" alt=\"Downloads\" /></a>\n\n> 🚀 Help me to become a full-time open-source developer by [sponsoring me on Github](https://github.com/sponsors/Brooooooklyn)\n\n## Usage\n\n```ts\nconst { register } = require('@swc-node/register/register')\n\nregister({\n  ...\n})\n```\n\n### CLI\n\n```\nnode -r @swc-node/register index.ts\n```\n\n### Mocha\n\n```\nmocha --require @swc-node/register --watch-extensions ts,tsx \"test/**/*.{ts,tsx}\" [...args]\n```\n\n### ava\n\n```json\n// package.json\n\n{\n  \"ava\": {\n    \"extensions\": [\"ts\", \"tsx\"],\n    \"require\": [\"@swc-node/register\"],\n    \"files\": [\"packages/**/*.spec.{ts,tsx}\"]\n  }\n}\n```\n\n## Read `tsconfig.json`\n\nset `SWC_NODE_PROJECT` or `TS_NODE_PROJECT` env:\n\n```bash\nSWC_NODE_PROJECT=./tsconfig.test.json mocha --require @swc-node/register --watch-extensions ts,tsx \"test/**/*.{ts,tsx}\" [...args]\n```\n\n`@swc-node/register` respect the following option in `tsconfig`:\n\n### `extends`\n\n`@swc-node/register` respect the extends key in `tsconfig.json`, and use the **merged** values.\n\n### `compilerOptions.target`\n\n```ts\nswitch (target) {\n  case ts.ScriptTarget.ES3:\n    return 'es3'\n  case ts.ScriptTarget.ES5:\n    return 'es5'\n  case ts.ScriptTarget.ES2015:\n    return 'es2015'\n  case ts.ScriptTarget.ES2016:\n    return 'es2016'\n  case ts.ScriptTarget.ES2017:\n    return 'es2017'\n  case ts.ScriptTarget.ES2018:\n    return 'es2018'\n  case ts.ScriptTarget.ES2019:\n    return 'es2019'\n  case ts.ScriptTarget.ES2020:\n  case ts.ScriptTarget.ES2021:\n  case ts.ScriptTarget.ES2022:\n  case ts.ScriptTarget.ESNext:\n  case ts.ScriptTarget.Latest:\n    return 'es2020'\n  case ts.ScriptTarget.JSON:\n    return 'es5'\n}\n```\n\n### `compilerOptions.jsx`\n\nIf `filename` endsWith `.jsx` or `.tsx`, always set the `jsx: true` in `swc config` regards the `jsx` option in `tsconfig`.\nIf `filename` not endsWith `.jsx` or `.tsx`, set the `jsx: Boolean(tsconfig.compilerOptions.jsx)` in `swc config`.\n\n### compilerOptions.module\n\n> notes, if `compilerOptions.module` higher than `es2020`, the `dynamicImport` in `swc config` will be set to `true`.\n\n```ts\nswitch (moduleKind) {\n  case ts.ModuleKind.CommonJS:\n    return 'commonjs'\n  case ts.ModuleKind.UMD:\n    return 'umd'\n  case ts.ModuleKind.AMD:\n    return 'amd'\n  case ts.ModuleKind.ES2015:\n  case ts.ModuleKind.ES2020:\n  case ts.ModuleKind.ESNext:\n  case ts.ModuleKind.None:\n    return 'es6'\n  case ts.ModuleKind.System:\n    throw new TypeError('Do not support system kind module')\n}\n```\n\n### compilerOptions.experimentalDecorators\n\nRespect the boolean value in `tsconfig`.\n\n### compilerOptions.emitDecoratorMetadata\n\nRespect the boolean value in `tsconfig`.\n\n### compilerOptions.esModuleInterop\n\nRespect the boolean value in `tsconfig`.\n\n### include/exclude\n\n`TypeScript` gives files list to `@swc-node/register`, if parse `tsconfig.json` failed or files list empty, `@swc-node/register` will transform all files which were required.\n\nAnd if failed to parse `tsconfig.json`, `@swc-node/register` will print warning which contains failed reason.\n\n## Performance tuning\n\n### Transform cache\n\n`@swc-node/register` now keeps a transform cache (memory + disk) keyed by source, filename, compiler options, and runtime versions.\n\nEnvironment variables:\n\n- `SWC_NODE_CACHE=0` disable cache.\n- `SWC_NODE_CACHE_DIR=./path/to/cache` choose disk cache directory.\n- `SWC_NODE_CACHE_MEMORY_LIMIT=2000` max in-process transform entries.\n\nProgrammatic cache control:\n\n```js\nconst { clearTransformCache, getTransformCacheDirectory } = require('@swc-node/register/register')\n\n// clear memory + disk (default)\nclearTransformCache()\n\n// clear only memory cache\nclearTransformCache({ memory: true, disk: false })\n\n// inspect resolved disk cache path\nconsole.log(getTransformCacheDirectory())\n```\n\n### Source map memory mode\n\nUse `SWC_NODE_SOURCE_MAP_MODE` to tune source map memory behavior:\n\n- `auto` (default): inline maps when Node native source maps are enabled, otherwise map-store mode.\n- `inline`: inline data URL source maps only.\n- `store`: in-memory map store only (`source-map-support` path).\n- `both`: inline + store (highest memory use, mainly for compatibility/debug edge cases).\n- `none`: disable both inline/store map injection.\n\n### Skipping compilation for runtime JS\n\nPlain JavaScript files (`.js`, `.mjs`, `.cjs`, `.es`, `.es6`) that Node can already\nexecute are passed through without an SWC transform, which speeds up startup. A\nfile is still transformed when it needs to be — it contains JSX, it uses ESM\nsyntax under CommonJS output, or an `.swcrc` is in effect.\n\nKnown caveats (kept intentionally, for speed):\n\n- A `tsconfig.json` `paths` alias imported via **dynamic** `import('@alias/…')` in a\n  passed-through `.js` file is not rewritten, so the alias will not resolve. Static\n  `import`/`require` are unaffected. Use `.ts`/`.mts` (or a static import) if you\n  rely on alias resolution here.\n- Dynamically `import()`-ing a CommonJS module from a passed-through `.js` file\n  yields a native module namespace rather than SWC's interop shape (`ns.default`\n  instead of `ns`).\n","publish_time":1784191186183,"_cnpm_publish_time":1784191186183,"dist-tags":{"latest":"1.12.1"}}