diff --git a/apps/sample/package.json b/apps/sample/package.json index c725b6da3..d38edd1a1 100644 --- a/apps/sample/package.json +++ b/apps/sample/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev", + "dev": "next dev --turbo", "build": "next build", "start": "next start", "lint": "next lint" diff --git a/package.json b/package.json index 269b18bfc..74e8ac3ab 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "jest": "^29.7.0", "lint-staged": "^15.2.0", "prettier": "^3.1.1", + "rimraf": "^5.0.5", "turbo": "^1.11.2", "typescript": "^5.3.3", "zx": "^7.2.3" diff --git a/packages/config/eslint/index.js b/packages/config/eslint/index.js index c37da5384..31ed47591 100644 --- a/packages/config/eslint/index.js +++ b/packages/config/eslint/index.js @@ -49,7 +49,7 @@ module.exports = { }, }, { - files: ["**/scripts/*.mjs"], + files: ["**/*.mjs"], env: { es6: true, node: true, diff --git a/packages/config/typescript/sdk.json b/packages/config/typescript/sdk.json index 31bc1f432..0ae0a817d 100644 --- a/packages/config/typescript/sdk.json +++ b/packages/config/typescript/sdk.json @@ -26,8 +26,8 @@ "experimentalDecorators": true, "stripInternal": true, "emitDecoratorMetadata": true, - "moduleResolution": "NodeNext", - "module": "NodeNext" + "moduleResolution": "bundler", + "module": "esnext" }, "exclude": ["node_modules"] } diff --git a/packages/core/.eslintrc.js b/packages/core/.eslintrc.js index fca763878..f1495cd5c 100644 --- a/packages/core/.eslintrc.js +++ b/packages/core/.eslintrc.js @@ -5,13 +5,4 @@ module.exports = { project: true, tsconfigRootDir: __dirname, }, - overrides: [ - { - files: "src/**/*.test.ts", - parserOptions: { - project: "tsconfig.test.json", - tsconfigRootDir: __dirname, - }, - }, - ], }; diff --git a/packages/core/package.json b/packages/core/package.json index 00b905eea..cde19d97a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -8,15 +8,14 @@ "./lib" ], "scripts": { - "build": "rm -rf lib && tsc && tsc-alias", - "dev": "tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")", + "build": "rimraf lib && tsc -p tsconfig.prod.json && tsc-alias -p tsconfig.prod.json", + "dev": "tsc && (concurrently \"tsc -w -p tsconfig.prod.json\" \"tsc-alias -w -p tsconfig.prod.json\")", "lint": "eslint --cache --ext .ts \"src\"", "lint:fix": "eslint --cache --fix --ext .ts \"src\"", "test": "jest src", "test:watch": "pnpm test -- --watch", "test:coverage": "pnpm test -- --coverage", - "module:init": "zx scripts/add-module.mjs", - "run:index": "ts-node src/index.ts" + "module:init": "zx scripts/add-module.mjs" }, "dependencies": { "inversify": "^6.0.2", diff --git a/packages/core/src/internal/config/data/LocalConfigDataSource.test.ts b/packages/core/src/internal/config/data/LocalConfigDataSource.test.ts index bc7b3d4f9..779befa29 100644 --- a/packages/core/src/internal/config/data/LocalConfigDataSource.test.ts +++ b/packages/core/src/internal/config/data/LocalConfigDataSource.test.ts @@ -1,10 +1,11 @@ -import fs from "fs"; import { Either, Left } from "purify-ts"; import { JSONParseError, ReadFileError } from "@internal/config/di/configTypes"; import { LocalConfigDataSource } from "./ConfigDataSource"; -import { FileLocalConfigDataSource } from "./LocalConfigDataSource"; +import * as LocalConfig from "./LocalConfigDataSource"; -const readFileSyncSpy = jest.spyOn(fs, "readFileSync"); +const { FileLocalConfigDataSource } = LocalConfig; + +const readFileSyncSpy = jest.spyOn(LocalConfig, "stubFsReadFile"); const jsonParse = jest.spyOn(JSON, "parse"); let datasource: LocalConfigDataSource; @@ -61,4 +62,12 @@ describe("LocalConfigDataSource", () => { expect(datasource.getConfig()).toEqual(Left(new JSONParseError(err))); }); }); + + describe("stubFsReadFile", () => { + it("should return a stringified version of the version object", () => { + expect(LocalConfig.stubFsReadFile()).toEqual( + JSON.stringify({ name: "DeviceSDK", version: "0.0.0-local.1" }) + ); + }); + }); }); diff --git a/packages/core/src/internal/config/data/LocalConfigDataSource.ts b/packages/core/src/internal/config/data/LocalConfigDataSource.ts index 64ccad93c..05b91bca1 100644 --- a/packages/core/src/internal/config/data/LocalConfigDataSource.ts +++ b/packages/core/src/internal/config/data/LocalConfigDataSource.ts @@ -1,6 +1,4 @@ -import fs from "fs"; import { injectable } from "inversify"; -import path from "path"; import { Either } from "purify-ts"; import { ReadFileError, @@ -10,6 +8,13 @@ import { import { Config } from "@internal/config/model/Config"; import { LocalConfigDataSource } from "./ConfigDataSource"; +const version = { + name: "DeviceSDK", + version: "0.0.0-local.1", +}; + +export const stubFsReadFile = () => JSON.stringify(version); + /** * * class FileLocalConfigDataSource @@ -19,9 +24,7 @@ import { LocalConfigDataSource } from "./ConfigDataSource"; @injectable() export class FileLocalConfigDataSource implements LocalConfigDataSource { getConfig(): Either { - return Either.encase(() => - fs.readFileSync(path.join(__dirname, "version.json"), "utf-8") - ) + return Either.encase(() => stubFsReadFile()) .mapLeft((error) => { console.log("readFileSync error"); return new ReadFileError(error); diff --git a/packages/core/src/internal/config/data/RemoteConfigDataSource.test.ts b/packages/core/src/internal/config/data/RemoteConfigDataSource.test.ts index bc4a5209b..a3b413187 100644 --- a/packages/core/src/internal/config/data/RemoteConfigDataSource.test.ts +++ b/packages/core/src/internal/config/data/RemoteConfigDataSource.test.ts @@ -9,7 +9,7 @@ import { RestRemoteConfigDataSource } from "./RemoteConfigDataSource"; let datasource: RemoteConfigDataSource; -// Necesary to use `any` on the prototype to be able to spy on private methods +// Necessary to use `any` on the prototype to be able to spy on private methods /* eslint-disable @typescript-eslint/no-explicit-any */ const callApiSpy = jest.spyOn( RestRemoteConfigDataSource.prototype as any, diff --git a/packages/core/src/internal/config/data/version.json b/packages/core/src/internal/config/data/version.json deleted file mode 100644 index 2fde7da1a..000000000 --- a/packages/core/src/internal/config/data/version.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "DeviceSDK", - "version": "0.0.0-local.1" -} diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index ee3fcdc53..8ffe96945 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -7,6 +7,5 @@ "@internal/*": ["src/internal/*"] } }, - "include": ["src/**/*", "jest.config.ts", "jest.setup.ts"], - "exclude": ["src/**/*.test.ts"] + "include": ["src", "jest.*.ts"] } diff --git a/packages/core/tsconfig.prod.json b/packages/core/tsconfig.prod.json new file mode 100644 index 000000000..457b19611 --- /dev/null +++ b/packages/core/tsconfig.prod.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["src/**/*.test.ts", "jest.*.ts"] +} diff --git a/packages/core/tsconfig.test.json b/packages/core/tsconfig.test.json deleted file mode 100644 index 560cb6484..000000000 --- a/packages/core/tsconfig.test.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "@ledgerhq/tsconfig-dsdk/sdk", - "compilerOptions": { - "baseUrl": ".", - "paths": { - "@internal/*": ["src/internal/*"] - } - }, - "include": ["src/**/*.test.ts"] -} diff --git a/packages/signer/package.json b/packages/signer/package.json index 539dbe798..5d22ed8b9 100644 --- a/packages/signer/package.json +++ b/packages/signer/package.json @@ -8,7 +8,7 @@ "./lib" ], "scripts": { - "build": "rm -rf lib && tsc", + "build": "rimraf lib && tsc", "dev": "tsc --watch", "lint": "eslint --cache --ext .ts \"src\"", "lint:fix": "eslint --cache --fix --ext .ts \"src\"", diff --git a/packages/trusted-apps/package.json b/packages/trusted-apps/package.json index e6a05f3b8..af535ef61 100644 --- a/packages/trusted-apps/package.json +++ b/packages/trusted-apps/package.json @@ -8,7 +8,7 @@ "./lib" ], "scripts": { - "build": "rm -rf lib && tsc", + "build": "rimraf lib && tsc", "lint": "eslint --cache --ext .ts \"src\"", "lint:fix": "eslint --cache --fix --ext .ts \"src\"", "dev": "tsc --watch", diff --git a/packages/ui/package.json b/packages/ui/package.json index c14e0385f..df50fed1c 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -8,7 +8,7 @@ "./lib" ], "scripts": { - "build": "rm -rf lib && tsc", + "build": "rimraf lib && tsc", "dev": "tsc --watch", "lint": "eslint --cache --ext .ts \"src\"", "lint:fix": "eslint --cache --fix --ext .ts \"src\"", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0bbe16e8a..a9bd7a6ea 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: prettier: specifier: ^3.1.1 version: 3.1.1 + rimraf: + specifier: ^5.0.5 + version: 5.0.5 turbo: specifier: ^1.11.2 version: 1.11.2 @@ -615,6 +618,18 @@ packages: resolution: {integrity: sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==} dev: true + /@isaacs/cliui@8.0.2: + resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} + engines: {node: '>=12'} + dependencies: + string-width: 5.1.2 + string-width-cjs: /string-width@4.2.3 + strip-ansi: 7.1.0 + strip-ansi-cjs: /strip-ansi@6.0.1 + wrap-ansi: 8.1.0 + wrap-ansi-cjs: /wrap-ansi@7.0.0 + dev: true + /@istanbuljs/load-nyc-config@1.1.0: resolution: {integrity: sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==} engines: {node: '>=8'} @@ -1008,6 +1023,13 @@ packages: fastq: 1.15.0 dev: true + /@pkgjs/parseargs@0.11.0: + resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} + engines: {node: '>=14'} + requiresBuild: true + dev: true + optional: true + /@pkgr/utils@2.4.2: resolution: {integrity: sha512-POgTXhjrTfbTV63DiFXav4lBHiICLKKwDeaKn9Nphwj7WH6m0hMMCaJkMyRWjgtPFyRKRVoMXXjczsTQRDEhYw==} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} @@ -1797,6 +1819,12 @@ packages: concat-map: 0.0.1 dev: true + /brace-expansion@2.0.1: + resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} + dependencies: + balanced-match: 1.0.2 + dev: true + /braces@3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} engines: {node: '>=8'} @@ -2252,6 +2280,10 @@ packages: resolution: {integrity: sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==} dev: true + /eastasianwidth@0.2.0: + resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} + dev: true + /electron-to-chromium@1.4.614: resolution: {integrity: sha512-X4ze/9Sc3QWs6h92yerwqv7aB/uU8vCjZcrMjA8N9R1pjMFRe44dLsck5FzLilOYvcXuDn93B+bpGYyufc70gQ==} @@ -3078,6 +3110,14 @@ packages: is-callable: 1.2.7 dev: true + /foreground-child@3.1.1: + resolution: {integrity: sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==} + engines: {node: '>=14'} + dependencies: + cross-spawn: 7.0.3 + signal-exit: 4.1.0 + dev: true + /formdata-polyfill@4.0.10: resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} engines: {node: '>=12.20.0'} @@ -3216,6 +3256,18 @@ packages: resolution: {integrity: sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==} dev: false + /glob@10.3.10: + resolution: {integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==} + engines: {node: '>=16 || 14 >=14.17'} + hasBin: true + dependencies: + foreground-child: 3.1.1 + jackspeak: 2.3.6 + minimatch: 9.0.3 + minipass: 7.0.4 + path-scurry: 1.10.1 + dev: true + /glob@7.1.6: resolution: {integrity: sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==} dependencies: @@ -3753,6 +3805,15 @@ packages: set-function-name: 2.0.1 dev: true + /jackspeak@2.3.6: + resolution: {integrity: sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==} + engines: {node: '>=14'} + dependencies: + '@isaacs/cliui': 8.0.2 + optionalDependencies: + '@pkgjs/parseargs': 0.11.0 + dev: true + /jest-changed-files@29.7.0: resolution: {integrity: sha512-fEArFiwf1BpQ+4bXSprcDc3/x4HSzL4al2tozwVpDFpsxALjLYdyiIK4e5Vz66GQJIbXJ82+35PtysofptNX2w==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -4376,6 +4437,11 @@ packages: dependencies: js-tokens: 4.0.0 + /lru-cache@10.2.0: + resolution: {integrity: sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==} + engines: {node: 14 || >=16.14} + dev: true + /lru-cache@5.1.1: resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} dependencies: @@ -4447,10 +4513,22 @@ packages: brace-expansion: 1.1.11 dev: true + /minimatch@9.0.3: + resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minimist@1.2.8: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} dev: true + /minipass@7.0.4: + resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} + engines: {node: '>=16 || 14 >=14.17'} + dev: true + /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} @@ -4762,6 +4840,14 @@ packages: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} dev: true + /path-scurry@1.10.1: + resolution: {integrity: sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + lru-cache: 10.2.0 + minipass: 7.0.4 + dev: true + /path-type@4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} @@ -5154,6 +5240,14 @@ packages: glob: 7.2.3 dev: true + /rimraf@5.0.5: + resolution: {integrity: sha512-CqDakW+hMe/Bz202FPEymy68P+G50RfMQK+Qo5YUqc9SPipvbGjCGKd0RSKEelbsfQuw3g5NZDSrlZZAJurH1A==} + engines: {node: '>=14'} + hasBin: true + dependencies: + glob: 10.3.10 + dev: true + /run-applescript@5.0.0: resolution: {integrity: sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==} engines: {node: '>=12'} @@ -5405,6 +5499,15 @@ packages: strip-ansi: 6.0.1 dev: true + /string-width@5.1.2: + resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} + engines: {node: '>=12'} + dependencies: + eastasianwidth: 0.2.0 + emoji-regex: 9.2.2 + strip-ansi: 7.1.0 + dev: true + /string-width@7.0.0: resolution: {integrity: sha512-GPQHj7row82Hjo9hKZieKcHIhaAIKOJvFSIZXuCU9OASVZrMNUaZuz++SPVrBjnLsnk4k+z9f2EIypgxf2vNFw==} engines: {node: '>=18'} @@ -6079,6 +6182,15 @@ packages: strip-ansi: 6.0.1 dev: true + /wrap-ansi@8.1.0: + resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} + engines: {node: '>=12'} + dependencies: + ansi-styles: 6.2.1 + string-width: 5.1.2 + strip-ansi: 7.1.0 + dev: true + /wrap-ansi@9.0.0: resolution: {integrity: sha512-G8ura3S+3Z2G+mkgNRq8dqaFZAuxfsxpBB8OCTGRTCtp+l/v9nbFNmCUP1BZMts3G1142MsZfn6eeUKrr4PD1Q==} engines: {node: '>=18'}