-
-
Notifications
You must be signed in to change notification settings - Fork 281
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
feat(prisma): enable prisma generator support for ESM #2700
feat(prisma): enable prisma generator support for ESM #2700
Conversation
import { argv } from "node:process"; | ||
|
||
// @ts-ignore | ||
register('extensionless', import.meta.url, {data: {argv1: argv[1]}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's preferable to add extension explicitly no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#!/usr/bin/env node --import extensionless/register
import "./cli/generator";
The modification above simplifies the originally committed code. However, it requires installing the 'extensionless' module in my own project. I'm not sure how to improve this further. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The target is to generate the code for esm without an additional plugin. So I prefer to not register a loader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe trying to have the same code base to generate cjs and esm code is an error 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using top level yarn build import statement contains .js extension. but js files emit by prisma generator is missing the js extension.
lib/esm/.schema/index.js
export * from "./interfaces";
export * from "./models";
export * from "./services/PrismaService";
export * from "./repositories";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall I add a .js suffix to all these import statements? such as following ts file
tsed/packages/orm/prisma/src/generator/utils/generateIndex.ts
export function generateIndex(project: Project, baseDirPath: string, hasEnum: boolean) {
const indexFile = path.resolve(baseDirPath, "index.ts");
project.createSourceFile(indexFile, undefined, {overwrite: true}).addExportDeclarations(
[
{
moduleSpecifier: "./interfaces"
},
hasEnum && {
moduleSpecifier: "./enums"
},
{
moduleSpecifier: "./models"
},
{
moduleSpecifier: "./services/PrismaService"
},
{
moduleSpecifier: "./repositories"
}
].filter(Boolean) as any[]
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vangie done. I fixed all path. You can run locally the appropriate npm scripts "generate:postgres:esm"
If you see something wrong tell me :)
Hello @vangie Also, the repo follow a angular commit convention and use semantic release. Can you remove emoji from your commit message please (isn't supported by semantic release). The commit message must be:
|
d0c3b48
to
92001c5
Compare
OK, I have amended the git msg and add the missing yarn.lock file |
I think publish a code that support commonjs / esm for this plugin is complicated. I started the v8 branch (ESM only). Maybe it's more appropriate to add this PR to the v8 roadmap. The branch is almost ready. There are small issue related to GQL and prisma module. Another solution is to duplicate the code inside the tsed/prisma module (one for cjs and one esm) and use exports field to use the appropriate code convention. See you |
16aca2f
to
65476b2
Compare
@vangie I pushed some commit to unlock your dev ;) Now you can generate the code for ESM and CJS.
See you |
dbd41ba
to
b35a99f
Compare
b35a99f
to
61442f0
Compare
2533ce2
to
2552db1
Compare
@vangie @Tomdrouv1 The PR seems to be ready ;) can you review the changes ? |
🎉 This PR is included in version 7.71.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Information
Todos