Skip to content

Commit 7e5c13d

Browse files
committed
refactor: replace execa with tinyexec
No dependencies, windows support, not trying to recreate shell.
1 parent b2a844a commit 7e5c13d

File tree

7 files changed

+39
-118
lines changed

7 files changed

+39
-118
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
"change-case": "^5.4.4",
4343
"deepmerge": "^4.3.1",
4444
"env-paths": "^3.0.0",
45-
"execa": "^7.2.0",
4645
"p-limit": "^4.0.0",
4746
"parse5": "7.1.2",
4847
"picocolors": "^1.1.0",
4948
"strip-indent": "^4.0.0",
49+
"tinyexec": "^0.3.1",
5050
"yargs": "^17.7.2",
5151
"zod": "^3.22.4"
5252
},

packages/cli/src/commands/init-flow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { chdir, cwd } from "node:process";
22
import { join } from "node:path";
33
import pc from "picocolors";
4+
import { x } from "tinyexec";
45
import {
56
cancel,
67
confirm,
@@ -10,7 +11,6 @@ import {
1011
spinner,
1112
text,
1213
} from "@clack/prompts";
13-
import { $ } from "execa";
1414
import { createFolderIfNotExists, isFileExists } from "../fs-utils";
1515
import { PROJECT_TEMPLATES } from "../config";
1616
import { link, validateShareLink } from "./link";
@@ -112,7 +112,7 @@ export const initFlow = async (
112112
if (shouldInstallDeps === true) {
113113
const install = spinner();
114114
install.start("Installing dependencies");
115-
await $`npm install`;
115+
await x("npm", ["install"]);
116116
install.stop("Installed dependencies");
117117
}
118118

packages/prisma-client/migrations-cli/cli.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Commands:
1414
create-schema <name> — Create a migration based on the changes in schema.prisma
1515
create-data <name> — Create a migration that will change data rather than schema
1616
migrate — Apply all pending migrations
17-
reset — Clear the database and apply all migrations
1817
status — Information about the state of the migrations
1918
pending-count — Get the number of pending migrations
2019
resolve <applied|rolled-back> <name> — Mark a failed migration as applied or rolled-back
@@ -102,11 +101,6 @@ const main = async () => {
102101
return;
103102
}
104103

105-
if (command === "reset") {
106-
await commands.reset();
107-
return;
108-
}
109-
110104
throw new UserError(`Unknown command: ${command}`);
111105
};
112106

packages/prisma-client/migrations-cli/commands.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,3 @@ export const resolve = async ({
346346
logger.info(`Resolved ${migrationName} as rolled back`);
347347
logger.info("");
348348
};
349-
350-
export const reset = async () => {
351-
// Just to make it read the migrations folder
352-
// and fail early if something is wrong with it.
353-
await getStatus();
354-
355-
logger.info("You're about to DELETE ALL INFORMATION from the database,");
356-
logger.info("and run all migrations from scratch!");
357-
logger.info("");
358-
359-
await prismaMigrations.resetDatabase();
360-
await up();
361-
};

packages/prisma-client/migrations-cli/prisma-migrations.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// We want to preserve semantics of the migrations folder and the _prisma_migrations table.
33
// https://github.com/prisma/prisma-engines/blob/4.3.0/migration-engine/ARCHITECTURE.md
44

5-
import { $ } from "execa";
65
import path from "node:path";
76
import fs from "node:fs";
87
import { fileURLToPath } from "node:url";
98
import { createHash } from "node:crypto";
9+
import { x } from "tinyexec";
1010
import { createPrisma } from "../src/prisma";
1111
import { UserError } from "./errors";
1212
import { PrismaClient } from "../src/__generated__";
@@ -248,32 +248,33 @@ export const generateMigrationName = (baseName: string) => {
248248
return `${prefix}_${baseName}`.slice(0, 254);
249249
};
250250

251-
export const resetDatabase = async () => {
252-
const { stdout: sqlToDeleteEverything } = await $({
253-
cwd: prismaDir,
254-
})`"prisma migrate diff --from-schema-datasource ${schemaFilePath} --to-empty --script`;
255-
256-
await $({
257-
input: sqlToDeleteEverything,
258-
cwd: prismaDir,
259-
})`prisma db execute --stdin --schema ${schemaFilePath}`;
260-
261-
await context.prisma.$executeRaw`DROP TABLE IF EXISTS _prisma_migrations`;
262-
};
263-
264251
// https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-diff
265252
export const cliDiff = async () => {
266-
const { stdout } = await $({
267-
cwd: prismaDir,
268-
})`prisma migrate diff --from-schema-datasource ${schemaFilePath} --to-schema-datamodel ${schemaFilePath} --script`;
253+
const { stdout } = await x(
254+
"prisma",
255+
[
256+
"migrate",
257+
"diff",
258+
`--from-schema-datasource=${schemaFilePath}`,
259+
`--to-schema-datamodel=${schemaFilePath}`,
260+
"--script",
261+
],
262+
{
263+
nodeOptions: { cwd: prismaDir },
264+
}
265+
);
269266
return stdout;
270267
};
271268

272269
// https://www.prisma.io/docs/reference/api-reference/command-reference#db-execute
273270
export const cliExecute = async (filePath: string) => {
274-
await $({
275-
cwd: prismaDir,
276-
})`prisma db execute --file ${filePath} --schema ${schemaFilePath}`;
271+
await x(
272+
"prisma",
273+
["db", "execute", `--file=${filePath}`, `--schema=${schemaFilePath}`],
274+
{
275+
nodeOptions: { cwd: prismaDir },
276+
}
277+
);
277278
};
278279

279280
export const generateMigrationClient = async (migrationName: string) => {
@@ -297,7 +298,7 @@ export const generateMigrationClient = async (migrationName: string) => {
297298
}
298299

299300
// https://www.prisma.io/docs/reference/api-reference/command-reference#generate
300-
await $({
301-
cwd: prismaDir,
302-
})`prisma generate --schema ${schemaPath}`;
301+
await x("prisma", ["generate", `--schema=${schemaPath}`], {
302+
nodeOptions: { cwd: prismaDir },
303+
});
303304
};

packages/prisma-client/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"license": "AGPL-3.0-or-later",
2626
"private": true,
2727
"dependencies": {
28-
"execa": "^7.2.0",
29-
"nanoid": "^5.0.1",
28+
"tinyexec": "^0.3.1",
3029
"umzug": "^3.2.1"
3130
},
3231
"peerDependencies": {

pnpm-lock.yaml

Lines changed: 11 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)