Skip to content

Commit

Permalink
Migrate from tsimp to swc (#416)
Browse files Browse the repository at this point in the history
* Migrate from tsimp to swc using an import shim to mitigate the bn.js import bug

* Updating version to 2.0.159

---------

Co-authored-by: dc-autobot[bot] <181364585+dc-autobot[bot]@users.noreply.github.com>
  • Loading branch information
mattdean-digicatapult and dc-autobot[bot] authored Jan 6, 2025
1 parent 47bf611 commit 2529c5e
Show file tree
Hide file tree
Showing 9 changed files with 2,479 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .depcheckrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ignores: ["pg", "prettier-plugin-organize-imports", "@digicatapult/tsimp", "reflect-metadata"]
ignores: ["pg", "prettier-plugin-organize-imports", "reflect-metadata", "rimraf"]
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ coverage
.idea
.env
.vscode
.tsimp
build
src/routes.ts
src/swagger.json
24 changes: 24 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://swc.rs/schema.json",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true,
"importMeta": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"useDefineForClassFields": true
},
"target": "es2022"
},
"exclude": [
"/__test__/"
],
"sourceMaps": true,
"isModule": true,
"minify": false
}
11 changes: 11 additions & 0 deletions import/hooks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { resolve as swcResolve } from '@swc-node/register/esm'
export { load } from '@swc-node/register/esm'

const skipSwcSet = new Set(['bn.js'])

export function resolve(specifier, context, nextResolve) {
if (skipSwcSet.has(specifier)) {
return nextResolve(specifier, context)
}
return swcResolve(specifier, context, nextResolve)
}
3 changes: 3 additions & 0 deletions import/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { register } from 'node:module'

register('./hooks.mjs', import.meta.url)
Loading

0 comments on commit 2529c5e

Please sign in to comment.