@stackframe/init-stack 2.8.35 → 2.8.39

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/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @stackframe/init-stack
2
2
 
3
+ ## 2.8.39
4
+
5
+ ### Patch Changes
6
+
7
+ - Various changes
8
+ - Updated dependencies
9
+ - @stackframe/stack-shared@2.8.39
10
+
11
+ ## 2.8.38
12
+
13
+ ### Patch Changes
14
+
15
+ - Various changes
16
+ - Updated dependencies
17
+ - @stackframe/stack-shared@2.8.38
18
+
19
+ ## 2.8.37
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+ - @stackframe/stack-shared@2.8.37
25
+
26
+ ## 2.8.36
27
+
28
+ ### Patch Changes
29
+
30
+ - Various changes
31
+ - Updated dependencies
32
+ - @stackframe/stack-shared@2.8.36
33
+
3
34
  ## 2.8.35
4
35
 
5
36
  ### Patch Changes
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import { PostHog } from "posthog-node";
14
14
  // package.json
15
15
  var package_default = {
16
16
  name: "@stackframe/init-stack",
17
- version: "2.8.35",
17
+ version: "2.8.39",
18
18
  description: "The setup wizard for Stack. https://stack-auth.com",
19
19
  main: "dist/index.js",
20
20
  type: "module",
@@ -26,19 +26,23 @@ var package_default = {
26
26
  lint: "eslint --ext .tsx,.ts .",
27
27
  typecheck: "tsc --noEmit",
28
28
  "init-stack": "node dist/index.js",
29
- "init-stack:local": "STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE=../../stack STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE=../../js node dist/index.js",
29
+ "init-stack:local": "STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE=../../stack STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE=../../js STACK_REACT_INSTALL_PACKAGE_NAME_OVERRIDE=../../react node dist/index.js",
30
30
  "test-run": "pnpm run build && pnpm run test-run-js && pnpm run test-run-node && pnpm run test-run-next && pnpm run test-run-neon && pnpm run test-run-no-browser",
31
31
  "test-run:manual": "pnpm run build && pnpm run test-run-js:manual && pnpm run test-run-node:manual && pnpm run test-run-next:manual && pnpm run test-run-neon:manual",
32
32
  "ensure-neon": `grep -q '"@neondatabase/serverless"' ./test-run-output/package.json && echo 'Initialized Neon successfully!'`,
33
33
  "test-run-neon": "pnpm run test-run-node --neon && pnpm run ensure-neon",
34
34
  "test-run-neon:manual": "pnpm run test-run-node:manual --neon && pnpm run ensure-neon",
35
- "test-run-no-browser": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --server --npm --no-browser",
35
+ "test-run-no-browser": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --agent-mode --js --server --npm --no-browser",
36
36
  "test-run-node:manual": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init && cd .. && pnpm run init-stack:local test-run-output",
37
- "test-run-node": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --server --npm",
37
+ "test-run-node": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --agent-mode --js --server --npm --no-browser",
38
38
  "test-run-js:manual": "rimraf test-run-output && npx -y sv create test-run-output --no-install && pnpm run init-stack:local test-run-output",
39
- "test-run-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --client --npm",
39
+ "test-run-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --agent-mode --js --client --npm --no-browser",
40
40
  "test-run-next:manual": "rimraf test-run-output && npx -y create-next-app@latest test-run-output && pnpm run init-stack:local test-run-output",
41
- "test-run-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output"
41
+ "test-run-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --agent-mode --no-browser",
42
+ "test-run-keys-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --agent-mode --project-id my-project-id --publishable-client-key my-publishable-client-key",
43
+ "test-run-keys-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --agent-mode --js --client --npm --project-id my-project-id --publishable-client-key my-publishable-client-key",
44
+ "test-run-react": "rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --agent-mode --no-browser --npm",
45
+ "test-run-react:manual": "rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --react"
42
46
  },
43
47
  files: [
44
48
  "README.md",
@@ -82,17 +86,20 @@ var jsLikeFileExtensions = [
82
86
  "js"
83
87
  ];
84
88
  var program = new Command();
85
- program.name(package_default.name).description("Stack Auth Initialization Tool").version(package_default.version).argument("[project-path]", "Path to your project").usage(`[project-path] [options]`).option("--dry-run", "Run without making any changes").option("--neon", "Use Neon database").option("--js", "Initialize for JavaScript project").option("--next", "Initialize for Next.js project").option("--npm", "Use npm as package manager").option("--yarn", "Use yarn as package manager").option("--pnpm", "Use pnpm as package manager").option("--bun", "Use bun as package manager").option("--client", "Initialize client-side only").option("--server", "Initialize server-side only").option("--no-browser", "Don't open browser for environment variable setup").addHelpText("after", `
89
+ program.name(package_default.name).description("Stack Auth Initialization Tool").version(package_default.version).argument("[project-path]", "Path to your project").usage(`[project-path] [options]`).option("--dry-run", "Run without making any changes").option("--neon", "Use Neon database").option("--js", "Initialize for JavaScript project").option("--next", "Initialize for Next.js project").option("--react", "Initialize for React project").option("--npm", "Use npm as package manager").option("--yarn", "Use yarn as package manager").option("--pnpm", "Use pnpm as package manager").option("--bun", "Use bun as package manager").option("--client", "Initialize client-side only").option("--server", "Initialize server-side only").option("--project-id <project-id>", "Project ID to use in setup").option("--publishable-client-key <publishable-client-key>", "Publishable client key to use in setup").option("--no-browser", "Don't open browser for environment variable setup").option("--agent-mode", "Run without prompting for any input").addHelpText("after", `
86
90
  For more information, please visit https://docs.stack-auth.com/getting-started/setup`);
87
91
  program.parse();
88
92
  var options = program.opts();
89
93
  var savedProjectPath = program.args[0] || void 0;
90
94
  var isDryRun = options.dryRun || false;
91
95
  var isNeon = options.neon || false;
92
- var typeFromArgs = options.js ? "js" : options.next ? "next" : void 0;
96
+ var typeFromArgs = options.js ? "js" : options.next ? "next" : options.react ? "react" : void 0;
93
97
  var packageManagerFromArgs = options.npm ? "npm" : options.yarn ? "yarn" : options.pnpm ? "pnpm" : options.bun ? "bun" : void 0;
94
98
  var isClient = options.client || false;
95
99
  var isServer = options.server || false;
100
+ var projectIdFromArgs = options.projectId;
101
+ var publishableClientKeyFromArgs = options.publishableClientKey;
102
+ var agentMode = !!options.agentMode;
96
103
  var noBrowser = !options.browser;
97
104
  var UserError = class extends Error {
98
105
  constructor(message) {
@@ -183,11 +190,25 @@ async function main() {
183
190
  if (type === "next") {
184
191
  const projectInfo = await Steps.getNextProjectInfo({ packageJson: projectPackageJson });
185
192
  await Steps.updateNextLayoutFile(projectInfo);
193
+ await Steps.writeStackAppFile(projectInfo, "client");
186
194
  await Steps.writeStackAppFile(projectInfo, "server");
187
195
  await Steps.writeNextHandlerFile(projectInfo);
188
196
  await Steps.writeNextLoadingFile(projectInfo);
189
197
  nextSteps.push(`Copy the environment variables from the new API key into your .env.local file`);
190
- } else if (type === "js") {
198
+ } else if (type === "react") {
199
+ const defaultExtension = await Steps.guessDefaultFileExtension();
200
+ const srcPath = await Steps.guessSrcPath();
201
+ const hasReactRouterDom = !!(projectPackageJson.dependencies?.["react-router-dom"] || projectPackageJson.devDependencies?.["react-router-dom"]);
202
+ const { fileName } = await Steps.writeReactClientFile({
203
+ srcPath,
204
+ defaultExtension,
205
+ indentation: " ",
206
+ hasReactRouterDom
207
+ });
208
+ nextSteps.push(
209
+ `Copy the environment variables from the new API key into your own environment and reference them in ${fileName}`
210
+ );
211
+ } else {
191
212
  const defaultExtension = await Steps.guessDefaultFileExtension();
192
213
  const where = await Steps.getServerOrClientOrBoth();
193
214
  const srcPath = await Steps.guessSrcPath();
@@ -205,8 +226,6 @@ async function main() {
205
226
  `Copy the environment variables from the new API key into your own environment and reference them in ${appFiles.join(" and ")}`,
206
227
  `Follow the instructions on how to use Stack Auth's vanilla SDK at http://docs.stack-auth.com/others/js-client`
207
228
  );
208
- } else {
209
- throw new Error("Unknown type: " + type);
210
229
  }
211
230
  const { packageManager } = await Steps.getPackageManager();
212
231
  await capture(`package-manager-selected`, {
@@ -216,8 +235,15 @@ async function main() {
216
235
  await Steps.ensureReady(type);
217
236
  console.log();
218
237
  console.log(colorize.bold`Installing dependencies...`);
219
- const installCommand = packageManager === "yarn" ? "yarn add" : `${packageManager} install`;
220
- await shellNicelyFormatted(`${installCommand} ${packagesToInstall.join(" ")}`, {
238
+ const installCommandMap = /* @__PURE__ */ new Map([
239
+ ["npm", "npm install"],
240
+ ["yarn", "yarn add"],
241
+ ["pnpm", "pnpm add"],
242
+ ["bun", "bun add"]
243
+ ]);
244
+ const installCommand = installCommandMap.get(packageManager) ?? `${packageManager} install`;
245
+ const safePackages = packagesToInstall.map((p) => JSON.stringify(p));
246
+ await shellNicelyFormatted(`${installCommand} ${safePackages.join(" ")}`, {
221
247
  shell: true,
222
248
  cwd: projectPath
223
249
  });
@@ -274,7 +300,7 @@ ${colorize.bold`Next steps:`}
274
300
 
275
301
  For more information, please visit https://docs.stack-auth.com/getting-started/setup
276
302
  `.trim());
277
- if (!process.env.STACK_DISABLE_INTERACTIVE && !noBrowser) {
303
+ if (!noBrowser) {
278
304
  await open(`https://app.stack-auth.com/wizard-congrats?stack-init-id=${encodeURIComponent(distinctId)}`);
279
305
  }
280
306
  await ph_client.shutdown();
@@ -337,7 +363,15 @@ var Steps = {
337
363
  async getProjectType({ packageJson }) {
338
364
  if (typeFromArgs) return typeFromArgs;
339
365
  const maybeNextProject = await Steps.maybeGetNextProjectInfo({ packageJson });
340
- if (!("error" in maybeNextProject)) return "next";
366
+ if (!("error" in maybeNextProject)) {
367
+ return "next";
368
+ }
369
+ if (packageJson.dependencies?.["react"] || packageJson.dependencies?.["react-dom"]) {
370
+ return "react";
371
+ }
372
+ if (agentMode) {
373
+ return "js";
374
+ }
341
375
  const { type } = await inquirer.prompt([
342
376
  {
343
377
  type: "list",
@@ -345,6 +379,7 @@ var Steps = {
345
379
  message: "Which integration would you like to install?",
346
380
  choices: [
347
381
  { name: "None (vanilla JS, Node.js, etc)", value: "js" },
382
+ { name: "React", value: "react" },
348
383
  { name: "Next.js", value: "next" }
349
384
  ]
350
385
  }
@@ -352,10 +387,12 @@ var Steps = {
352
387
  return type;
353
388
  },
354
389
  async getStackPackageName(type, install = false) {
355
- return {
356
- "js": install && process.env.STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE || "@stackframe/js",
357
- "next": install && process.env.STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE || "@stackframe/stack"
358
- }[type] ?? throwErr("Unknown type in addStackPackage: " + type);
390
+ const mapping = {
391
+ js: install && process.env.STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE || "@stackframe/js",
392
+ next: install && process.env.STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE || "@stackframe/stack",
393
+ react: install && process.env.STACK_REACT_INSTALL_PACKAGE_NAME_OVERRIDE || "@stackframe/react"
394
+ };
395
+ return mapping[type];
359
396
  },
360
397
  async addStackPackage(type) {
361
398
  packagesToInstall.push(await Steps.getStackPackageName(type, true));
@@ -412,7 +449,20 @@ Only Next.js 14 & 15 projects are currently supported. See Next's upgrade guide:
412
449
  envLocalPath
413
450
  ];
414
451
  if (potentialEnvLocations.every((p) => !fs.existsSync(p))) {
415
- const envContent = noBrowser ? "# Stack Auth keys\n# To get these variables:\n# 1. Go to https://app.stack-auth.com\n# 2. Create a new project\n# 3. Copy the keys below\nNEXT_PUBLIC_STACK_PROJECT_ID=\nNEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=\nSTACK_SECRET_SERVER_KEY=\n" : "# Stack Auth keys\n# Get these variables by creating a project on https://app.stack-auth.com.\nNEXT_PUBLIC_STACK_PROJECT_ID=\nNEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=\nSTACK_SECRET_SERVER_KEY=\n";
452
+ const envContent = noBrowser ? `# Stack Auth keys
453
+ # To get these variables:
454
+ # 1. Go to https://app.stack-auth.com
455
+ # 2. Create a new project
456
+ # 3. Copy the keys below
457
+ NEXT_PUBLIC_STACK_PROJECT_ID="${projectIdFromArgs ?? ""}"
458
+ NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY="${publishableClientKeyFromArgs ?? ""}"
459
+ STACK_SECRET_SERVER_KEY=
460
+ ` : `# Stack Auth keys
461
+ # Get these variables by creating a project on https://app.stack-auth.com.
462
+ NEXT_PUBLIC_STACK_PROJECT_ID="${projectIdFromArgs ?? ""}"
463
+ NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY="${publishableClientKeyFromArgs ?? ""}"
464
+ STACK_SECRET_SERVER_KEY=
465
+ `;
416
466
  laterWriteFile(envLocalPath, envContent);
417
467
  return true;
418
468
  }
@@ -446,11 +496,8 @@ Only Next.js 14 & 15 projects are currently supported. See Next's upgrade guide:
446
496
  const clientOrServerCap = {
447
497
  client: "Client",
448
498
  server: "Server"
449
- }[clientOrServer] ?? throwErr("unknown clientOrServer " + clientOrServer);
450
- const relativeStackAppPath = {
451
- js: `stack/${clientOrServer}`,
452
- next: "stack"
453
- }[type] ?? throwErr("unknown type");
499
+ }[clientOrServer];
500
+ const relativeStackAppPath = `stack/${clientOrServer}`;
454
501
  const stackAppPathWithoutExtension = path.join(srcPath, relativeStackAppPath);
455
502
  const stackAppFileExtension = await findJsExtension(stackAppPathWithoutExtension) ?? defaultExtension;
456
503
  const stackAppPath = stackAppPathWithoutExtension + "." + stackAppFileExtension;
@@ -458,31 +505,73 @@ Only Next.js 14 & 15 projects are currently supported. See Next's upgrade guide:
458
505
  if (stackAppContent) {
459
506
  if (!stackAppContent.includes("@stackframe/")) {
460
507
  throw new UserError(
461
- `A file at the path ${stackAppPath} already exists. Stack uses the stack.ts file to initialize the Stack SDK. Please remove the existing file and try again.`
508
+ `A file at the path ${stackAppPath} already exists. Stack uses the stack/${clientOrServer}.ts file to initialize the Stack SDK. Please remove the existing file and try again.`
462
509
  );
463
510
  }
464
511
  throw new UserError(
465
512
  `It seems that you already installed Stack in this project.`
466
513
  );
467
514
  }
515
+ const tokenStore = type === "next" ? '"nextjs-cookie"' : clientOrServer === "client" ? '"cookie"' : '"memory"';
516
+ const publishableClientKeyWrite = clientOrServer === "server" ? `process.env.STACK_PUBLISHABLE_CLIENT_KEY ${publishableClientKeyFromArgs ? `|| '${publishableClientKeyFromArgs}'` : ""}` : `'${publishableClientKeyFromArgs ?? "INSERT_YOUR_PUBLISHABLE_CLIENT_KEY_HERE"}'`;
517
+ const jsOptions = type === "js" ? [
518
+ `
519
+
520
+ ${indentation}// get your Stack Auth API keys from https://app.stack-auth.com${clientOrServer === "client" ? ` and store them in a safe place (eg. environment variables)` : ""}`,
521
+ `${projectIdFromArgs ? `${indentation}projectId: '${projectIdFromArgs}',` : ""}`,
522
+ `${indentation}publishableClientKey: ${publishableClientKeyWrite},`,
523
+ `${clientOrServer === "server" ? `${indentation}secretServerKey: process.env.STACK_SECRET_SERVER_KEY,` : ""}`
524
+ ].filter(Boolean).join("\n") : "";
468
525
  laterWriteFileIfNotExists(
469
526
  stackAppPath,
470
527
  `
471
- ${type === "next" ? `import "server-only";` : ""}
528
+ ${type === "next" && clientOrServer === "server" ? `import "server-only";` : ""}
472
529
 
473
530
  import { Stack${clientOrServerCap}App } from ${JSON.stringify(packageName)};
474
531
 
475
532
  export const stack${clientOrServerCap}App = new Stack${clientOrServerCap}App({
476
- ${indentation}tokenStore: ${type === "next" ? '"nextjs-cookie"' : clientOrServer === "client" ? '"cookie"' : '"memory"'},${type === "js" ? `
477
-
478
- ${indentation}// get your Stack Auth API keys from https://app.stack-auth.com${clientOrServer === "client" ? ` and store them in a safe place (eg. environment variables)` : ""}` : ""}${type === "js" ? `
479
- ${indentation}publishableClientKey: ${clientOrServer === "server" ? "process.env.STACK_PUBLISHABLE_CLIENT_KEY" : "INSERT_YOUR_PUBLISHABLE_CLIENT_KEY_HERE"},` : ""}${type === "js" && clientOrServer === "server" ? `
480
- ${indentation}secretServerKey: process.env.STACK_SECRET_SERVER_KEY,` : ""}
533
+ ${indentation}tokenStore: ${tokenStore},${jsOptions}
481
534
  });
482
535
  `.trim() + "\n"
483
536
  );
484
537
  return { fileName: stackAppPath };
485
538
  },
539
+ async writeReactClientFile({ srcPath, defaultExtension, indentation, hasReactRouterDom }) {
540
+ const packageName = await Steps.getStackPackageName("react");
541
+ const relativeStackAppPath = `stack/client`;
542
+ const stackAppPathWithoutExtension = path.join(srcPath, relativeStackAppPath);
543
+ const stackAppFileExtension = await findJsExtension(stackAppPathWithoutExtension) ?? defaultExtension;
544
+ const stackAppPath = stackAppPathWithoutExtension + "." + stackAppFileExtension;
545
+ const stackAppContent = await readFile(stackAppPath);
546
+ if (stackAppContent) {
547
+ if (!stackAppContent.includes("@stackframe/")) {
548
+ throw new UserError(`A file at the path ${stackAppPath} already exists. Stack uses the stack/client.ts file to initialize the Stack SDK. Please remove the existing file and try again.`);
549
+ }
550
+ throw new UserError(`It seems that you already installed Stack in this project.`);
551
+ }
552
+ const publishableClientKeyWrite = `'${publishableClientKeyFromArgs ?? "INSERT_YOUR_PUBLISHABLE_CLIENT_KEY_HERE"}'`;
553
+ const projectIdWrite = `'${projectIdFromArgs ?? "INSERT_PROJECT_ID"}'`;
554
+ const imports = hasReactRouterDom ? `import { StackClientApp } from ${JSON.stringify(packageName)};
555
+ import { useNavigate } from "react-router-dom";
556
+
557
+ ` : `import { StackClientApp } from ${JSON.stringify(packageName)};
558
+
559
+ `;
560
+ const redirectMethod = hasReactRouterDom ? `,
561
+ ${indentation}redirectMethod: {
562
+ ${indentation}${indentation}useNavigate,
563
+ ${indentation}}` : "";
564
+ laterWriteFileIfNotExists(
565
+ stackAppPath,
566
+ `${imports}export const stackClientApp = new StackClientApp({
567
+ ${indentation}tokenStore: "cookie",
568
+ ${indentation}projectId: ${projectIdWrite},
569
+ ${indentation}publishableClientKey: ${publishableClientKeyWrite}${redirectMethod},
570
+ });
571
+ `
572
+ );
573
+ return { fileName: stackAppPath };
574
+ },
486
575
  async writeNextHandlerFile(projectInfo) {
487
576
  const handlerPathWithoutExtension = path.join(
488
577
  projectInfo.appPath,
@@ -493,17 +582,17 @@ ${indentation}secretServerKey: process.env.STACK_SECRET_SERVER_KEY,` : ""}
493
582
  const handlerContent = await readFile(handlerPath);
494
583
  if (handlerContent && !handlerContent.includes("@stackframe/")) {
495
584
  throw new UserError(
496
- `A file at the path ${handlerPath} already exists. Stack uses the /handler path to handle incoming requests. Please remove the existing file and try again.`
585
+ `A file at the path ${handlerPath} already exists.Stack uses the / handler path to handle incoming requests.Please remove the existing file and try again.`
497
586
  );
498
587
  }
499
588
  laterWriteFileIfNotExists(
500
589
  handlerPath,
501
- `import { StackHandler } from "@stackframe/stack";
502
- import { stackServerApp } from "../../../stack";
590
+ `import { StackHandler } from "@stackframe/stack";
591
+ import { stackServerApp } from "../../../stack/server";
503
592
 
504
- export default function Handler(props${handlerFileExtension.includes("ts") ? ": unknown" : ""}) {
505
- ${projectInfo.indentation}return <StackHandler fullPage app={stackServerApp} routeProps={props} />;
506
- }
593
+ export default function Handler(props${handlerFileExtension.includes("ts") ? ": unknown" : ""}) {
594
+ ${projectInfo.indentation} return <StackHandler fullPage app = { stackServerApp } routeProps = { props } />;
595
+ }
507
596
  `
508
597
  );
509
598
  },
@@ -514,6 +603,7 @@ ${projectInfo.indentation}return <StackHandler fullPage app={stackServerApp} rou
514
603
  laterWriteFileIfNotExists(
515
604
  loadingPath,
516
605
  `export default function Loading() {
606
+
517
607
  ${projectInfo.indentation}// Stack uses React Suspense, which will render this page while user data is being fetched.
518
608
  ${projectInfo.indentation}// See: https://nextjs.org/docs/app/api-reference/file-conventions/loading
519
609
  ${projectInfo.indentation}return <></>;
@@ -537,11 +627,13 @@ ${projectInfo.indentation}return <></>;
537
627
  },
538
628
  async ensureReady(type) {
539
629
  const projectPath = await getProjectPath();
540
- const typeString = {
630
+ const typeStringMap = {
541
631
  js: "JavaScript",
542
- next: "Next.js"
543
- }[type] ?? throwErr("unknown type");
544
- const isReady = !!process.env.STACK_DISABLE_INTERACTIVE || (await inquirer.prompt([
632
+ next: "Next.js",
633
+ react: "React"
634
+ };
635
+ const typeString = typeStringMap[type];
636
+ const isReady = agentMode || (await inquirer.prompt([
545
637
  {
546
638
  type: "confirm",
547
639
  name: "ready",
@@ -557,6 +649,9 @@ ${projectInfo.indentation}return <></>;
557
649
  if (isClient && isServer) return ["server", "client"];
558
650
  if (isServer) return ["server"];
559
651
  if (isClient) return ["client"];
652
+ if (agentMode) {
653
+ throw new UserError("Please specify the installation type using the --server or --client argument.");
654
+ }
560
655
  return (await inquirer.prompt([{
561
656
  type: "list",
562
657
  name: "type",
@@ -598,7 +693,7 @@ async function getUpdatedLayout(originalLayout) {
598
693
  const importInsertLocationM1 = firstImportLocationM1 ?? (hasStringAsFirstLine ? layout.indexOf("\n") : -1);
599
694
  const importInsertLocation = importInsertLocationM1 + 1;
600
695
  const importStatement = `import { StackProvider, StackTheme } from "@stackframe/stack";
601
- import { stackServerApp } from "../stack";
696
+ import { stackServerApp } from "../stack/server";
602
697
  `;
603
698
  layout = layout.slice(0, importInsertLocation) + importStatement + layout.slice(importInsertLocation);
604
699
  const bodyOpenTag = /<\s*body[^>]*>/.exec(layout);
@@ -660,6 +755,9 @@ async function getProjectPath() {
660
755
  path.join(savedProjectPath, "package.json")
661
756
  );
662
757
  if (askForPathModification) {
758
+ if (agentMode) {
759
+ throw new UserError(`No package.json file found in the project directory ${savedProjectPath}. Please specify the correct project path using the --project-path argument, or create a new project before running the wizard.`);
760
+ }
663
761
  savedProjectPath = (await inquirer.prompt([
664
762
  {
665
763
  type: "input",
@@ -696,6 +794,9 @@ async function promptPackageManager() {
696
794
  } else if (!yarnLock && !pnpmLock && !npmLock && bunLock) {
697
795
  return "bun";
698
796
  }
797
+ if (agentMode) {
798
+ throw new UserError("Unable to determine which package manager to use. Please rerun the init command and specify the package manager using exactly one of the following arguments: --npm, --yarn, --pnpm, or --bun.");
799
+ }
699
800
  const answers = await inquirer.prompt([
700
801
  {
701
802
  type: "list",
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../package.json"],"sourcesContent":["import * as child_process from \"child_process\";\nimport { Command } from \"commander\";\nimport * as crypto from 'crypto';\nimport * as fs from \"fs\";\nimport inquirer from \"inquirer\";\nimport open from \"open\";\nimport * as os from 'os';\nimport * as path from \"path\";\nimport { PostHog } from 'posthog-node';\nimport packageJson from '../package.json';\n\nconst jsLikeFileExtensions: string[] = [\n \"mtsx\",\n \"ctsx\",\n \"tsx\",\n \"mts\",\n \"cts\",\n \"ts\",\n \"mjsx\",\n \"cjsx\",\n \"jsx\",\n \"mjs\",\n \"cjs\",\n \"js\",\n];\n\n// Setup command line parsing\nconst program = new Command();\nprogram\n .name(packageJson.name)\n .description(\"Stack Auth Initialization Tool\")\n .version(packageJson.version)\n .argument(\"[project-path]\", \"Path to your project\")\n .usage(`[project-path] [options]`)\n .option(\"--dry-run\", \"Run without making any changes\")\n .option(\"--neon\", \"Use Neon database\")\n .option(\"--js\", \"Initialize for JavaScript project\")\n .option(\"--next\", \"Initialize for Next.js project\")\n .option(\"--npm\", \"Use npm as package manager\")\n .option(\"--yarn\", \"Use yarn as package manager\")\n .option(\"--pnpm\", \"Use pnpm as package manager\")\n .option(\"--bun\", \"Use bun as package manager\")\n .option(\"--client\", \"Initialize client-side only\")\n .option(\"--server\", \"Initialize server-side only\")\n .option(\"--no-browser\", \"Don't open browser for environment variable setup\")\n .addHelpText('after', `\nFor more information, please visit https://docs.stack-auth.com/getting-started/setup`);\n\nprogram.parse();\n\nconst options = program.opts();\n\n// Keep existing variables but assign from Commander\nlet savedProjectPath: string | undefined = program.args[0] || undefined;\nconst isDryRun: boolean = options.dryRun || false;\nconst isNeon: boolean = options.neon || false;\nconst typeFromArgs: string | undefined = options.js ? \"js\" : options.next ? \"next\" : undefined;\nconst packageManagerFromArgs: string | undefined = options.npm ? \"npm\" : options.yarn ? \"yarn\" : options.pnpm ? \"pnpm\" : options.bun ? \"bun\" : undefined;\nconst isClient: boolean = options.client || false;\nconst isServer: boolean = options.server || false;\n// Commander negates the boolean options with prefix `--no-`\n// so `--no-browser` becomes `browser: false`\nconst noBrowser: boolean = !options.browser;\n\nclass UserError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"UserError\";\n }\n}\n\ntype Ansis = {\n red: string,\n blue: string,\n green: string,\n yellow: string,\n clear: string,\n bold: string,\n};\n\nconst ansis: Ansis = {\n red: \"\\x1b[31m\",\n blue: \"\\x1b[34m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n\n clear: \"\\x1b[0m\",\n bold: \"\\x1b[1m\",\n};\n\ntype TemplateFunction = (strings: TemplateStringsArray, ...values: any[]) => string;\n\ntype Colorize = {\n red: TemplateFunction,\n blue: TemplateFunction,\n green: TemplateFunction,\n yellow: TemplateFunction,\n bold: TemplateFunction,\n};\n\nconst colorize: Colorize = {\n red: (strings, ...values) => ansis.red + templateIdentity(strings, ...values) + ansis.clear,\n blue: (strings, ...values) => ansis.blue + templateIdentity(strings, ...values) + ansis.clear,\n green: (strings, ...values) => ansis.green + templateIdentity(strings, ...values) + ansis.clear,\n yellow: (strings, ...values) => ansis.yellow + templateIdentity(strings, ...values) + ansis.clear,\n bold: (strings, ...values) => ansis.bold + templateIdentity(strings, ...values) + ansis.clear,\n};\n\nconst filesCreated: string[] = [];\nconst filesModified: string[] = [];\nconst commandsExecuted: string[] = [];\n\nconst packagesToInstall: string[] = [];\nconst writeFileHandlers: Array<() => Promise<void>> = [];\nconst nextSteps: string[] = [\n `Create an account and Stack Auth API key for your project on https://app.stack-auth.com`,\n];\n\n\nconst STACK_AUTH_PUBLIC_HOG_KEY = \"phc_vIUFi0HzHo7oV26OsaZbUASqxvs8qOmap1UBYAutU4k\";\nconst EVENT_PREFIX = \"stack-init-\";\nconst ph_client = new PostHog(STACK_AUTH_PUBLIC_HOG_KEY, {\n host: \"https://eu.i.posthog.com\",\n flushAt: 1,\n flushInterval: 0,\n});\nconst distinctId = crypto.randomUUID();\n\n\nasync function capture(event: string, properties: Record<string, any>) {\n ph_client.capture({\n event: `${EVENT_PREFIX}${event}`,\n distinctId,\n properties,\n });\n}\n\n\nasync function main(): Promise<void> {\n // Welcome message\n console.log();\n console.log(`\n ██████\n ██████████████\n████████████████████\n████████████████████ WELCOME TO\n█████████████████ ╔═╗╔╦╗╔═╗╔═╗╦╔═ ┌─┐┬ ┬┌┬┐┬ ┬\n█████████████ ╚═╗ ║ ╠═╣║ ╠╩╗ ├─┤│ │ │ ├─┤\n█████████████ ████ ╚═╝ ╩ ╩ ╩╚═╝╩ ╩ ┴ ┴└─┘ ┴ ┴ ┴\n █████████████████\n ██████ ██\n████ ████\n █████ █████\n ██████\n `);\n console.log();\n\n await capture(\"start\", {\n version: packageJson.version,\n isDryRun,\n isNeon,\n typeFromArgs,\n packageManagerFromArgs,\n isClient,\n isServer,\n noBrowser,\n platform: os.platform(),\n arch: os.arch(),\n nodeVersion: process.version,\n });\n\n // Wait just briefly so we can use `Steps` in here (it's defined only after the call to `main()`)\n await new Promise<void>((resolve) => resolve());\n\n\n // Prepare some stuff\n await clearStdin();\n const projectPath = await getProjectPath();\n\n\n // Steps\n const { packageJson: projectPackageJson } = await Steps.getProject();\n const type = await Steps.getProjectType({ packageJson: projectPackageJson });\n\n await capture(\"project-type-selected\", {\n type,\n wasSpecifiedInArgs: !!typeFromArgs,\n });\n\n await Steps.addStackPackage(type);\n if (isNeon) packagesToInstall.push('@neondatabase/serverless');\n\n await Steps.writeEnvVars(type);\n\n if (type === \"next\") {\n const projectInfo = await Steps.getNextProjectInfo({ packageJson: projectPackageJson });\n await Steps.updateNextLayoutFile(projectInfo);\n await Steps.writeStackAppFile(projectInfo, \"server\");\n await Steps.writeNextHandlerFile(projectInfo);\n await Steps.writeNextLoadingFile(projectInfo);\n nextSteps.push(`Copy the environment variables from the new API key into your .env.local file`);\n } else if (type === \"js\") {\n const defaultExtension = await Steps.guessDefaultFileExtension();\n const where = await Steps.getServerOrClientOrBoth();\n const srcPath = await Steps.guessSrcPath();\n const appFiles: string[] = [];\n for (const w of where) {\n const { fileName } = await Steps.writeStackAppFile({\n type,\n defaultExtension,\n indentation: \" \",\n srcPath,\n }, w);\n appFiles.push(fileName);\n }\n nextSteps.push(\n `Copy the environment variables from the new API key into your own environment and reference them in ${appFiles.join(\" and \")}`,\n `Follow the instructions on how to use Stack Auth's vanilla SDK at http://docs.stack-auth.com/others/js-client`,\n );\n } else {\n throw new Error(\"Unknown type: \" + type);\n }\n\n const { packageManager } = await Steps.getPackageManager();\n\n await capture(`package-manager-selected`, {\n packageManager,\n wasSpecifiedInArgs: !!packageManagerFromArgs,\n });\n\n await Steps.ensureReady(type);\n\n\n // Install dependencies\n console.log();\n console.log(colorize.bold`Installing dependencies...`);\n const installCommand = packageManager === \"yarn\" ? \"yarn add\" : `${packageManager} install`;\n await shellNicelyFormatted(`${installCommand} ${packagesToInstall.join(' ')}`, {\n shell: true,\n cwd: projectPath,\n });\n\n await capture(`dependencies-installed`, {\n packageManager,\n packages: packagesToInstall,\n });\n\n // Write files\n console.log();\n console.log(colorize.bold`Writing files...`);\n console.log();\n for (const writeFileHandler of writeFileHandlers) {\n await writeFileHandler();\n }\n console.log(`${colorize.green`√`} Done writing files`);\n\n console.log('\\n\\n\\n');\n console.log(colorize.bold`${colorize.green`Installation succeeded!`}`);\n console.log();\n console.log(\"Commands executed:\");\n for (const command of commandsExecuted) {\n console.log(` ${colorize.blue`${command}`}`);\n }\n console.log();\n console.log(\"Files written:\");\n for (const file of filesModified) {\n console.log(` ${colorize.yellow`${file}`}`);\n }\n for (const file of filesCreated) {\n console.log(` ${colorize.green`${file}`}`);\n }\n console.log();\n\n await capture(\"complete\", {\n success: true,\n type,\n packageManager,\n isNeon,\n isClient,\n isServer,\n noBrowser,\n filesCreated,\n filesModified,\n commandsExecuted,\n });\n\n // Success!\n console.log(`\n${colorize.green`===============================================`}\n\n${colorize.green`Successfully installed Stack! 🚀🚀🚀`}\n\n${colorize.bold`Next steps:`}\n\n1. ${noBrowser ?\n `Create a project at https://app.stack-auth.com and get your API keys` :\n `Complete the setup in your browser to get your API keys`}\n2. Add the API keys to your .env.local file\n3. Import the Stack components in your app\n4. Add authentication to your app\n\nFor more information, please visit https://docs.stack-auth.com/getting-started/setup\n `.trim());\n if (!process.env.STACK_DISABLE_INTERACTIVE && !noBrowser) {\n await open(`https://app.stack-auth.com/wizard-congrats?stack-init-id=${encodeURIComponent(distinctId)}`);\n }\n await ph_client.shutdown();\n}\n\n// eslint-disable-next-line no-restricted-syntax\nmain().catch(async (err) => {\n try {\n await capture(\"error\", {\n error: err.message,\n errorType: err instanceof UserError ? \"UserError\" : \"SystemError\",\n stack: err.stack,\n });\n } catch (e) { }\n if (!(err instanceof UserError)) {\n console.error(err);\n }\n console.error('\\n\\n\\n\\n');\n console.log(colorize.red`===============================================`);\n console.error();\n if (err instanceof UserError) {\n console.error(`${colorize.red`ERROR!`} ${err.message}`);\n } else {\n console.error(\"An error occurred during the initialization process.\");\n }\n console.error();\n console.log(colorize.red`===============================================`);\n console.error();\n console.error(\n \"If you need assistance, please try installing Stack manually as described in https://docs.stack-auth.com/getting-started/setup or join our Discord where we're happy to help: https://discord.stack-auth.com\"\n );\n if (!(err instanceof UserError)) {\n console.error(\"\");\n console.error(`Error message: ${err.message}`);\n }\n console.error();\n await ph_client.shutdown();\n process.exit(1);\n});\n\n\ntype PackageJson = {\n dependencies?: Record<string, string>,\n devDependencies?: Record<string, string>,\n [key: string]: any,\n}\n\ntype ProjectInfo = {\n type: string,\n srcPath: string,\n appPath: string,\n defaultExtension: string,\n indentation: string,\n}\n\ntype NextProjectInfoError = {\n error: string,\n}\n\ntype NextProjectInfoResult = ProjectInfo | NextProjectInfoError;\n\ntype StackAppFileOptions = {\n type: string,\n srcPath: string,\n defaultExtension: string,\n indentation: string,\n}\n\ntype StackAppFileResult = {\n fileName: string,\n}\n\nconst Steps = {\n async getProject(): Promise<{ packageJson: PackageJson }> {\n let projectPath = await getProjectPath();\n if (!fs.existsSync(projectPath)) {\n throw new UserError(`The project path ${projectPath} does not exist`);\n }\n\n const packageJsonPath = path.join(projectPath, \"package.json\");\n if (!fs.existsSync(packageJsonPath)) {\n throw new UserError(\n `The package.json file does not exist in the project path ${projectPath}. You must initialize a new project first before installing Stack.`\n );\n }\n\n const packageJsonText = fs.readFileSync(packageJsonPath, \"utf-8\");\n let packageJson: PackageJson;\n try {\n packageJson = JSON.parse(packageJsonText);\n } catch (e) {\n throw new UserError(`package.json file is not valid JSON: ${e}`);\n }\n\n return { packageJson };\n },\n\n async getProjectType({ packageJson }: { packageJson: PackageJson }): Promise<string> {\n if (typeFromArgs) return typeFromArgs;\n\n const maybeNextProject = await Steps.maybeGetNextProjectInfo({ packageJson });\n if (!(\"error\" in maybeNextProject)) return \"next\";\n\n const { type } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"type\",\n message: \"Which integration would you like to install?\",\n choices: [\n { name: \"None (vanilla JS, Node.js, etc)\", value: \"js\" },\n { name: \"Next.js\", value: \"next\" },\n ]\n }\n ]);\n\n return type;\n },\n\n async getStackPackageName(type: string, install = false): Promise<string> {\n return {\n \"js\": (install && process.env.STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE) || \"@stackframe/js\",\n \"next\": (install && process.env.STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE) || \"@stackframe/stack\",\n }[type] ?? throwErr(\"Unknown type in addStackPackage: \" + type);\n },\n\n async addStackPackage(type: string): Promise<void> {\n packagesToInstall.push(await Steps.getStackPackageName(type, true));\n },\n\n async getNextProjectInfo({ packageJson }: { packageJson: PackageJson }): Promise<ProjectInfo> {\n const maybe = await Steps.maybeGetNextProjectInfo({ packageJson });\n if (\"error\" in maybe) throw new UserError(maybe.error);\n return maybe;\n },\n\n async maybeGetNextProjectInfo({ packageJson }: { packageJson: PackageJson }): Promise<NextProjectInfoResult> {\n const projectPath = await getProjectPath();\n\n const nextVersionInPackageJson = packageJson.dependencies?.[\"next\"] ?? packageJson.devDependencies?.[\"next\"];\n if (!nextVersionInPackageJson) {\n return { error: `The project at ${projectPath} does not appear to be a Next.js project, or does not have 'next' installed as a dependency.` };\n }\n if (\n !nextVersionInPackageJson.includes(\"14\") &&\n !nextVersionInPackageJson.includes(\"15\") &&\n nextVersionInPackageJson !== \"latest\"\n ) {\n return { error: `The project at ${projectPath} is using an unsupported version of Next.js (found ${nextVersionInPackageJson}).\\n\\nOnly Next.js 14 & 15 projects are currently supported. See Next's upgrade guide: https://nextjs.org/docs/app/building-your-application/upgrading/version-14` };\n }\n\n const nextConfigPathWithoutExtension = path.join(projectPath, \"next.config\");\n const nextConfigFileExtension = await findJsExtension(\n nextConfigPathWithoutExtension\n );\n const nextConfigPath =\n nextConfigPathWithoutExtension + \".\" + (nextConfigFileExtension ?? \"js\");\n if (!fs.existsSync(nextConfigPath)) {\n return { error: `Expected file at ${nextConfigPath}. Only Next.js projects are currently supported.` };\n }\n\n const hasSrcAppFolder = fs.existsSync(path.join(projectPath, \"src/app\"));\n const srcPath = path.join(projectPath, hasSrcAppFolder ? \"src\" : \"\");\n const appPath = path.join(srcPath, \"app\");\n if (!fs.existsSync(appPath)) {\n return { error: `The app path ${appPath} does not exist. Only the Next.js app router is supported.` };\n }\n\n const dryUpdateNextLayoutFileResult = await Steps.dryUpdateNextLayoutFile({ appPath, defaultExtension: \"jsx\" });\n\n return {\n type: \"next\",\n srcPath,\n appPath,\n defaultExtension: dryUpdateNextLayoutFileResult.fileExtension,\n indentation: dryUpdateNextLayoutFileResult.indentation,\n };\n },\n\n async writeEnvVars(type: string): Promise<boolean> {\n const projectPath = await getProjectPath();\n\n // TODO: in non-Next environments, ask the user what method they prefer for envvars\n if (type !== \"next\") return false;\n\n const envLocalPath = path.join(projectPath, \".env.local\");\n\n const potentialEnvLocations = [\n path.join(projectPath, \".env\"),\n path.join(projectPath, \".env.development\"),\n path.join(projectPath, \".env.default\"),\n path.join(projectPath, \".env.defaults\"),\n path.join(projectPath, \".env.example\"),\n envLocalPath,\n ];\n if (potentialEnvLocations.every((p) => !fs.existsSync(p))) {\n const envContent = noBrowser\n ? \"# Stack Auth keys\\n\" +\n \"# To get these variables:\\n\" +\n \"# 1. Go to https://app.stack-auth.com\\n\" +\n \"# 2. Create a new project\\n\" +\n \"# 3. Copy the keys below\\n\" +\n \"NEXT_PUBLIC_STACK_PROJECT_ID=\\n\" +\n \"NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=\\n\" +\n \"STACK_SECRET_SERVER_KEY=\\n\"\n : \"# Stack Auth keys\\n\" +\n \"# Get these variables by creating a project on https://app.stack-auth.com.\\n\" +\n \"NEXT_PUBLIC_STACK_PROJECT_ID=\\n\" +\n \"NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=\\n\" +\n \"STACK_SECRET_SERVER_KEY=\\n\";\n\n laterWriteFile(envLocalPath, envContent);\n return true;\n }\n\n return false;\n },\n\n async dryUpdateNextLayoutFile({ appPath, defaultExtension }: { appPath: string, defaultExtension: string }): Promise<{\n path: string,\n updatedContent: string,\n fileExtension: string,\n indentation: string,\n }> {\n const layoutPathWithoutExtension = path.join(appPath, \"layout\");\n const layoutFileExtension =\n (await findJsExtension(layoutPathWithoutExtension)) ?? defaultExtension;\n const layoutPath = layoutPathWithoutExtension + \".\" + layoutFileExtension;\n const layoutContent =\n (await readFile(layoutPath)) ??\n throwErr(\n `The layout file at ${layoutPath} does not exist. Stack requires a layout file to be present in the /app folder.`\n );\n const updatedLayoutResult =\n (await getUpdatedLayout(layoutContent)) ??\n throwErr(\n \"Unable to parse root layout file. Make sure it contains a <body> tag. If it still doesn't work, you may need to manually install Stack. See: https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required\"\n );\n const updatedLayoutContent = updatedLayoutResult.content;\n return {\n path: layoutPath,\n updatedContent: updatedLayoutContent,\n fileExtension: layoutFileExtension,\n indentation: updatedLayoutResult.indentation\n };\n },\n\n async updateNextLayoutFile(projectInfo: ProjectInfo): Promise<{\n path: string,\n updatedContent: string,\n fileExtension: string,\n indentation: string,\n }> {\n const res = await Steps.dryUpdateNextLayoutFile(projectInfo);\n laterWriteFile(res.path, res.updatedContent);\n return res;\n },\n\n async writeStackAppFile({ type, srcPath, defaultExtension, indentation }: StackAppFileOptions, clientOrServer: string): Promise<StackAppFileResult> {\n const packageName = await Steps.getStackPackageName(type);\n\n const clientOrServerCap = {\n client: \"Client\",\n server: \"Server\",\n }[clientOrServer] ?? throwErr(\"unknown clientOrServer \" + clientOrServer);\n\n const relativeStackAppPath = {\n js: `stack/${clientOrServer}`,\n next: \"stack\",\n }[type] ?? throwErr(\"unknown type\");\n\n const stackAppPathWithoutExtension = path.join(srcPath, relativeStackAppPath);\n const stackAppFileExtension =\n (await findJsExtension(stackAppPathWithoutExtension)) ?? defaultExtension;\n const stackAppPath =\n stackAppPathWithoutExtension + \".\" + stackAppFileExtension;\n const stackAppContent = await readFile(stackAppPath);\n if (stackAppContent) {\n if (!stackAppContent.includes(\"@stackframe/\")) {\n throw new UserError(\n `A file at the path ${stackAppPath} already exists. Stack uses the stack.ts file to initialize the Stack SDK. Please remove the existing file and try again.`\n );\n }\n throw new UserError(\n `It seems that you already installed Stack in this project.`\n );\n }\n laterWriteFileIfNotExists(\n stackAppPath,\n `\n${type === \"next\" ? `import \"server-only\";` : \"\"}\n\nimport { Stack${clientOrServerCap}App } from ${JSON.stringify(packageName)};\n\nexport const stack${clientOrServerCap}App = new Stack${clientOrServerCap}App({\n${indentation}tokenStore: ${type === \"next\" ? '\"nextjs-cookie\"' : (clientOrServer === \"client\" ? '\"cookie\"' : '\"memory\"')},${\ntype === \"js\" ? `\\n\\n${indentation}// get your Stack Auth API keys from https://app.stack-auth.com${clientOrServer === \"client\" ? ` and store them in a safe place (eg. environment variables)` : \"\"}` : \"\"}${\ntype === \"js\" ? `\\n${indentation}publishableClientKey: ${clientOrServer === \"server\" ? 'process.env.STACK_PUBLISHABLE_CLIENT_KEY' : 'INSERT_YOUR_PUBLISHABLE_CLIENT_KEY_HERE'},` : \"\"}${\ntype === \"js\" && clientOrServer === \"server\" ? `\\n${indentation}secretServerKey: process.env.STACK_SECRET_SERVER_KEY,` : \"\"}\n});\n `.trim() + \"\\n\"\n );\n return { fileName: stackAppPath };\n },\n\n async writeNextHandlerFile(projectInfo: ProjectInfo): Promise<void> {\n const handlerPathWithoutExtension = path.join(\n projectInfo.appPath,\n \"handler/[...stack]/page\"\n );\n const handlerFileExtension =\n (await findJsExtension(handlerPathWithoutExtension)) ?? projectInfo.defaultExtension;\n const handlerPath = handlerPathWithoutExtension + \".\" + handlerFileExtension;\n const handlerContent = await readFile(handlerPath);\n if (handlerContent && !handlerContent.includes(\"@stackframe/\")) {\n throw new UserError(\n `A file at the path ${handlerPath} already exists. Stack uses the /handler path to handle incoming requests. Please remove the existing file and try again.`\n );\n }\n laterWriteFileIfNotExists(\n handlerPath,\n `import { StackHandler } from \"@stackframe/stack\";\\nimport { stackServerApp } from \"../../../stack\";\\n\\nexport default function Handler(props${\n handlerFileExtension.includes(\"ts\") ? \": unknown\" : \"\"\n }) {\\n${projectInfo.indentation}return <StackHandler fullPage app={stackServerApp} routeProps={props} />;\\n}\\n`\n );\n },\n\n async writeNextLoadingFile(projectInfo: ProjectInfo): Promise<void> {\n let loadingPathWithoutExtension = path.join(projectInfo.appPath, \"loading\");\n const loadingFileExtension =\n (await findJsExtension(loadingPathWithoutExtension)) ?? projectInfo.defaultExtension;\n const loadingPath = loadingPathWithoutExtension + \".\" + loadingFileExtension;\n laterWriteFileIfNotExists(\n loadingPath,\n `export default function Loading() {\\n${projectInfo.indentation}// Stack uses React Suspense, which will render this page while user data is being fetched.\\n${projectInfo.indentation}// See: https://nextjs.org/docs/app/api-reference/file-conventions/loading\\n${projectInfo.indentation}return <></>;\\n}\\n`\n );\n },\n\n async getPackageManager(): Promise<{ packageManager: string }> {\n if (packageManagerFromArgs) return { packageManager: packageManagerFromArgs };\n const packageManager = await promptPackageManager();\n const versionCommand = `${packageManager} --version`;\n\n try {\n await shellNicelyFormatted(versionCommand, { shell: true, quiet: true });\n } catch (err) {\n console.error(err);\n throw new UserError(\n `Could not run the package manager command '${versionCommand}'. Please make sure ${packageManager} is installed on your system.`\n );\n }\n\n return { packageManager };\n },\n\n async ensureReady(type: string): Promise<void> {\n const projectPath = await getProjectPath();\n\n const typeString = {\n js: \"JavaScript\",\n next: \"Next.js\"\n }[type] ?? throwErr(\"unknown type\");\n const isReady = !!process.env.STACK_DISABLE_INTERACTIVE || (await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"ready\",\n message: `Found a ${typeString} project at ${projectPath} — ready to install Stack Auth?`,\n default: true,\n },\n ])).ready;\n if (!isReady) {\n throw new UserError(\"Installation aborted.\");\n }\n },\n\n async getServerOrClientOrBoth(): Promise<string[]> {\n if (isClient && isServer) return [\"server\", \"client\"];\n if (isServer) return [\"server\"];\n if (isClient) return [\"client\"];\n\n return (await inquirer.prompt([{\n type: \"list\",\n name: \"type\",\n message: \"Do you want to use Stack Auth on the server, or on the client?\",\n choices: [\n { name: \"Client (eg. Vite, HTML)\", value: [\"client\"] },\n { name: \"Server (eg. Node.js)\", value: [\"server\"] },\n { name: \"Both\", value: [\"server\", \"client\"] }\n ]\n }])).type;\n },\n\n /**\n * note: this is a heuristic, specific frameworks may have better heuristics (eg. the Next.js code uses the extension of the global layout file)\n */\n async guessDefaultFileExtension(): Promise<string> {\n const projectPath = await getProjectPath();\n const hasTsConfig = fs.existsSync(\n path.join(projectPath, \"tsconfig.json\")\n );\n return hasTsConfig ? \"ts\" : \"js\";\n },\n\n /**\n * note: this is a heuristic, specific frameworks may have better heuristics (eg. the Next.js code uses the location of the app folder)\n */\n async guessSrcPath(): Promise<string> {\n const projectPath = await getProjectPath();\n const potentialSrcPath = path.join(projectPath, \"src\");\n const hasSrcFolder = fs.existsSync(\n path.join(projectPath, \"src\")\n );\n return hasSrcFolder ? potentialSrcPath : projectPath;\n },\n\n\n};\n\n\ntype LayoutResult = {\n content: string,\n indentation: string,\n}\n\nasync function getUpdatedLayout(originalLayout: string): Promise<LayoutResult | undefined> {\n let layout = originalLayout;\n const indentation = guessIndentation(originalLayout);\n\n const firstImportLocationM1 = /\\simport\\s/.exec(layout)?.index;\n const hasStringAsFirstLine = layout.startsWith('\"') || layout.startsWith(\"'\");\n const importInsertLocationM1 =\n firstImportLocationM1 ?? (hasStringAsFirstLine ? layout.indexOf(\"\\n\") : -1);\n const importInsertLocation = importInsertLocationM1 + 1;\n const importStatement = `import { StackProvider, StackTheme } from \"@stackframe/stack\";\\nimport { stackServerApp } from \"../stack\";\\n`;\n layout =\n layout.slice(0, importInsertLocation) +\n importStatement +\n layout.slice(importInsertLocation);\n\n const bodyOpenTag = /<\\s*body[^>]*>/.exec(layout);\n const bodyCloseTag = /<\\s*\\/\\s*body[^>]*>/.exec(layout);\n if (!bodyOpenTag || !bodyCloseTag) {\n return undefined;\n }\n const bodyOpenEndIndex = bodyOpenTag.index + bodyOpenTag[0].length;\n const bodyCloseStartIndex = bodyCloseTag.index;\n if (bodyCloseStartIndex <= bodyOpenEndIndex) {\n return undefined;\n }\n\n const lines = layout.split(\"\\n\");\n const [bodyOpenEndLine, bodyOpenEndIndexInLine] = getLineIndex(\n lines,\n bodyOpenEndIndex\n );\n const [bodyCloseStartLine, bodyCloseStartIndexInLine] = getLineIndex(\n lines,\n bodyCloseStartIndex\n );\n\n const insertOpen = \"<StackProvider app={stackServerApp}><StackTheme>\";\n const insertClose = \"</StackTheme></StackProvider>\";\n\n layout =\n layout.slice(0, bodyCloseStartIndex) +\n insertClose +\n layout.slice(bodyCloseStartIndex);\n layout =\n layout.slice(0, bodyOpenEndIndex) +\n insertOpen +\n layout.slice(bodyOpenEndIndex);\n\n return {\n content: `${layout}`,\n indentation,\n };\n}\n\nfunction guessIndentation(str: string): string {\n const lines = str.split(\"\\n\");\n const linesLeadingWhitespaces = lines\n .map((line) => line.match(/^\\s*/)![0])\n .filter((ws) => ws.length > 0);\n const isMostlyTabs =\n linesLeadingWhitespaces.filter((ws) => ws.includes(\"\\t\")).length >=\n (linesLeadingWhitespaces.length * 2) / 3;\n if (isMostlyTabs) return \"\\t\";\n const linesLeadingWhitespacesCount = linesLeadingWhitespaces.map(\n (ws) => ws.length\n );\n const min = Math.min(Infinity, ...linesLeadingWhitespacesCount);\n return Number.isFinite(min) ? \" \".repeat(Math.max(2, min)) : \" \";\n}\n\nfunction getLineIndex(lines: string[], stringIndex: number): [number, number] {\n let lineIndex = 0;\n for (let l = 0; l < lines.length; l++) {\n const line = lines[l];\n if (stringIndex < lineIndex + line.length) {\n return [l, stringIndex - lineIndex];\n }\n lineIndex += line.length + 1;\n }\n throw new Error(\n `Index ${stringIndex} is out of bounds for lines ${JSON.stringify(lines)}`\n );\n}\n\nasync function getProjectPath(): Promise<string> {\n if (savedProjectPath === undefined) {\n savedProjectPath = process.cwd();\n\n const askForPathModification = !fs.existsSync(\n path.join(savedProjectPath, \"package.json\")\n );\n if (askForPathModification) {\n savedProjectPath = (\n await inquirer.prompt([\n {\n type: \"input\",\n name: \"newPath\",\n message: \"Please enter the path to your project:\",\n default: \".\",\n },\n ])\n ).newPath;\n }\n }\n return savedProjectPath as string;\n}\n\nasync function findJsExtension(fullPathWithoutExtension: string): Promise<string | null> {\n for (const ext of jsLikeFileExtensions) {\n const fullPath = fullPathWithoutExtension + \".\" + ext;\n if (fs.existsSync(fullPath)) {\n return ext;\n }\n }\n return null;\n}\n\nasync function promptPackageManager(): Promise<string> {\n const projectPath = await getProjectPath();\n const yarnLock = fs.existsSync(path.join(projectPath, \"yarn.lock\"));\n const pnpmLock = fs.existsSync(path.join(projectPath, \"pnpm-lock.yaml\"));\n const npmLock = fs.existsSync(path.join(projectPath, \"package-lock.json\"));\n const bunLock = fs.existsSync(path.join(projectPath, \"bun.lockb\"));\n\n if (yarnLock && !pnpmLock && !npmLock && !bunLock) {\n return \"yarn\";\n } else if (!yarnLock && pnpmLock && !npmLock && !bunLock) {\n return \"pnpm\";\n } else if (!yarnLock && !pnpmLock && npmLock && !bunLock) {\n return \"npm\";\n } else if (!yarnLock && !pnpmLock && !npmLock && bunLock) {\n return \"bun\";\n }\n\n const answers = await inquirer.prompt([\n {\n type: \"list\",\n name: \"packageManager\",\n message: \"Which package manager are you using for this project?\",\n choices: [\"npm\", \"yarn\", \"pnpm\", \"bun\"],\n },\n ]);\n return answers.packageManager;\n}\n\ntype ShellOptions = {\n quiet?: boolean,\n shell?: boolean,\n cwd?: string,\n [key: string]: any,\n}\n\nasync function shellNicelyFormatted(command: string, { quiet, ...options }: ShellOptions): Promise<void> {\n let ui: any;\n let interval: NodeJS.Timeout | undefined;\n if (!quiet) {\n console.log();\n ui = new inquirer.ui.BottomBar();\n let dots = 4;\n ui.updateBottomBar(\n colorize.blue`Running command: ${command}...`\n );\n interval = setInterval(() => {\n if (!isDryRun) {\n ui.updateBottomBar(\n colorize.blue`Running command: ${command}${\".\".repeat(dots++ % 5)}`\n );\n }\n }, 700);\n }\n\n try {\n if (!isDryRun) {\n const child = child_process.spawn(command, options);\n if (!quiet) {\n child.stdout.pipe(ui.log);\n child.stderr.pipe(ui.log);\n }\n\n await new Promise<void>((resolve, reject) => {\n child.on(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n } else {\n reject(new Error(`Command ${command} failed with code ${code}`));\n }\n });\n });\n } else {\n console.log(`[DRY-RUN] Would have run: ${command}`);\n }\n\n if (!quiet) {\n commandsExecuted.push(command);\n ui.updateBottomBar(\n `${colorize.green`√`} Command ${command} succeeded\\n`\n );\n }\n } catch (e) {\n if (!quiet) {\n ui.updateBottomBar(\n `${colorize.red`X`} Command ${command} failed\\n`\n );\n }\n throw e;\n } finally {\n if (interval) {\n clearTimeout(interval);\n }\n if (!quiet) {\n ui.close();\n }\n }\n}\n\nasync function readFile(fullPath: string): Promise<string | null> {\n try {\n if (!isDryRun) {\n return fs.readFileSync(fullPath, \"utf-8\");\n }\n return null;\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n return null;\n }\n throw err;\n }\n}\n\nasync function writeFile(fullPath: string, content: string): Promise<void> {\n let create = !fs.existsSync(fullPath);\n if (!isDryRun) {\n fs.mkdirSync(path.dirname(fullPath), { recursive: true });\n fs.writeFileSync(fullPath, content);\n } else {\n console.log(`[DRY-RUN] Would have written to ${fullPath}`);\n }\n const relativeToProjectPath = path.relative(await getProjectPath(), fullPath);\n if (!create) {\n filesModified.push(relativeToProjectPath);\n } else {\n filesCreated.push(relativeToProjectPath);\n }\n}\n\nfunction laterWriteFile(fullPath: string, content: string): void {\n writeFileHandlers.push(async () => {\n await writeFile(fullPath, content);\n });\n}\n\nasync function writeFileIfNotExists(fullPath: string, content: string): Promise<void> {\n if (!fs.existsSync(fullPath)) {\n await writeFile(fullPath, content);\n }\n}\n\nfunction laterWriteFileIfNotExists(fullPath: string, content: string): void {\n writeFileHandlers.push(async () => {\n await writeFileIfNotExists(fullPath, content);\n });\n}\n\nfunction assertInteractive(): true {\n if (process.env.STACK_DISABLE_INTERACTIVE) {\n throw new UserError(\"STACK_DISABLE_INTERACTIVE is set, but wizard requires interactivity to complete. Make sure you supplied all required command line arguments!\");\n }\n return true;\n}\n\nfunction throwErr(message: string): never {\n throw new Error(message);\n}\n\n// TODO import this function from stack-shared instead (but that would require us to fix the build to let us import it)\nexport function templateIdentity(strings: TemplateStringsArray, ...values: any[]): string {\n if (strings.length === 0) return \"\";\n if (values.length !== strings.length - 1) throw new Error(\"Invalid number of values; must be one less than strings\");\n\n return strings.slice(1).reduce((result, string, i) => `${result}${values[i] ?? \"n/a\"}${string}`, strings[0]);\n}\n\nasync function clearStdin(): Promise<void> {\n await new Promise<void>((resolve) => {\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true);\n }\n process.stdin.resume();\n process.stdin.removeAllListeners('data');\n\n const flush = () => {\n while (process.stdin.read() !== null) {}\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false);\n }\n resolve();\n };\n\n // Add a small delay to allow any buffered input to clear\n setTimeout(flush, 10);\n });\n}\n","{\n \"name\": \"@stackframe/init-stack\",\n \"version\": \"2.8.35\",\n \"description\": \"The setup wizard for Stack. https://stack-auth.com\",\n \"main\": \"dist/index.js\",\n \"type\": \"module\",\n \"bin\": \"./dist/index.js\",\n \"scripts\": {\n \"clean\": \"rimraf test-run-output && rimraf node_modules && rimraf dist\",\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint --ext .tsx,.ts .\",\n \"typecheck\": \"tsc --noEmit\",\n \"init-stack\": \"node dist/index.js\",\n \"init-stack:local\": \"STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE=../../stack STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE=../../js node dist/index.js\",\n \"test-run\": \"pnpm run build && pnpm run test-run-js && pnpm run test-run-node && pnpm run test-run-next && pnpm run test-run-neon && pnpm run test-run-no-browser\",\n \"test-run:manual\": \"pnpm run build && pnpm run test-run-js:manual && pnpm run test-run-node:manual && pnpm run test-run-next:manual && pnpm run test-run-neon:manual\",\n \"ensure-neon\": \"grep -q '\\\"@neondatabase/serverless\\\"' ./test-run-output/package.json && echo 'Initialized Neon successfully!'\",\n \"test-run-neon\": \"pnpm run test-run-node --neon && pnpm run ensure-neon\",\n \"test-run-neon:manual\": \"pnpm run test-run-node:manual --neon && pnpm run ensure-neon\",\n \"test-run-no-browser\": \"rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --server --npm --no-browser\",\n \"test-run-node:manual\": \"rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init && cd .. && pnpm run init-stack:local test-run-output\",\n \"test-run-node\": \"rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --server --npm\",\n \"test-run-js:manual\": \"rimraf test-run-output && npx -y sv create test-run-output --no-install && pnpm run init-stack:local test-run-output\",\n \"test-run-js\": \"rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --client --npm\",\n \"test-run-next:manual\": \"rimraf test-run-output && npx -y create-next-app@latest test-run-output && pnpm run init-stack:local test-run-output\",\n \"test-run-next\": \"rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output\"\n },\n \"files\": [\n \"README.md\",\n \"dist\",\n \"CHANGELOG.md\",\n \"LICENSE\"\n ],\n \"homepage\": \"https://stack-auth.com\",\n \"keywords\": [],\n \"author\": \"\",\n \"license\": \"MIT\",\n \"dependencies\": {\n \"@stackframe/stack-shared\": \"workspace:*\",\n \"commander\": \"^13.1.0\",\n \"inquirer\": \"^9.2.19\",\n \"open\": \"^10.1.0\",\n \"posthog-node\": \"^4.1.0\"\n },\n \"devDependencies\": {\n \"@types/inquirer\": \"^9.0.7\",\n \"@types/node\": \"20.17.6\",\n \"rimraf\": \"^6.0.1\",\n \"tsup\": \"^8.4.0\",\n \"typescript\": \"5.3.3\"\n }\n}\n"],"mappings":";;;AAAA,YAAY,mBAAmB;AAC/B,SAAS,eAAe;AACxB,YAAY,YAAY;AACxB,YAAY,QAAQ;AACpB,OAAO,cAAc;AACrB,OAAO,UAAU;AACjB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,eAAe;;;ACRxB;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,KAAO;AAAA,EACP,SAAW;AAAA,IACT,OAAS;AAAA,IACT,OAAS;AAAA,IACT,KAAO;AAAA,IACP,MAAQ;AAAA,IACR,WAAa;AAAA,IACb,cAAc;AAAA,IACd,oBAAoB;AAAA,IACpB,YAAY;AAAA,IACZ,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,iBAAiB;AAAA,IACjB,wBAAwB;AAAA,IACxB,uBAAuB;AAAA,IACvB,wBAAwB;AAAA,IACxB,iBAAiB;AAAA,IACjB,sBAAsB;AAAA,IACtB,eAAe;AAAA,IACf,wBAAwB;AAAA,IACxB,iBAAiB;AAAA,EACnB;AAAA,EACA,OAAS;AAAA,IACP;AAAA,I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,IAAI,MAAM,yDAAyD;AAEnH,SAAO,QAAQ,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,QAAQ,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,KAAK,KAAK,GAAG,MAAM,IAAI,QAAQ,CAAC,CAAC;AAC7G;AAEA,eAAe,aAA4B;AACzC,QAAM,IAAI,QAAc,CAAC,YAAY;AACnC,QAAI,QAAQ,MAAM,OAAO;AACrB,cAAQ,MAAM,WAAW,IAAI;AAAA,IACjC;AACE,YAAQ,MAAM,OAAO;AACrB,YAAQ,MAAM,mBAAmB,MAAM;AAEvC,UAAM,QAAQ,MAAM;AAClB,aAAO,QAAQ,MAAM,KAAK,MAAM,MAAM;AAAA,MAAC;AACvC,UAAI,QAAQ,MAAM,OAAO;AACrB,gBAAQ,MAAM,WAAW,KAAK;AAAA,MAClC;AACE,cAAQ;AAAA,IACZ;AAGA,eAAW,OAAO,EAAE;AAAA,EACxB,CAAC;AACH;","names":["options"]}
1
+ {"version":3,"sources":["../src/index.ts","../package.json"],"sourcesContent":["import * as child_process from \"child_process\";\nimport { Command } from \"commander\";\nimport * as crypto from 'crypto';\nimport * as fs from \"fs\";\nimport inquirer from \"inquirer\";\nimport open from \"open\";\nimport * as os from 'os';\nimport * as path from \"path\";\nimport { PostHog } from 'posthog-node';\nimport packageJson from '../package.json';\n\nconst jsLikeFileExtensions: string[] = [\n \"mtsx\",\n \"ctsx\",\n \"tsx\",\n \"mts\",\n \"cts\",\n \"ts\",\n \"mjsx\",\n \"cjsx\",\n \"jsx\",\n \"mjs\",\n \"cjs\",\n \"js\",\n];\n\n// Setup command line parsing\nconst program = new Command();\nprogram\n .name(packageJson.name)\n .description(\"Stack Auth Initialization Tool\")\n .version(packageJson.version)\n .argument(\"[project-path]\", \"Path to your project\")\n .usage(`[project-path] [options]`)\n .option(\"--dry-run\", \"Run without making any changes\")\n .option(\"--neon\", \"Use Neon database\")\n .option(\"--js\", \"Initialize for JavaScript project\")\n .option(\"--next\", \"Initialize for Next.js project\")\n .option(\"--react\", \"Initialize for React project\")\n .option(\"--npm\", \"Use npm as package manager\")\n .option(\"--yarn\", \"Use yarn as package manager\")\n .option(\"--pnpm\", \"Use pnpm as package manager\")\n .option(\"--bun\", \"Use bun as package manager\")\n .option(\"--client\", \"Initialize client-side only\")\n .option(\"--server\", \"Initialize server-side only\")\n .option(\"--project-id <project-id>\", \"Project ID to use in setup\")\n .option(\"--publishable-client-key <publishable-client-key>\", \"Publishable client key to use in setup\")\n .option(\"--no-browser\", \"Don't open browser for environment variable setup\")\n .option(\"--agent-mode\", \"Run without prompting for any input\")\n .addHelpText('after', `\nFor more information, please visit https://docs.stack-auth.com/getting-started/setup`);\n\nprogram.parse();\n\nconst options = program.opts();\n\n// Keep existing variables but assign from Commander\nlet savedProjectPath: string | undefined = program.args[0] || undefined;\nconst isDryRun: boolean = options.dryRun || false;\nconst isNeon: boolean = options.neon || false;\nconst typeFromArgs: \"js\" | \"next\" | \"react\" | undefined = options.js ? \"js\" : options.next ? \"next\" : options.react ? \"react\" : undefined;\nconst packageManagerFromArgs: string | undefined = options.npm ? \"npm\" : options.yarn ? \"yarn\" : options.pnpm ? \"pnpm\" : options.bun ? \"bun\" : undefined;\nconst isClient: boolean = options.client || false;\nconst isServer: boolean = options.server || false;\nconst projectIdFromArgs: string | undefined = options.projectId;\nconst publishableClientKeyFromArgs: string | undefined = options.publishableClientKey;\nconst agentMode = !!options.agentMode;\n// Commander negates the boolean options with prefix `--no-`\n// so `--no-browser` becomes `browser: false`\nconst noBrowser: boolean = !options.browser;\n\nclass UserError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"UserError\";\n }\n}\n\ntype Ansis = {\n red: string,\n blue: string,\n green: string,\n yellow: string,\n clear: string,\n bold: string,\n};\n\nconst ansis: Ansis = {\n red: \"\\x1b[31m\",\n blue: \"\\x1b[34m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n\n clear: \"\\x1b[0m\",\n bold: \"\\x1b[1m\",\n};\n\ntype TemplateFunction = (strings: TemplateStringsArray, ...values: any[]) => string;\n\ntype Colorize = {\n red: TemplateFunction,\n blue: TemplateFunction,\n green: TemplateFunction,\n yellow: TemplateFunction,\n bold: TemplateFunction,\n};\n\nconst colorize: Colorize = {\n red: (strings, ...values) => ansis.red + templateIdentity(strings, ...values) + ansis.clear,\n blue: (strings, ...values) => ansis.blue + templateIdentity(strings, ...values) + ansis.clear,\n green: (strings, ...values) => ansis.green + templateIdentity(strings, ...values) + ansis.clear,\n yellow: (strings, ...values) => ansis.yellow + templateIdentity(strings, ...values) + ansis.clear,\n bold: (strings, ...values) => ansis.bold + templateIdentity(strings, ...values) + ansis.clear,\n};\n\nconst filesCreated: string[] = [];\nconst filesModified: string[] = [];\nconst commandsExecuted: string[] = [];\n\nconst packagesToInstall: string[] = [];\nconst writeFileHandlers: Array<() => Promise<void>> = [];\nconst nextSteps: string[] = [\n `Create an account and Stack Auth API key for your project on https://app.stack-auth.com`,\n];\n\n\nconst STACK_AUTH_PUBLIC_HOG_KEY = \"phc_vIUFi0HzHo7oV26OsaZbUASqxvs8qOmap1UBYAutU4k\";\nconst EVENT_PREFIX = \"stack-init-\";\nconst ph_client = new PostHog(STACK_AUTH_PUBLIC_HOG_KEY, {\n host: \"https://eu.i.posthog.com\",\n flushAt: 1,\n flushInterval: 0,\n});\nconst distinctId = crypto.randomUUID();\n\n\nasync function capture(event: string, properties: Record<string, any>) {\n ph_client.capture({\n event: `${EVENT_PREFIX}${event}`,\n distinctId,\n properties,\n });\n}\n\n\nasync function main(): Promise<void> {\n // Welcome message\n console.log();\n console.log(`\n ██████\n ██████████████\n████████████████████\n████████████████████ WELCOME TO\n█████████████████ ╔═╗╔╦╗╔═╗╔═╗╦╔═ ┌─┐┬ ┬┌┬┐┬ ┬\n█████████████ ╚═╗ ║ ╠═╣║ ╠╩╗ ├─┤│ │ │ ├─┤\n█████████████ ████ ╚═╝ ╩ ╩ ╩╚═╝╩ ╩ ┴ ┴└─┘ ┴ ┴ ┴\n █████████████████\n ██████ ██\n████ ████\n █████ █████\n ██████\n `);\n console.log();\n\n await capture(\"start\", {\n version: packageJson.version,\n isDryRun,\n isNeon,\n typeFromArgs,\n packageManagerFromArgs,\n isClient,\n isServer,\n noBrowser,\n platform: os.platform(),\n arch: os.arch(),\n nodeVersion: process.version,\n });\n\n // Wait just briefly so we can use `Steps` in here (it's defined only after the call to `main()`)\n await new Promise<void>((resolve) => resolve());\n\n\n // Prepare some stuff\n await clearStdin();\n const projectPath = await getProjectPath();\n\n\n // Steps\n const { packageJson: projectPackageJson } = await Steps.getProject();\n const type = await Steps.getProjectType({ packageJson: projectPackageJson });\n\n await capture(\"project-type-selected\", {\n type,\n wasSpecifiedInArgs: !!typeFromArgs,\n });\n\n await Steps.addStackPackage(type);\n if (isNeon) packagesToInstall.push('@neondatabase/serverless');\n\n await Steps.writeEnvVars(type);\n\n if (type === \"next\") {\n const projectInfo = await Steps.getNextProjectInfo({ packageJson: projectPackageJson });\n await Steps.updateNextLayoutFile(projectInfo);\n await Steps.writeStackAppFile(projectInfo, \"client\");\n await Steps.writeStackAppFile(projectInfo, \"server\");\n await Steps.writeNextHandlerFile(projectInfo);\n await Steps.writeNextLoadingFile(projectInfo);\n nextSteps.push(`Copy the environment variables from the new API key into your .env.local file`);\n } else if (type === \"react\") {\n const defaultExtension = await Steps.guessDefaultFileExtension();\n const srcPath = await Steps.guessSrcPath();\n const hasReactRouterDom = !!(projectPackageJson.dependencies?.[\"react-router-dom\"] || projectPackageJson.devDependencies?.[\"react-router-dom\"]);\n const { fileName } = await Steps.writeReactClientFile({\n srcPath,\n defaultExtension,\n indentation: \" \",\n hasReactRouterDom,\n });\n nextSteps.push(\n `Copy the environment variables from the new API key into your own environment and reference them in ${fileName}`,\n );\n } else {\n const defaultExtension = await Steps.guessDefaultFileExtension();\n const where = await Steps.getServerOrClientOrBoth();\n const srcPath = await Steps.guessSrcPath();\n const appFiles: string[] = [];\n for (const w of where) {\n const { fileName } = await Steps.writeStackAppFile({\n type,\n defaultExtension,\n indentation: \" \",\n srcPath,\n }, w);\n appFiles.push(fileName);\n }\n nextSteps.push(\n `Copy the environment variables from the new API key into your own environment and reference them in ${appFiles.join(\" and \")}`,\n `Follow the instructions on how to use Stack Auth's vanilla SDK at http://docs.stack-auth.com/others/js-client`,\n );\n }\n\n const { packageManager } = await Steps.getPackageManager();\n\n await capture(`package-manager-selected`, {\n packageManager,\n wasSpecifiedInArgs: !!packageManagerFromArgs,\n });\n\n await Steps.ensureReady(type);\n\n\n // Install dependencies\n console.log();\n console.log(colorize.bold`Installing dependencies...`);\n const installCommandMap = new Map<string, string>([\n [\"npm\", \"npm install\"],\n [\"yarn\", \"yarn add\"],\n [\"pnpm\", \"pnpm add\"],\n [\"bun\", \"bun add\"],\n ]);\n const installCommand = installCommandMap.get(packageManager) ?? `${packageManager} install`;\n // Quote each package name to avoid shell interpretation of env-overridden values.\n const safePackages = packagesToInstall.map((p) => JSON.stringify(p));\n await shellNicelyFormatted(`${installCommand} ${safePackages.join(' ')}`, {\n shell: true,\n cwd: projectPath,\n });\n\n await capture(`dependencies-installed`, {\n packageManager,\n packages: packagesToInstall,\n });\n\n // Write files\n console.log();\n console.log(colorize.bold`Writing files...`);\n console.log();\n for (const writeFileHandler of writeFileHandlers) {\n await writeFileHandler();\n }\n console.log(`${colorize.green`√`} Done writing files`);\n\n console.log('\\n\\n\\n');\n console.log(colorize.bold`${colorize.green`Installation succeeded!`}`);\n console.log();\n console.log(\"Commands executed:\");\n for (const command of commandsExecuted) {\n console.log(` ${colorize.blue`${command}`}`);\n }\n console.log();\n console.log(\"Files written:\");\n for (const file of filesModified) {\n console.log(` ${colorize.yellow`${file}`}`);\n }\n for (const file of filesCreated) {\n console.log(` ${colorize.green`${file}`}`);\n }\n console.log();\n\n await capture(\"complete\", {\n success: true,\n type,\n packageManager,\n isNeon,\n isClient,\n isServer,\n noBrowser,\n filesCreated,\n filesModified,\n commandsExecuted,\n });\n\n // Success!\n console.log(`\n${colorize.green`===============================================`}\n\n${colorize.green`Successfully installed Stack! 🚀🚀🚀`}\n\n${colorize.bold`Next steps:`}\n\n1. ${noBrowser ?\n `Create a project at https://app.stack-auth.com and get your API keys` :\n `Complete the setup in your browser to get your API keys`}\n2. Add the API keys to your .env.local file\n3. Import the Stack components in your app\n4. Add authentication to your app\n\nFor more information, please visit https://docs.stack-auth.com/getting-started/setup\n `.trim());\n if (!noBrowser) {\n await open(`https://app.stack-auth.com/wizard-congrats?stack-init-id=${encodeURIComponent(distinctId)}`);\n }\n await ph_client.shutdown();\n}\n\n// eslint-disable-next-line no-restricted-syntax\nmain().catch(async (err) => {\n try {\n await capture(\"error\", {\n error: err.message,\n errorType: err instanceof UserError ? \"UserError\" : \"SystemError\",\n stack: err.stack,\n });\n } catch (e) { }\n if (!(err instanceof UserError)) {\n console.error(err);\n }\n console.error('\\n\\n\\n\\n');\n console.log(colorize.red`===============================================`);\n console.error();\n if (err instanceof UserError) {\n console.error(`${colorize.red`ERROR!`} ${err.message}`);\n } else {\n console.error(\"An error occurred during the initialization process.\");\n }\n console.error();\n console.log(colorize.red`===============================================`);\n console.error();\n console.error(\n \"If you need assistance, please try installing Stack manually as described in https://docs.stack-auth.com/getting-started/setup or join our Discord where we're happy to help: https://discord.stack-auth.com\"\n );\n if (!(err instanceof UserError)) {\n console.error(\"\");\n console.error(`Error message: ${err.message}`);\n }\n console.error();\n await ph_client.shutdown();\n process.exit(1);\n});\n\n\ntype PackageJson = {\n dependencies?: Record<string, string>,\n devDependencies?: Record<string, string>,\n [key: string]: any,\n}\n\ntype ProjectInfo = {\n type: \"js\" | \"next\" | \"react\",\n srcPath: string,\n appPath: string,\n defaultExtension: string,\n indentation: string,\n}\n\ntype NextProjectInfoError = {\n error: string,\n}\n\ntype NextProjectInfoResult = ProjectInfo | NextProjectInfoError;\n\ntype StackAppFileOptions = {\n type: \"js\" | \"next\" | \"react\",\n srcPath: string,\n defaultExtension: string,\n indentation: string,\n}\n\ntype StackAppFileResult = {\n fileName: string,\n}\n\nconst Steps = {\n async getProject(): Promise<{ packageJson: PackageJson }> {\n let projectPath = await getProjectPath();\n if (!fs.existsSync(projectPath)) {\n throw new UserError(`The project path ${projectPath} does not exist`);\n }\n\n const packageJsonPath = path.join(projectPath, \"package.json\");\n if (!fs.existsSync(packageJsonPath)) {\n throw new UserError(\n `The package.json file does not exist in the project path ${projectPath}. You must initialize a new project first before installing Stack.`\n );\n }\n\n const packageJsonText = fs.readFileSync(packageJsonPath, \"utf-8\");\n let packageJson: PackageJson;\n try {\n packageJson = JSON.parse(packageJsonText);\n } catch (e) {\n throw new UserError(`package.json file is not valid JSON: ${e}`);\n }\n\n return { packageJson };\n },\n\n async getProjectType({ packageJson }: { packageJson: PackageJson }): Promise<\"js\" | \"next\" | \"react\"> {\n if (typeFromArgs) return typeFromArgs;\n\n const maybeNextProject = await Steps.maybeGetNextProjectInfo({ packageJson });\n if (!(\"error\" in maybeNextProject)) {\n return \"next\";\n }\n if (packageJson.dependencies?.[\"react\"] || packageJson.dependencies?.[\"react-dom\"]) {\n return \"react\";\n }\n if (agentMode) {\n return \"js\";\n }\n\n const { type } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"type\",\n message: \"Which integration would you like to install?\",\n choices: [\n { name: \"None (vanilla JS, Node.js, etc)\", value: \"js\" },\n { name: \"React\", value: \"react\" },\n { name: \"Next.js\", value: \"next\" },\n ]\n }\n ]);\n\n return type;\n },\n\n async getStackPackageName(type: \"js\" | \"next\" | \"react\", install = false): Promise<string> {\n const mapping = {\n js: (install && process.env.STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE) || \"@stackframe/js\",\n next: (install && process.env.STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE) || \"@stackframe/stack\",\n react: (install && process.env.STACK_REACT_INSTALL_PACKAGE_NAME_OVERRIDE) || \"@stackframe/react\",\n } as const;\n return mapping[type];\n },\n\n async addStackPackage(type: \"js\" | \"next\" | \"react\"): Promise<void> {\n packagesToInstall.push(await Steps.getStackPackageName(type, true));\n },\n\n async getNextProjectInfo({ packageJson }: { packageJson: PackageJson }): Promise<ProjectInfo> {\n const maybe = await Steps.maybeGetNextProjectInfo({ packageJson });\n if (\"error\" in maybe) throw new UserError(maybe.error);\n return maybe;\n },\n\n async maybeGetNextProjectInfo({ packageJson }: { packageJson: PackageJson }): Promise<NextProjectInfoResult> {\n const projectPath = await getProjectPath();\n\n const nextVersionInPackageJson = packageJson.dependencies?.[\"next\"] ?? packageJson.devDependencies?.[\"next\"];\n if (!nextVersionInPackageJson) {\n return { error: `The project at ${projectPath} does not appear to be a Next.js project, or does not have 'next' installed as a dependency.` };\n }\n if (\n !nextVersionInPackageJson.includes(\"14\") &&\n !nextVersionInPackageJson.includes(\"15\") &&\n nextVersionInPackageJson !== \"latest\"\n ) {\n return { error: `The project at ${projectPath} is using an unsupported version of Next.js (found ${nextVersionInPackageJson}).\\n\\nOnly Next.js 14 & 15 projects are currently supported. See Next's upgrade guide: https://nextjs.org/docs/app/building-your-application/upgrading/version-14` };\n }\n\n const nextConfigPathWithoutExtension = path.join(projectPath, \"next.config\");\n const nextConfigFileExtension = await findJsExtension(\n nextConfigPathWithoutExtension\n );\n const nextConfigPath =\n nextConfigPathWithoutExtension + \".\" + (nextConfigFileExtension ?? \"js\");\n if (!fs.existsSync(nextConfigPath)) {\n return { error: `Expected file at ${nextConfigPath}. Only Next.js projects are currently supported.` };\n }\n\n const hasSrcAppFolder = fs.existsSync(path.join(projectPath, \"src/app\"));\n const srcPath = path.join(projectPath, hasSrcAppFolder ? \"src\" : \"\");\n const appPath = path.join(srcPath, \"app\");\n if (!fs.existsSync(appPath)) {\n return { error: `The app path ${appPath} does not exist. Only the Next.js app router is supported.` };\n }\n\n const dryUpdateNextLayoutFileResult = await Steps.dryUpdateNextLayoutFile({ appPath, defaultExtension: \"jsx\" });\n\n return {\n type: \"next\",\n srcPath,\n appPath,\n defaultExtension: dryUpdateNextLayoutFileResult.fileExtension,\n indentation: dryUpdateNextLayoutFileResult.indentation,\n };\n },\n\n async writeEnvVars(type: \"js\" | \"next\" | \"react\"): Promise<boolean> {\n const projectPath = await getProjectPath();\n\n // TODO: in non-Next environments, ask the user what method they prefer for envvars\n if (type !== \"next\") return false;\n\n const envLocalPath = path.join(projectPath, \".env.local\");\n\n const potentialEnvLocations = [\n path.join(projectPath, \".env\"),\n path.join(projectPath, \".env.development\"),\n path.join(projectPath, \".env.default\"),\n path.join(projectPath, \".env.defaults\"),\n path.join(projectPath, \".env.example\"),\n envLocalPath,\n ];\n if (potentialEnvLocations.every((p) => !fs.existsSync(p))) {\n const envContent = noBrowser\n ? \"# Stack Auth keys\\n\" +\n \"# To get these variables:\\n\" +\n \"# 1. Go to https://app.stack-auth.com\\n\" +\n \"# 2. Create a new project\\n\" +\n \"# 3. Copy the keys below\\n\" +\n `NEXT_PUBLIC_STACK_PROJECT_ID=\"${projectIdFromArgs ?? \"\"}\"\\n` +\n `NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=\"${publishableClientKeyFromArgs ?? \"\"}\"\\n` +\n \"STACK_SECRET_SERVER_KEY=\\n\"\n : \"# Stack Auth keys\\n\" +\n \"# Get these variables by creating a project on https://app.stack-auth.com.\\n\" +\n `NEXT_PUBLIC_STACK_PROJECT_ID=\"${projectIdFromArgs ?? \"\"}\"\\n` +\n `NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY=\"${publishableClientKeyFromArgs ?? \"\"}\"\\n` +\n \"STACK_SECRET_SERVER_KEY=\\n\";\n\n laterWriteFile(envLocalPath, envContent);\n return true;\n }\n\n return false;\n },\n\n async dryUpdateNextLayoutFile({ appPath, defaultExtension }: { appPath: string, defaultExtension: string }): Promise<{\n path: string,\n updatedContent: string,\n fileExtension: string,\n indentation: string,\n }> {\n const layoutPathWithoutExtension = path.join(appPath, \"layout\");\n const layoutFileExtension =\n (await findJsExtension(layoutPathWithoutExtension)) ?? defaultExtension;\n const layoutPath = layoutPathWithoutExtension + \".\" + layoutFileExtension;\n const layoutContent =\n (await readFile(layoutPath)) ??\n throwErr(\n `The layout file at ${layoutPath} does not exist. Stack requires a layout file to be present in the /app folder.`\n );\n const updatedLayoutResult =\n (await getUpdatedLayout(layoutContent)) ??\n throwErr(\n \"Unable to parse root layout file. Make sure it contains a <body> tag. If it still doesn't work, you may need to manually install Stack. See: https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required\"\n );\n const updatedLayoutContent = updatedLayoutResult.content;\n return {\n path: layoutPath,\n updatedContent: updatedLayoutContent,\n fileExtension: layoutFileExtension,\n indentation: updatedLayoutResult.indentation\n };\n },\n\n async updateNextLayoutFile(projectInfo: ProjectInfo): Promise<{\n path: string,\n updatedContent: string,\n fileExtension: string,\n indentation: string,\n }> {\n const res = await Steps.dryUpdateNextLayoutFile(projectInfo);\n laterWriteFile(res.path, res.updatedContent);\n return res;\n },\n\n async writeStackAppFile({ type, srcPath, defaultExtension, indentation }: StackAppFileOptions, clientOrServer: \"server\" | \"client\"): Promise<StackAppFileResult> {\n const packageName = await Steps.getStackPackageName(type);\n\n const clientOrServerCap = {\n client: \"Client\",\n server: \"Server\",\n }[clientOrServer as \"client\" | \"server\"];\n const relativeStackAppPath = `stack/${clientOrServer}`;\n\n const stackAppPathWithoutExtension = path.join(srcPath, relativeStackAppPath);\n const stackAppFileExtension =\n (await findJsExtension(stackAppPathWithoutExtension)) ?? defaultExtension;\n const stackAppPath =\n stackAppPathWithoutExtension + \".\" + stackAppFileExtension;\n const stackAppContent = await readFile(stackAppPath);\n if (stackAppContent) {\n if (!stackAppContent.includes(\"@stackframe/\")) {\n throw new UserError(\n `A file at the path ${stackAppPath} already exists. Stack uses the stack/${clientOrServer}.ts file to initialize the Stack SDK. Please remove the existing file and try again.`\n );\n }\n throw new UserError(\n `It seems that you already installed Stack in this project.`\n );\n }\n\n const tokenStore = type === \"next\" ? '\"nextjs-cookie\"' : (clientOrServer === \"client\" ? '\"cookie\"' : '\"memory\"');\n const publishableClientKeyWrite = clientOrServer === \"server\"\n ? `process.env.STACK_PUBLISHABLE_CLIENT_KEY ${publishableClientKeyFromArgs ? `|| '${publishableClientKeyFromArgs}'` : \"\"}`\n : `'${publishableClientKeyFromArgs ?? 'INSERT_YOUR_PUBLISHABLE_CLIENT_KEY_HERE'}'`;\n const jsOptions = type === \"js\" ? [\n `\\n\\n${indentation}// get your Stack Auth API keys from https://app.stack-auth.com${clientOrServer === \"client\" ? ` and store them in a safe place (eg. environment variables)` : \"\"}`,\n `${projectIdFromArgs ? `${indentation}projectId: '${projectIdFromArgs}',` : \"\"}`,\n `${indentation}publishableClientKey: ${publishableClientKeyWrite},`,\n `${clientOrServer === \"server\" ? `${indentation}secretServerKey: process.env.STACK_SECRET_SERVER_KEY,` : \"\"}`,\n ].filter(Boolean).join(\"\\n\") : \"\";\n\n\n laterWriteFileIfNotExists(\n stackAppPath,\n `\n${type === \"next\" && clientOrServer === \"server\" ? `import \"server-only\";` : \"\"}\n\nimport { Stack${clientOrServerCap}App } from ${JSON.stringify(packageName)};\n\nexport const stack${clientOrServerCap}App = new Stack${clientOrServerCap}App({\n${indentation}tokenStore: ${tokenStore},${jsOptions}\n});\n `.trim() + \"\\n\"\n );\n return { fileName: stackAppPath };\n },\n\n async writeReactClientFile({ srcPath, defaultExtension, indentation, hasReactRouterDom }: { srcPath: string, defaultExtension: string, indentation: string, hasReactRouterDom: boolean }): Promise<StackAppFileResult> {\n const packageName = await Steps.getStackPackageName(\"react\");\n const relativeStackAppPath = `stack/client`;\n const stackAppPathWithoutExtension = path.join(srcPath, relativeStackAppPath);\n const stackAppFileExtension = (await findJsExtension(stackAppPathWithoutExtension)) ?? defaultExtension;\n const stackAppPath = stackAppPathWithoutExtension + \".\" + stackAppFileExtension;\n const stackAppContent = await readFile(stackAppPath);\n if (stackAppContent) {\n if (!stackAppContent.includes(\"@stackframe/\")) {\n throw new UserError(`A file at the path ${stackAppPath} already exists. Stack uses the stack/client.ts file to initialize the Stack SDK. Please remove the existing file and try again.`);\n }\n throw new UserError(`It seems that you already installed Stack in this project.`);\n }\n\n const publishableClientKeyWrite = `'${publishableClientKeyFromArgs ?? 'INSERT_YOUR_PUBLISHABLE_CLIENT_KEY_HERE'}'`;\n const projectIdWrite = `'${projectIdFromArgs ?? 'INSERT_PROJECT_ID'}'`;\n\n const imports = hasReactRouterDom\n ? `import { StackClientApp } from ${JSON.stringify(packageName)};\\nimport { useNavigate } from \"react-router-dom\";\\n\\n`\n : `import { StackClientApp } from ${JSON.stringify(packageName)};\\n\\n`;\n\n const redirectMethod = hasReactRouterDom\n ? `,\\n${indentation}redirectMethod: {\\n${indentation}${indentation}useNavigate,\\n${indentation}}`\n : \"\";\n\n laterWriteFileIfNotExists(\n stackAppPath,\n `${imports}export const stackClientApp = new StackClientApp({ \\n${indentation}tokenStore: \"cookie\", \\n${indentation}projectId: ${projectIdWrite}, \\n${indentation}publishableClientKey: ${publishableClientKeyWrite}${redirectMethod}, \\n}); \\n`\n );\n return { fileName: stackAppPath };\n },\n\n async writeNextHandlerFile(projectInfo: ProjectInfo): Promise<void> {\n const handlerPathWithoutExtension = path.join(\n projectInfo.appPath,\n \"handler/[...stack]/page\"\n );\n const handlerFileExtension =\n (await findJsExtension(handlerPathWithoutExtension)) ?? projectInfo.defaultExtension;\n const handlerPath = handlerPathWithoutExtension + \".\" + handlerFileExtension;\n const handlerContent = await readFile(handlerPath);\n if (handlerContent && !handlerContent.includes(\"@stackframe/\")) {\n throw new UserError(\n `A file at the path ${handlerPath} already exists.Stack uses the / handler path to handle incoming requests.Please remove the existing file and try again.`\n );\n }\n laterWriteFileIfNotExists(\n handlerPath,\n `import { StackHandler } from \"@stackframe/stack\"; \\nimport { stackServerApp } from \"../../../stack/server\"; \\n\\nexport default function Handler(props${handlerFileExtension.includes(\"ts\") ? \": unknown\" : \"\"\n }) { \\n${projectInfo.indentation} return <StackHandler fullPage app = { stackServerApp } routeProps = { props } />; \\n } \\n`\n );\n },\n\n async writeNextLoadingFile(projectInfo: ProjectInfo): Promise<void> {\n let loadingPathWithoutExtension = path.join(projectInfo.appPath, \"loading\");\n const loadingFileExtension =\n (await findJsExtension(loadingPathWithoutExtension)) ?? projectInfo.defaultExtension;\n const loadingPath = loadingPathWithoutExtension + \".\" + loadingFileExtension;\n laterWriteFileIfNotExists(\n loadingPath,\n `export default function Loading() {\n\\n${projectInfo.indentation}// Stack uses React Suspense, which will render this page while user data is being fetched.\\n${projectInfo.indentation}// See: https://nextjs.org/docs/app/api-reference/file-conventions/loading\\n${projectInfo.indentation}return <></>;\\n}\\n`\n );\n },\n\n async getPackageManager(): Promise<{ packageManager: string }> {\n if (packageManagerFromArgs) return { packageManager: packageManagerFromArgs };\n const packageManager = await promptPackageManager();\n const versionCommand = `${packageManager} --version`;\n\n try {\n await shellNicelyFormatted(versionCommand, { shell: true, quiet: true });\n } catch (err) {\n console.error(err);\n throw new UserError(\n `Could not run the package manager command '${versionCommand}'. Please make sure ${packageManager} is installed on your system.`\n );\n }\n\n return { packageManager };\n },\n\n async ensureReady(type: \"js\" | \"next\" | \"react\"): Promise<void> {\n const projectPath = await getProjectPath();\n\n const typeStringMap = {\n js: \"JavaScript\",\n next: \"Next.js\",\n react: \"React\",\n } as const;\n const typeString = typeStringMap[type];\n const isReady = agentMode || (await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"ready\",\n message: `Found a ${typeString} project at ${projectPath} — ready to install Stack Auth?`,\n default: true,\n },\n ])).ready;\n if (!isReady) {\n throw new UserError(\"Installation aborted.\");\n }\n },\n\n async getServerOrClientOrBoth(): Promise<Array<\"server\" | \"client\">> {\n if (isClient && isServer) return [\"server\", \"client\"];\n if (isServer) return [\"server\"];\n if (isClient) return [\"client\"];\n\n if (agentMode) {\n throw new UserError(\"Please specify the installation type using the --server or --client argument.\");\n }\n\n return (await inquirer.prompt([{\n type: \"list\",\n name: \"type\",\n message: \"Do you want to use Stack Auth on the server, or on the client?\",\n choices: [\n { name: \"Client (eg. Vite, HTML)\", value: [\"client\"] },\n { name: \"Server (eg. Node.js)\", value: [\"server\"] },\n { name: \"Both\", value: [\"server\", \"client\"] }\n ]\n }])).type;\n },\n\n /**\n * note: this is a heuristic, specific frameworks may have better heuristics (eg. the Next.js code uses the extension of the global layout file)\n */\n async guessDefaultFileExtension(): Promise<string> {\n const projectPath = await getProjectPath();\n const hasTsConfig = fs.existsSync(\n path.join(projectPath, \"tsconfig.json\")\n );\n return hasTsConfig ? \"ts\" : \"js\";\n },\n\n /**\n * note: this is a heuristic, specific frameworks may have better heuristics (eg. the Next.js code uses the location of the app folder)\n */\n async guessSrcPath(): Promise<string> {\n const projectPath = await getProjectPath();\n const potentialSrcPath = path.join(projectPath, \"src\");\n const hasSrcFolder = fs.existsSync(\n path.join(projectPath, \"src\")\n );\n return hasSrcFolder ? potentialSrcPath : projectPath;\n },\n\n\n};\n\n\ntype LayoutResult = {\n content: string,\n indentation: string,\n}\n\nasync function getUpdatedLayout(originalLayout: string): Promise<LayoutResult | undefined> {\n let layout = originalLayout;\n const indentation = guessIndentation(originalLayout);\n\n const firstImportLocationM1 = /\\simport\\s/.exec(layout)?.index;\n const hasStringAsFirstLine = layout.startsWith('\"') || layout.startsWith(\"'\");\n const importInsertLocationM1 =\n firstImportLocationM1 ?? (hasStringAsFirstLine ? layout.indexOf(\"\\n\") : -1);\n const importInsertLocation = importInsertLocationM1 + 1;\n const importStatement = `import { StackProvider, StackTheme } from \"@stackframe/stack\";\\nimport { stackServerApp } from \"../stack/server\";\\n`;\n layout =\n layout.slice(0, importInsertLocation) +\n importStatement +\n layout.slice(importInsertLocation);\n\n const bodyOpenTag = /<\\s*body[^>]*>/.exec(layout);\n const bodyCloseTag = /<\\s*\\/\\s*body[^>]*>/.exec(layout);\n if (!bodyOpenTag || !bodyCloseTag) {\n return undefined;\n }\n const bodyOpenEndIndex = bodyOpenTag.index + bodyOpenTag[0].length;\n const bodyCloseStartIndex = bodyCloseTag.index;\n if (bodyCloseStartIndex <= bodyOpenEndIndex) {\n return undefined;\n }\n\n const lines = layout.split(\"\\n\");\n const [bodyOpenEndLine, bodyOpenEndIndexInLine] = getLineIndex(\n lines,\n bodyOpenEndIndex\n );\n const [bodyCloseStartLine, bodyCloseStartIndexInLine] = getLineIndex(\n lines,\n bodyCloseStartIndex\n );\n\n const insertOpen = \"<StackProvider app={stackServerApp}><StackTheme>\";\n const insertClose = \"</StackTheme></StackProvider>\";\n\n layout =\n layout.slice(0, bodyCloseStartIndex) +\n insertClose +\n layout.slice(bodyCloseStartIndex);\n layout =\n layout.slice(0, bodyOpenEndIndex) +\n insertOpen +\n layout.slice(bodyOpenEndIndex);\n\n return {\n content: `${layout}`,\n indentation,\n };\n}\n\nfunction guessIndentation(str: string): string {\n const lines = str.split(\"\\n\");\n const linesLeadingWhitespaces = lines\n .map((line) => line.match(/^\\s*/)![0])\n .filter((ws) => ws.length > 0);\n const isMostlyTabs =\n linesLeadingWhitespaces.filter((ws) => ws.includes(\"\\t\")).length >=\n (linesLeadingWhitespaces.length * 2) / 3;\n if (isMostlyTabs) return \"\\t\";\n const linesLeadingWhitespacesCount = linesLeadingWhitespaces.map(\n (ws) => ws.length\n );\n const min = Math.min(Infinity, ...linesLeadingWhitespacesCount);\n return Number.isFinite(min) ? \" \".repeat(Math.max(2, min)) : \" \";\n}\n\nfunction getLineIndex(lines: string[], stringIndex: number): [number, number] {\n let lineIndex = 0;\n for (let l = 0; l < lines.length; l++) {\n const line = lines[l];\n if (stringIndex < lineIndex + line.length) {\n return [l, stringIndex - lineIndex];\n }\n lineIndex += line.length + 1;\n }\n throw new Error(\n `Index ${stringIndex} is out of bounds for lines ${JSON.stringify(lines)}`\n );\n}\n\nasync function getProjectPath(): Promise<string> {\n if (savedProjectPath === undefined) {\n savedProjectPath = process.cwd();\n\n const askForPathModification = !fs.existsSync(\n path.join(savedProjectPath, \"package.json\")\n );\n if (askForPathModification) {\n if (agentMode) {\n throw new UserError(`No package.json file found in the project directory ${savedProjectPath}. Please specify the correct project path using the --project-path argument, or create a new project before running the wizard.`);\n }\n savedProjectPath = (\n await inquirer.prompt([\n {\n type: \"input\",\n name: \"newPath\",\n message: \"Please enter the path to your project:\",\n default: \".\",\n },\n ])\n ).newPath;\n }\n }\n return savedProjectPath as string;\n}\n\nasync function findJsExtension(fullPathWithoutExtension: string): Promise<string | null> {\n for (const ext of jsLikeFileExtensions) {\n const fullPath = fullPathWithoutExtension + \".\" + ext;\n if (fs.existsSync(fullPath)) {\n return ext;\n }\n }\n return null;\n}\n\nasync function promptPackageManager(): Promise<string> {\n const projectPath = await getProjectPath();\n const yarnLock = fs.existsSync(path.join(projectPath, \"yarn.lock\"));\n const pnpmLock = fs.existsSync(path.join(projectPath, \"pnpm-lock.yaml\"));\n const npmLock = fs.existsSync(path.join(projectPath, \"package-lock.json\"));\n const bunLock = fs.existsSync(path.join(projectPath, \"bun.lockb\"));\n\n if (yarnLock && !pnpmLock && !npmLock && !bunLock) {\n return \"yarn\";\n } else if (!yarnLock && pnpmLock && !npmLock && !bunLock) {\n return \"pnpm\";\n } else if (!yarnLock && !pnpmLock && npmLock && !bunLock) {\n return \"npm\";\n } else if (!yarnLock && !pnpmLock && !npmLock && bunLock) {\n return \"bun\";\n }\n\n if (agentMode) {\n throw new UserError(\"Unable to determine which package manager to use. Please rerun the init command and specify the package manager using exactly one of the following arguments: --npm, --yarn, --pnpm, or --bun.\");\n }\n\n const answers = await inquirer.prompt([\n {\n type: \"list\",\n name: \"packageManager\",\n message: \"Which package manager are you using for this project?\",\n choices: [\"npm\", \"yarn\", \"pnpm\", \"bun\"],\n },\n ]);\n return answers.packageManager;\n}\n\ntype ShellOptions = {\n quiet?: boolean,\n shell?: boolean,\n cwd?: string,\n [key: string]: any,\n}\n\nasync function shellNicelyFormatted(command: string, { quiet, ...options }: ShellOptions): Promise<void> {\n let ui: any;\n let interval: NodeJS.Timeout | undefined;\n if (!quiet) {\n console.log();\n ui = new inquirer.ui.BottomBar();\n let dots = 4;\n ui.updateBottomBar(\n colorize.blue`Running command: ${command}...`\n );\n interval = setInterval(() => {\n if (!isDryRun) {\n ui.updateBottomBar(\n colorize.blue`Running command: ${command}${\".\".repeat(dots++ % 5)}`\n );\n }\n }, 700);\n }\n\n try {\n if (!isDryRun) {\n const child = child_process.spawn(command, options);\n if (!quiet) {\n child.stdout.pipe(ui.log);\n child.stderr.pipe(ui.log);\n }\n\n await new Promise<void>((resolve, reject) => {\n child.on(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n } else {\n reject(new Error(`Command ${command} failed with code ${code}`));\n }\n });\n });\n } else {\n console.log(`[DRY-RUN] Would have run: ${command}`);\n }\n\n if (!quiet) {\n commandsExecuted.push(command);\n ui.updateBottomBar(\n `${colorize.green`√`} Command ${command} succeeded\\n`\n );\n }\n } catch (e) {\n if (!quiet) {\n ui.updateBottomBar(\n `${colorize.red`X`} Command ${command} failed\\n`\n );\n }\n throw e;\n } finally {\n if (interval) {\n clearTimeout(interval);\n }\n if (!quiet) {\n ui.close();\n }\n }\n}\n\nasync function readFile(fullPath: string): Promise<string | null> {\n try {\n if (!isDryRun) {\n return fs.readFileSync(fullPath, \"utf-8\");\n }\n return null;\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n return null;\n }\n throw err;\n }\n}\n\nasync function writeFile(fullPath: string, content: string): Promise<void> {\n let create = !fs.existsSync(fullPath);\n if (!isDryRun) {\n fs.mkdirSync(path.dirname(fullPath), { recursive: true });\n fs.writeFileSync(fullPath, content);\n } else {\n console.log(`[DRY-RUN] Would have written to ${fullPath}`);\n }\n const relativeToProjectPath = path.relative(await getProjectPath(), fullPath);\n if (!create) {\n filesModified.push(relativeToProjectPath);\n } else {\n filesCreated.push(relativeToProjectPath);\n }\n}\n\nfunction laterWriteFile(fullPath: string, content: string): void {\n writeFileHandlers.push(async () => {\n await writeFile(fullPath, content);\n });\n}\n\nasync function writeFileIfNotExists(fullPath: string, content: string): Promise<void> {\n if (!fs.existsSync(fullPath)) {\n await writeFile(fullPath, content);\n }\n}\n\nfunction laterWriteFileIfNotExists(fullPath: string, content: string): void {\n writeFileHandlers.push(async () => {\n await writeFileIfNotExists(fullPath, content);\n });\n}\n\nfunction throwErr(message: string): never {\n throw new Error(message);\n}\n\n// TODO import this function from stack-shared instead (but that would require us to fix the build to let us import it)\nexport function templateIdentity(strings: TemplateStringsArray, ...values: any[]): string {\n if (strings.length === 0) return \"\";\n if (values.length !== strings.length - 1) throw new Error(\"Invalid number of values; must be one less than strings\");\n\n return strings.slice(1).reduce((result, string, i) => `${result}${values[i] ?? \"n/a\"}${string}`, strings[0]);\n}\n\nasync function clearStdin(): Promise<void> {\n await new Promise<void>((resolve) => {\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true);\n }\n process.stdin.resume();\n process.stdin.removeAllListeners('data');\n\n const flush = () => {\n while (process.stdin.read() !== null) { }\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false);\n }\n resolve();\n };\n\n // Add a small delay to allow any buffered input to clear\n setTimeout(flush, 10);\n });\n}\n","{\n \"name\": \"@stackframe/init-stack\",\n \"version\": \"2.8.39\",\n \"description\": \"The setup wizard for Stack. https://stack-auth.com\",\n \"main\": \"dist/index.js\",\n \"type\": \"module\",\n \"bin\": \"./dist/index.js\",\n \"scripts\": {\n \"clean\": \"rimraf test-run-output && rimraf node_modules && rimraf dist\",\n \"build\": \"tsup\",\n \"dev\": \"tsup --watch\",\n \"lint\": \"eslint --ext .tsx,.ts .\",\n \"typecheck\": \"tsc --noEmit\",\n \"init-stack\": \"node dist/index.js\",\n \"init-stack:local\": \"STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE=../../stack STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE=../../js STACK_REACT_INSTALL_PACKAGE_NAME_OVERRIDE=../../react node dist/index.js\",\n \"test-run\": \"pnpm run build && pnpm run test-run-js && pnpm run test-run-node && pnpm run test-run-next && pnpm run test-run-neon && pnpm run test-run-no-browser\",\n \"test-run:manual\": \"pnpm run build && pnpm run test-run-js:manual && pnpm run test-run-node:manual && pnpm run test-run-next:manual && pnpm run test-run-neon:manual\",\n \"ensure-neon\": \"grep -q '\\\"@neondatabase/serverless\\\"' ./test-run-output/package.json && echo 'Initialized Neon successfully!'\",\n \"test-run-neon\": \"pnpm run test-run-node --neon && pnpm run ensure-neon\",\n \"test-run-neon:manual\": \"pnpm run test-run-node:manual --neon && pnpm run ensure-neon\",\n \"test-run-no-browser\": \"rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --agent-mode --js --server --npm --no-browser\",\n \"test-run-node:manual\": \"rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init && cd .. && pnpm run init-stack:local test-run-output\",\n \"test-run-node\": \"rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --agent-mode --js --server --npm --no-browser\",\n \"test-run-js:manual\": \"rimraf test-run-output && npx -y sv create test-run-output --no-install && pnpm run init-stack:local test-run-output\",\n \"test-run-js\": \"rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --agent-mode --js --client --npm --no-browser\",\n \"test-run-next:manual\": \"rimraf test-run-output && npx -y create-next-app@latest test-run-output && pnpm run init-stack:local test-run-output\",\n \"test-run-next\": \"rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --agent-mode --no-browser\",\n \"test-run-keys-next\": \"rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --agent-mode --project-id my-project-id --publishable-client-key my-publishable-client-key\",\n \"test-run-keys-js\": \"rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --agent-mode --js --client --npm --project-id my-project-id --publishable-client-key my-publishable-client-key\",\n \"test-run-react\": \"rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --agent-mode --no-browser --npm\",\n \"test-run-react:manual\": \"rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --react\"\n },\n \"files\": [\n \"README.md\",\n \"dist\",\n \"CHANGELOG.md\",\n \"LICENSE\"\n ],\n \"homepage\": \"https://stack-auth.com\",\n \"keywords\": [],\n \"author\": \"\",\n \"license\": \"MIT\",\n \"dependencies\": {\n \"@stackframe/stack-shared\": \"workspace:*\",\n \"commander\": \"^13.1.0\",\n \"inquirer\": \"^9.2.19\",\n \"open\": \"^10.1.0\",\n \"posthog-node\": \"^4.1.0\"\n },\n \"devDependencies\": {\n \"@types/inquirer\": \"^9.0.7\",\n \"@types/node\": \"20.17.6\",\n \"rimraf\": \"^6.0.1\",\n \"tsup\": \"^8.4.0\",\n \"typescript\": \"5.3.3\"\n }\n}\n"],"mappings":";;;AAAA,YAAY,mBAAmB;AAC/B,SAAS,eAAe;AACxB,YAAY,YAAY;AACxB,YAAY,QAAQ;AACpB,OAAO,cAAc;AACrB,OAAO,UAAU;AACjB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,eAAe;;;ACRxB;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,MAAQ;AAAA,EACR,KAAO;AAAA,EACP,SAAW;AAAA,IACT,OAAS;AAAA,IACT,OAAS;AAAA,IACT,KAAO;AAAA,IACP,MAAQ;AAAA,IACR,WAAa;AAAA,IACb,cAAc;AAAA,IACd,oBAAoB;AAAA,IACpB,YAAY;AAAA,IACZ,mBAAmB;AAAA,IACnB,eAAe;AAAA,IACf,iBAAiB;AAAA,IACjB,wBA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,EACnC;AACF;AAEA,SAAS,0BAA0B,UAAkB,SAAuB;AAC1E,oBAAkB,KAAK,YAAY;AACjC,UAAM,qBAAqB,UAAU,OAAO;AAAA,EAC9C,CAAC;AACH;AAEA,SAAS,SAAS,SAAwB;AACxC,QAAM,IAAI,MAAM,OAAO;AACzB;AAGO,SAAS,iBAAiB,YAAkC,QAAuB;AACxF,MAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,MAAI,OAAO,WAAW,QAAQ,SAAS,EAAG,OAAM,IAAI,MAAM,yDAAyD;AAEnH,SAAO,QAAQ,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,QAAQ,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,KAAK,KAAK,GAAG,MAAM,IAAI,QAAQ,CAAC,CAAC;AAC7G;AAEA,eAAe,aAA4B;AACzC,QAAM,IAAI,QAAc,CAAC,YAAY;AACnC,QAAI,QAAQ,MAAM,OAAO;AACvB,cAAQ,MAAM,WAAW,IAAI;AAAA,IAC/B;AACA,YAAQ,MAAM,OAAO;AACrB,YAAQ,MAAM,mBAAmB,MAAM;AAEvC,UAAM,QAAQ,MAAM;AAClB,aAAO,QAAQ,MAAM,KAAK,MAAM,MAAM;AAAA,MAAE;AACxC,UAAI,QAAQ,MAAM,OAAO;AACvB,gBAAQ,MAAM,WAAW,KAAK;AAAA,MAChC;AACA,cAAQ;AAAA,IACV;AAGA,eAAW,OAAO,EAAE;AAAA,EACtB,CAAC;AACH;","names":["options"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackframe/init-stack",
3
- "version": "2.8.35",
3
+ "version": "2.8.39",
4
4
  "description": "The setup wizard for Stack. https://stack-auth.com",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "inquirer": "^9.2.19",
21
21
  "open": "^10.1.0",
22
22
  "posthog-node": "^4.1.0",
23
- "@stackframe/stack-shared": "2.8.35"
23
+ "@stackframe/stack-shared": "2.8.39"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/inquirer": "^9.0.7",
@@ -36,18 +36,22 @@
36
36
  "lint": "eslint --ext .tsx,.ts .",
37
37
  "typecheck": "tsc --noEmit",
38
38
  "init-stack": "node dist/index.js",
39
- "init-stack:local": "STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE=../../stack STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE=../../js node dist/index.js",
39
+ "init-stack:local": "STACK_NEXT_INSTALL_PACKAGE_NAME_OVERRIDE=../../stack STACK_JS_INSTALL_PACKAGE_NAME_OVERRIDE=../../js STACK_REACT_INSTALL_PACKAGE_NAME_OVERRIDE=../../react node dist/index.js",
40
40
  "test-run": "pnpm run build && pnpm run test-run-js && pnpm run test-run-node && pnpm run test-run-next && pnpm run test-run-neon && pnpm run test-run-no-browser",
41
41
  "test-run:manual": "pnpm run build && pnpm run test-run-js:manual && pnpm run test-run-node:manual && pnpm run test-run-next:manual && pnpm run test-run-neon:manual",
42
42
  "ensure-neon": "grep -q '\"@neondatabase/serverless\"' ./test-run-output/package.json && echo 'Initialized Neon successfully!'",
43
43
  "test-run-neon": "pnpm run test-run-node --neon && pnpm run ensure-neon",
44
44
  "test-run-neon:manual": "pnpm run test-run-node:manual --neon && pnpm run ensure-neon",
45
- "test-run-no-browser": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --server --npm --no-browser",
45
+ "test-run-no-browser": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --agent-mode --js --server --npm --no-browser",
46
46
  "test-run-node:manual": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init && cd .. && pnpm run init-stack:local test-run-output",
47
- "test-run-node": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --server --npm",
47
+ "test-run-node": "rimraf test-run-output && mkdir test-run-output && cd test-run-output && npm init --init-author-name example-author --init-license UNLICENSED --init-author-url http://example.com --init-module test-run-output --init-version 1.0.0 -y && cd .. && pnpm run init-stack:local test-run-output --agent-mode --js --server --npm --no-browser",
48
48
  "test-run-js:manual": "rimraf test-run-output && npx -y sv create test-run-output --no-install && pnpm run init-stack:local test-run-output",
49
- "test-run-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output --js --client --npm",
49
+ "test-run-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --agent-mode --js --client --npm --no-browser",
50
50
  "test-run-next:manual": "rimraf test-run-output && npx -y create-next-app@latest test-run-output && pnpm run init-stack:local test-run-output",
51
- "test-run-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && STACK_DISABLE_INTERACTIVE=true pnpm run init-stack:local test-run-output"
51
+ "test-run-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --agent-mode --no-browser",
52
+ "test-run-keys-next": "rimraf test-run-output && npx -y create-next-app@latest test-run-output --app --ts --no-src-dir --tailwind --use-npm --eslint --import-alias '##@#/*' --turbopack && pnpm run init-stack:local test-run-output --agent-mode --project-id my-project-id --publishable-client-key my-publishable-client-key",
53
+ "test-run-keys-js": "rimraf test-run-output && npx -y sv create test-run-output --template minimal --types ts --no-add-ons --no-install && pnpm run init-stack:local test-run-output --agent-mode --js --client --npm --project-id my-project-id --publishable-client-key my-publishable-client-key",
54
+ "test-run-react": "rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --agent-mode --no-browser --npm",
55
+ "test-run-react:manual": "rimraf test-run-output && npx -y create-vite@latest test-run-output --template react-ts && pnpm run init-stack:local test-run-output --react"
52
56
  }
53
57
  }