lukeed / ley

(WIP) Driver-agnostic database migrations
MIT License
260 stars 14 forks source link

Document ts-node moduleTypes #22

Closed karlhorky closed 2 years ago

karlhorky commented 3 years ago

Hi @lukeed πŸ‘‹ Hope you are well.

A quick PR to document the new moduleTypes module type overrides for authors who are writing the rest of their package in ESM via "type": "module"

codecov-commenter commented 3 years ago

Codecov Report

Merging #22 (38822cb) into master (3c290b7) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #22   +/-   ##
=======================================
  Coverage   50.00%   50.00%           
=======================================
  Files           2        2           
  Lines         206      206           
=======================================
  Hits          103      103           
  Misses        103      103           

Continue to review full report at Codecov.

Legend - Click here to learn more Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data Powered by Codecov. Last update 3c290b7...38822cb. Read the comment docs.

karlhorky commented 3 years ago

Without this change, it seems that ts-node doesn't transform the TS files to CommonJS, which Ley requires

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/j/c/packages/l/migrations/1619435929-create-courses-table.ts
    require() of ES modules is not supported.
    require() of /Users/j/c/packages/l/migrations/1619435929-create-courses-table.ts from /Users/j/c/node_modules/ley/lib/util.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.