Skip to content
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

feat: add typeorm CLI variations that include ts-node #8776

Merged
merged 2 commits into from Mar 22, 2022

Conversation

giladgd
Copy link
Contributor

@giladgd giladgd commented Mar 22, 2022

Description of change

Add typeorm-ts-node-commonjs and typeorm-ts-node-esm CLI commands.
This removes the need to manually write node --require ts-node/register ./node_modules/typeorm/cli.js or node --loader ts-node/esm ./node_modules/typeorm/cli.js in order to use TypeORM CLI without transpiling the code in advance.

This is more useful now than before since the new CLI in version 0.3 requires you to specify a file path instead of just a file name, so being able to cd to a folder and then run a simple and intuitive command is now more important.

Previous usage of the CLI in version 0.3:

cd src/db/migrations
node --loader ts-node/esm ../../../node_modules/typeorm/cli.js migration:generate -d ../data-source.ts --pretty SomeMigrationName

New possible usage of the CLI:

cd src/db/migrations
npx typeorm-ts-node-esm migration:generate -d ../data-source.ts --pretty SomeMigrationName

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change - N/A
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

Add `typeorm-ts-node-commonjs` and `typeorm-ts-node-esm` CLI commands.
This removes the need to manually write `node --require ts-node/register ./node_modules/typeorm/cli.js` or `node --loader ts-node/esm ./node_modules/typeorm/cli.js` in order to use TypeORM CLI without transpiling the code in advance.
@pleerock pleerock merged commit 05fc744 into typeorm:master Mar 22, 2022
@pleerock
Copy link
Member

thank you!!!

@cduff
Copy link
Contributor

cduff commented Mar 23, 2022

@giladgd I just spotted this change released in 0.3.2 and see that the documentation has been updated as well.

I currently use the following for my typeorm CLI script:

"typeorm": "node -r ts-node/register --preserve-symlinks ./node_modules/typeorm/cli.js",

Note it includes --preserve-symlinks which is required due to the project setup.

Do you know how I could get this flag passed to node under your new typeorm-ts-node-commonjs approach? I just tried a few different things but couldn't get it to work.

@giladgd
Copy link
Contributor Author

giladgd commented Mar 23, 2022

@cduff You could change your script to this:

"typeorm": "NODE_OPTIONS=\"--preserve-symlinks\" typeorm-ts-node-commonjs"

If you want it to also work well on Windows, do this instead:

npm install cross-env --save-dev
"typeorm": "cross-env NODE_OPTIONS=\"--preserve-symlinks\" typeorm-ts-node-commonjs"

@pleerock
Copy link
Member

if windows requires something specific, it's better to document it since there are many windows users out there.

@giladgd
Copy link
Contributor Author

giladgd commented Mar 23, 2022

@pleerock cross-env is only needed when using NODE_OPTIONS on Windows.
Using plain typeorm-ts-node-commonjs/typeorm-ts-node-esm should work without any additional configuration on both Windows and macOS/linux.

@cduff
Copy link
Contributor

cduff commented Mar 24, 2022

@cduff You could change your script to this:
`

"typeorm": "NODE_OPTIONS=\"--preserve-symlinks\" typeorm-ts-node-commonjs"

If you want it to also work well on Windows, do this instead:

npm install cross-env --save-dev
"typeorm": "cross-env NODE_OPTIONS=\"--preserve-symlinks\" typeorm-ts-node-commonjs"

Thanks @giladgd I got it working using NODE_OPTIONS & cross-env. 👍

@lfaires
Copy link

lfaires commented Mar 26, 2022

Hi, I've installed version 0.3.4 and followed the doc adding "typeorm": "typeorm-ts-node-ems" to my scripts, but when I run the command it doesn't work and show this message /bin/sh: 1: typeorm-ts-node-ems: not found

Any ideas what I'm doing wrong?

@giladgd
Copy link
Contributor Author

giladgd commented Mar 27, 2022

@lfaires Your command is wrong, you should use "typeorm-ts-node-esm"

@lfaires
Copy link

lfaires commented Mar 27, 2022

@giladgd thanks a lot!!

@cduff
Copy link
Contributor

cduff commented Mar 28, 2022

@giladgd can you help with this? #8818

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants