-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
271: trying to use babel-node when using typescript files #272
271: trying to use babel-node when using typescript files #272
Conversation
lasmil
commented
Oct 7, 2022
- when dealing with typescript files, we need to make sure the ts-node is being used to autoload components
- closes: babel-node + typescript. Error only with autoloads : throw new Error(@fastify/autoload cannot import plugin at '${file}'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.) #271
- when dealing with typescript files, we need to make sure the ts-node is being used to autoload components - closes: fastify#271
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any different from #264
There is a difference between the 2 PRs. In this PR I am using: In the other (reverted) PR we are trying to require ts-node even when the type is not 'typescript'. |
approach looks reasonable, let's add tests to confirm it works! |
Still, it didn't convince me why we need to explicitly register The solution should be detect if the current script run under |
When I tried with the mentioned project I did indeed needed to install ts-node as a dev dependency. Let me try your solution. |
I have pushed a commit to this PR. I tried to find a better way to detect if the script is running under babel-node but unfortunately I was unable to find it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few comments but overall LGTM
url: '/' | ||
}) | ||
expect(response.statusCode).toEqual(200) | ||
expect(JSON.parse(response.payload)).toEqual({ hello: 'world' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(JSON.parse(response.payload)).toEqual({ hello: 'world' }) | |
expect(response.json()).toEqual({ hello: 'world' }) |
beforeAll( done => { | ||
app.register(AutoLoad, { | ||
dir: join(__dirname, '../../commonjs/babel-node/routes') | ||
}) | ||
app.ready(done) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's use newer async/await syntax
fastify.get("/", function () { | ||
return { foo: "bar" }; | ||
}) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting: let's use quotes consistently, either single or double
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/' | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're GETting root you don't need this variant of inject, simple inject('/')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@climba03003 PTAL |