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

271: trying to use babel-node when using typescript files #272

Merged
merged 4 commits into from
Oct 9, 2022

Conversation

lasmil
Copy link
Contributor

@lasmil 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: fastify#271
Copy link
Member

@climba03003 climba03003 left a 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

index.js Outdated Show resolved Hide resolved
@lasmil
Copy link
Contributor Author

lasmil commented Oct 7, 2022

There is a difference between the 2 PRs. In this PR I am using:
const type = getScriptType(file, options.packageType) the type to know if it's 'typescript' or not.

In the other (reverted) PR we are trying to require ts-node even when the type is not 'typescript'.

@simoneb
Copy link
Contributor

simoneb commented Oct 7, 2022

approach looks reasonable, let's add tests to confirm it works!

@climba03003
Copy link
Member

There is a difference between the 2 PRs. In this PR I am using: const type = getScriptType(file, options.packageType) the type to know if it's 'typescript' or not.

In the other (reverted) PR we are trying to require ts-node even when the type is not 'typescript'.

Still, it didn't convince me why we need to explicitly register ts-node for the user.
In the issue, I don't see ts-node as devDependency. How can explicitly register ts-node can solve the problem of someone that do not install it?

The solution should be detect if the current script run under babel-node and allow it as typescript runtime.

@lasmil
Copy link
Contributor Author

lasmil commented Oct 7, 2022

When I tried with the mentioned project I did indeed needed to install ts-node as a dev dependency. Let me try your solution.

@lasmil
Copy link
Contributor Author

lasmil commented Oct 7, 2022

When I tried with the mentioned project I did indeed needed to install ts-node as a dev dependency. Let me try your solution.

There is a difference between the 2 PRs. In this PR I am using: const type = getScriptType(file, options.packageType) the type to know if it's 'typescript' or not.
In the other (reverted) PR we are trying to require ts-node even when the type is not 'typescript'.

Still, it didn't convince me why we need to explicitly register ts-node for the user. In the issue, I don't see ts-node as devDependency. How can explicitly register ts-node can solve the problem of someone that do not install it?

The solution should be detect if the current script run under babel-node and allow it as typescript runtime.

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.

@lasmil lasmil changed the title 271: trying to use tsnode when using typescript files 271: trying to use babel-node when using typescript files Oct 7, 2022
Copy link
Contributor

@simoneb simoneb left a 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' })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(JSON.parse(response.payload)).toEqual({ hello: 'world' })
expect(response.json()).toEqual({ hello: 'world' })

Comment on lines +8 to +13
beforeAll( done => {
app.register(AutoLoad, {
dir: join(__dirname, '../../commonjs/babel-node/routes')
})
app.ready(done)
})
Copy link
Contributor

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

Comment on lines +2 to +5
fastify.get("/", function () {
return { foo: "bar" };
})
};
Copy link
Contributor

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

Comment on lines +16 to +19
const response = await app.inject({
method: 'GET',
url: '/'
})
Copy link
Contributor

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('/')

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
Copy link
Member

mcollina commented Oct 9, 2022

@climba03003 PTAL

@mcollina mcollina merged commit c41e96e into fastify:master Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants