Skip to content

Commit

Permalink
improve: remove @nexus/schema & graphql from peer deps (#735)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Kuhrt <jasonkuhrt@me.com>
  • Loading branch information
Weakky and jasonkuhrt authored Jun 30, 2020
1 parent 2e325dd commit 70e7be7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,22 @@
"release:stable": "dripip stable",
"release:pr": "dripip pr",
"clean": "rm -rf dist",
"build": "ts-node scripts/ensure-prisma2-version && yarn -s clean && yarn -s build:module-facades && tsc && ts-node scripts/post-build",
"build": "yarn clean && yarn build:module-facades && tsc && ts-node scripts/post-build",
"build:module-facades": "node scripts/build-module-facades",
"build:ci": "tsc",
"dev": "yarn -s build:module-facades && tsc --watch",
"prepublishOnly": "yarn -s build",
"format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts' 'examples/**/*.ts'",
"postinstall": "node ./scripts/postinstall.js",
"test": "ts-node scripts/ensure-prisma2-version && ts-node tests/__ensure-engine && jest --forceExit",
"test:dev": "ts-node scripts/ensure-prisma2-version && ts-node tests/__ensure-engine && jest src tests/schema --watch",
"test": "ts-node tests/__ensure-engine && jest --forceExit",
"test:dev": "ts-node tests/__ensure-engine && jest src tests/schema --watch",
"test:unit": "jest src --testTimeout=15000 --forceExit",
"test:schema": "yarn test --testTimeout=15000 tests/schema",
"test:fw:e2e:mysql": "yarn test --testTimeout=400000 tests/framework/e2e/mysql.test.ts",
"test:fw:e2e:postgres": "yarn test --testTimeout=400000 tests/framework/e2e/postgres.test.ts",
"test:fw:e2e:sqlite": "yarn test --testTimeout=400000 tests/framework/e2e/sqlite.test.ts",
"test:db:setup": "docker-compose down && rm -rf .mysql-data && rm -rf .postgres-data && docker-compose up -d"
},
"peerDependencies": {
"@nexus/schema": "^0.14.0",
"graphql": "^14.6.0"
},
"dependencies": {
"@prisma/cli": "2.1.3",
"@prisma/client": "2.1.3",
Expand Down
26 changes: 0 additions & 26 deletions scripts/ensure-prisma2-version.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/schema-entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
import { ensureDepIsInstalled } from './schema/utils'

ensureDepIsInstalled('@nexus/schema')
ensureDepIsInstalled('graphql')

export * from './schema'
20 changes: 20 additions & 0 deletions src/schema/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs-extra'
import { GraphQLResolveInfo } from 'graphql'
import * as path from 'path'
import { isDeepStrictEqual } from 'util'
import chalk from 'chalk'

/**
* Write file contents but first delete the file off disk if present. This is a
Expand Down Expand Up @@ -185,3 +186,22 @@ export const isEmptyObject = (o: any) => isDeepStrictEqual(o, {})
export function keys<A extends object>(a: A): (keyof A)[] {
return Object.keys(a) as any
}

export function ensureDepIsInstalled(depName: string) {
try {
require(depName)
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
console.error(
`${chalk.redBright('ERROR:')} When nexus-plugin-prisma is used as a Nexus Schema plugin, ${chalk.greenBright(
depName
)} must be installed as a dependency. Please run \`${chalk.greenBright(
`npm install ${depName}`
)}\`.`
)
process.exit(1)
} else {
throw err
}
}
}

0 comments on commit 70e7be7

Please sign in to comment.