Describe the feature
Right now if you define transform option when creating jiti, it will completely drop default behaviour.
So to add support for custom extensions one have to create a dummy jiti instance, take default transition from there and use it in actual jiti:
const defaultJiti = createJiti(ERUDIT.config.paths.project, {
fsCache: false,
moduleCache: false,
jsx: {
runtime: 'automatic',
importSource: '@erudit-js/prose',
},
});
const defaultTransform = defaultJiti.transform.bind(defaultJiti);
jiti = createJiti(ERUDIT.config.paths.project, {
fsCache: false, // true
moduleCache: false,
jsx: {
runtime: 'automatic',
importSource: '@erudit-js/prose',
},
extensions: [
'.ts',
'.tsx',
'.js',
'.jsx',
'.json',
'.jpg',
'.png',
'.svg',
],
transform: (opts) => {
if (opts.filename && opts.filename.endsWith('.jpg')) {
console.log('Transforming JPG:', opts.filename);
return { code: `exports.default = 'foobar';` };
}
return { code: defaultTransform(opts) };
},
});
I think it would be a good idea to support extending default transition or passing default transition method inside redefined transition to use it there.
Sounds like a good idea to me... Or I am doing something wrong and not where it is intended to be done?
Context
I use jiti in my auto-generated documentation project to read documentation .tsx files containing prose (written in my own custom JSX DSL):
import testImage from './testImage.jpg';
import { pifagorTheorem } from './pifagor.tsx';
export default (<>
<p>Paragraph<p>
{pifagorTheorem}
<Image module={testImage} />
...
</>)
Obviously, I can't use ESM await import(...) to import such prose files because Node does not know how to handle TypeScript, JSX and custom extensions. So I use jiti to import such files.
Additional information
Describe the feature
Right now if you define
transformoption when creating jiti, it will completely drop default behaviour.So to add support for custom extensions one have to create a dummy jiti instance, take default
transitionfrom there and use it in actual jiti:I think it would be a good idea to support extending default transition or passing default transition method inside redefined
transitionto use it there.Sounds like a good idea to me... Or I am doing something wrong and not where it is intended to be done?
Context
I use jiti in my auto-generated documentation project to read documentation
.tsxfiles containing prose (written in my own custom JSX DSL):Obviously, I can't use ESM
await import(...)to import such prose files because Node does not know how to handle TypeScript, JSX and custom extensions. So I use jiti to import such files.Additional information