Skip to content

chore(typescript): change moduleResolution #1605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4ce46f3
chore(typescript): change moduleResolution
alexandre-abrioux Apr 14, 2025
1cc4d4d
remove corepack field
alexandre-abrioux Apr 14, 2025
08c1467
use nodenext
alexandre-abrioux Apr 14, 2025
13fcb50
change module too
alexandre-abrioux Apr 14, 2025
ec996e5
fix ajv
alexandre-abrioux Apr 14, 2025
c210da6
remove corepack field
alexandre-abrioux Apr 14, 2025
1aa1232
update hinkal
alexandre-abrioux Apr 15, 2025
bf4b00f
bump hinkal
alexandre-abrioux Apr 15, 2025
0882d51
Merge branch 'master' into moduleresolution
alexandre-abrioux Apr 17, 2025
ddd2837
fix ci
alexandre-abrioux Apr 17, 2025
4a7e963
fix ajv
alexandre-abrioux Apr 17, 2025
ca74d7c
fix jest
alexandre-abrioux Apr 17, 2025
2b9a2e9
remove corepack field
alexandre-abrioux Apr 17, 2025
9086e84
dedupe package
alexandre-abrioux Apr 17, 2025
5e58c52
esModuleInterop
alexandre-abrioux Apr 17, 2025
5511457
fix ci
alexandre-abrioux Apr 17, 2025
ec033a9
remove ci change
alexandre-abrioux Apr 17, 2025
944fd75
fix ci
alexandre-abrioux Apr 17, 2025
3dc97e4
fix ci
alexandre-abrioux Apr 17, 2025
2957d4d
update ts-jest
alexandre-abrioux Apr 17, 2025
2f55bf1
add isolatedmodules
alexandre-abrioux Apr 17, 2025
db0eb65
fix isolatedmodule errors
alexandre-abrioux Apr 17, 2025
17f77bd
fix isolatedmodule errors
alexandre-abrioux Apr 17, 2025
008fefe
fix isolatedmodule errors
alexandre-abrioux Apr 17, 2025
6e97cbb
fix isolatedmodule errors
alexandre-abrioux Apr 17, 2025
b43d2ca
fix isolatedmodule errors
alexandre-abrioux Apr 17, 2025
e491985
fix isolatedmodule errors
alexandre-abrioux Apr 17, 2025
7960f48
fix isolatedmodule errors
alexandre-abrioux Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ jobs:
--ignore @requestnetwork/payment-processor \
--ignore @requestnetwork/integration-test \
--concurrency=2
environment:
# Lerna starts 2 Jest commands at the same time (see above --concurrency=2),
# so we use 50% of our CPU cores on each
JEST_MAX_WORKERS: '50%'
Comment on lines +122 to +125
Copy link
Member Author

@alexandre-abrioux alexandre-abrioux Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not mandatory.

While fiddling with our TS config, I had some issues with the CI, especially before I found out that we had to activate isolatedModules=true for ts-jest to work with module=nodenext (see explanation in the tsconfig.json file). At this point, ts-jest was consuming a considerable amount of RAM during tests. The job highlighted above (test-unit) constantly consumed 100% of the RAM and failed with timeouts or out-of-memory errors.

While digging, I found that configuring Jest to only use 4 workers (50% of CPU cores) instead of 8 (default 100% CPU cores) completely stabilized the tests, even with this buggy ts-jest config consuming a lot of memory.

After enabling isolatedModules=true, I could have reverted that change, because ts-jest was back to consuming a normal amount of memory. However this change seems to improve test time quite a bit:

In the end, even if this change is not mandatory, I have kept it as it made our pipeline faster.

Side note that confirms this: Adobe dev team advises in their blog using a maximum of 50% CPU cores for Jest workers, especially on small machines like CI runners, so as to leave some room for Jest to spawn NodeJS processes.

Here, I have only modified the configuration for this specific test-unit job, which was causing me issues, but the new JEST_MAX_WORKERS environment variable I introduced could be extended later on to other jobs if needed, to reduce potential flakiness or increase CI speed.

- store_test_results:
path: packages/advance-logic/reports/
- store_test_results:
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ module.exports = {
},
],
],
...(process.env.JEST_MAX_WORKERS ? { maxWorkers: process.env.JEST_MAX_WORKERS } : {}),
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"npm-package-json-lint": "5.1.0",
"prettier": "2.8.8",
"prettier-plugin-solidity": "1.0.0-beta.19",
"typescript": "5.1.3"
"typescript": "5.8.3"
Copy link
Member Author

@alexandre-abrioux alexandre-abrioux Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated Typescript to support loading ES modules in CommonJS synchronously (without await import()):
https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require

This is needed to support the latest version of graphql-request used in the payment-detection package.

},
"resolutions": {
"elliptic": "^6.6.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/advanced-logic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@
"@requestnetwork/currency": "0.28.0",
"@requestnetwork/types": "0.54.0",
"@requestnetwork/utils": "0.54.0",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@types/jest": "29.5.6",
"@types/node": "18.11.9",
"jest": "29.5.0",
"jest-junit": "16.0.0",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-node": "10.9.1",
"typescript": "5.1.3"
"typescript": "5.8.3"
},
"gitHead": "6155223cfce769e48ccae480c510b35b4f54b4d0"
}
6 changes: 3 additions & 3 deletions packages/currency/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@requestnetwork/utils": "0.54.0",
"multicoin-address-validator": "0.5.15",
"node-dijkstra": "2.5.0",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@types/jest": "29.5.6",
Expand All @@ -57,8 +57,8 @@
"jest": "29.5.0",
"jest-junit": "16.0.0",
"source-map-support": "0.5.19",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-node": "10.9.1",
"typescript": "5.1.3"
"typescript": "5.8.3"
}
}
6 changes: 3 additions & 3 deletions packages/data-access/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@
"@requestnetwork/multi-format": "0.28.0",
"@requestnetwork/types": "0.54.0",
"@requestnetwork/utils": "0.54.0",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@types/jest": "29.5.6",
"@types/node": "18.11.9",
"jest": "29.5.0",
"jest-junit": "16.0.0",
"source-map-support": "0.5.19",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-node": "10.9.1",
"typescript": "5.1.3"
"typescript": "5.8.3"
},
"gitHead": "6155223cfce769e48ccae480c510b35b4f54b4d0"
}
2 changes: 1 addition & 1 deletion packages/data-access/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export { CombinedDataAccess } from './combined-data-access';
export { DataAccessWrite } from './data-write';
export { DataAccessRead } from './data-read';
export { PendingStore } from './pending-store';
export { DataAccessBaseOptions } from './types';
export type { DataAccessBaseOptions } from './types';
Copy link
Member Author

@alexandre-abrioux alexandre-abrioux Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed when exporting types with isolatedModules=true

export { MockDataAccess } from './mock-data-access';
export { NoPersistDataWrite } from './no-persist-data-write';
7 changes: 4 additions & 3 deletions packages/data-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
"test:watch": "yarn test --watch"
},
"dependencies": {
"ajv": "6.12.4",
"ajv": "8.17.1",
"ajv-formats": "3.0.1",
"ethers": "5.7.2",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@types/node": "18.11.9",
"jest-junit": "16.0.0",
"ts-node": "10.9.1",
"typescript": "5.1.3"
"typescript": "5.8.3"
},
"gitHead": "6155223cfce769e48ccae480c510b35b4f54b4d0"
}
6 changes: 4 additions & 2 deletions packages/data-format/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as AJV from 'ajv';
import { Ajv } from 'ajv';
Copy link
Member Author

@alexandre-abrioux alexandre-abrioux Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the old version (v6) of Avj there was a TypeScript issue, but only during tests. I fixed it by updating Avj to v8 and handling the breaking changes. This was before I found out that ts-jest needs isolatedModules=true to support module=nodenext.

Later, I tested again with Ajv v6, this time with isolatedModules=true, and it also works. But I figured I would keep this change since I went through the trouble of updating it.

import addFormats from 'ajv-formats';
import * as jsonSchema from 'ajv/lib/refs/json-schema-draft-06.json';
import * as schemaAddress from './format/address.json';
import { formats } from './format';
Expand All @@ -9,7 +10,8 @@ import { formats } from './format';
* @return object.valid == true if the json is valid, object.valid == false and object.errors otherwise.
*/
export function validate(data: any): any {
const validationTool = new AJV().addMetaSchema(jsonSchema).addSchema(schemaAddress);
const validationTool = new Ajv().addMetaSchema(jsonSchema).addSchema(schemaAddress);
addFormats(validationTool);

// Check the meta information
if (!data.meta) {
Expand Down
8 changes: 4 additions & 4 deletions packages/data-format/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Request Network Data Validator', () => {
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('should be string');
expect(result.errors[0].message).toBe('must be string');
});

it('should not validate an invalid invoice 0.0.3 format', () => {
Expand All @@ -39,7 +39,7 @@ describe('Request Network Data Validator', () => {
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('should be string');
expect(result.errors[0].message).toBe('must be string');
});

it('should not validate a json without meta', () => {
Expand All @@ -66,7 +66,7 @@ describe('Request Network Data Validator', () => {
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe('should match format "date-time"');
expect(result.errors[0].message).toBe('must match format "date-time"');
});

it('should not validate a json with required parameter missing', () => {
Expand All @@ -75,7 +75,7 @@ describe('Request Network Data Validator', () => {
// 'result.valid should be false'
expect(result.valid).toBe(false);
// 'result.errors is wrong'
expect(result.errors[0].message).toBe(`should have required property \'name\'`);
expect(result.errors[0].message).toBe(`must have required property \'name\'`);
});

it('should not validate a json with meta.format missing', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/epk-cipher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@requestnetwork/multi-format": "0.28.0",
"@requestnetwork/types": "0.54.0",
"@requestnetwork/utils": "0.54.0",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@types/jest": "29.5.6",
Expand All @@ -58,10 +58,10 @@
"source-map-support": "0.5.19",
"stream-browserify": "3.0.0",
"terser-webpack-plugin": "4.2.3",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-loader": "8.4.0",
"ts-node": "10.9.1",
"typescript": "5.1.3",
"typescript": "5.8.3",
"webpack": "5.94.0",
"webpack-bundle-analyzer": "4.2.0",
"webpack-cli": "3.3.12"
Expand Down
6 changes: 3 additions & 3 deletions packages/epk-decryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@requestnetwork/multi-format": "0.28.0",
"@requestnetwork/types": "0.54.0",
"@requestnetwork/utils": "0.54.0",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@types/jest": "29.5.6",
Expand All @@ -57,10 +57,10 @@
"source-map-support": "0.5.19",
"stream-browserify": "3.0.0",
"terser-webpack-plugin": "4.2.3",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-loader": "8.4.0",
"ts-node": "10.9.1",
"typescript": "5.1.3",
"typescript": "5.8.3",
"webpack": "5.94.0",
"webpack-bundle-analyzer": "4.2.0",
"webpack-cli": "3.3.12"
Expand Down
6 changes: 3 additions & 3 deletions packages/epk-signature/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@requestnetwork/types": "0.54.0",
"@requestnetwork/utils": "0.54.0",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@types/jest": "29.5.6",
Expand All @@ -56,10 +56,10 @@
"source-map-support": "0.5.19",
"stream-browserify": "3.0.0",
"terser-webpack-plugin": "4.2.3",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-loader": "8.4.0",
"ts-node": "10.9.1",
"typescript": "5.1.3",
"typescript": "5.8.3",
"webpack": "5.94.0",
"webpack-bundle-analyzer": "4.2.0",
"webpack-cli": "3.3.12"
Expand Down
6 changes: 3 additions & 3 deletions packages/ethereum-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"form-data": "3.0.0",
"qs": "6.11.2",
"shelljs": "0.8.5",
"tslib": "2.5.0",
"tslib": "2.8.1",
"yargs": "17.6.2"
},
"devDependencies": {
Expand All @@ -59,9 +59,9 @@
"msw": "2.0.6",
"solium": "1.2.5",
"source-map-support": "0.5.19",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-node": "10.9.1",
"typescript": "5.1.3",
"typescript": "5.8.3",
"web3-providers-http": "1.3.6"
},
"gitHead": "6155223cfce769e48ccae480c510b35b4f54b4d0"
Expand Down
6 changes: 3 additions & 3 deletions packages/integration-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
"jest": "29.5.0",
"jest-junit": "16.0.0",
"npm-run-all": "4.1.5",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-node": "10.9.1",
"tslib": "2.5.0",
"typescript": "5.1.3"
"tslib": "2.8.1",
"typescript": "5.8.3"
}
}
4 changes: 2 additions & 2 deletions packages/lit-protocol-cipher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"@types/node": "18.11.9",
"jest": "29.5.0",
"jest-junit": "16.0.0",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-node": "10.9.1",
"typescript": "5.1.3"
"typescript": "5.8.3"
}
}
6 changes: 3 additions & 3 deletions packages/multi-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
},
"dependencies": {
"@requestnetwork/types": "0.54.0",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@types/jest": "29.5.6",
"jest": "29.5.0",
"jest-junit": "16.0.0",
"source-map-support": "0.5.19",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-node": "10.9.1",
"typescript": "5.1.3"
"typescript": "5.8.3"
}
}
8 changes: 4 additions & 4 deletions packages/payment-detection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
"graphql-request": "6.1.0",
"graphql-tag": "2.12.6",
"satoshi-bitcoin": "1.0.4",
"tslib": "2.5.0"
"tslib": "2.8.1"
},
"devDependencies": {
"@babel/helper-get-function-arity": "7.16.7",
"@graphql-codegen/cli": "4.0.1",
"@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-document-nodes": "4.0.1",
"@graphql-codegen/typescript-graphql-request": "6.0.1",
"@graphql-codegen/typescript-graphql-request": "6.2.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the generated GraphQL code that previously contained imports not compatible with latest module resolution.

"@graphql-codegen/typescript-operations": "4.0.1",
"@graphql-codegen/typescript-resolvers": "4.0.1",
"@jridgewell/gen-mapping": "0.3.2",
Expand All @@ -66,8 +66,8 @@
"jest": "29.5.0",
"jest-junit": "16.0.0",
"source-map-support": "0.5.19",
"ts-jest": "29.1.0",
"ts-jest": "29.3.2",
"ts-node": "10.9.1",
"typescript": "5.1.3"
"typescript": "5.8.3"
}
}
6 changes: 3 additions & 3 deletions packages/payment-detection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import * as PaymentReferenceCalculator from './payment-reference-calculator';
import * as BtcPaymentNetwork from './btc';
import { DeclarativePaymentDetector } from './declarative';
import * as Erc20PaymentNetwork from './erc20';
import { ERC20TransferableReceivablePaymentDetector } from './erc20';
import { AnyToERC20PaymentDetector, AnyToEthFeeProxyPaymentDetector } from './any';
import { EthFeeProxyPaymentDetector, EthInputDataPaymentDetector } from './eth';
import { getTheGraphClient, getTheGraphEvmClient, getTheGraphNearClient } from './thegraph';
import {
calculateEscrowState,
flattenRequestByPnId,
formatAddress,
getPaymentNetworkExtension,
getPaymentReference,
getPaymentReferencesForMetaPnRequest,
flattenRequestByPnId,
hashReference,
padAmountForChainlink,
parseLogArgs,
Expand All @@ -29,14 +30,13 @@ import { SuperFluidPaymentDetector } from './erc777/superfluid-detector';
import { EscrowERC20InfoRetriever } from './erc20/escrow-info-retriever';
import { SuperFluidInfoRetriever } from './erc777/superfluid-retriever';
import { PaymentNetworkOptions } from './types';
import { ERC20TransferableReceivablePaymentDetector } from './erc20';
import { MetaDetector } from './meta-payment-detector';

export type { TheGraphClient } from './thegraph';

export type { PaymentNetworkOptions };
export {
PaymentNetworkFactory,
PaymentNetworkOptions,
PaymentReferenceCalculator,
BtcPaymentNetwork,
DeclarativePaymentDetector,
Expand Down
5 changes: 3 additions & 2 deletions packages/payment-detection/src/thegraph/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import { CurrencyTypes } from '@requestnetwork/types';
import { NearChains } from '@requestnetwork/currency';
import { GraphQLClient } from 'graphql-request';
import { Block_Height, Maybe, getSdk } from './generated/graphql';
import { Block_Height, getSdk, Maybe } from './generated/graphql';
import { getSdk as getNearSdk } from './generated/graphql-near';
import { RequestConfig } from 'graphql-request/src/types';
Copy link
Member Author

@alexandre-abrioux alexandre-abrioux Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is not compatible with ESM. We can't do such type of imports anymore, as graphql-request/src/types is not an exported module.


const THE_GRAPH_STUDIO_URL =
'https://api.studio.thegraph.com/query/67444/request-payments-$NETWORK/version/latest';
Expand Down Expand Up @@ -41,6 +40,8 @@ export type TheGraphQueryOptions = {
blockFilter?: Maybe<Block_Height>;
};

type RequestConfig = (typeof GraphQLClient.prototype)['requestConfig'];

export type TheGraphClientOptions = RequestConfig & {
/** constraint to select indexers that have at least parsed this block */
minIndexedBlock?: number | undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/payment-detection/src/thegraph/superfluid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GraphQLClient } from 'graphql-request';
import { getSdk } from './generated/graphql-superfluid';
import { RequestConfig } from 'graphql-request/src/types';

const BASE_URL = `https://subgraph-endpoints.superfluid.dev`;
const NETWORK_TO_URL: Record<string, string> = {
Expand All @@ -16,6 +15,8 @@ const NETWORK_TO_URL: Record<string, string> = {
xdai: 'xdai-mainnet',
};

type RequestConfig = (typeof GraphQLClient.prototype)['requestConfig'];

// NB: the GraphQL client is automatically generated based on files present in ./queries,
// using graphql-codegen.
// To generate types, run `yarn codegen`, then open the generated files so that the code editor picks up the changes.
Expand Down
Loading