verida-js icon indicating copy to clipboard operation
verida-js copied to clipboard

Redefine the engine requirement and the typescript config

Open aurelticot opened this issue 4 months ago • 0 comments

[!CAUTION] Changing the engine requirement and the build target is a breaking change!

The engine requirement in package.json is a result of the compilation of the code, which itself is defined based on the environments the SDK is expected to run.

ES2020 ES2021 ES2022
Node 14 (unmaintained) No Yes Yes
Node 16 (unmaintained) Yes Yes Yes
Node 18 (maintenance) Yes Yes Yes
Node 20 (current LTS) Yes Yes Yes
Browser 93% of all users 92% of all users 85-91% of all users
React Native JSC ? ? ?
React Native Hermes ? ? ?

By seeing the current support, ES2020 is widespread enough for browser support and Node under maintenance. By choosing ES2020, we can set the engine requirement to Node 16 to still allow projects stuck with that version.

We'd still have to check the dependencies are compatible (if not, look at updating them)

Recommended values:

  • Typescript target: es2020 (would result in a more optimised code than the current es5)
  • Typescript lib: es2020 (same as target)
  • Typescript module: commonjs
  • package.json engine: node >= 16 (breaking change)

Other recommendations:

  • All packages must have the same target in their respective tsconfig
    • Suggest using a base tsconfig extended by each package's tsconfig, so the common configuration is defined once, in the base
  • All packages must defined the same engine requirements in their respective package.json
    • To be fair, it's already the case
  • Run the tests in the CI with a matrix of Node versions
    • Testing and building from the minimum version of Node supported (engine requirement) to the current LTS, and even to the latest: Node 16, 18, 20, 21.
    • If not, at least the version defined in .nvmrc
  • .nvmrc is only used for dev, test and build, not runtime
    • Recommendation to use the LTS, currently Node 20 (lts/iron)
      • But only if the tests are run with a matrix checking the lowest version support
    • If tests not run with a matrix, .nvmrc should be aligned with the engine requirements
      • Ensure we develop, test and build with the lowest supported version
    • Use the name instead of a defined version: lts/hydrogen for node 18
  • The actual build being published should be done with the version defined in .nvmrc

aurelticot avatar Feb 07 '24 06:02 aurelticot