Skip to content

Commit

Permalink
refactor(client,migrate,sdk): rename/prefix env vars with PRISMA_ (#6298
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Jolg42 committed Mar 29, 2021
1 parent e0473e3 commit 2621ae3
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions src/packages/client/scripts/postinstall.js
Expand Up @@ -19,27 +19,27 @@ function debug(message, ...optionalParams) {
* Adds `package.json` to the end of a path if it doesn't already exist'
* @param {string} pth
*/
function addPackageJSON(pth){
if(pth.endsWith('package.json')) return pth
function addPackageJSON(pth) {
if (pth.endsWith('package.json')) return pth
return path.join(pth, 'package.json')
}

/**
* Looks up for a `package.json` which is not `@prisma/cli` or `prisma` and returns the directory of the package
* @param {string} startPath - Path to Start At
* @param {number} limit - Find Up limit
* @returns {string | null}
* @returns {string | null}
*/
function findPackageRoot(startPath, limit = 10){
if(!startPath || !fs.existsSync(startPath)) return null
let currentPath = startPath
function findPackageRoot(startPath, limit = 10) {
if (!startPath || !fs.existsSync(startPath)) return null
let currentPath = startPath
// Limit traversal
for(let i = 0; i < limit; i++){
for (let i = 0; i < limit; i++) {
const pkgPath = addPackageJSON(currentPath)
if(fs.existsSync(pkgPath)){
if (fs.existsSync(pkgPath)) {
try {
const pkg = require(pkgPath)
if(pkg.name && !['@prisma/cli', 'prisma'].includes(pkg.name)){
if (pkg.name && !['@prisma/cli', 'prisma'].includes(pkg.name)) {
return pkgPath.replace('package.json', '')
}
} catch {}
Expand Down Expand Up @@ -68,7 +68,7 @@ async function main() {
const root = findPackageRoot(localPath)

process.env.PRISMA_GENERATE_IN_POSTINSTALL = root ? root : 'true'

debug({
localPath,
installedGlobally,
Expand Down Expand Up @@ -148,7 +148,7 @@ Please uninstall it with either ${c.green('npm remove -g prisma')} or ${c.green(
}
}

if (!process.env.SKIP_GENERATE) {
if (!process.env.PRISMA_SKIP_POSTINSTALL_GENERATE) {
main()
.catch((e) => {
if (e.stderr) {
Expand Down
@@ -1,5 +1,5 @@
// Prevent postinstall script from running
process.env.SKIP_GENERATE = 'true'
process.env.PRISMA_SKIP_POSTINSTALL_GENERATE = 'true'

import {
getPostInstallTrigger,
Expand Down
2 changes: 1 addition & 1 deletion src/packages/migrate/src/__tests__/DbPush.test.ts
@@ -1,5 +1,5 @@
process.env.GITHUB_ACTIONS = '1'
process.env.MIGRATE_SKIP_GENERATE = '1'
process.env.PRISMA_MIGRATE_SKIP_GENERATE = '1'

import prompt from 'prompts'
import { DbPush } from '../commands/DbPush'
Expand Down
2 changes: 1 addition & 1 deletion src/packages/migrate/src/__tests__/MigrateDev.test.ts
Expand Up @@ -13,7 +13,7 @@ import {
const ctx = Context.new().add(consoleContext()).assemble()

process.env.GITHUB_ACTIONS = '1'
process.env.MIGRATE_SKIP_GENERATE = '1'
process.env.PRISMA_MIGRATE_SKIP_GENERATE = '1'

describe('common', () => {
it('wrong flag', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/migrate/src/__tests__/MigrateReset.test.ts
@@ -1,4 +1,4 @@
process.env.MIGRATE_SKIP_GENERATE = '1'
process.env.PRISMA_MIGRATE_SKIP_GENERATE = '1'
process.env.GITHUB_ACTIONS = '1'

import prompt from 'prompts'
Expand Down
2 changes: 1 addition & 1 deletion src/packages/migrate/src/commands/DbPush.ts
Expand Up @@ -255,7 +255,7 @@ ${chalk.bold.redBright('All data will be lost.')}
}

// Run if not skipped
if (!process.env.MIGRATE_SKIP_GENERATE && !args['--skip-generate']) {
if (!process.env.PRISMA_MIGRATE_SKIP_GENERATE && !args['--skip-generate']) {
await migrate.tryToRunGenerate()
}

Expand Down
4 changes: 2 additions & 2 deletions src/packages/migrate/src/commands/MigrateDev.ts
Expand Up @@ -190,7 +190,7 @@ ${chalk.bold('Examples')}
// If database was reset we want to run the seed if not skipped
if (
devDiagnostic.action.tag === 'reset' &&
!process.env.MIGRATE_SKIP_SEED &&
!process.env.PRISMA_MIGRATE_SKIP_SEED &&
!args['--skip-seed']
) {
// Run seed if 1 or more seed files are present
Expand Down Expand Up @@ -293,7 +293,7 @@ ${chalk.green('Your database is now in sync with your schema.')}`,
}

// Run if not skipped
if (!process.env.MIGRATE_SKIP_GENERATE && !args['--skip-generate']) {
if (!process.env.PRISMA_MIGRATE_SKIP_GENERATE && !args['--skip-generate']) {
await migrate.tryToRunGenerate()
console.info() // empty line
}
Expand Down
4 changes: 2 additions & 2 deletions src/packages/migrate/src/commands/MigrateReset.ts
Expand Up @@ -159,12 +159,12 @@ The following migration(s) have been applied:\n\n${chalk(
}

// Run if not skipped
if (!process.env.MIGRATE_SKIP_GENERATE && !args['--skip-generate']) {
if (!process.env.PRISMA_MIGRATE_SKIP_GENERATE && !args['--skip-generate']) {
await migrate.tryToRunGenerate()
}

// Run if not skipped
if (!process.env.MIGRATE_SKIP_SEED && !args['--skip-seed']) {
if (!process.env.PRISMA_MIGRATE_SKIP_SEED && !args['--skip-seed']) {
// Run seed if 1 or more seed files are present
const detected = detectSeedFiles(schemaPath)
if (detected.numberOfSeedFiles > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/sdk/src/predefinedGeneratorResolvers.ts
Expand Up @@ -126,7 +126,7 @@ async function installPackage(baseDir: string, pkg: string): Promise<void> {
cwd: baseDir,
stdio: 'inherit',
env: {
SKIP_GENERATE: 'true',
PRISMA_SKIP_POSTINSTALL_GENERATE: 'true',
},
})
}
Expand Down
Expand Up @@ -9,7 +9,7 @@ import { getTestClient } from '@prisma/client/dist/utils/getTestClient'

process.setMaxListeners(200)

process.env.SKIP_GENERATE = 'true'
process.env.PRISMA_SKIP_POSTINSTALL_GENERATE = 'true'

const engine = new IntrospectionEngine()

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/ci/all.ts
Expand Up @@ -14,7 +14,7 @@ async function run(cwd: string, cmd: string): Promise<void> {
shell: true,
env: {
...process.env,
SKIP_GENERATE: 'true',
PRISMA_SKIP_POSTINSTALL_GENERATE: 'true',
},
})
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/ci/publish.ts
Expand Up @@ -149,7 +149,7 @@ async function run(
shell: true,
env: {
...process.env,
SKIP_GENERATE: 'true',
PRISMA_SKIP_POSTINSTALL_GENERATE: 'true',
},
})
} catch (e) {
Expand Down

0 comments on commit 2621ae3

Please sign in to comment.