sv 0.9.8 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +52 -17
- package/dist/{create-G_G45yBx.js → create-CdiXN6U7.js} +1 -1
- package/dist/{install-DhHe_LP6.js → install-CD-dlXd7.js} +346 -204
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.js +2 -2
- package/dist/lib/testing.js +1 -1
- package/dist/shared.json +8 -0
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Element, MagicString, T, Tag, __toESM, any, be, createPrinter, dedent_default, defineAddon, defineAddonOptions, detect, getUserAgent, import_picocolors as import_picocolors$2, parseCss, parseHtml, parseHtml$1, parseJson, parseScript, parseScript$1, parseSvelte, require_picocolors, resolveCommand, serializeScript, stripAst, walk } from "./create-
|
|
1
|
+
import { Element, MagicString, T, Tag, __toESM, any, be, createPrinter, dedent_default, defineAddon, defineAddonOptions, detect, getUserAgent, import_picocolors as import_picocolors$2, parseCss, parseHtml, parseHtml$1, parseJson, parseScript, parseScript$1, parseSvelte, require_picocolors, resolveCommand, serializeScript, stripAst, walk } from "./create-CdiXN6U7.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import process from "node:process";
|
|
@@ -21,10 +21,10 @@ function decircular(object) {
|
|
|
21
21
|
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region ../core/tooling/js/common.ts
|
|
24
|
-
function addJsDocTypeComment(node, options$
|
|
24
|
+
function addJsDocTypeComment(node, options$7) {
|
|
25
25
|
const comment = {
|
|
26
26
|
type: "Block",
|
|
27
|
-
value: `* @type {${options$
|
|
27
|
+
value: `* @type {${options$7.type}} `
|
|
28
28
|
};
|
|
29
29
|
addComment(node, comment);
|
|
30
30
|
}
|
|
@@ -49,8 +49,8 @@ function areNodesEqual(node, otherNode) {
|
|
|
49
49
|
const otherNodeClone = stripAst(decircular(otherNode), ["loc", "raw"]);
|
|
50
50
|
return serializeScript(nodeClone) === serializeScript(otherNodeClone);
|
|
51
51
|
}
|
|
52
|
-
function appendFromString(node, options$
|
|
53
|
-
const program = parseScript$1(dedent_default(options$
|
|
52
|
+
function appendFromString(node, options$7) {
|
|
53
|
+
const program = parseScript$1(dedent_default(options$7.code));
|
|
54
54
|
for (const childNode of program.body) node.body.push(childNode);
|
|
55
55
|
}
|
|
56
56
|
function parseExpression(code) {
|
|
@@ -67,8 +67,8 @@ function parseFromString(code) {
|
|
|
67
67
|
return parseScript$1(dedent_default(code)).body[0];
|
|
68
68
|
}
|
|
69
69
|
/** Appends the statement to body of the block if it doesn't already exist */
|
|
70
|
-
function appendStatement(node, options$
|
|
71
|
-
if (!contains(node, options$
|
|
70
|
+
function appendStatement(node, options$7) {
|
|
71
|
+
if (!contains(node, options$7.statement)) node.body.push(options$7.statement);
|
|
72
72
|
}
|
|
73
73
|
/** Returns `true` if the provided node exists in the AST */
|
|
74
74
|
function contains(node, targetNode) {
|
|
@@ -82,8 +82,8 @@ function contains(node, targetNode) {
|
|
|
82
82
|
} });
|
|
83
83
|
return found;
|
|
84
84
|
}
|
|
85
|
-
function hasTypeProperty(node, options$
|
|
86
|
-
return node.type === "TSPropertySignature" && node.key.type === "Identifier" && node.key.name === options$
|
|
85
|
+
function hasTypeProperty(node, options$7) {
|
|
86
|
+
return node.type === "TSPropertySignature" && node.key.type === "Identifier" && node.key.name === options$7.name;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
//#endregion
|
|
@@ -100,7 +100,7 @@ function append(node, element) {
|
|
|
100
100
|
function prepend(node, element) {
|
|
101
101
|
insertElement(node, element, { insertEnd: false });
|
|
102
102
|
}
|
|
103
|
-
function insertElement(node, element, options$
|
|
103
|
+
function insertElement(node, element, options$7) {
|
|
104
104
|
if (typeof element === "string") {
|
|
105
105
|
let literal = node.elements.filter((item) => item !== null && item.type === "Literal").find((item) => item.value === element);
|
|
106
106
|
if (!literal) {
|
|
@@ -108,31 +108,31 @@ function insertElement(node, element, options$6) {
|
|
|
108
108
|
type: "Literal",
|
|
109
109
|
value: element
|
|
110
110
|
};
|
|
111
|
-
if (options$
|
|
111
|
+
if (options$7.insertEnd) node.elements.push(literal);
|
|
112
112
|
else node.elements.unshift(literal);
|
|
113
113
|
}
|
|
114
|
-
} else if (!node.elements.some((item) => item && areNodesEqual(element, item))) if (options$
|
|
114
|
+
} else if (!node.elements.some((item) => item && areNodesEqual(element, item))) if (options$7.insertEnd) node.elements.push(element);
|
|
115
115
|
else node.elements.unshift(element);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region ../core/tooling/js/object.ts
|
|
120
|
-
function property(node, options$
|
|
121
|
-
return propertyNode(node, options$
|
|
120
|
+
function property(node, options$7) {
|
|
121
|
+
return propertyNode(node, options$7).value;
|
|
122
122
|
}
|
|
123
|
-
function propertyNode(node, options$
|
|
124
|
-
let prop = node.properties.filter((x$1) => x$1.type === "Property").find((x$1) => x$1.key.name === options$
|
|
123
|
+
function propertyNode(node, options$7) {
|
|
124
|
+
let prop = node.properties.filter((x$1) => x$1.type === "Property").find((x$1) => x$1.key.name === options$7.name);
|
|
125
125
|
if (!prop) {
|
|
126
126
|
let isShorthand = false;
|
|
127
|
-
if (options$
|
|
127
|
+
if (options$7.fallback.type === "Identifier") isShorthand = options$7.fallback.name === options$7.name;
|
|
128
128
|
prop = {
|
|
129
129
|
type: "Property",
|
|
130
130
|
shorthand: isShorthand,
|
|
131
131
|
key: {
|
|
132
132
|
type: "Identifier",
|
|
133
|
-
name: options$
|
|
133
|
+
name: options$7.name
|
|
134
134
|
},
|
|
135
|
-
value: options$
|
|
135
|
+
value: options$7.fallback,
|
|
136
136
|
kind: "init",
|
|
137
137
|
computed: false,
|
|
138
138
|
method: false
|
|
@@ -158,67 +158,67 @@ function overrideProperties(objectExpression, properties) {
|
|
|
158
158
|
override: true
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
-
function overrideProperty(node, options$
|
|
162
|
-
const prop = node.properties.filter((x$1) => x$1.type === "Property").find((x$1) => x$1.key.name === options$
|
|
161
|
+
function overrideProperty(node, options$7) {
|
|
162
|
+
const prop = node.properties.filter((x$1) => x$1.type === "Property").find((x$1) => x$1.key.name === options$7.name);
|
|
163
163
|
if (!prop) return property(node, {
|
|
164
|
-
name: options$
|
|
165
|
-
fallback: options$
|
|
164
|
+
name: options$7.name,
|
|
165
|
+
fallback: options$7.value
|
|
166
166
|
});
|
|
167
|
-
prop.value = options$
|
|
168
|
-
return options$
|
|
167
|
+
prop.value = options$7.value;
|
|
168
|
+
return options$7.value;
|
|
169
169
|
}
|
|
170
|
-
function populateObjectExpression(options$
|
|
170
|
+
function populateObjectExpression(options$7) {
|
|
171
171
|
const getExpression = (value, existingExpression) => {
|
|
172
172
|
let expression;
|
|
173
173
|
if (Array.isArray(value)) {
|
|
174
174
|
expression = create$1();
|
|
175
175
|
for (const v of value) append(expression, getExpression(v));
|
|
176
176
|
} else if (typeof value === "object" && value !== null) if (value.type !== void 0) expression = value;
|
|
177
|
-
else if (options$
|
|
177
|
+
else if (options$7.override && existingExpression && existingExpression.type === "ObjectExpression") expression = populateObjectExpression({
|
|
178
178
|
objectExpression: existingExpression,
|
|
179
179
|
properties: value,
|
|
180
|
-
override: options$
|
|
180
|
+
override: options$7.override
|
|
181
181
|
});
|
|
182
182
|
else expression = populateObjectExpression({
|
|
183
183
|
objectExpression: create({}),
|
|
184
184
|
properties: value,
|
|
185
|
-
override: options$
|
|
185
|
+
override: options$7.override
|
|
186
186
|
});
|
|
187
187
|
else expression = createLiteral(value);
|
|
188
188
|
return expression;
|
|
189
189
|
};
|
|
190
|
-
for (const [prop, value] of Object.entries(options$
|
|
190
|
+
for (const [prop, value] of Object.entries(options$7.properties)) {
|
|
191
191
|
if (value === void 0) continue;
|
|
192
|
-
if (options$
|
|
193
|
-
const existingProperty = options$
|
|
192
|
+
if (options$7.override) {
|
|
193
|
+
const existingProperty = options$7.objectExpression.properties.filter((x$1) => x$1.type === "Property").find((x$1) => x$1.key.name === prop);
|
|
194
194
|
const existingExpression = existingProperty?.value.type === "ObjectExpression" ? existingProperty.value : void 0;
|
|
195
|
-
overrideProperty(options$
|
|
195
|
+
overrideProperty(options$7.objectExpression, {
|
|
196
196
|
name: prop,
|
|
197
197
|
value: getExpression(value, existingExpression)
|
|
198
198
|
});
|
|
199
|
-
} else property(options$
|
|
199
|
+
} else property(options$7.objectExpression, {
|
|
200
200
|
name: prop,
|
|
201
201
|
fallback: getExpression(value)
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
|
-
return options$
|
|
204
|
+
return options$7.objectExpression;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
//#endregion
|
|
208
208
|
//#region ../core/tooling/js/function.ts
|
|
209
|
-
function createCall(options$
|
|
209
|
+
function createCall(options$7) {
|
|
210
210
|
const callExpression = {
|
|
211
211
|
type: "CallExpression",
|
|
212
212
|
callee: {
|
|
213
213
|
type: "Identifier",
|
|
214
|
-
name: options$
|
|
214
|
+
name: options$7.name
|
|
215
215
|
},
|
|
216
216
|
arguments: [],
|
|
217
217
|
optional: false
|
|
218
218
|
};
|
|
219
|
-
for (const arg of options$
|
|
219
|
+
for (const arg of options$7.args) {
|
|
220
220
|
let argNode;
|
|
221
|
-
if (options$
|
|
221
|
+
if (options$7.useIdentifiers) argNode = {
|
|
222
222
|
type: "Identifier",
|
|
223
223
|
name: arg
|
|
224
224
|
};
|
|
@@ -230,20 +230,20 @@ function createCall(options$6) {
|
|
|
230
230
|
}
|
|
231
231
|
return callExpression;
|
|
232
232
|
}
|
|
233
|
-
function getArgument(node, options$
|
|
234
|
-
if (options$
|
|
235
|
-
node.arguments.push(options$
|
|
236
|
-
return options$
|
|
233
|
+
function getArgument(node, options$7) {
|
|
234
|
+
if (options$7.index < node.arguments.length) return node.arguments[options$7.index];
|
|
235
|
+
node.arguments.push(options$7.fallback);
|
|
236
|
+
return options$7.fallback;
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
//#endregion
|
|
240
240
|
//#region ../core/tooling/js/imports.ts
|
|
241
|
-
function addEmpty(node, options$
|
|
241
|
+
function addEmpty(node, options$7) {
|
|
242
242
|
const expectedImportDeclaration = {
|
|
243
243
|
type: "ImportDeclaration",
|
|
244
244
|
source: {
|
|
245
245
|
type: "Literal",
|
|
246
|
-
value: options$
|
|
246
|
+
value: options$7.from
|
|
247
247
|
},
|
|
248
248
|
specifiers: [],
|
|
249
249
|
attributes: [],
|
|
@@ -251,37 +251,37 @@ function addEmpty(node, options$6) {
|
|
|
251
251
|
};
|
|
252
252
|
addImportIfNecessary(node, expectedImportDeclaration);
|
|
253
253
|
}
|
|
254
|
-
function addNamespace(node, options$
|
|
254
|
+
function addNamespace(node, options$7) {
|
|
255
255
|
const expectedImportDeclaration = {
|
|
256
256
|
type: "ImportDeclaration",
|
|
257
257
|
importKind: "value",
|
|
258
258
|
source: {
|
|
259
259
|
type: "Literal",
|
|
260
|
-
value: options$
|
|
260
|
+
value: options$7.from
|
|
261
261
|
},
|
|
262
262
|
specifiers: [{
|
|
263
263
|
type: "ImportNamespaceSpecifier",
|
|
264
264
|
local: {
|
|
265
265
|
type: "Identifier",
|
|
266
|
-
name: options$
|
|
266
|
+
name: options$7.as
|
|
267
267
|
}
|
|
268
268
|
}],
|
|
269
269
|
attributes: []
|
|
270
270
|
};
|
|
271
271
|
addImportIfNecessary(node, expectedImportDeclaration);
|
|
272
272
|
}
|
|
273
|
-
function addDefault(node, options$
|
|
273
|
+
function addDefault(node, options$7) {
|
|
274
274
|
const expectedImportDeclaration = {
|
|
275
275
|
type: "ImportDeclaration",
|
|
276
276
|
source: {
|
|
277
277
|
type: "Literal",
|
|
278
|
-
value: options$
|
|
278
|
+
value: options$7.from
|
|
279
279
|
},
|
|
280
280
|
specifiers: [{
|
|
281
281
|
type: "ImportDefaultSpecifier",
|
|
282
282
|
local: {
|
|
283
283
|
type: "Identifier",
|
|
284
|
-
name: options$
|
|
284
|
+
name: options$7.as
|
|
285
285
|
}
|
|
286
286
|
}],
|
|
287
287
|
attributes: [],
|
|
@@ -289,8 +289,8 @@ function addDefault(node, options$6) {
|
|
|
289
289
|
};
|
|
290
290
|
addImportIfNecessary(node, expectedImportDeclaration);
|
|
291
291
|
}
|
|
292
|
-
function addNamed(node, options$
|
|
293
|
-
const o_imports = Array.isArray(options$
|
|
292
|
+
function addNamed(node, options$7) {
|
|
293
|
+
const o_imports = Array.isArray(options$7.imports) ? Object.fromEntries(options$7.imports.map((n) => [n, n])) : options$7.imports;
|
|
294
294
|
const specifiers = Object.entries(o_imports).map(([key, value]) => {
|
|
295
295
|
return {
|
|
296
296
|
type: "ImportSpecifier",
|
|
@@ -306,7 +306,7 @@ function addNamed(node, options$6) {
|
|
|
306
306
|
});
|
|
307
307
|
let importDecl;
|
|
308
308
|
walk(node, null, { ImportDeclaration(declaration$1) {
|
|
309
|
-
if (declaration$1.source.value === options$
|
|
309
|
+
if (declaration$1.source.value === options$7.from && declaration$1.specifiers) importDecl = declaration$1;
|
|
310
310
|
} });
|
|
311
311
|
if (importDecl) {
|
|
312
312
|
specifiers.forEach((specifierToAdd) => {
|
|
@@ -318,23 +318,23 @@ function addNamed(node, options$6) {
|
|
|
318
318
|
type: "ImportDeclaration",
|
|
319
319
|
source: {
|
|
320
320
|
type: "Literal",
|
|
321
|
-
value: options$
|
|
321
|
+
value: options$7.from
|
|
322
322
|
},
|
|
323
323
|
specifiers,
|
|
324
324
|
attributes: [],
|
|
325
|
-
importKind: options$
|
|
325
|
+
importKind: options$7.isType ? "type" : "value"
|
|
326
326
|
};
|
|
327
327
|
node.body.unshift(expectedImportDeclaration);
|
|
328
328
|
}
|
|
329
329
|
function addImportIfNecessary(node, expectedImportDeclaration) {
|
|
330
330
|
if (!node.body.filter((item) => item.type === "ImportDeclaration").find((item) => areNodesEqual(item, expectedImportDeclaration))) node.body.unshift(expectedImportDeclaration);
|
|
331
331
|
}
|
|
332
|
-
function find(ast, options$
|
|
333
|
-
let alias = options$
|
|
332
|
+
function find(ast, options$7) {
|
|
333
|
+
let alias = options$7.name;
|
|
334
334
|
let statement;
|
|
335
335
|
walk(ast, null, { ImportDeclaration(node) {
|
|
336
|
-
if (node.specifiers && node.source.value === options$
|
|
337
|
-
const specifier = node.specifiers.find((sp) => sp.type === "ImportSpecifier" && sp.imported.type === "Identifier" && sp.imported.name === options$
|
|
336
|
+
if (node.specifiers && node.source.value === options$7.from) {
|
|
337
|
+
const specifier = node.specifiers.find((sp) => sp.type === "ImportSpecifier" && sp.imported.type === "Identifier" && sp.imported.name === options$7.name);
|
|
338
338
|
if (specifier) {
|
|
339
339
|
statement = node;
|
|
340
340
|
alias = specifier.local?.name ?? alias;
|
|
@@ -351,38 +351,38 @@ function find(ast, options$6) {
|
|
|
351
351
|
alias: void 0
|
|
352
352
|
};
|
|
353
353
|
}
|
|
354
|
-
function remove(ast, options$
|
|
355
|
-
const statement = options$
|
|
356
|
-
name: options$
|
|
357
|
-
from: options$
|
|
354
|
+
function remove(ast, options$7) {
|
|
355
|
+
const statement = options$7.statement ?? find(ast, {
|
|
356
|
+
name: options$7.name,
|
|
357
|
+
from: options$7.from
|
|
358
358
|
}).statement;
|
|
359
359
|
if (!statement) return;
|
|
360
360
|
if (statement.specifiers?.length === 1) {
|
|
361
361
|
const idxToRemove = ast.body.indexOf(statement);
|
|
362
362
|
ast.body.splice(idxToRemove, 1);
|
|
363
363
|
} else {
|
|
364
|
-
const idxToRemove = statement.specifiers?.findIndex((s) => s.type === "ImportSpecifier" && s.imported.type === "Identifier" && s.imported.name === options$
|
|
364
|
+
const idxToRemove = statement.specifiers?.findIndex((s) => s.type === "ImportSpecifier" && s.imported.type === "Identifier" && s.imported.name === options$7.name);
|
|
365
365
|
if (idxToRemove !== void 0 && idxToRemove !== -1) statement.specifiers?.splice(idxToRemove, 1);
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
//#endregion
|
|
370
370
|
//#region ../core/tooling/js/variables.ts
|
|
371
|
-
function declaration(node, options$
|
|
371
|
+
function declaration(node, options$7) {
|
|
372
372
|
let declaration$1 = (node.type === "Program" ? node.body.filter((x$1) => x$1.type === "VariableDeclaration") : [node]).find((x$1) => {
|
|
373
|
-
return x$1.declarations[0].id.name === options$
|
|
373
|
+
return x$1.declarations[0].id.name === options$7.name;
|
|
374
374
|
});
|
|
375
375
|
if (declaration$1) return declaration$1;
|
|
376
376
|
declaration$1 = {
|
|
377
377
|
type: "VariableDeclaration",
|
|
378
|
-
kind: options$
|
|
378
|
+
kind: options$7.kind,
|
|
379
379
|
declarations: [{
|
|
380
380
|
type: "VariableDeclarator",
|
|
381
381
|
id: {
|
|
382
382
|
type: "Identifier",
|
|
383
|
-
name: options$
|
|
383
|
+
name: options$7.name
|
|
384
384
|
},
|
|
385
|
-
init: options$
|
|
385
|
+
init: options$7.value
|
|
386
386
|
}]
|
|
387
387
|
};
|
|
388
388
|
return declaration$1;
|
|
@@ -393,14 +393,14 @@ function createIdentifier(name) {
|
|
|
393
393
|
name
|
|
394
394
|
};
|
|
395
395
|
}
|
|
396
|
-
function typeAnnotateDeclarator(node, options$
|
|
396
|
+
function typeAnnotateDeclarator(node, options$7) {
|
|
397
397
|
if (node.id.type === "Identifier") node.id.typeAnnotation = {
|
|
398
398
|
type: "TSTypeAnnotation",
|
|
399
399
|
typeAnnotation: {
|
|
400
400
|
type: "TSTypeReference",
|
|
401
401
|
typeName: {
|
|
402
402
|
type: "Identifier",
|
|
403
|
-
name: options$
|
|
403
|
+
name: options$7.typeName
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
};
|
|
@@ -409,17 +409,17 @@ function typeAnnotateDeclarator(node, options$6) {
|
|
|
409
409
|
|
|
410
410
|
//#endregion
|
|
411
411
|
//#region ../core/tooling/js/exports.ts
|
|
412
|
-
function createDefault(node, options$
|
|
412
|
+
function createDefault(node, options$7) {
|
|
413
413
|
const existingNode = node.body.find((item) => item.type === "ExportDefaultDeclaration");
|
|
414
414
|
if (!existingNode) {
|
|
415
415
|
const exportNode = {
|
|
416
416
|
type: "ExportDefaultDeclaration",
|
|
417
|
-
declaration: options$
|
|
417
|
+
declaration: options$7.fallback
|
|
418
418
|
};
|
|
419
419
|
node.body.push(exportNode);
|
|
420
420
|
return {
|
|
421
421
|
astNode: exportNode,
|
|
422
|
-
value: options$
|
|
422
|
+
value: options$7.fallback,
|
|
423
423
|
isFallback: true
|
|
424
424
|
};
|
|
425
425
|
}
|
|
@@ -448,14 +448,14 @@ function createDefault(node, options$6) {
|
|
|
448
448
|
isFallback: false
|
|
449
449
|
};
|
|
450
450
|
}
|
|
451
|
-
function createNamed(node, options$
|
|
451
|
+
function createNamed(node, options$7) {
|
|
452
452
|
let namedExport = node.body.filter((item) => item.type === "ExportNamedDeclaration").find((exportNode) => {
|
|
453
|
-
return exportNode.declaration.declarations[0].id.name === options$
|
|
453
|
+
return exportNode.declaration.declarations[0].id.name === options$7.name;
|
|
454
454
|
});
|
|
455
455
|
if (namedExport) return namedExport;
|
|
456
456
|
namedExport = {
|
|
457
457
|
type: "ExportNamedDeclaration",
|
|
458
|
-
declaration: options$
|
|
458
|
+
declaration: options$7.fallback,
|
|
459
459
|
specifiers: [],
|
|
460
460
|
attributes: []
|
|
461
461
|
};
|
|
@@ -465,7 +465,7 @@ function createNamed(node, options$6) {
|
|
|
465
465
|
|
|
466
466
|
//#endregion
|
|
467
467
|
//#region ../core/tooling/js/kit.ts
|
|
468
|
-
function addGlobalAppInterface(node, options$
|
|
468
|
+
function addGlobalAppInterface(node, options$7) {
|
|
469
469
|
let globalDecl = node.body.filter((n) => n.type === "TSModuleDeclaration").find((m) => m.global && m.declare);
|
|
470
470
|
if (!globalDecl) {
|
|
471
471
|
globalDecl = parseFromString("declare global {}");
|
|
@@ -480,7 +480,7 @@ function addGlobalAppInterface(node, options$6) {
|
|
|
480
480
|
next();
|
|
481
481
|
},
|
|
482
482
|
TSInterfaceDeclaration(node$1) {
|
|
483
|
-
if (node$1.id.type === "Identifier" && node$1.id.name === options$
|
|
483
|
+
if (node$1.id.type === "Identifier" && node$1.id.name === options$7.name) interfaceNode = node$1;
|
|
484
484
|
}
|
|
485
485
|
});
|
|
486
486
|
if (!app) {
|
|
@@ -489,13 +489,13 @@ function addGlobalAppInterface(node, options$6) {
|
|
|
489
489
|
}
|
|
490
490
|
if (app.body?.type !== "TSModuleBlock") throw new Error("Unexpected body type of `namespace App` in `src/app.d.ts`");
|
|
491
491
|
if (!interfaceNode) {
|
|
492
|
-
interfaceNode = parseFromString(`interface ${options$
|
|
492
|
+
interfaceNode = parseFromString(`interface ${options$7.name} {}`);
|
|
493
493
|
app.body.body.push(interfaceNode);
|
|
494
494
|
}
|
|
495
495
|
return interfaceNode;
|
|
496
496
|
}
|
|
497
|
-
function addHooksHandle(node, options$
|
|
498
|
-
if (options$
|
|
497
|
+
function addHooksHandle(node, options$7) {
|
|
498
|
+
if (options$7.typescript) addNamed(node, {
|
|
499
499
|
from: "@sveltejs/kit",
|
|
500
500
|
imports: { Handle: "Handle" },
|
|
501
501
|
isType: true
|
|
@@ -524,15 +524,15 @@ function addHooksHandle(node, options$6) {
|
|
|
524
524
|
originalHandleDecl = maybeHandleDecl;
|
|
525
525
|
}
|
|
526
526
|
} });
|
|
527
|
-
const newHandle = parseExpression(options$
|
|
527
|
+
const newHandle = parseExpression(options$7.handleContent);
|
|
528
528
|
if (contains(node, newHandle)) return;
|
|
529
529
|
if (!originalHandleDecl || !exportDecl) {
|
|
530
530
|
const newHandleDecl$1 = declaration(node, {
|
|
531
531
|
kind: "const",
|
|
532
|
-
name: options$
|
|
532
|
+
name: options$7.newHandleName,
|
|
533
533
|
value: newHandle
|
|
534
534
|
});
|
|
535
|
-
if (options$
|
|
535
|
+
if (options$7.typescript) {
|
|
536
536
|
const declarator = newHandleDecl$1.declarations[0];
|
|
537
537
|
typeAnnotateDeclarator(declarator, { typeName: "Handle" });
|
|
538
538
|
}
|
|
@@ -540,9 +540,9 @@ function addHooksHandle(node, options$6) {
|
|
|
540
540
|
const handleDecl = declaration(node, {
|
|
541
541
|
kind: "const",
|
|
542
542
|
name: handleName,
|
|
543
|
-
value: createIdentifier(options$
|
|
543
|
+
value: createIdentifier(options$7.newHandleName)
|
|
544
544
|
});
|
|
545
|
-
if (options$
|
|
545
|
+
if (options$7.typescript) {
|
|
546
546
|
const declarator = handleDecl.declarations[0];
|
|
547
547
|
typeAnnotateDeclarator(declarator, { typeName: "Handle" });
|
|
548
548
|
}
|
|
@@ -554,17 +554,17 @@ function addHooksHandle(node, options$6) {
|
|
|
554
554
|
}
|
|
555
555
|
const newHandleDecl = declaration(node, {
|
|
556
556
|
kind: "const",
|
|
557
|
-
name: options$
|
|
557
|
+
name: options$7.newHandleName,
|
|
558
558
|
value: newHandle
|
|
559
559
|
});
|
|
560
|
-
if (options$
|
|
560
|
+
if (options$7.typescript) {
|
|
561
561
|
const declarator = newHandleDecl.declarations[0];
|
|
562
562
|
typeAnnotateDeclarator(declarator, { typeName: "Handle" });
|
|
563
563
|
}
|
|
564
564
|
let sequence;
|
|
565
565
|
if (originalHandleDecl.type === "VariableDeclaration") sequence = originalHandleDecl.declarations.find((declarator) => declarator.type === "VariableDeclarator" && usingSequence(declarator, handleName))?.init;
|
|
566
566
|
if (sequence) {
|
|
567
|
-
if (!sequence.arguments.some((arg) => arg.type === "Identifier" && arg.name === options$
|
|
567
|
+
if (!sequence.arguments.some((arg) => arg.type === "Identifier" && arg.name === options$7.newHandleName)) sequence.arguments.push(createIdentifier(options$7.newHandleName));
|
|
568
568
|
node.body = node.body.filter((item) => item !== originalHandleDecl && item !== exportDecl && item !== newHandleDecl);
|
|
569
569
|
if (isSpecifier) node.body.push(newHandleDecl, originalHandleDecl, exportDecl);
|
|
570
570
|
else node.body.push(newHandleDecl, exportDecl);
|
|
@@ -572,7 +572,7 @@ function addHooksHandle(node, options$6) {
|
|
|
572
572
|
const NEW_HANDLE_NAME = "originalHandle";
|
|
573
573
|
const sequenceCall = createCall({
|
|
574
574
|
name: "sequence",
|
|
575
|
-
args: [NEW_HANDLE_NAME, options$
|
|
575
|
+
args: [NEW_HANDLE_NAME, options$7.newHandleName],
|
|
576
576
|
useIdentifiers: true
|
|
577
577
|
});
|
|
578
578
|
const finalHandleDecl = declaration(node, {
|
|
@@ -608,7 +608,7 @@ function addHooksHandle(node, options$6) {
|
|
|
608
608
|
const variableDeclarator = getVariableDeclarator(originalHandleDecl, handleName);
|
|
609
609
|
const sequenceCall$1 = createCall({
|
|
610
610
|
name: "sequence",
|
|
611
|
-
args: [(variableDeclarator?.init).name, options$
|
|
611
|
+
args: [(variableDeclarator?.init).name, options$7.newHandleName],
|
|
612
612
|
useIdentifiers: true
|
|
613
613
|
});
|
|
614
614
|
const finalHandleDecl$1 = declaration(node, {
|
|
@@ -616,7 +616,7 @@ function addHooksHandle(node, options$6) {
|
|
|
616
616
|
name: handleName,
|
|
617
617
|
value: sequenceCall$1
|
|
618
618
|
});
|
|
619
|
-
if (options$
|
|
619
|
+
if (options$7.typescript) {
|
|
620
620
|
const declarator = finalHandleDecl$1.declarations[0];
|
|
621
621
|
typeAnnotateDeclarator(declarator, { typeName: "Handle" });
|
|
622
622
|
}
|
|
@@ -649,13 +649,13 @@ function isConfigWrapper(callExpression, knownWrappers) {
|
|
|
649
649
|
const isObjectCall = callExpression.arguments.length === 1 && callExpression.arguments[0]?.type === "ObjectExpression";
|
|
650
650
|
return knownWrappers.includes(calleeName) || isObjectCall;
|
|
651
651
|
}
|
|
652
|
-
function exportDefaultConfig(ast, options$
|
|
653
|
-
const { fallback, ignoreWrapper } = options$
|
|
652
|
+
function exportDefaultConfig(ast, options$7) {
|
|
653
|
+
const { fallback, ignoreWrapper } = options$7;
|
|
654
654
|
let fallbackExpression;
|
|
655
655
|
if (fallback) fallbackExpression = typeof fallback.code === "string" ? parseExpression(fallback.code) : fallback.code;
|
|
656
656
|
else fallbackExpression = create({});
|
|
657
657
|
const { value, isFallback } = createDefault(ast, { fallback: fallbackExpression });
|
|
658
|
-
if (isFallback) options$
|
|
658
|
+
if (isFallback) options$7.fallback?.additional?.(ast);
|
|
659
659
|
const rootObject = value.type === "TSSatisfiesExpression" ? value.expression : value;
|
|
660
660
|
let configObject;
|
|
661
661
|
if (!("arguments" in rootObject) || !Array.isArray(rootObject.arguments)) {
|
|
@@ -697,8 +697,8 @@ function exportDefaultConfig(ast, options$6) {
|
|
|
697
697
|
else configObject = create({});
|
|
698
698
|
return configObject;
|
|
699
699
|
}
|
|
700
|
-
function addInArrayOfObject(ast, options$
|
|
701
|
-
const { code, arrayProperty, mode = "append" } = options$
|
|
700
|
+
function addInArrayOfObject(ast, options$7) {
|
|
701
|
+
const { code, arrayProperty, mode = "append" } = options$7;
|
|
702
702
|
const targetArray = property(ast, {
|
|
703
703
|
name: arrayProperty,
|
|
704
704
|
fallback: create$1()
|
|
@@ -707,11 +707,11 @@ function addInArrayOfObject(ast, options$6) {
|
|
|
707
707
|
if (mode === "prepend") prepend(targetArray, expression);
|
|
708
708
|
else append(targetArray, expression);
|
|
709
709
|
}
|
|
710
|
-
const addPlugin = (ast, options$
|
|
710
|
+
const addPlugin = (ast, options$7) => {
|
|
711
711
|
const configObject = getConfig(ast);
|
|
712
712
|
addInArrayOfObject(configObject, {
|
|
713
713
|
arrayProperty: "plugins",
|
|
714
|
-
...options$
|
|
714
|
+
...options$7
|
|
715
715
|
});
|
|
716
716
|
};
|
|
717
717
|
const getConfig = (ast) => {
|
|
@@ -810,7 +810,7 @@ const PORTS = {
|
|
|
810
810
|
postgresql: "5432",
|
|
811
811
|
sqlite: ""
|
|
812
812
|
};
|
|
813
|
-
const options$
|
|
813
|
+
const options$6 = defineAddonOptions().add("database", {
|
|
814
814
|
question: "Which database would you like to use?",
|
|
815
815
|
type: "select",
|
|
816
816
|
default: "sqlite",
|
|
@@ -889,45 +889,58 @@ var drizzle_default = defineAddon({
|
|
|
889
889
|
id: "drizzle",
|
|
890
890
|
shortDescription: "database orm",
|
|
891
891
|
homepage: "https://orm.drizzle.team",
|
|
892
|
-
options: options$
|
|
893
|
-
setup: ({ kit, unsupported, runsAfter
|
|
892
|
+
options: options$6,
|
|
893
|
+
setup: ({ kit, unsupported, runsAfter }) => {
|
|
894
894
|
runsAfter("prettier");
|
|
895
|
-
const ext = typescript ? "ts" : "js";
|
|
896
895
|
if (!kit) return unsupported("Requires SvelteKit");
|
|
897
|
-
const baseDBPath = path.resolve(kit.libDirectory, "server", "db");
|
|
898
|
-
const paths = {
|
|
899
|
-
"drizzle config": path.relative(cwd, path.resolve(cwd, `drizzle.config.${ext}`)),
|
|
900
|
-
"database schema": path.relative(cwd, path.resolve(baseDBPath, `schema.${ext}`)),
|
|
901
|
-
database: path.relative(cwd, path.resolve(baseDBPath, `index.${ext}`))
|
|
902
|
-
};
|
|
903
|
-
for (const [fileType, filePath] of Object.entries(paths)) if (fs.existsSync(filePath)) unsupported(`Preexisting ${fileType} file at '${filePath}'`);
|
|
904
896
|
},
|
|
905
|
-
run: ({ sv, typescript, options: options$
|
|
897
|
+
run: ({ sv, typescript, options: options$7, kit, dependencyVersion, cwd, cancel }) => {
|
|
898
|
+
if (!kit) throw new Error("SvelteKit is required");
|
|
906
899
|
const ext = typescript ? "ts" : "js";
|
|
900
|
+
const baseDBPath = path.resolve(cwd, kit.libDirectory, "server", "db");
|
|
901
|
+
const paths = {
|
|
902
|
+
"drizzle config": path.resolve(cwd, `drizzle.config.${ext}`),
|
|
903
|
+
"database schema": path.resolve(baseDBPath, `schema.${ext}`),
|
|
904
|
+
database: path.resolve(baseDBPath, `index.${ext}`)
|
|
905
|
+
};
|
|
906
|
+
for (const [fileType, filePath] of Object.entries(paths)) if (fs.existsSync(filePath)) return cancel(`Preexisting ${fileType} file at '${filePath}'`);
|
|
907
|
+
console.log(`no preexisting files`);
|
|
907
908
|
sv.devDependency("drizzle-orm", "^0.44.5");
|
|
908
909
|
sv.devDependency("drizzle-kit", "^0.31.4");
|
|
909
910
|
sv.devDependency("@types/node", getNodeTypesVersion());
|
|
910
|
-
if (options$
|
|
911
|
-
if (options$
|
|
912
|
-
if (options$
|
|
913
|
-
if (options$
|
|
914
|
-
if (options$
|
|
911
|
+
if (options$7.mysql === "mysql2") sv.dependency("mysql2", "^3.15.0");
|
|
912
|
+
if (options$7.mysql === "planetscale") sv.dependency("@planetscale/database", "^1.19.0");
|
|
913
|
+
if (options$7.postgresql === "neon") sv.dependency("@neondatabase/serverless", "^1.0.1");
|
|
914
|
+
if (options$7.postgresql === "postgres.js") sv.dependency("postgres", "^3.4.7");
|
|
915
|
+
if (options$7.sqlite === "better-sqlite3") {
|
|
915
916
|
sv.dependency("better-sqlite3", "^12.4.1");
|
|
916
917
|
sv.devDependency("@types/better-sqlite3", "^7.6.13");
|
|
917
918
|
sv.pnpmBuildDependency("better-sqlite3");
|
|
918
919
|
}
|
|
919
|
-
if (options$
|
|
920
|
-
sv.file(".env", (content) => generateEnvFileContent(content, options$
|
|
921
|
-
sv.file(".env.example", (content) => generateEnvFileContent(content, options$
|
|
922
|
-
if (options$
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
920
|
+
if (options$7.sqlite === "libsql" || options$7.sqlite === "turso") sv.devDependency("@libsql/client", "^0.15.15");
|
|
921
|
+
sv.file(".env", (content) => generateEnvFileContent(content, options$7));
|
|
922
|
+
sv.file(".env.example", (content) => generateEnvFileContent(content, options$7));
|
|
923
|
+
if (options$7.docker && (options$7.mysql === "mysql2" || options$7.postgresql === "postgres.js")) {
|
|
924
|
+
const composeFileOptions = [
|
|
925
|
+
"docker-compose.yml",
|
|
926
|
+
"docker-compose.yaml",
|
|
927
|
+
"compose.yaml"
|
|
928
|
+
];
|
|
929
|
+
let composeFile = "";
|
|
930
|
+
for (const option of composeFileOptions) {
|
|
931
|
+
composeFile = option;
|
|
932
|
+
if (fs.existsSync(path.resolve(cwd, option))) break;
|
|
933
|
+
}
|
|
934
|
+
if (composeFile === "") throw new Error("unreachable state...");
|
|
935
|
+
sv.file(composeFile, (content) => {
|
|
936
|
+
if (content.length > 0) return content;
|
|
937
|
+
const imageName = options$7.database === "mysql" ? "mysql" : "postgres";
|
|
938
|
+
const port = PORTS[options$7.database];
|
|
939
|
+
const USER = "root";
|
|
940
|
+
const PASSWORD = "mysecretpassword";
|
|
941
|
+
const DB_NAME = "local";
|
|
942
|
+
let dbSpecificContent = "";
|
|
943
|
+
if (options$7.mysql === "mysql2") dbSpecificContent = `
|
|
931
944
|
MYSQL_ROOT_PASSWORD: ${PASSWORD}
|
|
932
945
|
MYSQL_DATABASE: ${DB_NAME}
|
|
933
946
|
volumes:
|
|
@@ -935,7 +948,7 @@ var drizzle_default = defineAddon({
|
|
|
935
948
|
volumes:
|
|
936
949
|
mysqldata:
|
|
937
950
|
`;
|
|
938
|
-
|
|
951
|
+
if (options$7.postgresql === "postgres.js") dbSpecificContent = `
|
|
939
952
|
POSTGRES_USER: ${USER}
|
|
940
953
|
POSTGRES_PASSWORD: ${PASSWORD}
|
|
941
954
|
POSTGRES_DB: ${DB_NAME}
|
|
@@ -944,7 +957,7 @@ var drizzle_default = defineAddon({
|
|
|
944
957
|
volumes:
|
|
945
958
|
pgdata:
|
|
946
959
|
`;
|
|
947
|
-
|
|
960
|
+
content = dedent_default`
|
|
948
961
|
services:
|
|
949
962
|
db:
|
|
950
963
|
image: ${imageName}
|
|
@@ -953,13 +966,14 @@ var drizzle_default = defineAddon({
|
|
|
953
966
|
- ${port}:${port}
|
|
954
967
|
environment: ${dbSpecificContent}
|
|
955
968
|
`;
|
|
956
|
-
|
|
957
|
-
|
|
969
|
+
return content;
|
|
970
|
+
});
|
|
971
|
+
}
|
|
958
972
|
sv.file("package.json", (content) => {
|
|
959
973
|
const { data, generateCode } = parseJson(content);
|
|
960
974
|
data.scripts ??= {};
|
|
961
975
|
const scripts = data.scripts;
|
|
962
|
-
if (options$
|
|
976
|
+
if (options$7.docker) scripts["db:start"] ??= "docker compose up";
|
|
963
977
|
scripts["db:push"] ??= "drizzle-kit push";
|
|
964
978
|
scripts["db:generate"] ??= "drizzle-kit generate";
|
|
965
979
|
scripts["db:migrate"] ??= "drizzle-kit migrate";
|
|
@@ -970,12 +984,12 @@ var drizzle_default = defineAddon({
|
|
|
970
984
|
if (!content.includes(`/drizzle/`)) return content.trimEnd() + "\n/drizzle/";
|
|
971
985
|
return content;
|
|
972
986
|
});
|
|
973
|
-
if (options$
|
|
987
|
+
if (options$7.database === "sqlite") sv.file(".gitignore", (content) => {
|
|
974
988
|
if (content.length === 0) return content;
|
|
975
989
|
if (!content.includes("\n*.db")) content = content.trimEnd() + "\n\n# SQLite\n*.db";
|
|
976
990
|
return content;
|
|
977
991
|
});
|
|
978
|
-
sv.file(
|
|
992
|
+
sv.file(paths["drizzle config"], (content) => {
|
|
979
993
|
const { ast, generateCode } = parseScript(content);
|
|
980
994
|
addNamed(ast, {
|
|
981
995
|
from: "drizzle-kit",
|
|
@@ -985,9 +999,9 @@ var drizzle_default = defineAddon({
|
|
|
985
999
|
createDefault(ast, { fallback: parseExpression(`
|
|
986
1000
|
defineConfig({
|
|
987
1001
|
schema: "./src/lib/server/db/schema.${typescript ? "ts" : "js"}",
|
|
988
|
-
dialect: "${options$
|
|
1002
|
+
dialect: "${options$7.sqlite === "turso" ? "turso" : options$7.database}",
|
|
989
1003
|
dbCredentials: {
|
|
990
|
-
${options$
|
|
1004
|
+
${options$7.sqlite === "turso" ? "authToken: process.env.DATABASE_AUTH_TOKEN," : ""}
|
|
991
1005
|
url: process.env.DATABASE_URL
|
|
992
1006
|
},
|
|
993
1007
|
verbose: true,
|
|
@@ -995,10 +1009,10 @@ var drizzle_default = defineAddon({
|
|
|
995
1009
|
})`) });
|
|
996
1010
|
return generateCode();
|
|
997
1011
|
});
|
|
998
|
-
sv.file(
|
|
1012
|
+
sv.file(paths["database schema"], (content) => {
|
|
999
1013
|
const { ast, generateCode } = parseScript(content);
|
|
1000
1014
|
let userSchemaExpression;
|
|
1001
|
-
if (options$
|
|
1015
|
+
if (options$7.database === "sqlite") {
|
|
1002
1016
|
addNamed(ast, {
|
|
1003
1017
|
from: "drizzle-orm/sqlite-core",
|
|
1004
1018
|
imports: [
|
|
@@ -1012,7 +1026,7 @@ var drizzle_default = defineAddon({
|
|
|
1012
1026
|
age: integer('age')
|
|
1013
1027
|
})`);
|
|
1014
1028
|
}
|
|
1015
|
-
if (options$
|
|
1029
|
+
if (options$7.database === "mysql") {
|
|
1016
1030
|
addNamed(ast, {
|
|
1017
1031
|
from: "drizzle-orm/mysql-core",
|
|
1018
1032
|
imports: [
|
|
@@ -1026,7 +1040,7 @@ var drizzle_default = defineAddon({
|
|
|
1026
1040
|
age: int('age'),
|
|
1027
1041
|
})`);
|
|
1028
1042
|
}
|
|
1029
|
-
if (options$
|
|
1043
|
+
if (options$7.database === "postgresql") {
|
|
1030
1044
|
addNamed(ast, {
|
|
1031
1045
|
from: "drizzle-orm/pg-core",
|
|
1032
1046
|
imports: [
|
|
@@ -1052,7 +1066,7 @@ var drizzle_default = defineAddon({
|
|
|
1052
1066
|
});
|
|
1053
1067
|
return generateCode();
|
|
1054
1068
|
});
|
|
1055
|
-
sv.file(
|
|
1069
|
+
sv.file(paths["database"], (content) => {
|
|
1056
1070
|
const { ast, generateCode } = parseScript(content);
|
|
1057
1071
|
addNamed(ast, {
|
|
1058
1072
|
from: "$env/dynamic/private",
|
|
@@ -1065,7 +1079,7 @@ var drizzle_default = defineAddon({
|
|
|
1065
1079
|
const dbURLCheck = parseStatement("if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');");
|
|
1066
1080
|
ast.body.push(dbURLCheck);
|
|
1067
1081
|
let clientExpression;
|
|
1068
|
-
if (options$
|
|
1082
|
+
if (options$7.sqlite === "better-sqlite3") {
|
|
1069
1083
|
addDefault(ast, {
|
|
1070
1084
|
from: "better-sqlite3",
|
|
1071
1085
|
as: "Database"
|
|
@@ -1076,7 +1090,7 @@ var drizzle_default = defineAddon({
|
|
|
1076
1090
|
});
|
|
1077
1091
|
clientExpression = parseExpression("new Database(env.DATABASE_URL)");
|
|
1078
1092
|
}
|
|
1079
|
-
if (options$
|
|
1093
|
+
if (options$7.sqlite === "libsql" || options$7.sqlite === "turso") {
|
|
1080
1094
|
addNamed(ast, {
|
|
1081
1095
|
from: "@libsql/client",
|
|
1082
1096
|
imports: ["createClient"]
|
|
@@ -1085,7 +1099,7 @@ var drizzle_default = defineAddon({
|
|
|
1085
1099
|
from: "drizzle-orm/libsql",
|
|
1086
1100
|
imports: ["drizzle"]
|
|
1087
1101
|
});
|
|
1088
|
-
if (options$
|
|
1102
|
+
if (options$7.sqlite === "turso") {
|
|
1089
1103
|
addNamed(ast, {
|
|
1090
1104
|
from: "$app/environment",
|
|
1091
1105
|
imports: ["dev"]
|
|
@@ -1095,7 +1109,7 @@ var drizzle_default = defineAddon({
|
|
|
1095
1109
|
clientExpression = parseExpression("createClient({ url: env.DATABASE_URL, authToken: env.DATABASE_AUTH_TOKEN })");
|
|
1096
1110
|
} else clientExpression = parseExpression("createClient({ url: env.DATABASE_URL })");
|
|
1097
1111
|
}
|
|
1098
|
-
if (options$
|
|
1112
|
+
if (options$7.mysql === "mysql2" || options$7.mysql === "planetscale") {
|
|
1099
1113
|
addDefault(ast, {
|
|
1100
1114
|
from: "mysql2/promise",
|
|
1101
1115
|
as: "mysql"
|
|
@@ -1106,7 +1120,7 @@ var drizzle_default = defineAddon({
|
|
|
1106
1120
|
});
|
|
1107
1121
|
clientExpression = parseExpression("mysql.createPool(env.DATABASE_URL)");
|
|
1108
1122
|
}
|
|
1109
|
-
if (options$
|
|
1123
|
+
if (options$7.postgresql === "neon") {
|
|
1110
1124
|
addNamed(ast, {
|
|
1111
1125
|
from: "@neondatabase/serverless",
|
|
1112
1126
|
imports: ["neon"]
|
|
@@ -1117,7 +1131,7 @@ var drizzle_default = defineAddon({
|
|
|
1117
1131
|
});
|
|
1118
1132
|
clientExpression = parseExpression("neon(env.DATABASE_URL)");
|
|
1119
1133
|
}
|
|
1120
|
-
if (options$
|
|
1134
|
+
if (options$7.postgresql === "postgres.js") {
|
|
1121
1135
|
addDefault(ast, {
|
|
1122
1136
|
from: "postgres",
|
|
1123
1137
|
as: "postgres"
|
|
@@ -1140,8 +1154,8 @@ var drizzle_default = defineAddon({
|
|
|
1140
1154
|
useIdentifiers: true
|
|
1141
1155
|
});
|
|
1142
1156
|
const paramObject = create({ schema: createIdentifier("schema") });
|
|
1143
|
-
if (options$
|
|
1144
|
-
const mode = options$
|
|
1157
|
+
if (options$7.database === "mysql") {
|
|
1158
|
+
const mode = options$7.mysql === "planetscale" ? "planetscale" : "default";
|
|
1145
1159
|
property(paramObject, {
|
|
1146
1160
|
name: "mode",
|
|
1147
1161
|
fallback: createLiteral(mode)
|
|
@@ -1160,9 +1174,9 @@ var drizzle_default = defineAddon({
|
|
|
1160
1174
|
return generateCode();
|
|
1161
1175
|
});
|
|
1162
1176
|
},
|
|
1163
|
-
nextSteps: ({ options: options$
|
|
1177
|
+
nextSteps: ({ options: options$7, highlighter, packageManager }) => {
|
|
1164
1178
|
const steps = [`You will need to set ${highlighter.env("DATABASE_URL")} in your production environment`];
|
|
1165
|
-
if (options$
|
|
1179
|
+
if (options$7.docker) {
|
|
1166
1180
|
const { command: command$1, args: args$1 } = resolveCommand(packageManager, "run", ["db:start"]);
|
|
1167
1181
|
steps.push(`Run ${highlighter.command(`${command$1} ${args$1.join(" ")}`)} to start the docker container`);
|
|
1168
1182
|
} else steps.push(`Check ${highlighter.env("DATABASE_URL")} in ${highlighter.path(".env")} and adjust it to your needs`);
|
|
@@ -1363,7 +1377,7 @@ const TABLE_TYPE = {
|
|
|
1363
1377
|
};
|
|
1364
1378
|
let drizzleDialect;
|
|
1365
1379
|
let schemaPath;
|
|
1366
|
-
const options$
|
|
1380
|
+
const options$5 = defineAddonOptions().add("demo", {
|
|
1367
1381
|
type: "boolean",
|
|
1368
1382
|
default: true,
|
|
1369
1383
|
question: `Do you want to include a demo? ${import_picocolors$2.default.dim("(includes a login/register page)")}`
|
|
@@ -1372,17 +1386,17 @@ var lucia_default = defineAddon({
|
|
|
1372
1386
|
id: "lucia",
|
|
1373
1387
|
shortDescription: "auth guide",
|
|
1374
1388
|
homepage: "https://lucia-auth.com",
|
|
1375
|
-
options: options$
|
|
1389
|
+
options: options$5,
|
|
1376
1390
|
setup: ({ kit, dependencyVersion, unsupported, dependsOn, runsAfter }) => {
|
|
1377
1391
|
if (!kit) unsupported("Requires SvelteKit");
|
|
1378
1392
|
if (!dependencyVersion("drizzle-orm")) dependsOn("drizzle");
|
|
1379
1393
|
runsAfter("tailwindcss");
|
|
1380
1394
|
},
|
|
1381
|
-
run: ({ sv, typescript, options: options$
|
|
1395
|
+
run: ({ sv, typescript, options: options$7, kit, dependencyVersion }) => {
|
|
1382
1396
|
const ext = typescript ? "ts" : "js";
|
|
1383
1397
|
sv.devDependency("@oslojs/crypto", "^1.0.1");
|
|
1384
1398
|
sv.devDependency("@oslojs/encoding", "^1.1.0");
|
|
1385
|
-
if (options$
|
|
1399
|
+
if (options$7.demo) sv.dependency("@node-rs/argon2", "^2.0.2");
|
|
1386
1400
|
sv.file(`drizzle.config.${ext}`, (content) => {
|
|
1387
1401
|
const { ast, generateCode } = parseScript(content);
|
|
1388
1402
|
const isProp = (name, node) => node.key.type === "Identifier" && node.key.name === name;
|
|
@@ -1436,7 +1450,7 @@ var lucia_default = defineAddon({
|
|
|
1436
1450
|
]
|
|
1437
1451
|
});
|
|
1438
1452
|
overrideProperties(userAttributes, { id: parseExpression("text('id').primaryKey()") });
|
|
1439
|
-
if (options$
|
|
1453
|
+
if (options$7.demo) overrideProperties(userAttributes, {
|
|
1440
1454
|
username: parseExpression("text('username').notNull().unique()"),
|
|
1441
1455
|
passwordHash: parseExpression("text('password_hash').notNull()")
|
|
1442
1456
|
});
|
|
@@ -1456,7 +1470,7 @@ var lucia_default = defineAddon({
|
|
|
1456
1470
|
]
|
|
1457
1471
|
});
|
|
1458
1472
|
overrideProperties(userAttributes, { id: parseExpression("varchar('id', { length: 255 }).primaryKey()") });
|
|
1459
|
-
if (options$
|
|
1473
|
+
if (options$7.demo) overrideProperties(userAttributes, {
|
|
1460
1474
|
username: parseExpression("varchar('username', { length: 32 }).notNull().unique()"),
|
|
1461
1475
|
passwordHash: parseExpression("varchar('password_hash', { length: 255 }).notNull()")
|
|
1462
1476
|
});
|
|
@@ -1476,7 +1490,7 @@ var lucia_default = defineAddon({
|
|
|
1476
1490
|
]
|
|
1477
1491
|
});
|
|
1478
1492
|
overrideProperties(userAttributes, { id: parseExpression("text('id').primaryKey()") });
|
|
1479
|
-
if (options$
|
|
1493
|
+
if (options$7.demo) overrideProperties(userAttributes, {
|
|
1480
1494
|
username: parseExpression("text('username').notNull().unique()"),
|
|
1481
1495
|
passwordHash: parseExpression("text('password_hash').notNull()")
|
|
1482
1496
|
});
|
|
@@ -1649,7 +1663,7 @@ var lucia_default = defineAddon({
|
|
|
1649
1663
|
});
|
|
1650
1664
|
return generateCode();
|
|
1651
1665
|
});
|
|
1652
|
-
if (options$
|
|
1666
|
+
if (options$7.demo) {
|
|
1653
1667
|
sv.file(`${kit?.routesDirectory}/demo/+page.svelte`, (content) => {
|
|
1654
1668
|
return addToDemoPage(content, "lucia");
|
|
1655
1669
|
});
|
|
@@ -1883,10 +1897,10 @@ var lucia_default = defineAddon({
|
|
|
1883
1897
|
});
|
|
1884
1898
|
}
|
|
1885
1899
|
},
|
|
1886
|
-
nextSteps: ({ highlighter, options: options$
|
|
1900
|
+
nextSteps: ({ highlighter, options: options$7, packageManager }) => {
|
|
1887
1901
|
const { command, args } = resolveCommand(packageManager, "run", ["db:push"]);
|
|
1888
1902
|
const steps = [`Run ${highlighter.command(`${command} ${args.join(" ")}`)} to update your database schema`];
|
|
1889
|
-
if (options$
|
|
1903
|
+
if (options$7.demo) steps.push(`Visit ${highlighter.route("/demo/lucia")} route to view the demo`);
|
|
1890
1904
|
return steps;
|
|
1891
1905
|
}
|
|
1892
1906
|
});
|
|
@@ -2011,14 +2025,14 @@ function addFromRawHtml(childNodes, html) {
|
|
|
2011
2025
|
const document = parseHtml$1(html);
|
|
2012
2026
|
for (const childNode of document.childNodes) childNodes.push(childNode);
|
|
2013
2027
|
}
|
|
2014
|
-
function addSlot(jsAst, options$
|
|
2015
|
-
if (options$
|
|
2028
|
+
function addSlot(jsAst, options$7) {
|
|
2029
|
+
if (options$7.svelteVersion && (options$7.svelteVersion.startsWith("4") || options$7.svelteVersion.startsWith("3"))) {
|
|
2016
2030
|
const slot = createElement("slot");
|
|
2017
|
-
appendElement(options$
|
|
2031
|
+
appendElement(options$7.htmlAst.childNodes, slot);
|
|
2018
2032
|
return;
|
|
2019
2033
|
}
|
|
2020
2034
|
appendFromString(jsAst, { code: "let { children } = $props();" });
|
|
2021
|
-
addFromRawHtml(options$
|
|
2035
|
+
addFromRawHtml(options$7.htmlAst.childNodes, "{@render children()}");
|
|
2022
2036
|
}
|
|
2023
2037
|
|
|
2024
2038
|
//#endregion
|
|
@@ -2028,7 +2042,7 @@ const DEFAULT_INLANG_PROJECT = {
|
|
|
2028
2042
|
modules: ["https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4/dist/index.js", "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2/dist/index.js"],
|
|
2029
2043
|
"plugin.inlang.messageFormat": { pathPattern: "./messages/{locale}.json" }
|
|
2030
2044
|
};
|
|
2031
|
-
const options$
|
|
2045
|
+
const options$4 = defineAddonOptions().add("languageTags", {
|
|
2032
2046
|
question: `Which languages would you like to support? ${import_picocolors$2.default.gray("(e.g. en,de-ch)")}`,
|
|
2033
2047
|
type: "string",
|
|
2034
2048
|
default: "en, es",
|
|
@@ -2051,11 +2065,11 @@ var paraglide_default = defineAddon({
|
|
|
2051
2065
|
id: "paraglide",
|
|
2052
2066
|
shortDescription: "i18n",
|
|
2053
2067
|
homepage: "https://inlang.com/m/gerre34r/library-inlang-paraglideJs",
|
|
2054
|
-
options: options$
|
|
2068
|
+
options: options$4,
|
|
2055
2069
|
setup: ({ kit, unsupported }) => {
|
|
2056
2070
|
if (!kit) unsupported("Requires SvelteKit");
|
|
2057
2071
|
},
|
|
2058
|
-
run: ({ sv, options: options$
|
|
2072
|
+
run: ({ sv, options: options$7, viteConfigFile, typescript, kit }) => {
|
|
2059
2073
|
const ext = typescript ? "ts" : "js";
|
|
2060
2074
|
if (!kit) throw new Error("SvelteKit is required");
|
|
2061
2075
|
const paraglideOutDir = "src/lib/paraglide";
|
|
@@ -2064,7 +2078,7 @@ var paraglide_default = defineAddon({
|
|
|
2064
2078
|
if (content) return content;
|
|
2065
2079
|
const { data, generateCode } = parseJson(content);
|
|
2066
2080
|
for (const key in DEFAULT_INLANG_PROJECT) data[key] = DEFAULT_INLANG_PROJECT[key];
|
|
2067
|
-
const { validLanguageTags: validLanguageTags$1 } = parseLanguageTagInput(options$
|
|
2081
|
+
const { validLanguageTags: validLanguageTags$1 } = parseLanguageTagInput(options$7.languageTags);
|
|
2068
2082
|
data.baseLocale = validLanguageTags$1[0];
|
|
2069
2083
|
data.locales = validLanguageTags$1;
|
|
2070
2084
|
return generateCode();
|
|
@@ -2136,7 +2150,7 @@ var paraglide_default = defineAddon({
|
|
|
2136
2150
|
if (!content.includes(`\n${paraglideOutDir}`)) content = content.trimEnd() + `\n\n# Paraglide\n${paraglideOutDir}`;
|
|
2137
2151
|
return content;
|
|
2138
2152
|
});
|
|
2139
|
-
if (options$
|
|
2153
|
+
if (options$7.demo) {
|
|
2140
2154
|
sv.file(`${kit.routesDirectory}/demo/+page.svelte`, (content) => {
|
|
2141
2155
|
return addToDemoPage(content, "paraglide");
|
|
2142
2156
|
});
|
|
@@ -2161,7 +2175,7 @@ var paraglide_default = defineAddon({
|
|
|
2161
2175
|
const scriptCode = new MagicString(script.generateCode());
|
|
2162
2176
|
const templateCode = new MagicString(template.source);
|
|
2163
2177
|
templateCode.append("\n\n<h1>{m.hello_world({ name: 'SvelteKit User' })}</h1>\n");
|
|
2164
|
-
const { validLanguageTags: validLanguageTags$1 } = parseLanguageTagInput(options$
|
|
2178
|
+
const { validLanguageTags: validLanguageTags$1 } = parseLanguageTagInput(options$7.languageTags);
|
|
2165
2179
|
const links = validLanguageTags$1.map((x$1) => `${templateCode.getIndentString()}<button onclick={() => setLocale('${x$1}')}>${x$1}</button>`).join("\n");
|
|
2166
2180
|
templateCode.append(`<div>\n${links}\n</div>`);
|
|
2167
2181
|
templateCode.append("<p>\nIf you use VSCode, install the <a href=\"https://marketplace.visualstudio.com/items?itemName=inlang.vs-code-extension\" target=\"_blank\">Sherlock i18n extension</a> for a better i18n experience.\n</p>");
|
|
@@ -2171,7 +2185,7 @@ var paraglide_default = defineAddon({
|
|
|
2171
2185
|
});
|
|
2172
2186
|
});
|
|
2173
2187
|
}
|
|
2174
|
-
const { validLanguageTags } = parseLanguageTagInput(options$
|
|
2188
|
+
const { validLanguageTags } = parseLanguageTagInput(options$7.languageTags);
|
|
2175
2189
|
for (const languageTag of validLanguageTags) sv.file(`messages/${languageTag}.json`, (content) => {
|
|
2176
2190
|
const { data, generateCode } = parseJson(content);
|
|
2177
2191
|
data["$schema"] = "https://inlang.com/schema/inlang-message-format";
|
|
@@ -2181,7 +2195,7 @@ var paraglide_default = defineAddon({
|
|
|
2181
2195
|
},
|
|
2182
2196
|
nextSteps: ({ highlighter }) => {
|
|
2183
2197
|
const steps = [`Edit your messages in ${highlighter.path("messages/en.json")}`];
|
|
2184
|
-
if (options$
|
|
2198
|
+
if (options$4.demo) steps.push(`Visit ${highlighter.route("/demo/paraglide")} route to view the demo`);
|
|
2185
2199
|
return steps;
|
|
2186
2200
|
}
|
|
2187
2201
|
});
|
|
@@ -2198,6 +2212,120 @@ function parseLanguageTagInput(input) {
|
|
|
2198
2212
|
};
|
|
2199
2213
|
}
|
|
2200
2214
|
|
|
2215
|
+
//#endregion
|
|
2216
|
+
//#region ../addons/mcp/index.ts
|
|
2217
|
+
const options$3 = defineAddonOptions().add("ide", {
|
|
2218
|
+
question: "Which client would you like to use?",
|
|
2219
|
+
type: "multiselect",
|
|
2220
|
+
default: [],
|
|
2221
|
+
options: [
|
|
2222
|
+
{
|
|
2223
|
+
value: "claude-code",
|
|
2224
|
+
label: "claude code"
|
|
2225
|
+
},
|
|
2226
|
+
{
|
|
2227
|
+
value: "cursor",
|
|
2228
|
+
label: "Cursor"
|
|
2229
|
+
},
|
|
2230
|
+
{
|
|
2231
|
+
value: "gemini",
|
|
2232
|
+
label: "Gemini"
|
|
2233
|
+
},
|
|
2234
|
+
{
|
|
2235
|
+
value: "opencode",
|
|
2236
|
+
label: "opencode"
|
|
2237
|
+
},
|
|
2238
|
+
{
|
|
2239
|
+
value: "vscode",
|
|
2240
|
+
label: "VSCode"
|
|
2241
|
+
},
|
|
2242
|
+
{
|
|
2243
|
+
value: "other",
|
|
2244
|
+
label: "Other"
|
|
2245
|
+
}
|
|
2246
|
+
],
|
|
2247
|
+
required: true
|
|
2248
|
+
}).add("setup", {
|
|
2249
|
+
question: "What setup you want to use?",
|
|
2250
|
+
type: "select",
|
|
2251
|
+
default: "remote",
|
|
2252
|
+
options: [{
|
|
2253
|
+
value: "local",
|
|
2254
|
+
label: "Local",
|
|
2255
|
+
hint: "will use stdio"
|
|
2256
|
+
}, {
|
|
2257
|
+
value: "remote",
|
|
2258
|
+
label: "Remote",
|
|
2259
|
+
hint: "will use a remote endpoint"
|
|
2260
|
+
}],
|
|
2261
|
+
required: true
|
|
2262
|
+
}).build();
|
|
2263
|
+
var mcp_default = defineAddon({
|
|
2264
|
+
id: "mcp",
|
|
2265
|
+
shortDescription: "Svelte MCP",
|
|
2266
|
+
homepage: "https://svelte.dev/docs/mcp",
|
|
2267
|
+
options: options$3,
|
|
2268
|
+
run: ({ sv, options: options$7 }) => {
|
|
2269
|
+
const getLocalConfig = (o) => {
|
|
2270
|
+
return {
|
|
2271
|
+
...o?.type ? { type: o.type } : {},
|
|
2272
|
+
command: "npx",
|
|
2273
|
+
args: ["-y", "@sveltejs/mcp"],
|
|
2274
|
+
...o?.env ? { env: {} } : {}
|
|
2275
|
+
};
|
|
2276
|
+
};
|
|
2277
|
+
const getRemoteConfig = (o) => {
|
|
2278
|
+
return {
|
|
2279
|
+
...o?.type ? { type: o.type } : {},
|
|
2280
|
+
url: "https://mcp.svelte.dev/mcp"
|
|
2281
|
+
};
|
|
2282
|
+
};
|
|
2283
|
+
const configurator = {
|
|
2284
|
+
"claude-code": {
|
|
2285
|
+
filePath: ".mcp.json",
|
|
2286
|
+
typeLocal: "stdio",
|
|
2287
|
+
typeRemote: "http",
|
|
2288
|
+
env: true
|
|
2289
|
+
},
|
|
2290
|
+
cursor: { filePath: ".cursor/mcp.json" },
|
|
2291
|
+
gemini: { filePath: ".gemini/settings.json" },
|
|
2292
|
+
opencode: {
|
|
2293
|
+
schema: "https://opencode.ai/config.json",
|
|
2294
|
+
mcpServersKey: "mcp",
|
|
2295
|
+
filePath: "opencode.json",
|
|
2296
|
+
typeLocal: "local",
|
|
2297
|
+
typeRemote: "remote"
|
|
2298
|
+
},
|
|
2299
|
+
vscode: {
|
|
2300
|
+
mcpServersKey: "servers",
|
|
2301
|
+
filePath: ".vscode/mcp.json"
|
|
2302
|
+
},
|
|
2303
|
+
other: { other: true }
|
|
2304
|
+
};
|
|
2305
|
+
for (const ide of options$7.ide) {
|
|
2306
|
+
const value = configurator[ide];
|
|
2307
|
+
if ("other" in value) continue;
|
|
2308
|
+
const { mcpServersKey, filePath, typeLocal, typeRemote, env, schema } = value;
|
|
2309
|
+
sv.file(filePath, (content) => {
|
|
2310
|
+
const { data, generateCode } = parseJson(content);
|
|
2311
|
+
if (schema) data["$schema"] = schema;
|
|
2312
|
+
const key = mcpServersKey || "mcpServers";
|
|
2313
|
+
data[key] ??= {};
|
|
2314
|
+
data[key].svelte = options$7.setup === "local" ? getLocalConfig({
|
|
2315
|
+
type: typeLocal,
|
|
2316
|
+
env
|
|
2317
|
+
}) : getRemoteConfig({ type: typeRemote });
|
|
2318
|
+
return generateCode();
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
},
|
|
2322
|
+
nextSteps({ highlighter, options: options$7 }) {
|
|
2323
|
+
const steps = [];
|
|
2324
|
+
if (options$7.ide.includes("other")) steps.push(`For other clients: ${highlighter.website(`https://svelte.dev/docs/mcp/${options$7.setup}-setup#Other-clients`)}`);
|
|
2325
|
+
return steps;
|
|
2326
|
+
}
|
|
2327
|
+
});
|
|
2328
|
+
|
|
2201
2329
|
//#endregion
|
|
2202
2330
|
//#region ../addons/playwright/index.ts
|
|
2203
2331
|
var playwright_default = defineAddon({
|
|
@@ -2409,8 +2537,8 @@ var sveltekit_adapter_default = defineAddon({
|
|
|
2409
2537
|
setup: ({ kit, unsupported }) => {
|
|
2410
2538
|
if (!kit) unsupported("Requires SvelteKit");
|
|
2411
2539
|
},
|
|
2412
|
-
run: ({ sv, options: options$
|
|
2413
|
-
const adapter = adapters.find((a) => a.id === options$
|
|
2540
|
+
run: ({ sv, options: options$7 }) => {
|
|
2541
|
+
const adapter = adapters.find((a) => a.id === options$7.adapter);
|
|
2414
2542
|
sv.file("package.json", (content) => {
|
|
2415
2543
|
const { data, generateCode } = parseJson(content);
|
|
2416
2544
|
const devDeps = data["devDependencies"];
|
|
@@ -2481,14 +2609,14 @@ var tailwindcss_default = defineAddon({
|
|
|
2481
2609
|
shortDescription: "css framework",
|
|
2482
2610
|
homepage: "https://tailwindcss.com",
|
|
2483
2611
|
options: options$1,
|
|
2484
|
-
run: ({ sv, options: options$
|
|
2612
|
+
run: ({ sv, options: options$7, viteConfigFile, typescript, kit, dependencyVersion }) => {
|
|
2485
2613
|
const prettierInstalled = Boolean(dependencyVersion("prettier"));
|
|
2486
2614
|
sv.devDependency("tailwindcss", "^4.1.13");
|
|
2487
2615
|
sv.devDependency("@tailwindcss/vite", "^4.1.13");
|
|
2488
2616
|
sv.pnpmBuildDependency("@tailwindcss/oxide");
|
|
2489
2617
|
if (prettierInstalled) sv.devDependency("prettier-plugin-tailwindcss", "^0.6.14");
|
|
2490
2618
|
for (const plugin of plugins) {
|
|
2491
|
-
if (!options$
|
|
2619
|
+
if (!options$7.plugins.includes(plugin.id)) continue;
|
|
2492
2620
|
sv.devDependency(plugin.package, plugin.version);
|
|
2493
2621
|
}
|
|
2494
2622
|
sv.file(viteConfigFile, (content) => {
|
|
@@ -2514,7 +2642,7 @@ var tailwindcss_default = defineAddon({
|
|
|
2514
2642
|
}
|
|
2515
2643
|
const pluginPos = atRules.findLast((rule) => ["plugin", "import"].includes(rule.name)).source.end.offset;
|
|
2516
2644
|
for (const plugin of plugins) {
|
|
2517
|
-
if (!options$
|
|
2645
|
+
if (!options$7.plugins.includes(plugin.id)) continue;
|
|
2518
2646
|
if (!findAtRule("plugin", plugin.package)) {
|
|
2519
2647
|
const pluginImport = `\n@plugin '${plugin.package}';`;
|
|
2520
2648
|
code = code.substring(0, pluginPos) + pluginImport + code.substring(pluginPos);
|
|
@@ -2575,10 +2703,10 @@ var vitest_addon_default = defineAddon({
|
|
|
2575
2703
|
shortDescription: "unit testing",
|
|
2576
2704
|
homepage: "https://vitest.dev",
|
|
2577
2705
|
options,
|
|
2578
|
-
run: ({ sv, viteConfigFile, typescript, kit, options: options$
|
|
2706
|
+
run: ({ sv, viteConfigFile, typescript, kit, options: options$7 }) => {
|
|
2579
2707
|
const ext = typescript ? "ts" : "js";
|
|
2580
|
-
const unitTesting = options$
|
|
2581
|
-
const componentTesting = options$
|
|
2708
|
+
const unitTesting = options$7.usages.includes("unit");
|
|
2709
|
+
const componentTesting = options$7.usages.includes("component");
|
|
2582
2710
|
sv.devDependency("vitest", "^3.2.4");
|
|
2583
2711
|
if (componentTesting) {
|
|
2584
2712
|
sv.devDependency("@vitest/browser", "^3.2.4");
|
|
@@ -2708,7 +2836,8 @@ const officialAddons = {
|
|
|
2708
2836
|
lucia: lucia_default,
|
|
2709
2837
|
mdsvex: mdsvex_default,
|
|
2710
2838
|
paraglide: paraglide_default,
|
|
2711
|
-
storybook: storybook_default
|
|
2839
|
+
storybook: storybook_default,
|
|
2840
|
+
mcp: mcp_default
|
|
2712
2841
|
};
|
|
2713
2842
|
function getAddonDetails(id) {
|
|
2714
2843
|
const details = Object.values(officialAddons).find((a) => a.id === id);
|
|
@@ -2741,17 +2870,17 @@ function getPackageJson(cwd) {
|
|
|
2741
2870
|
generateCode
|
|
2742
2871
|
};
|
|
2743
2872
|
}
|
|
2744
|
-
async function formatFiles(options$
|
|
2873
|
+
async function formatFiles(options$7) {
|
|
2745
2874
|
const args = [
|
|
2746
2875
|
"prettier",
|
|
2747
2876
|
"--write",
|
|
2748
2877
|
"--ignore-unknown",
|
|
2749
|
-
...options$
|
|
2878
|
+
...options$7.paths
|
|
2750
2879
|
];
|
|
2751
|
-
const cmd = resolveCommand(options$
|
|
2880
|
+
const cmd = resolveCommand(options$7.packageManager, "execute-local", args);
|
|
2752
2881
|
await be(cmd.command, cmd.args, {
|
|
2753
2882
|
nodeOptions: {
|
|
2754
|
-
cwd: options$
|
|
2883
|
+
cwd: options$7.cwd,
|
|
2755
2884
|
stdio: "pipe"
|
|
2756
2885
|
},
|
|
2757
2886
|
throwOnError: true
|
|
@@ -2813,15 +2942,16 @@ function getHighlighter() {
|
|
|
2813
2942
|
|
|
2814
2943
|
//#endregion
|
|
2815
2944
|
//#region commands/add/workspace.ts
|
|
2816
|
-
async function createWorkspace({ cwd, options: options$
|
|
2945
|
+
async function createWorkspace({ cwd, options: options$7 = {}, packageManager }) {
|
|
2817
2946
|
const resolvedCwd = path.resolve(cwd);
|
|
2818
2947
|
const usesTypescript = !any([commonFilePaths.jsconfig, commonFilePaths.tsconfig], { cwd })?.endsWith(commonFilePaths.jsconfig);
|
|
2819
2948
|
const viteConfigPath = path.join(resolvedCwd, commonFilePaths.viteConfigTS);
|
|
2820
2949
|
const viteConfigFile = fs.existsSync(viteConfigPath) ? commonFilePaths.viteConfigTS : commonFilePaths.viteConfig;
|
|
2821
2950
|
let dependencies = {};
|
|
2822
2951
|
let directory = resolvedCwd;
|
|
2823
|
-
const
|
|
2824
|
-
|
|
2952
|
+
const workspaceRoot = findWorkspaceRoot(directory);
|
|
2953
|
+
const { root } = path.parse(directory);
|
|
2954
|
+
while (directory && directory.length >= workspaceRoot.length) {
|
|
2825
2955
|
if (fs.existsSync(path.join(directory, commonFilePaths.packageJson))) {
|
|
2826
2956
|
const { data: packageJson } = getPackageJson(directory);
|
|
2827
2957
|
dependencies = {
|
|
@@ -2830,12 +2960,13 @@ async function createWorkspace({ cwd, options: options$6 = {}, packageManager })
|
|
|
2830
2960
|
...dependencies
|
|
2831
2961
|
};
|
|
2832
2962
|
}
|
|
2963
|
+
if (root === directory) break;
|
|
2833
2964
|
directory = path.dirname(directory);
|
|
2834
2965
|
}
|
|
2835
2966
|
for (const [key, value] of Object.entries(dependencies)) dependencies[key] = value.replaceAll(/[^\d|.]/g, "");
|
|
2836
2967
|
return {
|
|
2837
2968
|
cwd: resolvedCwd,
|
|
2838
|
-
options: options$
|
|
2969
|
+
options: options$7,
|
|
2839
2970
|
packageManager: packageManager ?? (await detect({ cwd }))?.name ?? getUserAgent() ?? "npm",
|
|
2840
2971
|
typescript: usesTypescript,
|
|
2841
2972
|
viteConfigFile,
|
|
@@ -2843,7 +2974,7 @@ async function createWorkspace({ cwd, options: options$6 = {}, packageManager })
|
|
|
2843
2974
|
dependencyVersion: (pkg) => dependencies[pkg]
|
|
2844
2975
|
};
|
|
2845
2976
|
}
|
|
2846
|
-
function
|
|
2977
|
+
function findWorkspaceRoot(cwd) {
|
|
2847
2978
|
const { root } = path.parse(cwd);
|
|
2848
2979
|
let directory = cwd;
|
|
2849
2980
|
while (directory && directory !== root) {
|
|
@@ -2854,7 +2985,7 @@ function findRoot(cwd) {
|
|
|
2854
2985
|
}
|
|
2855
2986
|
directory = path.dirname(directory);
|
|
2856
2987
|
}
|
|
2857
|
-
return
|
|
2988
|
+
return cwd;
|
|
2858
2989
|
}
|
|
2859
2990
|
function parseKitOptions(cwd) {
|
|
2860
2991
|
const configSource = readFile(cwd, commonFilePaths.svelteConfig);
|
|
@@ -2904,7 +3035,7 @@ const TESTING = process.env.NODE_ENV?.toLowerCase() === "test";
|
|
|
2904
3035
|
//#endregion
|
|
2905
3036
|
//#region lib/install.ts
|
|
2906
3037
|
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
2907
|
-
async function installAddon({ addons, cwd, options: options$
|
|
3038
|
+
async function installAddon({ addons, cwd, options: options$7, packageManager = "npm" }) {
|
|
2908
3039
|
const workspace = await createWorkspace({
|
|
2909
3040
|
cwd,
|
|
2910
3041
|
packageManager
|
|
@@ -2913,31 +3044,35 @@ async function installAddon({ addons, cwd, options: options$6, packageManager =
|
|
|
2913
3044
|
return await applyAddons({
|
|
2914
3045
|
addons,
|
|
2915
3046
|
workspace,
|
|
2916
|
-
options: options$
|
|
3047
|
+
options: options$7,
|
|
2917
3048
|
addonSetupResults
|
|
2918
3049
|
});
|
|
2919
3050
|
}
|
|
2920
|
-
async function applyAddons({ addons, workspace, addonSetupResults, options: options$
|
|
3051
|
+
async function applyAddons({ addons, workspace, addonSetupResults, options: options$7 }) {
|
|
2921
3052
|
const filesToFormat = /* @__PURE__ */ new Set();
|
|
2922
3053
|
const allPnpmBuildDependencies = [];
|
|
3054
|
+
const status = {};
|
|
2923
3055
|
const mapped = Object.entries(addons).map(([, addon]) => addon);
|
|
2924
3056
|
const ordered = orderAddons(mapped, addonSetupResults);
|
|
2925
3057
|
for (const addon of ordered) {
|
|
2926
3058
|
workspace = await createWorkspace({
|
|
2927
3059
|
...workspace,
|
|
2928
|
-
options: options$
|
|
3060
|
+
options: options$7[addon.id]
|
|
2929
3061
|
});
|
|
2930
|
-
const { files, pnpmBuildDependencies } = await runAddon({
|
|
3062
|
+
const { files, pnpmBuildDependencies, cancels } = await runAddon({
|
|
2931
3063
|
workspace,
|
|
2932
3064
|
addon,
|
|
2933
3065
|
multiple: ordered.length > 1
|
|
2934
3066
|
});
|
|
2935
3067
|
files.forEach((f) => filesToFormat.add(f));
|
|
2936
3068
|
pnpmBuildDependencies.forEach((s) => allPnpmBuildDependencies.push(s));
|
|
3069
|
+
if (cancels.length === 0) status[addon.id] = "success";
|
|
3070
|
+
else status[addon.id] = cancels;
|
|
2937
3071
|
}
|
|
2938
3072
|
return {
|
|
2939
3073
|
filesToFormat: Array.from(filesToFormat),
|
|
2940
|
-
pnpmBuildDependencies: allPnpmBuildDependencies
|
|
3074
|
+
pnpmBuildDependencies: allPnpmBuildDependencies,
|
|
3075
|
+
status
|
|
2941
3076
|
};
|
|
2942
3077
|
}
|
|
2943
3078
|
function setupAddons(addons, workspace) {
|
|
@@ -3016,15 +3151,22 @@ async function runAddon({ addon, multiple, workspace }) {
|
|
|
3016
3151
|
pnpmBuildDependencies.push(pkg);
|
|
3017
3152
|
}
|
|
3018
3153
|
};
|
|
3154
|
+
const cancels = [];
|
|
3019
3155
|
await addon.run({
|
|
3156
|
+
cancel: (reason) => {
|
|
3157
|
+
cancels.push(reason);
|
|
3158
|
+
},
|
|
3020
3159
|
...workspace,
|
|
3021
3160
|
sv
|
|
3022
3161
|
});
|
|
3023
|
-
|
|
3024
|
-
|
|
3162
|
+
if (cancels.length === 0) {
|
|
3163
|
+
const pkgPath = installPackages(dependencies, workspace);
|
|
3164
|
+
files.add(pkgPath);
|
|
3165
|
+
}
|
|
3025
3166
|
return {
|
|
3026
3167
|
files: Array.from(files),
|
|
3027
|
-
pnpmBuildDependencies
|
|
3168
|
+
pnpmBuildDependencies,
|
|
3169
|
+
cancels
|
|
3028
3170
|
};
|
|
3029
3171
|
}
|
|
3030
3172
|
function orderAddons(addons, setupResults) {
|