aelbore / esbuild-jest

A Jest transformer using esbuild
519 stars 51 forks source link

unexpected "loaders" file extension parsing #52

Open gavinsharp opened 3 years ago

gavinsharp commented 3 years ago

I was trying to configure the loader used for all .js files, because I need to use the JSX parser for .js due to legacy constraints.

However, the getExt logic from https://github.com/aelbore/esbuild-jest/blob/daa5847b3b382d9ddf6cc26e60ad949d202c4461/src/utils.ts#L5 does not work the way I was expecting. For example, getExt('file.test.js') will return test.js. So I need to specify e.g.:

loaders: {
  '.test.js': 'jsx',
  '.js': 'jsx',
}

if I want both *.test.js and *.js files to use the JSX loader. And I would need to do this for any other "double extension" (e.g. *.story.js, etc.). I would expect loaders: { '.js': 'jsx' } to be sufficient here.

Is there a reason the getExt helper behaves this way? I think it's fairly unexpected and differs from e.g. path.extname behaviour.