create-astro 4.8.0 → 4.8.2

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/index.js CHANGED
@@ -1,176 +1,6 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
- // If the importer is in node compatibility mode or this is not an ESM
20
- // file that has been converted to a CommonJS file using a Babel-
21
- // compatible transform (i.e. "__esModule" has not been set), then set
22
- // "default" to the CommonJS "module.exports" for node compatibility.
23
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
- mod
25
- ));
26
-
27
- // ../../node_modules/.pnpm/arg@5.0.2/node_modules/arg/index.js
28
- var require_arg = __commonJS({
29
- "../../node_modules/.pnpm/arg@5.0.2/node_modules/arg/index.js"(exports, module) {
30
- var flagSymbol = Symbol("arg flag");
31
- var ArgError = class _ArgError extends Error {
32
- constructor(msg, code) {
33
- super(msg);
34
- this.name = "ArgError";
35
- this.code = code;
36
- Object.setPrototypeOf(this, _ArgError.prototype);
37
- }
38
- };
39
- function arg2(opts, {
40
- argv = process.argv.slice(2),
41
- permissive = false,
42
- stopAtPositional = false
43
- } = {}) {
44
- if (!opts) {
45
- throw new ArgError(
46
- "argument specification object is required",
47
- "ARG_CONFIG_NO_SPEC"
48
- );
49
- }
50
- const result = { _: [] };
51
- const aliases = {};
52
- const handlers = {};
53
- for (const key of Object.keys(opts)) {
54
- if (!key) {
55
- throw new ArgError(
56
- "argument key cannot be an empty string",
57
- "ARG_CONFIG_EMPTY_KEY"
58
- );
59
- }
60
- if (key[0] !== "-") {
61
- throw new ArgError(
62
- `argument key must start with '-' but found: '${key}'`,
63
- "ARG_CONFIG_NONOPT_KEY"
64
- );
65
- }
66
- if (key.length === 1) {
67
- throw new ArgError(
68
- `argument key must have a name; singular '-' keys are not allowed: ${key}`,
69
- "ARG_CONFIG_NONAME_KEY"
70
- );
71
- }
72
- if (typeof opts[key] === "string") {
73
- aliases[key] = opts[key];
74
- continue;
75
- }
76
- let type = opts[key];
77
- let isFlag = false;
78
- if (Array.isArray(type) && type.length === 1 && typeof type[0] === "function") {
79
- const [fn] = type;
80
- type = (value, name, prev = []) => {
81
- prev.push(fn(value, name, prev[prev.length - 1]));
82
- return prev;
83
- };
84
- isFlag = fn === Boolean || fn[flagSymbol] === true;
85
- } else if (typeof type === "function") {
86
- isFlag = type === Boolean || type[flagSymbol] === true;
87
- } else {
88
- throw new ArgError(
89
- `type missing or not a function or valid array type: ${key}`,
90
- "ARG_CONFIG_VAD_TYPE"
91
- );
92
- }
93
- if (key[1] !== "-" && key.length > 2) {
94
- throw new ArgError(
95
- `short argument keys (with a single hyphen) must have only one character: ${key}`,
96
- "ARG_CONFIG_SHORTOPT_TOOLONG"
97
- );
98
- }
99
- handlers[key] = [type, isFlag];
100
- }
101
- for (let i = 0, len = argv.length; i < len; i++) {
102
- const wholeArg = argv[i];
103
- if (stopAtPositional && result._.length > 0) {
104
- result._ = result._.concat(argv.slice(i));
105
- break;
106
- }
107
- if (wholeArg === "--") {
108
- result._ = result._.concat(argv.slice(i + 1));
109
- break;
110
- }
111
- if (wholeArg.length > 1 && wholeArg[0] === "-") {
112
- const separatedArguments = wholeArg[1] === "-" || wholeArg.length === 2 ? [wholeArg] : wholeArg.slice(1).split("").map((a) => `-${a}`);
113
- for (let j = 0; j < separatedArguments.length; j++) {
114
- const arg3 = separatedArguments[j];
115
- const [originalArgName, argStr] = arg3[1] === "-" ? arg3.split(/=(.*)/, 2) : [arg3, void 0];
116
- let argName = originalArgName;
117
- while (argName in aliases) {
118
- argName = aliases[argName];
119
- }
120
- if (!(argName in handlers)) {
121
- if (permissive) {
122
- result._.push(arg3);
123
- continue;
124
- } else {
125
- throw new ArgError(
126
- `unknown or unexpected option: ${originalArgName}`,
127
- "ARG_UNKNOWN_OPTION"
128
- );
129
- }
130
- }
131
- const [type, isFlag] = handlers[argName];
132
- if (!isFlag && j + 1 < separatedArguments.length) {
133
- throw new ArgError(
134
- `option requires argument (but was followed by another short argument): ${originalArgName}`,
135
- "ARG_MISSING_REQUIRED_SHORTARG"
136
- );
137
- }
138
- if (isFlag) {
139
- result[argName] = type(true, argName, result[argName]);
140
- } else if (argStr === void 0) {
141
- if (argv.length < i + 2 || argv[i + 1].length > 1 && argv[i + 1][0] === "-" && !(argv[i + 1].match(/^-?\d*(\.(?=\d))?\d*$/) && (type === Number || // eslint-disable-next-line no-undef
142
- typeof BigInt !== "undefined" && type === BigInt))) {
143
- const extended = originalArgName === argName ? "" : ` (alias for ${argName})`;
144
- throw new ArgError(
145
- `option requires argument: ${originalArgName}${extended}`,
146
- "ARG_MISSING_REQUIRED_LONGARG"
147
- );
148
- }
149
- result[argName] = type(argv[i + 1], argName, result[argName]);
150
- ++i;
151
- } else {
152
- result[argName] = type(argStr, argName, result[argName]);
153
- }
154
- }
155
- } else {
156
- result._.push(wholeArg);
157
- }
158
- }
159
- return result;
160
- }
161
- arg2.flag = (fn) => {
162
- fn[flagSymbol] = true;
163
- return fn;
164
- };
165
- arg2.COUNT = arg2.flag((v, name, existingCount) => (existingCount || 0) + 1);
166
- arg2.ArgError = ArgError;
167
- module.exports = arg2;
168
- }
169
- });
170
-
171
1
  // src/actions/context.ts
172
- var import_arg = __toESM(require_arg(), 1);
173
2
  import os from "node:os";
3
+ import { parseArgs } from "node:util";
174
4
  import { prompt } from "@astrojs/cli-kit";
175
5
  import { random } from "@astrojs/cli-kit/utils";
176
6
 
@@ -270,17 +100,15 @@ function getSeason() {
270
100
  }
271
101
  }
272
102
  function rarity(frequency, emoji) {
273
- if (frequency === 1)
274
- return emoji;
275
- if (frequency === 0)
276
- return [""];
103
+ if (frequency === 1) return emoji;
104
+ if (frequency === 0) return [""];
277
105
  const empty = Array.from({ length: Math.round(emoji.length * frequency) }, () => "");
278
106
  return [...emoji, ...empty];
279
107
  }
280
108
 
281
109
  // src/messages.ts
282
110
  import { exec } from "node:child_process";
283
- import { color, label, say as houston, spinner as load } from "@astrojs/cli-kit";
111
+ import { color, say as houston, label, spinner as load } from "@astrojs/cli-kit";
284
112
  import { align, sleep } from "@astrojs/cli-kit/utils";
285
113
 
286
114
  // ../../node_modules/.pnpm/ansi-regex@6.0.1/node_modules/ansi-regex/index.js
@@ -319,7 +147,7 @@ async function shell(command, flags, opts = {}) {
319
147
  const done = new Promise((resolve) => child.on("close", resolve));
320
148
  [stdout2, stderr] = await Promise.all([text(child.stdout), text(child.stderr)]);
321
149
  await done;
322
- } catch (e) {
150
+ } catch {
323
151
  throw { stdout: stdout2, stderr, exitCode: 1 };
324
152
  }
325
153
  const { exitCode } = child;
@@ -335,15 +163,13 @@ async function shell(command, flags, opts = {}) {
335
163
  // src/messages.ts
336
164
  var _registry;
337
165
  async function getRegistry(packageManager) {
338
- if (_registry)
339
- return _registry;
166
+ if (_registry) return _registry;
340
167
  const fallback = "https://registry.npmjs.org";
341
168
  try {
342
169
  const { stdout: stdout2 } = await shell(packageManager, ["config", "get", "registry"]);
343
170
  _registry = stdout2?.trim()?.replace(/\/$/, "") || fallback;
344
- if (!new URL(_registry).host)
345
- _registry = fallback;
346
- } catch (e) {
171
+ if (!new URL(_registry).host) _registry = fallback;
172
+ } catch {
347
173
  _registry = fallback;
348
174
  }
349
175
  return _registry;
@@ -467,7 +293,7 @@ function printHelp({
467
293
  if (headline) {
468
294
  message.push(
469
295
  linebreak(),
470
- `${title(commandName)} ${color.green(`v${"4.8.0"}`)} ${headline}`
296
+ `${title(commandName)} ${color.green(`v${"4.8.2"}`)} ${headline}`
471
297
  );
472
298
  }
473
299
  if (usage) {
@@ -492,62 +318,70 @@ function printHelp({
492
318
 
493
319
  // src/actions/context.ts
494
320
  async function getContext(argv) {
495
- const flags = (0, import_arg.default)(
496
- {
497
- "--template": String,
498
- "--ref": String,
499
- "--yes": Boolean,
500
- "--no": Boolean,
501
- "--install": Boolean,
502
- "--no-install": Boolean,
503
- "--git": Boolean,
504
- "--no-git": Boolean,
505
- "--typescript": String,
506
- "--skip-houston": Boolean,
507
- "--dry-run": Boolean,
508
- "--help": Boolean,
509
- "--fancy": Boolean,
510
- "-y": "--yes",
511
- "-n": "--no",
512
- "-h": "--help"
513
- },
514
- { argv, permissive: true }
515
- );
321
+ const args = parseArgs({
322
+ args: argv,
323
+ allowPositionals: true,
324
+ strict: false,
325
+ options: {
326
+ template: { type: "string" },
327
+ ref: { type: "string" },
328
+ yes: { type: "boolean", short: "y" },
329
+ no: { type: "boolean", short: "n" },
330
+ install: { type: "boolean" },
331
+ "no-install": { type: "boolean" },
332
+ git: { type: "boolean" },
333
+ "no-git": { type: "boolean" },
334
+ typescript: { type: "string" },
335
+ "skip-houston": { type: "boolean" },
336
+ "dry-run": { type: "boolean" },
337
+ help: { type: "boolean", short: "h" },
338
+ fancy: { type: "boolean" }
339
+ }
340
+ });
516
341
  const packageManager = detectPackageManager() ?? "npm";
517
- let cwd = flags["_"][0];
342
+ const projectName2 = args.positionals[0];
518
343
  let {
519
- "--help": help2 = false,
520
- "--template": template2,
521
- "--no": no,
522
- "--yes": yes,
523
- "--install": install2,
524
- "--no-install": noInstall,
525
- "--git": git2,
526
- "--no-git": noGit,
527
- "--typescript": typescript2,
528
- "--fancy": fancy,
529
- "--skip-houston": skipHouston,
530
- "--dry-run": dryRun,
531
- "--ref": ref
532
- } = flags;
533
- let projectName2 = cwd;
344
+ help: help2,
345
+ template: template2,
346
+ no,
347
+ yes,
348
+ install: install2,
349
+ "no-install": noInstall,
350
+ git: git2,
351
+ "no-git": noGit,
352
+ typescript: typescript2,
353
+ fancy,
354
+ "skip-houston": skipHouston,
355
+ "dry-run": dryRun,
356
+ ref
357
+ } = args.values;
534
358
  if (no) {
535
359
  yes = false;
536
- if (install2 == void 0)
537
- install2 = false;
538
- if (git2 == void 0)
539
- git2 = false;
540
- if (typescript2 == void 0)
541
- typescript2 = "strict";
360
+ if (install2 == void 0) install2 = false;
361
+ if (git2 == void 0) git2 = false;
362
+ if (typescript2 == void 0) typescript2 = "strict";
542
363
  }
364
+ skipHouston = typeof skipHouston == "boolean" ? skipHouston : void 0;
543
365
  skipHouston = (os.platform() === "win32" && !fancy || skipHouston) ?? [yes, no, install2, git2, typescript2].some((v) => v !== void 0);
366
+ help2 = !!help2;
367
+ template2 = typeof template2 == "string" ? template2 : void 0;
368
+ no = !!no;
369
+ yes = !!yes;
370
+ install2 = !!install2;
371
+ noInstall = !!noInstall;
372
+ git2 = !!git2;
373
+ noGit = !!noGit;
374
+ typescript2 = typeof typescript2 == "string" ? typescript2 : void 0;
375
+ fancy = !!fancy;
376
+ dryRun = !!dryRun;
377
+ ref = typeof ref == "string" ? ref : void 0;
544
378
  const { messages, hats, ties } = getSeasonalHouston({ fancy });
545
379
  const context = {
546
380
  help: help2,
547
381
  prompt,
548
382
  packageManager,
549
383
  username: getName(),
550
- version: getVersion(packageManager, "astro", "4.6.0"),
384
+ version: getVersion(packageManager, "astro", "4.14.0"),
551
385
  skipHouston,
552
386
  fancy,
553
387
  dryRun,
@@ -561,7 +395,7 @@ async function getContext(argv) {
561
395
  install: install2 ?? (noInstall ? false : void 0),
562
396
  git: git2 ?? (noGit ? false : void 0),
563
397
  typescript: typescript2,
564
- cwd,
398
+ cwd: projectName2,
565
399
  exit(code) {
566
400
  process.exit(code);
567
401
  },
@@ -570,8 +404,7 @@ async function getContext(argv) {
570
404
  return context;
571
405
  }
572
406
  function detectPackageManager() {
573
- if (!process.env.npm_config_user_agent)
574
- return;
407
+ if (!process.env.npm_config_user_agent) return;
575
408
  const specifier = process.env.npm_config_user_agent.split(" ")[0];
576
409
  const name = specifier.substring(0, specifier.lastIndexOf("/"));
577
410
  return name === "npminstall" ? "cnpm" : name;
@@ -623,14 +456,12 @@ async function dependencies(ctx) {
623
456
  }
624
457
  }
625
458
  async function install({ packageManager, cwd }) {
626
- if (packageManager === "yarn")
627
- await ensureYarnLock({ cwd });
459
+ if (packageManager === "yarn") await ensureYarnLock({ cwd });
628
460
  return shell(packageManager, ["install"], { cwd, timeout: 9e4, stdio: "ignore" });
629
461
  }
630
462
  async function ensureYarnLock({ cwd }) {
631
463
  const yarnLock = path.join(cwd, "yarn.lock");
632
- if (fs.existsSync(yarnLock))
633
- return;
464
+ if (fs.existsSync(yarnLock)) return;
634
465
  return fs.promises.writeFile(yarnLock, "", { encoding: "utf-8" });
635
466
  }
636
467
 
@@ -687,7 +518,7 @@ async function init({ cwd }) {
687
518
  ],
688
519
  { cwd, stdio: "ignore" }
689
520
  );
690
- } catch (e) {
521
+ } catch {
691
522
  }
692
523
  }
693
524
 
@@ -802,8 +633,7 @@ function isValidName(projectName2) {
802
633
  return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(projectName2);
803
634
  }
804
635
  function toValidName(projectName2) {
805
- if (isValidName(projectName2))
806
- return projectName2;
636
+ if (isValidName(projectName2)) return projectName2;
807
637
  return projectName2.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z\d\-~]+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
808
638
  }
809
639
 
@@ -871,8 +701,7 @@ import path5 from "node:path";
871
701
  import { color as color6 } from "@astrojs/cli-kit";
872
702
  import { downloadTemplate } from "giget";
873
703
  async function template(ctx) {
874
- if (!ctx.template && ctx.yes)
875
- ctx.template = "basics";
704
+ if (!ctx.template && ctx.yes) ctx.template = "basics";
876
705
  if (ctx.template) {
877
706
  await info("tmpl", `Using ${color6.reset(ctx.template)}${color6.dim(" as project template")}`);
878
707
  } else {
@@ -932,8 +761,7 @@ function getTemplateTarget(tmpl, ref = "latest") {
932
761
  return `withastro/starlight/examples/${starter}`;
933
762
  }
934
763
  const isThirdParty = tmpl.includes("/");
935
- if (isThirdParty)
936
- return tmpl;
764
+ if (isThirdParty) return tmpl;
937
765
  return `github:withastro/astro/examples/${tmpl}#${ref}`;
938
766
  }
939
767
  async function copyTemplate(tmpl, ctx) {
@@ -953,11 +781,22 @@ async function copyTemplate(tmpl, ctx) {
953
781
  } catch (_) {
954
782
  }
955
783
  }
956
- if (err.message.includes("404")) {
784
+ if (err.message?.includes("404")) {
957
785
  throw new Error(`Template ${color6.reset(tmpl)} ${color6.dim("does not exist!")}`);
958
- } else {
959
- throw new Error(err.message);
960
786
  }
787
+ if (err.message) {
788
+ error("error", err.message);
789
+ }
790
+ try {
791
+ if ("cause" in err) {
792
+ error("error", err.cause);
793
+ if ("cause" in err.cause) {
794
+ error("error", err.cause?.cause);
795
+ }
796
+ }
797
+ } catch {
798
+ }
799
+ throw new Error(`Unable to download template ${color6.reset(tmpl)}`);
961
800
  }
962
801
  if (fs4.readdirSync(ctx.cwd).length === 0) {
963
802
  throw new Error(`Template ${color6.reset(tmpl)} ${color6.dim("is empty!")}`);
@@ -1142,18 +981,16 @@ var FILES_TO_UPDATE2 = {
1142
981
  parsedPackageJson.scripts.build = `astro check && ${buildScript}`;
1143
982
  }
1144
983
  const [astroCheckVersion, typescriptVersion] = await Promise.all([
1145
- getVersion(options.ctx.packageManager, "@astrojs/check", "0.5.8"),
1146
- getVersion(options.ctx.packageManager, "typescript", "5.2.2")
984
+ getVersion(options.ctx.packageManager, "@astrojs/check", "0.9.2"),
985
+ getVersion(options.ctx.packageManager, "typescript", "5.5.4")
1147
986
  ]);
1148
987
  parsedPackageJson.dependencies ??= {};
1149
988
  parsedPackageJson.dependencies["@astrojs/check"] = `^${astroCheckVersion}`;
1150
989
  parsedPackageJson.dependencies.typescript = `^${typescriptVersion}`;
1151
990
  await writeFile(file, JSON.stringify(parsedPackageJson, null, indent), "utf-8");
1152
991
  } catch (err) {
1153
- if (err && err.code === "ENOENT")
1154
- return;
1155
- if (err instanceof Error)
1156
- throw new Error(err.message);
992
+ if (err && err.code === "ENOENT") return;
993
+ if (err instanceof Error) throw new Error(err.message);
1157
994
  }
1158
995
  },
1159
996
  "tsconfig.json": async (file, options) => {
@@ -1235,9 +1072,8 @@ async function verifyTemplate(tmpl, ref) {
1235
1072
  }
1236
1073
  var GIT_RE = /^(?<repo>[\w.-]+\/[\w.-]+)(?<subdir>[^#]+)?(?<ref>#[\w.-]+)?/;
1237
1074
  function parseGitURI(input) {
1238
- const m = input.match(GIT_RE)?.groups;
1239
- if (!m)
1240
- throw new Error(`Unable to parse "${input}"`);
1075
+ const m = GIT_RE.exec(input)?.groups;
1076
+ if (!m) throw new Error(`Unable to parse "${input}"`);
1241
1077
  return {
1242
1078
  repo: m.repo,
1243
1079
  subdir: m.subdir || "/",
@@ -1251,7 +1087,7 @@ process.on("SIGINT", exit);
1251
1087
  process.on("SIGTERM", exit);
1252
1088
  async function main() {
1253
1089
  console.log("");
1254
- const cleanArgv = process.argv.slice(2).filter((arg2) => arg2 !== "--");
1090
+ const cleanArgv = process.argv.slice(2).filter((arg) => arg !== "--");
1255
1091
  const ctx = await getContext(cleanArgv);
1256
1092
  if (ctx.help) {
1257
1093
  help();
package/dist/shell.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { StdioOptions } from 'node:child_process';
3
2
  export interface ExecaOptions {
4
3
  cwd?: string | URL;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-astro",
3
- "version": "4.8.0",
3
+ "version": "4.8.2",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
27
27
  "dependencies": {
28
28
  "@astrojs/cli-kit": "^0.4.1",
29
- "giget": "1.1.3"
29
+ "giget": "1.2.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "arg": "^5.0.2",