1
0
mirror of synced 2025-12-19 18:11:23 -05:00

fix blitz generate Windows Error: spawn prisma ENOENT (patch) (#1979)

This commit is contained in:
Brandon Bayer
2021-02-20 15:09:06 -05:00
committed by GitHub
parent 177c2b0519
commit 87c4ee058c
11 changed files with 200 additions and 49 deletions

View File

@@ -77,7 +77,6 @@
"@types/passport": "1.0.5",
"@types/pluralize": "0.0.29",
"@types/prettier": "2.1.6",
"@types/npm-run": "5.0.0",
"@types/pump": "1.1.0",
"@types/pumpify": "1.4.1",
"@types/react": "17.0.0",

View File

@@ -13,6 +13,6 @@
"noEmit": false,
"lib": ["dom", "dom.iterable", "ES2018"]
},
"include": ["src/**/*", "types"],
"include": ["src/**/*", "types", "../../types"],
"exclude": ["node_modules"]
}

View File

@@ -49,7 +49,8 @@
"htmlescape": "^1.1.1",
"lodash": "^4.17.20",
"lodash-es": "^4.17.20",
"npm-run": "^5.0.1",
"npm-which": "^3.0.1",
"cross-spawn": "7.0.3",
"passport": "0.4.1",
"react-query": "2.5.12",
"secure-password": "4.0.0",

View File

@@ -1,4 +1,5 @@
import {exec} from "npm-run"
import {spawn} from "cross-spawn"
import which from "npm-which"
interface Constructor<T = unknown> {
new (...args: never[]): T
@@ -33,15 +34,15 @@ export const enhancePrisma = <TPrismaClientCtor extends Constructor>(
"You are calling db.$reset() in a production environment. We think you probably didn't mean to do that, so we are throwing this error instead of destroying your life's work.",
)
}
await new Promise<void>((res, rej) =>
exec("prisma migrate reset --force --skip-generate --preview-feature", function (err) {
if (err) {
rej(err)
} else {
res()
}
}),
)
const prismaBin = which(process.cwd()).sync("prisma")
await new Promise((res, rej) => {
const process = spawn(
prismaBin,
["migrate", "reset", "--force", "--skip-generate", "--preview-feature"],
{stdio: "inherit"},
)
process.on("exit", (code) => (code === 0 ? res(0) : rej(code)))
})
global._blitz_prismaClient.$disconnect()
}

View File

@@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "types", "test"],
"include": ["src", "types", "test", "../../types"],
"exclude": ["node_modules"],
"compilerOptions": {
"baseUrl": "./",

View File

@@ -48,7 +48,7 @@
"jscodeshift": "0.11.0",
"mem-fs": "1.2.0",
"mem-fs-editor": "8.0.0",
"npm-run": "^5.0.1",
"npm-which": "^3.0.1",
"pluralize": "^8.0.0",
"recast": "0.20.4",
"username": "^5.1.0",

View File

@@ -1,5 +1,6 @@
import {log} from "@blitzjs/display"
import {spawn} from "npm-run"
import {spawn} from "cross-spawn"
import which from "npm-which"
import path from "path"
import {Generator, GeneratorOptions} from "../generator"
import {Field} from "../prisma/field"
@@ -91,7 +92,8 @@ export class ModelGenerator extends Generator<ModelGeneratorOptions> {
const shouldMigrate = await this.prismaMigratePrompt()
if (shouldMigrate) {
await new Promise<void>((res, rej) => {
const child = spawn("prisma", ["migrate", "dev", "--preview-feature"], {stdio: "inherit"})
const prismaBin = which(process.cwd()).sync("prisma")
const child = spawn(prismaBin, ["migrate", "dev", "--preview-feature"], {stdio: "inherit"})
child.on("exit", (code) => (code === 0 ? res() : rej()))
})
}

View File

@@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "test"],
"include": ["src", "test", "../../types"],
"exclude": ["node_modules"],
"compilerOptions": {
"baseUrl": "./",

View File

@@ -40,7 +40,8 @@ export function withBlitz(nextConfig: any) {
/node_modules[\\/]passport/,
/node_modules[\\/]cookie-session/,
/node_modules[\\/]secure-password/,
/node_modules[\\/]npm-run/,
/node_modules[\\/]npm-which/,
/node_modules[\\/]cross-spawn/,
/node_modules[\\/]node-libs-browser/,
/node_modules[\\/]crypto-browserify/,
]

176
types/npm-which.d.ts vendored Normal file
View File

@@ -0,0 +1,176 @@
// Type definitions for npm-which 3.0
// Project: https://github.com/timoxley/npm-which
// Definitions by: Manuel Thalmann <https://github.com/manuth>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "npm-which" {
/**
* Provides options for the `npmwhich`-module.
*/
interface NpmWhichOptions {
/**
* The environment to use for resolving the binary.
*/
env?: NodeJS.ProcessEnv
/**
* The directory to find the binary for.
*/
cwd?: string
}
/**
* Provides options for the `npmwhich`-module.
*/
interface StaticWhichOptions {
/**
* The environment to use for resolving the binary.
*/
env?: NodeJS.ProcessEnv
/**
* The directory to find the binary for.
*/
cwd: string
}
/**
* Represents a callback for handling the result of `NpmWhich`.
*/
interface NpmWhichCallback {
/**
* Handles the result of `NpmWhich`.
*
* @param error
* The error-message.
*
* @param result
* The result.
*/
(error: string, result: string): void
}
/**
* Represents a basic interface for `npm-which`.
*/
interface WhichBase<TOptions> {
/**
* Creates a searcher for the specified command.
*
* @param cmd
* The command to look for.
*
* @param options
* The default options.
*
* @return
* A searcher for the specified command.
*/
(cmd: string, options?: TOptions): InnerWhich
/**
* Searches for the specified command.
*
* @param cmd
* The command to look for.
*
* @param callback
* A callback for handling the result.
*/
(cmd: string, callback: NpmWhichCallback): void
/**
* Searches for the specified command.
*
* @param cmd
* The command to look for.
*
* @param options
* The options for searching the command.
*
* @param callback
* A callback for handling the result.
*/
(cmd: string, options: TOptions, callback: NpmWhichCallback): void
}
/**
* Represents the static instance of `npm-which`.
*/
interface StaticWhich extends WhichBase<StaticWhichOptions> {
/**
* Initializes an `NpmWhich`-instance for the specified working-directory.
*
* @param cwd
* The working-directory to browse.
*/
(cwd?: string): NpmWhich
/**
* Searches for the specified command.
*
* @param cmd
* The command to look for.
*
* @param options
* The options for searching the command.
*/
sync(cmd: string, options: StaticWhichOptions): string
}
/**
* Provides the functionality to search for a command.
*/
interface NpmWhich extends WhichBase<NpmWhichOptions> {
/**
* Searches for the specified command.
*
* @param cmd
* The command to look for.
*
* @param options
* The options for searching the command.
*/
sync(cmd: string, options?: StaticWhichOptions): string
}
interface InnerWhich {
/**
* Creates a searcher for the specified command.
*
* @param options
* The options for searching the command.
*/
(options?: NpmWhichOptions): InnerWhich
/**
* Searches for the command.
*
* @param callback
* A callback for handling the result.
*/
(callback: NpmWhichCallback): void
/**
* Searches for the command.
*
* @param options
* The options for searching the command.
*
* @param callback
* A callback for handling the result.
*/
(options: NpmWhichOptions, callback: NpmWhichCallback): void
/**
* Searches for the command.
*
* @param options
* The options for searching the command.
*/
sync(options?: NpmWhichOptions): string
}
let npmWhich: StaticWhich
export = npmWhich
}

View File

@@ -3428,13 +3428,6 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==
"@types/npm-run@5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@types/npm-run/-/npm-run-5.0.0.tgz#e2cf7bb4f5215c65ca14d286ccf0f176e951cb45"
integrity sha512-SbRnR2S0/CL9GW5mKng/V9T3uEPFSkGC5a71AcyCnT1ltK/kSv1A0nSO8AYI3FjuE4ep04HPi6eCuXWpnwD5HQ==
dependencies:
"@types/node" "*"
"@types/oauth@*":
version "0.9.1"
resolved "https://registry.yarnpkg.com/@types/oauth/-/oauth-0.9.1.tgz#e17221e7f7936b0459ae7d006255dff61adca305"
@@ -13896,7 +13889,7 @@ npm-packlist@^1.1.6, npm-packlist@^1.4.1, npm-packlist@^1.4.4:
npm-bundled "^1.0.1"
npm-normalize-package-bin "^1.0.1"
npm-path@^2.0.2, npm-path@^2.0.4:
npm-path@^2.0.2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/npm-path/-/npm-path-2.0.4.tgz#c641347a5ff9d6a09e4d9bce5580c4f505278e64"
integrity sha512-IFsj0R9C7ZdR5cP+ET342q77uSRdtWOlWpih5eC+lu29tIDbNEgDbzgVJ5UFvYHWhxDZ5TFkJafFioO0pPQjCw==
@@ -13941,16 +13934,6 @@ npm-run-path@^4.0.0, npm-run-path@^4.0.1:
dependencies:
path-key "^3.0.0"
npm-run@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/npm-run/-/npm-run-5.0.1.tgz#1baea93389b50ae25a32382c8ca322398e50cd16"
integrity sha512-s7FyRpHUgaJfzkRgOnevX8rAWWsv1dofY1XS7hliWCF6LSQh+HtDfBvpigPS1krLvXw+Fi17CYMY8mUtblnyWw==
dependencies:
minimist "^1.2.0"
npm-path "^2.0.4"
npm-which "^3.0.1"
serializerr "^1.0.3"
npm-which@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/npm-which/-/npm-which-3.0.1.tgz#9225f26ec3a285c209cae67c3b11a6b4ab7140aa"
@@ -15547,11 +15530,6 @@ proto-list@~1.2.1:
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=
protochain@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/protochain/-/protochain-1.0.5.tgz#991c407e99de264aadf8f81504b5e7faf7bfa260"
integrity sha1-mRxAfpneJkqt+PgVBLXn+ve/omA=
protocols@^1.1.0, protocols@^1.4.0:
version "1.4.8"
resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.8.tgz#48eea2d8f58d9644a4a32caae5d5db290a075ce8"
@@ -17027,13 +17005,6 @@ serialize-javascript@^4.0.0:
dependencies:
randombytes "^2.1.0"
serializerr@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/serializerr/-/serializerr-1.0.3.tgz#12d4c5aa1c3ffb8f6d1dc5f395aa9455569c3f91"
integrity sha1-EtTFqhw/+49tHcXzlaqUVVacP5E=
dependencies:
protochain "^1.0.5"
set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"