-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Lazy loading for ts-node + optional peer-dependecies #79
Comments
Currently, The Happy to take a look this week at introducing lazy loading, or happy to review PR's if it's urgent 😄 I imagine something like: export function TypeScriptLoader(options?: RegisterOptions): Loader {
let tsNodeInstance: Service;
return (path: string, content: string) => {
try {
if (!tsNodeInstance) {
const { register } = require("ts-node") as typeof import("ts-node");
tsNodeInstance = register({
...options,
compilerOptions: { module: "commonjs" },
});
}
... Would suffice, however would need to explore testing, since vitest is |
The implementation proposed is correct. This should work. Regarding ESM - it's a hard topic. So i think using Vitest with esm-first support is a good thing, but for the old project such as cosmiconfig probably not a good choice for now. |
Additionally, you should make the peer dependency optional in package.json, no?
|
Hey, thanks for the job.
Currently, loader implemented in such a way that it doesn't matter does the cosmiconfig found a .ts file or not
ts-node
is trying to load.The cosmiconfg + cosmiconfig-typescript-loader is usually used on the projects (libraries) where authors want to give users some flexibility of config files. It means some part of users want to use
.rc
files with json content, another.js
and some.ts
.But once you add this loader to the project,
ts-node
become a required dependency even if you don't use typescript configs. And application would break if you will not installts-node
m which might be not necessary for pure js projects.Related issue: lingui/js-lingui#1401
Currently, i implemented a workaround, which lazy-load a
cosmiconfig-typescript-loader
only if a *.ts file is trying to be loaded. But I think this logic could be implemented in loader itself.Also, that would be great to mention in the readme, for library authors. If they are going to use it in theirs project, they have to add all peer-depedencies from this loader to the upstream project. (as optional, if lazy-loading would be implemented)
The text was updated successfully, but these errors were encountered: