From 9c549b85f47d569bf7aa4f66667e1ecada55a278 Mon Sep 17 00:00:00 2001 From: Rostislav Simonik Date: Mon, 31 Jul 2023 22:01:32 +0200 Subject: [PATCH] fix: remove esm build (#696) * 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 --- docs/pages/docs/notes.mdx | 4 +++ lint-staged.config.js | 7 ++++- package.json | 20 ++++--------- tests/__helpers__/helpers.ts | 3 +- tests/e2e/__snapshots__/esm.test.ts.snap | 11 +++++++ tests/e2e/esm.test.ts | 31 ++++++++++++++++++++ tests/e2e/fixtures/esm/.gitignore | 1 + tests/e2e/fixtures/esm/main.ts | 27 +++++++++++++++++ tests/e2e/fixtures/esm/nexus-prisma.cjs | 1 + tests/e2e/fixtures/esm/package.json | 18 ++++++++++++ tests/e2e/fixtures/esm/prisma/db.sqlite | Bin 0 -> 20480 bytes tests/e2e/fixtures/esm/prisma/schema.prisma | 16 ++++++++++ tests/e2e/fixtures/esm/tsconfig.json | 7 +++++ 13 files changed, 129 insertions(+), 17 deletions(-) create mode 100644 tests/e2e/__snapshots__/esm.test.ts.snap create mode 100644 tests/e2e/esm.test.ts create mode 100644 tests/e2e/fixtures/esm/.gitignore create mode 100644 tests/e2e/fixtures/esm/main.ts create mode 100644 tests/e2e/fixtures/esm/nexus-prisma.cjs create mode 100644 tests/e2e/fixtures/esm/package.json create mode 100644 tests/e2e/fixtures/esm/prisma/db.sqlite create mode 100644 tests/e2e/fixtures/esm/prisma/schema.prisma create mode 100644 tests/e2e/fixtures/esm/tsconfig.json diff --git a/docs/pages/docs/notes.mdx b/docs/pages/docs/notes.mdx index da69e0a6f..5fd44ba47 100644 --- a/docs/pages/docs/notes.mdx +++ b/docs/pages/docs/notes.mdx @@ -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). diff --git a/lint-staged.config.js b/lint-staged.config.js index 6866c7d5a..93c02af97 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -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', ], } diff --git a/package.json b/package.json index 322867e43..797437b5a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "license": "MIT", "files": [ "dist-cjs", - "dist-esm", "scripts/production", "scalars.d.ts", "scalars.js", @@ -15,18 +14,9 @@ "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" } @@ -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", diff --git a/tests/__helpers__/helpers.ts b/tests/__helpers__/helpers.ts index 6b25ab28f..90827a08b 100644 --- a/tests/__helpers__/helpers.ts +++ b/tests/__helpers__/helpers.ts @@ -22,9 +22,10 @@ export const timeoutRace = async ( } 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`) } diff --git a/tests/e2e/__snapshots__/esm.test.ts.snap b/tests/e2e/__snapshots__/esm.test.ts.snap new file mode 100644 index 000000000..006366c09 --- /dev/null +++ b/tests/e2e/__snapshots__/esm.test.ts.snap @@ -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] +}" +`; diff --git a/tests/e2e/esm.test.ts b/tests/e2e/esm.test.ts new file mode 100644 index 000000000..29ed4964d --- /dev/null +++ b/tests/e2e/esm.test.ts @@ -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, +) diff --git a/tests/e2e/fixtures/esm/.gitignore b/tests/e2e/fixtures/esm/.gitignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/tests/e2e/fixtures/esm/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/tests/e2e/fixtures/esm/main.ts b/tests/e2e/fixtures/esm/main.ts new file mode 100644 index 000000000..43a32575d --- /dev/null +++ b/tests/e2e/fixtures/esm/main.ts @@ -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)) diff --git a/tests/e2e/fixtures/esm/nexus-prisma.cjs b/tests/e2e/fixtures/esm/nexus-prisma.cjs new file mode 100644 index 000000000..b09312dfe --- /dev/null +++ b/tests/e2e/fixtures/esm/nexus-prisma.cjs @@ -0,0 +1 @@ +module.exports = require('.nexus-prisma') diff --git a/tests/e2e/fixtures/esm/package.json b/tests/e2e/fixtures/esm/package.json new file mode 100644 index 000000000..5622479d2 --- /dev/null +++ b/tests/e2e/fixtures/esm/package.json @@ -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" + } +} diff --git a/tests/e2e/fixtures/esm/prisma/db.sqlite b/tests/e2e/fixtures/esm/prisma/db.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..697f34514d38df8b5e77794ea38f320cd85aeaec GIT binary patch literal 20480 zcmeI&K}*9h6u|MM?TQXY20QE;3W8pQ;mMm-D#)sHvw}NFsjR|aTGS495WM&W{WgLZ zU&X;ZOgwog|3_Y$hLVt9P9eP*#?vylx5eXKR@yz)R$8kAYn4*IWJ7Wpjx@aGi#+v8 zdtK94yMyPJc~_okEAwjJOxs+q`=Q*9<=9Gcbo>Z=QZd9f% zNo_uq6aoPR5I_I{1Q0*~0R#|0009K*C*W$wWKCHY=l}X`E-OL+0R#|0009ILKmY** z5J2Etz;n%JR^9*0PyYl02q1s}0tg_000IagfB*sr)L5Xp|L6Q);|*qM2q1s}0tg_0 O00IagfB*srh`=ZKt55>~ literal 0 HcmV?d00001 diff --git a/tests/e2e/fixtures/esm/prisma/schema.prisma b/tests/e2e/fixtures/esm/prisma/schema.prisma new file mode 100644 index 000000000..2b9672a1c --- /dev/null +++ b/tests/e2e/fixtures/esm/prisma/schema.prisma @@ -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()) +} diff --git a/tests/e2e/fixtures/esm/tsconfig.json b/tests/e2e/fixtures/esm/tsconfig.json new file mode 100644 index 000000000..fd6f95005 --- /dev/null +++ b/tests/e2e/fixtures/esm/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "module": "ES2015" + }, + "include": ["."] +}