sv 0.5.5 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -25,7 +25,7 @@ import require$$0$3 from 'events';
25
25
  import { t as templates, c as create$2 } from './index-A89HFWzv.js';
26
26
 
27
27
  var name = "sv";
28
- var version = "0.5.5";
28
+ var version = "0.5.7";
29
29
  var type = "module";
30
30
  var description = "A CLI for creating and updating SvelteKit projects";
31
31
  var license = "MIT";
@@ -48593,14 +48593,18 @@ var drizzle = defineAdder({
48593
48593
  }
48594
48594
  }
48595
48595
  ],
48596
- nextSteps: ({ options: options2, highlighter }) => {
48596
+ nextSteps: ({ options: options2, highlighter, packageManager }) => {
48597
48597
  const steps = [
48598
48598
  `You will need to set ${highlighter.env("DATABASE_URL")} in your production environment`
48599
48599
  ];
48600
48600
  if (options2.docker) {
48601
- steps.push(`Run ${highlighter.command("npm run db:start")} to start the docker container`);
48601
+ steps.push(
48602
+ `Run ${highlighter.command(`${packageManager} run db:start`)} to start the docker container`
48603
+ );
48602
48604
  }
48603
- steps.push(`Run ${highlighter.command("npm run db:push")} to update your database schema`);
48605
+ steps.push(
48606
+ `Run ${highlighter.command(`${packageManager} run db:push`)} to update your database schema`
48607
+ );
48604
48608
  return steps;
48605
48609
  }
48606
48610
  });
@@ -50700,8 +50704,10 @@ ${sessionType}`);
50700
50704
  }
50701
50705
  }
50702
50706
  ],
50703
- nextSteps: ({ highlighter, options: options2 }) => {
50704
- const steps = [`Run ${highlighter.command("npm run db:push")} to update your database schema`];
50707
+ nextSteps: ({ highlighter, options: options2, packageManager }) => {
50708
+ const steps = [
50709
+ `Run ${highlighter.command(`${packageManager} run db:push`)} to update your database schema`
50710
+ ];
50705
50711
  if (options2.demo) {
50706
50712
  steps.push(`Visit ${highlighter.route("/demo/lucia")} route to view the demo`);
50707
50713
  }
@@ -51687,55 +51693,40 @@ async function runCommand(action) {
51687
51693
  }
51688
51694
  }
51689
51695
  }
51690
- async function formatFiles(cwd, paths) {
51691
- const pm = detectPackageManager(cwd);
51692
- const args = ["prettier", "--write", "--ignore-unknown", ...paths];
51693
- const cmd = resolveCommand(pm, "execute-local", args);
51694
- await be(cmd.command, cmd.args, {
51695
- nodeOptions: { cwd, stdio: "pipe" }
51696
- });
51696
+ async function formatFiles(options) {
51697
+ const args = ["prettier", "--write", "--ignore-unknown", ...options.paths];
51698
+ const cmd = resolveCommand(options.packageManager, "execute-local", args);
51699
+ await be(cmd.command, cmd.args, { nodeOptions: { cwd: options.cwd, stdio: "pipe" } });
51697
51700
  }
51698
- async function suggestInstallingDependencies(cwd) {
51701
+ const agents = AGENTS.filter((agent) => !agent.includes("@"));
51702
+ const agentOptions = agents.map((pm) => ({ value: pm, label: pm }));
51703
+ agentOptions.unshift({ label: "None", value: void 0 });
51704
+ async function packageManagerPrompt(cwd) {
51699
51705
  const detected = detectSync({ cwd });
51700
- const agent = detected?.agent ?? getUserAgent() ?? null;
51701
- const agents = AGENTS.filter((agent2) => !agent2.includes("@"));
51702
- const options = agents.map((pm2) => ({ value: pm2, label: pm2 }));
51703
- options.unshift({ label: "None", value: null });
51706
+ const agent = detected?.name ?? getUserAgent();
51704
51707
  const pm = await select({
51705
51708
  message: "Which package manager do you want to install dependencies with?",
51706
- options,
51709
+ options: agentOptions,
51707
51710
  initialValue: agent
51708
51711
  });
51709
51712
  if (isCancel(pm)) {
51710
51713
  cancel("Operation cancelled.");
51711
51714
  process$1$1.exit(1);
51712
51715
  }
51713
- if (!pm) {
51714
- return "skipped";
51715
- }
51716
- const { command, args } = constructCommand(COMMANDS[pm].install, []);
51717
- const loadingSpinner = spinner();
51718
- loadingSpinner.start("Installing dependencies...");
51719
- await installDependencies(command, args, cwd);
51720
- packageManager = command;
51721
- loadingSpinner.stop("Successfully installed dependencies");
51722
- return "installed";
51716
+ return pm;
51723
51717
  }
51724
- async function installDependencies(command, args, cwd) {
51718
+ async function installDependencies(agent, cwd) {
51719
+ const spinner$1 = spinner();
51720
+ spinner$1.start("Installing dependencies...");
51725
51721
  try {
51722
+ const { command, args } = constructCommand(COMMANDS[agent].install, []);
51726
51723
  await be(command, args, { nodeOptions: { cwd } });
51724
+ spinner$1.stop("Successfully installed dependencies");
51727
51725
  } catch (error) {
51728
- const typedError = error;
51729
- throw new Error(`Unable to install dependencies: ${typedError.message}`);
51726
+ spinner$1.stop("Failed to install dependencies", 2);
51727
+ throw error;
51730
51728
  }
51731
51729
  }
51732
- let packageManager;
51733
- function detectPackageManager(cwd) {
51734
- if (packageManager) return packageManager;
51735
- const pm = detectSync({ cwd });
51736
- if (pm?.name) packageManager = pm.name;
51737
- return pm?.name ?? getUserAgent() ?? "npm";
51738
- }
51739
51730
  function getUserAgent() {
51740
51731
  const userAgent = process$1$1.env.npm_config_user_agent;
51741
51732
  if (!userAgent) return void 0;
@@ -55111,27 +55102,18 @@ function getHighlighter() {
55111
55102
  };
55112
55103
  }
55113
55104
 
55114
- function createEmptyWorkspace() {
55115
- return {
55116
- options: {},
55117
- cwd: "",
55118
- dependencyVersion: (_pkg) => void 0,
55119
- typescript: false,
55120
- kit: void 0
55121
- };
55122
- }
55123
- function createWorkspace(cwd) {
55124
- const workspace = createEmptyWorkspace();
55125
- workspace.cwd = path$3.resolve(cwd);
55126
- let usesTypescript = fs$3.existsSync(path$3.join(cwd, commonFilePaths.viteConfigTS));
55105
+ function createWorkspace({ cwd, packageManager }) {
55106
+ const resolvedCwd = path$3.resolve(cwd);
55107
+ const viteConfigPath = path$3.join(resolvedCwd, commonFilePaths.viteConfigTS);
55108
+ let usesTypescript = fs$3.existsSync(viteConfigPath);
55127
55109
  if (TESTING) {
55128
- usesTypescript || (usesTypescript = fs$3.existsSync(path$3.join(cwd, commonFilePaths.tsconfig)));
55110
+ usesTypescript || (usesTypescript = fs$3.existsSync(path$3.join(resolvedCwd, commonFilePaths.tsconfig)));
55129
55111
  } else {
55130
55112
  usesTypescript || (usesTypescript = up$1(commonFilePaths.tsconfig, { cwd }) !== void 0);
55131
55113
  }
55132
55114
  let dependencies = {};
55133
- let directory = workspace.cwd;
55134
- const root = findRoot(workspace.cwd);
55115
+ let directory = resolvedCwd;
55116
+ const root = findRoot(resolvedCwd);
55135
55117
  while (directory && directory !== root) {
55136
55118
  if (fs$3.existsSync(path$3.join(directory, commonFilePaths.packageJson))) {
55137
55119
  const { data: packageJson } = getPackageJson(directory);
@@ -55146,13 +55128,14 @@ function createWorkspace(cwd) {
55146
55128
  for (const [key, value] of Object.entries(dependencies)) {
55147
55129
  dependencies[key] = value.replaceAll(/[^\d|.]/g, "");
55148
55130
  }
55149
- workspace.dependencyVersion = (pkg) => {
55150
- return dependencies[pkg];
55131
+ return {
55132
+ kit: dependencies["@sveltejs/kit"] ? parseKitOptions(resolvedCwd) : void 0,
55133
+ packageManager: packageManager ?? getUserAgent() ?? "npm",
55134
+ cwd: resolvedCwd,
55135
+ dependencyVersion: (pkg) => dependencies[pkg],
55136
+ typescript: usesTypescript,
55137
+ options: {}
55151
55138
  };
55152
- workspace.typescript = usesTypescript;
55153
- workspace.packageManager = detectPackageManager(cwd);
55154
- if (workspace.dependencyVersion("@sveltejs/kit")) workspace.kit = parseKitOptions(workspace);
55155
- return workspace;
55156
55139
  }
55157
55140
  function findRoot(cwd) {
55158
55141
  const { root } = path$3.parse(cwd);
@@ -55171,8 +55154,8 @@ function findRoot(cwd) {
55171
55154
  }
55172
55155
  return root;
55173
55156
  }
55174
- function parseKitOptions(workspace) {
55175
- const configSource = readFile(workspace.cwd, commonFilePaths.svelteConfig);
55157
+ function parseKitOptions(cwd) {
55158
+ const configSource = readFile(cwd, commonFilePaths.svelteConfig);
55176
55159
  const { ast } = parseScript(configSource);
55177
55160
  const defaultExport = ast.body.find((s) => s.type === "ExportDefaultDeclaration");
55178
55161
  if (!defaultExport) throw Error("Missing default export in `svelte.config.js`");
@@ -55409,7 +55392,7 @@ Available options: ${communityAdderIds.join(", ")}`
55409
55392
  }
55410
55393
  }
55411
55394
  if (selectedAdders.length === 0) {
55412
- const workspace2 = createWorkspace(options.cwd);
55395
+ const workspace2 = createWorkspace({ cwd: options.cwd });
55413
55396
  const projectType = workspace2.kit ? "kit" : "svelte";
55414
55397
  const adderOptions = officialAdders.map((adder) => {
55415
55398
  if (projectType === "kit" && !adder.environments.kit) return;
@@ -55433,7 +55416,7 @@ Available options: ${communityAdderIds.join(", ")}`
55433
55416
  }
55434
55417
  for (const { adder } of selectedAdders) {
55435
55418
  const dependents = adder.dependsOn?.filter((dep) => !selectedAdders.some((a) => a.adder.id === dep)) ?? [];
55436
- const workspace2 = createWorkspace(options.cwd);
55419
+ const workspace2 = createWorkspace({ cwd: options.cwd });
55437
55420
  for (const depId of dependents) {
55438
55421
  const dependent = officialAdders.find((a) => a.id === depId);
55439
55422
  if (!dependent) throw new Error(`Adder '${adder.id}' depends on an invalid '${depId}'`);
@@ -55454,7 +55437,7 @@ Available options: ${communityAdderIds.join(", ")}`
55454
55437
  }
55455
55438
  }
55456
55439
  if (options.preconditions && selectedAdders.length > 0) {
55457
- const { kit } = createWorkspace(options.cwd);
55440
+ const { kit } = createWorkspace({ cwd: options.cwd });
55458
55441
  const projectType = kit ? "kit" : "svelte";
55459
55442
  const adders = selectedAdders.map(({ adder }) => adder);
55460
55443
  const { preconditions } = getGlobalPreconditions(options.cwd, projectType, adders);
@@ -55529,21 +55512,22 @@ Available options: ${communityAdderIds.join(", ")}`
55529
55512
  values[questionId] = answer;
55530
55513
  }
55531
55514
  }
55532
- let filesToFormat = [];
55533
- if (Object.keys({ ...official, ...community }).length > 0) {
55534
- filesToFormat = await runAdders({ cwd: options.cwd, official, community });
55535
- log$1.success("Successfully setup integrations");
55515
+ if (selectedAdders.length === 0) return { packageManager: null };
55516
+ let packageManager;
55517
+ if (options.install) {
55518
+ packageManager = await packageManagerPrompt(options.cwd);
55536
55519
  }
55537
- let depsStatus = "skipped";
55538
- if (options.install && selectedAdders.length > 0) {
55539
- depsStatus = await suggestInstallingDependencies(options.cwd);
55520
+ const filesToFormat = await runAdders({ cwd: options.cwd, packageManager, official, community });
55521
+ log$1.success("Successfully setup integrations");
55522
+ if (packageManager && options.install) {
55523
+ await installDependencies(packageManager, options.cwd);
55540
55524
  }
55541
- const workspace = createWorkspace(options.cwd);
55542
- if (filesToFormat.length > 0 && depsStatus === "installed" && !!workspace.dependencyVersion("prettier")) {
55525
+ const workspace = createWorkspace({ cwd: options.cwd, packageManager });
55526
+ if (filesToFormat.length > 0 && packageManager && !!workspace.dependencyVersion("prettier")) {
55543
55527
  const { start, stop } = spinner();
55544
55528
  start("Formatting modified files");
55545
55529
  try {
55546
- await formatFiles(options.cwd, filesToFormat);
55530
+ await formatFiles({ packageManager, cwd: options.cwd, paths: filesToFormat });
55547
55531
  stop("Successfully formatted modified files");
55548
55532
  } catch (e) {
55549
55533
  stop("Failed to format files");
@@ -55565,12 +55549,13 @@ Available options: ${communityAdderIds.join(", ")}`
55565
55549
  adderMessage += `- ${adderNextSteps.join("\n- ")}`;
55566
55550
  return adderMessage;
55567
55551
  }).join("\n\n") || void 0;
55568
- return { nextSteps };
55552
+ return { nextSteps, packageManager };
55569
55553
  }
55570
55554
  async function runAdders({
55571
55555
  cwd,
55572
55556
  official = {},
55573
- community = {}
55557
+ community = {},
55558
+ packageManager
55574
55559
  }) {
55575
55560
  const adderDetails = Object.keys(official).map((id) => getAdderDetails(id));
55576
55561
  const commDetails = Object.keys(community).map(
@@ -55585,7 +55570,7 @@ async function runAdders({
55585
55570
  const filesToFormat = /* @__PURE__ */ new Set();
55586
55571
  for (const config of details) {
55587
55572
  const adderId = config.id;
55588
- const workspace = createWorkspace(cwd);
55573
+ const workspace = createWorkspace({ cwd, packageManager });
55589
55574
  workspace.options = official[adderId] ?? community[adderId];
55590
55575
  await config.preInstall?.(workspace);
55591
55576
  const pkgPath = installPackages(config, workspace);
@@ -55707,12 +55692,12 @@ const create = new Command("create").description("scaffolds a new SvelteKit proj
55707
55692
  const cwd = parse$8(ProjectPathSchema, projectPath);
55708
55693
  const options = parse$8(OptionsSchema, opts);
55709
55694
  runCommand(async () => {
55710
- const { directory, integrationNextSteps } = await createProject(cwd, options);
55695
+ const { directory, integrationNextSteps, packageManager } = await createProject(cwd, options);
55711
55696
  const highlight = (str) => pc.bold(pc.cyan(str));
55712
55697
  let i = 1;
55713
55698
  const initialSteps = [];
55714
55699
  const relative = path$3.relative(process$1$1.cwd(), directory);
55715
- const pm = detectPackageManager(cwd);
55700
+ const pm = packageManager ?? detectSync({ cwd })?.name ?? getUserAgent() ?? "npm";
55716
55701
  if (relative !== "") {
55717
55702
  initialSteps.push(`${i++}: ${highlight(`cd ${relative}`)}`);
55718
55703
  }
@@ -55792,18 +55777,26 @@ async function createProject(cwd, options) {
55792
55777
  types: language
55793
55778
  });
55794
55779
  log$1.success("Project created");
55780
+ let packageManager;
55795
55781
  let integrationNextSteps;
55782
+ const installDeps = async () => {
55783
+ packageManager = await packageManagerPrompt(projectPath);
55784
+ if (packageManager) await installDependencies(packageManager, projectPath);
55785
+ };
55796
55786
  if (options.integrations) {
55797
- const { nextSteps } = await runAddCommand(
55798
- { cwd: projectPath, install: false, preconditions: true, community: [] },
55787
+ const { nextSteps, packageManager: pm } = await runAddCommand(
55788
+ { cwd: projectPath, install: options.install, preconditions: true, community: [] },
55799
55789
  []
55800
55790
  );
55791
+ packageManager = pm;
55801
55792
  integrationNextSteps = nextSteps;
55793
+ } else if (options.install) {
55794
+ await installDeps();
55802
55795
  }
55803
- if (options.install) {
55804
- await suggestInstallingDependencies(projectPath);
55796
+ if (packageManager === null && options.install) {
55797
+ await installDeps();
55805
55798
  }
55806
- return { directory: projectPath, integrationNextSteps };
55799
+ return { directory: projectPath, integrationNextSteps, packageManager };
55807
55800
  }
55808
55801
 
55809
55802
  const migrate = new Command("migrate").description("a CLI for migrating Svelte(Kit) codebases").argument("<migration>", "migration to run").option("-C, --cwd <path>", "path to working directory", process$1$1.cwd()).configureHelp({