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

Make datasource imports work with ts-node #2794

Closed
bforbis opened this issue Apr 24, 2019 · 6 comments
Closed

Make datasource imports work with ts-node #2794

bforbis opened this issue Apr 24, 2019 · 6 comments

Comments

@bforbis
Copy link

bforbis commented Apr 24, 2019

Currently the lb4 datasource command will create a {name}.datasource.ts file and a {name}.datasource.json file. Since these files have the same base name, it causes issues with imports while running with ts-node (useful for development). By default, ts-node will import the JSON file over the TS file, causing datasource construction to fail. For more info on how ts-node works, see TypeStrong/ts-node#769

I was able to workaround this issue by manually renaming the json file, but it would be good if the datasource generator didn't create two files with the same base name.

@dougal83
Copy link
Contributor

Hey, Please excuse my ignorance but why do you use ts-node? Curious as to the necessity, are you doing something that specifically requires it?

@bforbis
Copy link
Author

bforbis commented Apr 25, 2019

It's not really necessary, but it makes certain things in development have a quicker feedback loop.

  1. I can throw together quick ts scripts and test them with a single command
  2. It allows me to skip some more complex steps of my normal build phase that involves moving static files around, as executing within ts-node will operate under the same directory structure within src/, instead of in dist/

@dougal83
Copy link
Contributor

quicker feedback loop.

Ah like build times with the watch flag? I just use ts-node for scripts like building .env files. Fair dos, I think this'll be low priority until lb4 has feature parity with lb3.

@bajtos bajtos added the feature label Jun 18, 2019
@bajtos bajtos changed the title Datasource imports dont work with ts-node Make datasource imports work with ts-node Jun 18, 2019
@bajtos
Copy link
Member

bajtos commented Jun 18, 2019

@bforbis thank you for starting this discussion. I was looking into ts-jest and ts-node recently and discovered a similar problem: by default, LoopBack booters look for .js files only, and therefore don't discover .ts files.

I think it would be great to improve LoopBack to support ts-node. Would you like to help?

For example, we can modify our CLI templates to use the following naming convention: {name}.datasource-config.json.

Thoughts?

/cc @strongloop/loopback-maintainers

@achrinza
Copy link
Member

achrinza commented Dec 2, 2019

@bajtos This has probably been fixed by #4060

@bajtos
Copy link
Member

bajtos commented Dec 5, 2019

@achrinza thank you for the comment. I am going to close this issue as resolved then.

@bajtos bajtos closed this as completed Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants