Skip to content

Commit

Permalink
fix: remove esm build (#696)
Browse files Browse the repository at this point in the history
* test: add esm e2e test

* test: update esm test to work with commonjs nexus-prisma

* fix: remove esm build

* fix: remove require statements from exports section
  • Loading branch information
rostislav-simonik authored Jul 31, 2023
1 parent 8a50ccc commit 9c549b8
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 17 deletions.
4 changes: 4 additions & 0 deletions docs/pages/docs/notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ We test the latest versions of `@prisma/client` against Node 18, 16 and 14 on Ub
### Patch Version Support Policy

We only support the latest patch version of a minor series. For example imagine that there was a bug when `nexus-prisma` was integrated with `@prisma/client@2.30.1` but _not_ when integrated with `@prisma/client@2.30.2`. Our policy would be that users should upgrade to the latest `2.30.x` version, and that we would not release any no code changes of `nexus-prisma`.

### ESM Support

We are not supporting esm build yet, more info [here](https://github.com/graphql-nexus/nexus-prisma/discussions/693).
7 changes: 6 additions & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const filter = (filenames) =>
filenames.filter((filename) =>
['docs', 'tests/e2e/fixtures'].every((pattern) => filename.indexOf(pattern) === -1),
)

module.exports = {
'*': 'prettier --ignore-unknown --check',
'*.{ts,tsx}': (filenames) => [
`yarn eslint --ext .ts,.tsx --max-warnings 0 ${filenames.join(' ')}`,
`yarn eslint --ext .ts,.tsx --max-warnings 0 ${filter(filenames).join(' ')}`,
'yarn type:check --skipLibCheck',
],
}
20 changes: 5 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,16 @@
"license": "MIT",
"files": [
"dist-cjs",
"dist-esm",
"scripts/production",
"scalars.d.ts",
"scalars.js",
"generator.d.ts",
"generator.js"
],
"exports": {
".": {
"require": "./dist-cjs/entrypoints/main.js",
"import": "./dist-esm/entrypoints/main.js"
},
"./scalars": {
"require": "./dist-cjs/entrypoints/scalars.js",
"import": "./dist-esm/entrypoints/scalars.js"
},
"./generator": {
"require": "./dist-cjs/entrypoints/generator.js",
"import": "./dist-esm/entrypoints/generator.js"
},
".": "./dist-cjs/entrypoints/main.js",
"./scalars": "./dist-cjs/entrypoints/scalars.js",
"./generator": "./dist-cjs/entrypoints/generator.js",
"./*": {
"default": "./*.js"
}
Expand Down Expand Up @@ -57,10 +47,10 @@
"format": "prettier --check .",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"lint": "eslint . --ext .ts,.tsx --max-warnings 0",
"dev": "yarn -s clean && tsc --build --watch tsconfig.cjs.json tsconfig.esm.json",
"dev": "yarn -s clean && tsc --build --watch tsconfig.cjs.json",
"dev:ts": "yarn dev",
"dev:yalc": "nodemon --delay 1.5 --exec 'yalc push --no-scripts' --watch 'dist-*/**/*'",
"build": "yarn generate && yarn clean && tsc --build tsconfig.cjs.json tsconfig.esm.json",
"build": "yarn generate && yarn clean && tsc --build tsconfig.cjs.json",
"test": "cross-env NO_COLOR=true DEBUG='konn*,e2e' jest",
"test:e2e": "cross-env NO_COLOR=true DEBUG=e2e jest --selectProjects e2e",
"test:unit": "cross-env NO_COLOR=true jest --selectProjects unit",
Expand Down
3 changes: 2 additions & 1 deletion tests/__helpers__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export const timeoutRace = async <T>(
}

export function assertBuildPresent() {
/* not supported yet, for more info https://github.com/graphql-nexus/nexus-prisma/discussions/693
if (fs.exists(Path.join(__dirname, '../../dist-esm')) === false)
throw new Error(`Please run build ESM before running this test`)

*/
if (fs.exists(Path.join(__dirname, '../../dist-cjs')) === false)
throw new Error(`Please run build CJS before running this test`)
}
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/__snapshots__/esm.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`esm: esm project successfully imports nexus-prisma 1`] = `
"type Foo {
id: ID!
}
type Query {
foos: [Foo]
}"
`;
31 changes: 31 additions & 0 deletions tests/e2e/esm.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { konn, providers } from 'konn'
import * as Path from 'path'
import { stripEndingLines } from '../__helpers__/helpers'
import { project } from '../__providers__/project'
import { monitorAsyncMethod, run } from '../__providers__/run'

const ctx = konn().useBeforeEach(providers.dir()).useBeforeEach(run()).useBeforeEach(project()).done()

it(
'esm: esm project successfully imports nexus-prisma',
async () => {
expect.assertions(1)
await ctx.fixture.useAsync(Path.join(__dirname, 'fixtures/esm'))
await ctx.runAsyncOrThrow(
`${Path.join(process.cwd(), 'node_modules/.bin/yalc')} add ${ctx.thisPackageName}`,
)
await monitorAsyncMethod(
() =>
ctx.runPackagerCommandAsyncOrThrow('install', '--legacy-peer-deps', {
env: { PEER_DEPENDENCY_CHECK: 'false' },
}),
{ retry: 3, timeout: 90 * 1000 },
)
await ctx.runPackagerCommandAsyncOrThrow('run', 'prisma generate')
const result = await ctx.runPackagerCommandAsyncOrThrow('run', '--silent dev', {
env: { PEER_DEPENDENCY_CHECK: 'false' },
})
expect(stripEndingLines(result.stdout)).toMatchSnapshot()
},
320 * 1000,
)
1 change: 1 addition & 0 deletions tests/e2e/fixtures/esm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
27 changes: 27 additions & 0 deletions tests/e2e/fixtures/esm/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { printSchema } from 'graphql'
import { makeSchema, objectType, queryType } from 'nexus'
import NexusPrisma from './nexus-prisma.cjs'
const { Foo } = NexusPrisma

const schema = makeSchema({
types: [
objectType({
name: Foo.$name,
definition(t) {
t.field(Foo.id)
},
}),
queryType({
definition(t) {
t.list.field('foos', {
type: 'Foo',
resolve(_, __, ctx) {
return ctx.prisma.foo.findMany()
},
})
},
}),
],
})

console.log(printSchema(schema))
1 change: 1 addition & 0 deletions tests/e2e/fixtures/esm/nexus-prisma.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('.nexus-prisma')
18 changes: 18 additions & 0 deletions tests/e2e/fixtures/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "nexus-prisma-fixture-esm",
"version": "0.0.0",
"type": "module",
"scripts": {
"build": "npm run build:prisma",
"build:prisma": "prisma generate",
"dev": "tsc && ts-node --esm main.js"
},
"devDependencies": {
"@prisma/client": "__dynamic__",
"graphql": "__dynamic__",
"nexus": "__dynamic__",
"prisma": "__dynamic__",
"ts-node": "10.9.1",
"typescript": "5.1.6"
}
}
Binary file added tests/e2e/fixtures/esm/prisma/db.sqlite
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/e2e/fixtures/esm/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
datasource db {
provider = "sqlite"
url = "file:./db.sqlite"
}

generator client {
provider = "prisma-client-js"
}

generator nexusPrisma {
provider = "nexus-prisma"
}

model Foo {
id String @id @default(cuid())
}
7 changes: 7 additions & 0 deletions tests/e2e/fixtures/esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "ES2015"
},
"include": ["."]
}

0 comments on commit 9c549b8

Please sign in to comment.