create-astro 5.0.0-beta.2 → 5.0.0-beta.4

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.
Files changed (2) hide show
  1. package/dist/index.js +41 -10
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -295,7 +295,7 @@ async function shell(command, flags, opts = {}) {
295
295
  let stdout2 = "";
296
296
  let stderr = "";
297
297
  try {
298
- child = spawn(`${command} ${flags.join(" ")}`, {
298
+ child = spawn(command, flags, {
299
299
  cwd: opts.cwd,
300
300
  shell: true,
301
301
  stdio: opts.stdio,
@@ -355,8 +355,15 @@ var getName = () => new Promise((resolve) => {
355
355
  var getVersion = (packageManager, packageName, packageTag = "latest", fallback = "") => new Promise(async (resolve) => {
356
356
  let registry = await getRegistry(packageManager);
357
357
  const { version } = await fetch(`${registry}/${packageName}/${packageTag}`, {
358
- redirect: "follow"
359
- }).then((res) => res.json()).catch(() => ({ version: fallback }));
358
+ redirect: "follow",
359
+ signal: AbortSignal.timeout(1e4)
360
+ }).then((res) => res.json()).catch(() => {
361
+ const fallbackName = fallback || `'latest'`;
362
+ console.warn(
363
+ `Unable to fetch latest ${packageName} version from the npm registry. Using ${fallbackName} instead.`
364
+ );
365
+ return { version: fallback };
366
+ });
360
367
  return resolve(version);
361
368
  });
362
369
  var log = (message) => stdout.write(message + "\n");
@@ -445,7 +452,7 @@ function printHelp({
445
452
  if (headline) {
446
453
  message.push(
447
454
  linebreak(),
448
- `${title(commandName)} ${color.green(`v${"5.0.0-beta.2"}`)} ${headline}`
455
+ `${title(commandName)} ${color.green(`v${"5.0.0-beta.4"}`)} ${headline}`
449
456
  );
450
457
  }
451
458
  if (usage) {
@@ -521,6 +528,12 @@ async function getContext(argv) {
521
528
  "--ref": ref,
522
529
  "--add": add
523
530
  } = flags;
531
+ if (add?.length && noInstall) {
532
+ console.error(
533
+ "The --add flag requires dependencies to be installed. Remove --no-install or run `astro add` manually after installation."
534
+ );
535
+ process.exit(1);
536
+ }
524
537
  let projectName2 = cwd;
525
538
  if (no) {
526
539
  yes = false;
@@ -538,7 +551,7 @@ async function getContext(argv) {
538
551
  packageManager,
539
552
  "astro",
540
553
  getPackageTag(packageSpecifier),
541
- "6.0.0-beta.3"
554
+ "6.0.0-beta.10"
542
555
  ),
543
556
  skipHouston,
544
557
  fancy,
@@ -571,6 +584,21 @@ function detectPackageManager() {
571
584
  // src/actions/dependencies.ts
572
585
  import fs from "node:fs";
573
586
  import path from "node:path";
587
+
588
+ // ../internal-helpers/dist/cli.js
589
+ var NPM_PACKAGE_NAME_REGEX = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
590
+ function validatePackageName(packageName) {
591
+ return NPM_PACKAGE_NAME_REGEX.test(packageName);
592
+ }
593
+ function assertValidPackageName(packageName) {
594
+ if (!validatePackageName(packageName)) {
595
+ throw new Error(
596
+ `Invalid package name "${packageName}". Package names must follow npm naming rules: lowercase letters, numbers, hyphens, underscores, and dots. Scoped packages like @org/package are also supported.`
597
+ );
598
+ }
599
+ }
600
+
601
+ // src/actions/dependencies.ts
574
602
  import { color as color2 } from "@astrojs/cli-kit";
575
603
  async function dependencies(ctx) {
576
604
  let deps = ctx.install ?? ctx.yes;
@@ -586,6 +614,11 @@ async function dependencies(ctx) {
586
614
  ctx.install = deps;
587
615
  }
588
616
  ctx.add = ctx.add?.reduce((acc, item) => acc.concat(item.split(",")), []);
617
+ if (ctx.add) {
618
+ for (const addValue of ctx.add) {
619
+ assertValidPackageName(addValue);
620
+ }
621
+ }
589
622
  if (ctx.dryRun) {
590
623
  await info(
591
624
  "--dry-run",
@@ -638,11 +671,9 @@ async function astroAdd({
638
671
  cwd
639
672
  }) {
640
673
  if (packageManager === "yarn") await ensureYarnLock({ cwd });
641
- return shell(
642
- packageManager === "npm" ? "npx" : `${packageManager} dlx`,
643
- ["astro add", integrations.join(" "), "-y"],
644
- { cwd, timeout: 9e4, stdio: "ignore" }
645
- );
674
+ const command = packageManager === "npm" ? "npx" : packageManager;
675
+ const args = packageManager === "npm" ? ["astro", "add", ...integrations, "-y"] : ["dlx", "astro", "add", ...integrations, "-y"];
676
+ return shell(command, args, { cwd, timeout: 9e4, stdio: "ignore" });
646
677
  }
647
678
  async function install({ packageManager, cwd }) {
648
679
  if (packageManager === "yarn") await ensureYarnLock({ cwd });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "5.0.0-beta.2",
3
+ "version": "5.0.0-beta.4",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -30,6 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "arg": "^5.0.2",
33
+ "@astrojs/internal-helpers": "0.8.0-beta.1",
33
34
  "astro-scripts": "0.0.14"
34
35
  },
35
36
  "engines": {