sv 0.10.7 → 0.10.8

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.
@@ -1,18 +1,29 @@
1
1
  #!/usr/bin/env node
2
- import { $ as et, A as parseSvelte, B as isVersionUnsupportedBelow, C as dist, G as De, J, K as Fe, O as parseJson, Q as We, T as resolveCommand, X as T, Y as Ke, Z as Ue, a as getUserAgent, at as Option, b as detect, c as packageManagerPrompt, d as from, et as ke, f as commonFilePaths, g as getPackageJson, h as getHighlighter, i as addPnpmBuildDependencies, it as Command, k as parseScript, lt as __toESM, m as formatFiles, n as templates, nt as Vu, o as installDependencies, ot as program, q as Ge, r as AGENT_NAMES, rt as require_picocolors, s as installOption, t as create$1, tt as ze, u as up$1, w as getSharedFiles } from "./create-DTIS6AzL.js";
3
- import { a as communityAddonIds, c as officialAddons, d as create$2, f as overrideProperties, i as createWorkspace, l as createDefault, o as getCommunityAddon, r as setupAddons, s as getAddonDetails, t as applyAddons, u as addDefault } from "./install-BPIL0v3f.js";
4
- import { exec, execSync } from "node:child_process";
5
- import path, { dirname, join } from "node:path";
2
+ import { i as __toESM } from "./chunk-BjMGrMj9.mjs";
3
+ import { D as dist, E as templates, O as getSharedFiles, S as resolveCommand, T as create$1, a as installOption, b as from, c as Option, f as formatFiles, i as installDependencies, l as program, m as getPackageJson, n as addPnpmBuildDependencies, o as packageManagerPrompt, p as getHighlighter, r as getUserAgent, s as Command, t as AGENT_NAMES, u as commonFilePaths, x as detect, y as up$1 } from "./package-manager-Cn_q-LoO.mjs";
4
+ import { $ as Ge, C as createDefault, D as addDefault, F as overrideProperties, P as create$2, Q as Fe, Y as walk, Z as De, a as toFragment, ct as ze, et as J, g as parseSvelte, h as parseScript, it as We, lt as Vu, m as parseJson, nt as T, o as isVersionUnsupportedBelow, ot as et, r as ensureScript, rt as Ue, st as ke, tt as Ke, ut as require_picocolors } from "./core-B7rc0ndx.mjs";
5
+ import { a as setupAddons, n as officialAddons, o as createWorkspace, r as applyAddons, t as getAddonDetails } from "./official-BW6tJgBq.mjs";
6
6
  import fs, { existsSync } from "node:fs";
7
+ import path, { dirname, join } from "node:path";
8
+ import { fileURLToPath } from "node:url";
7
9
  import process from "node:process";
8
10
  import { promisify } from "node:util";
9
- import { fileURLToPath } from "node:url";
11
+ import { exec, execSync } from "node:child_process";
10
12
  import { createGunzip } from "node:zlib";
11
13
  import { pipeline } from "node:stream/promises";
12
14
 
13
15
  //#region package.json
14
16
  var name = "sv";
15
- var version = "0.10.7";
17
+ var version = "0.10.8";
18
+
19
+ //#endregion
20
+ //#region lib/addons/_config/community.ts
21
+ /** EVALUATED AT BUILD TIME */
22
+ const communityAddonIds = ["unocss", "unplugin-icons"];
23
+ async function getCommunityAddon(name$1) {
24
+ const { default: details } = await import(`../../../community-addons/${name$1}.ts`);
25
+ return details;
26
+ }
16
27
 
17
28
  //#endregion
18
29
  //#region ../../node_modules/.pnpm/empathic@1.1.0/node_modules/empathic/package.mjs
@@ -439,7 +450,7 @@ function pipe(...pipe2) {
439
450
  }
440
451
 
441
452
  //#endregion
442
- //#region utils/errors.ts
453
+ //#region lib/cli/utils/errors.ts
443
454
  var UnsupportedError = class extends Error {
444
455
  constructor(reasons) {
445
456
  super();
@@ -450,7 +461,7 @@ var UnsupportedError = class extends Error {
450
461
  };
451
462
 
452
463
  //#endregion
453
- //#region utils/common.ts
464
+ //#region lib/cli/utils/common.ts
454
465
  const NO_PREFIX = "--no-";
455
466
  let options = [];
456
467
  function getLongFlag(flags) {
@@ -550,7 +561,7 @@ function errorAndExit(message) {
550
561
  }
551
562
 
552
563
  //#endregion
553
- //#region commands/add/verifiers.ts
564
+ //#region lib/cli/add/verifiers.ts
554
565
  function verifyCleanWorkingDirectory(cwd, gitCheck) {
555
566
  const verifications = [];
556
567
  if (gitCheck) verifications.push({
@@ -596,7 +607,7 @@ function verifyUnsupportedAddons(addons, addonSetupResult) {
596
607
  }
597
608
 
598
609
  //#endregion
599
- //#region commands/add/fetch-packages.ts
610
+ //#region lib/cli/add/fetch-packages.ts
600
611
  const NODE_MODULES = fileURLToPath(new URL("../node_modules", import.meta.url));
601
612
  const REGISTRY = "https://registry.npmjs.org";
602
613
  const Directive = {
@@ -608,10 +619,10 @@ function verifyPackage(pkg, specifier) {
608
619
  ...pkg.dependencies,
609
620
  ...pkg.peerDependencies
610
621
  };
611
- if (!deps["@sveltejs/cli-core"]) throw new Error(`Invalid add-on package specified: '${specifier}' is missing a dependency on '@sveltejs/cli-core' in its 'package.json'`);
622
+ if (!deps["sv"]) throw new Error(`Invalid add-on package specified: '${specifier}' is missing a dependency on 'sv' in its 'package.json'`);
612
623
  for (const dep of Object.keys(deps)) {
613
- if (dep === "@sveltejs/cli-core") continue;
614
- throw new Error(`Invalid add-on package detected: '${specifier}'\nCommunity addons should not have any external 'dependencies' besides '@sveltejs/cli-core'. Consider bundling your dependencies if they are necessary`);
624
+ if (dep === "sv") continue;
625
+ throw new Error(`Invalid add-on package detected: '${specifier}'\nCommunity addons should not have any external 'dependencies' besides 'sv'. Consider bundling your dependencies if they are necessary`);
615
626
  }
616
627
  }
617
628
  /**
@@ -675,7 +686,7 @@ async function fetchPackageJSON(packageName) {
675
686
  }
676
687
 
677
688
  //#endregion
678
- //#region commands/add/index.ts
689
+ //#region lib/cli/add/index.ts
679
690
  var import_picocolors$2 = /* @__PURE__ */ __toESM(require_picocolors(), 1);
680
691
  const officialAddons$1 = Object.values(officialAddons);
681
692
  const aliases = officialAddons$1.map((c) => c.alias).filter((v) => v !== void 0);
@@ -1215,7 +1226,7 @@ async function resolveCommunityAddons(cwd, community) {
1215
1226
  }
1216
1227
 
1217
1228
  //#endregion
1218
- //#region ../create/playground.ts
1229
+ //#region lib/create/playground.ts
1219
1230
  function validatePlaygroundUrl(link) {
1220
1231
  try {
1221
1232
  const url = new URL(link);
@@ -1271,8 +1282,10 @@ function detectPlaygroundDependencies(files) {
1271
1282
  ];
1272
1283
  for (const file of files) {
1273
1284
  let ast;
1274
- if (file.name.endsWith(".svelte")) ast = parseSvelte(file.content).script.ast;
1275
- else if (file.name.endsWith(".js") || file.name.endsWith(".ts")) ast = parseScript(file.content).ast;
1285
+ if (file.name.endsWith(".svelte")) {
1286
+ const { ast: svelteAst } = parseSvelte(file.content);
1287
+ ast = ensureScript(svelteAst);
1288
+ } else if (file.name.endsWith(".js") || file.name.endsWith(".ts")) ast = parseScript(file.content).ast;
1276
1289
  if (!ast) continue;
1277
1290
  ast.body.filter((node) => node.type === "ImportDeclaration").map((node) => node.source.value).filter((importPath) => !importPath.startsWith("./") && !importPath.startsWith("/")).filter((importPath) => !excludedPrefixes.some((prefix) => importPath.startsWith(prefix))).map(extractPackageInfo).forEach(({ pkgName, version: version$1 }) => packages.set(pkgName, version$1));
1278
1291
  }
@@ -1303,7 +1316,7 @@ function extractPackageVersion(pkgName) {
1303
1316
  if (pkgName.includes("@", 1)) [, version$1] = pkgName.split("@");
1304
1317
  return version$1;
1305
1318
  }
1306
- function setupPlaygroundProject(url, playground, cwd, installDependencies$1, typescript) {
1319
+ function setupPlaygroundProject(url, playground, cwd, installDependencies$1) {
1307
1320
  const mainFile = playground.files.find((file) => file.name === "App.svelte");
1308
1321
  if (!mainFile) throw new Error("Failed to find `App.svelte` entrypoint.");
1309
1322
  const dependencies = detectPlaygroundDependencies(playground.files);
@@ -1318,33 +1331,36 @@ function setupPlaygroundProject(url, playground, cwd, installDependencies$1, typ
1318
1331
  for (const file of playgroundFiles) {
1319
1332
  let contentToWrite = file.contents;
1320
1333
  if (file.name === "src/lib/PlaygroundLayout.svelte") {
1321
- const { script: script$1, template, css } = parseSvelte(file.contents);
1322
- const { generateCode: generateCode$1 } = parseSvelte("", { typescript });
1323
- contentToWrite = generateCode$1({
1324
- script: script$1.generateCode().replaceAll("$sv-title-$sv", playground.name).replaceAll("$sv-url-$sv", url),
1325
- template: template.generateCode().replaceAll("onclick=\"{switchTheme}\"", "onclick={switchTheme}"),
1326
- css: css.generateCode()
1327
- });
1334
+ const { ast: ast$1, generateCode: generateCode$1 } = parseSvelte(file.contents);
1335
+ walk(ensureScript(ast$1), null, { Literal(node) {
1336
+ if (node.value === "$sv-title-$sv") {
1337
+ node.value = playground.name;
1338
+ node.raw = void 0;
1339
+ } else if (node.value === "$sv-url-$sv") {
1340
+ node.value = url;
1341
+ node.raw = void 0;
1342
+ }
1343
+ } });
1344
+ contentToWrite = generateCode$1();
1328
1345
  }
1329
1346
  fs.writeFileSync(path.join(cwd, file.name), contentToWrite, "utf-8");
1330
1347
  }
1331
1348
  }
1332
1349
  const filePath = path.join(cwd, "src/routes/+page.svelte");
1333
- const { script, generateCode } = parseSvelte(fs.readFileSync(filePath, "utf-8"), { typescript });
1334
- addDefault(script.ast, {
1350
+ const { ast, generateCode } = parseSvelte(fs.readFileSync(filePath, "utf-8"));
1351
+ const scriptAst = ensureScript(ast);
1352
+ addDefault(scriptAst, {
1335
1353
  as: "App",
1336
1354
  from: `$lib/playground/${mainFile.name}`
1337
1355
  });
1338
- addDefault(script.ast, {
1356
+ addDefault(scriptAst, {
1339
1357
  as: "PlaygroundLayout",
1340
1358
  from: `$lib/PlaygroundLayout.svelte`
1341
1359
  });
1342
- const newContent = generateCode({
1343
- script: script.generateCode(),
1344
- template: `<PlaygroundLayout>
1360
+ ast.fragment.nodes.push(...toFragment(`<PlaygroundLayout>
1345
1361
  <App />
1346
- </PlaygroundLayout>`
1347
- });
1362
+ </PlaygroundLayout>`));
1363
+ const newContent = generateCode();
1348
1364
  fs.writeFileSync(filePath, newContent, "utf-8");
1349
1365
  const pkgPath = path.join(cwd, "package.json");
1350
1366
  const pkgJson = parseJson(fs.readFileSync(pkgPath, "utf-8"));
@@ -1357,8 +1373,8 @@ function setupPlaygroundProject(url, playground, cwd, installDependencies$1, typ
1357
1373
  let experimentalAsyncNeeded = true;
1358
1374
  const addExperimentalAsync = () => {
1359
1375
  const svelteConfigPath = path.join(cwd, "svelte.config.js");
1360
- const { ast, generateCode: generateCode$1 } = parseScript(fs.readFileSync(svelteConfigPath, "utf-8"));
1361
- const { value: config } = createDefault(ast, { fallback: create$2({}) });
1376
+ const { ast: ast$1, generateCode: generateCode$1 } = parseScript(fs.readFileSync(svelteConfigPath, "utf-8"));
1377
+ const { value: config } = createDefault(ast$1, { fallback: create$2({}) });
1362
1378
  overrideProperties(config, { compilerOptions: { experimental: { async: true } } });
1363
1379
  fs.writeFileSync(svelteConfigPath, generateCode$1(), "utf-8");
1364
1380
  };
@@ -1376,7 +1392,7 @@ function setupPlaygroundProject(url, playground, cwd, installDependencies$1, typ
1376
1392
  }
1377
1393
 
1378
1394
  //#endregion
1379
- //#region commands/create.ts
1395
+ //#region lib/cli/create.ts
1380
1396
  var import_picocolors$1 = /* @__PURE__ */ __toESM(require_picocolors(), 1);
1381
1397
  const langs = ["ts", "jsdoc"];
1382
1398
  const langMap = {
@@ -1539,7 +1555,7 @@ async function createProject(cwd, options$1) {
1539
1555
  template,
1540
1556
  types: language
1541
1557
  });
1542
- if (options$1.fromPlayground) await createProjectFromPlayground(options$1.fromPlayground, projectPath, language === "typescript");
1558
+ if (options$1.fromPlayground) await createProjectFromPlayground(options$1.fromPlayground, projectPath);
1543
1559
  T.success("Project created");
1544
1560
  let addOnNextSteps = [];
1545
1561
  let argsFormattedAddons = [];
@@ -1587,10 +1603,10 @@ async function createProject(cwd, options$1) {
1587
1603
  packageManager
1588
1604
  };
1589
1605
  }
1590
- async function createProjectFromPlayground(url, cwd, typescript) {
1606
+ async function createProjectFromPlayground(url, cwd) {
1591
1607
  const playground = await downloadPlaygroundData(parsePlaygroundUrl(url));
1592
1608
  const dependencies = detectPlaygroundDependencies(playground.files);
1593
- setupPlaygroundProject(url, playground, cwd, await confirmExternalDependencies(Array.from(dependencies.keys())), typescript);
1609
+ setupPlaygroundProject(url, playground, cwd, await confirmExternalDependencies(Array.from(dependencies.keys())));
1594
1610
  }
1595
1611
  async function confirmExternalDependencies(dependencies) {
1596
1612
  if (dependencies.length === 0) return false;
@@ -1634,7 +1650,7 @@ async function createVirtualWorkspace({ cwd, template, type }) {
1634
1650
  }
1635
1651
 
1636
1652
  //#endregion
1637
- //#region commands/migrate.ts
1653
+ //#region lib/cli/migrate.ts
1638
1654
  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.cwd()).action((migration, options$1) => {
1639
1655
  runMigrate(options$1.cwd, [migration]);
1640
1656
  });
@@ -1654,7 +1670,7 @@ function runMigrate(cwd, args) {
1654
1670
  }
1655
1671
 
1656
1672
  //#endregion
1657
- //#region commands/check.ts
1673
+ //#region lib/cli/check.ts
1658
1674
  var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
1659
1675
  const check = new Command("check").description("a CLI for checking your Svelte code").allowUnknownOption(true).allowExcessArguments(true).option("-C, --cwd <path>", "path to working directory", process.cwd()).configureHelp({ formatHelp() {
1660
1676
  runCheck(process.cwd(), ["--help"]);
@@ -0,0 +1,45 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
11
+ var __export = (all, symbols) => {
12
+ let target = {};
13
+ for (var name in all) {
14
+ __defProp(target, name, {
15
+ get: all[name],
16
+ enumerable: true
17
+ });
18
+ }
19
+ if (symbols) {
20
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
21
+ }
22
+ return target;
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") {
26
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
27
+ key = keys[i];
28
+ if (!__hasOwnProp.call(to, key) && key !== except) {
29
+ __defProp(to, key, {
30
+ get: ((k) => from[k]).bind(null, key),
31
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
32
+ });
33
+ }
34
+ }
35
+ }
36
+ return to;
37
+ };
38
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
39
+ value: mod,
40
+ enumerable: true
41
+ }) : target, mod));
42
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
43
+
44
+ //#endregion
45
+ export { __toESM as i, __export as n, __require as r, __commonJSMin as t };