Skip to content

Commit

Permalink
Migrate from tsimp to swc (#555)
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 3.1.27

* Try a shorter sleep

---------

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 eeca5e8 commit f79af40
Show file tree
Hide file tree
Showing 12 changed files with 2,130 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .depcheckrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ignores: [
'@swc/cli',
'concurrently',
'pino-colada',
'nodemon',
'multer',
'pg',
'@digicatapult/tsimp',
'ts-node',
'@polkadot/util-crypto',
'@polkadot/types',
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ src/swagger.json
src/routes.ts
dist
coverage
.tsimp

.npm
.env
Expand Down
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
}
2 changes: 1 addition & 1 deletion docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
image: digicatapult/sqnc-identity-service:latest
container_name: identity-service
command: /bin/sh -c "
sleep 30 &&
sleep 20 &&
npm run db:migrate &&
npm start"
ports:
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const compat = new FlatCompat({

export default [
{
ignores: ['**/node_modules', '**/package.json', '**/build', '**/.tsimp'],
ignores: ['**/node_modules', '**/package.json', '**/build'],
},
...compat.extends('eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'),
{
Expand Down
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)
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exec": "node --import=@digicatapult/tsimp/import src/index.ts",
"exec": "node --import=./import/index.mjs src/index.ts",
"watch": ["src"],
"ext": "ts"
}
Loading

0 comments on commit f79af40

Please sign in to comment.