From e8a86fd0e037d042e2b1bec25b6dcb9b15654da2 Mon Sep 17 00:00:00 2001 From: Errorname Date: Mon, 25 May 2020 23:11:44 +0200 Subject: [PATCH] :bookmark: Release 2.0.0-beta.4 --- README.md | 2 +- .../basic-js/multi-tenancy-example.js | 6 +-- docs/examples/basic-js/package-lock.json | 38 +++++++--------- docs/examples/basic-js/package.json | 7 ++- .../basic-ts/multi-tenancy-example.ts | 6 +-- docs/examples/basic-ts/package-lock.json | 44 ++++++++----------- docs/examples/basic-ts/package.json | 7 ++- package-lock.json | 8 ++-- package.json | 6 +-- src/cli/helpers/checkCompatibility.ts | 4 +- src/lib/index.ts | 10 +++++ src/shared/constants.ts | 2 +- tests/lib/constructor.test.ts | 2 +- tests/playground/example/package.json | 4 +- 14 files changed, 66 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 2dbbd2b..235611b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ npm i -g prisma-multi-tenant@beta ``` $> prisma-multi-tenant help - 🧭 prisma-multi-tenant v2.0.0-beta.3 + 🧭 prisma-multi-tenant v2.0.0-beta.4 USAGE diff --git a/docs/examples/basic-js/multi-tenancy-example.js b/docs/examples/basic-js/multi-tenancy-example.js index 60c9488..821ff7a 100644 --- a/docs/examples/basic-js/multi-tenancy-example.js +++ b/docs/examples/basic-js/multi-tenancy-example.js @@ -1,10 +1,6 @@ const { MultiTenant } = require('prisma-multi-tenant') -require('dotenv').config({ - path: 'prisma/.env' -}) - -// This is the name of your first tenant, try with another one +// This is the name of your first tenant, try with another one: "prod" const name = 'dev' const multiTenant = new MultiTenant() diff --git a/docs/examples/basic-js/package-lock.json b/docs/examples/basic-js/package-lock.json index 336f59f..815bda0 100644 --- a/docs/examples/basic-js/package-lock.json +++ b/docs/examples/basic-js/package-lock.json @@ -5,15 +5,15 @@ "requires": true, "dependencies": { "@prisma/cli": { - "version": "2.0.0-beta.3", - "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.3.tgz", - "integrity": "sha512-VZxeTLLMenhkAyaY4tvTqChcW6QtUkiVvZj7N6A2vi6HsM1Tnf0fIZsiH1h3e/LEnaaDGIUC8F4Gkh2SeyeyCg==", + "version": "2.0.0-beta.4", + "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.4.tgz", + "integrity": "sha512-z9si4cmn/dN7bxVx3hbdDFL6fQuosTzj45EhVrCYt6VCWcJ5jYn0Fzamr+npZvbR/Gl6eLhexXP1sa7iGe8gjA==", "dev": true }, "@prisma/client": { - "version": "2.0.0-beta.3", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.0.0-beta.3.tgz", - "integrity": "sha512-itwRDl9PS8pD9InbHFeh1m3kyMibpZbkMHx9/Q7lNVaxvBJeJjNlVFmclL9AIFMDAUhD+KtspqkBwUHKgJpd7g==" + "version": "2.0.0-beta.4", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.0.0-beta.4.tgz", + "integrity": "sha512-LEtHIQVJrM7Y8H0G288sKxvsFv1od7tG8SiaWQvzv51AZo7IsK+n+wJ8A1/tJ6eL/7UQWHZQjZN7JLgpxetFvw==" }, "@types/color-name": { "version": "1.1.1", @@ -765,11 +765,6 @@ "isobject": "^3.0.1" } }, - "is-promise": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", - "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" - }, "is-windows": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", @@ -968,9 +963,9 @@ "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, "prisma-multi-tenant": { - "version": "2.0.0-beta.3", - "resolved": "https://registry.npmjs.org/prisma-multi-tenant/-/prisma-multi-tenant-2.0.0-beta.3.tgz", - "integrity": "sha512-/b6+FO4PQ1hHi7OYIblISMpfadcJnBzqdtQ+Tscu7VWLMBOUytcS7NWRVnKZorZkUq+sfu9Kqu8b4lDMBNFCPw==", + "version": "2.0.0-beta.4", + "resolved": "https://registry.npmjs.org/prisma-multi-tenant/-/prisma-multi-tenant-2.0.0-beta.4.tgz", + "integrity": "sha512-WPYnu804xQ8t7Fprc5gm1rE27fonoPDzpX0ktdwo2MPG/7yEox9DGK+2BV27EQHn4WNRLqvmiDzzmA9OOHkE0w==", "requires": { "arg": "^4.1.2", "chalk": "^3.0.0", @@ -1028,12 +1023,9 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==" }, "run-async": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.0.tgz", - "integrity": "sha512-xJTbh/d7Lm7SBhc1tNvTpeCHaEzoyxPrqNlvSdMfBTYwaY++UJFyXUOxAtsRUXjlqOfj8luNaR9vjCh4KeV+pg==", - "requires": { - "is-promise": "^2.1.0" - } + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", + "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==" }, "rxjs": { "version": "6.5.5", @@ -1305,9 +1297,9 @@ } }, "tslib": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", - "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==" + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", + "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==" }, "type-fest": { "version": "0.11.0", diff --git a/docs/examples/basic-js/package.json b/docs/examples/basic-js/package.json index c74ece0..09afada 100644 --- a/docs/examples/basic-js/package.json +++ b/docs/examples/basic-js/package.json @@ -10,11 +10,10 @@ "author": "", "license": "ISC", "devDependencies": { - "@prisma/cli": "2.0.0-beta.3" + "@prisma/cli": "2.0.0-beta.4" }, "dependencies": { - "@prisma/client": "2.0.0-beta.3", - "dotenv": "8.2.0", - "prisma-multi-tenant": "2.0.0-beta.3" + "@prisma/client": "2.0.0-beta.4", + "prisma-multi-tenant": "2.0.0-beta.4" } } diff --git a/docs/examples/basic-ts/multi-tenancy-example.ts b/docs/examples/basic-ts/multi-tenancy-example.ts index bfbba74..47a4d41 100644 --- a/docs/examples/basic-ts/multi-tenancy-example.ts +++ b/docs/examples/basic-ts/multi-tenancy-example.ts @@ -1,11 +1,7 @@ import { PrismaClient } from '@prisma/client' import { MultiTenant } from 'prisma-multi-tenant' -require('dotenv').config({ - path: 'prisma/.env' -}) - -// This is the name of your first tenant, try with another one +// This is the name of your first tenant, try with another one: "prod" const name = 'dev' const multiTenant = new MultiTenant() diff --git a/docs/examples/basic-ts/package-lock.json b/docs/examples/basic-ts/package-lock.json index b10fe91..7abd839 100644 --- a/docs/examples/basic-ts/package-lock.json +++ b/docs/examples/basic-ts/package-lock.json @@ -5,15 +5,15 @@ "requires": true, "dependencies": { "@prisma/cli": { - "version": "2.0.0-beta.3", - "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.3.tgz", - "integrity": "sha512-VZxeTLLMenhkAyaY4tvTqChcW6QtUkiVvZj7N6A2vi6HsM1Tnf0fIZsiH1h3e/LEnaaDGIUC8F4Gkh2SeyeyCg==", + "version": "2.0.0-beta.4", + "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.4.tgz", + "integrity": "sha512-z9si4cmn/dN7bxVx3hbdDFL6fQuosTzj45EhVrCYt6VCWcJ5jYn0Fzamr+npZvbR/Gl6eLhexXP1sa7iGe8gjA==", "dev": true }, "@prisma/client": { - "version": "2.0.0-beta.3", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.0.0-beta.3.tgz", - "integrity": "sha512-itwRDl9PS8pD9InbHFeh1m3kyMibpZbkMHx9/Q7lNVaxvBJeJjNlVFmclL9AIFMDAUhD+KtspqkBwUHKgJpd7g==" + "version": "2.0.0-beta.4", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.0.0-beta.4.tgz", + "integrity": "sha512-LEtHIQVJrM7Y8H0G288sKxvsFv1od7tG8SiaWQvzv51AZo7IsK+n+wJ8A1/tJ6eL/7UQWHZQjZN7JLgpxetFvw==" }, "@types/color-name": { "version": "1.1.1", @@ -775,11 +775,6 @@ "isobject": "^3.0.1" } }, - "is-promise": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", - "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" - }, "is-windows": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", @@ -983,9 +978,9 @@ "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, "prisma-multi-tenant": { - "version": "2.0.0-beta.3", - "resolved": "https://registry.npmjs.org/prisma-multi-tenant/-/prisma-multi-tenant-2.0.0-beta.3.tgz", - "integrity": "sha512-/b6+FO4PQ1hHi7OYIblISMpfadcJnBzqdtQ+Tscu7VWLMBOUytcS7NWRVnKZorZkUq+sfu9Kqu8b4lDMBNFCPw==", + "version": "2.0.0-beta.4", + "resolved": "https://registry.npmjs.org/prisma-multi-tenant/-/prisma-multi-tenant-2.0.0-beta.4.tgz", + "integrity": "sha512-WPYnu804xQ8t7Fprc5gm1rE27fonoPDzpX0ktdwo2MPG/7yEox9DGK+2BV27EQHn4WNRLqvmiDzzmA9OOHkE0w==", "requires": { "arg": "^4.1.2", "chalk": "^3.0.0", @@ -1043,12 +1038,9 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==" }, "run-async": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.0.tgz", - "integrity": "sha512-xJTbh/d7Lm7SBhc1tNvTpeCHaEzoyxPrqNlvSdMfBTYwaY++UJFyXUOxAtsRUXjlqOfj8luNaR9vjCh4KeV+pg==", - "requires": { - "is-promise": "^2.1.0" - } + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", + "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==" }, "rxjs": { "version": "6.5.5", @@ -1212,9 +1204,9 @@ } }, "source-map-support": { - "version": "0.5.16", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.16.tgz", - "integrity": "sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==", + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -1348,9 +1340,9 @@ } }, "tslib": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz", - "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==" + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz", + "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==" }, "type-fest": { "version": "0.11.0", diff --git a/docs/examples/basic-ts/package.json b/docs/examples/basic-ts/package.json index f4cd95c..e7d995b 100644 --- a/docs/examples/basic-ts/package.json +++ b/docs/examples/basic-ts/package.json @@ -10,12 +10,11 @@ "author": "", "license": "ISC", "devDependencies": { - "@prisma/cli": "2.0.0-beta.3" + "@prisma/cli": "2.0.0-beta.4" }, "dependencies": { - "@prisma/client": "2.0.0-beta.3", - "dotenv": "8.2.0", - "prisma-multi-tenant": "2.0.0-beta.3", + "@prisma/client": "2.0.0-beta.4", + "prisma-multi-tenant": "2.0.0-beta.4", "ts-node": "8.6.2", "typescript": "3.8.2" } diff --git a/package-lock.json b/package-lock.json index b43806f..f8aa621 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prisma-multi-tenant", - "version": "2.0.0-beta.3", + "version": "2.0.0-beta.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1450,9 +1450,9 @@ } }, "@prisma/cli": { - "version": "2.0.0-beta.3", - "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.3.tgz", - "integrity": "sha512-VZxeTLLMenhkAyaY4tvTqChcW6QtUkiVvZj7N6A2vi6HsM1Tnf0fIZsiH1h3e/LEnaaDGIUC8F4Gkh2SeyeyCg==", + "version": "2.0.0-beta.4", + "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.0.0-beta.4.tgz", + "integrity": "sha512-z9si4cmn/dN7bxVx3hbdDFL6fQuosTzj45EhVrCYt6VCWcJ5jYn0Fzamr+npZvbR/Gl6eLhexXP1sa7iGe8gjA==", "dev": true }, "@sinonjs/commons": { diff --git a/package.json b/package.json index 06a31a7..928fbfe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prisma-multi-tenant", - "version": "2.0.0-beta.3", + "version": "2.0.0-beta.4", "description": "🧭 Use Prisma as a multi-tenant provider for your application", "author": { "name": "Thibaud Courtoison", @@ -34,13 +34,13 @@ "inquirer": "^7.0.4" }, "peerDependencies": { - "@prisma/cli": "^2.0.0-beta.3" + "@prisma/cli": "^2.0.0-beta.4" }, "devDependencies": { "@babel/core": "^7.8.3", "@babel/preset-env": "^7.8.3", "@babel/preset-typescript": "^7.8.3", - "@prisma/cli": "^2.0.0-beta.3", + "@prisma/cli": "^2.0.0-beta.4", "@types/inquirer": "^6.5.0", "@types/jest": "^25.1.0", "@types/node": "^13.7.0", diff --git a/src/cli/helpers/checkCompatibility.ts b/src/cli/helpers/checkCompatibility.ts index c2b9502..444f462 100644 --- a/src/cli/helpers/checkCompatibility.ts +++ b/src/cli/helpers/checkCompatibility.ts @@ -18,6 +18,8 @@ export default () => { ) } } catch { - console.warn(chalk.yellow`Warning: Couldn't verify version compatibility with @prisma/cli`) + console.warn( + chalk.yellow`Warning: Couldn't verify version compatibility with @prisma/cli. Did you forget to install it locally?` + ) } } diff --git a/src/lib/index.ts b/src/lib/index.ts index 9ba13a2..1fb6152 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,3 +1,4 @@ +import path from 'path' import { datasourceProviders } from '../shared/constants' import { runDistantPrisma, requireDistant } from '../shared/shell' import Management from '../shared/management' @@ -31,6 +32,8 @@ class MultiTenant Promise }> { constructor(options?: MultiTenantOptions) { this.options = { ...defaultMultiTenantOptions, ...options } + this.loadEnv() + this.ClientTenant = this.requireTenant() if (this.options.useManagement) { @@ -40,6 +43,13 @@ class MultiTenant Promise }> { this.tenants = {} } + private loadEnv(): void { + // Try loading env variables + require('dotenv').config({ + path: path.resolve(process.cwd(), 'prisma/.env') + }) + } + private requireTenant(): any { if (this.options.PrismaClient) { return this.options.PrismaClient diff --git a/src/shared/constants.ts b/src/shared/constants.ts index d217720..478ca48 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -1,2 +1,2 @@ export const datasourceProviders = ['sqlite', 'mysql', 'postgresql'] -export const clientManagementPath = '@prisma/prisma-multi-tenant/management' +export const clientManagementPath = '.prisma-multi-tenant/management' diff --git a/tests/lib/constructor.test.ts b/tests/lib/constructor.test.ts index 30d574c..48a125e 100644 --- a/tests/lib/constructor.test.ts +++ b/tests/lib/constructor.test.ts @@ -32,7 +32,7 @@ describe('constructor', () => { test('PrismaClient & PrismaClientManagement', () => { const PrismaClient = require(`@prisma/client`) - const PrismaClientManagement = require(`@prisma/prisma-multi-tenant/management`) + const PrismaClientManagement = require(`.prisma-multi-tenant/management`) const multiTenant = new MultiTenant({ PrismaClient, diff --git a/tests/playground/example/package.json b/tests/playground/example/package.json index 54ad38d..a0558f7 100644 --- a/tests/playground/example/package.json +++ b/tests/playground/example/package.json @@ -3,10 +3,10 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@prisma/client": "2.0.0-beta.3" + "@prisma/client": "2.0.0-beta.4" }, "devDependencies": { - "@prisma/cli": "2.0.0-beta.3" + "@prisma/cli": "2.0.0-beta.4" }, "scripts": { "dev": "node ./script.js"