Cauen / prisma-generator-pothos-codegen

The fastest way to create a fully customizable CRUD Graphql API from Prisma Schema.
https://www.npmjs.com/package/prisma-generator-pothos-codegen
102 stars 19 forks source link

ESM support? #63

Open H01001000 opened 11 months ago

H01001000 commented 11 months ago

Hello, it is not mentioned in the README, but I wonder does it supports outputting ESM module?

Cauen commented 11 months ago

Hi @H01001000 I don't know if I understand your issue correctly Has Commonjs been generated for you?

H01001000 commented 11 months ago

Mainly about importing, esm need import extension, where input and builder file I can manually add .js at back, but for example utils and object.base don’t have import extension

Cauen commented 11 months ago

You are needing to replace imports with -.js ?

For example: import { defineMutation, defineMutationFunction, defineMutationPrismaObject } from '../../utils'; to import { defineMutation, defineMutationFunction, defineMutationPrismaObject } from '../../utils.js';

?

Although I don't understand exactly why, if this is the case perhaps you could use the configs.global.replacer setting to define a function for this

H01001000 commented 11 months ago

@Cauen https://nodejs.org/api/esm.html#mandatory-file-extensions

Cauen commented 11 months ago

@H01001000 If I understand correctly the way your project is configured, you need the .ts at the end of each import, right? Does the replacer solve your case?

joshuaavalon commented 11 months ago

@Cauen In simple words,

ESM can works with

// Same with TypeScript targeting ESM
import { } from "./script.js"
import { } from "./dir/index.js"

CommonJS can works with both

const { } = require("./script");
const { } = require("./script.js");
const { } = require("./dir");
const { } = require("./dir/index.js");
// TypeScript target CJS
import { } from "./script"
import { } from "./script.js"
import { } from "./dir"
import { } from "./dir/index.js"
H01001000 commented 11 months ago

@Cauen sorry for the late reply, it should Besides it seems that because this repo's target is commonJS, an explicit .cjs extension is needed for pothos.config.xxx

for now, I did is generate it as a separate package with type commonJS, and import it to main pkg

p.s. is type checking possible? tsc with skipLibCheck: false results in run out heap or run forever. there also seems some type error

Cauen commented 11 months ago

Our lib today generates typescript code, right? I can't quite understand how these extensions cause any problems in your project.

Could you send me some minimal example of the problem you have there?

In the develop branch, i've created an example with dev, build and start commands https://github.com/Cauen/prisma-generator-pothos-codegen/blob/develop/examples/inputs-simple-sqlite/package.json

Is the problem you face with the build?

H01001000 commented 11 months ago

@Cauen MRE: add "type": "module" to package.json

Cauen commented 10 months ago

Hi @H01001000 Can you please propose the solution you need as a PR?

H01001000 commented 10 months ago

sure, btw what yarn version you using? it seem the yarn is not up to date, want we pr it?

Cauen commented 10 months ago

Feel free to update it :)

My version: 1.22.21

H01001000 commented 10 months ago

@Cauen btw I found out that when simple is false, tsc runs out of the heap when compiling my input.ts file. Is it possible to split the input file for each model?