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

Allow TypeScript transpiler customization #218

Open
marco-ippolito opened this issue Aug 7, 2024 · 6 comments
Open

Allow TypeScript transpiler customization #218

marco-ippolito opened this issue Aug 7, 2024 · 6 comments

Comments

@marco-ippolito
Copy link
Member

marco-ippolito commented Aug 7, 2024

Current problem:

  • It is not possible to hook an Amaro version different from the one bundled in core.
  • It is also not possible to allow the user to enable to customize the behavior of the transpiling function or change the default settings of Amaro.

Possible solution

A way that allows to override the default behavior of the transformSync.
I have created this PR which makes possible to build a public api on top to customize the default behavior.

I'm open for discussion
cc @nodejs/typescript

@joyeecheung
Copy link
Member

Isn't this already achievable with this loader?

const amaro = require('amaro');
exports.load = async function(source, context, nextLoad) {
  if (context.format && context.format.includes('typescript')) {
    return {
      source: amaro.transformSync(source, {MY_DEFAULT_SETTINGS }),
      shortCircuit: true  // Skips bundled transpilation
    };
  }
  return { source: await nextLoad(source, context) };
}

@marco-ippolito
Copy link
Member Author

marco-ippolito commented Aug 7, 2024

@joyeecheung to my surprise it could be possible, I thought it wouldnt work 😮
So next step is to make amaro export a loader.
The issue remains the configuration of the loader because it needs to be configurable (type stripping or enable transformation). If only we have a node configuration file 😆
We could actually use the https://swc.rs/docs/configuration/swcrc

@khaosdoctor
Copy link
Member

@joyeecheung to my surprise it could be possible, I thought it wouldnt work 😮 So next step is to make amaro export a loader. The issue remains the configuration of the loader because it needs to be configurable (type stripping or enable transformation). If only we have a node configuration file 😆 We could actually use the swc.rs/docs/configuration/swcrc

I was gonna suggest the configuration file, but I see this could have possible implications. Is adding keys to package.json an option?

My only concern about using .swcrc is that we will eventually be hooked to SWC, on the bright side we will have all the implementations from SWC out of the box, but if we ever need to change it in the future we will also have to deprecate all the projects that are using this file for configuration. Don't know if this is too forward-thinking but I think it's a point to consider

@khaosdoctor
Copy link
Member

btw I can tackle the loader export on amaro if that's ok :) I haven't fiddled around with loaders that much and it would be a nice opportunity to dive in and learn the specifics

@marco-ippolito
Copy link
Member Author

I have already created a PR nodejs/amaro#47, I need to add more testing.
The main problem is that is not customizable and I dont see another way other than support .swcrc

@khaosdoctor
Copy link
Member

Oh nice I'll take a look :D

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

No branches or pull requests

3 participants