create-prisma 0.4.2-pr.34.109.1 → 0.4.2-pr.34.112.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import "./create-dRPbnGmA.mjs";
2
+ import "./create-D7XYRH3T.mjs";
3
3
  import { createCreatePrismaCli } from "./index.mjs";
4
4
 
5
5
  //#region src/cli.ts
@@ -1706,7 +1706,9 @@ async function executeCreateAddonSetupContext(params) {
1706
1706
 
1707
1707
  //#endregion
1708
1708
  //#region src/tasks/deploy-to-compute.ts
1709
- const PRISMA_CLI_PACKAGE = "@prisma/cli@dev";
1709
+ const PRISMA_CLI_PACKAGE = "@prisma/cli@latest";
1710
+ const COMPUTE_DEPLOY_BRANCH = "main";
1711
+ const COMPUTE_ENV_ROLE = "production";
1710
1712
  const DEPLOY_OPTIONS_BY_TEMPLATE = {
1711
1713
  hono: {
1712
1714
  framework: "hono",
@@ -1720,12 +1722,15 @@ const DEPLOY_OPTIONS_BY_TEMPLATE = {
1720
1722
  "tanstack-start": { framework: "tanstack-start" }
1721
1723
  };
1722
1724
  function getPrismaCliCommand(packageManager) {
1723
- return getPackageExecutionCommand(packageManager, [PRISMA_CLI_PACKAGE]);
1725
+ return getPackageExecutionCommand(getPrismaCliExecutionPackageManager(packageManager), [PRISMA_CLI_PACKAGE]);
1724
1726
  }
1725
1727
  function runPrismaCli(packageManager, args, options = {}) {
1726
- const execution = getPackageExecutionArgs(packageManager, [PRISMA_CLI_PACKAGE, ...args]);
1728
+ const execution = getPackageExecutionArgs(getPrismaCliExecutionPackageManager(packageManager), [PRISMA_CLI_PACKAGE, ...args]);
1727
1729
  return execa(execution.command, execution.args, options);
1728
1730
  }
1731
+ function getPrismaCliExecutionPackageManager(packageManager) {
1732
+ return packageManager === "deno" ? "npm" : packageManager;
1733
+ }
1729
1734
  async function isAuthenticated(packageManager) {
1730
1735
  try {
1731
1736
  await runPrismaCli(packageManager, [
@@ -1752,85 +1757,6 @@ async function ensurePrismaCliAvailable(packageManager) {
1752
1757
  return false;
1753
1758
  }
1754
1759
  }
1755
- async function fetchProjects(packageManager) {
1756
- const { stdout } = await runPrismaCli(packageManager, [
1757
- "project",
1758
- "list",
1759
- "--json"
1760
- ], { stdio: "pipe" });
1761
- const parsed = parseProjectListJson(stdout);
1762
- if (!parsed) throw new Error("Failed to list Prisma projects: invalid command output");
1763
- if (!parsed.ok) throw new Error(getJsonErrorMessage(parsed.error, "Failed to list Prisma projects"));
1764
- return parsed.result.items.map((project) => ({
1765
- id: project.id,
1766
- name: project.name
1767
- }));
1768
- }
1769
- function parseProjectListJson(stdout) {
1770
- if (typeof stdout !== "string" || stdout.trim().length === 0) return null;
1771
- try {
1772
- return JSON.parse(stdout);
1773
- } catch {
1774
- return null;
1775
- }
1776
- }
1777
- async function promptForNewProjectName(defaultProjectName) {
1778
- const projectNameInput = await text({
1779
- message: "Prisma project name",
1780
- placeholder: defaultProjectName,
1781
- initialValue: defaultProjectName,
1782
- validate: (value) => {
1783
- if (!value || value.trim().length === 0) return "Project name is required";
1784
- }
1785
- });
1786
- if (isCancel(projectNameInput)) {
1787
- cancel("Operation cancelled.");
1788
- return;
1789
- }
1790
- return projectNameInput.trim();
1791
- }
1792
- async function promptForNewProjectTarget(defaultProjectName) {
1793
- const projectName = await promptForNewProjectName(defaultProjectName);
1794
- return projectName ? { createProjectName: projectName } : void 0;
1795
- }
1796
- async function collectProjectTarget(options) {
1797
- const projects = await fetchProjects(options.packageManager);
1798
- if (projects.length === 1) {
1799
- const only = projects[0];
1800
- const shouldUseExistingProject = await confirm({
1801
- message: `Use Prisma project ${only.name}?`,
1802
- initialValue: true
1803
- });
1804
- if (isCancel(shouldUseExistingProject)) {
1805
- cancel("Operation cancelled.");
1806
- return;
1807
- }
1808
- return shouldUseExistingProject ? { projectRef: only.id } : promptForNewProjectTarget(options.defaultProjectName);
1809
- }
1810
- if (projects.length > 1) {
1811
- const selection = await select({
1812
- message: "Select Prisma project",
1813
- options: [{
1814
- value: { type: "create" },
1815
- label: "Create new project"
1816
- }, ...projects.slice().sort((a, b) => a.name.localeCompare(b.name)).map((project) => ({
1817
- value: {
1818
- type: "existing",
1819
- project
1820
- },
1821
- label: project.name,
1822
- hint: project.id
1823
- }))]
1824
- });
1825
- if (isCancel(selection)) {
1826
- cancel("Operation cancelled.");
1827
- return;
1828
- }
1829
- return selection.type === "create" ? promptForNewProjectTarget(options.defaultProjectName) : { projectRef: selection.project.id };
1830
- }
1831
- log.info("No Prisma projects found.");
1832
- return promptForNewProjectTarget(options.defaultProjectName);
1833
- }
1834
1760
  async function collectComputeDeployContext(input, options) {
1835
1761
  if (!isComputeDeployableTemplate(options.template)) return null;
1836
1762
  if (input.deploy === false) return null;
@@ -1863,43 +1789,15 @@ async function collectComputeDeployContext(input, options) {
1863
1789
  return null;
1864
1790
  }
1865
1791
  }
1866
- let projectTarget;
1867
- try {
1868
- projectTarget = await collectProjectTarget({
1869
- packageManager: options.packageManager,
1870
- defaultProjectName: options.defaultServiceName
1871
- });
1872
- } catch (error) {
1873
- log.warn(`Could not list Prisma projects${error instanceof Error ? `: ${redactSecrets(error.message)}` : "."}`);
1874
- if (input.deploy === true) throw createExplicitDeployError("could not list Prisma projects", error);
1875
- return null;
1876
- }
1877
- if (!projectTarget) {
1878
- if (input.deploy === true) throw createExplicitDeployError("no Prisma project was selected or created");
1879
- return null;
1880
- }
1881
- const appNameInput = await text({
1882
- message: "App name",
1883
- placeholder: options.defaultServiceName,
1884
- initialValue: options.defaultServiceName,
1885
- validate: (value) => {
1886
- if (!value || value.trim().length === 0) return "App name is required";
1887
- }
1888
- });
1889
- if (isCancel(appNameInput)) {
1890
- cancel("Operation cancelled.");
1891
- return;
1892
- }
1893
1792
  const deployOptions = DEPLOY_OPTIONS_BY_TEMPLATE[options.template];
1894
1793
  if (!deployOptions) {
1895
1794
  if (input.deploy === true) throw createExplicitDeployError(`${options.template} is not supported by prisma app deploy yet`);
1896
1795
  return null;
1897
1796
  }
1898
1797
  return {
1899
- ...projectTarget,
1900
1798
  template: options.template,
1901
1799
  packageManager: options.packageManager,
1902
- appName: appNameInput.trim(),
1800
+ createProjectName: options.defaultServiceName,
1903
1801
  framework: deployOptions.framework,
1904
1802
  httpPort: deployOptions.httpPort
1905
1803
  };
@@ -1908,6 +1806,15 @@ function redactSecrets(message) {
1908
1806
  return message.replace(/(['"])([A-Z0-9_]*(?:DATABASE_URL|DIRECT_URL|TOKEN|SECRET|PASSWORD|API_KEY|PRIVATE_KEY|ACCESS_KEY)[A-Z0-9_]*=)(.*?)\1/g, "$1$2<redacted>$1").replace(/\b([A-Z0-9_]*(?:DATABASE_URL|DIRECT_URL|TOKEN|SECRET|PASSWORD|API_KEY|PRIVATE_KEY|ACCESS_KEY)[A-Z0-9_]*=)[^\s]+/g, "$1<redacted>");
1909
1807
  }
1910
1808
  function parseDeployJson(stdout) {
1809
+ return parsePrismaCliJson(stdout);
1810
+ }
1811
+ function parseProjectCreateJson(stdout) {
1812
+ return parsePrismaCliJson(stdout);
1813
+ }
1814
+ function parseProjectEnvJson(stdout) {
1815
+ return parsePrismaCliJson(stdout);
1816
+ }
1817
+ function parsePrismaCliJson(stdout) {
1911
1818
  if (typeof stdout !== "string" || stdout.trim().length === 0) return null;
1912
1819
  try {
1913
1820
  return JSON.parse(stdout);
@@ -1939,29 +1846,95 @@ function toComputeDeployResult(data) {
1939
1846
  branchName: data.result.branch.name
1940
1847
  };
1941
1848
  }
1849
+ async function createComputeProjectForDeploy(params) {
1850
+ const { stdout, exitCode } = await runPrismaCli(params.context.packageManager, [
1851
+ "project",
1852
+ "create",
1853
+ params.context.createProjectName,
1854
+ "--json",
1855
+ "--yes"
1856
+ ], {
1857
+ cwd: params.projectDir,
1858
+ reject: false,
1859
+ stdio: [
1860
+ "ignore",
1861
+ "pipe",
1862
+ "pipe"
1863
+ ]
1864
+ });
1865
+ const parsed = parseProjectCreateJson(stdout);
1866
+ if (!parsed) throw new Error("Could not parse prisma project create output.");
1867
+ if (exitCode !== 0 || !parsed.ok) throw createDeployError(parsed.ok ? "Prisma project create failed." : getJsonErrorMessage(parsed.error, "Prisma project create failed."));
1868
+ return parsed.result.project.id;
1869
+ }
1870
+ async function writeComputeEnvironmentVariables(params) {
1871
+ for (const [key, value] of Object.entries(params.envVars ?? {})) {
1872
+ const commonArgs = [
1873
+ `${key}=${value}`,
1874
+ "--project",
1875
+ params.projectRef,
1876
+ "--role",
1877
+ COMPUTE_ENV_ROLE,
1878
+ "--json",
1879
+ "--yes"
1880
+ ];
1881
+ if ((await runProjectEnvCommand(params.context, params.projectDir, ["add", ...commonArgs])).ok) continue;
1882
+ const updateResult = await runProjectEnvCommand(params.context, params.projectDir, ["update", ...commonArgs]);
1883
+ if (!updateResult.ok) throw createDeployError(getJsonErrorMessage(updateResult.error, `Failed to configure ${key} for Prisma Compute.`));
1884
+ }
1885
+ }
1886
+ async function runProjectEnvCommand(context, projectDir, args) {
1887
+ const { stdout, exitCode } = await runPrismaCli(context.packageManager, [
1888
+ "project",
1889
+ "env",
1890
+ ...args
1891
+ ], {
1892
+ cwd: projectDir,
1893
+ reject: false,
1894
+ stdio: [
1895
+ "ignore",
1896
+ "pipe",
1897
+ "pipe"
1898
+ ]
1899
+ });
1900
+ const parsed = parseProjectEnvJson(stdout);
1901
+ if (!parsed) throw new Error("Could not parse prisma project env output.");
1902
+ if (exitCode !== 0 && parsed.ok) return {
1903
+ ok: false,
1904
+ error: { message: "Prisma project env command failed." }
1905
+ };
1906
+ return parsed;
1907
+ }
1942
1908
  async function executeComputeDeployContext(params) {
1909
+ const deploySpinner = spinner();
1910
+ deploySpinner.start("Deploying to Prisma Compute...");
1911
+ const envVars = params.envVars ?? {};
1912
+ const shouldPreconfigureEnvVars = Object.keys(envVars).length > 0;
1943
1913
  const args = [
1944
1914
  "app",
1945
1915
  "deploy",
1946
1916
  "--json",
1947
1917
  "--yes",
1948
- "--app",
1949
- params.context.appName,
1950
1918
  "--framework",
1951
- params.context.framework
1919
+ params.context.framework,
1920
+ "--branch",
1921
+ COMPUTE_DEPLOY_BRANCH
1952
1922
  ];
1953
- if (params.context.projectRef) args.push("--project", params.context.projectRef);
1954
- else if (params.context.createProjectName) args.push("--create-project", params.context.createProjectName);
1955
- else return {
1956
- ok: false,
1957
- cancelled: false,
1958
- error: /* @__PURE__ */ new Error("Deploy target is missing a Prisma project.")
1959
- };
1960
- if (params.context.httpPort) args.push("--http-port", String(params.context.httpPort));
1961
- for (const [key, value] of Object.entries(params.envVars ?? {})) args.push("--env", `${key}=${value}`);
1962
- const deploySpinner = spinner();
1963
- deploySpinner.start("Deploying to Prisma Compute...");
1964
1923
  try {
1924
+ if (shouldPreconfigureEnvVars) {
1925
+ const projectRef = await createComputeProjectForDeploy({
1926
+ context: params.context,
1927
+ projectDir: params.projectDir
1928
+ });
1929
+ await writeComputeEnvironmentVariables({
1930
+ context: params.context,
1931
+ projectDir: params.projectDir,
1932
+ projectRef,
1933
+ envVars
1934
+ });
1935
+ args.push("--project", projectRef);
1936
+ } else args.push("--create-project", params.context.createProjectName);
1937
+ if (params.context.httpPort) args.push("--http-port", String(params.context.httpPort));
1965
1938
  const { stdout, exitCode } = await runPrismaCli(params.context.packageManager, args, {
1966
1939
  cwd: params.projectDir,
1967
1940
  reject: false,
@@ -2051,7 +2024,7 @@ async function getAnonymousId() {
2051
2024
  }
2052
2025
  function getCommonProperties() {
2053
2026
  return {
2054
- "cli-version": "0.4.2-pr.34.109.1",
2027
+ "cli-version": "0.4.2-pr.34.112.1",
2055
2028
  "node-version": process.version,
2056
2029
  platform: process.platform,
2057
2030
  arch: process.arch
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { a as DatabaseUrlSchema, i as DatabaseProviderSchema, n as CreateCommandInputSchema, o as PackageManagerSchema, r as CreateTemplateSchema, s as SchemaPresetSchema, t as runCreateCommand } from "./create-dRPbnGmA.mjs";
2
+ import { a as DatabaseUrlSchema, i as DatabaseProviderSchema, n as CreateCommandInputSchema, o as PackageManagerSchema, r as CreateTemplateSchema, s as SchemaPresetSchema, t as runCreateCommand } from "./create-D7XYRH3T.mjs";
3
3
  import { os } from "@orpc/server";
4
4
  import { createCli } from "trpc-cli";
5
5
 
6
6
  //#region src/index.ts
7
- const CLI_VERSION = "0.4.2-pr.34.109.1";
7
+ const CLI_VERSION = "0.4.2-pr.34.112.1";
8
8
  const router = os.router({ create: os.meta({
9
9
  description: "Create a new project with Prisma setup",
10
10
  default: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma",
3
- "version": "0.4.2-pr.34.109.1",
3
+ "version": "0.4.2-pr.34.112.1",
4
4
  "private": false,
5
5
  "description": "Create Prisma 7 projects with first-party templates and great DX.",
6
6
  "homepage": "https://github.com/prisma/create-prisma",