sv 0.11.2 → 0.11.3
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/add-BWQarWDB.mjs +7000 -0
- package/dist/add-nRRWTjzp.d.mts +35 -0
- package/dist/bin.mjs +25 -1845
- package/dist/{index-7xp7FWpU.d.mts → core-CnPhgWST.d.mts} +294 -46
- package/dist/lib/core.d.mts +2 -0
- package/dist/lib/core.mjs +3 -0
- package/dist/lib/index.d.mts +16 -0
- package/dist/lib/index.mjs +4 -4
- package/dist/lib/testing.d.mts +108 -0
- package/dist/lib/testing.mjs +970 -927
- package/dist/{package-manager-CySZrSUa.mjs → package-manager-DkCPtZM1.mjs} +219 -1328
- package/dist/shared.json +30 -4
- package/dist/templates/addon/assets/DOT-gitignore +27 -0
- package/dist/templates/addon/assets/src/index.js +52 -0
- package/dist/templates/addon/assets/tests/addon.test.js +50 -0
- package/dist/templates/addon/assets/tests/setup/global.js +14 -0
- package/dist/templates/addon/assets/tests/setup/suite.js +130 -0
- package/dist/templates/addon/assets/vitest.config.js +16 -0
- package/dist/templates/addon/files.types=checkjs.json +1 -0
- package/dist/templates/addon/files.types=none.json +1 -0
- package/dist/templates/addon/files.types=typescript.json +1 -0
- package/dist/templates/addon/meta.json +4 -0
- package/dist/templates/addon/package.json +32 -0
- package/dist/templates/demo/files.types=checkjs.json +5 -5
- package/dist/templates/demo/files.types=none.json +5 -5
- package/dist/templates/demo/files.types=typescript.json +5 -5
- package/dist/templates/demo/package.json +1 -1
- package/dist/templates/library/package.json +1 -1
- package/dist/templates/minimal/package.json +1 -1
- package/dist/{core-D715tamU.mjs → utils-DjBRIDJG.mjs} +26494 -25089
- package/package.json +7 -7
- package/dist/index.d.mts +0 -2
- package/dist/index2.d.mts +0 -65
- package/dist/lib/core/index.mjs +0 -4
- package/dist/official-P5OKi7QM.mjs +0 -2586
- package/dist/testing.d.mts +0 -50
package/dist/bin.mjs
CHANGED
|
@@ -1,1834 +1,43 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { i as __toESM } from "./chunk-BjMGrMj9.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
6
|
-
import fs, { existsSync } from "node:fs";
|
|
7
|
-
import path, { dirname, join } from "node:path";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { exec, execSync } from "node:child_process";
|
|
3
|
+
import { f as program, l as from, r as getUserAgent, u as Command } from "./package-manager-DkCPtZM1.mjs";
|
|
4
|
+
import { Et as require_picocolors, ft as resolveCommand } from "./utils-DjBRIDJG.mjs";
|
|
5
|
+
import { a as helpConfig, i as forwardExitCode, n as add, o as name, r as create, s as version } from "./add-BWQarWDB.mjs";
|
|
10
6
|
import process from "node:process";
|
|
11
|
-
import {
|
|
12
|
-
import { createGunzip } from "node:zlib";
|
|
13
|
-
import { pipeline } from "node:stream/promises";
|
|
7
|
+
import { execSync } from "node:child_process";
|
|
14
8
|
|
|
15
|
-
//#region
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const { default: details } = await import(`../../../community-addons/${name$1}.ts`);
|
|
25
|
-
return details;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region ../../node_modules/.pnpm/empathic@2.0.0/node_modules/empathic/package.mjs
|
|
30
|
-
/**
|
|
31
|
-
* Find the closest "package.json" file while walking parent directories.
|
|
32
|
-
* @returns The absolute path to a "package.json", if found.
|
|
33
|
-
*/
|
|
34
|
-
function up(options$1) {
|
|
35
|
-
return up$1("package.json", options$1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region ../../node_modules/.pnpm/valibot@1.2.0_typescript@5.9.3/node_modules/valibot/dist/index.mjs
|
|
40
|
-
var import_picocolors$3 = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
41
|
-
let store$4;
|
|
42
|
-
/**
|
|
43
|
-
* Returns the global configuration.
|
|
44
|
-
*
|
|
45
|
-
* @param config The config to merge.
|
|
46
|
-
*
|
|
47
|
-
* @returns The configuration.
|
|
48
|
-
*/
|
|
49
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
50
|
-
function getGlobalConfig(config$1) {
|
|
51
|
-
return {
|
|
52
|
-
lang: config$1?.lang ?? store$4?.lang,
|
|
53
|
-
message: config$1?.message,
|
|
54
|
-
abortEarly: config$1?.abortEarly ?? store$4?.abortEarly,
|
|
55
|
-
abortPipeEarly: config$1?.abortPipeEarly ?? store$4?.abortPipeEarly
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
let store$3;
|
|
59
|
-
/**
|
|
60
|
-
* Returns a global error message.
|
|
61
|
-
*
|
|
62
|
-
* @param lang The language of the message.
|
|
63
|
-
*
|
|
64
|
-
* @returns The error message.
|
|
65
|
-
*/
|
|
66
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
67
|
-
function getGlobalMessage(lang) {
|
|
68
|
-
return store$3?.get(lang);
|
|
69
|
-
}
|
|
70
|
-
let store$2;
|
|
71
|
-
/**
|
|
72
|
-
* Returns a schema error message.
|
|
73
|
-
*
|
|
74
|
-
* @param lang The language of the message.
|
|
75
|
-
*
|
|
76
|
-
* @returns The error message.
|
|
77
|
-
*/
|
|
78
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
79
|
-
function getSchemaMessage(lang) {
|
|
80
|
-
return store$2?.get(lang);
|
|
81
|
-
}
|
|
82
|
-
let store$1;
|
|
83
|
-
/**
|
|
84
|
-
* Returns a specific error message.
|
|
85
|
-
*
|
|
86
|
-
* @param reference The identifier reference.
|
|
87
|
-
* @param lang The language of the message.
|
|
88
|
-
*
|
|
89
|
-
* @returns The error message.
|
|
90
|
-
*/
|
|
91
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
92
|
-
function getSpecificMessage(reference, lang) {
|
|
93
|
-
return store$1?.get(reference)?.get(lang);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Stringifies an unknown input to a literal or type string.
|
|
97
|
-
*
|
|
98
|
-
* @param input The unknown input.
|
|
99
|
-
*
|
|
100
|
-
* @returns A literal or type string.
|
|
101
|
-
*
|
|
102
|
-
* @internal
|
|
103
|
-
*/
|
|
104
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
105
|
-
function _stringify(input) {
|
|
106
|
-
const type = typeof input;
|
|
107
|
-
if (type === "string") return `"${input}"`;
|
|
108
|
-
if (type === "number" || type === "bigint" || type === "boolean") return `${input}`;
|
|
109
|
-
if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
|
|
110
|
-
return type;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Adds an issue to the dataset.
|
|
114
|
-
*
|
|
115
|
-
* @param context The issue context.
|
|
116
|
-
* @param label The issue label.
|
|
117
|
-
* @param dataset The input dataset.
|
|
118
|
-
* @param config The configuration.
|
|
119
|
-
* @param other The optional props.
|
|
120
|
-
*
|
|
121
|
-
* @internal
|
|
122
|
-
*/
|
|
123
|
-
function _addIssue(context, label, dataset, config$1, other) {
|
|
124
|
-
const input = other && "input" in other ? other.input : dataset.value;
|
|
125
|
-
const expected = other?.expected ?? context.expects ?? null;
|
|
126
|
-
const received = other?.received ?? /* @__PURE__ */ _stringify(input);
|
|
127
|
-
const issue = {
|
|
128
|
-
kind: context.kind,
|
|
129
|
-
type: context.type,
|
|
130
|
-
input,
|
|
131
|
-
expected,
|
|
132
|
-
received,
|
|
133
|
-
message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
|
|
134
|
-
requirement: context.requirement,
|
|
135
|
-
path: other?.path,
|
|
136
|
-
issues: other?.issues,
|
|
137
|
-
lang: config$1.lang,
|
|
138
|
-
abortEarly: config$1.abortEarly,
|
|
139
|
-
abortPipeEarly: config$1.abortPipeEarly
|
|
140
|
-
};
|
|
141
|
-
const isSchema = context.kind === "schema";
|
|
142
|
-
const message$1 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config$1.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
|
|
143
|
-
if (message$1 !== void 0) issue.message = typeof message$1 === "function" ? message$1(issue) : message$1;
|
|
144
|
-
if (isSchema) dataset.typed = false;
|
|
145
|
-
if (dataset.issues) dataset.issues.push(issue);
|
|
146
|
-
else dataset.issues = [issue];
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Returns the Standard Schema properties.
|
|
150
|
-
*
|
|
151
|
-
* @param context The schema context.
|
|
152
|
-
*
|
|
153
|
-
* @returns The Standard Schema properties.
|
|
154
|
-
*/
|
|
155
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
156
|
-
function _getStandardProps(context) {
|
|
157
|
-
return {
|
|
158
|
-
version: 1,
|
|
159
|
-
vendor: "valibot",
|
|
160
|
-
validate(value$1) {
|
|
161
|
-
return context["~run"]({ value: value$1 }, /* @__PURE__ */ getGlobalConfig());
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Disallows inherited object properties and prevents object prototype
|
|
167
|
-
* pollution by disallowing certain keys.
|
|
168
|
-
*
|
|
169
|
-
* @param object The object to check.
|
|
170
|
-
* @param key The key to check.
|
|
171
|
-
*
|
|
172
|
-
* @returns Whether the key is allowed.
|
|
173
|
-
*
|
|
174
|
-
* @internal
|
|
175
|
-
*/
|
|
176
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
177
|
-
function _isValidObjectKey(object$1, key) {
|
|
178
|
-
return Object.hasOwn(object$1, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Joins multiple `expects` values with the given separator.
|
|
182
|
-
*
|
|
183
|
-
* @param values The `expects` values.
|
|
184
|
-
* @param separator The separator.
|
|
185
|
-
*
|
|
186
|
-
* @returns The joined `expects` property.
|
|
187
|
-
*
|
|
188
|
-
* @internal
|
|
189
|
-
*/
|
|
190
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
191
|
-
function _joinExpects(values$1, separator) {
|
|
192
|
-
const list = [...new Set(values$1)];
|
|
193
|
-
if (list.length > 1) return `(${list.join(` ${separator} `)})`;
|
|
194
|
-
return list[0] ?? "never";
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* A Valibot error with useful information.
|
|
198
|
-
*/
|
|
199
|
-
var ValiError = class extends Error {
|
|
200
|
-
/**
|
|
201
|
-
* Creates a Valibot error with useful information.
|
|
202
|
-
*
|
|
203
|
-
* @param issues The error issues.
|
|
204
|
-
*/
|
|
205
|
-
constructor(issues) {
|
|
206
|
-
super(issues[0].message);
|
|
207
|
-
this.name = "ValiError";
|
|
208
|
-
this.issues = issues;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
/**
|
|
212
|
-
* Creates a custom transformation action.
|
|
213
|
-
*
|
|
214
|
-
* @param operation The transformation operation.
|
|
215
|
-
*
|
|
216
|
-
* @returns A transform action.
|
|
217
|
-
*/
|
|
218
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
219
|
-
function transform(operation) {
|
|
220
|
-
return {
|
|
221
|
-
kind: "transformation",
|
|
222
|
-
type: "transform",
|
|
223
|
-
reference: transform,
|
|
224
|
-
async: false,
|
|
225
|
-
operation,
|
|
226
|
-
"~run"(dataset) {
|
|
227
|
-
dataset.value = this.operation(dataset.value);
|
|
228
|
-
return dataset;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Returns the fallback value of the schema.
|
|
234
|
-
*
|
|
235
|
-
* @param schema The schema to get it from.
|
|
236
|
-
* @param dataset The output dataset if available.
|
|
237
|
-
* @param config The config if available.
|
|
238
|
-
*
|
|
239
|
-
* @returns The fallback value.
|
|
240
|
-
*/
|
|
241
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
242
|
-
function getFallback(schema, dataset, config$1) {
|
|
243
|
-
return typeof schema.fallback === "function" ? schema.fallback(dataset, config$1) : schema.fallback;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Returns the default value of the schema.
|
|
247
|
-
*
|
|
248
|
-
* @param schema The schema to get it from.
|
|
249
|
-
* @param dataset The input dataset if available.
|
|
250
|
-
* @param config The config if available.
|
|
251
|
-
*
|
|
252
|
-
* @returns The default value.
|
|
253
|
-
*/
|
|
254
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
255
|
-
function getDefault(schema, dataset, config$1) {
|
|
256
|
-
return typeof schema.default === "function" ? schema.default(dataset, config$1) : schema.default;
|
|
257
|
-
}
|
|
258
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
259
|
-
function array(item, message$1) {
|
|
260
|
-
return {
|
|
261
|
-
kind: "schema",
|
|
262
|
-
type: "array",
|
|
263
|
-
reference: array,
|
|
264
|
-
expects: "Array",
|
|
265
|
-
async: false,
|
|
266
|
-
item,
|
|
267
|
-
message: message$1,
|
|
268
|
-
get "~standard"() {
|
|
269
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
270
|
-
},
|
|
271
|
-
"~run"(dataset, config$1) {
|
|
272
|
-
const input = dataset.value;
|
|
273
|
-
if (Array.isArray(input)) {
|
|
274
|
-
dataset.typed = true;
|
|
275
|
-
dataset.value = [];
|
|
276
|
-
for (let key = 0; key < input.length; key++) {
|
|
277
|
-
const value$1 = input[key];
|
|
278
|
-
const itemDataset = this.item["~run"]({ value: value$1 }, config$1);
|
|
279
|
-
if (itemDataset.issues) {
|
|
280
|
-
const pathItem = {
|
|
281
|
-
type: "array",
|
|
282
|
-
origin: "value",
|
|
283
|
-
input,
|
|
284
|
-
key,
|
|
285
|
-
value: value$1
|
|
286
|
-
};
|
|
287
|
-
for (const issue of itemDataset.issues) {
|
|
288
|
-
if (issue.path) issue.path.unshift(pathItem);
|
|
289
|
-
else issue.path = [pathItem];
|
|
290
|
-
dataset.issues?.push(issue);
|
|
291
|
-
}
|
|
292
|
-
if (!dataset.issues) dataset.issues = itemDataset.issues;
|
|
293
|
-
if (config$1.abortEarly) {
|
|
294
|
-
dataset.typed = false;
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if (!itemDataset.typed) dataset.typed = false;
|
|
299
|
-
dataset.value.push(itemDataset.value);
|
|
300
|
-
}
|
|
301
|
-
} else _addIssue(this, "type", dataset, config$1);
|
|
302
|
-
return dataset;
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
307
|
-
function boolean(message$1) {
|
|
308
|
-
return {
|
|
309
|
-
kind: "schema",
|
|
310
|
-
type: "boolean",
|
|
311
|
-
reference: boolean,
|
|
312
|
-
expects: "boolean",
|
|
313
|
-
async: false,
|
|
314
|
-
message: message$1,
|
|
315
|
-
get "~standard"() {
|
|
316
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
317
|
-
},
|
|
318
|
-
"~run"(dataset, config$1) {
|
|
319
|
-
if (typeof dataset.value === "boolean") dataset.typed = true;
|
|
320
|
-
else _addIssue(this, "type", dataset, config$1);
|
|
321
|
-
return dataset;
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
326
|
-
function optional(wrapped, default_) {
|
|
327
|
-
return {
|
|
328
|
-
kind: "schema",
|
|
329
|
-
type: "optional",
|
|
330
|
-
reference: optional,
|
|
331
|
-
expects: `(${wrapped.expects} | undefined)`,
|
|
332
|
-
async: false,
|
|
333
|
-
wrapped,
|
|
334
|
-
default: default_,
|
|
335
|
-
get "~standard"() {
|
|
336
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
337
|
-
},
|
|
338
|
-
"~run"(dataset, config$1) {
|
|
339
|
-
if (dataset.value === void 0) {
|
|
340
|
-
if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);
|
|
341
|
-
if (dataset.value === void 0) {
|
|
342
|
-
dataset.typed = true;
|
|
343
|
-
return dataset;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return this.wrapped["~run"](dataset, config$1);
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
351
|
-
function picklist(options$1, message$1) {
|
|
352
|
-
return {
|
|
353
|
-
kind: "schema",
|
|
354
|
-
type: "picklist",
|
|
355
|
-
reference: picklist,
|
|
356
|
-
expects: /* @__PURE__ */ _joinExpects(options$1.map(_stringify), "|"),
|
|
357
|
-
async: false,
|
|
358
|
-
options: options$1,
|
|
359
|
-
message: message$1,
|
|
360
|
-
get "~standard"() {
|
|
361
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
362
|
-
},
|
|
363
|
-
"~run"(dataset, config$1) {
|
|
364
|
-
if (this.options.includes(dataset.value)) dataset.typed = true;
|
|
365
|
-
else _addIssue(this, "type", dataset, config$1);
|
|
366
|
-
return dataset;
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
371
|
-
function record(key, value$1, message$1) {
|
|
372
|
-
return {
|
|
373
|
-
kind: "schema",
|
|
374
|
-
type: "record",
|
|
375
|
-
reference: record,
|
|
376
|
-
expects: "Object",
|
|
377
|
-
async: false,
|
|
378
|
-
key,
|
|
379
|
-
value: value$1,
|
|
380
|
-
message: message$1,
|
|
381
|
-
get "~standard"() {
|
|
382
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
383
|
-
},
|
|
384
|
-
"~run"(dataset, config$1) {
|
|
385
|
-
const input = dataset.value;
|
|
386
|
-
if (input && typeof input === "object") {
|
|
387
|
-
dataset.typed = true;
|
|
388
|
-
dataset.value = {};
|
|
389
|
-
for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
|
|
390
|
-
const entryValue = input[entryKey];
|
|
391
|
-
const keyDataset = this.key["~run"]({ value: entryKey }, config$1);
|
|
392
|
-
if (keyDataset.issues) {
|
|
393
|
-
const pathItem = {
|
|
394
|
-
type: "object",
|
|
395
|
-
origin: "key",
|
|
396
|
-
input,
|
|
397
|
-
key: entryKey,
|
|
398
|
-
value: entryValue
|
|
399
|
-
};
|
|
400
|
-
for (const issue of keyDataset.issues) {
|
|
401
|
-
issue.path = [pathItem];
|
|
402
|
-
dataset.issues?.push(issue);
|
|
403
|
-
}
|
|
404
|
-
if (!dataset.issues) dataset.issues = keyDataset.issues;
|
|
405
|
-
if (config$1.abortEarly) {
|
|
406
|
-
dataset.typed = false;
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
const valueDataset = this.value["~run"]({ value: entryValue }, config$1);
|
|
411
|
-
if (valueDataset.issues) {
|
|
412
|
-
const pathItem = {
|
|
413
|
-
type: "object",
|
|
414
|
-
origin: "value",
|
|
415
|
-
input,
|
|
416
|
-
key: entryKey,
|
|
417
|
-
value: entryValue
|
|
418
|
-
};
|
|
419
|
-
for (const issue of valueDataset.issues) {
|
|
420
|
-
if (issue.path) issue.path.unshift(pathItem);
|
|
421
|
-
else issue.path = [pathItem];
|
|
422
|
-
dataset.issues?.push(issue);
|
|
423
|
-
}
|
|
424
|
-
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
425
|
-
if (config$1.abortEarly) {
|
|
426
|
-
dataset.typed = false;
|
|
427
|
-
break;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;
|
|
431
|
-
if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;
|
|
432
|
-
}
|
|
433
|
-
} else _addIssue(this, "type", dataset, config$1);
|
|
434
|
-
return dataset;
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
439
|
-
function strictObject(entries$1, message$1) {
|
|
440
|
-
return {
|
|
441
|
-
kind: "schema",
|
|
442
|
-
type: "strict_object",
|
|
443
|
-
reference: strictObject,
|
|
444
|
-
expects: "Object",
|
|
445
|
-
async: false,
|
|
446
|
-
entries: entries$1,
|
|
447
|
-
message: message$1,
|
|
448
|
-
get "~standard"() {
|
|
449
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
450
|
-
},
|
|
451
|
-
"~run"(dataset, config$1) {
|
|
452
|
-
const input = dataset.value;
|
|
453
|
-
if (input && typeof input === "object") {
|
|
454
|
-
dataset.typed = true;
|
|
455
|
-
dataset.value = {};
|
|
456
|
-
for (const key in this.entries) {
|
|
457
|
-
const valueSchema = this.entries[key];
|
|
458
|
-
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
|
|
459
|
-
const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
|
|
460
|
-
const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
|
|
461
|
-
if (valueDataset.issues) {
|
|
462
|
-
const pathItem = {
|
|
463
|
-
type: "object",
|
|
464
|
-
origin: "value",
|
|
465
|
-
input,
|
|
466
|
-
key,
|
|
467
|
-
value: value$1
|
|
468
|
-
};
|
|
469
|
-
for (const issue of valueDataset.issues) {
|
|
470
|
-
if (issue.path) issue.path.unshift(pathItem);
|
|
471
|
-
else issue.path = [pathItem];
|
|
472
|
-
dataset.issues?.push(issue);
|
|
473
|
-
}
|
|
474
|
-
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
475
|
-
if (config$1.abortEarly) {
|
|
476
|
-
dataset.typed = false;
|
|
477
|
-
break;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
if (!valueDataset.typed) dataset.typed = false;
|
|
481
|
-
dataset.value[key] = valueDataset.value;
|
|
482
|
-
} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
483
|
-
else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
484
|
-
_addIssue(this, "key", dataset, config$1, {
|
|
485
|
-
input: void 0,
|
|
486
|
-
expected: `"${key}"`,
|
|
487
|
-
path: [{
|
|
488
|
-
type: "object",
|
|
489
|
-
origin: "key",
|
|
490
|
-
input,
|
|
491
|
-
key,
|
|
492
|
-
value: input[key]
|
|
493
|
-
}]
|
|
494
|
-
});
|
|
495
|
-
if (config$1.abortEarly) break;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
if (!dataset.issues || !config$1.abortEarly) {
|
|
499
|
-
for (const key in input) if (!(key in this.entries)) {
|
|
500
|
-
_addIssue(this, "key", dataset, config$1, {
|
|
501
|
-
input: key,
|
|
502
|
-
expected: "never",
|
|
503
|
-
path: [{
|
|
504
|
-
type: "object",
|
|
505
|
-
origin: "key",
|
|
506
|
-
input,
|
|
507
|
-
key,
|
|
508
|
-
value: input[key]
|
|
509
|
-
}]
|
|
510
|
-
});
|
|
511
|
-
break;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
} else _addIssue(this, "type", dataset, config$1);
|
|
515
|
-
return dataset;
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
520
|
-
function string(message$1) {
|
|
521
|
-
return {
|
|
522
|
-
kind: "schema",
|
|
523
|
-
type: "string",
|
|
524
|
-
reference: string,
|
|
525
|
-
expects: "string",
|
|
526
|
-
async: false,
|
|
527
|
-
message: message$1,
|
|
528
|
-
get "~standard"() {
|
|
529
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
530
|
-
},
|
|
531
|
-
"~run"(dataset, config$1) {
|
|
532
|
-
if (typeof dataset.value === "string") dataset.typed = true;
|
|
533
|
-
else _addIssue(this, "type", dataset, config$1);
|
|
534
|
-
return dataset;
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Returns the sub issues of the provided datasets for the union issue.
|
|
540
|
-
*
|
|
541
|
-
* @param datasets The datasets.
|
|
542
|
-
*
|
|
543
|
-
* @returns The sub issues.
|
|
544
|
-
*
|
|
545
|
-
* @internal
|
|
546
|
-
*/
|
|
547
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
548
|
-
function _subIssues(datasets) {
|
|
549
|
-
let issues;
|
|
550
|
-
if (datasets) for (const dataset of datasets) if (issues) issues.push(...dataset.issues);
|
|
551
|
-
else issues = dataset.issues;
|
|
552
|
-
return issues;
|
|
553
|
-
}
|
|
554
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
555
|
-
function union(options$1, message$1) {
|
|
556
|
-
return {
|
|
557
|
-
kind: "schema",
|
|
558
|
-
type: "union",
|
|
559
|
-
reference: union,
|
|
560
|
-
expects: /* @__PURE__ */ _joinExpects(options$1.map((option) => option.expects), "|"),
|
|
561
|
-
async: false,
|
|
562
|
-
options: options$1,
|
|
563
|
-
message: message$1,
|
|
564
|
-
get "~standard"() {
|
|
565
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
566
|
-
},
|
|
567
|
-
"~run"(dataset, config$1) {
|
|
568
|
-
let validDataset;
|
|
569
|
-
let typedDatasets;
|
|
570
|
-
let untypedDatasets;
|
|
571
|
-
for (const schema of this.options) {
|
|
572
|
-
const optionDataset = schema["~run"]({ value: dataset.value }, config$1);
|
|
573
|
-
if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
|
|
574
|
-
else typedDatasets = [optionDataset];
|
|
575
|
-
else {
|
|
576
|
-
validDataset = optionDataset;
|
|
577
|
-
break;
|
|
578
|
-
}
|
|
579
|
-
else if (untypedDatasets) untypedDatasets.push(optionDataset);
|
|
580
|
-
else untypedDatasets = [optionDataset];
|
|
581
|
-
}
|
|
582
|
-
if (validDataset) return validDataset;
|
|
583
|
-
if (typedDatasets) {
|
|
584
|
-
if (typedDatasets.length === 1) return typedDatasets[0];
|
|
585
|
-
_addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
|
|
586
|
-
dataset.typed = true;
|
|
587
|
-
} else if (untypedDatasets?.length === 1) return untypedDatasets[0];
|
|
588
|
-
else _addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
|
|
589
|
-
return dataset;
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* Parses an unknown input based on a schema.
|
|
595
|
-
*
|
|
596
|
-
* @param schema The schema to be used.
|
|
597
|
-
* @param input The input to be parsed.
|
|
598
|
-
* @param config The parse configuration.
|
|
599
|
-
*
|
|
600
|
-
* @returns The parsed input.
|
|
601
|
-
*/
|
|
602
|
-
function parse(schema, input, config$1) {
|
|
603
|
-
const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1));
|
|
604
|
-
if (dataset.issues) throw new ValiError(dataset.issues);
|
|
605
|
-
return dataset.value;
|
|
606
|
-
}
|
|
607
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
608
|
-
function pipe(...pipe$1) {
|
|
609
|
-
return {
|
|
610
|
-
...pipe$1[0],
|
|
611
|
-
pipe: pipe$1,
|
|
612
|
-
get "~standard"() {
|
|
613
|
-
return /* @__PURE__ */ _getStandardProps(this);
|
|
614
|
-
},
|
|
615
|
-
"~run"(dataset, config$1) {
|
|
616
|
-
for (const item of pipe$1) if (item.kind !== "metadata") {
|
|
617
|
-
if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
|
|
618
|
-
dataset.typed = false;
|
|
619
|
-
break;
|
|
620
|
-
}
|
|
621
|
-
if (!dataset.issues || !config$1.abortEarly && !config$1.abortPipeEarly) dataset = item["~run"](dataset, config$1);
|
|
622
|
-
}
|
|
623
|
-
return dataset;
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
//#endregion
|
|
629
|
-
//#region lib/cli/utils/errors.ts
|
|
630
|
-
var UnsupportedError = class extends Error {
|
|
631
|
-
constructor(reasons) {
|
|
632
|
-
super();
|
|
633
|
-
this.name = "Unsupported Environment";
|
|
634
|
-
this.reasons = [];
|
|
635
|
-
this.reasons = reasons;
|
|
636
|
-
}
|
|
637
|
-
};
|
|
638
|
-
|
|
639
|
-
//#endregion
|
|
640
|
-
//#region lib/cli/utils/common.ts
|
|
641
|
-
const NO_PREFIX = "--no-";
|
|
642
|
-
let options = [];
|
|
643
|
-
function getLongFlag(flags) {
|
|
644
|
-
return flags.split(",").map((f) => f.trim()).find((f) => f.startsWith("--"));
|
|
645
|
-
}
|
|
646
|
-
const helpConfig = {
|
|
647
|
-
argumentDescription: formatDescription,
|
|
648
|
-
optionDescription: formatDescription,
|
|
649
|
-
visibleOptions(cmd) {
|
|
650
|
-
options = cmd.options;
|
|
651
|
-
const visible = cmd.options.filter((o) => !o.hidden);
|
|
652
|
-
const show = [];
|
|
653
|
-
for (const option of visible) {
|
|
654
|
-
const flag = getLongFlag(option.flags);
|
|
655
|
-
if (flag?.startsWith(NO_PREFIX)) {
|
|
656
|
-
const stripped = flag.slice(5);
|
|
657
|
-
if (visible.some((o) => getLongFlag(o.flags)?.startsWith(`--${stripped}`))) continue;
|
|
658
|
-
}
|
|
659
|
-
show.push(option);
|
|
660
|
-
}
|
|
661
|
-
return show;
|
|
662
|
-
},
|
|
663
|
-
optionTerm(option) {
|
|
664
|
-
const longFlag = getLongFlag(option.flags);
|
|
665
|
-
const flag = longFlag?.split(" ").at(0);
|
|
666
|
-
if (!flag || !longFlag) return option.flags;
|
|
667
|
-
const noVariant = `--no-${flag.slice(2)}`;
|
|
668
|
-
if (options.some((o) => getLongFlag(o.flags) === noVariant)) return `--[no-]${longFlag.slice(2)}`;
|
|
669
|
-
return option.flags;
|
|
670
|
-
},
|
|
671
|
-
styleTitle: (str) => import_picocolors$3.default.underline(str),
|
|
672
|
-
styleCommandText: (str) => import_picocolors$3.default.red(str),
|
|
673
|
-
styleDescriptionText: (str) => import_picocolors$3.default.gray(str),
|
|
674
|
-
styleOptionText: (str) => import_picocolors$3.default.white(str),
|
|
675
|
-
styleArgumentText: (str) => import_picocolors$3.default.white(str),
|
|
676
|
-
styleSubcommandText: (str) => import_picocolors$3.default.red(str)
|
|
677
|
-
};
|
|
678
|
-
function formatDescription(arg) {
|
|
679
|
-
let output = arg.description;
|
|
680
|
-
if (arg.defaultValue !== void 0 && String(arg.defaultValue)) output += import_picocolors$3.default.dim(` (default: ${JSON.stringify(arg.defaultValue)})`);
|
|
681
|
-
if (arg.argChoices !== void 0 && String(arg.argChoices)) output += import_picocolors$3.default.dim(` (choices: ${arg.argChoices.join(", ")})`);
|
|
682
|
-
return output;
|
|
683
|
-
}
|
|
684
|
-
async function runCommand(action) {
|
|
685
|
-
try {
|
|
686
|
-
Ge(`Welcome to the Svelte CLI! ${import_picocolors$3.default.gray(`(v${version})`)}`);
|
|
687
|
-
const minimumVersion = "18.3.0";
|
|
688
|
-
if (isVersionUnsupportedBelow(process.versions.node, minimumVersion)) T.warn(`You are using Node.js ${import_picocolors$3.default.red(process.versions.node)}, please upgrade to Node.js ${import_picocolors$3.default.green(minimumVersion)} or higher.`);
|
|
689
|
-
await action();
|
|
690
|
-
Fe("You're all set!");
|
|
691
|
-
} catch (e) {
|
|
692
|
-
if (e instanceof UnsupportedError) {
|
|
693
|
-
const padding = getPadding(e.reasons.map((r) => r.id));
|
|
694
|
-
const message = e.reasons.map((r) => ` ${r.id.padEnd(padding)} ${import_picocolors$3.default.red(r.reason)}`).join("\n");
|
|
695
|
-
T.error(`${e.name}\n\n${message}`);
|
|
696
|
-
T.message();
|
|
697
|
-
} else if (e instanceof Error) {
|
|
698
|
-
T.error(e.stack ?? String(e));
|
|
699
|
-
T.message();
|
|
700
|
-
}
|
|
701
|
-
De("Operation failed.");
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
function getPadding(lines) {
|
|
705
|
-
const lengths = lines.map((s) => s.length);
|
|
706
|
-
return Math.max(...lengths);
|
|
707
|
-
}
|
|
708
|
-
function forwardExitCode(error) {
|
|
709
|
-
if (error && typeof error === "object" && "status" in error && typeof error.status === "number") process.exit(error.status);
|
|
710
|
-
else process.exit(1);
|
|
711
|
-
}
|
|
712
|
-
function parseAddonOptions(optionFlags) {
|
|
713
|
-
if (optionFlags === void 0 || optionFlags === "") return;
|
|
714
|
-
const options$1 = optionFlags.split("+");
|
|
715
|
-
const malformed = options$1.filter((option) => !/.+:.*/.test(option));
|
|
716
|
-
if (malformed.length > 0) {
|
|
717
|
-
const message = `Malformed arguments: The following add-on options: ${malformed.map((o) => `'${o}'`).join(", ")} are missing their option name or value (e.g. 'addon=option1:value1+option2:value2').`;
|
|
718
|
-
throw new Error(message);
|
|
719
|
-
}
|
|
720
|
-
return options$1;
|
|
721
|
-
}
|
|
722
|
-
function logArgs(agent, command, args, lastArgs = []) {
|
|
723
|
-
const allArgs = [
|
|
724
|
-
"sv",
|
|
725
|
-
command,
|
|
726
|
-
...args
|
|
727
|
-
];
|
|
728
|
-
if (agent === null || agent === void 0) allArgs.push("--no-install");
|
|
729
|
-
else allArgs.push("--install", agent);
|
|
730
|
-
const res = resolveCommand(agent ?? "npm", "execute", [...allArgs, ...lastArgs]);
|
|
731
|
-
T.message(import_picocolors$3.default.dim([res.command, ...res.args].join(" ")));
|
|
732
|
-
}
|
|
733
|
-
function errorAndExit(message) {
|
|
734
|
-
T.error(message);
|
|
735
|
-
De("Operation failed.");
|
|
736
|
-
process.exit(1);
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
//#endregion
|
|
740
|
-
//#region lib/cli/add/verifiers.ts
|
|
741
|
-
function verifyCleanWorkingDirectory(cwd$1, gitCheck) {
|
|
742
|
-
const verifications = [];
|
|
743
|
-
if (gitCheck) verifications.push({
|
|
744
|
-
name: "clean working directory",
|
|
745
|
-
run: async () => {
|
|
746
|
-
try {
|
|
747
|
-
const { stdout: stdout$1 } = await promisify(exec)("git status --short", { cwd: cwd$1 });
|
|
748
|
-
if (stdout$1) return {
|
|
749
|
-
success: false,
|
|
750
|
-
message: "Found modified files"
|
|
751
|
-
};
|
|
752
|
-
return {
|
|
753
|
-
success: true,
|
|
754
|
-
message: void 0
|
|
755
|
-
};
|
|
756
|
-
} catch {
|
|
757
|
-
return {
|
|
758
|
-
success: true,
|
|
759
|
-
message: "Not a git repository"
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
return verifications;
|
|
765
|
-
}
|
|
766
|
-
function verifyUnsupportedAddons(addons, addonSetupResult) {
|
|
767
|
-
const verifications = [];
|
|
768
|
-
verifications.push({
|
|
769
|
-
name: "unsupported add-ons",
|
|
770
|
-
run: () => {
|
|
771
|
-
const reasons = addons.flatMap((a) => addonSetupResult[a.id].unsupported.map((reason) => ({
|
|
772
|
-
id: a.id,
|
|
773
|
-
reason
|
|
774
|
-
})));
|
|
775
|
-
if (reasons.length === 0) return {
|
|
776
|
-
success: true,
|
|
777
|
-
message: void 0
|
|
778
|
-
};
|
|
779
|
-
throw new UnsupportedError(reasons);
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
return verifications;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
//#endregion
|
|
786
|
-
//#region lib/cli/add/fetch-packages.ts
|
|
787
|
-
const NODE_MODULES = fileURLToPath(new URL("../node_modules", import.meta.url));
|
|
788
|
-
const REGISTRY = "https://registry.npmjs.org";
|
|
789
|
-
const Directive = {
|
|
790
|
-
file: "file:",
|
|
791
|
-
npm: "npm:"
|
|
792
|
-
};
|
|
793
|
-
function verifyPackage(pkg, specifier) {
|
|
794
|
-
const deps = {
|
|
795
|
-
...pkg.dependencies,
|
|
796
|
-
...pkg.peerDependencies
|
|
797
|
-
};
|
|
798
|
-
if (!deps["sv"]) throw new Error(`Invalid add-on package specified: '${specifier}' is missing a dependency on 'sv' in its 'package.json'`);
|
|
799
|
-
for (const dep of Object.keys(deps)) {
|
|
800
|
-
if (dep === "sv") continue;
|
|
801
|
-
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`);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* Downloads and installs the package into the `node_modules` of `sv`.
|
|
806
|
-
* @returns the details of the downloaded addon
|
|
807
|
-
*/
|
|
808
|
-
async function downloadPackage(options$1) {
|
|
809
|
-
const { pkg } = options$1;
|
|
810
|
-
if (options$1.path) {
|
|
811
|
-
const dest = path.join(NODE_MODULES, pkg.name.split("/").join(path.sep));
|
|
812
|
-
if (fs.existsSync(dest)) fs.rmSync(dest);
|
|
813
|
-
const dir = path.dirname(dest);
|
|
814
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
815
|
-
fs.symlinkSync(options$1.path, dest);
|
|
816
|
-
const { default: details$1 } = await import(pkg.name);
|
|
817
|
-
return details$1;
|
|
818
|
-
}
|
|
819
|
-
const tarballUrl = pkg.dist.tarball;
|
|
820
|
-
const data = await fetch(tarballUrl);
|
|
821
|
-
if (!data.body) throw new Error(`Unexpected response: '${tarballUrl}' responded with no body`);
|
|
822
|
-
await pipeline(data.body, createGunzip());
|
|
823
|
-
const { default: details } = await import(pkg.name);
|
|
824
|
-
return details;
|
|
825
|
-
}
|
|
826
|
-
async function getPackageJSON({ cwd: cwd$1, packageName }) {
|
|
827
|
-
let npm = packageName;
|
|
828
|
-
if (packageName.startsWith(Directive.file)) {
|
|
829
|
-
const pkgPath = path.resolve(cwd$1, packageName.slice(Directive.file.length));
|
|
830
|
-
const pkgJSONPath = path.resolve(pkgPath, "package.json");
|
|
831
|
-
const json = fs.readFileSync(pkgJSONPath, "utf8");
|
|
832
|
-
const pkg$1 = JSON.parse(json);
|
|
833
|
-
verifyPackage(pkg$1, packageName);
|
|
834
|
-
return {
|
|
835
|
-
path: pkgPath,
|
|
836
|
-
pkg: pkg$1,
|
|
837
|
-
repo: pkgPath
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
if (packageName.startsWith(Directive.npm)) npm = packageName.slice(Directive.npm.length);
|
|
841
|
-
const pkg = await fetchPackageJSON(npm);
|
|
842
|
-
verifyPackage(pkg, packageName);
|
|
843
|
-
return {
|
|
844
|
-
pkg,
|
|
845
|
-
repo: pkg.repository?.url ?? `https://www.npmjs.com/package/${npm}`
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
async function fetchPackageJSON(packageName) {
|
|
849
|
-
let pkgName = packageName;
|
|
850
|
-
let scope = "";
|
|
851
|
-
if (packageName.startsWith("@")) {
|
|
852
|
-
const [org, name$2] = pkgName.split("/", 2);
|
|
853
|
-
scope = `${org}/`;
|
|
854
|
-
pkgName = name$2;
|
|
855
|
-
}
|
|
856
|
-
const [name$1, tag = "latest"] = pkgName.split("@");
|
|
857
|
-
const pkgUrl = `${REGISTRY}/${scope + name$1}/${tag}`;
|
|
858
|
-
const resp = await fetch(pkgUrl);
|
|
859
|
-
if (resp.status === 404) throw new Error(`Package '${packageName}' doesn't exist in the registry: '${pkgUrl}'`);
|
|
860
|
-
if (resp.status < 200 && resp.status >= 300) throw new Error(`Failed to fetch '${pkgUrl}' - GET ${resp.status}`);
|
|
861
|
-
return await resp.json();
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
//#endregion
|
|
865
|
-
//#region lib/cli/add/index.ts
|
|
866
|
-
var import_picocolors$2 = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
867
|
-
const officialAddons$1 = Object.values(officialAddons);
|
|
868
|
-
const aliases = officialAddons$1.map((c) => c.alias).filter((v) => v !== void 0);
|
|
869
|
-
const addonOptions = getAddonOptionFlags();
|
|
870
|
-
const communityDetails = [];
|
|
871
|
-
const AddonsSchema = array(string());
|
|
872
|
-
const OptionsSchema$1 = strictObject({
|
|
873
|
-
cwd: string(),
|
|
874
|
-
install: union([boolean(), picklist(AGENT_NAMES)]),
|
|
875
|
-
gitCheck: boolean(),
|
|
876
|
-
community: optional(union([AddonsSchema, boolean()])),
|
|
877
|
-
addons: record(string(), optional(array(string())))
|
|
878
|
-
});
|
|
879
|
-
const defaultPkgPath = up();
|
|
880
|
-
const defaultCwd = defaultPkgPath ? path.dirname(defaultPkgPath) : void 0;
|
|
881
|
-
const add = new Command("add").description("applies specified add-ons into a project").argument("[add-on...]", `add-ons to install`, (value, previous = []) => addonArgsHandler(previous, value)).option("-C, --cwd <path>", "path to working directory", defaultCwd).option("--no-git-check", "even if some files are dirty, no prompt will be shown").option("--no-install", "skip installing dependencies").addOption(installOption).configureHelp({
|
|
882
|
-
...helpConfig,
|
|
883
|
-
formatHelp(cmd, helper) {
|
|
884
|
-
const termWidth = helper.padWidth(cmd, helper);
|
|
885
|
-
const helpWidth = helper.helpWidth ?? 80;
|
|
886
|
-
function callFormatItem(term, description) {
|
|
887
|
-
return helper.formatItem(term, termWidth, description, helper);
|
|
888
|
-
}
|
|
889
|
-
let output = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
|
|
890
|
-
const commandDescription = helper.commandDescription(cmd);
|
|
891
|
-
if (commandDescription.length > 0) output = output.concat([helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth), ""]);
|
|
892
|
-
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
893
|
-
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
894
|
-
});
|
|
895
|
-
if (argumentList.length > 0) output = output.concat([
|
|
896
|
-
helper.styleTitle("Arguments:"),
|
|
897
|
-
...argumentList,
|
|
898
|
-
""
|
|
899
|
-
]);
|
|
900
|
-
const addonList = addonOptions.map((option) => {
|
|
901
|
-
const description = option.choices;
|
|
902
|
-
return callFormatItem(helper.styleArgumentTerm(option.id), helper.styleArgumentDescription(description));
|
|
903
|
-
});
|
|
904
|
-
if (addonList.length > 0) output = output.concat([
|
|
905
|
-
helper.styleTitle("Add-On Options:"),
|
|
906
|
-
...addonList,
|
|
907
|
-
""
|
|
908
|
-
]);
|
|
909
|
-
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
910
|
-
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
911
|
-
});
|
|
912
|
-
if (optionList.length > 0) output = output.concat([
|
|
913
|
-
helper.styleTitle("Options:"),
|
|
914
|
-
...optionList,
|
|
915
|
-
""
|
|
916
|
-
]);
|
|
917
|
-
if (helper.showGlobalOptions) {
|
|
918
|
-
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
919
|
-
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
920
|
-
});
|
|
921
|
-
if (globalOptionList.length > 0) output = output.concat([
|
|
922
|
-
helper.styleTitle("Global Options:"),
|
|
923
|
-
...globalOptionList,
|
|
924
|
-
""
|
|
925
|
-
]);
|
|
926
|
-
}
|
|
927
|
-
const commandList = helper.visibleCommands(cmd).map((cmd$1) => {
|
|
928
|
-
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(cmd$1)), helper.styleSubcommandDescription(helper.subcommandDescription(cmd$1)));
|
|
929
|
-
});
|
|
930
|
-
if (commandList.length > 0) output = output.concat([
|
|
931
|
-
helper.styleTitle("Commands:"),
|
|
932
|
-
...commandList,
|
|
933
|
-
""
|
|
934
|
-
]);
|
|
935
|
-
return output.join("\n");
|
|
936
|
-
}
|
|
937
|
-
}).action(async (addonArgs, opts) => {
|
|
938
|
-
if (opts.cwd === void 0) errorAndExit("Invalid workspace: Please verify that you are inside of a Svelte project. You can also specify the working directory with `--cwd <path>`");
|
|
939
|
-
else if (!fs.existsSync(path.resolve(opts.cwd, "package.json"))) errorAndExit(`Invalid workspace: Path '${path.resolve(opts.cwd)}' is not a valid workspace.`);
|
|
940
|
-
const selectedAddonArgs = sanitizeAddons(addonArgs);
|
|
941
|
-
const options$1 = parse(OptionsSchema$1, {
|
|
942
|
-
...opts,
|
|
943
|
-
addons: {}
|
|
944
|
-
});
|
|
945
|
-
selectedAddonArgs.forEach((addon) => options$1.addons[addon.id] = addon.options);
|
|
946
|
-
const workspace = await createWorkspace({ cwd: options$1.cwd });
|
|
947
|
-
runCommand(async () => {
|
|
948
|
-
const { answersCommunity, answersOfficial, selectedAddons } = await promptAddonQuestions({
|
|
949
|
-
options: options$1,
|
|
950
|
-
selectedAddonIds: selectedAddonArgs.map(({ id }) => id),
|
|
951
|
-
workspace
|
|
952
|
-
});
|
|
953
|
-
const { nextSteps } = await runAddonsApply({
|
|
954
|
-
answersOfficial,
|
|
955
|
-
answersCommunity,
|
|
956
|
-
options: options$1,
|
|
957
|
-
selectedAddons,
|
|
958
|
-
workspace,
|
|
959
|
-
fromCommand: "add"
|
|
960
|
-
});
|
|
961
|
-
if (nextSteps.length > 0) Ke(nextSteps.join("\n"), "Next steps", { format: (line) => line });
|
|
962
|
-
});
|
|
9
|
+
//#region lib/cli/check.ts
|
|
10
|
+
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
11
|
+
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() {
|
|
12
|
+
runCheck(process.cwd(), ["--help"]);
|
|
13
|
+
return "";
|
|
14
|
+
} }).action((options, check$1) => {
|
|
15
|
+
const cwd$1 = options.cwd;
|
|
16
|
+
const args = check$1.args;
|
|
17
|
+
runCheck(cwd$1, args);
|
|
963
18
|
});
|
|
964
|
-
|
|
965
|
-
const
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
const emptyAnswersReducer = (acc, id) => {
|
|
970
|
-
acc[id] = {};
|
|
971
|
-
return acc;
|
|
972
|
-
};
|
|
973
|
-
const answersOfficial = selectedOfficialAddons.map(({ id }) => id).reduce(emptyAnswersReducer, {});
|
|
974
|
-
for (const addonOption of addonOptions) {
|
|
975
|
-
const addonId = addonOption.id;
|
|
976
|
-
const specifiedOptions = options$1.addons[addonId];
|
|
977
|
-
if (!specifiedOptions) continue;
|
|
978
|
-
const details = getAddonDetails(addonId);
|
|
979
|
-
if (!selectedOfficialAddons.find((d) => d === details)) selectedOfficialAddons.push(details);
|
|
980
|
-
answersOfficial[addonId] ??= {};
|
|
981
|
-
const optionEntries = Object.entries(details.options);
|
|
982
|
-
const specifiedOptionsObject = Object.fromEntries(specifiedOptions.map((option) => option.split(":", 2)));
|
|
983
|
-
for (const option of specifiedOptions) {
|
|
984
|
-
const [optionId, optionValue] = option.split(":", 2);
|
|
985
|
-
const optionEntry = optionEntries.find(([id, question$1]) => {
|
|
986
|
-
if (id === optionId) return true;
|
|
987
|
-
if (question$1.group === optionId) {
|
|
988
|
-
if (question$1.type === "select") {
|
|
989
|
-
if (!question$1.options.some((opt) => opt.value === optionValue)) return false;
|
|
990
|
-
} else if (question$1.type === "multiselect") {
|
|
991
|
-
if (!(optionValue === "none" ? [] : optionValue.split(",")).every((val) => question$1.options.some((opt) => opt.value === val.trim()))) return false;
|
|
992
|
-
}
|
|
993
|
-
if (question$1.condition) return question$1.condition(specifiedOptionsObject);
|
|
994
|
-
return true;
|
|
995
|
-
}
|
|
996
|
-
return false;
|
|
997
|
-
});
|
|
998
|
-
if (!optionEntry) {
|
|
999
|
-
const { choices } = getOptionChoices(details);
|
|
1000
|
-
errorAndExit(`Invalid '${addonId}' add-on option: '${option}'\nAvailable options: ${choices.join(", ")}`);
|
|
1001
|
-
throw new Error();
|
|
1002
|
-
}
|
|
1003
|
-
const [questionId, question] = optionEntry;
|
|
1004
|
-
if (question.type === "multiselect" && questionId === optionId) {
|
|
1005
|
-
const invalidValues = (optionValue === "none" || optionValue === "" ? [] : optionValue.split(",")).filter((val) => !question.options.some((opt) => opt.value === val.trim()));
|
|
1006
|
-
if (invalidValues.length > 0) {
|
|
1007
|
-
const validValues = question.options.map((opt) => opt.value).join(", ");
|
|
1008
|
-
errorAndExit(`Invalid '${addonId}' add-on option: '${option}'\nInvalid values: ${invalidValues.join(", ")}\nAvailable values: ${validValues}`);
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
let existingOption = answersOfficial[addonId][questionId];
|
|
1012
|
-
if (existingOption !== void 0) {
|
|
1013
|
-
if (typeof existingOption === "boolean") existingOption = existingOption ? "yes" : "no";
|
|
1014
|
-
errorAndExit(`Conflicting '${addonId}' option: '${option}' conflicts with '${questionId}:${existingOption}'`);
|
|
1015
|
-
}
|
|
1016
|
-
if (question.type === "boolean") answersOfficial[addonId][questionId] = optionValue === "yes";
|
|
1017
|
-
else if (question.type === "number") answersOfficial[addonId][questionId] = Number(optionValue);
|
|
1018
|
-
else if (question.type === "multiselect") if (optionValue === "none" || optionValue === "") answersOfficial[addonId][questionId] = [];
|
|
1019
|
-
else answersOfficial[addonId][questionId] = optionValue.split(",").map((v) => v.trim());
|
|
1020
|
-
else answersOfficial[addonId][questionId] = optionValue;
|
|
1021
|
-
}
|
|
1022
|
-
for (const [id, question] of Object.entries(details.options)) if (question.condition?.(answersOfficial[addonId]) !== false) answersOfficial[addonId][id] ??= question.default;
|
|
1023
|
-
else if (answersOfficial[addonId][id] !== void 0) throw new Error(`Incompatible '${addonId}' option specified: '${answersOfficial[addonId][id]}'`);
|
|
1024
|
-
}
|
|
1025
|
-
if (options$1.community === true) {
|
|
1026
|
-
const promptOptions = (await Promise.all(communityAddonIds.map(async (id) => await getCommunityAddon(id)))).map((addon) => ({
|
|
1027
|
-
value: addon.id,
|
|
1028
|
-
label: addon.id,
|
|
1029
|
-
hint: "https://www.npmjs.com/package/" + addon.id
|
|
1030
|
-
}));
|
|
1031
|
-
const selected = await Ue({
|
|
1032
|
-
message: "Which community tools would you like to add to your project?",
|
|
1033
|
-
options: promptOptions,
|
|
1034
|
-
required: false
|
|
1035
|
-
});
|
|
1036
|
-
if (Vu(selected)) {
|
|
1037
|
-
De("Operation cancelled.");
|
|
1038
|
-
process.exit(1);
|
|
1039
|
-
} else if (selected.length === 0) {
|
|
1040
|
-
De("No add-ons selected. Exiting.");
|
|
1041
|
-
process.exit(1);
|
|
1042
|
-
}
|
|
1043
|
-
options$1.community = selected;
|
|
1044
|
-
}
|
|
1045
|
-
const selectedCommunityAddons = [];
|
|
1046
|
-
const answersCommunity = selectedCommunityAddons.map(({ id }) => id).reduce(emptyAnswersReducer, {});
|
|
1047
|
-
if (Array.isArray(options$1.community) && options$1.community.length > 0) selectedCommunityAddons.push(...await resolveCommunityAddons(options$1.cwd, options$1.community));
|
|
1048
|
-
const selectedAddons = [...selectedOfficialAddons.map((addon) => ({
|
|
1049
|
-
type: "official",
|
|
1050
|
-
addon
|
|
1051
|
-
})), ...selectedCommunityAddons.map((addon) => ({
|
|
1052
|
-
type: "community",
|
|
1053
|
-
addon
|
|
1054
|
-
}))];
|
|
1055
|
-
const addonSetupResults = setupAddons(selectedAddons.length ? selectedAddons.map(({ addon }) => addon) : officialAddons$1, workspace);
|
|
1056
|
-
if (selectedAddons.length === 0) {
|
|
1057
|
-
const allSetupResults = setupAddons(officialAddons$1, workspace);
|
|
1058
|
-
const addonOptions$1 = officialAddons$1.filter(({ id }) => allSetupResults[id].unsupported.length === 0).map(({ id, homepage, shortDescription }) => ({
|
|
1059
|
-
label: id,
|
|
1060
|
-
value: id,
|
|
1061
|
-
hint: `${shortDescription} - ${homepage}`
|
|
1062
|
-
}));
|
|
1063
|
-
const selected = await Ue({
|
|
1064
|
-
message: `What would you like to add to your project? ${import_picocolors$2.default.dim("(use arrow keys / space bar)")}`,
|
|
1065
|
-
options: addonOptions$1,
|
|
1066
|
-
required: false
|
|
1067
|
-
});
|
|
1068
|
-
if (Vu(selected)) {
|
|
1069
|
-
De("Operation cancelled.");
|
|
1070
|
-
process.exit(1);
|
|
1071
|
-
}
|
|
1072
|
-
for (const id of selected) {
|
|
1073
|
-
const addon = getAddonDetails(id);
|
|
1074
|
-
selectedAddons.push({
|
|
1075
|
-
type: "official",
|
|
1076
|
-
addon
|
|
1077
|
-
});
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
for (const { addon } of selectedAddons) {
|
|
1081
|
-
const missingDependencies = addonSetupResults[addon.id].dependsOn.filter((depId) => !selectedAddons.some((a) => a.addon.id === depId));
|
|
1082
|
-
for (const depId of missingDependencies) {
|
|
1083
|
-
const dependency = officialAddons$1.find((a) => a.id === depId);
|
|
1084
|
-
if (!dependency) throw new Error(`'${addon.id}' depends on an invalid add-on: '${depId}'`);
|
|
1085
|
-
if (await ke({ message: `The ${import_picocolors$2.default.bold(import_picocolors$2.default.cyan(addon.id))} add-on requires ${import_picocolors$2.default.bold(import_picocolors$2.default.cyan(depId))} to also be setup. ${import_picocolors$2.default.green("Include it?")}` }) !== true) {
|
|
1086
|
-
De("Operation cancelled.");
|
|
1087
|
-
process.exit(1);
|
|
1088
|
-
}
|
|
1089
|
-
selectedAddons.push({
|
|
1090
|
-
type: "official",
|
|
1091
|
-
addon: dependency
|
|
1092
|
-
});
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
const addons = selectedAddons.map(({ addon }) => addon);
|
|
1096
|
-
const verifications = [...verifyCleanWorkingDirectory(options$1.cwd, options$1.gitCheck), ...verifyUnsupportedAddons(addons, addonSetupResults)];
|
|
1097
|
-
const fails = [];
|
|
1098
|
-
for (const verification of verifications) {
|
|
1099
|
-
const { message, success } = await verification.run();
|
|
1100
|
-
if (!success) fails.push({
|
|
1101
|
-
name: verification.name,
|
|
1102
|
-
message
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
if (fails.length > 0) {
|
|
1106
|
-
const message = fails.map(({ name: name$1, message: message$1 }) => import_picocolors$2.default.yellow(`${name$1} (${message$1})`)).join("\n- ");
|
|
1107
|
-
Ke(`- ${message}`, "Verifications not met", { format: (line) => line });
|
|
1108
|
-
const force = await ke({
|
|
1109
|
-
message: "Verifications failed. Do you wish to continue?",
|
|
1110
|
-
initialValue: false
|
|
1111
|
-
});
|
|
1112
|
-
if (Vu(force) || !force) {
|
|
1113
|
-
De("Operation cancelled.");
|
|
1114
|
-
process.exit(1);
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
for (const { addon, type } of selectedAddons) {
|
|
1118
|
-
const addonId = addon.id;
|
|
1119
|
-
const questionPrefix = selectedAddons.length > 1 ? `${addon.id}: ` : "";
|
|
1120
|
-
let values = {};
|
|
1121
|
-
if (type === "official") {
|
|
1122
|
-
answersOfficial[addonId] ??= {};
|
|
1123
|
-
values = answersOfficial[addonId];
|
|
1124
|
-
}
|
|
1125
|
-
if (type === "community") {
|
|
1126
|
-
answersCommunity[addonId] ??= {};
|
|
1127
|
-
values = answersCommunity[addonId];
|
|
1128
|
-
}
|
|
1129
|
-
for (const [questionId, question] of Object.entries(addon.options)) {
|
|
1130
|
-
if (question.condition?.(values) === false || values[questionId] !== void 0) continue;
|
|
1131
|
-
let answer;
|
|
1132
|
-
const message = questionPrefix + question.question;
|
|
1133
|
-
if (question.type === "boolean") answer = await ke({
|
|
1134
|
-
message,
|
|
1135
|
-
initialValue: question.default
|
|
1136
|
-
});
|
|
1137
|
-
if (question.type === "select") answer = await ze({
|
|
1138
|
-
message,
|
|
1139
|
-
initialValue: question.default,
|
|
1140
|
-
options: question.options
|
|
1141
|
-
});
|
|
1142
|
-
if (question.type === "multiselect") answer = await Ue({
|
|
1143
|
-
message,
|
|
1144
|
-
initialValues: question.default,
|
|
1145
|
-
required: question.required,
|
|
1146
|
-
options: question.options
|
|
1147
|
-
});
|
|
1148
|
-
if (question.type === "string" || question.type === "number") {
|
|
1149
|
-
answer = await et({
|
|
1150
|
-
message,
|
|
1151
|
-
initialValue: question.default.toString(),
|
|
1152
|
-
placeholder: question.placeholder,
|
|
1153
|
-
validate: question.validate
|
|
1154
|
-
});
|
|
1155
|
-
if (question.type === "number") answer = Number(answer);
|
|
1156
|
-
}
|
|
1157
|
-
if (Vu(answer)) {
|
|
1158
|
-
De("Operation cancelled.");
|
|
1159
|
-
process.exit(1);
|
|
1160
|
-
}
|
|
1161
|
-
values[questionId] = answer;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
return {
|
|
1165
|
-
selectedAddons,
|
|
1166
|
-
answersOfficial,
|
|
1167
|
-
answersCommunity
|
|
1168
|
-
};
|
|
1169
|
-
}
|
|
1170
|
-
async function runAddonsApply({ answersOfficial, answersCommunity, options: options$1, selectedAddons, addonSetupResults, workspace, fromCommand }) {
|
|
1171
|
-
if (!addonSetupResults) addonSetupResults = setupAddons(selectedAddons.length ? selectedAddons.map(({ addon }) => addon) : officialAddons$1, workspace);
|
|
1172
|
-
if (selectedAddons.length === 0) return {
|
|
1173
|
-
nextSteps: [],
|
|
1174
|
-
argsFormattedAddons: [],
|
|
1175
|
-
filesToFormat: []
|
|
1176
|
-
};
|
|
1177
|
-
const officialDetails = Object.keys(answersOfficial).map((id) => getAddonDetails(id));
|
|
1178
|
-
const commDetails = Object.keys(answersCommunity).map((id) => communityDetails.find((a) => a.id === id));
|
|
1179
|
-
const details = officialDetails.concat(commDetails);
|
|
1180
|
-
const addonMap = Object.assign({}, ...details.map((a) => ({ [a.id]: a })));
|
|
1181
|
-
const { filesToFormat, pnpmBuildDependencies, status } = await applyAddons({
|
|
1182
|
-
workspace,
|
|
1183
|
-
addonSetupResults,
|
|
1184
|
-
addons: addonMap,
|
|
1185
|
-
options: answersOfficial
|
|
1186
|
-
});
|
|
1187
|
-
const addonSuccess = [];
|
|
1188
|
-
for (const [addonId, info] of Object.entries(status)) if (info === "success") addonSuccess.push(addonId);
|
|
1189
|
-
else {
|
|
1190
|
-
T.warn(`Canceled ${addonId}: ${info.join(", ")}`);
|
|
1191
|
-
selectedAddons = selectedAddons.filter((a) => a.addon.id !== addonId);
|
|
1192
|
-
}
|
|
1193
|
-
if (addonSuccess.length === 0) {
|
|
1194
|
-
De("All selected add-ons were canceled.");
|
|
19
|
+
function runCheck(cwd$1, args) {
|
|
20
|
+
const pm = getUserAgent() ?? "npm";
|
|
21
|
+
if (!from(cwd$1, "svelte-check", true)) {
|
|
22
|
+
const cmd = resolveCommand(pm, "add", ["-D", "svelte-check"]);
|
|
23
|
+
console.error(`'svelte-check' is not installed locally. Install it with: ${import_picocolors.default.bold(`${cmd.command} ${cmd.args.join(" ")}`)}`);
|
|
1195
24
|
process.exit(1);
|
|
1196
|
-
} else {
|
|
1197
|
-
const highlighter$1 = getHighlighter();
|
|
1198
|
-
T.success(`Successfully setup add-ons: ${addonSuccess.map((c) => highlighter$1.addon(c)).join(", ")}`);
|
|
1199
|
-
}
|
|
1200
|
-
const packageManager = options$1.install === false ? null : options$1.install === true ? await packageManagerPrompt(options$1.cwd) : options$1.install;
|
|
1201
|
-
await addPnpmBuildDependencies(workspace.cwd, packageManager, ["esbuild", ...pnpmBuildDependencies]);
|
|
1202
|
-
const argsFormattedAddons = [];
|
|
1203
|
-
for (const { addon, type } of selectedAddons) {
|
|
1204
|
-
const addonId = addon.id;
|
|
1205
|
-
const answers = type === "official" ? answersOfficial[addonId] : answersCommunity[addonId];
|
|
1206
|
-
if (!answers) continue;
|
|
1207
|
-
const addonDetails = type === "official" ? getAddonDetails(addonId) : addon;
|
|
1208
|
-
const optionParts = [];
|
|
1209
|
-
for (const [optionId, value] of Object.entries(answers)) {
|
|
1210
|
-
if (value === void 0) continue;
|
|
1211
|
-
const question = addonDetails.options[optionId];
|
|
1212
|
-
if (!question) continue;
|
|
1213
|
-
let formattedValue;
|
|
1214
|
-
if (question.type === "boolean") formattedValue = value ? "yes" : "no";
|
|
1215
|
-
else if (question.type === "number") formattedValue = String(value);
|
|
1216
|
-
else if (question.type === "multiselect") if (Array.isArray(value)) if (value.length === 0) formattedValue = "none";
|
|
1217
|
-
else formattedValue = value.join(",");
|
|
1218
|
-
else formattedValue = String(value);
|
|
1219
|
-
else formattedValue = String(value);
|
|
1220
|
-
optionParts.push(`${optionId}:${formattedValue}`);
|
|
1221
|
-
}
|
|
1222
|
-
if (optionParts.length > 0) argsFormattedAddons.push(`${addonId}="${optionParts.join("+")}"`);
|
|
1223
|
-
else argsFormattedAddons.push(addonId);
|
|
1224
|
-
}
|
|
1225
|
-
if (fromCommand === "add") logArgs(packageManager, "add", argsFormattedAddons);
|
|
1226
|
-
if (packageManager) {
|
|
1227
|
-
workspace.packageManager = packageManager;
|
|
1228
|
-
await installDependencies(packageManager, options$1.cwd);
|
|
1229
|
-
await formatFiles({
|
|
1230
|
-
packageManager,
|
|
1231
|
-
cwd: options$1.cwd,
|
|
1232
|
-
filesToFormat
|
|
1233
|
-
});
|
|
1234
25
|
}
|
|
1235
|
-
const highlighter = getHighlighter();
|
|
1236
|
-
return {
|
|
1237
|
-
nextSteps: selectedAddons.map(({ addon }) => {
|
|
1238
|
-
if (!addon.nextSteps) return;
|
|
1239
|
-
const addonOptions$1 = answersOfficial[addon.id];
|
|
1240
|
-
const addonNextSteps = addon.nextSteps({
|
|
1241
|
-
...workspace,
|
|
1242
|
-
options: addonOptions$1,
|
|
1243
|
-
highlighter
|
|
1244
|
-
});
|
|
1245
|
-
if (addonNextSteps.length === 0) return;
|
|
1246
|
-
let addonMessage = `${import_picocolors$2.default.green(addon.id)}:\n`;
|
|
1247
|
-
addonMessage += ` - ${addonNextSteps.join("\n - ")}`;
|
|
1248
|
-
return addonMessage;
|
|
1249
|
-
}).filter((msg) => msg !== void 0),
|
|
1250
|
-
argsFormattedAddons,
|
|
1251
|
-
filesToFormat
|
|
1252
|
-
};
|
|
1253
|
-
}
|
|
1254
|
-
/**
|
|
1255
|
-
* Sanitizes the add-on arguments by checking for invalid add-ons and transforming aliases.
|
|
1256
|
-
* @param addonArgs The add-on arguments to sanitize.
|
|
1257
|
-
* @returns The sanitized add-on arguments.
|
|
1258
|
-
*/
|
|
1259
|
-
function sanitizeAddons(addonArgs) {
|
|
1260
|
-
const officialAddonIds = officialAddons$1.map((addon) => addon.id);
|
|
1261
|
-
const invalidAddons = addonArgs.filter(({ id }) => !officialAddonIds.includes(id) && !aliases.includes(id)).map(({ id }) => id);
|
|
1262
|
-
if (invalidAddons.length > 0) errorAndExit(`Invalid add-ons specified: ${invalidAddons.join(", ")}`);
|
|
1263
|
-
return transformAliases(addonArgs);
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Handles passed add-on arguments, accumulating them into an array of {@link AddonArgs}.
|
|
1267
|
-
*/
|
|
1268
|
-
function addonArgsHandler(acc, current) {
|
|
1269
|
-
const [addonId, optionFlags] = current.split("=", 2);
|
|
1270
|
-
if (acc.find(({ id }) => id === addonId)) errorAndExit(`Malformed arguments: Add-on '${addonId}' is repeated multiple times.`);
|
|
1271
26
|
try {
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
27
|
+
const cmd = resolveCommand(pm, "execute-local", ["svelte-check", ...args]);
|
|
28
|
+
execSync(`${cmd.command} ${cmd.args.join(" ")}`, {
|
|
29
|
+
stdio: "inherit",
|
|
30
|
+
cwd: cwd$1
|
|
1276
31
|
});
|
|
1277
32
|
} catch (error) {
|
|
1278
|
-
|
|
1279
|
-
console.error(error);
|
|
1280
|
-
process.exit(1);
|
|
1281
|
-
}
|
|
1282
|
-
return acc;
|
|
1283
|
-
}
|
|
1284
|
-
/**
|
|
1285
|
-
* Dedupes and transforms aliases into their respective addon id
|
|
1286
|
-
*/
|
|
1287
|
-
function transformAliases(addons) {
|
|
1288
|
-
const set = /* @__PURE__ */ new Map();
|
|
1289
|
-
for (const addon of addons) if (aliases.includes(addon.id)) {
|
|
1290
|
-
const officialAddon = officialAddons$1.find((a) => a.alias === addon.id);
|
|
1291
|
-
set.set(officialAddon.id, {
|
|
1292
|
-
id: officialAddon.id,
|
|
1293
|
-
options: addon.options
|
|
1294
|
-
});
|
|
1295
|
-
} else set.set(addon.id, addon);
|
|
1296
|
-
return Array.from(set.values());
|
|
1297
|
-
}
|
|
1298
|
-
function getAddonOptionFlags() {
|
|
1299
|
-
const options$1 = [];
|
|
1300
|
-
for (const addon of officialAddons$1) {
|
|
1301
|
-
const id = addon.id;
|
|
1302
|
-
const details = getAddonDetails(id);
|
|
1303
|
-
if (Object.values(details.options).length === 0) continue;
|
|
1304
|
-
const { defaults, groups } = getOptionChoices(details);
|
|
1305
|
-
const choices = Object.entries(groups).map(([group, choices$1]) => `${import_picocolors$2.default.dim(`${group}:`)} ${choices$1.join(", ")}`).join("\n");
|
|
1306
|
-
const preset = defaults.join(", ") || "none";
|
|
1307
|
-
options$1.push({
|
|
1308
|
-
id,
|
|
1309
|
-
choices,
|
|
1310
|
-
preset
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
return options$1;
|
|
1314
|
-
}
|
|
1315
|
-
function getOptionChoices(details) {
|
|
1316
|
-
const choices = [];
|
|
1317
|
-
const defaults = [];
|
|
1318
|
-
const groups = {};
|
|
1319
|
-
const options$1 = {};
|
|
1320
|
-
for (const [id, question] of Object.entries(details.options)) {
|
|
1321
|
-
let values = [];
|
|
1322
|
-
const applyDefault = question.condition?.(options$1) !== false;
|
|
1323
|
-
if (question.type === "boolean") {
|
|
1324
|
-
values = ["yes", `no`];
|
|
1325
|
-
if (applyDefault) {
|
|
1326
|
-
options$1[id] = question.default;
|
|
1327
|
-
defaults.push(question.default ? values[0] : values[1]);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
if (question.type === "select") {
|
|
1331
|
-
values = question.options.map((o) => o.value);
|
|
1332
|
-
if (applyDefault) {
|
|
1333
|
-
options$1[id] = question.default;
|
|
1334
|
-
defaults.push(question.default);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
if (question.type === "multiselect") {
|
|
1338
|
-
values = question.options.map((o) => o.value);
|
|
1339
|
-
if (applyDefault) {
|
|
1340
|
-
options$1[id] = question.default;
|
|
1341
|
-
defaults.push(...question.default);
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
if (question.type === "string" || question.type === "number") {
|
|
1345
|
-
values = ["<user-input>"];
|
|
1346
|
-
if (applyDefault) {
|
|
1347
|
-
options$1[id] = question.default;
|
|
1348
|
-
defaults.push(question.default.toString());
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
choices.push(...values);
|
|
1352
|
-
const groupId = question.group ?? id;
|
|
1353
|
-
groups[groupId] ??= [];
|
|
1354
|
-
groups[groupId].push(...values);
|
|
1355
|
-
}
|
|
1356
|
-
return {
|
|
1357
|
-
choices,
|
|
1358
|
-
defaults,
|
|
1359
|
-
groups
|
|
1360
|
-
};
|
|
1361
|
-
}
|
|
1362
|
-
async function resolveCommunityAddons(cwd$1, community) {
|
|
1363
|
-
const selectedAddons = [];
|
|
1364
|
-
const addons = community.map((id) => {
|
|
1365
|
-
if (Object.values(Directive).some((directive) => id.startsWith(directive))) return id;
|
|
1366
|
-
if (!communityAddonIds.includes(id)) throw new Error(`Invalid community add-on specified: '${id}'\nAvailable options: ${communityAddonIds.join(", ")}`);
|
|
1367
|
-
return id;
|
|
1368
|
-
});
|
|
1369
|
-
const { start, stop } = J();
|
|
1370
|
-
try {
|
|
1371
|
-
start("Resolving community add-on packages");
|
|
1372
|
-
const pkgs = await Promise.all(addons.map(async (id) => {
|
|
1373
|
-
return await getPackageJSON({
|
|
1374
|
-
cwd: cwd$1,
|
|
1375
|
-
packageName: id
|
|
1376
|
-
});
|
|
1377
|
-
}));
|
|
1378
|
-
stop("Resolved community add-on packages");
|
|
1379
|
-
T.warn("The Svelte maintainers have not reviewed community add-ons for malicious code. Use at your discretion.");
|
|
1380
|
-
const paddingName = getPadding(pkgs.map(({ pkg }) => pkg.name));
|
|
1381
|
-
const paddingVersion = getPadding(pkgs.map(({ pkg }) => `(v${pkg.version})`));
|
|
1382
|
-
const packageInfos = pkgs.map(({ pkg, repo: _repo }) => {
|
|
1383
|
-
return `${import_picocolors$2.default.yellowBright(pkg.name.padEnd(paddingName))} ${import_picocolors$2.default.dim(`(v${pkg.version})`.padEnd(paddingVersion))} ${import_picocolors$2.default.dim(`(${_repo})`)}`;
|
|
1384
|
-
});
|
|
1385
|
-
T.message(packageInfos.join("\n"));
|
|
1386
|
-
if (await ke({ message: "Would you like to continue?" }) !== true) {
|
|
1387
|
-
De("Operation cancelled.");
|
|
1388
|
-
process.exit(1);
|
|
1389
|
-
}
|
|
1390
|
-
start("Downloading community add-on packages");
|
|
1391
|
-
const details = await Promise.all(pkgs.map(async (opts) => downloadPackage(opts)));
|
|
1392
|
-
for (const addon of details) {
|
|
1393
|
-
communityDetails.push(addon);
|
|
1394
|
-
selectedAddons.push(addon);
|
|
1395
|
-
}
|
|
1396
|
-
stop("Downloaded community add-on packages");
|
|
1397
|
-
} catch (err) {
|
|
1398
|
-
stop("Failed to resolve community add-on packages", 1);
|
|
1399
|
-
throw err;
|
|
1400
|
-
}
|
|
1401
|
-
return selectedAddons;
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
//#endregion
|
|
1405
|
-
//#region lib/create/playground.ts
|
|
1406
|
-
function validatePlaygroundUrl(link) {
|
|
1407
|
-
try {
|
|
1408
|
-
const url = new URL(link);
|
|
1409
|
-
if (url.hostname !== "svelte.dev" || !url.pathname.startsWith("/playground/")) return false;
|
|
1410
|
-
const { playgroundId, hash } = parsePlaygroundUrl(link);
|
|
1411
|
-
return playgroundId !== void 0 || hash !== void 0;
|
|
1412
|
-
} catch {
|
|
1413
|
-
return false;
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
function parsePlaygroundUrl(link) {
|
|
1417
|
-
const url = new URL(link);
|
|
1418
|
-
const [, playgroundId] = url.pathname.match(/\/playground\/([^/]+)/) || [];
|
|
1419
|
-
return {
|
|
1420
|
-
playgroundId,
|
|
1421
|
-
hash: url.hash !== "" ? url.hash.slice(1) : void 0,
|
|
1422
|
-
svelteVersion: url.searchParams.get("version") || void 0
|
|
1423
|
-
};
|
|
1424
|
-
}
|
|
1425
|
-
async function downloadPlaygroundData({ playgroundId, hash, svelteVersion }) {
|
|
1426
|
-
let data = [];
|
|
1427
|
-
if (hash) data = JSON.parse(await decodeAndDecompressText(hash));
|
|
1428
|
-
else data = await (await fetch(`https://svelte.dev/playground/api/${playgroundId}.json`)).json();
|
|
1429
|
-
const files = data.components !== void 0 ? data.components : data.files;
|
|
1430
|
-
return {
|
|
1431
|
-
name: data.name,
|
|
1432
|
-
files: files.map((file) => {
|
|
1433
|
-
return {
|
|
1434
|
-
name: file.name + (file.type !== "file" ? `.${file.type}` : ""),
|
|
1435
|
-
content: file.source || file.contents
|
|
1436
|
-
};
|
|
1437
|
-
}),
|
|
1438
|
-
svelteVersion
|
|
1439
|
-
};
|
|
1440
|
-
}
|
|
1441
|
-
async function decodeAndDecompressText(input) {
|
|
1442
|
-
const decoded = atob(input.replaceAll("-", "+").replaceAll("_", "/"));
|
|
1443
|
-
const u8 = new Uint8Array(decoded.length);
|
|
1444
|
-
for (let i = 0; i < decoded.length; i++) u8[i] = decoded.charCodeAt(i);
|
|
1445
|
-
const stream = new Blob([u8]).stream().pipeThrough(new DecompressionStream("gzip"));
|
|
1446
|
-
return new Response(stream).text();
|
|
1447
|
-
}
|
|
1448
|
-
/**
|
|
1449
|
-
* @returns A Map of packages with it's name as the key, and it's version as the value.
|
|
1450
|
-
*/
|
|
1451
|
-
function detectPlaygroundDependencies(files) {
|
|
1452
|
-
const packages = /* @__PURE__ */ new Map();
|
|
1453
|
-
const excludedPrefixes = [
|
|
1454
|
-
"$",
|
|
1455
|
-
"node:",
|
|
1456
|
-
"svelte",
|
|
1457
|
-
"@sveltejs/"
|
|
1458
|
-
];
|
|
1459
|
-
for (const file of files) {
|
|
1460
|
-
let ast;
|
|
1461
|
-
if (file.name.endsWith(".svelte")) {
|
|
1462
|
-
const { ast: svelteAst } = parseSvelte(file.content);
|
|
1463
|
-
ast = ensureScript(svelteAst);
|
|
1464
|
-
} else if (file.name.endsWith(".js") || file.name.endsWith(".ts")) ast = parseScript(file.content).ast;
|
|
1465
|
-
if (!ast) continue;
|
|
1466
|
-
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));
|
|
1467
|
-
}
|
|
1468
|
-
return packages;
|
|
1469
|
-
}
|
|
1470
|
-
/**
|
|
1471
|
-
* Extracts a package's name and it's versions from a provided import path.
|
|
1472
|
-
*
|
|
1473
|
-
* Handles imports with or without subpaths (e.g. `pkg-name/subpath`, `@org/pkg-name/subpath`)
|
|
1474
|
-
* as well as specified versions (e.g. pkg-name@1.2.3).
|
|
1475
|
-
*/
|
|
1476
|
-
function extractPackageInfo(importPath) {
|
|
1477
|
-
let pkgName = "";
|
|
1478
|
-
if (importPath.startsWith("@")) {
|
|
1479
|
-
const [org, pkg, _subpath] = importPath.split("/", 3);
|
|
1480
|
-
pkgName = `${org}/${pkg}`;
|
|
1481
|
-
}
|
|
1482
|
-
if (!pkgName) [pkgName] = importPath.split("/", 2);
|
|
1483
|
-
const version$1 = extractPackageVersion(pkgName);
|
|
1484
|
-
if (version$1 !== "latest") pkgName = pkgName.replace(`@${version$1}`, "");
|
|
1485
|
-
return {
|
|
1486
|
-
pkgName,
|
|
1487
|
-
version: version$1
|
|
1488
|
-
};
|
|
1489
|
-
}
|
|
1490
|
-
function extractPackageVersion(pkgName) {
|
|
1491
|
-
let version$1 = "latest";
|
|
1492
|
-
if (pkgName.includes("@", 1)) [, version$1] = pkgName.split("@");
|
|
1493
|
-
return version$1;
|
|
1494
|
-
}
|
|
1495
|
-
function setupPlaygroundProject(url, playground, cwd$1, installDependencies$1) {
|
|
1496
|
-
const mainFile = playground.files.find((file) => file.name === "App.svelte");
|
|
1497
|
-
if (!mainFile) throw new Error("Failed to find `App.svelte` entrypoint.");
|
|
1498
|
-
const dependencies = detectPlaygroundDependencies(playground.files);
|
|
1499
|
-
for (const file of playground.files) {
|
|
1500
|
-
for (const [pkg, version$1] of dependencies) if (version$1 !== "latest") file.content = file.content.replaceAll(`${pkg}@${version$1}`, pkg);
|
|
1501
|
-
const filePath$1 = path.join(cwd$1, "src", "lib", "playground", file.name);
|
|
1502
|
-
fs.mkdirSync(path.dirname(filePath$1), { recursive: true });
|
|
1503
|
-
fs.writeFileSync(filePath$1, file.content, "utf8");
|
|
1504
|
-
}
|
|
1505
|
-
{
|
|
1506
|
-
const playgroundFiles = getSharedFiles().filter((file) => file.include.includes("playground"));
|
|
1507
|
-
for (const file of playgroundFiles) {
|
|
1508
|
-
let contentToWrite = file.contents;
|
|
1509
|
-
if (file.name === "src/lib/PlaygroundLayout.svelte") {
|
|
1510
|
-
const { ast: ast$1, generateCode: generateCode$1 } = parseSvelte(file.contents);
|
|
1511
|
-
walk(ensureScript(ast$1), null, { Literal(node) {
|
|
1512
|
-
if (node.value === "$sv-title-$sv") {
|
|
1513
|
-
node.value = playground.name;
|
|
1514
|
-
node.raw = void 0;
|
|
1515
|
-
} else if (node.value === "$sv-url-$sv") {
|
|
1516
|
-
node.value = url;
|
|
1517
|
-
node.raw = void 0;
|
|
1518
|
-
}
|
|
1519
|
-
} });
|
|
1520
|
-
contentToWrite = generateCode$1();
|
|
1521
|
-
}
|
|
1522
|
-
fs.writeFileSync(path.join(cwd$1, file.name), contentToWrite, "utf-8");
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
const filePath = path.join(cwd$1, "src/routes/+page.svelte");
|
|
1526
|
-
const { ast, generateCode } = parseSvelte(fs.readFileSync(filePath, "utf-8"));
|
|
1527
|
-
const scriptAst = ensureScript(ast);
|
|
1528
|
-
addDefault(scriptAst, {
|
|
1529
|
-
as: "App",
|
|
1530
|
-
from: `$lib/playground/${mainFile.name}`
|
|
1531
|
-
});
|
|
1532
|
-
addDefault(scriptAst, {
|
|
1533
|
-
as: "PlaygroundLayout",
|
|
1534
|
-
from: `$lib/PlaygroundLayout.svelte`
|
|
1535
|
-
});
|
|
1536
|
-
ast.fragment.nodes.push(...toFragment(`<PlaygroundLayout>
|
|
1537
|
-
<App />
|
|
1538
|
-
</PlaygroundLayout>`));
|
|
1539
|
-
const newContent = generateCode();
|
|
1540
|
-
fs.writeFileSync(filePath, newContent, "utf-8");
|
|
1541
|
-
const pkgPath = path.join(cwd$1, commonFilePaths.packageJson);
|
|
1542
|
-
const pkgJson = parseJson(fs.readFileSync(pkgPath, "utf-8"));
|
|
1543
|
-
let updatePackageJson = false;
|
|
1544
|
-
if (installDependencies$1 && dependencies.size >= 0) {
|
|
1545
|
-
updatePackageJson = true;
|
|
1546
|
-
pkgJson.data.dependencies ??= {};
|
|
1547
|
-
for (const [dep, version$1] of dependencies) pkgJson.data.dependencies[dep] = version$1;
|
|
1548
|
-
}
|
|
1549
|
-
let experimentalAsyncNeeded = true;
|
|
1550
|
-
const addExperimentalAsync = () => {
|
|
1551
|
-
const svelteConfigPath = path.join(cwd$1, commonFilePaths.svelteConfig);
|
|
1552
|
-
const { ast: ast$1, generateCode: generateCode$1 } = parseScript(fs.readFileSync(svelteConfigPath, "utf-8"));
|
|
1553
|
-
const { value: config } = createDefault(ast$1, { fallback: create$2({}) });
|
|
1554
|
-
overrideProperties(config, { compilerOptions: { experimental: { async: true } } });
|
|
1555
|
-
fs.writeFileSync(svelteConfigPath, generateCode$1(), "utf-8");
|
|
1556
|
-
};
|
|
1557
|
-
if (playground.svelteVersion) {
|
|
1558
|
-
updatePackageJson = true;
|
|
1559
|
-
const match = /^(pr|commit|branch)-(.+)/.exec(playground.svelteVersion);
|
|
1560
|
-
const version$1 = match ? `https://pkg.pr.new/svelte@${match[2]}` : `${playground.svelteVersion}`;
|
|
1561
|
-
pkgJson.data.devDependencies["svelte"] = version$1;
|
|
1562
|
-
if (!version$1.includes("pkg.pr.new")) {
|
|
1563
|
-
if (isVersionUnsupportedBelow(version$1, "5.36")) experimentalAsyncNeeded = false;
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
if (experimentalAsyncNeeded) addExperimentalAsync();
|
|
1567
|
-
if (updatePackageJson) fs.writeFileSync(pkgPath, pkgJson.generateCode(), "utf-8");
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
//#endregion
|
|
1571
|
-
//#region lib/cli/create.ts
|
|
1572
|
-
var import_picocolors$1 = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
1573
|
-
const langs = ["ts", "jsdoc"];
|
|
1574
|
-
const langMap = {
|
|
1575
|
-
ts: "typescript",
|
|
1576
|
-
jsdoc: "checkjs",
|
|
1577
|
-
false: "none"
|
|
1578
|
-
};
|
|
1579
|
-
const templateChoices = templates.map((t) => t.name);
|
|
1580
|
-
const langOption = new Option("--types <lang>", "add type checking").choices(langs);
|
|
1581
|
-
const templateOption = new Option("--template <type>", "template to scaffold").choices(templateChoices);
|
|
1582
|
-
const noAddonsOption = new Option("--no-add-ons", "do not prompt to add add-ons").conflicts("add");
|
|
1583
|
-
const addOption = new Option("--add <addon...>", "add-on to include").default([]);
|
|
1584
|
-
const ProjectPathSchema = optional(string());
|
|
1585
|
-
const OptionsSchema = strictObject({
|
|
1586
|
-
types: pipe(optional(union([picklist(langs), boolean()])), transform((lang) => langMap[String(lang)])),
|
|
1587
|
-
addOns: boolean(),
|
|
1588
|
-
add: array(string()),
|
|
1589
|
-
install: union([boolean(), picklist(AGENT_NAMES)]),
|
|
1590
|
-
template: optional(picklist(templateChoices)),
|
|
1591
|
-
fromPlayground: optional(string()),
|
|
1592
|
-
dirCheck: boolean()
|
|
1593
|
-
});
|
|
1594
|
-
const create = new Command("create").description("scaffolds a new SvelteKit project").argument("[path]", "where the project will be created").addOption(templateOption).addOption(langOption).option("--no-types").addOption(noAddonsOption).addOption(addOption).option("--no-install", "skip installing dependencies").option("--from-playground <url>", "create a project from the svelte playground").option("--no-dir-check", "even if the folder is not empty, no prompt will be shown").addOption(installOption).configureHelp(helpConfig).action((projectPath, opts) => {
|
|
1595
|
-
const cwd$1 = parse(ProjectPathSchema, projectPath);
|
|
1596
|
-
const options$1 = parse(OptionsSchema, opts);
|
|
1597
|
-
if (options$1.fromPlayground && !validatePlaygroundUrl(options$1.fromPlayground)) {
|
|
1598
|
-
console.error(import_picocolors$1.default.red(`Error: Invalid playground URL: ${options$1.fromPlayground}`));
|
|
1599
|
-
process.exit(1);
|
|
1600
|
-
}
|
|
1601
|
-
runCommand(async () => {
|
|
1602
|
-
const { directory, addOnNextSteps, packageManager } = await createProject(cwd$1, options$1);
|
|
1603
|
-
const highlight = (str) => import_picocolors$1.default.bold(import_picocolors$1.default.cyan(str));
|
|
1604
|
-
let i = 1;
|
|
1605
|
-
const initialSteps = ["📁 Project steps", ""];
|
|
1606
|
-
const relative = path.relative(process.cwd(), directory);
|
|
1607
|
-
const pm = packageManager ?? (await detect({ cwd: directory }))?.name ?? getUserAgent() ?? "npm";
|
|
1608
|
-
if (relative !== "") {
|
|
1609
|
-
const pathHasSpaces = relative.includes(" ");
|
|
1610
|
-
initialSteps.push(` ${i++}: ${highlight(`cd ${pathHasSpaces ? `"${relative}"` : relative}`)}`);
|
|
1611
|
-
}
|
|
1612
|
-
if (!packageManager) {
|
|
1613
|
-
const { args: args$1, command: command$1 } = resolveCommand(pm, "install", []);
|
|
1614
|
-
initialSteps.push(` ${i++}: ${highlight(`${command$1} ${args$1.join(" ")}`)}`);
|
|
1615
|
-
}
|
|
1616
|
-
const { args, command } = resolveCommand(pm, "run", ["dev", "--open"]);
|
|
1617
|
-
const pmRunCmd = `${command} ${args.join(" ")}`;
|
|
1618
|
-
const steps = [
|
|
1619
|
-
...initialSteps,
|
|
1620
|
-
` ${i++}: ${highlight(pmRunCmd)}`,
|
|
1621
|
-
"",
|
|
1622
|
-
`To close the dev server, hit ${highlight("Ctrl-C")}`
|
|
1623
|
-
];
|
|
1624
|
-
if (addOnNextSteps.length > 0) {
|
|
1625
|
-
steps.push("", "🧩 Add-on steps", "");
|
|
1626
|
-
for (const step of addOnNextSteps) {
|
|
1627
|
-
const indented = step.replaceAll(" -", " -");
|
|
1628
|
-
steps.push(` ${indented}`);
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
steps.push("", `Stuck? Visit us at ${import_picocolors$1.default.cyan("https://svelte.dev/chat")}`);
|
|
1632
|
-
Ke(steps.join("\n"), "What's next?", { format: (line) => line });
|
|
1633
|
-
});
|
|
1634
|
-
}).showHelpAfterError(true);
|
|
1635
|
-
async function createProject(cwd$1, options$1) {
|
|
1636
|
-
if (options$1.fromPlayground) T.warn("The Svelte maintainers have not reviewed playgrounds for malicious code. Use at your discretion.");
|
|
1637
|
-
const { directory, template, language } = await We({
|
|
1638
|
-
directory: () => {
|
|
1639
|
-
const defaultPath = "./";
|
|
1640
|
-
if (cwd$1) return Promise.resolve(cwd$1);
|
|
1641
|
-
return et({
|
|
1642
|
-
message: "Where would you like your project to be created?",
|
|
1643
|
-
placeholder: ` (hit Enter to use '${defaultPath}')`,
|
|
1644
|
-
defaultValue: defaultPath
|
|
1645
|
-
});
|
|
1646
|
-
},
|
|
1647
|
-
force: async ({ results: { directory: directory$1 } }) => {
|
|
1648
|
-
if (!options$1.dirCheck) return;
|
|
1649
|
-
if (!fs.existsSync(directory$1)) return;
|
|
1650
|
-
if (!fs.readdirSync(directory$1).some((file) => !file.startsWith(".git"))) return;
|
|
1651
|
-
const force = await ke({
|
|
1652
|
-
message: "Directory not empty. Continue?",
|
|
1653
|
-
initialValue: false
|
|
1654
|
-
});
|
|
1655
|
-
if (Vu(force) || !force) {
|
|
1656
|
-
De("Exiting.");
|
|
1657
|
-
process.exit(0);
|
|
1658
|
-
}
|
|
1659
|
-
},
|
|
1660
|
-
template: () => {
|
|
1661
|
-
if (options$1.template) return Promise.resolve(options$1.template);
|
|
1662
|
-
if (options$1.fromPlayground) return Promise.resolve("minimal");
|
|
1663
|
-
return ze({
|
|
1664
|
-
message: "Which template would you like?",
|
|
1665
|
-
initialValue: "minimal",
|
|
1666
|
-
options: templates.map((t) => ({
|
|
1667
|
-
label: t.title,
|
|
1668
|
-
value: t.name,
|
|
1669
|
-
hint: t.description
|
|
1670
|
-
}))
|
|
1671
|
-
});
|
|
1672
|
-
},
|
|
1673
|
-
language: () => {
|
|
1674
|
-
if (options$1.types) return Promise.resolve(options$1.types);
|
|
1675
|
-
return ze({
|
|
1676
|
-
message: "Add type checking with TypeScript?",
|
|
1677
|
-
initialValue: "typescript",
|
|
1678
|
-
options: [
|
|
1679
|
-
{
|
|
1680
|
-
label: "Yes, using TypeScript syntax",
|
|
1681
|
-
value: "typescript"
|
|
1682
|
-
},
|
|
1683
|
-
{
|
|
1684
|
-
label: "Yes, using JavaScript with JSDoc comments",
|
|
1685
|
-
value: "checkjs"
|
|
1686
|
-
},
|
|
1687
|
-
{
|
|
1688
|
-
label: "No",
|
|
1689
|
-
value: "none"
|
|
1690
|
-
}
|
|
1691
|
-
]
|
|
1692
|
-
});
|
|
1693
|
-
}
|
|
1694
|
-
}, { onCancel: () => {
|
|
1695
|
-
De("Operation cancelled.");
|
|
1696
|
-
process.exit(0);
|
|
1697
|
-
} });
|
|
1698
|
-
const projectPath = path.resolve(directory);
|
|
1699
|
-
const projectName = path.basename(projectPath);
|
|
1700
|
-
let selectedAddons = [];
|
|
1701
|
-
let answersOfficial = {};
|
|
1702
|
-
let answersCommunity = {};
|
|
1703
|
-
let sanitizedAddonsMap = {};
|
|
1704
|
-
const workspace = await createVirtualWorkspace({
|
|
1705
|
-
cwd: projectPath,
|
|
1706
|
-
template,
|
|
1707
|
-
type: language
|
|
1708
|
-
});
|
|
1709
|
-
if (options$1.addOns || options$1.add.length > 0) {
|
|
1710
|
-
sanitizedAddonsMap = sanitizeAddons(options$1.add.reduce(addonArgsHandler, [])).reduce((acc, curr) => {
|
|
1711
|
-
acc[curr.id] = curr.options;
|
|
1712
|
-
return acc;
|
|
1713
|
-
}, {});
|
|
1714
|
-
const result = await promptAddonQuestions({
|
|
1715
|
-
options: {
|
|
1716
|
-
cwd: projectPath,
|
|
1717
|
-
install: false,
|
|
1718
|
-
gitCheck: false,
|
|
1719
|
-
community: [],
|
|
1720
|
-
addons: sanitizedAddonsMap
|
|
1721
|
-
},
|
|
1722
|
-
selectedAddonIds: Object.keys(sanitizedAddonsMap),
|
|
1723
|
-
workspace
|
|
1724
|
-
});
|
|
1725
|
-
selectedAddons = result.selectedAddons;
|
|
1726
|
-
answersOfficial = result.answersOfficial;
|
|
1727
|
-
answersCommunity = result.answersCommunity;
|
|
1728
|
-
}
|
|
1729
|
-
create$1(projectPath, {
|
|
1730
|
-
name: projectName,
|
|
1731
|
-
template,
|
|
1732
|
-
types: language
|
|
1733
|
-
});
|
|
1734
|
-
if (options$1.fromPlayground) await createProjectFromPlayground(options$1.fromPlayground, projectPath);
|
|
1735
|
-
T.success("Project created");
|
|
1736
|
-
let addOnNextSteps = [];
|
|
1737
|
-
let argsFormattedAddons = [];
|
|
1738
|
-
let addOnFilesToFormat = [];
|
|
1739
|
-
if (options$1.addOns || options$1.add.length > 0) {
|
|
1740
|
-
const { nextSteps, argsFormattedAddons: argsFormatted$1, filesToFormat } = await runAddonsApply({
|
|
1741
|
-
answersOfficial,
|
|
1742
|
-
answersCommunity,
|
|
1743
|
-
options: {
|
|
1744
|
-
cwd: projectPath,
|
|
1745
|
-
install: false,
|
|
1746
|
-
gitCheck: false,
|
|
1747
|
-
community: [],
|
|
1748
|
-
addons: sanitizedAddonsMap
|
|
1749
|
-
},
|
|
1750
|
-
selectedAddons,
|
|
1751
|
-
addonSetupResults: void 0,
|
|
1752
|
-
workspace,
|
|
1753
|
-
fromCommand: "create"
|
|
1754
|
-
});
|
|
1755
|
-
argsFormattedAddons = argsFormatted$1;
|
|
1756
|
-
addOnFilesToFormat = filesToFormat;
|
|
1757
|
-
addOnNextSteps = nextSteps;
|
|
1758
|
-
}
|
|
1759
|
-
const packageManager = options$1.install === false ? null : options$1.install === true ? await packageManagerPrompt(projectPath) : options$1.install;
|
|
1760
|
-
const argsFormatted = [];
|
|
1761
|
-
argsFormatted.push("--template", template);
|
|
1762
|
-
if (language === "typescript") argsFormatted.push("--types", "ts");
|
|
1763
|
-
else if (language === "checkjs") argsFormatted.push("--types", "jsdoc");
|
|
1764
|
-
else if (language === "none") argsFormatted.push("--no-types");
|
|
1765
|
-
if (argsFormattedAddons.length > 0) argsFormatted.push("--add", ...argsFormattedAddons);
|
|
1766
|
-
logArgs(packageManager, "create", argsFormatted, [directory]);
|
|
1767
|
-
await addPnpmBuildDependencies(projectPath, packageManager, ["esbuild"]);
|
|
1768
|
-
if (packageManager) {
|
|
1769
|
-
await installDependencies(packageManager, projectPath);
|
|
1770
|
-
await formatFiles({
|
|
1771
|
-
packageManager,
|
|
1772
|
-
cwd: projectPath,
|
|
1773
|
-
filesToFormat: addOnFilesToFormat
|
|
1774
|
-
});
|
|
1775
|
-
}
|
|
1776
|
-
return {
|
|
1777
|
-
directory: projectPath,
|
|
1778
|
-
addOnNextSteps,
|
|
1779
|
-
packageManager
|
|
1780
|
-
};
|
|
1781
|
-
}
|
|
1782
|
-
async function createProjectFromPlayground(url, cwd$1) {
|
|
1783
|
-
const playground = await downloadPlaygroundData(parsePlaygroundUrl(url));
|
|
1784
|
-
const dependencies = detectPlaygroundDependencies(playground.files);
|
|
1785
|
-
setupPlaygroundProject(url, playground, cwd$1, await confirmExternalDependencies(Array.from(dependencies.keys())));
|
|
1786
|
-
}
|
|
1787
|
-
async function confirmExternalDependencies(dependencies) {
|
|
1788
|
-
if (dependencies.length === 0) return false;
|
|
1789
|
-
const dependencyList = dependencies.map(import_picocolors$1.default.yellowBright).join(", ");
|
|
1790
|
-
T.warn(`The following external dependencies were found in the playground:\n\n${dependencyList}`);
|
|
1791
|
-
const installDeps = await ke({
|
|
1792
|
-
message: "Do you want to install these external dependencies?",
|
|
1793
|
-
initialValue: false
|
|
1794
|
-
});
|
|
1795
|
-
if (Vu(installDeps)) {
|
|
1796
|
-
De("Operation cancelled.");
|
|
1797
|
-
process.exit(0);
|
|
33
|
+
forwardExitCode(error);
|
|
1798
34
|
}
|
|
1799
|
-
return installDeps;
|
|
1800
|
-
}
|
|
1801
|
-
async function createVirtualWorkspace({ cwd: cwd$1, template, type }) {
|
|
1802
|
-
const override = { dependencies: {} };
|
|
1803
|
-
if (template === "minimal" || template === "demo" || template === "library") override.kit = {
|
|
1804
|
-
routesDirectory: "src/routes",
|
|
1805
|
-
libDirectory: "src/lib"
|
|
1806
|
-
};
|
|
1807
|
-
const { data: packageJson } = getPackageJson(dist(`templates/${template}`));
|
|
1808
|
-
override.dependencies = {
|
|
1809
|
-
...packageJson.devDependencies,
|
|
1810
|
-
...packageJson.dependencies,
|
|
1811
|
-
...override.dependencies
|
|
1812
|
-
};
|
|
1813
|
-
const tentativeWorkspace = await createWorkspace({
|
|
1814
|
-
cwd: cwd$1,
|
|
1815
|
-
override
|
|
1816
|
-
});
|
|
1817
|
-
return {
|
|
1818
|
-
...tentativeWorkspace,
|
|
1819
|
-
typescript: type === "typescript",
|
|
1820
|
-
files: {
|
|
1821
|
-
...tentativeWorkspace.files,
|
|
1822
|
-
viteConfig: type === "typescript" ? commonFilePaths.viteConfigTS : commonFilePaths.viteConfig,
|
|
1823
|
-
svelteConfig: commonFilePaths.svelteConfig
|
|
1824
|
-
}
|
|
1825
|
-
};
|
|
1826
35
|
}
|
|
1827
36
|
|
|
1828
37
|
//#endregion
|
|
1829
38
|
//#region lib/cli/migrate.ts
|
|
1830
|
-
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
|
|
1831
|
-
runMigrate(options
|
|
39
|
+
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) => {
|
|
40
|
+
runMigrate(options.cwd, [migration]);
|
|
1832
41
|
});
|
|
1833
42
|
function runMigrate(cwd$1, args) {
|
|
1834
43
|
const pm = getUserAgent() ?? "npm";
|
|
@@ -1845,35 +54,6 @@ function runMigrate(cwd$1, args) {
|
|
|
1845
54
|
}
|
|
1846
55
|
}
|
|
1847
56
|
|
|
1848
|
-
//#endregion
|
|
1849
|
-
//#region lib/cli/check.ts
|
|
1850
|
-
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
1851
|
-
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() {
|
|
1852
|
-
runCheck(process.cwd(), ["--help"]);
|
|
1853
|
-
return "";
|
|
1854
|
-
} }).action((options$1, check$1) => {
|
|
1855
|
-
const cwd$1 = options$1.cwd;
|
|
1856
|
-
const args = check$1.args;
|
|
1857
|
-
runCheck(cwd$1, args);
|
|
1858
|
-
});
|
|
1859
|
-
function runCheck(cwd$1, args) {
|
|
1860
|
-
const pm = getUserAgent() ?? "npm";
|
|
1861
|
-
if (!from(cwd$1, "svelte-check", true)) {
|
|
1862
|
-
const cmd = resolveCommand(pm, "add", ["-D", "svelte-check"]);
|
|
1863
|
-
console.error(`'svelte-check' is not installed locally. Install it with: ${import_picocolors.default.bold(`${cmd.command} ${cmd.args.join(" ")}`)}`);
|
|
1864
|
-
process.exit(1);
|
|
1865
|
-
}
|
|
1866
|
-
try {
|
|
1867
|
-
const cmd = resolveCommand(pm, "execute-local", ["svelte-check", ...args]);
|
|
1868
|
-
execSync(`${cmd.command} ${cmd.args.join(" ")}`, {
|
|
1869
|
-
stdio: "inherit",
|
|
1870
|
-
cwd: cwd$1
|
|
1871
|
-
});
|
|
1872
|
-
} catch (error) {
|
|
1873
|
-
forwardExitCode(error);
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
57
|
//#endregion
|
|
1878
58
|
//#region bin.ts
|
|
1879
59
|
console.log();
|