Skip to content

Commit

Permalink
fix(client): custom output dir
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Apr 24, 2020
1 parent c045200 commit 702dcf6
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/packages/cli/__snapshots__/integrate.generate.test.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exports['should work with a custom output dir 1'] = [
{
"id": 1,
"email": "bob@bob.bob",
"name": "Bobby Brown Sqlite"
}
]
1 change: 1 addition & 0 deletions src/packages/cli/fixtures/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,4 @@ if [[ ${GENERATE_ABSOLUTE_SCHEMA_FROM_PARENT_INVALID} != *"Provided --schema at
echo "prisma generate --schema=$GENERATE_ABSOLUTE_SCHEMA_FROM_PARENT_INVALID_PATH is broken (should fail)"
exit 1
fi

13 changes: 8 additions & 5 deletions src/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"version": "c526ff865b5185828c2db422138feb2168abef9a"
},
"devDependencies": {
"@apexearth/copy": "^1.4.5",
"@prisma/ci-info": "^2.1.1",
"@prisma/client": "workspace:*",
"@prisma/fetch-engine": "workspace:*",
Expand Down Expand Up @@ -80,6 +81,7 @@
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.3",
"execa": "^4.0.0",
"global-dirs": "^2.0.1",
"husky": "^4.2.5",
"is-installed-globally": "^0.3.2",
Expand All @@ -102,17 +104,18 @@
"sqlite3": "4.1.1",
"strip-ansi": "^6.0.0",
"strip-indent": "3.0.0",
"tempy": "^0.5.0",
"terminal-link": "^2.1.1",
"tmp": "^0.1.0",
"ts-jest": "^25.3.1",
"ts-mocha": "6.0.0",
"typescript": "^3.8.3"
},
"scripts": {
"test-sqlite": "./node_modules/.bin/mocha src/__tests__/integrate.sqlite.test.ts --require ts-mocha src/__tests__/integrate.sqlite.test.ts --timeout 10s",
"test-mariadb": "./node_modules/.bin/mocha src/__tests__/integrate.mariadb.test.ts --require ts-mocha src/__tests__/integrate.mariadb.test.ts --timeout 10s",
"test-mysql": "./node_modules/.bin/mocha src/__tests__/integrate.mysql.test.ts --require ts-mocha src/__tests__/integrate.mysql.test.ts --timeout 10s",
"test-postgresql": "./node_modules/.bin/mocha src/__tests__/integrate.postgresql.test.ts --require ts-mocha src/__tests__/integrate.postgresql.test.ts --timeout 10s",
"test:generate": "./node_modules/.bin/mocha src/__tests__/integrate.generate.test.ts --require ts-mocha src/__tests__/integrate.generate.test.ts --timeout 10s",
"test:sqlite": "./node_modules/.bin/mocha src/__tests__/integrate.sqlite.test.ts --require ts-mocha src/__tests__/integrate.sqlite.test.ts --timeout 10s",
"test:mariadb": "./node_modules/.bin/mocha src/__tests__/integrate.mariadb.test.ts --require ts-mocha src/__tests__/integrate.mariadb.test.ts --timeout 10s",
"test:mysql": "./node_modules/.bin/mocha src/__tests__/integrate.mysql.test.ts --require ts-mocha src/__tests__/integrate.mysql.test.ts --timeout 10s",
"test:postgresql": "./node_modules/.bin/mocha src/__tests__/integrate.postgresql.test.ts --require ts-mocha src/__tests__/integrate.postgresql.test.ts --timeout 10s",
"test": "./node_modules/.bin/packwatch && ./fixtures/test.sh && pnpm run test-postgresql && pnpm run test-sqlite && pnpm run test-mysql",
"test:debug": "./node_modules/.bin/mocha --inspect-brk src/__tests__/integrate.* --require ts-mocha src/__tests__/integrate.* --timeout 10s",
"test:mocha": "./node_modules/.bin/mocha src/__tests__/integrate.* --require ts-mocha src/__tests__/integrate.* --timeout 10s",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!prisma
!prisma/dev.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PrismaClient } from './generated/client'

export async function main() {
const client = new PrismaClient()

const data = await client.user.findMany()
client.disconnect()
return data
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
generator client {
provider = "prisma-client-js"
output = "../generated/client"
}

datasource db {
provider = "sqlite"
url = "file:dev.db"
}

model Post {
id Int @default(autoincrement()) @id
createdAt DateTime @default(now())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}

model Profile {
id Int @default(autoincrement()) @id
bio String?
user User @relation(fields: [userId], references: [id])
userId Int @unique
}

model User {
id Int @default(autoincrement()) @id
email String @unique
name String?
posts Post[]
profile Profile?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"strict": true /* Enable all strict type-checking options. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
72 changes: 72 additions & 0 deletions src/packages/cli/src/__tests__/fixtures/example-project/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@prisma/cli@^2.0.0-alpha.1137":
version "2.0.0-alpha.1137"
resolved "https://registry.yarnpkg.com/@prisma/cli/-/cli-2.0.0-alpha.1137.tgz#5edb93bb430958d3def715679dda22e7c62ad0eb"
integrity sha512-54YANz8G7oVpEE+gVF6prbxT61Pyea3YHv2fPYZemBXscXlrlG7GZkDh0JX0yR1Rcp9cjL4QMsJvNO5XKzwAew==

"@prisma/client@^2.0.0-alpha.1137":
version "2.0.0-alpha.1137"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-2.0.0-alpha.1137.tgz#fd5216e4a8b836a373b887aa20466a53e3942828"
integrity sha512-UNKgKySmeC17YZ3OfqZpwU0zR4Ljfi1gWEO4+aLWo7DyrK3sdp/45G2EZGIOpX/weVDM+vcZWIMcWOyJ3apkEQ==

"@types/node@^13.11.1":
version "13.11.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.11.1.tgz#49a2a83df9d26daacead30d0ccc8762b128d53c7"
integrity sha512-eWQGP3qtxwL8FGneRrC5DwrJLGN4/dH1clNTuLfN81HCrxVtxRjygDTUoZJ5ASlDEeo0ppYFQjQIlXhtXpOn6g==

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==

diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

source-map-support@^0.5.6:
version "0.5.16"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042"
integrity sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map@^0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

ts-node@^8.8.2:
version "8.8.2"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.8.2.tgz#0b39e690bee39ea5111513a9d2bcdc0bc121755f"
integrity sha512-duVj6BpSpUpD/oM4MfhO98ozgkp3Gt9qIp3jGxwU2DFvl/3IRaEAvbLa8G60uS7C77457e/m5TMowjedeRxI1Q==
dependencies:
arg "^4.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.6"
yn "3.1.1"

typescript@^3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==

yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
29 changes: 29 additions & 0 deletions src/packages/cli/src/__tests__/integrate.generate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import tempy from 'tempy'
import path from 'path'
import copy from '@apexearth/copy'
import execa from 'execa'
import assert from 'assert'
import snapshot from 'snap-shot-it'
import 'ts-node/register'

it('should work with a custom output dir', async () => {
// get temp dir
const target = tempy.directory()
// copy example into temp dir
// why a tmp dir? To make sure, we're outside of this workspace
await copy({
from: path.join(__dirname, './fixtures/example-project'),
to: target,
recursive: true,
})
// generate into temp dir
await execa.node(path.join(__dirname, '../../build/index.js'), ['generate'], {
cwd: target,
stdio: 'ignore',
})
// run code
const { main } = await import(path.join(target, 'main.ts'))
const result = await main()
snapshot(result)
assert(true)
})
8 changes: 8 additions & 0 deletions src/packages/engine-core/src/NodeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ You may have to run ${chalk.greenBright(
if (fs.existsSync(dirnamePath)) {
return dirnamePath
}
const parentDirName = await this.getQueryEnginePath(
this.platform,
path.join(eval('__dirname'), '..'),
)
debug({ parentDirName })
if (fs.existsSync(parentDirName)) {
return parentDirName
}
const cwdPath = await this.getQueryEnginePath(this.platform, this.cwd)
if (fs.existsSync(cwdPath)) {
return cwdPath
Expand Down
8 changes: 6 additions & 2 deletions src/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 702dcf6

Please sign in to comment.