kensho-technologies / babel-preset

Babel preset to transpile ES2020, TS(X), and language proposals

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detect Node target for library builds

billyjanitsch opened this issue · comments

We currently hardcode a target version of Node for library builds:

if (env === 'esm' || env === 'cjs') return {node: '14.14', browsers: []}

We're adding engines field to all of our projects. This corresponds to the consuming environment so the lowest satisfying version is exactly the one that we'd want as the default Node target when transpiling libraries.

We could try to detect this automatically:

  1. Starting from the file path being transpiled, traverse upwards to find a package.json.
  2. If one exists, check if it has an engines.node field.
  3. If it does, parse it and use the lowest satisfying version as the default target.
  4. Otherwise, fall back to the current explicit value as a default? Or throw, but provide an option to pass an explicit value if the auto-detection doesn't fit the use case?