nodejs / amaro

Node.js TypeScript wrapper
MIT License
260 stars 11 forks source link

feat: create amaro loader #47

Closed marco-ippolito closed 2 months ago

marco-ippolito commented 2 months ago

It is now possible to use amaro as external loader, that behaves the same way as in core, but allows to decouple the typescript version supported

marco-ippolito commented 2 months ago

This will behave exactly as the one in core, and it requires --experimental-strip-types to be enabled, so it uses node.js .ts resolution. This only overrides the swc transform function, and I would like to make it customizable. If in the future typescript releases a major version, and has breaking changes, we might keep the amaro version in core locked. This allows users to update amaro and use it regardless of the node version

marco-ippolito commented 2 months ago

PTAL @nodejs/typescript @nodejs/loaders

marco-ippolito commented 2 months ago

There are cases in node core where source will be undefined https://github.com/nodejs/node/blob/3cbeed88d9de9231f420ba53ad0e4d4a7af9c637/lib/internal/modules/esm/get_format.js#L131-L136

aduh95 commented 2 months ago

There are cases in node core where source will be undefined https://github.com/nodejs/node/blob/3cbeed88d9de9231f420ba53ad0e4d4a7af9c637/lib/internal/modules/esm/get_format.js#L131-L136

IIUC that's only true for when format is nullish; the comment explains when defaultResolve returns a nullish format – and it doesn't matter for us, because Amaro will only deal with TS files

marco-ippolito commented 2 months ago

There are cases in node core where source will be undefined https://github.com/nodejs/node/blob/3cbeed88d9de9231f420ba53ad0e4d4a7af9c637/lib/internal/modules/esm/get_format.js#L131-L136

IIUC that's only true for when format is nullish; the comment explains when defaultResolve returns a nullish format – and it doesn't matter for us, because Amaro will only deal with TS files

Apparently it happens so I had to add the check here https://github.com/nodejs/node/blob/3cbeed88d9de9231f420ba53ad0e4d4a7af9c637/lib/internal/modules/helpers.js#L335