sv 0.12.7 → 0.13.0
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.mjs +15 -18
- package/dist/{engine-v9g2eGJ2.mjs → engine-DOKagHfI.mjs} +1127 -935
- package/dist/{engine-BZ0rj9tz.d.mts → engine-M8NNzIgv.d.mts} +29 -48
- package/dist/{package-manager-BYzDyeam.mjs → package-manager-BU-MLhop.mjs} +946 -1503
- package/dist/shared.json +2 -2
- package/dist/src/index.d.mts +1 -1
- package/dist/src/index.mjs +3 -4
- package/dist/src/testing.d.mts +3 -6
- package/dist/src/testing.mjs +33 -47
- package/dist/templates/demo/files.types=checkjs.json +1 -1
- package/dist/templates/demo/files.types=none.json +1 -1
- package/dist/templates/demo/files.types=typescript.json +1 -1
- 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/templates/svelte/files.types=none.json +1 -1
- package/dist/templates/svelte/files.types=typescript.json +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as Pt, C as writeFile, D as Lt, E as Ie, F as kt, I as qt, L as Ct, M as R, N as Rt, O as Mt, P as Wt, R as __commonJSMin, S as readFile, T as
|
|
1
|
+
import { A as Pt, C as writeFile, D as Lt, E as Ie, F as kt, I as qt, L as Ct, M as R, N as Rt, O as Mt, P as Wt, R as __commonJSMin, S as readFile, T as z, _ as commonFilePaths, a as installOption, b as getPackageJson, c as up$1, d as Option, g as getSharedFiles, h as dist, i as installDependencies, j as Qt, k as Nt, m as templates, n as addPnpmBuildDependencies, o as packageManagerPrompt, p as create$1, r as detectPackageManager, s as any, t as AGENT_NAMES, u as Command, v as fileExists, x as installPackages, y as formatFiles, z as __require } from "./package-manager-BU-MLhop.mjs";
|
|
2
2
|
import { Walker, color, createPrinter, css, dedent, downloadJson, html, isVersionUnsupportedBelow, js, json, parse, resolveCommand, sanitizeName, splitVersion, svelte, text } from "@sveltejs/sv-utils";
|
|
3
|
-
import fs, {
|
|
4
|
-
import path, {
|
|
3
|
+
import fs, { readFileSync } from "node:fs";
|
|
4
|
+
import path, { join } from "node:path";
|
|
5
5
|
import process$1 from "node:process";
|
|
6
6
|
import { promisify } from "node:util";
|
|
7
7
|
import { exec } from "node:child_process";
|
|
@@ -10,18 +10,16 @@ import crypto from "node:crypto";
|
|
|
10
10
|
import { platform } from "node:os";
|
|
11
11
|
import { pipeline } from "node:stream/promises";
|
|
12
12
|
import { createGunzip } from "node:zlib";
|
|
13
|
-
|
|
14
13
|
//#region ../../node_modules/.pnpm/empathic@2.0.0/node_modules/empathic/package.mjs
|
|
15
14
|
/**
|
|
16
15
|
* Find the closest "package.json" file while walking parent directories.
|
|
17
16
|
* @returns The absolute path to a "package.json", if found.
|
|
18
17
|
*/
|
|
19
|
-
function up(options
|
|
20
|
-
return up$1("package.json", options
|
|
18
|
+
function up(options) {
|
|
19
|
+
return up$1("package.json", options);
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
//#endregion
|
|
24
|
-
//#region ../../node_modules/.pnpm/valibot@1.
|
|
22
|
+
//#region ../../node_modules/.pnpm/valibot@1.3.1_typescript@5.9.3/node_modules/valibot/dist/index.mjs
|
|
25
23
|
let store$4;
|
|
26
24
|
/**
|
|
27
25
|
* Returns the global configuration.
|
|
@@ -332,14 +330,14 @@ function optional(wrapped, default_) {
|
|
|
332
330
|
};
|
|
333
331
|
}
|
|
334
332
|
/* @__NO_SIDE_EFFECTS__ */
|
|
335
|
-
function picklist(options
|
|
333
|
+
function picklist(options, message$1) {
|
|
336
334
|
return {
|
|
337
335
|
kind: "schema",
|
|
338
336
|
type: "picklist",
|
|
339
337
|
reference: picklist,
|
|
340
|
-
expects: /* @__PURE__ */ _joinExpects(options
|
|
338
|
+
expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
|
|
341
339
|
async: false,
|
|
342
|
-
options
|
|
340
|
+
options,
|
|
343
341
|
message: message$1,
|
|
344
342
|
get "~standard"() {
|
|
345
343
|
return /* @__PURE__ */ _getStandardProps(this);
|
|
@@ -536,14 +534,14 @@ function _subIssues(datasets) {
|
|
|
536
534
|
return issues;
|
|
537
535
|
}
|
|
538
536
|
/* @__NO_SIDE_EFFECTS__ */
|
|
539
|
-
function union(options
|
|
537
|
+
function union(options, message$1) {
|
|
540
538
|
return {
|
|
541
539
|
kind: "schema",
|
|
542
540
|
type: "union",
|
|
543
541
|
reference: union,
|
|
544
|
-
expects: /* @__PURE__ */ _joinExpects(options
|
|
542
|
+
expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
|
|
545
543
|
async: false,
|
|
546
|
-
options
|
|
544
|
+
options,
|
|
547
545
|
message: message$1,
|
|
548
546
|
get "~standard"() {
|
|
549
547
|
return /* @__PURE__ */ _getStandardProps(this);
|
|
@@ -608,7 +606,6 @@ function pipe(...pipe$1) {
|
|
|
608
606
|
}
|
|
609
607
|
};
|
|
610
608
|
}
|
|
611
|
-
|
|
612
609
|
//#endregion
|
|
613
610
|
//#region src/core/config.ts
|
|
614
611
|
/**
|
|
@@ -650,25 +647,24 @@ function getErrorHint(source) {
|
|
|
650
647
|
function defineAddonOptions() {
|
|
651
648
|
return createOptionBuilder({});
|
|
652
649
|
}
|
|
653
|
-
function createOptionBuilder(options
|
|
650
|
+
function createOptionBuilder(options) {
|
|
654
651
|
return {
|
|
655
652
|
add(key, question) {
|
|
656
653
|
return createOptionBuilder({
|
|
657
|
-
...options
|
|
654
|
+
...options,
|
|
658
655
|
[key]: question
|
|
659
656
|
});
|
|
660
657
|
},
|
|
661
658
|
build() {
|
|
662
|
-
return options
|
|
659
|
+
return options;
|
|
663
660
|
}
|
|
664
661
|
};
|
|
665
662
|
}
|
|
666
|
-
|
|
667
663
|
//#endregion
|
|
668
664
|
//#region src/addons/common.ts
|
|
669
665
|
function addEslintConfigPrettier(content) {
|
|
670
666
|
const { ast, generateCode } = parse.script(content);
|
|
671
|
-
const sveltePluginImport = ast.body.filter((n) => n.type === "ImportDeclaration").find((n) => n.type === "ImportDeclaration" && n.source.value === "eslint-plugin-svelte" && n.specifiers?.some((n
|
|
667
|
+
const sveltePluginImport = ast.body.filter((n) => n.type === "ImportDeclaration").find((n) => n.type === "ImportDeclaration" && n.source.value === "eslint-plugin-svelte" && n.specifiers?.some((n) => n.type === "ImportDefaultSpecifier"));
|
|
672
668
|
let svelteImportName;
|
|
673
669
|
for (const specifier of sveltePluginImport?.specifiers ?? []) if (specifier.type === "ImportDefaultSpecifier" && specifier.local?.name) svelteImportName = specifier.local.name;
|
|
674
670
|
svelteImportName ??= "svelte";
|
|
@@ -694,20 +690,20 @@ function addEslintConfigPrettier(content) {
|
|
|
694
690
|
else elements.push(...nodesToInsert);
|
|
695
691
|
return generateCode();
|
|
696
692
|
}
|
|
697
|
-
function addToDemoPage(existingContent, path
|
|
693
|
+
function addToDemoPage(existingContent, path, language) {
|
|
698
694
|
const { ast, generateCode } = parse.svelte(existingContent);
|
|
699
695
|
for (const node of ast.fragment.nodes) if (node.type === "RegularElement") {
|
|
700
696
|
const hrefAttribute = node.attributes.find((x) => x.type === "Attribute" && x.name === "href");
|
|
701
697
|
if (!hrefAttribute || !hrefAttribute.value) continue;
|
|
702
698
|
if (!Array.isArray(hrefAttribute.value)) continue;
|
|
703
|
-
if (hrefAttribute.value.some((x) => x.type === "Text" && x.data.includes(`/demo/${path
|
|
699
|
+
if (hrefAttribute.value.some((x) => x.type === "Text" && x.data.includes(`/demo/${path}`))) return existingContent;
|
|
704
700
|
}
|
|
705
701
|
svelte.ensureScript(ast, { language });
|
|
706
702
|
js.imports.addNamed(ast.instance.content, {
|
|
707
703
|
imports: ["resolve"],
|
|
708
704
|
from: "$app/paths"
|
|
709
705
|
});
|
|
710
|
-
svelte.addFragment(ast, `<a href={resolve('/demo/${path
|
|
706
|
+
svelte.addFragment(ast, `<a href={resolve('/demo/${path}')}>${path}</a>`, { mode: "prepend" });
|
|
711
707
|
ast.fragment.nodes.unshift();
|
|
712
708
|
return generateCode();
|
|
713
709
|
}
|
|
@@ -726,45 +722,53 @@ function getNodeTypesVersion() {
|
|
|
726
722
|
if (!!process$1.release.lts || isDenoOrBun && isEvenMajor) return `^${major}`;
|
|
727
723
|
return `^${isEvenMajor ? majorNum - 2 : majorNum - 1}`;
|
|
728
724
|
}
|
|
729
|
-
|
|
725
|
+
//#endregion
|
|
726
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/taggedTemplateLiteral.js
|
|
727
|
+
function _taggedTemplateLiteral(e, t) {
|
|
728
|
+
return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } }));
|
|
729
|
+
}
|
|
730
730
|
//#endregion
|
|
731
731
|
//#region src/addons/better-auth.ts
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
type: "multiselect",
|
|
735
|
-
default: ["password"],
|
|
736
|
-
options: [{
|
|
737
|
-
value: "password",
|
|
738
|
-
label: "Email & Password"
|
|
739
|
-
}, {
|
|
740
|
-
value: "github",
|
|
741
|
-
label: "GitHub OAuth"
|
|
742
|
-
}],
|
|
743
|
-
required: false
|
|
744
|
-
}).build();
|
|
732
|
+
var _templateObject$1;
|
|
733
|
+
var _templateObject2;
|
|
745
734
|
var better_auth_default = defineAddon({
|
|
746
735
|
id: "better-auth",
|
|
747
736
|
shortDescription: "auth library",
|
|
748
737
|
homepage: "https://www.better-auth.com",
|
|
749
|
-
options:
|
|
738
|
+
options: defineAddonOptions().add("demo", {
|
|
739
|
+
question: "Which demo would you like to include?",
|
|
740
|
+
type: "multiselect",
|
|
741
|
+
default: ["password"],
|
|
742
|
+
options: [{
|
|
743
|
+
value: "password",
|
|
744
|
+
label: "Email & Password"
|
|
745
|
+
}, {
|
|
746
|
+
value: "github",
|
|
747
|
+
label: "GitHub OAuth"
|
|
748
|
+
}],
|
|
749
|
+
required: false
|
|
750
|
+
}).build(),
|
|
750
751
|
setup: ({ kit, dependencyVersion, unsupported, dependsOn, runsAfter }) => {
|
|
751
752
|
if (!kit) unsupported("Requires SvelteKit");
|
|
752
753
|
if (!dependencyVersion("drizzle-orm")) dependsOn("drizzle");
|
|
754
|
+
runsAfter("sveltekitAdapter");
|
|
753
755
|
runsAfter("tailwindcss");
|
|
754
756
|
},
|
|
755
|
-
run: ({ sv, language, options
|
|
757
|
+
run: ({ sv, language, options, kit, dependencyVersion, files }) => {
|
|
756
758
|
if (!kit) throw new Error("SvelteKit is required");
|
|
757
|
-
const demoPassword = options
|
|
758
|
-
const demoGithub = options
|
|
759
|
+
const demoPassword = options.demo.includes("password");
|
|
760
|
+
const demoGithub = options.demo.includes("github");
|
|
759
761
|
const hasDemo = demoPassword || demoGithub;
|
|
760
762
|
let drizzleDialect;
|
|
763
|
+
let d1 = false;
|
|
761
764
|
sv.devDependency("better-auth", "~1.4.21");
|
|
762
765
|
sv.devDependency("@better-auth/cli", "~1.4.21");
|
|
763
766
|
sv.file(`drizzle.config.${language}`, (content) => {
|
|
764
767
|
const { ast, generateCode } = parse.script(content);
|
|
765
|
-
const isProp = (name
|
|
768
|
+
const isProp = (name, node) => node.key.type === "Identifier" && node.key.name === name;
|
|
766
769
|
Walker.walk(ast, null, { Property(node) {
|
|
767
770
|
if (isProp("dialect", node) && node.value.type === "Literal" && typeof node.value.value === "string") drizzleDialect = node.value.value;
|
|
771
|
+
if (isProp("driver", node) && node.value.type === "Literal" && node.value.value === "d1-http") d1 = true;
|
|
768
772
|
} });
|
|
769
773
|
if (!drizzleDialect) throw new Error("Failed to detect DB dialect in your `drizzle.config.[js|ts]` file");
|
|
770
774
|
return generateCode();
|
|
@@ -775,7 +779,7 @@ var better_auth_default = defineAddon({
|
|
|
775
779
|
const { ast, generateCode, comments } = parse.script(content);
|
|
776
780
|
js.imports.addNamed(ast, {
|
|
777
781
|
from: "$lib/server/db",
|
|
778
|
-
imports: ["db"]
|
|
782
|
+
imports: [d1 ? "getDb" : "db"]
|
|
779
783
|
});
|
|
780
784
|
js.imports.addNamed(ast, {
|
|
781
785
|
from: "$app/server",
|
|
@@ -797,29 +801,56 @@ var better_auth_default = defineAddon({
|
|
|
797
801
|
from: "better-auth/minimal",
|
|
798
802
|
imports: ["betterAuth"]
|
|
799
803
|
});
|
|
800
|
-
const
|
|
801
|
-
export const auth = betterAuth({
|
|
802
|
-
baseURL: env.ORIGIN,
|
|
803
|
-
secret: env.BETTER_AUTH_SECRET,
|
|
804
|
-
database: drizzleAdapter(db, {
|
|
805
|
-
provider: '${{
|
|
804
|
+
const provider = {
|
|
806
805
|
mysql: "mysql",
|
|
807
806
|
postgresql: "pg",
|
|
808
807
|
sqlite: "sqlite",
|
|
809
808
|
turso: "sqlite"
|
|
810
|
-
}[drizzleDialect]
|
|
811
|
-
|
|
812
|
-
emailAndPassword: {
|
|
813
|
-
enabled: true
|
|
814
|
-
},${demoGithub ? `
|
|
809
|
+
}[drizzleDialect];
|
|
810
|
+
const githubProvider = demoGithub ? `
|
|
815
811
|
socialProviders: {
|
|
816
812
|
github: {
|
|
817
813
|
clientId: env.GITHUB_CLIENT_ID,
|
|
818
814
|
clientSecret: env.GITHUB_CLIENT_SECRET,
|
|
819
815
|
},
|
|
820
|
-
},` : ""
|
|
821
|
-
|
|
822
|
-
|
|
816
|
+
},` : "";
|
|
817
|
+
let authConfig = "";
|
|
818
|
+
if (d1) authConfig = dedent`
|
|
819
|
+
const authConfig = {
|
|
820
|
+
baseURL: env.ORIGIN,
|
|
821
|
+
secret: env.BETTER_AUTH_SECRET,
|
|
822
|
+
emailAndPassword: {
|
|
823
|
+
enabled: true
|
|
824
|
+
},${githubProvider}
|
|
825
|
+
plugins: [
|
|
826
|
+
sveltekitCookies(getRequestEvent) // make sure this is the last plugin in the array
|
|
827
|
+
],
|
|
828
|
+
}${language === "ts" ? " satisfies Omit<Parameters<typeof betterAuth>[0], \"database\">" : ""};
|
|
829
|
+
|
|
830
|
+
export const createAuth = (d1${language === "ts" ? ": D1Database" : ""}) => betterAuth({
|
|
831
|
+
...authConfig,
|
|
832
|
+
database: drizzleAdapter(getDb(d1), { provider: '${provider}' }),
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* DO NOT USE!
|
|
837
|
+
*
|
|
838
|
+
* This instance is used by the \`better-auth\` CLI for schema generation ONLY.
|
|
839
|
+
* To access \`auth\` at runtime, use \`event.locals.auth\`.
|
|
840
|
+
*/
|
|
841
|
+
export const auth = createAuth(${language === "ts" ? "null!" : "null"});`;
|
|
842
|
+
else authConfig = dedent`
|
|
843
|
+
export const auth = betterAuth({
|
|
844
|
+
baseURL: env.ORIGIN,
|
|
845
|
+
secret: env.BETTER_AUTH_SECRET,
|
|
846
|
+
database: drizzleAdapter(db, { provider: '${provider}' }),
|
|
847
|
+
emailAndPassword: {
|
|
848
|
+
enabled: true
|
|
849
|
+
},${githubProvider}
|
|
850
|
+
plugins: [
|
|
851
|
+
sveltekitCookies(getRequestEvent) // make sure this is the last plugin in the array
|
|
852
|
+
],
|
|
853
|
+
});`;
|
|
823
854
|
js.common.appendFromString(ast, {
|
|
824
855
|
code: authConfig,
|
|
825
856
|
comments
|
|
@@ -846,6 +877,10 @@ var better_auth_default = defineAddon({
|
|
|
846
877
|
});
|
|
847
878
|
sv.file("src/app.d.ts", (content) => {
|
|
848
879
|
const { ast, comments, generateCode } = parse.script(content);
|
|
880
|
+
if (d1) js.imports.addNamed(ast, {
|
|
881
|
+
imports: ["createAuth"],
|
|
882
|
+
from: "$lib/server/auth"
|
|
883
|
+
});
|
|
849
884
|
js.imports.addNamed(ast, {
|
|
850
885
|
imports: ["User", "Session"],
|
|
851
886
|
from: "better-auth/minimal",
|
|
@@ -856,8 +891,10 @@ var better_auth_default = defineAddon({
|
|
|
856
891
|
comments.remove((c) => c.type === "Line" && c.value.trim() === "interface Locals {}");
|
|
857
892
|
const user = locals.body.body.find((prop) => js.common.hasTypeProperty(prop, { name: "user" }));
|
|
858
893
|
const session = locals.body.body.find((prop) => js.common.hasTypeProperty(prop, { name: "session" }));
|
|
894
|
+
const auth = locals.body.body.find((prop) => js.common.hasTypeProperty(prop, { name: "auth" }));
|
|
859
895
|
if (!user) locals.body.body.push(js.common.createTypeProperty("user", "User", true));
|
|
860
896
|
if (!session) locals.body.body.push(js.common.createTypeProperty("session", "Session", true));
|
|
897
|
+
if (d1 && !auth) locals.body.body.push(js.common.createTypeProperty("auth", "ReturnType<typeof createAuth>", false));
|
|
861
898
|
return generateCode();
|
|
862
899
|
});
|
|
863
900
|
sv.file(`src/hooks.server.${language}`, (content) => {
|
|
@@ -867,7 +904,7 @@ var better_auth_default = defineAddon({
|
|
|
867
904
|
from: "better-auth/svelte-kit"
|
|
868
905
|
});
|
|
869
906
|
js.imports.addNamed(ast, {
|
|
870
|
-
imports: ["auth"],
|
|
907
|
+
imports: [d1 ? "createAuth" : "auth"],
|
|
871
908
|
from: "$lib/server/auth"
|
|
872
909
|
});
|
|
873
910
|
js.imports.addNamed(ast, {
|
|
@@ -875,7 +912,10 @@ var better_auth_default = defineAddon({
|
|
|
875
912
|
from: "$app/environment"
|
|
876
913
|
});
|
|
877
914
|
const handleContent = dedent`
|
|
878
|
-
async ({ event, resolve }) => {
|
|
915
|
+
async ({ event, resolve }) => {${d1 ? dedent`
|
|
916
|
+
if (!event.platform?.env?.DB) throw new Error('D1 binding "DB" not found — are you running with wrangler?');
|
|
917
|
+
event.locals.auth = createAuth(event.platform.env.DB);
|
|
918
|
+
const { auth } = event.locals;\n` : ""}
|
|
879
919
|
// Fetch current session from Better Auth
|
|
880
920
|
const session = await auth.api.getSession({
|
|
881
921
|
headers: event.request.headers
|
|
@@ -909,8 +949,9 @@ var better_auth_default = defineAddon({
|
|
|
909
949
|
return content;
|
|
910
950
|
}
|
|
911
951
|
const [ts] = createPrinter(language === "ts");
|
|
952
|
+
const d1AuthLine = d1 ? "\n const { auth } = event.locals;\n" : "";
|
|
912
953
|
const signInEmailAction = demoPassword ? `
|
|
913
|
-
signInEmail: async (event) => {
|
|
954
|
+
signInEmail: async (event) => {${d1AuthLine}
|
|
914
955
|
const formData = await event.request.formData();
|
|
915
956
|
const email = formData.get('email')?.toString() ?? '';
|
|
916
957
|
const password = formData.get('password')?.toString() ?? '';
|
|
@@ -932,7 +973,7 @@ var better_auth_default = defineAddon({
|
|
|
932
973
|
|
|
933
974
|
return redirect(302, '/demo/better-auth');
|
|
934
975
|
},
|
|
935
|
-
signUpEmail: async (event) => {
|
|
976
|
+
signUpEmail: async (event) => {${d1AuthLine}
|
|
936
977
|
const formData = await event.request.formData();
|
|
937
978
|
const email = formData.get('email')?.toString() ?? '';
|
|
938
979
|
const password = formData.get('password')?.toString() ?? '';
|
|
@@ -957,7 +998,7 @@ var better_auth_default = defineAddon({
|
|
|
957
998
|
return redirect(302, '/demo/better-auth');
|
|
958
999
|
},` : "";
|
|
959
1000
|
const signInSocialAction = demoGithub ? `
|
|
960
|
-
signInSocial: async (event) => {
|
|
1001
|
+
signInSocial: async (event) => {${d1AuthLine}
|
|
961
1002
|
const formData = await event.request.formData();
|
|
962
1003
|
const provider = formData.get('provider')?.toString() ?? 'github';
|
|
963
1004
|
const callbackURL = formData.get('callbackURL')?.toString() ?? '/demo/better-auth';
|
|
@@ -979,7 +1020,7 @@ var better_auth_default = defineAddon({
|
|
|
979
1020
|
import { fail, redirect } from '@sveltejs/kit';
|
|
980
1021
|
${ts("import type { Actions } from './$types';")}
|
|
981
1022
|
${ts("import type { PageServerLoad } from './$types';")}
|
|
982
|
-
import { auth } from '$lib/server/auth';
|
|
1023
|
+
${!d1 ? "import { auth } from '$lib/server/auth';" : ""}
|
|
983
1024
|
${needsAPIError ? "import { APIError } from 'better-auth/api';" : ""}
|
|
984
1025
|
|
|
985
1026
|
export const load${ts(": PageServerLoad")} = async (event) => {
|
|
@@ -1022,22 +1063,22 @@ var better_auth_default = defineAddon({
|
|
|
1022
1063
|
<button formaction="?/signUpEmail"${btn}>Register</button>
|
|
1023
1064
|
</form>
|
|
1024
1065
|
${tailwind ? `<p class="text-red-500">{form?.message ?? ''}</p>` : `<p style="color: red">{form?.message ?? ''}</p>`}` : "";
|
|
1025
|
-
const separator = demoPassword && demoGithub ? `\n\n
|
|
1066
|
+
const separator = demoPassword && demoGithub ? `\n\n\t\t\t\t\t<hr ${tailwind ? "class=\"my-4\"" : ""} />\n` : "";
|
|
1026
1067
|
const githubForm = demoGithub ? `
|
|
1027
1068
|
<form method="post" action="?/signInSocial" use:enhance>
|
|
1028
1069
|
<input type="hidden" name="provider" value="github" />
|
|
1029
1070
|
<input type="hidden" name="callbackURL" value="/demo/better-auth" />
|
|
1030
1071
|
<button${btn}>Sign in with GitHub</button>
|
|
1031
1072
|
</form>` : "";
|
|
1032
|
-
return dedent
|
|
1033
|
-
<script
|
|
1034
|
-
import { enhance } from '$app/forms'
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1073
|
+
return dedent(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral([
|
|
1074
|
+
"\n <script ",
|
|
1075
|
+
">\n import { enhance } from '$app/forms';\n ",
|
|
1076
|
+
"\n ",
|
|
1077
|
+
"\n <\/script>\n\n <h1>Login</h1>",
|
|
1078
|
+
"",
|
|
1079
|
+
"",
|
|
1080
|
+
"\n "
|
|
1081
|
+
])), ts("lang='ts'"), ts("import type { ActionData } from './$types';\n"), s5(`let { form }${ts(": { form: ActionData }")} = $props();`, `export let form${ts(": ActionData")};`), passwordForm, separator, githubForm);
|
|
1041
1082
|
});
|
|
1042
1083
|
sv.file(`${kit.routesDirectory}/demo/better-auth/+page.server.${language}`, (content) => {
|
|
1043
1084
|
if (content) {
|
|
@@ -1046,11 +1087,12 @@ var better_auth_default = defineAddon({
|
|
|
1046
1087
|
return content;
|
|
1047
1088
|
}
|
|
1048
1089
|
const [ts] = createPrinter(language === "ts");
|
|
1090
|
+
const d1AuthLine = d1 ? "\n const { auth } = event.locals;\n" : "";
|
|
1049
1091
|
return dedent`
|
|
1050
1092
|
import { redirect } from '@sveltejs/kit';
|
|
1051
1093
|
${ts("import type { Actions } from './$types';")}
|
|
1052
1094
|
${ts("import type { PageServerLoad } from './$types';")}
|
|
1053
|
-
import { auth } from '$lib/server/auth';
|
|
1095
|
+
${!d1 ? "import { auth } from '$lib/server/auth';" : ""}
|
|
1054
1096
|
|
|
1055
1097
|
export const load${ts(": PageServerLoad")} = async (event) => {
|
|
1056
1098
|
if (!event.locals.user) {
|
|
@@ -1060,7 +1102,7 @@ var better_auth_default = defineAddon({
|
|
|
1060
1102
|
};
|
|
1061
1103
|
|
|
1062
1104
|
export const actions${ts(": Actions")} = {
|
|
1063
|
-
signOut: async (event) => {
|
|
1105
|
+
signOut: async (event) => {${d1AuthLine}
|
|
1064
1106
|
await auth.api.signOut({
|
|
1065
1107
|
headers: event.request.headers
|
|
1066
1108
|
});
|
|
@@ -1079,23 +1121,17 @@ var better_auth_default = defineAddon({
|
|
|
1079
1121
|
const twBtnClasses = "class=\"bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition\"";
|
|
1080
1122
|
const svelte5 = !!dependencyVersion("svelte")?.startsWith("5");
|
|
1081
1123
|
const [ts, s5] = createPrinter(language === "ts", svelte5);
|
|
1082
|
-
return dedent
|
|
1083
|
-
<script
|
|
1084
|
-
import { enhance } from '$app/forms'
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
<h1>Hi, {data.user.name}!</h1>
|
|
1090
|
-
<p>Your user ID is {data.user.id}.</p>
|
|
1091
|
-
<form method="post" action="?/signOut" use:enhance>
|
|
1092
|
-
<button ${tailwind ? twBtnClasses : ""}>Sign out</button>
|
|
1093
|
-
</form>
|
|
1094
|
-
`;
|
|
1124
|
+
return dedent(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral([
|
|
1125
|
+
"\n <script ",
|
|
1126
|
+
">\n import { enhance } from '$app/forms';\n ",
|
|
1127
|
+
"\n ",
|
|
1128
|
+
"\n <\/script>\n\n <h1>Hi, {data.user.name}!</h1>\n <p>Your user ID is {data.user.id}.</p>\n <form method=\"post\" action=\"?/signOut\" use:enhance>\n <button ",
|
|
1129
|
+
">Sign out</button>\n </form>\n "
|
|
1130
|
+
])), ts("lang='ts'"), ts("import type { PageServerData } from './$types';\n"), s5(`let { data }${ts(": { data: PageServerData }")} = $props();`, `export let data${ts(": PageServerData")};`), tailwind ? twBtnClasses : "");
|
|
1095
1131
|
});
|
|
1096
1132
|
}
|
|
1097
1133
|
},
|
|
1098
|
-
nextSteps: ({ options
|
|
1134
|
+
nextSteps: ({ options, packageManager }) => {
|
|
1099
1135
|
const { command: authCmd, args: authArgs } = resolveCommand(packageManager, "run", ["auth:schema"]);
|
|
1100
1136
|
const { command: dbCmd, args: dbArgs } = resolveCommand(packageManager, "run", ["db:push"]);
|
|
1101
1137
|
const steps = [
|
|
@@ -1103,8 +1139,8 @@ var better_auth_default = defineAddon({
|
|
|
1103
1139
|
`Run ${color.command(`${dbCmd} ${dbArgs.join(" ")}`)} to update your database`,
|
|
1104
1140
|
`Check ${color.env("ORIGIN")} & ${color.env("BETTER_AUTH_SECRET")} in ${color.path(".env")} and adjust it to your needs`
|
|
1105
1141
|
];
|
|
1106
|
-
if (options
|
|
1107
|
-
if (options
|
|
1142
|
+
if (options.demo.includes("github")) steps.push(`Set your ${color.env("GITHUB_CLIENT_ID")} and ${color.env("GITHUB_CLIENT_SECRET")} in ${color.path(".env")}`);
|
|
1143
|
+
if (options.demo.length > 0) steps.push(`Visit ${color.route("/demo/better-auth")} route to view the demo`);
|
|
1108
1144
|
return steps;
|
|
1109
1145
|
}
|
|
1110
1146
|
});
|
|
@@ -1131,7 +1167,6 @@ function generateEnvFileContent$1(content, demoGithub, isExample) {
|
|
|
1131
1167
|
}
|
|
1132
1168
|
return content;
|
|
1133
1169
|
}
|
|
1134
|
-
|
|
1135
1170
|
//#endregion
|
|
1136
1171
|
//#region src/addons/devtools-json.ts
|
|
1137
1172
|
var devtools_json_default = defineAddon({
|
|
@@ -1153,104 +1188,109 @@ var devtools_json_default = defineAddon({
|
|
|
1153
1188
|
});
|
|
1154
1189
|
}
|
|
1155
1190
|
});
|
|
1156
|
-
|
|
1157
1191
|
//#endregion
|
|
1158
1192
|
//#region src/addons/drizzle.ts
|
|
1159
1193
|
const PORTS = {
|
|
1160
1194
|
mysql: "3306",
|
|
1161
1195
|
postgresql: "5432",
|
|
1162
|
-
sqlite: ""
|
|
1196
|
+
sqlite: "",
|
|
1197
|
+
d1: ""
|
|
1163
1198
|
};
|
|
1164
|
-
const options$6 = defineAddonOptions().add("database", {
|
|
1165
|
-
question: "Which database would you like to use?",
|
|
1166
|
-
type: "select",
|
|
1167
|
-
default: "sqlite",
|
|
1168
|
-
options: [
|
|
1169
|
-
{
|
|
1170
|
-
value: "postgresql",
|
|
1171
|
-
label: "PostgreSQL"
|
|
1172
|
-
},
|
|
1173
|
-
{
|
|
1174
|
-
value: "mysql",
|
|
1175
|
-
label: "MySQL"
|
|
1176
|
-
},
|
|
1177
|
-
{
|
|
1178
|
-
value: "sqlite",
|
|
1179
|
-
label: "SQLite"
|
|
1180
|
-
}
|
|
1181
|
-
]
|
|
1182
|
-
}).add("postgresql", {
|
|
1183
|
-
question: "Which PostgreSQL client would you like to use?",
|
|
1184
|
-
type: "select",
|
|
1185
|
-
group: "client",
|
|
1186
|
-
default: "postgres.js",
|
|
1187
|
-
options: [{
|
|
1188
|
-
value: "postgres.js",
|
|
1189
|
-
label: "Postgres.JS",
|
|
1190
|
-
hint: "recommended for most users"
|
|
1191
|
-
}, {
|
|
1192
|
-
value: "neon",
|
|
1193
|
-
label: "Neon",
|
|
1194
|
-
hint: "popular hosted platform"
|
|
1195
|
-
}],
|
|
1196
|
-
condition: ({ database }) => database === "postgresql"
|
|
1197
|
-
}).add("mysql", {
|
|
1198
|
-
question: "Which MySQL client would you like to use?",
|
|
1199
|
-
type: "select",
|
|
1200
|
-
group: "client",
|
|
1201
|
-
default: "mysql2",
|
|
1202
|
-
options: [{
|
|
1203
|
-
value: "mysql2",
|
|
1204
|
-
hint: "recommended for most users"
|
|
1205
|
-
}, {
|
|
1206
|
-
value: "planetscale",
|
|
1207
|
-
label: "PlanetScale",
|
|
1208
|
-
hint: "popular hosted platform"
|
|
1209
|
-
}],
|
|
1210
|
-
condition: ({ database }) => database === "mysql"
|
|
1211
|
-
}).add("sqlite", {
|
|
1212
|
-
question: "Which SQLite client would you like to use?",
|
|
1213
|
-
type: "select",
|
|
1214
|
-
group: "client",
|
|
1215
|
-
default: "libsql",
|
|
1216
|
-
options: [
|
|
1217
|
-
{
|
|
1218
|
-
value: "better-sqlite3",
|
|
1219
|
-
hint: "for traditional Node environments"
|
|
1220
|
-
},
|
|
1221
|
-
{
|
|
1222
|
-
value: "libsql",
|
|
1223
|
-
label: "libSQL",
|
|
1224
|
-
hint: "for serverless environments"
|
|
1225
|
-
},
|
|
1226
|
-
{
|
|
1227
|
-
value: "turso",
|
|
1228
|
-
label: "Turso",
|
|
1229
|
-
hint: "popular hosted platform"
|
|
1230
|
-
}
|
|
1231
|
-
],
|
|
1232
|
-
condition: ({ database }) => database === "sqlite"
|
|
1233
|
-
}).add("docker", {
|
|
1234
|
-
question: "Do you want to run the database locally with docker-compose?",
|
|
1235
|
-
default: false,
|
|
1236
|
-
type: "boolean",
|
|
1237
|
-
condition: ({ database, mysql, postgresql }) => database === "mysql" && mysql === "mysql2" || database === "postgresql" && postgresql === "postgres.js"
|
|
1238
|
-
}).build();
|
|
1239
1199
|
var drizzle_default = defineAddon({
|
|
1240
1200
|
id: "drizzle",
|
|
1241
1201
|
shortDescription: "database orm",
|
|
1242
1202
|
homepage: "https://orm.drizzle.team",
|
|
1243
|
-
options:
|
|
1203
|
+
options: defineAddonOptions().add("database", {
|
|
1204
|
+
question: "Which database would you like to use?",
|
|
1205
|
+
type: "select",
|
|
1206
|
+
default: "sqlite",
|
|
1207
|
+
options: [
|
|
1208
|
+
{
|
|
1209
|
+
value: "postgresql",
|
|
1210
|
+
label: "PostgreSQL"
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
value: "mysql",
|
|
1214
|
+
label: "MySQL"
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
value: "sqlite",
|
|
1218
|
+
label: "SQLite"
|
|
1219
|
+
},
|
|
1220
|
+
{
|
|
1221
|
+
value: "d1",
|
|
1222
|
+
label: "Cloudflare D1"
|
|
1223
|
+
}
|
|
1224
|
+
]
|
|
1225
|
+
}).add("postgresql", {
|
|
1226
|
+
question: "Which PostgreSQL client would you like to use?",
|
|
1227
|
+
type: "select",
|
|
1228
|
+
group: "client",
|
|
1229
|
+
default: "postgres.js",
|
|
1230
|
+
options: [{
|
|
1231
|
+
value: "postgres.js",
|
|
1232
|
+
label: "Postgres.JS",
|
|
1233
|
+
hint: "recommended for most users"
|
|
1234
|
+
}, {
|
|
1235
|
+
value: "neon",
|
|
1236
|
+
label: "Neon",
|
|
1237
|
+
hint: "popular hosted platform"
|
|
1238
|
+
}],
|
|
1239
|
+
condition: ({ database }) => database === "postgresql"
|
|
1240
|
+
}).add("mysql", {
|
|
1241
|
+
question: "Which MySQL client would you like to use?",
|
|
1242
|
+
type: "select",
|
|
1243
|
+
group: "client",
|
|
1244
|
+
default: "mysql2",
|
|
1245
|
+
options: [{
|
|
1246
|
+
value: "mysql2",
|
|
1247
|
+
hint: "recommended for most users"
|
|
1248
|
+
}, {
|
|
1249
|
+
value: "planetscale",
|
|
1250
|
+
label: "PlanetScale",
|
|
1251
|
+
hint: "popular hosted platform"
|
|
1252
|
+
}],
|
|
1253
|
+
condition: ({ database }) => database === "mysql"
|
|
1254
|
+
}).add("sqlite", {
|
|
1255
|
+
question: "Which SQLite client would you like to use?",
|
|
1256
|
+
type: "select",
|
|
1257
|
+
group: "client",
|
|
1258
|
+
default: "libsql",
|
|
1259
|
+
options: [
|
|
1260
|
+
{
|
|
1261
|
+
value: "better-sqlite3",
|
|
1262
|
+
hint: "for traditional Node environments"
|
|
1263
|
+
},
|
|
1264
|
+
{
|
|
1265
|
+
value: "libsql",
|
|
1266
|
+
label: "libSQL",
|
|
1267
|
+
hint: "for serverless environments"
|
|
1268
|
+
},
|
|
1269
|
+
{
|
|
1270
|
+
value: "turso",
|
|
1271
|
+
label: "Turso",
|
|
1272
|
+
hint: "popular hosted platform"
|
|
1273
|
+
}
|
|
1274
|
+
],
|
|
1275
|
+
condition: ({ database }) => database === "sqlite"
|
|
1276
|
+
}).add("docker", {
|
|
1277
|
+
question: "Do you want to run the database locally with docker-compose?",
|
|
1278
|
+
default: false,
|
|
1279
|
+
type: "boolean",
|
|
1280
|
+
condition: ({ database, mysql, postgresql }) => database === "mysql" && mysql === "mysql2" || database === "postgresql" && postgresql === "postgres.js"
|
|
1281
|
+
}).build(),
|
|
1244
1282
|
setup: ({ kit, unsupported, runsAfter }) => {
|
|
1245
1283
|
runsAfter("prettier");
|
|
1284
|
+
runsAfter("sveltekitAdapter");
|
|
1246
1285
|
if (!kit) return unsupported("Requires SvelteKit");
|
|
1247
1286
|
},
|
|
1248
|
-
run: ({ sv, language, options
|
|
1287
|
+
run: ({ sv, language, options, kit, dependencyVersion, cwd, cancel, files }) => {
|
|
1249
1288
|
if (!kit) throw new Error("SvelteKit is required");
|
|
1289
|
+
if (options.database === "d1" && !dependencyVersion("@sveltejs/adapter-cloudflare")) return cancel("Cloudflare D1 requires @sveltejs/adapter-cloudflare — add the adapter first");
|
|
1250
1290
|
const typescript = language === "ts";
|
|
1251
|
-
const baseDBPath = path.resolve(cwd
|
|
1291
|
+
const baseDBPath = path.resolve(cwd, kit.libDirectory, "server", "db");
|
|
1252
1292
|
const paths = {
|
|
1253
|
-
"drizzle config": path.resolve(cwd
|
|
1293
|
+
"drizzle config": path.resolve(cwd, `drizzle.config.${language}`),
|
|
1254
1294
|
"database schema": path.resolve(baseDBPath, `schema.${language}`),
|
|
1255
1295
|
database: path.resolve(baseDBPath, `index.${language}`)
|
|
1256
1296
|
};
|
|
@@ -1258,19 +1298,19 @@ var drizzle_default = defineAddon({
|
|
|
1258
1298
|
sv.devDependency("drizzle-orm", "^0.45.1");
|
|
1259
1299
|
sv.devDependency("drizzle-kit", "^0.31.8");
|
|
1260
1300
|
sv.devDependency("@types/node", getNodeTypesVersion());
|
|
1261
|
-
if (options
|
|
1262
|
-
if (options
|
|
1263
|
-
if (options
|
|
1264
|
-
if (options
|
|
1265
|
-
if (options
|
|
1301
|
+
if (options.mysql === "mysql2") sv.devDependency("mysql2", "^3.16.3");
|
|
1302
|
+
if (options.mysql === "planetscale") sv.devDependency("@planetscale/database", "^1.19.0");
|
|
1303
|
+
if (options.postgresql === "neon") sv.devDependency("@neondatabase/serverless", "^1.0.2");
|
|
1304
|
+
if (options.postgresql === "postgres.js") sv.devDependency("postgres", "^3.4.8");
|
|
1305
|
+
if (options.sqlite === "better-sqlite3") {
|
|
1266
1306
|
sv.dependency("better-sqlite3", "^12.6.2");
|
|
1267
1307
|
sv.devDependency("@types/better-sqlite3", "^7.6.13");
|
|
1268
1308
|
sv.pnpmBuildDependency("better-sqlite3");
|
|
1269
1309
|
}
|
|
1270
|
-
if (options
|
|
1271
|
-
sv.file(".env", (content) => generateEnvFileContent(content, options
|
|
1272
|
-
sv.file(".env.example", (content) => generateEnvFileContent(content, options
|
|
1273
|
-
if (options
|
|
1310
|
+
if (options.sqlite === "libsql" || options.sqlite === "turso") sv.devDependency("@libsql/client", "^0.17.0");
|
|
1311
|
+
sv.file(".env", (content) => generateEnvFileContent(content, options, false));
|
|
1312
|
+
sv.file(".env.example", (content) => generateEnvFileContent(content, options, true));
|
|
1313
|
+
if (options.docker && (options.mysql === "mysql2" || options.postgresql === "postgres.js")) {
|
|
1274
1314
|
const composeFileOptions = [
|
|
1275
1315
|
"docker-compose.yml",
|
|
1276
1316
|
"docker-compose.yaml",
|
|
@@ -1279,18 +1319,18 @@ var drizzle_default = defineAddon({
|
|
|
1279
1319
|
let composeFile = "";
|
|
1280
1320
|
for (const option of composeFileOptions) {
|
|
1281
1321
|
composeFile = option;
|
|
1282
|
-
if (fs.existsSync(path.resolve(cwd
|
|
1322
|
+
if (fs.existsSync(path.resolve(cwd, option))) break;
|
|
1283
1323
|
}
|
|
1284
1324
|
if (composeFile === "") throw new Error("unreachable state...");
|
|
1285
1325
|
sv.file(composeFile, (content) => {
|
|
1286
1326
|
if (content.length > 0) return content;
|
|
1287
|
-
const imageName = options
|
|
1288
|
-
const port = PORTS[options
|
|
1327
|
+
const imageName = options.database === "mysql" ? "mysql" : "postgres";
|
|
1328
|
+
const port = PORTS[options.database];
|
|
1289
1329
|
const USER = "root";
|
|
1290
1330
|
const PASSWORD = "mysecretpassword";
|
|
1291
1331
|
const DB_NAME = "local";
|
|
1292
1332
|
let dbSpecificContent = "";
|
|
1293
|
-
if (options
|
|
1333
|
+
if (options.mysql === "mysql2") dbSpecificContent = `
|
|
1294
1334
|
MYSQL_ROOT_PASSWORD: ${PASSWORD}
|
|
1295
1335
|
MYSQL_DATABASE: ${DB_NAME}
|
|
1296
1336
|
volumes:
|
|
@@ -1298,7 +1338,7 @@ var drizzle_default = defineAddon({
|
|
|
1298
1338
|
volumes:
|
|
1299
1339
|
mysqldata:
|
|
1300
1340
|
`;
|
|
1301
|
-
if (options
|
|
1341
|
+
if (options.postgresql === "postgres.js") dbSpecificContent = `
|
|
1302
1342
|
POSTGRES_USER: ${USER}
|
|
1303
1343
|
POSTGRES_PASSWORD: ${PASSWORD}
|
|
1304
1344
|
POSTGRES_DB: ${DB_NAME}
|
|
@@ -1321,7 +1361,7 @@ var drizzle_default = defineAddon({
|
|
|
1321
1361
|
}
|
|
1322
1362
|
sv.file(files.package, (content) => {
|
|
1323
1363
|
const { data, generateCode } = parse.json(content);
|
|
1324
|
-
if (options
|
|
1364
|
+
if (options.docker) json.packageScriptsUpsert(data, "db:start", "docker compose up");
|
|
1325
1365
|
json.packageScriptsUpsert(data, "db:push", "drizzle-kit push");
|
|
1326
1366
|
json.packageScriptsUpsert(data, "db:generate", "drizzle-kit generate");
|
|
1327
1367
|
json.packageScriptsUpsert(data, "db:migrate", "drizzle-kit migrate");
|
|
@@ -1331,34 +1371,54 @@ var drizzle_default = defineAddon({
|
|
|
1331
1371
|
if (Boolean(dependencyVersion("prettier"))) sv.file(files.prettierignore, (content) => {
|
|
1332
1372
|
return text.upsert(content, "/drizzle/");
|
|
1333
1373
|
});
|
|
1334
|
-
if (options
|
|
1374
|
+
if (options.database === "sqlite") sv.file(files.gitignore, (content) => {
|
|
1335
1375
|
if (content.length === 0) return content;
|
|
1336
1376
|
return text.upsert(content, "*.db", { comment: "SQLite" });
|
|
1337
1377
|
});
|
|
1338
1378
|
sv.file(paths["drizzle config"], (content) => {
|
|
1379
|
+
const d1 = options.database === "d1";
|
|
1380
|
+
const turso = options.sqlite === "turso";
|
|
1339
1381
|
const { ast, generateCode } = parse.script(content);
|
|
1340
1382
|
js.imports.addNamed(ast, {
|
|
1341
1383
|
from: "drizzle-kit",
|
|
1342
1384
|
imports: { defineConfig: "defineConfig" }
|
|
1343
1385
|
});
|
|
1344
|
-
ast.body.push(js.common.parseStatement("if (!process.env.
|
|
1386
|
+
if (d1) ast.body.push(js.common.parseStatement("if (!process.env.CLOUDFLARE_ACCOUNT_ID) throw new Error('CLOUDFLARE_ACCOUNT_ID is not set');"), js.common.parseStatement("if (!process.env.CLOUDFLARE_DATABASE_ID) throw new Error('CLOUDFLARE_DATABASE_ID is not set');"), js.common.parseStatement("if (!process.env.CLOUDFLARE_D1_TOKEN) throw new Error('CLOUDFLARE_D1_TOKEN is not set');"));
|
|
1387
|
+
else ast.body.push(js.common.parseStatement("if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');"));
|
|
1388
|
+
const getDialect = () => {
|
|
1389
|
+
if (d1) return "sqlite";
|
|
1390
|
+
if (turso) return "turso";
|
|
1391
|
+
return options.database;
|
|
1392
|
+
};
|
|
1393
|
+
const getCredentials = () => {
|
|
1394
|
+
const creds = [];
|
|
1395
|
+
if (d1) {
|
|
1396
|
+
creds.push("accountId: process.env.CLOUDFLARE_ACCOUNT_ID,");
|
|
1397
|
+
creds.push("databaseId: process.env.CLOUDFLARE_DATABASE_ID,");
|
|
1398
|
+
creds.push("token: process.env.CLOUDFLARE_D1_TOKEN,");
|
|
1399
|
+
}
|
|
1400
|
+
if (turso) creds.push("authToken: process.env.DATABASE_AUTH_TOKEN,");
|
|
1401
|
+
if (!d1) creds.push("url: process.env.DATABASE_URL,");
|
|
1402
|
+
return creds.join("\n");
|
|
1403
|
+
};
|
|
1345
1404
|
js.exports.createDefault(ast, { fallback: js.common.parseExpression(`
|
|
1346
1405
|
defineConfig({
|
|
1347
|
-
schema: "./src/lib/server/db/schema.${
|
|
1348
|
-
dialect: "${
|
|
1406
|
+
schema: "./src/lib/server/db/schema.${language}",
|
|
1407
|
+
dialect: "${getDialect()}",
|
|
1408
|
+
${d1 ? "driver: 'd1-http'," : ""}
|
|
1349
1409
|
dbCredentials: {
|
|
1350
|
-
${
|
|
1351
|
-
url: process.env.DATABASE_URL
|
|
1410
|
+
${getCredentials()}
|
|
1352
1411
|
},
|
|
1353
1412
|
verbose: true,
|
|
1354
1413
|
strict: true
|
|
1355
|
-
})
|
|
1414
|
+
})
|
|
1415
|
+
`) });
|
|
1356
1416
|
return generateCode();
|
|
1357
1417
|
});
|
|
1358
1418
|
sv.file(paths["database schema"], (content) => {
|
|
1359
1419
|
const { ast, generateCode } = parse.script(content);
|
|
1360
1420
|
let taskSchemaExpression;
|
|
1361
|
-
if (options
|
|
1421
|
+
if (options.database === "sqlite" || options.database === "d1") {
|
|
1362
1422
|
js.imports.addNamed(ast, {
|
|
1363
1423
|
from: "drizzle-orm/sqlite-core",
|
|
1364
1424
|
imports: [
|
|
@@ -1373,7 +1433,7 @@ var drizzle_default = defineAddon({
|
|
|
1373
1433
|
priority: integer('priority').notNull().default(1)
|
|
1374
1434
|
})`);
|
|
1375
1435
|
}
|
|
1376
|
-
if (options
|
|
1436
|
+
if (options.database === "mysql") {
|
|
1377
1437
|
js.imports.addNamed(ast, {
|
|
1378
1438
|
from: "drizzle-orm/mysql-core",
|
|
1379
1439
|
imports: [
|
|
@@ -1389,7 +1449,7 @@ var drizzle_default = defineAddon({
|
|
|
1389
1449
|
priority: int('priority').notNull().default(1)
|
|
1390
1450
|
})`);
|
|
1391
1451
|
}
|
|
1392
|
-
if (options
|
|
1452
|
+
if (options.database === "postgresql") {
|
|
1393
1453
|
js.imports.addNamed(ast, {
|
|
1394
1454
|
from: "drizzle-orm/pg-core",
|
|
1395
1455
|
imports: [
|
|
@@ -1417,8 +1477,21 @@ var drizzle_default = defineAddon({
|
|
|
1417
1477
|
});
|
|
1418
1478
|
return generateCode();
|
|
1419
1479
|
});
|
|
1420
|
-
sv.file(paths
|
|
1480
|
+
sv.file(paths.database, (content) => {
|
|
1421
1481
|
const { ast, generateCode } = parse.script(content);
|
|
1482
|
+
if (options.database === "d1") {
|
|
1483
|
+
js.imports.addNamespace(ast, {
|
|
1484
|
+
from: "./schema",
|
|
1485
|
+
as: "schema"
|
|
1486
|
+
});
|
|
1487
|
+
js.imports.addNamed(ast, {
|
|
1488
|
+
from: "drizzle-orm/d1",
|
|
1489
|
+
imports: ["drizzle"]
|
|
1490
|
+
});
|
|
1491
|
+
const getDbFn = js.common.parseStatement(`export const getDb = (d1${typescript ? ": D1Database" : ""}) => drizzle(d1, { schema });`);
|
|
1492
|
+
ast.body.push(getDbFn);
|
|
1493
|
+
return generateCode();
|
|
1494
|
+
}
|
|
1422
1495
|
js.imports.addNamed(ast, {
|
|
1423
1496
|
from: "$env/dynamic/private",
|
|
1424
1497
|
imports: ["env"]
|
|
@@ -1430,7 +1503,7 @@ var drizzle_default = defineAddon({
|
|
|
1430
1503
|
const dbURLCheck = js.common.parseStatement("if (!env.DATABASE_URL) throw new Error('DATABASE_URL is not set');");
|
|
1431
1504
|
ast.body.push(dbURLCheck);
|
|
1432
1505
|
let clientExpression;
|
|
1433
|
-
if (options
|
|
1506
|
+
if (options.sqlite === "better-sqlite3") {
|
|
1434
1507
|
js.imports.addDefault(ast, {
|
|
1435
1508
|
from: "better-sqlite3",
|
|
1436
1509
|
as: "Database"
|
|
@@ -1441,7 +1514,7 @@ var drizzle_default = defineAddon({
|
|
|
1441
1514
|
});
|
|
1442
1515
|
clientExpression = js.common.parseExpression("new Database(env.DATABASE_URL)");
|
|
1443
1516
|
}
|
|
1444
|
-
if (options
|
|
1517
|
+
if (options.sqlite === "libsql" || options.sqlite === "turso") {
|
|
1445
1518
|
js.imports.addNamed(ast, {
|
|
1446
1519
|
from: "@libsql/client",
|
|
1447
1520
|
imports: ["createClient"]
|
|
@@ -1450,12 +1523,12 @@ var drizzle_default = defineAddon({
|
|
|
1450
1523
|
from: "drizzle-orm/libsql",
|
|
1451
1524
|
imports: ["drizzle"]
|
|
1452
1525
|
});
|
|
1453
|
-
if (options
|
|
1526
|
+
if (options.sqlite === "turso") {
|
|
1454
1527
|
ast.body.push(js.common.parseStatement("if (!env.DATABASE_AUTH_TOKEN) throw new Error('DATABASE_AUTH_TOKEN is not set');"));
|
|
1455
1528
|
clientExpression = js.common.parseExpression("createClient({ url: env.DATABASE_URL, authToken: env.DATABASE_AUTH_TOKEN })");
|
|
1456
1529
|
} else clientExpression = js.common.parseExpression("createClient({ url: env.DATABASE_URL })");
|
|
1457
1530
|
}
|
|
1458
|
-
if (options
|
|
1531
|
+
if (options.mysql === "mysql2" || options.mysql === "planetscale") {
|
|
1459
1532
|
js.imports.addDefault(ast, {
|
|
1460
1533
|
from: "mysql2/promise",
|
|
1461
1534
|
as: "mysql"
|
|
@@ -1466,7 +1539,7 @@ var drizzle_default = defineAddon({
|
|
|
1466
1539
|
});
|
|
1467
1540
|
clientExpression = js.common.parseExpression("mysql.createPool(env.DATABASE_URL)");
|
|
1468
1541
|
}
|
|
1469
|
-
if (options
|
|
1542
|
+
if (options.postgresql === "neon") {
|
|
1470
1543
|
js.imports.addNamed(ast, {
|
|
1471
1544
|
from: "@neondatabase/serverless",
|
|
1472
1545
|
imports: ["neon"]
|
|
@@ -1477,7 +1550,7 @@ var drizzle_default = defineAddon({
|
|
|
1477
1550
|
});
|
|
1478
1551
|
clientExpression = js.common.parseExpression("neon(env.DATABASE_URL)");
|
|
1479
1552
|
}
|
|
1480
|
-
if (options
|
|
1553
|
+
if (options.postgresql === "postgres.js") {
|
|
1481
1554
|
js.imports.addDefault(ast, {
|
|
1482
1555
|
from: "postgres",
|
|
1483
1556
|
as: "postgres"
|
|
@@ -1500,8 +1573,8 @@ var drizzle_default = defineAddon({
|
|
|
1500
1573
|
useIdentifiers: true
|
|
1501
1574
|
});
|
|
1502
1575
|
const paramObject = js.object.create({ schema: js.variables.createIdentifier("schema") });
|
|
1503
|
-
if (options
|
|
1504
|
-
const mode = options
|
|
1576
|
+
if (options.database === "mysql") {
|
|
1577
|
+
const mode = options.mysql === "planetscale" ? "planetscale" : "default";
|
|
1505
1578
|
js.object.property(paramObject, {
|
|
1506
1579
|
name: "mode",
|
|
1507
1580
|
fallback: js.common.createLiteral(mode)
|
|
@@ -1520,12 +1593,23 @@ var drizzle_default = defineAddon({
|
|
|
1520
1593
|
return generateCode();
|
|
1521
1594
|
});
|
|
1522
1595
|
},
|
|
1523
|
-
nextSteps: ({ options
|
|
1596
|
+
nextSteps: ({ options, packageManager, cwd }) => {
|
|
1524
1597
|
const steps = [];
|
|
1525
|
-
if (options
|
|
1526
|
-
const
|
|
1527
|
-
|
|
1528
|
-
|
|
1598
|
+
if (options.database === "d1") {
|
|
1599
|
+
const ext = fileExists(cwd, "wrangler.toml") ? "toml" : "jsonc";
|
|
1600
|
+
const { command, args } = resolveCommand(packageManager, "run", [
|
|
1601
|
+
"wrangler",
|
|
1602
|
+
"d1",
|
|
1603
|
+
"create",
|
|
1604
|
+
`<DATABASE_NAME>`
|
|
1605
|
+
]);
|
|
1606
|
+
steps.push(`Add your ${color.env("CLOUDFLARE_ACCOUNT_ID")}, ${color.env("CLOUDFLARE_DATABASE_ID")}, and ${color.env("CLOUDFLARE_D1_TOKEN")} to ${color.path(".env")}`);
|
|
1607
|
+
steps.push(`Run ${color.command(`${command} ${args.join(" ")}`)} to generate a D1 database ID for your ${color.path(`wrangler.${ext}`)}`);
|
|
1608
|
+
}
|
|
1609
|
+
if (options.docker) {
|
|
1610
|
+
const { command, args } = resolveCommand(packageManager, "run", ["db:start"]);
|
|
1611
|
+
steps.push(`Run ${color.command(`${command} ${args.join(" ")}`)} to start the docker container`);
|
|
1612
|
+
} else if (options.database !== "d1") steps.push(`Check ${color.env("DATABASE_URL")} in ${color.path(".env")} and adjust it to your needs`);
|
|
1529
1613
|
const { command, args } = resolveCommand(packageManager, "run", ["db:push"]);
|
|
1530
1614
|
steps.push(`Run ${color.command(`${command} ${args.join(" ")}`)} to update your database schema`);
|
|
1531
1615
|
return steps;
|
|
@@ -1533,6 +1617,16 @@ var drizzle_default = defineAddon({
|
|
|
1533
1617
|
});
|
|
1534
1618
|
function generateEnvFileContent(content, opts, isExample) {
|
|
1535
1619
|
const DB_URL_KEY = "DATABASE_URL";
|
|
1620
|
+
if (opts.database === "d1") {
|
|
1621
|
+
content = text.upsert(content, "CLOUDFLARE_ACCOUNT_ID", {
|
|
1622
|
+
value: "\"\"",
|
|
1623
|
+
comment: ["Cloudflare D1"],
|
|
1624
|
+
separator: true
|
|
1625
|
+
});
|
|
1626
|
+
content = text.upsert(content, "CLOUDFLARE_DATABASE_ID", { value: "\"\"" });
|
|
1627
|
+
content = text.upsert(content, "CLOUDFLARE_D1_TOKEN", { value: "\"\"" });
|
|
1628
|
+
return content;
|
|
1629
|
+
}
|
|
1536
1630
|
let value;
|
|
1537
1631
|
const comment = ["Drizzle"];
|
|
1538
1632
|
if (opts.docker) value = `"${opts.database === "mysql" ? "mysql" : "postgres"}://root:mysecretpassword@localhost:${PORTS[opts.database]}/local"`;
|
|
@@ -1565,7 +1659,6 @@ function generateEnvFileContent(content, opts, isExample) {
|
|
|
1565
1659
|
if (opts.sqlite === "turso") content = text.upsert(content, "DATABASE_AUTH_TOKEN", { value: isExample ? `""` : `"${crypto.randomUUID()}"` });
|
|
1566
1660
|
return content;
|
|
1567
1661
|
}
|
|
1568
|
-
|
|
1569
1662
|
//#endregion
|
|
1570
1663
|
//#region src/addons/eslint.ts
|
|
1571
1664
|
var eslint_default = defineAddon({
|
|
@@ -1576,13 +1669,13 @@ var eslint_default = defineAddon({
|
|
|
1576
1669
|
run: ({ sv, language, dependencyVersion, files }) => {
|
|
1577
1670
|
const typescript = language === "ts";
|
|
1578
1671
|
const prettierInstalled = Boolean(dependencyVersion("prettier"));
|
|
1579
|
-
sv.devDependency("eslint", "^
|
|
1580
|
-
sv.devDependency("@eslint/compat", "^2.0.
|
|
1581
|
-
sv.devDependency("eslint-plugin-svelte", "^3.
|
|
1582
|
-
sv.devDependency("globals", "^17.
|
|
1583
|
-
sv.devDependency("@eslint/js", "^
|
|
1672
|
+
sv.devDependency("eslint", "^10.0.3");
|
|
1673
|
+
sv.devDependency("@eslint/compat", "^2.0.3");
|
|
1674
|
+
sv.devDependency("eslint-plugin-svelte", "^3.15.2");
|
|
1675
|
+
sv.devDependency("globals", "^17.4.0");
|
|
1676
|
+
sv.devDependency("@eslint/js", "^10.0.1");
|
|
1584
1677
|
sv.devDependency("@types/node", getNodeTypesVersion());
|
|
1585
|
-
if (typescript) sv.devDependency("typescript-eslint", "^8.
|
|
1678
|
+
if (typescript) sv.devDependency("typescript-eslint", "^8.57.0");
|
|
1586
1679
|
if (prettierInstalled) sv.devDependency("eslint-config-prettier", "^10.1.8");
|
|
1587
1680
|
sv.file(files.package, (content) => {
|
|
1588
1681
|
const { data, generateCode } = parse.json(content);
|
|
@@ -1702,62 +1795,58 @@ var eslint_default = defineAddon({
|
|
|
1702
1795
|
if (prettierInstalled) sv.file(files.eslintConfig, addEslintConfigPrettier);
|
|
1703
1796
|
}
|
|
1704
1797
|
});
|
|
1705
|
-
|
|
1706
|
-
//#endregion
|
|
1707
|
-
//#region src/addons/mcp.ts
|
|
1708
|
-
const options$5 = defineAddonOptions().add("ide", {
|
|
1709
|
-
question: "Which client would you like to use?",
|
|
1710
|
-
type: "multiselect",
|
|
1711
|
-
default: [],
|
|
1712
|
-
options: [
|
|
1713
|
-
{
|
|
1714
|
-
value: "claude-code",
|
|
1715
|
-
label: "claude code"
|
|
1716
|
-
},
|
|
1717
|
-
{
|
|
1718
|
-
value: "cursor",
|
|
1719
|
-
label: "Cursor"
|
|
1720
|
-
},
|
|
1721
|
-
{
|
|
1722
|
-
value: "gemini",
|
|
1723
|
-
label: "Gemini"
|
|
1724
|
-
},
|
|
1725
|
-
{
|
|
1726
|
-
value: "opencode",
|
|
1727
|
-
label: "opencode"
|
|
1728
|
-
},
|
|
1729
|
-
{
|
|
1730
|
-
value: "vscode",
|
|
1731
|
-
label: "VSCode"
|
|
1732
|
-
},
|
|
1733
|
-
{
|
|
1734
|
-
value: "other",
|
|
1735
|
-
label: "Other"
|
|
1736
|
-
}
|
|
1737
|
-
],
|
|
1738
|
-
required: true
|
|
1739
|
-
}).add("setup", {
|
|
1740
|
-
question: "What setup would you like to use?",
|
|
1741
|
-
type: "select",
|
|
1742
|
-
default: "remote",
|
|
1743
|
-
options: [{
|
|
1744
|
-
value: "local",
|
|
1745
|
-
label: "Local",
|
|
1746
|
-
hint: "will use stdio"
|
|
1747
|
-
}, {
|
|
1748
|
-
value: "remote",
|
|
1749
|
-
label: "Remote",
|
|
1750
|
-
hint: "will use a remote endpoint"
|
|
1751
|
-
}],
|
|
1752
|
-
required: true,
|
|
1753
|
-
condition: ({ ide }) => !(ide.length === 1 && ide.includes("opencode"))
|
|
1754
|
-
}).build();
|
|
1755
1798
|
var mcp_default = defineAddon({
|
|
1756
1799
|
id: "mcp",
|
|
1757
1800
|
shortDescription: "Svelte MCP",
|
|
1758
1801
|
homepage: "https://svelte.dev/docs/mcp",
|
|
1759
|
-
options:
|
|
1760
|
-
|
|
1802
|
+
options: defineAddonOptions().add("ide", {
|
|
1803
|
+
question: "Which client would you like to use?",
|
|
1804
|
+
type: "multiselect",
|
|
1805
|
+
default: [],
|
|
1806
|
+
options: [
|
|
1807
|
+
{
|
|
1808
|
+
value: "claude-code",
|
|
1809
|
+
label: "claude code"
|
|
1810
|
+
},
|
|
1811
|
+
{
|
|
1812
|
+
value: "cursor",
|
|
1813
|
+
label: "Cursor"
|
|
1814
|
+
},
|
|
1815
|
+
{
|
|
1816
|
+
value: "gemini",
|
|
1817
|
+
label: "Gemini"
|
|
1818
|
+
},
|
|
1819
|
+
{
|
|
1820
|
+
value: "opencode",
|
|
1821
|
+
label: "opencode"
|
|
1822
|
+
},
|
|
1823
|
+
{
|
|
1824
|
+
value: "vscode",
|
|
1825
|
+
label: "VSCode"
|
|
1826
|
+
},
|
|
1827
|
+
{
|
|
1828
|
+
value: "other",
|
|
1829
|
+
label: "Other"
|
|
1830
|
+
}
|
|
1831
|
+
],
|
|
1832
|
+
required: true
|
|
1833
|
+
}).add("setup", {
|
|
1834
|
+
question: "What setup would you like to use?",
|
|
1835
|
+
type: "select",
|
|
1836
|
+
default: "remote",
|
|
1837
|
+
options: [{
|
|
1838
|
+
value: "local",
|
|
1839
|
+
label: "Local",
|
|
1840
|
+
hint: "will use stdio"
|
|
1841
|
+
}, {
|
|
1842
|
+
value: "remote",
|
|
1843
|
+
label: "Remote",
|
|
1844
|
+
hint: "will use a remote endpoint"
|
|
1845
|
+
}],
|
|
1846
|
+
required: true,
|
|
1847
|
+
condition: ({ ide }) => !(ide.length === 1 && ide.includes("opencode"))
|
|
1848
|
+
}).build(),
|
|
1849
|
+
run: ({ sv, options }) => {
|
|
1761
1850
|
const getLocalConfig = (o) => {
|
|
1762
1851
|
return {
|
|
1763
1852
|
...o?.typeLocal ? { type: o.typeLocal } : {},
|
|
@@ -1813,7 +1902,7 @@ var mcp_default = defineAddon({
|
|
|
1813
1902
|
const filesAdded = [];
|
|
1814
1903
|
const filesExistingAlready = [];
|
|
1815
1904
|
const agentFile = getSharedFiles().filter((file) => file.include.includes("mcp")).find((file) => file.name === "AGENTS.md");
|
|
1816
|
-
for (const ide of options
|
|
1905
|
+
for (const ide of options.ide) {
|
|
1817
1906
|
const value = configurator[ide];
|
|
1818
1907
|
if (value === void 0) continue;
|
|
1819
1908
|
if ("other" in value) continue;
|
|
@@ -1829,29 +1918,28 @@ var mcp_default = defineAddon({
|
|
|
1829
1918
|
sv.file(configPath, (content) => {
|
|
1830
1919
|
const { data, generateCode } = parse.json(content);
|
|
1831
1920
|
if (schema) data["$schema"] = schema;
|
|
1832
|
-
if (customData) for (const [key, value
|
|
1921
|
+
if (customData) for (const [key, value] of Object.entries(customData)) data[key] = value;
|
|
1833
1922
|
if (mcpOptions) {
|
|
1834
1923
|
const key = mcpOptions.serversKey ?? "mcpServers";
|
|
1835
1924
|
data[key] ??= {};
|
|
1836
|
-
data[key].svelte = options
|
|
1925
|
+
data[key].svelte = options.setup === "local" ? getLocalConfig(mcpOptions) : getRemoteConfig(mcpOptions);
|
|
1837
1926
|
}
|
|
1838
1927
|
return generateCode();
|
|
1839
1928
|
});
|
|
1840
1929
|
if (extraFiles) for (const extra of extraFiles) sv.file(extra.path, (content) => {
|
|
1841
1930
|
const { data, generateCode } = parse.json(content);
|
|
1842
|
-
for (const [key, value
|
|
1931
|
+
for (const [key, value] of Object.entries(extra.data)) data[key] = value;
|
|
1843
1932
|
return generateCode();
|
|
1844
1933
|
});
|
|
1845
1934
|
}
|
|
1846
|
-
if (filesExistingAlready.length > 0) R.warn(`${filesExistingAlready.map((path
|
|
1935
|
+
if (filesExistingAlready.length > 0) R.warn(`${filesExistingAlready.map((path) => color.path(path)).join(", ")} already exists, we didn't touch ${filesExistingAlready.length > 1 ? "them" : "it"}. See ${color.website("https://svelte.dev/docs/mcp/overview#Usage")} for manual setup.`);
|
|
1847
1936
|
},
|
|
1848
|
-
nextSteps({ options
|
|
1937
|
+
nextSteps({ options }) {
|
|
1849
1938
|
const steps = [];
|
|
1850
|
-
if (options
|
|
1939
|
+
if (options.ide.includes("other")) steps.push(`For other clients: ${color.website(`https://svelte.dev/docs/mcp/${options.setup}-setup#Other-clients`)}`);
|
|
1851
1940
|
return steps;
|
|
1852
1941
|
}
|
|
1853
1942
|
});
|
|
1854
|
-
|
|
1855
1943
|
//#endregion
|
|
1856
1944
|
//#region src/addons/mdsvex.ts
|
|
1857
1945
|
var mdsvex_default = defineAddon({
|
|
@@ -1882,6 +1970,7 @@ var mdsvex_default = defineAddon({
|
|
|
1882
1970
|
name: "mdsvex",
|
|
1883
1971
|
args: []
|
|
1884
1972
|
});
|
|
1973
|
+
mdsvexCall.arguments.push(js.object.create({ extensions: [".svx", ".md"] }));
|
|
1885
1974
|
js.array.append(preprocessorArray, mdsvexCall);
|
|
1886
1975
|
const extensionsArray = js.object.property(exportDefault, {
|
|
1887
1976
|
name: "extensions",
|
|
@@ -1889,11 +1978,11 @@ var mdsvex_default = defineAddon({
|
|
|
1889
1978
|
});
|
|
1890
1979
|
js.array.append(extensionsArray, ".svelte");
|
|
1891
1980
|
js.array.append(extensionsArray, ".svx");
|
|
1981
|
+
js.array.append(extensionsArray, ".md");
|
|
1892
1982
|
return generateCode();
|
|
1893
1983
|
});
|
|
1894
1984
|
}
|
|
1895
1985
|
});
|
|
1896
|
-
|
|
1897
1986
|
//#endregion
|
|
1898
1987
|
//#region src/addons/paraglide.ts
|
|
1899
1988
|
const DEFAULT_INLANG_PROJECT = {
|
|
@@ -1928,7 +2017,7 @@ var paraglide_default = defineAddon({
|
|
|
1928
2017
|
setup: ({ kit, unsupported }) => {
|
|
1929
2018
|
if (!kit) unsupported("Requires SvelteKit");
|
|
1930
2019
|
},
|
|
1931
|
-
run: ({ sv, options
|
|
2020
|
+
run: ({ sv, options, files, language, kit }) => {
|
|
1932
2021
|
if (!kit) throw new Error("SvelteKit is required");
|
|
1933
2022
|
const paraglideOutDir = "src/lib/paraglide";
|
|
1934
2023
|
sv.devDependency("@inlang/paraglide-js", "^2.10.0");
|
|
@@ -2007,9 +2096,9 @@ var paraglide_default = defineAddon({
|
|
|
2007
2096
|
if (content) return content;
|
|
2008
2097
|
const { data, generateCode } = parse.json(content);
|
|
2009
2098
|
for (const key in DEFAULT_INLANG_PROJECT) data[key] = DEFAULT_INLANG_PROJECT[key];
|
|
2010
|
-
const { validLanguageTags
|
|
2011
|
-
data.baseLocale = validLanguageTags
|
|
2012
|
-
data.locales = validLanguageTags
|
|
2099
|
+
const { validLanguageTags } = parseLanguageTagInput(options.languageTags);
|
|
2100
|
+
data.baseLocale = validLanguageTags[0];
|
|
2101
|
+
data.locales = validLanguageTags;
|
|
2013
2102
|
return generateCode();
|
|
2014
2103
|
});
|
|
2015
2104
|
sv.file(`${kit.routesDirectory}/+layout.svelte`, (content) => {
|
|
@@ -2030,7 +2119,7 @@ var paraglide_default = defineAddon({
|
|
|
2030
2119
|
</div>`);
|
|
2031
2120
|
return generateCode();
|
|
2032
2121
|
});
|
|
2033
|
-
if (options
|
|
2122
|
+
if (options.demo) {
|
|
2034
2123
|
sv.file(`${kit.routesDirectory}/demo/+page.svelte`, (content) => {
|
|
2035
2124
|
return addToDemoPage(content, "paraglide", language);
|
|
2036
2125
|
});
|
|
@@ -2046,15 +2135,15 @@ var paraglide_default = defineAddon({
|
|
|
2046
2135
|
from: "$lib/paraglide/runtime"
|
|
2047
2136
|
});
|
|
2048
2137
|
let templateCode = "<h1>{m.hello_world({ name: 'SvelteKit User' })}</h1>";
|
|
2049
|
-
const { validLanguageTags
|
|
2050
|
-
const links = validLanguageTags
|
|
2138
|
+
const { validLanguageTags } = parseLanguageTagInput(options.languageTags);
|
|
2139
|
+
const links = validLanguageTags.map((x) => `<button onclick={() => setLocale('${x}')}>${x}</button>`).join("");
|
|
2051
2140
|
templateCode += `<div>${links}</div>`;
|
|
2052
2141
|
templateCode += "<p>If 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.</p>";
|
|
2053
2142
|
svelte.addFragment(ast, templateCode);
|
|
2054
2143
|
return generateCode();
|
|
2055
2144
|
});
|
|
2056
2145
|
}
|
|
2057
|
-
const { validLanguageTags } = parseLanguageTagInput(options
|
|
2146
|
+
const { validLanguageTags } = parseLanguageTagInput(options.languageTags);
|
|
2058
2147
|
for (const languageTag of validLanguageTags) sv.file(`messages/${languageTag}.json`, (content) => {
|
|
2059
2148
|
const { data, generateCode } = parse.json(content);
|
|
2060
2149
|
data["$schema"] = "https://inlang.com/schema/inlang-message-format";
|
|
@@ -2080,7 +2169,6 @@ function parseLanguageTagInput(input) {
|
|
|
2080
2169
|
invalidLanguageTags
|
|
2081
2170
|
};
|
|
2082
2171
|
}
|
|
2083
|
-
|
|
2084
2172
|
//#endregion
|
|
2085
2173
|
//#region src/addons/playwright.ts
|
|
2086
2174
|
var playwright_default = defineAddon({
|
|
@@ -2154,7 +2242,6 @@ var playwright_default = defineAddon({
|
|
|
2154
2242
|
return steps;
|
|
2155
2243
|
}
|
|
2156
2244
|
});
|
|
2157
|
-
|
|
2158
2245
|
//#endregion
|
|
2159
2246
|
//#region src/addons/prettier.ts
|
|
2160
2247
|
var prettier_default = defineAddon({
|
|
@@ -2229,10 +2316,9 @@ var prettier_default = defineAddon({
|
|
|
2229
2316
|
}
|
|
2230
2317
|
});
|
|
2231
2318
|
const SUPPORTED_ESLINT_VERSION = "9";
|
|
2232
|
-
function hasEslint(version
|
|
2233
|
-
return !!version
|
|
2319
|
+
function hasEslint(version) {
|
|
2320
|
+
return !!version && version.startsWith(SUPPORTED_ESLINT_VERSION);
|
|
2234
2321
|
}
|
|
2235
|
-
|
|
2236
2322
|
//#endregion
|
|
2237
2323
|
//#region src/addons/storybook.ts
|
|
2238
2324
|
var storybook_default = defineAddon({
|
|
@@ -2255,7 +2341,6 @@ var storybook_default = defineAddon({
|
|
|
2255
2341
|
sv.devDependency(`@types/node`, getNodeTypesVersion());
|
|
2256
2342
|
}
|
|
2257
2343
|
});
|
|
2258
|
-
|
|
2259
2344
|
//#endregion
|
|
2260
2345
|
//#region src/addons/sveltekit-adapter.ts
|
|
2261
2346
|
const adapters = [
|
|
@@ -2290,46 +2375,45 @@ const adapters = [
|
|
|
2290
2375
|
version: "^5.2.4"
|
|
2291
2376
|
}
|
|
2292
2377
|
];
|
|
2293
|
-
const options$3 = defineAddonOptions().add("adapter", {
|
|
2294
|
-
type: "select",
|
|
2295
|
-
question: "Which SvelteKit adapter would you like to use?",
|
|
2296
|
-
default: "auto",
|
|
2297
|
-
options: adapters.map((p) => ({
|
|
2298
|
-
value: p.id,
|
|
2299
|
-
label: p.id,
|
|
2300
|
-
hint: p.package
|
|
2301
|
-
}))
|
|
2302
|
-
}).add("cfTarget", {
|
|
2303
|
-
condition: (options$8) => options$8.adapter === "cloudflare",
|
|
2304
|
-
type: "select",
|
|
2305
|
-
question: "Are you deploying to Workers (assets) or Pages?",
|
|
2306
|
-
default: "workers",
|
|
2307
|
-
options: [{
|
|
2308
|
-
value: "workers",
|
|
2309
|
-
label: "Workers",
|
|
2310
|
-
hint: "Recommended way to deploy to Cloudflare"
|
|
2311
|
-
}, {
|
|
2312
|
-
value: "pages",
|
|
2313
|
-
label: "Pages"
|
|
2314
|
-
}]
|
|
2315
|
-
}).build();
|
|
2316
2378
|
var sveltekit_adapter_default = defineAddon({
|
|
2317
2379
|
id: "sveltekit-adapter",
|
|
2318
2380
|
alias: "adapter",
|
|
2319
2381
|
shortDescription: "deployment",
|
|
2320
2382
|
homepage: "https://svelte.dev/docs/kit/adapters",
|
|
2321
|
-
options:
|
|
2383
|
+
options: defineAddonOptions().add("adapter", {
|
|
2384
|
+
type: "select",
|
|
2385
|
+
question: "Which SvelteKit adapter would you like to use?",
|
|
2386
|
+
default: "auto",
|
|
2387
|
+
options: adapters.map((p) => ({
|
|
2388
|
+
value: p.id,
|
|
2389
|
+
label: p.id,
|
|
2390
|
+
hint: p.package
|
|
2391
|
+
}))
|
|
2392
|
+
}).add("cfTarget", {
|
|
2393
|
+
condition: (options) => options.adapter === "cloudflare",
|
|
2394
|
+
type: "select",
|
|
2395
|
+
question: "Are you deploying to Workers (assets) or Pages?",
|
|
2396
|
+
default: "workers",
|
|
2397
|
+
options: [{
|
|
2398
|
+
value: "workers",
|
|
2399
|
+
label: "Workers",
|
|
2400
|
+
hint: "Recommended way to deploy to Cloudflare"
|
|
2401
|
+
}, {
|
|
2402
|
+
value: "pages",
|
|
2403
|
+
label: "Pages"
|
|
2404
|
+
}]
|
|
2405
|
+
}).build(),
|
|
2322
2406
|
setup: ({ kit, unsupported }) => {
|
|
2323
2407
|
if (!kit) unsupported("Requires SvelteKit");
|
|
2324
2408
|
},
|
|
2325
|
-
run: ({ sv, options
|
|
2326
|
-
const adapter = adapters.find((a) => a.id === options
|
|
2409
|
+
run: ({ sv, options, files, cwd, language }) => {
|
|
2410
|
+
const adapter = adapters.find((a) => a.id === options.adapter);
|
|
2327
2411
|
sv.file(files.package, (content) => {
|
|
2328
2412
|
const { data, generateCode } = parse.json(content);
|
|
2329
2413
|
const devDeps = data["devDependencies"];
|
|
2330
2414
|
for (const pkg of Object.keys(devDeps)) if (pkg.startsWith("@sveltejs/adapter-")) delete devDeps[pkg];
|
|
2331
|
-
if (options
|
|
2332
|
-
const preview = options
|
|
2415
|
+
if (options.adapter === "cloudflare") {
|
|
2416
|
+
const preview = options.cfTarget === "workers" ? "wrangler dev .svelte-kit/cloudflare/_worker.js --port 4173" : "wrangler pages dev .svelte-kit/cloudflare --port 4173";
|
|
2333
2417
|
data.scripts.preview = preview;
|
|
2334
2418
|
}
|
|
2335
2419
|
return generateCode();
|
|
@@ -2365,15 +2449,15 @@ var sveltekit_adapter_default = defineAddon({
|
|
|
2365
2449
|
});
|
|
2366
2450
|
if (adapter.package === "@sveltejs/adapter-cloudflare") {
|
|
2367
2451
|
sv.devDependency("wrangler", "^4.63.0");
|
|
2368
|
-
const
|
|
2369
|
-
sv.file(`wrangler.${
|
|
2370
|
-
const { data, generateCode } =
|
|
2371
|
-
if (
|
|
2372
|
-
if (!data.name) data.name = sanitizeName(parse.json(readFileSync(join(cwd
|
|
2452
|
+
const ext = fileExists(cwd, "wrangler.toml") ? "toml" : "jsonc";
|
|
2453
|
+
sv.file(`wrangler.${ext}`, (content) => {
|
|
2454
|
+
const { data, generateCode } = ext === "jsonc" ? parse.json(content) : parse.toml(content);
|
|
2455
|
+
if (ext === "jsonc") data.$schema ??= "./node_modules/wrangler/config-schema.json";
|
|
2456
|
+
if (!data.name) data.name = sanitizeName(parse.json(readFileSync(join(cwd, files.package), "utf-8")).data.name, "wrangler");
|
|
2373
2457
|
data.compatibility_date ??= (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
2374
2458
|
data.compatibility_flags ??= [];
|
|
2375
2459
|
if (!data.compatibility_flags.includes("nodejs_compat") && !data.compatibility_flags.includes("nodejs_als")) data.compatibility_flags.push("nodejs_als");
|
|
2376
|
-
switch (options
|
|
2460
|
+
switch (options.cfTarget) {
|
|
2377
2461
|
case "workers":
|
|
2378
2462
|
data.main = ".svelte-kit/cloudflare/_worker.js";
|
|
2379
2463
|
data.assets ??= {};
|
|
@@ -2388,7 +2472,7 @@ var sveltekit_adapter_default = defineAddon({
|
|
|
2388
2472
|
}
|
|
2389
2473
|
return generateCode();
|
|
2390
2474
|
});
|
|
2391
|
-
const jsconfig = fileExists(cwd
|
|
2475
|
+
const jsconfig = fileExists(cwd, "jsconfig.json");
|
|
2392
2476
|
if (language === "ts" || jsconfig) {
|
|
2393
2477
|
sv.file(files.gitignore, (content) => {
|
|
2394
2478
|
if (content.length === 0) return content;
|
|
@@ -2408,25 +2492,24 @@ var sveltekit_adapter_default = defineAddon({
|
|
|
2408
2492
|
});
|
|
2409
2493
|
sv.file("src/app.d.ts", (content) => {
|
|
2410
2494
|
const { ast, comments, generateCode } = parse.script(content);
|
|
2411
|
-
const platform
|
|
2412
|
-
if (!platform
|
|
2495
|
+
const platform = js.kit.addGlobalAppInterface(ast, { name: "Platform" });
|
|
2496
|
+
if (!platform) throw new Error("Failed detecting `platform` interface in `src/app.d.ts`");
|
|
2413
2497
|
comments.remove((c) => c.type === "Line" && c.value.trim() === "interface Platform {}");
|
|
2414
|
-
platform
|
|
2498
|
+
platform.body.body.push(js.common.createTypeProperty("env", "Env"), js.common.createTypeProperty("ctx", "ExecutionContext"), js.common.createTypeProperty("caches", "CacheStorage"), js.common.createTypeProperty("cf", "IncomingRequestCfProperties", true));
|
|
2415
2499
|
return generateCode();
|
|
2416
2500
|
});
|
|
2417
2501
|
}
|
|
2418
2502
|
}
|
|
2419
2503
|
},
|
|
2420
|
-
nextSteps({ options
|
|
2421
|
-
const
|
|
2422
|
-
if (options
|
|
2504
|
+
nextSteps({ options, packageManager }) {
|
|
2505
|
+
const steps = [];
|
|
2506
|
+
if (options.adapter === "cloudflare") {
|
|
2423
2507
|
const { command, args } = resolveCommand(packageManager, "run", ["gen"]);
|
|
2424
|
-
|
|
2508
|
+
steps.push(`Run ${color.command(`${command} ${args.join(" ")}`)} to update ${color.addon("cloudflare")} types`);
|
|
2425
2509
|
}
|
|
2426
|
-
return
|
|
2510
|
+
return steps;
|
|
2427
2511
|
}
|
|
2428
2512
|
});
|
|
2429
|
-
|
|
2430
2513
|
//#endregion
|
|
2431
2514
|
//#region src/addons/tailwindcss.ts
|
|
2432
2515
|
const plugins = [{
|
|
@@ -2438,31 +2521,30 @@ const plugins = [{
|
|
|
2438
2521
|
package: "@tailwindcss/forms",
|
|
2439
2522
|
version: "^0.5.11"
|
|
2440
2523
|
}];
|
|
2441
|
-
const options$2 = defineAddonOptions().add("plugins", {
|
|
2442
|
-
type: "multiselect",
|
|
2443
|
-
question: "Which plugins would you like to add?",
|
|
2444
|
-
options: plugins.map((p) => ({
|
|
2445
|
-
value: p.id,
|
|
2446
|
-
label: p.id,
|
|
2447
|
-
hint: p.package
|
|
2448
|
-
})),
|
|
2449
|
-
default: [],
|
|
2450
|
-
required: false
|
|
2451
|
-
}).build();
|
|
2452
2524
|
var tailwindcss_default = defineAddon({
|
|
2453
2525
|
id: "tailwindcss",
|
|
2454
2526
|
alias: "tailwind",
|
|
2455
2527
|
shortDescription: "css framework",
|
|
2456
2528
|
homepage: "https://tailwindcss.com",
|
|
2457
|
-
options:
|
|
2458
|
-
|
|
2529
|
+
options: defineAddonOptions().add("plugins", {
|
|
2530
|
+
type: "multiselect",
|
|
2531
|
+
question: "Which plugins would you like to add?",
|
|
2532
|
+
options: plugins.map((p) => ({
|
|
2533
|
+
value: p.id,
|
|
2534
|
+
label: p.id,
|
|
2535
|
+
hint: p.package
|
|
2536
|
+
})),
|
|
2537
|
+
default: [],
|
|
2538
|
+
required: false
|
|
2539
|
+
}).build(),
|
|
2540
|
+
run: ({ sv, options, files, kit, dependencyVersion, language }) => {
|
|
2459
2541
|
const prettierInstalled = Boolean(dependencyVersion("prettier"));
|
|
2460
2542
|
sv.devDependency("tailwindcss", "^4.1.18");
|
|
2461
2543
|
sv.devDependency("@tailwindcss/vite", "^4.1.18");
|
|
2462
2544
|
sv.pnpmBuildDependency("@tailwindcss/oxide");
|
|
2463
2545
|
if (prettierInstalled) sv.devDependency("prettier-plugin-tailwindcss", "^0.7.2");
|
|
2464
2546
|
for (const plugin of plugins) {
|
|
2465
|
-
if (!options
|
|
2547
|
+
if (!options.plugins.includes(plugin.id)) continue;
|
|
2466
2548
|
sv.devDependency(plugin.package, plugin.version);
|
|
2467
2549
|
}
|
|
2468
2550
|
sv.file(files.viteConfig, (content) => {
|
|
@@ -2481,7 +2563,7 @@ var tailwindcss_default = defineAddon({
|
|
|
2481
2563
|
sv.file(files.stylesheet, (content) => {
|
|
2482
2564
|
const { ast, generateCode } = parse.css(content);
|
|
2483
2565
|
for (const plugin of plugins) {
|
|
2484
|
-
if (!options
|
|
2566
|
+
if (!options.plugins.includes(plugin.id)) continue;
|
|
2485
2567
|
css.addAtRule(ast, {
|
|
2486
2568
|
name: "plugin",
|
|
2487
2569
|
params: `'${plugin.package}'`,
|
|
@@ -2544,9 +2626,9 @@ var tailwindcss_default = defineAddon({
|
|
|
2544
2626
|
});
|
|
2545
2627
|
}
|
|
2546
2628
|
});
|
|
2547
|
-
|
|
2548
2629
|
//#endregion
|
|
2549
2630
|
//#region src/addons/vitest-addon.ts
|
|
2631
|
+
var _templateObject;
|
|
2550
2632
|
const options$1 = defineAddonOptions().add("usages", {
|
|
2551
2633
|
question: "What do you want to use vitest for?",
|
|
2552
2634
|
type: "multiselect",
|
|
@@ -2561,40 +2643,45 @@ const options$1 = defineAddonOptions().add("usages", {
|
|
|
2561
2643
|
required: true
|
|
2562
2644
|
}).build();
|
|
2563
2645
|
let vitestV3Installed = false;
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2646
|
+
//#endregion
|
|
2647
|
+
//#region src/addons/index.ts
|
|
2648
|
+
const officialAddons$1 = {
|
|
2649
|
+
prettier: prettier_default,
|
|
2650
|
+
eslint: eslint_default,
|
|
2651
|
+
vitest: defineAddon({
|
|
2652
|
+
id: "vitest",
|
|
2653
|
+
shortDescription: "unit testing",
|
|
2654
|
+
homepage: "https://vitest.dev",
|
|
2655
|
+
options: options$1,
|
|
2656
|
+
run: ({ sv, files, language, kit, options, dependencyVersion }) => {
|
|
2657
|
+
const unitTesting = options.usages.includes("unit");
|
|
2658
|
+
const componentTesting = options.usages.includes("component");
|
|
2659
|
+
vitestV3Installed = (dependencyVersion("vitest") ?? "").replaceAll("^", "").replaceAll("~", "")?.startsWith("3.");
|
|
2660
|
+
sv.devDependency("vitest", "^4.1.0");
|
|
2661
|
+
if (componentTesting) {
|
|
2662
|
+
sv.devDependency("@vitest/browser-playwright", "^4.1.0");
|
|
2663
|
+
sv.devDependency("vitest-browser-svelte", "^2.0.2");
|
|
2664
|
+
sv.devDependency("playwright", "^1.58.2");
|
|
2665
|
+
}
|
|
2666
|
+
sv.file(files.package, (content) => {
|
|
2667
|
+
const { data, generateCode } = parse.json(content);
|
|
2668
|
+
json.packageScriptsUpsert(data, "test:unit", "vitest");
|
|
2669
|
+
json.packageScriptsUpsert(data, "test", "npm run test:unit -- --run", { mode: "prepend" });
|
|
2670
|
+
return generateCode();
|
|
2671
|
+
});
|
|
2672
|
+
const examplesDir = (kit ? kit.libDirectory : "src/lib") + "/vitest-examples";
|
|
2673
|
+
const typed = language === "ts";
|
|
2674
|
+
if (unitTesting || componentTesting) sv.file(`${examplesDir}/greet.${language}`, (content) => {
|
|
2675
|
+
if (content) return content;
|
|
2676
|
+
return dedent`
|
|
2590
2677
|
export function greet(${typed ? "name: string" : "name"})${typed ? ": string" : ""} {
|
|
2591
2678
|
return 'Hello, ' + name + '!';
|
|
2592
2679
|
}
|
|
2593
2680
|
`;
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2681
|
+
});
|
|
2682
|
+
if (unitTesting) sv.file(`${examplesDir}/greet.spec.${language}`, (content) => {
|
|
2683
|
+
if (content) return content;
|
|
2684
|
+
return dedent`
|
|
2598
2685
|
import { describe, it, expect } from 'vitest';
|
|
2599
2686
|
import { greet } from './greet';
|
|
2600
2687
|
|
|
@@ -2604,24 +2691,15 @@ var vitest_addon_default = defineAddon({
|
|
|
2604
2691
|
});
|
|
2605
2692
|
});
|
|
2606
2693
|
`;
|
|
2607
|
-
});
|
|
2608
|
-
if (componentTesting) {
|
|
2609
|
-
sv.file(`${examplesDir}/Welcome.svelte`, (content) => {
|
|
2610
|
-
if (content) return content;
|
|
2611
|
-
return dedent`
|
|
2612
|
-
<script>
|
|
2613
|
-
import { greet } from './greet';
|
|
2614
|
-
|
|
2615
|
-
let { host = 'SvelteKit', guest = 'Vitest' } = $props();
|
|
2616
|
-
<\/script>
|
|
2617
|
-
|
|
2618
|
-
<h1>{greet(host)}</h1>
|
|
2619
|
-
<p>{greet(guest)}</p>
|
|
2620
|
-
`;
|
|
2621
2694
|
});
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2695
|
+
if (componentTesting) {
|
|
2696
|
+
sv.file(`${examplesDir}/Welcome.svelte`, (content) => {
|
|
2697
|
+
if (content) return content;
|
|
2698
|
+
return dedent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n <script>\n import { greet } from './greet';\n\n let { host = 'SvelteKit', guest = 'Vitest' } = $props();\n <\/script>\n\n <h1>{greet(host)}</h1>\n <p>{greet(guest)}</p>\n "])));
|
|
2699
|
+
});
|
|
2700
|
+
sv.file(`${examplesDir}/Welcome.svelte.spec.${language}`, (content) => {
|
|
2701
|
+
if (content) return content;
|
|
2702
|
+
return dedent`
|
|
2625
2703
|
import { page } from 'vitest/browser';
|
|
2626
2704
|
import { describe, expect, it } from 'vitest';
|
|
2627
2705
|
import { render } from 'vitest-browser-svelte';
|
|
@@ -2636,92 +2714,85 @@ var vitest_addon_default = defineAddon({
|
|
|
2636
2714
|
});
|
|
2637
2715
|
});
|
|
2638
2716
|
`;
|
|
2639
|
-
});
|
|
2640
|
-
}
|
|
2641
|
-
sv.file(files.viteConfig, (content) => {
|
|
2642
|
-
const { ast, generateCode } = parse.script(content);
|
|
2643
|
-
const clientObjectExpression = js.object.create({
|
|
2644
|
-
extends: `./${files.viteConfig}`,
|
|
2645
|
-
test: {
|
|
2646
|
-
name: "client",
|
|
2647
|
-
browser: {
|
|
2648
|
-
enabled: true,
|
|
2649
|
-
provider: js.functions.createCall({
|
|
2650
|
-
name: "playwright",
|
|
2651
|
-
args: []
|
|
2652
|
-
}),
|
|
2653
|
-
instances: [{
|
|
2654
|
-
browser: "chromium",
|
|
2655
|
-
headless: true
|
|
2656
|
-
}]
|
|
2657
|
-
},
|
|
2658
|
-
include: ["src/**/*.svelte.{test,spec}.{js,ts}"],
|
|
2659
|
-
exclude: ["src/lib/server/**"]
|
|
2660
|
-
}
|
|
2661
|
-
});
|
|
2662
|
-
const serverObjectExpression = js.object.create({
|
|
2663
|
-
extends: `./${files.viteConfig}`,
|
|
2664
|
-
test: {
|
|
2665
|
-
name: "server",
|
|
2666
|
-
environment: "node",
|
|
2667
|
-
include: ["src/**/*.{test,spec}.{js,ts}"],
|
|
2668
|
-
exclude: ["src/**/*.svelte.{test,spec}.{js,ts}"]
|
|
2669
|
-
}
|
|
2670
|
-
});
|
|
2671
|
-
const viteConfig = js.vite.getConfig(ast);
|
|
2672
|
-
const testObject = js.object.property(viteConfig, {
|
|
2673
|
-
name: "test",
|
|
2674
|
-
fallback: js.object.create({ expect: { requireAssertions: true } })
|
|
2675
|
-
});
|
|
2676
|
-
const workspaceArray = js.object.property(testObject, {
|
|
2677
|
-
name: "projects",
|
|
2678
|
-
fallback: js.array.create()
|
|
2679
|
-
});
|
|
2680
|
-
if (componentTesting) js.array.append(workspaceArray, clientObjectExpression);
|
|
2681
|
-
if (unitTesting) js.array.append(workspaceArray, serverObjectExpression);
|
|
2682
|
-
if (componentTesting) js.imports.addNamed(ast, {
|
|
2683
|
-
imports: ["playwright"],
|
|
2684
|
-
from: "@vitest/browser-playwright"
|
|
2685
|
-
});
|
|
2686
|
-
const importName = "defineConfig";
|
|
2687
|
-
const { statement, alias } = js.imports.find(ast, {
|
|
2688
|
-
name: importName,
|
|
2689
|
-
from: "vite"
|
|
2690
|
-
});
|
|
2691
|
-
if (statement) {
|
|
2692
|
-
js.imports.addNamed(ast, {
|
|
2693
|
-
imports: { defineConfig: alias },
|
|
2694
|
-
from: "vitest/config"
|
|
2695
2717
|
});
|
|
2696
|
-
|
|
2718
|
+
}
|
|
2719
|
+
sv.file(files.viteConfig, (content) => {
|
|
2720
|
+
const { ast, generateCode } = parse.script(content);
|
|
2721
|
+
const clientObjectExpression = js.object.create({
|
|
2722
|
+
extends: `./${files.viteConfig}`,
|
|
2723
|
+
test: {
|
|
2724
|
+
name: "client",
|
|
2725
|
+
browser: {
|
|
2726
|
+
enabled: true,
|
|
2727
|
+
provider: js.functions.createCall({
|
|
2728
|
+
name: "playwright",
|
|
2729
|
+
args: []
|
|
2730
|
+
}),
|
|
2731
|
+
instances: [{
|
|
2732
|
+
browser: "chromium",
|
|
2733
|
+
headless: true
|
|
2734
|
+
}]
|
|
2735
|
+
},
|
|
2736
|
+
include: ["src/**/*.svelte.{test,spec}.{js,ts}"],
|
|
2737
|
+
exclude: ["src/lib/server/**"]
|
|
2738
|
+
}
|
|
2739
|
+
});
|
|
2740
|
+
const serverObjectExpression = js.object.create({
|
|
2741
|
+
extends: `./${files.viteConfig}`,
|
|
2742
|
+
test: {
|
|
2743
|
+
name: "server",
|
|
2744
|
+
environment: "node",
|
|
2745
|
+
include: ["src/**/*.{test,spec}.{js,ts}"],
|
|
2746
|
+
exclude: ["src/**/*.svelte.{test,spec}.{js,ts}"]
|
|
2747
|
+
}
|
|
2748
|
+
});
|
|
2749
|
+
const viteConfig = js.vite.getConfig(ast);
|
|
2750
|
+
const testObject = js.object.property(viteConfig, {
|
|
2751
|
+
name: "test",
|
|
2752
|
+
fallback: js.object.create({ expect: { requireAssertions: true } })
|
|
2753
|
+
});
|
|
2754
|
+
const workspaceArray = js.object.property(testObject, {
|
|
2755
|
+
name: "projects",
|
|
2756
|
+
fallback: js.array.create()
|
|
2757
|
+
});
|
|
2758
|
+
if (componentTesting) js.array.append(workspaceArray, clientObjectExpression);
|
|
2759
|
+
if (unitTesting) js.array.append(workspaceArray, serverObjectExpression);
|
|
2760
|
+
if (componentTesting) js.imports.addNamed(ast, {
|
|
2761
|
+
imports: ["playwright"],
|
|
2762
|
+
from: "@vitest/browser-playwright"
|
|
2763
|
+
});
|
|
2764
|
+
const importName = "defineConfig";
|
|
2765
|
+
const { statement, alias } = js.imports.find(ast, {
|
|
2697
2766
|
name: importName,
|
|
2698
|
-
from: "vite"
|
|
2699
|
-
statement
|
|
2767
|
+
from: "vite"
|
|
2700
2768
|
});
|
|
2769
|
+
if (statement) {
|
|
2770
|
+
js.imports.addNamed(ast, {
|
|
2771
|
+
imports: { defineConfig: alias },
|
|
2772
|
+
from: "vitest/config"
|
|
2773
|
+
});
|
|
2774
|
+
js.imports.remove(ast, {
|
|
2775
|
+
name: importName,
|
|
2776
|
+
from: "vite",
|
|
2777
|
+
statement
|
|
2778
|
+
});
|
|
2779
|
+
}
|
|
2780
|
+
return generateCode();
|
|
2781
|
+
});
|
|
2782
|
+
},
|
|
2783
|
+
nextSteps: ({ language, options }) => {
|
|
2784
|
+
const toReturn = [];
|
|
2785
|
+
if (vitestV3Installed) {
|
|
2786
|
+
if (options.usages.includes("component")) {
|
|
2787
|
+
toReturn.push(`Uninstall ${color.command("@vitest/browser")} package`);
|
|
2788
|
+
toReturn.push(`Update usage from ${color.command("'@vitest/browser...'")} to ${color.command("'vitest/browser'")}`);
|
|
2789
|
+
}
|
|
2790
|
+
toReturn.push(`${color.optional("Optional")} Check ${color.path("./vite.config.ts")} and remove duplicate project definitions`);
|
|
2791
|
+
toReturn.push(`${color.optional("Optional")} Remove ${color.path(`./vitest-setup-client.${language}`)} file`);
|
|
2701
2792
|
}
|
|
2702
|
-
return
|
|
2703
|
-
});
|
|
2704
|
-
},
|
|
2705
|
-
nextSteps: ({ language, options: options$8 }) => {
|
|
2706
|
-
const toReturn = [];
|
|
2707
|
-
if (vitestV3Installed) {
|
|
2708
|
-
if (options$8.usages.includes("component")) {
|
|
2709
|
-
toReturn.push(`Uninstall ${color.command("@vitest/browser")} package`);
|
|
2710
|
-
toReturn.push(`Update usage from ${color.command("'@vitest/browser...'")} to ${color.command("'vitest/browser'")}`);
|
|
2711
|
-
}
|
|
2712
|
-
toReturn.push(`${color.optional("Optional")} Check ${color.path("./vite.config.ts")} and remove duplicate project definitions`);
|
|
2713
|
-
toReturn.push(`${color.optional("Optional")} Remove ${color.path(`./vitest-setup-client.${language}`)} file`);
|
|
2793
|
+
return toReturn;
|
|
2714
2794
|
}
|
|
2715
|
-
|
|
2716
|
-
}
|
|
2717
|
-
});
|
|
2718
|
-
|
|
2719
|
-
//#endregion
|
|
2720
|
-
//#region src/addons/index.ts
|
|
2721
|
-
const officialAddons$1 = {
|
|
2722
|
-
prettier: prettier_default,
|
|
2723
|
-
eslint: eslint_default,
|
|
2724
|
-
vitest: vitest_addon_default,
|
|
2795
|
+
}),
|
|
2725
2796
|
playwright: playwright_default,
|
|
2726
2797
|
tailwindcss: tailwindcss_default,
|
|
2727
2798
|
sveltekitAdapter: sveltekit_adapter_default,
|
|
@@ -2738,12 +2809,10 @@ function getAddonDetails(id) {
|
|
|
2738
2809
|
if (!details) throw new Error(`Invalid add-on: ${id}`);
|
|
2739
2810
|
return details;
|
|
2740
2811
|
}
|
|
2741
|
-
|
|
2742
2812
|
//#endregion
|
|
2743
2813
|
//#region package.json
|
|
2744
2814
|
var name = "sv";
|
|
2745
|
-
var version = "0.
|
|
2746
|
-
|
|
2815
|
+
var version = "0.13.0";
|
|
2747
2816
|
//#endregion
|
|
2748
2817
|
//#region src/core/errors.ts
|
|
2749
2818
|
var UnsupportedError = class extends Error {
|
|
@@ -2754,7 +2823,6 @@ var UnsupportedError = class extends Error {
|
|
|
2754
2823
|
this.reasons = reasons;
|
|
2755
2824
|
}
|
|
2756
2825
|
};
|
|
2757
|
-
|
|
2758
2826
|
//#endregion
|
|
2759
2827
|
//#region src/core/common.ts
|
|
2760
2828
|
const NO_PREFIX = "--no-";
|
|
@@ -2796,8 +2864,57 @@ function formatDescription(arg) {
|
|
|
2796
2864
|
if (arg.argChoices !== void 0 && String(arg.argChoices)) output += color.dim(` (choices: ${arg.argChoices.join(", ")})`);
|
|
2797
2865
|
return output;
|
|
2798
2866
|
}
|
|
2867
|
+
/**
|
|
2868
|
+
* Returns standard help sections and a formatItem helper.
|
|
2869
|
+
* Used by `add` and `create` custom `formatHelp` to avoid duplicating boilerplate.
|
|
2870
|
+
*/
|
|
2871
|
+
function getHelpSections(cmd, helper) {
|
|
2872
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
2873
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
2874
|
+
function formatItem(term, description) {
|
|
2875
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
2876
|
+
}
|
|
2877
|
+
const usage = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
|
|
2878
|
+
const descText = helper.commandDescription(cmd);
|
|
2879
|
+
const description = descText.length > 0 ? [helper.boxWrap(helper.styleCommandDescription(descText), helpWidth), ""] : [];
|
|
2880
|
+
const argItems = helper.visibleArguments(cmd).map((argument) => formatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument))));
|
|
2881
|
+
const arguments_ = argItems.length > 0 ? [
|
|
2882
|
+
helper.styleTitle("Arguments:"),
|
|
2883
|
+
...argItems,
|
|
2884
|
+
""
|
|
2885
|
+
] : [];
|
|
2886
|
+
const optItems = helper.visibleOptions(cmd).map((option) => formatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option))));
|
|
2887
|
+
const options = optItems.length > 0 ? [
|
|
2888
|
+
helper.styleTitle("Options:"),
|
|
2889
|
+
...optItems,
|
|
2890
|
+
""
|
|
2891
|
+
] : [];
|
|
2892
|
+
const globalOptItems = helper.showGlobalOptions ? helper.visibleGlobalOptions(cmd).map((option) => formatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)))) : [];
|
|
2893
|
+
const globalOptions = globalOptItems.length > 0 ? [
|
|
2894
|
+
helper.styleTitle("Global Options:"),
|
|
2895
|
+
...globalOptItems,
|
|
2896
|
+
""
|
|
2897
|
+
] : [];
|
|
2898
|
+
const cmdItems = helper.visibleCommands(cmd).map((sub) => formatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub))));
|
|
2899
|
+
const commands = cmdItems.length > 0 ? [
|
|
2900
|
+
helper.styleTitle("Commands:"),
|
|
2901
|
+
...cmdItems,
|
|
2902
|
+
""
|
|
2903
|
+
] : [];
|
|
2904
|
+
return {
|
|
2905
|
+
formatItem,
|
|
2906
|
+
styleTitle: helper.styleTitle.bind(helper),
|
|
2907
|
+
usage,
|
|
2908
|
+
description,
|
|
2909
|
+
arguments: arguments_,
|
|
2910
|
+
options,
|
|
2911
|
+
globalOptions,
|
|
2912
|
+
commands
|
|
2913
|
+
};
|
|
2914
|
+
}
|
|
2799
2915
|
async function runCommand(action) {
|
|
2800
2916
|
try {
|
|
2917
|
+
console.log(color.hidden("HINT: Run \"sv --help\" to get the full list of commands, add-ons, and examples to one-shot and skip interactive prompts."));
|
|
2801
2918
|
Nt(`Welcome to the Svelte CLI! ${color.optional(`(v${version})`)}`);
|
|
2802
2919
|
const minimumVersion = "18.3.0";
|
|
2803
2920
|
if (isVersionUnsupportedBelow(process$1.versions.node, minimumVersion)) R.warn(`You are using Node.js ${color.error(process$1.versions.node)}, please upgrade to Node.js ${color.success(minimumVersion)} or higher.`);
|
|
@@ -2826,13 +2943,13 @@ function forwardExitCode(error) {
|
|
|
2826
2943
|
}
|
|
2827
2944
|
function parseAddonOptions(optionFlags) {
|
|
2828
2945
|
if (optionFlags === void 0 || optionFlags === "") return;
|
|
2829
|
-
const options
|
|
2830
|
-
const malformed = options
|
|
2946
|
+
const options = optionFlags.split("+");
|
|
2947
|
+
const malformed = options.filter((option) => !/.+:.*/.test(option));
|
|
2831
2948
|
if (malformed.length > 0) {
|
|
2832
2949
|
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').`;
|
|
2833
2950
|
throw new Error(message);
|
|
2834
2951
|
}
|
|
2835
|
-
return options
|
|
2952
|
+
return options;
|
|
2836
2953
|
}
|
|
2837
2954
|
function buildAndLogArgs(agent, command, args, lastArgs = []) {
|
|
2838
2955
|
const allArgs = [
|
|
@@ -2902,13 +3019,11 @@ function updateAgent(projectPath, language, packageManager, loadedAddons) {
|
|
|
2902
3019
|
fs.writeFileSync(agentPath, content);
|
|
2903
3020
|
}
|
|
2904
3021
|
}
|
|
2905
|
-
|
|
2906
3022
|
//#endregion
|
|
2907
3023
|
//#region ../../node_modules/.pnpm/events-universal@1.0.1/node_modules/events-universal/default.js
|
|
2908
3024
|
var require_default = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2909
3025
|
module.exports = __require("events");
|
|
2910
3026
|
}));
|
|
2911
|
-
|
|
2912
3027
|
//#endregion
|
|
2913
3028
|
//#region ../../node_modules/.pnpm/fast-fifo@1.3.2/node_modules/fast-fifo/fixed-size.js
|
|
2914
3029
|
var require_fixed_size = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -2947,7 +3062,6 @@ var require_fixed_size = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2947
3062
|
}
|
|
2948
3063
|
};
|
|
2949
3064
|
}));
|
|
2950
|
-
|
|
2951
3065
|
//#endregion
|
|
2952
3066
|
//#region ../../node_modules/.pnpm/fast-fifo@1.3.2/node_modules/fast-fifo/index.js
|
|
2953
3067
|
var require_fast_fifo = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -2993,9 +3107,8 @@ var require_fast_fifo = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2993
3107
|
}
|
|
2994
3108
|
};
|
|
2995
3109
|
}));
|
|
2996
|
-
|
|
2997
3110
|
//#endregion
|
|
2998
|
-
//#region ../../node_modules/.pnpm/b4a@1.
|
|
3111
|
+
//#region ../../node_modules/.pnpm/b4a@1.8.0/node_modules/b4a/index.js
|
|
2999
3112
|
var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3000
3113
|
function isBuffer(value) {
|
|
3001
3114
|
return Buffer.isBuffer(value) || value instanceof Uint8Array;
|
|
@@ -3012,8 +3125,8 @@ var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3012
3125
|
function allocUnsafeSlow(size) {
|
|
3013
3126
|
return Buffer.allocUnsafeSlow(size);
|
|
3014
3127
|
}
|
|
3015
|
-
function byteLength(string
|
|
3016
|
-
return Buffer.byteLength(string
|
|
3128
|
+
function byteLength(string, encoding) {
|
|
3129
|
+
return Buffer.byteLength(string, encoding);
|
|
3017
3130
|
}
|
|
3018
3131
|
function compare(a, b) {
|
|
3019
3132
|
return Buffer.compare(a, b);
|
|
@@ -3058,8 +3171,8 @@ var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3058
3171
|
function toString(buffer, encoding, start, end) {
|
|
3059
3172
|
return toBuffer(buffer).toString(encoding, start, end);
|
|
3060
3173
|
}
|
|
3061
|
-
function write(buffer, string
|
|
3062
|
-
return toBuffer(buffer).write(string
|
|
3174
|
+
function write(buffer, string, offset, length, encoding) {
|
|
3175
|
+
return toBuffer(buffer).write(string, offset, length, encoding);
|
|
3063
3176
|
}
|
|
3064
3177
|
function readDoubleBE(buffer, offset) {
|
|
3065
3178
|
return toBuffer(buffer).readDoubleBE(offset);
|
|
@@ -3149,9 +3262,8 @@ var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3149
3262
|
writeUInt32LE
|
|
3150
3263
|
};
|
|
3151
3264
|
}));
|
|
3152
|
-
|
|
3153
3265
|
//#endregion
|
|
3154
|
-
//#region ../../node_modules/.pnpm/text-decoder@1.2.
|
|
3266
|
+
//#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/lib/pass-through-decoder.js
|
|
3155
3267
|
var require_pass_through_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3156
3268
|
const b4a = require_b4a();
|
|
3157
3269
|
module.exports = class PassThroughDecoder {
|
|
@@ -3161,17 +3273,16 @@ var require_pass_through_decoder = /* @__PURE__ */ __commonJSMin(((exports, modu
|
|
|
3161
3273
|
get remaining() {
|
|
3162
3274
|
return 0;
|
|
3163
3275
|
}
|
|
3164
|
-
decode(
|
|
3165
|
-
return b4a.toString(
|
|
3276
|
+
decode(data) {
|
|
3277
|
+
return b4a.toString(data, this.encoding);
|
|
3166
3278
|
}
|
|
3167
3279
|
flush() {
|
|
3168
3280
|
return "";
|
|
3169
3281
|
}
|
|
3170
3282
|
};
|
|
3171
3283
|
}));
|
|
3172
|
-
|
|
3173
3284
|
//#endregion
|
|
3174
|
-
//#region ../../node_modules/.pnpm/text-decoder@1.2.
|
|
3285
|
+
//#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/lib/utf8-decoder.js
|
|
3175
3286
|
var require_utf8_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3176
3287
|
const b4a = require_b4a();
|
|
3177
3288
|
/**
|
|
@@ -3179,80 +3290,147 @@ var require_utf8_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3179
3290
|
*/
|
|
3180
3291
|
module.exports = class UTF8Decoder {
|
|
3181
3292
|
constructor() {
|
|
3182
|
-
this.
|
|
3183
|
-
this.bytesSeen = 0;
|
|
3184
|
-
this.bytesNeeded = 0;
|
|
3185
|
-
this.lowerBoundary = 128;
|
|
3186
|
-
this.upperBoundary = 191;
|
|
3293
|
+
this._reset();
|
|
3187
3294
|
}
|
|
3188
3295
|
get remaining() {
|
|
3189
3296
|
return this.bytesSeen;
|
|
3190
3297
|
}
|
|
3191
3298
|
decode(data) {
|
|
3192
|
-
if (
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3299
|
+
if (data.byteLength === 0) return "";
|
|
3300
|
+
if (this.bytesNeeded === 0 && trailingIncomplete(data, 0) === 0) {
|
|
3301
|
+
this.bytesSeen = trailingBytesSeen(data);
|
|
3302
|
+
return b4a.toString(data, "utf8");
|
|
3196
3303
|
}
|
|
3197
3304
|
let result = "";
|
|
3198
|
-
|
|
3305
|
+
let start = 0;
|
|
3306
|
+
if (this.bytesNeeded > 0) {
|
|
3307
|
+
while (start < data.byteLength) {
|
|
3308
|
+
const byte = data[start];
|
|
3309
|
+
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
3310
|
+
result += "�";
|
|
3311
|
+
this._reset();
|
|
3312
|
+
break;
|
|
3313
|
+
}
|
|
3314
|
+
this.lowerBoundary = 128;
|
|
3315
|
+
this.upperBoundary = 191;
|
|
3316
|
+
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
3317
|
+
this.bytesSeen++;
|
|
3318
|
+
start++;
|
|
3319
|
+
if (this.bytesSeen === this.bytesNeeded) {
|
|
3320
|
+
result += String.fromCodePoint(this.codePoint);
|
|
3321
|
+
this._reset();
|
|
3322
|
+
break;
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
if (this.bytesNeeded > 0) return result;
|
|
3326
|
+
}
|
|
3327
|
+
const trailing = trailingIncomplete(data, start);
|
|
3328
|
+
const end = data.byteLength - trailing;
|
|
3329
|
+
if (end > start) result += b4a.toString(data, "utf8", start, end);
|
|
3330
|
+
for (let i = end; i < data.byteLength; i++) {
|
|
3199
3331
|
const byte = data[i];
|
|
3200
3332
|
if (this.bytesNeeded === 0) {
|
|
3201
|
-
if (byte <= 127)
|
|
3202
|
-
|
|
3333
|
+
if (byte <= 127) {
|
|
3334
|
+
this.bytesSeen = 0;
|
|
3335
|
+
result += String.fromCharCode(byte);
|
|
3336
|
+
} else if (byte >= 194 && byte <= 223) {
|
|
3337
|
+
this.bytesNeeded = 2;
|
|
3338
|
+
this.bytesSeen = 1;
|
|
3339
|
+
this.codePoint = byte & 31;
|
|
3340
|
+
} else if (byte >= 224 && byte <= 239) {
|
|
3341
|
+
if (byte === 224) this.lowerBoundary = 160;
|
|
3342
|
+
else if (byte === 237) this.upperBoundary = 159;
|
|
3343
|
+
this.bytesNeeded = 3;
|
|
3344
|
+
this.bytesSeen = 1;
|
|
3345
|
+
this.codePoint = byte & 15;
|
|
3346
|
+
} else if (byte >= 240 && byte <= 244) {
|
|
3347
|
+
if (byte === 240) this.lowerBoundary = 144;
|
|
3348
|
+
else if (byte === 244) this.upperBoundary = 143;
|
|
3349
|
+
this.bytesNeeded = 4;
|
|
3203
3350
|
this.bytesSeen = 1;
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
if (byte === 224) this.lowerBoundary = 160;
|
|
3209
|
-
else if (byte === 237) this.upperBoundary = 159;
|
|
3210
|
-
this.bytesNeeded = 3;
|
|
3211
|
-
this.codePoint = byte & 15;
|
|
3212
|
-
} else if (byte >= 240 && byte <= 244) {
|
|
3213
|
-
if (byte === 240) this.lowerBoundary = 144;
|
|
3214
|
-
if (byte === 244) this.upperBoundary = 143;
|
|
3215
|
-
this.bytesNeeded = 4;
|
|
3216
|
-
this.codePoint = byte & 7;
|
|
3217
|
-
} else result += "�";
|
|
3351
|
+
this.codePoint = byte & 7;
|
|
3352
|
+
} else {
|
|
3353
|
+
this.bytesSeen = 1;
|
|
3354
|
+
result += "�";
|
|
3218
3355
|
}
|
|
3219
3356
|
continue;
|
|
3220
3357
|
}
|
|
3221
3358
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
3222
|
-
this.codePoint = 0;
|
|
3223
|
-
this.bytesNeeded = 0;
|
|
3224
|
-
this.bytesSeen = 0;
|
|
3225
|
-
this.lowerBoundary = 128;
|
|
3226
|
-
this.upperBoundary = 191;
|
|
3227
3359
|
result += "�";
|
|
3360
|
+
i--;
|
|
3361
|
+
this._reset();
|
|
3228
3362
|
continue;
|
|
3229
3363
|
}
|
|
3230
3364
|
this.lowerBoundary = 128;
|
|
3231
3365
|
this.upperBoundary = 191;
|
|
3232
3366
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
3233
3367
|
this.bytesSeen++;
|
|
3234
|
-
if (this.bytesSeen
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
this.bytesSeen = 0;
|
|
3368
|
+
if (this.bytesSeen === this.bytesNeeded) {
|
|
3369
|
+
result += String.fromCodePoint(this.codePoint);
|
|
3370
|
+
this._reset();
|
|
3371
|
+
}
|
|
3239
3372
|
}
|
|
3240
3373
|
return result;
|
|
3241
3374
|
}
|
|
3242
3375
|
flush() {
|
|
3243
3376
|
const result = this.bytesNeeded > 0 ? "�" : "";
|
|
3377
|
+
this._reset();
|
|
3378
|
+
return result;
|
|
3379
|
+
}
|
|
3380
|
+
_reset() {
|
|
3244
3381
|
this.codePoint = 0;
|
|
3245
3382
|
this.bytesNeeded = 0;
|
|
3246
3383
|
this.bytesSeen = 0;
|
|
3247
3384
|
this.lowerBoundary = 128;
|
|
3248
3385
|
this.upperBoundary = 191;
|
|
3249
|
-
return result;
|
|
3250
3386
|
}
|
|
3251
3387
|
};
|
|
3388
|
+
function trailingIncomplete(data, start) {
|
|
3389
|
+
const len = data.byteLength;
|
|
3390
|
+
if (len <= start) return 0;
|
|
3391
|
+
const limit = Math.max(start, len - 4);
|
|
3392
|
+
let i = len - 1;
|
|
3393
|
+
while (i > limit && (data[i] & 192) === 128) i--;
|
|
3394
|
+
if (i < start) return 0;
|
|
3395
|
+
const byte = data[i];
|
|
3396
|
+
let needed;
|
|
3397
|
+
if (byte <= 127) return 0;
|
|
3398
|
+
if (byte >= 194 && byte <= 223) needed = 2;
|
|
3399
|
+
else if (byte >= 224 && byte <= 239) needed = 3;
|
|
3400
|
+
else if (byte >= 240 && byte <= 244) needed = 4;
|
|
3401
|
+
else return 0;
|
|
3402
|
+
const available = len - i;
|
|
3403
|
+
return available < needed ? available : 0;
|
|
3404
|
+
}
|
|
3405
|
+
function trailingBytesSeen(data) {
|
|
3406
|
+
const len = data.byteLength;
|
|
3407
|
+
if (len === 0) return 0;
|
|
3408
|
+
const last = data[len - 1];
|
|
3409
|
+
if (last <= 127) return 0;
|
|
3410
|
+
if ((last & 192) !== 128) return 1;
|
|
3411
|
+
const limit = Math.max(0, len - 4);
|
|
3412
|
+
let i = len - 2;
|
|
3413
|
+
while (i >= limit && (data[i] & 192) === 128) i--;
|
|
3414
|
+
if (i < 0) return 1;
|
|
3415
|
+
const first = data[i];
|
|
3416
|
+
let needed;
|
|
3417
|
+
if (first >= 194 && first <= 223) needed = 2;
|
|
3418
|
+
else if (first >= 224 && first <= 239) needed = 3;
|
|
3419
|
+
else if (first >= 240 && first <= 244) needed = 4;
|
|
3420
|
+
else return 1;
|
|
3421
|
+
if (len - i !== needed) return 1;
|
|
3422
|
+
if (needed >= 3) {
|
|
3423
|
+
const second = data[i + 1];
|
|
3424
|
+
if (first === 224 && second < 160) return 1;
|
|
3425
|
+
if (first === 237 && second > 159) return 1;
|
|
3426
|
+
if (first === 240 && second < 144) return 1;
|
|
3427
|
+
if (first === 244 && second > 143) return 1;
|
|
3428
|
+
}
|
|
3429
|
+
return 0;
|
|
3430
|
+
}
|
|
3252
3431
|
}));
|
|
3253
|
-
|
|
3254
3432
|
//#endregion
|
|
3255
|
-
//#region ../../node_modules/.pnpm/text-decoder@1.2.
|
|
3433
|
+
//#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/index.js
|
|
3256
3434
|
var require_text_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3257
3435
|
const PassThroughDecoder = require_pass_through_decoder();
|
|
3258
3436
|
const UTF8Decoder = require_utf8_decoder();
|
|
@@ -3303,9 +3481,8 @@ var require_text_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3303
3481
|
}
|
|
3304
3482
|
}
|
|
3305
3483
|
}));
|
|
3306
|
-
|
|
3307
3484
|
//#endregion
|
|
3308
|
-
//#region ../../node_modules/.pnpm/streamx@2.
|
|
3485
|
+
//#region ../../node_modules/.pnpm/streamx@2.25.0/node_modules/streamx/index.js
|
|
3309
3486
|
var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3310
3487
|
const { EventEmitter } = require_default();
|
|
3311
3488
|
const STREAM_DESTROYED = /* @__PURE__ */ new Error("Stream was destroyed");
|
|
@@ -3413,6 +3590,9 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3413
3590
|
this.afterWrite = afterWrite.bind(this);
|
|
3414
3591
|
this.afterUpdateNextTick = updateWriteNT.bind(this);
|
|
3415
3592
|
}
|
|
3593
|
+
get ending() {
|
|
3594
|
+
return (this.stream._duplexState & WRITE_FINISHING) !== 0;
|
|
3595
|
+
}
|
|
3416
3596
|
get ended() {
|
|
3417
3597
|
return (this.stream._duplexState & WRITE_DONE) !== 0;
|
|
3418
3598
|
}
|
|
@@ -3509,6 +3689,9 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3509
3689
|
this.afterRead = afterRead.bind(this);
|
|
3510
3690
|
this.afterUpdateNextTick = updateReadNT.bind(this);
|
|
3511
3691
|
}
|
|
3692
|
+
get ending() {
|
|
3693
|
+
return (this.stream._duplexState & READ_ENDING) !== 0;
|
|
3694
|
+
}
|
|
3512
3695
|
get ended() {
|
|
3513
3696
|
return (this.stream._duplexState & READ_DONE) !== 0;
|
|
3514
3697
|
}
|
|
@@ -3563,9 +3746,9 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3563
3746
|
const pending = [this.map !== null ? this.map(data) : data];
|
|
3564
3747
|
while (this.buffered > 0) pending.push(this.shift());
|
|
3565
3748
|
for (let i = 0; i < pending.length - 1; i++) {
|
|
3566
|
-
const data
|
|
3567
|
-
this.buffered += this.byteLength(data
|
|
3568
|
-
this.queue.push(data
|
|
3749
|
+
const data = pending[i];
|
|
3750
|
+
this.buffered += this.byteLength(data);
|
|
3751
|
+
this.queue.push(data);
|
|
3569
3752
|
}
|
|
3570
3753
|
this.push(pending[pending.length - 1]);
|
|
3571
3754
|
}
|
|
@@ -3768,19 +3951,19 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3768
3951
|
if (data !== void 0 && data !== null) this.push(data);
|
|
3769
3952
|
this._writableState.afterWrite(err);
|
|
3770
3953
|
}
|
|
3771
|
-
function newListener(name
|
|
3954
|
+
function newListener(name) {
|
|
3772
3955
|
if (this._readableState !== null) {
|
|
3773
|
-
if (name
|
|
3956
|
+
if (name === "data") {
|
|
3774
3957
|
this._duplexState |= READ_EMIT_DATA | READ_RESUMED_READ_AHEAD;
|
|
3775
3958
|
this._readableState.updateNextTick();
|
|
3776
3959
|
}
|
|
3777
|
-
if (name
|
|
3960
|
+
if (name === "readable") {
|
|
3778
3961
|
this._duplexState |= READ_EMIT_READABLE;
|
|
3779
3962
|
this._readableState.updateNextTick();
|
|
3780
3963
|
}
|
|
3781
3964
|
}
|
|
3782
3965
|
if (this._writableState !== null) {
|
|
3783
|
-
if (name
|
|
3966
|
+
if (name === "drain") {
|
|
3784
3967
|
this._duplexState |= WRITE_EMIT_DRAIN;
|
|
3785
3968
|
this._writableState.updateNextTick();
|
|
3786
3969
|
}
|
|
@@ -3945,8 +4128,8 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3945
4128
|
return this;
|
|
3946
4129
|
},
|
|
3947
4130
|
next() {
|
|
3948
|
-
return new Promise(function(resolve
|
|
3949
|
-
promiseResolve = resolve
|
|
4131
|
+
return new Promise(function(resolve, reject) {
|
|
4132
|
+
promiseResolve = resolve;
|
|
3950
4133
|
promiseReject = reject;
|
|
3951
4134
|
const data = stream.read();
|
|
3952
4135
|
if (data !== null) ondata(data);
|
|
@@ -3978,14 +4161,14 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3978
4161
|
}
|
|
3979
4162
|
function destroy(err) {
|
|
3980
4163
|
stream.destroy(err);
|
|
3981
|
-
return new Promise((resolve
|
|
3982
|
-
if (stream._duplexState & DESTROYED) return resolve
|
|
4164
|
+
return new Promise((resolve, reject) => {
|
|
4165
|
+
if (stream._duplexState & DESTROYED) return resolve({
|
|
3983
4166
|
value: void 0,
|
|
3984
4167
|
done: true
|
|
3985
4168
|
});
|
|
3986
4169
|
stream.once("close", function() {
|
|
3987
4170
|
if (err) reject(err);
|
|
3988
|
-
else resolve
|
|
4171
|
+
else resolve({
|
|
3989
4172
|
value: void 0,
|
|
3990
4173
|
done: true
|
|
3991
4174
|
});
|
|
@@ -4031,10 +4214,10 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4031
4214
|
const writes = (isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length) + (ws._duplexState & WRITE_WRITING ? 1 : 0);
|
|
4032
4215
|
if (writes === 0) return Promise.resolve(true);
|
|
4033
4216
|
if (state.drains === null) state.drains = [];
|
|
4034
|
-
return new Promise((resolve
|
|
4217
|
+
return new Promise((resolve) => {
|
|
4035
4218
|
state.drains.push({
|
|
4036
4219
|
writes,
|
|
4037
|
-
resolve
|
|
4220
|
+
resolve
|
|
4038
4221
|
});
|
|
4039
4222
|
});
|
|
4040
4223
|
}
|
|
@@ -4133,10 +4316,10 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4133
4316
|
cb(null);
|
|
4134
4317
|
}
|
|
4135
4318
|
function pipelinePromise(...streams) {
|
|
4136
|
-
return new Promise((resolve
|
|
4319
|
+
return new Promise((resolve, reject) => {
|
|
4137
4320
|
return pipeline(...streams, (err) => {
|
|
4138
4321
|
if (err) return reject(err);
|
|
4139
|
-
resolve
|
|
4322
|
+
resolve();
|
|
4140
4323
|
});
|
|
4141
4324
|
});
|
|
4142
4325
|
}
|
|
@@ -4169,12 +4352,12 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4169
4352
|
if (autoDestroy) dest.on("close", () => done(error || (fin ? null : PREMATURE_CLOSE)));
|
|
4170
4353
|
}
|
|
4171
4354
|
return dest;
|
|
4172
|
-
function errorHandle(s, rd, wr, onerror
|
|
4173
|
-
s.on("error", onerror
|
|
4355
|
+
function errorHandle(s, rd, wr, onerror) {
|
|
4356
|
+
s.on("error", onerror);
|
|
4174
4357
|
s.on("close", onclose);
|
|
4175
4358
|
function onclose() {
|
|
4176
|
-
if (rd && s._readableState && !s._readableState.ended) return onerror
|
|
4177
|
-
if (wr && s._writableState && !s._writableState.ended) return onerror
|
|
4359
|
+
if (rd && s._readableState && !s._readableState.ended) return onerror(PREMATURE_CLOSE);
|
|
4360
|
+
if (wr && s._writableState && !s._writableState.ended) return onerror(PREMATURE_CLOSE);
|
|
4178
4361
|
}
|
|
4179
4362
|
}
|
|
4180
4363
|
function onerror(err) {
|
|
@@ -4192,9 +4375,15 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4192
4375
|
function isStreamx(stream) {
|
|
4193
4376
|
return typeof stream._duplexState === "number" && isStream(stream);
|
|
4194
4377
|
}
|
|
4378
|
+
function isEnding(stream) {
|
|
4379
|
+
return !!stream._readableState && stream._readableState.ending;
|
|
4380
|
+
}
|
|
4195
4381
|
function isEnded(stream) {
|
|
4196
4382
|
return !!stream._readableState && stream._readableState.ended;
|
|
4197
4383
|
}
|
|
4384
|
+
function isFinishing(stream) {
|
|
4385
|
+
return !!stream._writableState && stream._writableState.ending;
|
|
4386
|
+
}
|
|
4198
4387
|
function isFinished(stream) {
|
|
4199
4388
|
return !!stream._writableState && stream._writableState.ended;
|
|
4200
4389
|
}
|
|
@@ -4206,7 +4395,7 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4206
4395
|
return isStreamx(stream) && stream.readable;
|
|
4207
4396
|
}
|
|
4208
4397
|
function isDisturbed(stream) {
|
|
4209
|
-
return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0;
|
|
4398
|
+
return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & DESTROYING) === DESTROYING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0;
|
|
4210
4399
|
}
|
|
4211
4400
|
function isTypedArray(data) {
|
|
4212
4401
|
return typeof data === "object" && data !== null && typeof data.byteLength === "number";
|
|
@@ -4226,7 +4415,9 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4226
4415
|
pipelinePromise,
|
|
4227
4416
|
isStream,
|
|
4228
4417
|
isStreamx,
|
|
4418
|
+
isEnding,
|
|
4229
4419
|
isEnded,
|
|
4420
|
+
isFinishing,
|
|
4230
4421
|
isFinished,
|
|
4231
4422
|
isDisturbed,
|
|
4232
4423
|
getStreamError,
|
|
@@ -4238,9 +4429,8 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4238
4429
|
PassThrough
|
|
4239
4430
|
};
|
|
4240
4431
|
}));
|
|
4241
|
-
|
|
4242
4432
|
//#endregion
|
|
4243
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
4433
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/headers.js
|
|
4244
4434
|
var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4245
4435
|
const b4a = require_b4a();
|
|
4246
4436
|
const ZEROS = "0000000000000000000";
|
|
@@ -4295,19 +4485,19 @@ var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4295
4485
|
};
|
|
4296
4486
|
exports.encode = function encode(opts) {
|
|
4297
4487
|
const buf = b4a.alloc(512);
|
|
4298
|
-
let name
|
|
4488
|
+
let name = opts.name;
|
|
4299
4489
|
let prefix = "";
|
|
4300
|
-
if (opts.typeflag === 5 && name
|
|
4301
|
-
if (b4a.byteLength(name
|
|
4302
|
-
while (b4a.byteLength(name
|
|
4303
|
-
const i = name
|
|
4490
|
+
if (opts.typeflag === 5 && name[name.length - 1] !== "/") name += "/";
|
|
4491
|
+
if (b4a.byteLength(name) !== name.length) return null;
|
|
4492
|
+
while (b4a.byteLength(name) > 100) {
|
|
4493
|
+
const i = name.indexOf("/");
|
|
4304
4494
|
if (i === -1) return null;
|
|
4305
|
-
prefix += prefix ? "/" + name
|
|
4306
|
-
name
|
|
4495
|
+
prefix += prefix ? "/" + name.slice(0, i) : name.slice(0, i);
|
|
4496
|
+
name = name.slice(i + 1);
|
|
4307
4497
|
}
|
|
4308
|
-
if (b4a.byteLength(name
|
|
4498
|
+
if (b4a.byteLength(name) > 100 || b4a.byteLength(prefix) > 155) return null;
|
|
4309
4499
|
if (opts.linkname && b4a.byteLength(opts.linkname) > 100) return null;
|
|
4310
|
-
b4a.write(buf, name
|
|
4500
|
+
b4a.write(buf, name);
|
|
4311
4501
|
b4a.write(buf, encodeOct(opts.mode & MASK, 6), 100);
|
|
4312
4502
|
b4a.write(buf, encodeOct(opts.uid, 6), 108);
|
|
4313
4503
|
b4a.write(buf, encodeOct(opts.gid, 6), 116);
|
|
@@ -4327,7 +4517,7 @@ var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4327
4517
|
};
|
|
4328
4518
|
exports.decode = function decode(buf, filenameEncoding, allowUnknownFormat) {
|
|
4329
4519
|
let typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET;
|
|
4330
|
-
let name
|
|
4520
|
+
let name = decodeStr(buf, 0, 100, filenameEncoding);
|
|
4331
4521
|
const mode = decodeOct(buf, 100, 8);
|
|
4332
4522
|
const uid = decodeOct(buf, 108, 8);
|
|
4333
4523
|
const gid = decodeOct(buf, 116, 8);
|
|
@@ -4343,11 +4533,11 @@ var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4343
4533
|
if (c === 256) return null;
|
|
4344
4534
|
if (c !== decodeOct(buf, 148, 8)) throw new Error("Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?");
|
|
4345
4535
|
if (isUSTAR(buf)) {
|
|
4346
|
-
if (buf[345]) name
|
|
4536
|
+
if (buf[345]) name = decodeStr(buf, 345, 155, filenameEncoding) + "/" + name;
|
|
4347
4537
|
} else if (isGNU(buf)) {} else if (!allowUnknownFormat) throw new Error("Invalid tar header: unknown format.");
|
|
4348
|
-
if (typeflag === 0 && name
|
|
4538
|
+
if (typeflag === 0 && name && name[name.length - 1] === "/") typeflag = 5;
|
|
4349
4539
|
return {
|
|
4350
|
-
name
|
|
4540
|
+
name,
|
|
4351
4541
|
mode,
|
|
4352
4542
|
uid,
|
|
4353
4543
|
gid,
|
|
@@ -4474,9 +4664,8 @@ var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4474
4664
|
return len + digits + str;
|
|
4475
4665
|
}
|
|
4476
4666
|
}));
|
|
4477
|
-
|
|
4478
4667
|
//#endregion
|
|
4479
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
4668
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/extract.js
|
|
4480
4669
|
var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4481
4670
|
const { Writable, Readable, getStreamError } = require_streamx();
|
|
4482
4671
|
const FIFO = require_fast_fifo();
|
|
@@ -4720,7 +4909,7 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4720
4909
|
let promiseReject = null;
|
|
4721
4910
|
let entryStream = null;
|
|
4722
4911
|
let entryCallback = null;
|
|
4723
|
-
const extract
|
|
4912
|
+
const extract = this;
|
|
4724
4913
|
this.on("entry", onentry);
|
|
4725
4914
|
this.on("error", (err) => {
|
|
4726
4915
|
error = err;
|
|
@@ -4746,20 +4935,20 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4746
4935
|
entryCallback = null;
|
|
4747
4936
|
cb(err);
|
|
4748
4937
|
}
|
|
4749
|
-
function onnext(resolve
|
|
4938
|
+
function onnext(resolve, reject) {
|
|
4750
4939
|
if (error) return reject(error);
|
|
4751
4940
|
if (entryStream) {
|
|
4752
|
-
resolve
|
|
4941
|
+
resolve({
|
|
4753
4942
|
value: entryStream,
|
|
4754
4943
|
done: false
|
|
4755
4944
|
});
|
|
4756
4945
|
entryStream = null;
|
|
4757
4946
|
return;
|
|
4758
4947
|
}
|
|
4759
|
-
promiseResolve = resolve
|
|
4948
|
+
promiseResolve = resolve;
|
|
4760
4949
|
promiseReject = reject;
|
|
4761
4950
|
consumeCallback(null);
|
|
4762
|
-
if (extract
|
|
4951
|
+
if (extract._finished && promiseResolve) {
|
|
4763
4952
|
promiseResolve({
|
|
4764
4953
|
value: void 0,
|
|
4765
4954
|
done: true
|
|
@@ -4789,16 +4978,16 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4789
4978
|
promiseResolve = promiseReject = null;
|
|
4790
4979
|
}
|
|
4791
4980
|
function destroy(err) {
|
|
4792
|
-
extract
|
|
4981
|
+
extract.destroy(err);
|
|
4793
4982
|
consumeCallback(err);
|
|
4794
|
-
return new Promise((resolve
|
|
4795
|
-
if (extract
|
|
4983
|
+
return new Promise((resolve, reject) => {
|
|
4984
|
+
if (extract.destroyed) return resolve({
|
|
4796
4985
|
value: void 0,
|
|
4797
4986
|
done: true
|
|
4798
4987
|
});
|
|
4799
|
-
extract
|
|
4988
|
+
extract.once("close", function() {
|
|
4800
4989
|
if (err) reject(err);
|
|
4801
|
-
else resolve
|
|
4990
|
+
else resolve({
|
|
4802
4991
|
value: void 0,
|
|
4803
4992
|
done: true
|
|
4804
4993
|
});
|
|
@@ -4807,7 +4996,7 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4807
4996
|
}
|
|
4808
4997
|
}
|
|
4809
4998
|
};
|
|
4810
|
-
module.exports = function extract
|
|
4999
|
+
module.exports = function extract(opts) {
|
|
4811
5000
|
return new Extract(opts);
|
|
4812
5001
|
};
|
|
4813
5002
|
function noop() {}
|
|
@@ -4816,9 +5005,8 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4816
5005
|
return size && 512 - size;
|
|
4817
5006
|
}
|
|
4818
5007
|
}));
|
|
4819
|
-
|
|
4820
5008
|
//#endregion
|
|
4821
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
5009
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/constants.js
|
|
4822
5010
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4823
5011
|
const constants = {
|
|
4824
5012
|
S_IFMT: 61440,
|
|
@@ -4834,9 +5022,8 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4834
5022
|
module.exports = constants;
|
|
4835
5023
|
}
|
|
4836
5024
|
}));
|
|
4837
|
-
|
|
4838
5025
|
//#endregion
|
|
4839
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
5026
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/pack.js
|
|
4840
5027
|
var require_pack = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4841
5028
|
const { Readable, Writable, getStreamError } = require_streamx();
|
|
4842
5029
|
const b4a = require_b4a();
|
|
@@ -5056,14 +5243,12 @@ var require_pack = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5056
5243
|
return b4a.isBuffer(buf) ? buf : b4a.from(buf);
|
|
5057
5244
|
}
|
|
5058
5245
|
}));
|
|
5059
|
-
|
|
5060
5246
|
//#endregion
|
|
5061
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
5247
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/index.js
|
|
5062
5248
|
var require_tar_stream = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
5063
5249
|
exports.extract = require_extract();
|
|
5064
5250
|
exports.pack = require_pack();
|
|
5065
5251
|
}));
|
|
5066
|
-
|
|
5067
5252
|
//#endregion
|
|
5068
5253
|
//#region ../../node_modules/.pnpm/wrappy@1.0.2/node_modules/wrappy/wrappy.js
|
|
5069
5254
|
var require_wrappy = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -5079,15 +5264,14 @@ var require_wrappy = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5079
5264
|
var args = new Array(arguments.length);
|
|
5080
5265
|
for (var i = 0; i < args.length; i++) args[i] = arguments[i];
|
|
5081
5266
|
var ret = fn.apply(this, args);
|
|
5082
|
-
var cb
|
|
5083
|
-
if (typeof ret === "function" && ret !== cb
|
|
5084
|
-
ret[k] = cb
|
|
5267
|
+
var cb = args[args.length - 1];
|
|
5268
|
+
if (typeof ret === "function" && ret !== cb) Object.keys(cb).forEach(function(k) {
|
|
5269
|
+
ret[k] = cb[k];
|
|
5085
5270
|
});
|
|
5086
5271
|
return ret;
|
|
5087
5272
|
}
|
|
5088
5273
|
}
|
|
5089
5274
|
}));
|
|
5090
|
-
|
|
5091
5275
|
//#endregion
|
|
5092
5276
|
//#region ../../node_modules/.pnpm/once@1.4.0/node_modules/once/once.js
|
|
5093
5277
|
var require_once = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -5128,7 +5312,6 @@ var require_once = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5128
5312
|
return f;
|
|
5129
5313
|
}
|
|
5130
5314
|
}));
|
|
5131
|
-
|
|
5132
5315
|
//#endregion
|
|
5133
5316
|
//#region ../../node_modules/.pnpm/end-of-stream@1.4.5/node_modules/end-of-stream/index.js
|
|
5134
5317
|
var require_end_of_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -5209,9 +5392,8 @@ var require_end_of_stream = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
5209
5392
|
};
|
|
5210
5393
|
module.exports = eos;
|
|
5211
5394
|
}));
|
|
5212
|
-
|
|
5213
5395
|
//#endregion
|
|
5214
|
-
//#region ../../node_modules/.pnpm/pump@3.0.
|
|
5396
|
+
//#region ../../node_modules/.pnpm/pump@3.0.4/node_modules/pump/index.js
|
|
5215
5397
|
var require_pump = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
5216
5398
|
var once = require_once();
|
|
5217
5399
|
var eos = require_end_of_stream();
|
|
@@ -5283,10 +5465,9 @@ var require_pump = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5283
5465
|
};
|
|
5284
5466
|
module.exports = pump;
|
|
5285
5467
|
}));
|
|
5286
|
-
|
|
5287
5468
|
//#endregion
|
|
5288
|
-
//#region
|
|
5289
|
-
var
|
|
5469
|
+
//#region src/core/fetch-packages.ts
|
|
5470
|
+
var import_tar_fs = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
5290
5471
|
const tar = require_tar_stream();
|
|
5291
5472
|
const pump = require_pump();
|
|
5292
5473
|
const fs$1 = __require("fs");
|
|
@@ -5301,15 +5482,15 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5301
5482
|
function processUmask() {
|
|
5302
5483
|
return !global.Bare && process.umask ? process.umask() : 0;
|
|
5303
5484
|
}
|
|
5304
|
-
exports.extract = function extract
|
|
5305
|
-
if (!cwd
|
|
5485
|
+
exports.extract = function extract(cwd, opts) {
|
|
5486
|
+
if (!cwd) cwd = ".";
|
|
5306
5487
|
if (!opts) opts = {};
|
|
5307
|
-
cwd
|
|
5488
|
+
cwd = path$1.resolve(cwd);
|
|
5308
5489
|
const xfs = opts.fs || fs$1;
|
|
5309
5490
|
const ignore = opts.ignore || opts.filter || noop;
|
|
5310
5491
|
const mapStream = opts.mapStream || echo;
|
|
5311
5492
|
const own = opts.chown !== false && !win32 && processGetuid() === 0;
|
|
5312
|
-
const extract
|
|
5493
|
+
const extract = opts.extract || tar.extract();
|
|
5313
5494
|
const stack = [];
|
|
5314
5495
|
const now = /* @__PURE__ */ new Date();
|
|
5315
5496
|
const umask = typeof opts.umask === "number" ? ~opts.umask : ~processUmask();
|
|
@@ -5327,24 +5508,24 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5327
5508
|
dmode |= parseInt(333, 8);
|
|
5328
5509
|
fmode |= parseInt(222, 8);
|
|
5329
5510
|
}
|
|
5330
|
-
extract
|
|
5331
|
-
if (opts.finish) extract
|
|
5332
|
-
return extract
|
|
5511
|
+
extract.on("entry", onentry);
|
|
5512
|
+
if (opts.finish) extract.on("finish", opts.finish);
|
|
5513
|
+
return extract;
|
|
5333
5514
|
function onentry(header, stream, next) {
|
|
5334
5515
|
header = map(header) || header;
|
|
5335
5516
|
header.name = normalize(header.name);
|
|
5336
|
-
const name
|
|
5337
|
-
if (ignore(name
|
|
5517
|
+
const name = path$1.join(cwd, path$1.join("/", header.name));
|
|
5518
|
+
if (ignore(name, header)) {
|
|
5338
5519
|
stream.resume();
|
|
5339
5520
|
return next();
|
|
5340
5521
|
}
|
|
5341
|
-
const dir = path$1.join(name
|
|
5342
|
-
validate(xfs, dir, path$1.join(cwd
|
|
5522
|
+
const dir = path$1.join(name, ".") === path$1.join(cwd, ".") ? cwd : path$1.dirname(name);
|
|
5523
|
+
validate(xfs, dir, path$1.join(cwd, "."), function(err, valid) {
|
|
5343
5524
|
if (err) return next(err);
|
|
5344
5525
|
if (!valid) return next(/* @__PURE__ */ new Error(dir + " is not a valid path"));
|
|
5345
5526
|
if (header.type === "directory") {
|
|
5346
|
-
stack.push([name
|
|
5347
|
-
return mkdirfix(name
|
|
5527
|
+
stack.push([name, header.mtime]);
|
|
5528
|
+
return mkdirfix(name, {
|
|
5348
5529
|
fs: xfs,
|
|
5349
5530
|
own,
|
|
5350
5531
|
uid: header.uid,
|
|
@@ -5358,54 +5539,59 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5358
5539
|
uid: header.uid,
|
|
5359
5540
|
gid: header.gid,
|
|
5360
5541
|
mode: 493
|
|
5361
|
-
}, function(err
|
|
5362
|
-
if (err
|
|
5542
|
+
}, function(err) {
|
|
5543
|
+
if (err) return next(err);
|
|
5363
5544
|
switch (header.type) {
|
|
5364
5545
|
case "file": return onfile();
|
|
5365
5546
|
case "link": return onlink();
|
|
5366
5547
|
case "symlink": return onsymlink();
|
|
5367
5548
|
}
|
|
5368
|
-
if (strict) return next(/* @__PURE__ */ new Error("unsupported type for " + name
|
|
5549
|
+
if (strict) return next(/* @__PURE__ */ new Error("unsupported type for " + name + " (" + header.type + ")"));
|
|
5369
5550
|
stream.resume();
|
|
5370
5551
|
next();
|
|
5371
5552
|
});
|
|
5372
5553
|
});
|
|
5373
5554
|
function stat(err) {
|
|
5374
5555
|
if (err) return next(err);
|
|
5375
|
-
utimes(name
|
|
5376
|
-
if (err
|
|
5556
|
+
utimes(name, header, function(err) {
|
|
5557
|
+
if (err) return next(err);
|
|
5377
5558
|
if (win32) return next();
|
|
5378
|
-
chperm(name
|
|
5559
|
+
chperm(name, header, next);
|
|
5379
5560
|
});
|
|
5380
5561
|
}
|
|
5381
5562
|
function onsymlink() {
|
|
5382
5563
|
if (win32) return next();
|
|
5383
|
-
xfs.unlink(name
|
|
5384
|
-
|
|
5385
|
-
|
|
5564
|
+
xfs.unlink(name, function() {
|
|
5565
|
+
const dst = path$1.resolve(path$1.dirname(name), header.linkname);
|
|
5566
|
+
if (!inCwd(dst) && validateSymLinks) return next(/* @__PURE__ */ new Error(name + " is not a valid symlink"));
|
|
5567
|
+
validateNotSymlink(xfs, dst, path$1.join(cwd, "."), function(err, valid) {
|
|
5568
|
+
if (err) return next(err);
|
|
5569
|
+
if (!valid && validateSymLinks) return next(/* @__PURE__ */ new Error(name + " is not a valid symlink"));
|
|
5570
|
+
xfs.symlink(header.linkname, name, stat);
|
|
5571
|
+
});
|
|
5386
5572
|
});
|
|
5387
5573
|
}
|
|
5388
5574
|
function onlink() {
|
|
5389
5575
|
if (win32) return next();
|
|
5390
|
-
xfs.unlink(name
|
|
5391
|
-
const link = path$1.join(cwd
|
|
5392
|
-
|
|
5393
|
-
if (err || !inCwd(dst)) return next(/* @__PURE__ */ new Error(name
|
|
5394
|
-
xfs.link(dst, name
|
|
5395
|
-
if (err
|
|
5576
|
+
xfs.unlink(name, function() {
|
|
5577
|
+
const link = path$1.join(cwd, path$1.join("/", header.linkname));
|
|
5578
|
+
xfs.realpath(link, function(err, dst) {
|
|
5579
|
+
if (err || !inCwd(dst)) return next(/* @__PURE__ */ new Error(name + " is not a valid hardlink"));
|
|
5580
|
+
xfs.link(dst, name, function(err) {
|
|
5581
|
+
if (err && err.code === "EPERM" && opts.hardlinkAsFilesFallback) {
|
|
5396
5582
|
stream = xfs.createReadStream(dst);
|
|
5397
5583
|
return onfile();
|
|
5398
5584
|
}
|
|
5399
|
-
stat(err
|
|
5585
|
+
stat(err);
|
|
5400
5586
|
});
|
|
5401
5587
|
});
|
|
5402
5588
|
});
|
|
5403
5589
|
}
|
|
5404
5590
|
function inCwd(dst) {
|
|
5405
|
-
return dst === cwd
|
|
5591
|
+
return dst === cwd || dst.startsWith(cwd + path$1.sep);
|
|
5406
5592
|
}
|
|
5407
5593
|
function onfile() {
|
|
5408
|
-
const ws = xfs.createWriteStream(name
|
|
5594
|
+
const ws = xfs.createWriteStream(name);
|
|
5409
5595
|
const rs = mapStream(stream, header);
|
|
5410
5596
|
ws.on("error", function(err) {
|
|
5411
5597
|
rs.destroy(err);
|
|
@@ -5416,63 +5602,72 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5416
5602
|
});
|
|
5417
5603
|
}
|
|
5418
5604
|
}
|
|
5419
|
-
function utimesParent(name
|
|
5605
|
+
function utimesParent(name, cb) {
|
|
5420
5606
|
let top;
|
|
5421
|
-
while ((top = head(stack)) && name
|
|
5607
|
+
while ((top = head(stack)) && name.slice(0, top[0].length) !== top[0]) stack.pop();
|
|
5422
5608
|
if (!top) return cb();
|
|
5423
5609
|
xfs.utimes(top[0], now, top[1], cb);
|
|
5424
5610
|
}
|
|
5425
|
-
function utimes(name
|
|
5611
|
+
function utimes(name, header, cb) {
|
|
5426
5612
|
if (opts.utimes === false) return cb();
|
|
5427
|
-
if (header.type === "directory") return xfs.utimes(name
|
|
5428
|
-
if (header.type === "symlink") return utimesParent(name
|
|
5429
|
-
xfs.utimes(name
|
|
5613
|
+
if (header.type === "directory") return xfs.utimes(name, now, header.mtime, cb);
|
|
5614
|
+
if (header.type === "symlink") return utimesParent(name, cb);
|
|
5615
|
+
xfs.utimes(name, now, header.mtime, function(err) {
|
|
5430
5616
|
if (err) return cb(err);
|
|
5431
|
-
utimesParent(name
|
|
5617
|
+
utimesParent(name, cb);
|
|
5432
5618
|
});
|
|
5433
5619
|
}
|
|
5434
|
-
function chperm(name
|
|
5620
|
+
function chperm(name, header, cb) {
|
|
5435
5621
|
const link = header.type === "symlink";
|
|
5436
5622
|
const chmod = link ? xfs.lchmod : xfs.chmod;
|
|
5437
5623
|
const chown = link ? xfs.lchown : xfs.chown;
|
|
5438
5624
|
if (!chmod) return cb();
|
|
5439
5625
|
const mode = (header.mode | (header.type === "directory" ? dmode : fmode)) & umask;
|
|
5440
|
-
if (chown && own) chown.call(xfs, name
|
|
5626
|
+
if (chown && own) chown.call(xfs, name, header.uid, header.gid, onchown);
|
|
5441
5627
|
else onchown(null);
|
|
5442
5628
|
function onchown(err) {
|
|
5443
5629
|
if (err) return cb(err);
|
|
5444
5630
|
if (!chmod) return cb();
|
|
5445
|
-
chmod.call(xfs, name
|
|
5631
|
+
chmod.call(xfs, name, mode, cb);
|
|
5446
5632
|
}
|
|
5447
5633
|
}
|
|
5448
|
-
function mkdirfix(name
|
|
5449
|
-
xfs.stat(name
|
|
5634
|
+
function mkdirfix(name, opts, cb) {
|
|
5635
|
+
xfs.stat(name, function(err) {
|
|
5450
5636
|
if (!err) return cb(null);
|
|
5451
5637
|
if (err.code !== "ENOENT") return cb(err);
|
|
5452
|
-
xfs.mkdir(name
|
|
5453
|
-
mode: opts
|
|
5638
|
+
xfs.mkdir(name, {
|
|
5639
|
+
mode: opts.mode,
|
|
5454
5640
|
recursive: true
|
|
5455
|
-
}, function(err
|
|
5456
|
-
if (err
|
|
5457
|
-
chperm(name
|
|
5641
|
+
}, function(err, made) {
|
|
5642
|
+
if (err) return cb(err);
|
|
5643
|
+
chperm(name, opts, cb);
|
|
5458
5644
|
});
|
|
5459
5645
|
});
|
|
5460
5646
|
}
|
|
5461
5647
|
};
|
|
5462
|
-
function
|
|
5463
|
-
if (name
|
|
5464
|
-
|
|
5648
|
+
function validateNotSymlink(fs, name, root, cb) {
|
|
5649
|
+
if (name === root) return cb(null, true);
|
|
5650
|
+
if (!name.startsWith(root + path$1.sep)) return cb(null, false);
|
|
5651
|
+
fs.lstat(name, function(err, st) {
|
|
5652
|
+
if (err && err.code !== "ENOENT" && err.code !== "EPERM") return cb(err);
|
|
5653
|
+
if (err || !st.isSymbolicLink()) return validateNotSymlink(fs, path$1.join(name, ".."), root, cb);
|
|
5654
|
+
cb(null, false);
|
|
5655
|
+
});
|
|
5656
|
+
}
|
|
5657
|
+
function validate(fs, name, root, cb) {
|
|
5658
|
+
if (name === root) return cb(null, true);
|
|
5659
|
+
fs.lstat(name, function(err, st) {
|
|
5465
5660
|
if (err && err.code !== "ENOENT" && err.code !== "EPERM") return cb(err);
|
|
5466
|
-
if (err || st.isDirectory()) return validate(fs
|
|
5661
|
+
if (err || st.isDirectory()) return validate(fs, path$1.join(name, ".."), root, cb);
|
|
5467
5662
|
cb(null, false);
|
|
5468
5663
|
});
|
|
5469
5664
|
}
|
|
5470
5665
|
function noop() {}
|
|
5471
|
-
function echo(name
|
|
5472
|
-
return name
|
|
5666
|
+
function echo(name) {
|
|
5667
|
+
return name;
|
|
5473
5668
|
}
|
|
5474
|
-
function normalize(name
|
|
5475
|
-
return win32 ? name
|
|
5669
|
+
function normalize(name) {
|
|
5670
|
+
return win32 ? name.replace(/\\/g, "/").replace(/[:?<>|]/g, "_") : name;
|
|
5476
5671
|
}
|
|
5477
5672
|
function strip(map, level) {
|
|
5478
5673
|
return function(header) {
|
|
@@ -5482,11 +5677,7 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5482
5677
|
return map(header);
|
|
5483
5678
|
};
|
|
5484
5679
|
}
|
|
5485
|
-
}));
|
|
5486
|
-
|
|
5487
|
-
//#endregion
|
|
5488
|
-
//#region src/core/fetch-packages.ts
|
|
5489
|
-
var import_tar_fs = require_tar_fs();
|
|
5680
|
+
})))();
|
|
5490
5681
|
const NODE_MODULES = fileURLToPath(new URL("../../node_modules", import.meta.url));
|
|
5491
5682
|
function verifyPackage(addonPkg, specifier) {
|
|
5492
5683
|
const deps = { ...addonPkg.dependencies };
|
|
@@ -5521,17 +5712,17 @@ function copyDirectorySync(src, dest) {
|
|
|
5521
5712
|
* Downloads and installs the package into the `node_modules` of `sv`.
|
|
5522
5713
|
* @returns the details of the downloaded addon
|
|
5523
5714
|
*/
|
|
5524
|
-
async function downloadPackage(options
|
|
5525
|
-
const { pkg } = options
|
|
5526
|
-
if (options
|
|
5715
|
+
async function downloadPackage(options) {
|
|
5716
|
+
const { pkg } = options;
|
|
5717
|
+
if (options.path) {
|
|
5527
5718
|
const dest = path.join(NODE_MODULES, pkg.name.split("/").join(path.sep));
|
|
5528
5719
|
if (fs.existsSync(dest)) fs.rmSync(dest, { recursive: true });
|
|
5529
5720
|
const dir = path.dirname(dest);
|
|
5530
5721
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
5531
5722
|
try {
|
|
5532
|
-
fs.symlinkSync(options
|
|
5723
|
+
fs.symlinkSync(options.path, dest, "dir");
|
|
5533
5724
|
} catch (error) {
|
|
5534
|
-
if (platform() === "win32" && (error.code === "EPERM" || error.code === "EACCES")) copyDirectorySync(options
|
|
5725
|
+
if (platform() === "win32" && (error.code === "EPERM" || error.code === "EACCES")) copyDirectorySync(options.path, dest);
|
|
5535
5726
|
else throw error;
|
|
5536
5727
|
}
|
|
5537
5728
|
return await importAddonCode(pkg.name);
|
|
@@ -5547,8 +5738,8 @@ async function downloadPackage(options$8) {
|
|
|
5547
5738
|
}
|
|
5548
5739
|
async function importAddonCode(pkgName) {
|
|
5549
5740
|
try {
|
|
5550
|
-
const { default: details
|
|
5551
|
-
return details
|
|
5741
|
+
const { default: details } = await import(`${pkgName}/sv`);
|
|
5742
|
+
return details;
|
|
5552
5743
|
} catch {}
|
|
5553
5744
|
const { default: details } = await import(pkgName);
|
|
5554
5745
|
return details;
|
|
@@ -5558,14 +5749,14 @@ async function getPackageJSON(ref) {
|
|
|
5558
5749
|
if (source.kind === "official") throw new Error(`Unexpected official addon in non-official getPackageJSON(): ${specifier}`);
|
|
5559
5750
|
if (source.kind === "file") {
|
|
5560
5751
|
const pkgJSONPath = path.resolve(source.path, "package.json");
|
|
5561
|
-
const json
|
|
5562
|
-
const pkg
|
|
5563
|
-
const warning
|
|
5752
|
+
const json = fs.readFileSync(pkgJSONPath, "utf8");
|
|
5753
|
+
const pkg = JSON.parse(json);
|
|
5754
|
+
const warning = verifyPackage(pkg, specifier);
|
|
5564
5755
|
return {
|
|
5565
5756
|
path: source.path,
|
|
5566
|
-
pkg
|
|
5757
|
+
pkg,
|
|
5567
5758
|
repo: source.path,
|
|
5568
|
-
warning
|
|
5759
|
+
warning
|
|
5569
5760
|
};
|
|
5570
5761
|
}
|
|
5571
5762
|
if ((await downloadJson("https://raw.githubusercontent.com/sveltejs/cli/refs/heads/main/packages/sv/blocklist.json")).npm_names.includes(source.packageName)) errorAndExit(`${color.warning(source.packageName)} blocked from being installed. If this is not the intended behavior please open an issue here: https://github.com/sveltejs/cli/issues.`);
|
|
@@ -5577,17 +5768,16 @@ async function getPackageJSON(ref) {
|
|
|
5577
5768
|
warning
|
|
5578
5769
|
};
|
|
5579
5770
|
}
|
|
5580
|
-
|
|
5581
5771
|
//#endregion
|
|
5582
5772
|
//#region src/core/verifiers.ts
|
|
5583
|
-
function verifyCleanWorkingDirectory(cwd
|
|
5773
|
+
function verifyCleanWorkingDirectory(cwd, gitCheck) {
|
|
5584
5774
|
const verifications = [];
|
|
5585
5775
|
if (gitCheck) verifications.push({
|
|
5586
5776
|
name: "clean working directory",
|
|
5587
5777
|
run: async () => {
|
|
5588
5778
|
try {
|
|
5589
|
-
const { stdout
|
|
5590
|
-
if (stdout
|
|
5779
|
+
const { stdout } = await promisify(exec)("git status --short", { cwd });
|
|
5780
|
+
if (stdout) return {
|
|
5591
5781
|
success: false,
|
|
5592
5782
|
message: "Found modified files"
|
|
5593
5783
|
};
|
|
@@ -5623,12 +5813,11 @@ function verifyUnsupportedAddons(addons, setupResults) {
|
|
|
5623
5813
|
});
|
|
5624
5814
|
return verifications;
|
|
5625
5815
|
}
|
|
5626
|
-
|
|
5627
5816
|
//#endregion
|
|
5628
5817
|
//#region src/core/workspace.ts
|
|
5629
|
-
async function createWorkspace({ cwd
|
|
5630
|
-
const resolvedCwd = path.resolve(cwd
|
|
5631
|
-
const typescript = any([commonFilePaths.jsconfig, commonFilePaths.tsconfig], { cwd
|
|
5818
|
+
async function createWorkspace({ cwd, packageManager, override }) {
|
|
5819
|
+
const resolvedCwd = path.resolve(cwd);
|
|
5820
|
+
const typescript = any([commonFilePaths.jsconfig, commonFilePaths.tsconfig], { cwd })?.endsWith(commonFilePaths.tsconfig) ?? false;
|
|
5632
5821
|
const viteConfigPath = path.join(resolvedCwd, commonFilePaths.viteConfigTS);
|
|
5633
5822
|
const viteConfig = fs.existsSync(viteConfigPath) ? commonFilePaths.viteConfigTS : commonFilePaths.viteConfig;
|
|
5634
5823
|
const svelteConfigPath = path.join(resolvedCwd, commonFilePaths.svelteConfigTS);
|
|
@@ -5657,7 +5846,7 @@ async function createWorkspace({ cwd: cwd$1, packageManager, override }) {
|
|
|
5657
5846
|
const stylesheet = kit ? `${kit.routesDirectory}/layout.css` : "src/app.css";
|
|
5658
5847
|
return {
|
|
5659
5848
|
cwd: resolvedCwd,
|
|
5660
|
-
packageManager: packageManager ?? await detectPackageManager(cwd
|
|
5849
|
+
packageManager: packageManager ?? await detectPackageManager(cwd),
|
|
5661
5850
|
language: typescript ? "ts" : "js",
|
|
5662
5851
|
files: {
|
|
5663
5852
|
viteConfig,
|
|
@@ -5681,9 +5870,9 @@ async function createWorkspace({ cwd: cwd$1, packageManager, override }) {
|
|
|
5681
5870
|
dependencyVersion: (pkg) => dependencies[pkg]
|
|
5682
5871
|
};
|
|
5683
5872
|
}
|
|
5684
|
-
function findWorkspaceRoot(cwd
|
|
5685
|
-
const { root } = path.parse(cwd
|
|
5686
|
-
let directory = cwd
|
|
5873
|
+
function findWorkspaceRoot(cwd) {
|
|
5874
|
+
const { root } = path.parse(cwd);
|
|
5875
|
+
let directory = cwd;
|
|
5687
5876
|
while (directory && directory !== root) {
|
|
5688
5877
|
if (fs.existsSync(path.join(directory, commonFilePaths.packageJson))) {
|
|
5689
5878
|
if (fs.existsSync(path.join(directory, "pnpm-workspace.yaml"))) return directory;
|
|
@@ -5694,10 +5883,10 @@ function findWorkspaceRoot(cwd$1) {
|
|
|
5694
5883
|
if (directory.includes(".test-output") && !parent.includes(".test-output")) break;
|
|
5695
5884
|
directory = parent;
|
|
5696
5885
|
}
|
|
5697
|
-
return cwd
|
|
5886
|
+
return cwd;
|
|
5698
5887
|
}
|
|
5699
|
-
function parseKitOptions(cwd
|
|
5700
|
-
const configSource = readFile(cwd
|
|
5888
|
+
function parseKitOptions(cwd, svelteConfigPath) {
|
|
5889
|
+
const configSource = readFile(cwd, svelteConfigPath);
|
|
5701
5890
|
const { ast } = parse.script(configSource);
|
|
5702
5891
|
const defaultExport = ast.body.find((s) => s.type === "ExportDefaultDeclaration");
|
|
5703
5892
|
if (!defaultExport) throw Error(`Missing default export in \`${svelteConfigPath}\``);
|
|
@@ -5734,7 +5923,6 @@ function parseKitOptions(cwd$1, svelteConfigPath) {
|
|
|
5734
5923
|
libDirectory: lib.value || "src/lib"
|
|
5735
5924
|
};
|
|
5736
5925
|
}
|
|
5737
|
-
|
|
5738
5926
|
//#endregion
|
|
5739
5927
|
//#region src/create/playground.ts
|
|
5740
5928
|
function validatePlaygroundUrl(link) {
|
|
@@ -5798,7 +5986,7 @@ function detectPlaygroundDependencies(files) {
|
|
|
5798
5986
|
ast = svelteAst.instance.content;
|
|
5799
5987
|
} else if (file.name.endsWith(".js") || file.name.endsWith(".ts")) ast = parse.script(file.content).ast;
|
|
5800
5988
|
if (!ast) continue;
|
|
5801
|
-
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
|
|
5989
|
+
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 }) => packages.set(pkgName, version));
|
|
5802
5990
|
}
|
|
5803
5991
|
return packages;
|
|
5804
5992
|
}
|
|
@@ -5815,36 +6003,36 @@ function extractPackageInfo(importPath) {
|
|
|
5815
6003
|
pkgName = `${org}/${pkg}`;
|
|
5816
6004
|
}
|
|
5817
6005
|
if (!pkgName) [pkgName] = importPath.split("/", 2);
|
|
5818
|
-
const version
|
|
5819
|
-
if (version
|
|
6006
|
+
const version = extractPackageVersion(pkgName);
|
|
6007
|
+
if (version !== "latest") pkgName = pkgName.replace(`@${version}`, "");
|
|
5820
6008
|
return {
|
|
5821
6009
|
pkgName,
|
|
5822
|
-
version
|
|
6010
|
+
version
|
|
5823
6011
|
};
|
|
5824
6012
|
}
|
|
5825
6013
|
function extractPackageVersion(pkgName) {
|
|
5826
|
-
let version
|
|
5827
|
-
if (pkgName.includes("@", 1)) [, version
|
|
5828
|
-
return version
|
|
6014
|
+
let version = "latest";
|
|
6015
|
+
if (pkgName.includes("@", 1)) [, version] = pkgName.split("@");
|
|
6016
|
+
return version;
|
|
5829
6017
|
}
|
|
5830
|
-
function setupPlaygroundProject(url, playground, cwd
|
|
6018
|
+
function setupPlaygroundProject(url, playground, cwd, installDependencies) {
|
|
5831
6019
|
const mainFile = playground.files.find((file) => file.name === "App.svelte");
|
|
5832
6020
|
if (!mainFile) throw new Error("Failed to find `App.svelte` entrypoint.");
|
|
5833
6021
|
const dependencies = detectPlaygroundDependencies(playground.files);
|
|
5834
6022
|
for (const file of playground.files) {
|
|
5835
|
-
for (const [pkg, version
|
|
5836
|
-
const filePath
|
|
5837
|
-
fs.mkdirSync(path.dirname(filePath
|
|
5838
|
-
fs.writeFileSync(filePath
|
|
6023
|
+
for (const [pkg, version] of dependencies) if (version !== "latest") file.content = file.content.replaceAll(`${pkg}@${version}`, pkg);
|
|
6024
|
+
const filePath = path.join(cwd, "src", "lib", "playground", file.name);
|
|
6025
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
6026
|
+
fs.writeFileSync(filePath, file.content, "utf8");
|
|
5839
6027
|
}
|
|
5840
6028
|
{
|
|
5841
6029
|
const playgroundFiles = getSharedFiles().filter((file) => file.include.includes("playground"));
|
|
5842
6030
|
for (const file of playgroundFiles) {
|
|
5843
6031
|
let contentToWrite = file.contents;
|
|
5844
6032
|
if (file.name === "src/lib/PlaygroundLayout.svelte") {
|
|
5845
|
-
const { ast
|
|
5846
|
-
svelte.ensureScript(ast
|
|
5847
|
-
Walker.walk(ast
|
|
6033
|
+
const { ast, generateCode } = parse.svelte(file.contents);
|
|
6034
|
+
svelte.ensureScript(ast);
|
|
6035
|
+
Walker.walk(ast.instance.content, null, { Literal(node) {
|
|
5848
6036
|
if (node.value === "$sv-title-$sv") {
|
|
5849
6037
|
node.value = playground.name;
|
|
5850
6038
|
node.raw = void 0;
|
|
@@ -5853,12 +6041,12 @@ function setupPlaygroundProject(url, playground, cwd$1, installDependencies$1) {
|
|
|
5853
6041
|
node.raw = void 0;
|
|
5854
6042
|
}
|
|
5855
6043
|
} });
|
|
5856
|
-
contentToWrite = generateCode
|
|
6044
|
+
contentToWrite = generateCode();
|
|
5857
6045
|
}
|
|
5858
|
-
fs.writeFileSync(path.join(cwd
|
|
6046
|
+
fs.writeFileSync(path.join(cwd, file.name), contentToWrite, "utf-8");
|
|
5859
6047
|
}
|
|
5860
6048
|
}
|
|
5861
|
-
const filePath = path.join(cwd
|
|
6049
|
+
const filePath = path.join(cwd, "src/routes/+page.svelte");
|
|
5862
6050
|
const content = fs.readFileSync(filePath, "utf-8");
|
|
5863
6051
|
const { ast, generateCode } = parse.svelte(content);
|
|
5864
6052
|
svelte.ensureScript(ast);
|
|
@@ -5875,37 +6063,36 @@ function setupPlaygroundProject(url, playground, cwd$1, installDependencies$1) {
|
|
|
5875
6063
|
</PlaygroundLayout>`);
|
|
5876
6064
|
const newContent = generateCode();
|
|
5877
6065
|
fs.writeFileSync(filePath, newContent, "utf-8");
|
|
5878
|
-
const pkgPath = path.join(cwd
|
|
6066
|
+
const pkgPath = path.join(cwd, commonFilePaths.packageJson);
|
|
5879
6067
|
const pkgSource = fs.readFileSync(pkgPath, "utf-8");
|
|
5880
6068
|
const pkgJson = parse.json(pkgSource);
|
|
5881
6069
|
let updatePackageJson = false;
|
|
5882
|
-
if (installDependencies
|
|
6070
|
+
if (installDependencies && dependencies.size >= 0) {
|
|
5883
6071
|
updatePackageJson = true;
|
|
5884
6072
|
pkgJson.data.dependencies ??= {};
|
|
5885
|
-
for (const [dep, version
|
|
6073
|
+
for (const [dep, version] of dependencies) pkgJson.data.dependencies[dep] = version;
|
|
5886
6074
|
}
|
|
5887
6075
|
let experimentalAsyncNeeded = true;
|
|
5888
6076
|
const addExperimentalAsync = () => {
|
|
5889
|
-
const svelteConfigPath = path.join(cwd
|
|
6077
|
+
const svelteConfigPath = path.join(cwd, commonFilePaths.svelteConfig);
|
|
5890
6078
|
const svelteConfig = fs.readFileSync(svelteConfigPath, "utf-8");
|
|
5891
|
-
const { ast
|
|
5892
|
-
const { value: config } = js.exports.createDefault(ast
|
|
6079
|
+
const { ast, generateCode } = parse.script(svelteConfig);
|
|
6080
|
+
const { value: config } = js.exports.createDefault(ast, { fallback: js.object.create({}) });
|
|
5893
6081
|
js.object.overrideProperties(config, { compilerOptions: { experimental: { async: true } } });
|
|
5894
|
-
fs.writeFileSync(svelteConfigPath, generateCode
|
|
6082
|
+
fs.writeFileSync(svelteConfigPath, generateCode(), "utf-8");
|
|
5895
6083
|
};
|
|
5896
6084
|
if (playground.svelteVersion) {
|
|
5897
6085
|
updatePackageJson = true;
|
|
5898
6086
|
const match = /^(pr|commit|branch)-(.+)/.exec(playground.svelteVersion);
|
|
5899
|
-
const version
|
|
5900
|
-
pkgJson.data.devDependencies["svelte"] = version
|
|
5901
|
-
if (!version
|
|
5902
|
-
if (isVersionUnsupportedBelow(version
|
|
6087
|
+
const version = match ? `https://pkg.pr.new/svelte@${match[2]}` : `${playground.svelteVersion}`;
|
|
6088
|
+
pkgJson.data.devDependencies["svelte"] = version;
|
|
6089
|
+
if (!version.includes("pkg.pr.new")) {
|
|
6090
|
+
if (isVersionUnsupportedBelow(version, "5.36")) experimentalAsyncNeeded = false;
|
|
5903
6091
|
}
|
|
5904
6092
|
}
|
|
5905
6093
|
if (experimentalAsyncNeeded) addExperimentalAsync();
|
|
5906
6094
|
if (updatePackageJson) fs.writeFileSync(pkgPath, pkgJson.generateCode(), "utf-8");
|
|
5907
6095
|
}
|
|
5908
|
-
|
|
5909
6096
|
//#endregion
|
|
5910
6097
|
//#region src/cli/create.ts
|
|
5911
6098
|
const langs = ["ts", "jsdoc"];
|
|
@@ -5918,29 +6105,54 @@ const templateChoices = templates.map((t) => t.name);
|
|
|
5918
6105
|
const langOption = new Option("--types <lang>", "add type checking").choices(langs);
|
|
5919
6106
|
const templateOption = new Option("--template <type>", "template to scaffold").choices(templateChoices);
|
|
5920
6107
|
const noAddonsOption = new Option("--no-add-ons", "do not prompt to add add-ons").conflicts("add");
|
|
5921
|
-
const addOption = new Option("--add <addon...>", "add-
|
|
6108
|
+
const addOption = new Option("--add <addon...>", "add-ons to include (see Add-Ons section below)").default([]);
|
|
5922
6109
|
const noDownloadCheckOption = new Option("--no-download-check", "skip all download confirmation prompts");
|
|
5923
6110
|
const noInstallOption = new Option("--no-install", "skip installing dependencies");
|
|
5924
|
-
const ProjectPathSchema = optional(string());
|
|
5925
|
-
const OptionsSchema$1 = strictObject({
|
|
5926
|
-
types: pipe(optional(union([picklist(langs), boolean()])), transform((lang) => langMap[String(lang)])),
|
|
5927
|
-
addOns: boolean(),
|
|
5928
|
-
add: array(string()),
|
|
5929
|
-
install: union([boolean(), picklist(AGENT_NAMES)]),
|
|
5930
|
-
template: optional(picklist(templateChoices)),
|
|
5931
|
-
fromPlayground: optional(string()),
|
|
5932
|
-
dirCheck: boolean(),
|
|
5933
|
-
downloadCheck: boolean()
|
|
6111
|
+
const ProjectPathSchema = /* @__PURE__ */ optional(/* @__PURE__ */ string());
|
|
6112
|
+
const OptionsSchema$1 = /* @__PURE__ */ strictObject({
|
|
6113
|
+
types: /* @__PURE__ */ pipe(/* @__PURE__ */ optional(/* @__PURE__ */ union([/* @__PURE__ */ picklist(langs), /* @__PURE__ */ boolean()])), /* @__PURE__ */ transform((lang) => langMap[String(lang)])),
|
|
6114
|
+
addOns: /* @__PURE__ */ boolean(),
|
|
6115
|
+
add: /* @__PURE__ */ array(/* @__PURE__ */ string()),
|
|
6116
|
+
install: /* @__PURE__ */ union([/* @__PURE__ */ boolean(), /* @__PURE__ */ picklist(AGENT_NAMES)]),
|
|
6117
|
+
template: /* @__PURE__ */ optional(/* @__PURE__ */ picklist(templateChoices)),
|
|
6118
|
+
fromPlayground: /* @__PURE__ */ optional(/* @__PURE__ */ string()),
|
|
6119
|
+
dirCheck: /* @__PURE__ */ boolean(),
|
|
6120
|
+
downloadCheck: /* @__PURE__ */ boolean()
|
|
5934
6121
|
});
|
|
5935
|
-
const create = new Command("create").description("
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
6122
|
+
const create = new Command("create").description("Scaffold a new project (--add to include add-ons)").argument("[path]", "where the project will be created").addOption(templateOption).addOption(langOption).option("--no-types").addOption(noAddonsOption).addOption(addOption).addOption(noInstallOption).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(noDownloadCheckOption).addOption(installOption).configureHelp({
|
|
6123
|
+
...helpConfig,
|
|
6124
|
+
formatHelp(cmd, helper) {
|
|
6125
|
+
const s = getHelpSections(cmd, helper);
|
|
6126
|
+
const addonSection = formatAddonHelpSection({
|
|
6127
|
+
styleTitle: s.styleTitle,
|
|
6128
|
+
formatItem: (term, desc) => s.formatItem(helper.styleArgumentTerm(term), helper.styleArgumentDescription(desc))
|
|
6129
|
+
});
|
|
6130
|
+
return [
|
|
6131
|
+
...s.usage,
|
|
6132
|
+
...s.description,
|
|
6133
|
+
...s.arguments,
|
|
6134
|
+
...s.options,
|
|
6135
|
+
...addonSection,
|
|
6136
|
+
s.styleTitle("Non-interactive usage:"),
|
|
6137
|
+
" Provide --template, --types, --add, and --install (or --no-install) to skip prompts entirely.",
|
|
6138
|
+
" Note: --add and --no-add-ons cannot be used together.",
|
|
6139
|
+
"",
|
|
6140
|
+
s.styleTitle("Examples:"),
|
|
6141
|
+
" sv create my-app --template minimal --types ts --add prettier eslint --install pnpm",
|
|
6142
|
+
" sv create my-app --template minimal --types ts --add prettier vitest=\"usages:unit\" tailwindcss=\"plugins:none\" --install pnpm",
|
|
6143
|
+
" sv create my-app --template minimal --types ts --add drizzle=\"database:postgresql+client:postgres.js\" --no-install",
|
|
6144
|
+
""
|
|
6145
|
+
].join("\n");
|
|
6146
|
+
}
|
|
6147
|
+
}).action((projectPath, opts) => {
|
|
6148
|
+
const cwd = parse$1(ProjectPathSchema, projectPath);
|
|
6149
|
+
const options = parse$1(OptionsSchema$1, opts);
|
|
6150
|
+
if (options.fromPlayground && !validatePlaygroundUrl(options.fromPlayground)) {
|
|
6151
|
+
console.error(color.error(`Error: Invalid playground URL: ${options.fromPlayground}`));
|
|
5940
6152
|
process$1.exit(1);
|
|
5941
6153
|
}
|
|
5942
6154
|
runCommand(async () => {
|
|
5943
|
-
const { directory, addOnNextSteps, packageManager } = await createProject(cwd
|
|
6155
|
+
const { directory, addOnNextSteps, packageManager } = await createProject(cwd, options);
|
|
5944
6156
|
let i = 1;
|
|
5945
6157
|
const initialSteps = ["📁 Project steps", ""];
|
|
5946
6158
|
const relative = path.relative(process$1.cwd(), directory);
|
|
@@ -5950,8 +6162,8 @@ const create = new Command("create").description("scaffolds a new SvelteKit proj
|
|
|
5950
6162
|
initialSteps.push(` ${i++}: ${color.command(`cd ${pathHasSpaces ? `"${relative}"` : relative}`)}`);
|
|
5951
6163
|
}
|
|
5952
6164
|
if (!packageManager) {
|
|
5953
|
-
const { args
|
|
5954
|
-
initialSteps.push(` ${i++}: ${color.command(`${command
|
|
6165
|
+
const { args, command } = resolveCommand(pm, "install", []);
|
|
6166
|
+
initialSteps.push(` ${i++}: ${color.command(`${command} ${args.join(" ")}`)}`);
|
|
5955
6167
|
}
|
|
5956
6168
|
const { args, command } = resolveCommand(pm, "run", ["dev", "--open"]);
|
|
5957
6169
|
const pmRunCmd = `${command} ${args.join(" ")}`;
|
|
@@ -5972,22 +6184,22 @@ const create = new Command("create").description("scaffolds a new SvelteKit proj
|
|
|
5972
6184
|
kt(steps.join("\n"), "What's next?", { format: (line) => line });
|
|
5973
6185
|
});
|
|
5974
6186
|
}).showHelpAfterError(true);
|
|
5975
|
-
async function createProject(cwd
|
|
5976
|
-
if (options
|
|
6187
|
+
async function createProject(cwd, options) {
|
|
6188
|
+
if (options.fromPlayground) R.warn("Svelte maintainers have not reviewed playgrounds for malicious code. Use at your discretion.");
|
|
5977
6189
|
const promptGroupResult = await Rt({
|
|
5978
6190
|
directory: () => {
|
|
5979
6191
|
const defaultPath = "./";
|
|
5980
|
-
if (cwd
|
|
6192
|
+
if (cwd) return Promise.resolve(normalizePosix(cwd));
|
|
5981
6193
|
return Qt({
|
|
5982
6194
|
message: "Where would you like your project to be created?",
|
|
5983
6195
|
placeholder: ` (hit Enter to use '${defaultPath}')`,
|
|
5984
6196
|
defaultValue: defaultPath
|
|
5985
6197
|
});
|
|
5986
6198
|
},
|
|
5987
|
-
force: async ({ results: { directory
|
|
5988
|
-
if (!options
|
|
5989
|
-
if (!fs.existsSync(directory
|
|
5990
|
-
if (!fs.readdirSync(directory
|
|
6199
|
+
force: async ({ results: { directory } }) => {
|
|
6200
|
+
if (!options.dirCheck) return;
|
|
6201
|
+
if (!fs.existsSync(directory)) return;
|
|
6202
|
+
if (!fs.readdirSync(directory).some((file) => !file.startsWith(".git"))) return;
|
|
5991
6203
|
const force = await Mt({
|
|
5992
6204
|
message: "Directory not empty. Continue?",
|
|
5993
6205
|
initialValue: false
|
|
@@ -5998,13 +6210,12 @@ async function createProject(cwd$1, options$8) {
|
|
|
5998
6210
|
}
|
|
5999
6211
|
},
|
|
6000
6212
|
template: () => {
|
|
6001
|
-
if (options
|
|
6002
|
-
if (options
|
|
6003
|
-
const availableTemplates = templates.filter((t) => t.name !== "addon");
|
|
6213
|
+
if (options.template) return Promise.resolve(options.template);
|
|
6214
|
+
if (options.fromPlayground) return Promise.resolve("minimal");
|
|
6004
6215
|
return qt({
|
|
6005
6216
|
message: "Which template would you like?",
|
|
6006
6217
|
initialValue: "minimal",
|
|
6007
|
-
options:
|
|
6218
|
+
options: templates.filter((t) => t.name !== "addon").map((t) => ({
|
|
6008
6219
|
label: t.title,
|
|
6009
6220
|
value: t.name,
|
|
6010
6221
|
hint: t.description
|
|
@@ -6012,7 +6223,7 @@ async function createProject(cwd$1, options$8) {
|
|
|
6012
6223
|
});
|
|
6013
6224
|
},
|
|
6014
6225
|
language: (o) => {
|
|
6015
|
-
if (options
|
|
6226
|
+
if (options.types) return Promise.resolve(options.types);
|
|
6016
6227
|
if (o.results.template === "addon") return Promise.resolve("none");
|
|
6017
6228
|
return qt({
|
|
6018
6229
|
message: "Add type checking with TypeScript?",
|
|
@@ -6043,7 +6254,7 @@ async function createProject(cwd$1, options$8) {
|
|
|
6043
6254
|
const basename = path.basename(projectPath);
|
|
6044
6255
|
const parentDirName = path.basename(path.dirname(projectPath));
|
|
6045
6256
|
const projectName = parentDirName.startsWith("@") ? `${parentDirName}/${basename}` : basename;
|
|
6046
|
-
if (template === "addon" && options
|
|
6257
|
+
if (template === "addon" && options.add.length > 0) errorAndExit(`The ${color.command("--add")} flag cannot be used with the ${color.command("addon")} template.`);
|
|
6047
6258
|
let loadedAddons = [];
|
|
6048
6259
|
let answers = {};
|
|
6049
6260
|
let addonsOptionsMap = {};
|
|
@@ -6052,8 +6263,8 @@ async function createProject(cwd$1, options$8) {
|
|
|
6052
6263
|
template,
|
|
6053
6264
|
type: language
|
|
6054
6265
|
});
|
|
6055
|
-
if (template !== "addon" && (options
|
|
6056
|
-
loadedAddons = await resolveAddons(classifyAddons(options
|
|
6266
|
+
if (template !== "addon" && (options.addOns || options.add.length > 0)) {
|
|
6267
|
+
loadedAddons = await resolveAddons(classifyAddons(options.add.reduce(addonArgsHandler, []), projectPath), options.downloadCheck);
|
|
6057
6268
|
addonsOptionsMap = {};
|
|
6058
6269
|
for (const loaded of loadedAddons) addonsOptionsMap[loaded.addon.id] = loaded.reference.options;
|
|
6059
6270
|
const result = await promptAddonQuestions({
|
|
@@ -6061,7 +6272,7 @@ async function createProject(cwd$1, options$8) {
|
|
|
6061
6272
|
cwd: projectPath,
|
|
6062
6273
|
install: false,
|
|
6063
6274
|
gitCheck: false,
|
|
6064
|
-
downloadCheck: options
|
|
6275
|
+
downloadCheck: options.downloadCheck,
|
|
6065
6276
|
addons: addonsOptionsMap
|
|
6066
6277
|
},
|
|
6067
6278
|
loadedAddons,
|
|
@@ -6075,19 +6286,19 @@ async function createProject(cwd$1, options$8) {
|
|
|
6075
6286
|
template,
|
|
6076
6287
|
types: language
|
|
6077
6288
|
});
|
|
6078
|
-
if (options
|
|
6289
|
+
if (options.fromPlayground) await createProjectFromPlayground(options.fromPlayground, projectPath);
|
|
6079
6290
|
R.success("Project created");
|
|
6080
6291
|
let argsFormattedAddons = [];
|
|
6081
6292
|
let addOnFilesToFormat = [];
|
|
6082
6293
|
let addOnSuccessfulAddons = [];
|
|
6083
|
-
if (template !== "addon" && (options
|
|
6084
|
-
const { argsFormattedAddons: argsFormatted
|
|
6294
|
+
if (template !== "addon" && (options.addOns || options.add.length > 0)) {
|
|
6295
|
+
const { argsFormattedAddons: argsFormatted, filesToFormat, successfulAddons } = await runAddonsApply({
|
|
6085
6296
|
answers,
|
|
6086
6297
|
options: {
|
|
6087
6298
|
cwd: projectPath,
|
|
6088
6299
|
install: false,
|
|
6089
6300
|
gitCheck: false,
|
|
6090
|
-
downloadCheck: options
|
|
6301
|
+
downloadCheck: options.downloadCheck,
|
|
6091
6302
|
addons: addonsOptionsMap
|
|
6092
6303
|
},
|
|
6093
6304
|
loadedAddons,
|
|
@@ -6095,19 +6306,18 @@ async function createProject(cwd$1, options$8) {
|
|
|
6095
6306
|
workspace,
|
|
6096
6307
|
fromCommand: "create"
|
|
6097
6308
|
});
|
|
6098
|
-
argsFormattedAddons = argsFormatted
|
|
6309
|
+
argsFormattedAddons = argsFormatted;
|
|
6099
6310
|
addOnFilesToFormat = filesToFormat;
|
|
6100
6311
|
addOnSuccessfulAddons = successfulAddons;
|
|
6101
6312
|
}
|
|
6102
|
-
const packageManager = options
|
|
6313
|
+
const packageManager = options.install === false ? null : options.install === true ? await packageManagerPrompt(projectPath) : options.install;
|
|
6103
6314
|
const argsFormatted = [];
|
|
6104
6315
|
argsFormatted.push("--template", template);
|
|
6105
6316
|
if (language === "typescript") argsFormatted.push("--types", "ts");
|
|
6106
6317
|
else if (language === "checkjs") argsFormatted.push("--types", "jsdoc");
|
|
6107
6318
|
else if (language === "none") argsFormatted.push("--no-types");
|
|
6108
6319
|
if (argsFormattedAddons.length > 0) argsFormatted.push("--add", ...argsFormattedAddons);
|
|
6109
|
-
|
|
6110
|
-
updateReadme(directory, prompt);
|
|
6320
|
+
updateReadme(directory, buildAndLogArgs(packageManager, "create", argsFormatted, [directory]));
|
|
6111
6321
|
updateAgent(directory, language, packageManager ?? "npm", loadedAddons);
|
|
6112
6322
|
if (packageManager) workspace.packageManager = packageManager;
|
|
6113
6323
|
const addOnNextSteps = getNextSteps(addOnSuccessfulAddons, workspace, answers);
|
|
@@ -6126,10 +6336,10 @@ async function createProject(cwd$1, options$8) {
|
|
|
6126
6336
|
packageManager
|
|
6127
6337
|
};
|
|
6128
6338
|
}
|
|
6129
|
-
async function createProjectFromPlayground(url, cwd
|
|
6339
|
+
async function createProjectFromPlayground(url, cwd) {
|
|
6130
6340
|
const playground = await downloadPlaygroundData(parsePlaygroundUrl(url));
|
|
6131
6341
|
const dependencies = detectPlaygroundDependencies(playground.files);
|
|
6132
|
-
setupPlaygroundProject(url, playground, cwd
|
|
6342
|
+
setupPlaygroundProject(url, playground, cwd, await confirmExternalDependencies(Array.from(dependencies.keys())));
|
|
6133
6343
|
}
|
|
6134
6344
|
async function confirmExternalDependencies(dependencies) {
|
|
6135
6345
|
if (dependencies.length === 0) return false;
|
|
@@ -6145,7 +6355,7 @@ async function confirmExternalDependencies(dependencies) {
|
|
|
6145
6355
|
}
|
|
6146
6356
|
return installDeps;
|
|
6147
6357
|
}
|
|
6148
|
-
async function createVirtualWorkspace({ cwd
|
|
6358
|
+
async function createVirtualWorkspace({ cwd, template, type }) {
|
|
6149
6359
|
const override = { dependencies: {} };
|
|
6150
6360
|
if (template === "minimal" || template === "demo" || template === "library") override.kit = {
|
|
6151
6361
|
routesDirectory: "src/routes",
|
|
@@ -6158,7 +6368,7 @@ async function createVirtualWorkspace({ cwd: cwd$1, template, type }) {
|
|
|
6158
6368
|
...override.dependencies
|
|
6159
6369
|
};
|
|
6160
6370
|
const tentativeWorkspace = await createWorkspace({
|
|
6161
|
-
cwd
|
|
6371
|
+
cwd,
|
|
6162
6372
|
override
|
|
6163
6373
|
});
|
|
6164
6374
|
return {
|
|
@@ -6171,22 +6381,21 @@ async function createVirtualWorkspace({ cwd: cwd$1, template, type }) {
|
|
|
6171
6381
|
}
|
|
6172
6382
|
};
|
|
6173
6383
|
}
|
|
6174
|
-
|
|
6175
6384
|
//#endregion
|
|
6176
6385
|
//#region src/cli/add.ts
|
|
6177
6386
|
const officialAddons = Object.values(officialAddons$1);
|
|
6178
6387
|
const addonOptions = getAddonOptionFlags();
|
|
6179
|
-
const OptionsSchema = strictObject({
|
|
6180
|
-
cwd: string(),
|
|
6181
|
-
install: union([boolean(), picklist(AGENT_NAMES)]),
|
|
6182
|
-
gitCheck: boolean(),
|
|
6183
|
-
downloadCheck: boolean(),
|
|
6184
|
-
addons: record(string(), optional(array(string())))
|
|
6388
|
+
const OptionsSchema = /* @__PURE__ */ strictObject({
|
|
6389
|
+
cwd: /* @__PURE__ */ string(),
|
|
6390
|
+
install: /* @__PURE__ */ union([/* @__PURE__ */ boolean(), /* @__PURE__ */ picklist(AGENT_NAMES)]),
|
|
6391
|
+
gitCheck: /* @__PURE__ */ boolean(),
|
|
6392
|
+
downloadCheck: /* @__PURE__ */ boolean(),
|
|
6393
|
+
addons: /* @__PURE__ */ record(/* @__PURE__ */ string(), /* @__PURE__ */ optional(/* @__PURE__ */ array(/* @__PURE__ */ string())))
|
|
6185
6394
|
});
|
|
6186
6395
|
/**
|
|
6187
6396
|
* Classifies addon inputs into AddonReferences with source information.
|
|
6188
6397
|
*/
|
|
6189
|
-
function classifyAddons(inputs, cwd
|
|
6398
|
+
function classifyAddons(inputs, cwd) {
|
|
6190
6399
|
const seen = /* @__PURE__ */ new Map();
|
|
6191
6400
|
const invalidAddons = [];
|
|
6192
6401
|
for (const input of inputs) {
|
|
@@ -6209,7 +6418,7 @@ function classifyAddons(inputs, cwd$1) {
|
|
|
6209
6418
|
}
|
|
6210
6419
|
const source = {
|
|
6211
6420
|
kind: "file",
|
|
6212
|
-
path: path.resolve(cwd
|
|
6421
|
+
path: path.resolve(cwd, relativePath)
|
|
6213
6422
|
};
|
|
6214
6423
|
seen.set(input.specifier, {
|
|
6215
6424
|
specifier: input.specifier,
|
|
@@ -6222,13 +6431,13 @@ function classifyAddons(inputs, cwd$1) {
|
|
|
6222
6431
|
let tag;
|
|
6223
6432
|
if (normalized.startsWith("@")) {
|
|
6224
6433
|
const slashIndex = normalized.indexOf("/");
|
|
6225
|
-
const [name
|
|
6226
|
-
packageName = normalized.slice(0, slashIndex + 1) + name
|
|
6227
|
-
tag = version
|
|
6434
|
+
const [name, version = "latest"] = normalized.slice(slashIndex + 1).split("@");
|
|
6435
|
+
packageName = normalized.slice(0, slashIndex + 1) + name;
|
|
6436
|
+
tag = version;
|
|
6228
6437
|
} else {
|
|
6229
|
-
const [name
|
|
6230
|
-
packageName = name
|
|
6231
|
-
tag = version
|
|
6438
|
+
const [name, version = "latest"] = normalized.split("@");
|
|
6439
|
+
packageName = name;
|
|
6440
|
+
tag = version;
|
|
6232
6441
|
}
|
|
6233
6442
|
const npmUrl = `https://www.npmjs.com/package/${packageName}`;
|
|
6234
6443
|
const registryUrl = `https://registry.npmjs.org/${packageName}/${tag}`;
|
|
@@ -6270,82 +6479,49 @@ const defaultCwd = defaultPkgPath ? path.dirname(defaultPkgPath) : void 0;
|
|
|
6270
6479
|
const add$1 = 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").addOption(noDownloadCheckOption).addOption(noInstallOption).addOption(installOption).configureHelp({
|
|
6271
6480
|
...helpConfig,
|
|
6272
6481
|
formatHelp(cmd, helper) {
|
|
6273
|
-
const
|
|
6274
|
-
const
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
}
|
|
6278
|
-
let output = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
|
|
6279
|
-
const commandDescription = helper.commandDescription(cmd);
|
|
6280
|
-
if (commandDescription.length > 0) output = output.concat([helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth), ""]);
|
|
6281
|
-
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
6282
|
-
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
6283
|
-
});
|
|
6284
|
-
if (argumentList.length > 0) output = output.concat([
|
|
6285
|
-
helper.styleTitle("Arguments:"),
|
|
6286
|
-
...argumentList,
|
|
6287
|
-
""
|
|
6288
|
-
]);
|
|
6289
|
-
const addonList = addonOptions.map((option) => {
|
|
6290
|
-
const description = option.choices;
|
|
6291
|
-
return callFormatItem(helper.styleArgumentTerm(option.id), helper.styleArgumentDescription(description));
|
|
6292
|
-
});
|
|
6293
|
-
if (addonList.length > 0) output = output.concat([
|
|
6294
|
-
helper.styleTitle("Add-On Options:"),
|
|
6295
|
-
...addonList,
|
|
6296
|
-
""
|
|
6297
|
-
]);
|
|
6298
|
-
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
6299
|
-
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
6482
|
+
const s = getHelpSections(cmd, helper);
|
|
6483
|
+
const addonSection = formatAddonHelpSection({
|
|
6484
|
+
styleTitle: s.styleTitle,
|
|
6485
|
+
formatItem: (term, desc) => s.formatItem(helper.styleArgumentTerm(term), helper.styleArgumentDescription(desc))
|
|
6300
6486
|
});
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
...
|
|
6487
|
+
return [
|
|
6488
|
+
...s.usage,
|
|
6489
|
+
...s.description,
|
|
6490
|
+
...s.arguments,
|
|
6491
|
+
...addonSection,
|
|
6492
|
+
...s.options,
|
|
6493
|
+
...s.globalOptions,
|
|
6494
|
+
...s.commands,
|
|
6495
|
+
s.styleTitle("Examples:"),
|
|
6496
|
+
" sv add prettier eslint",
|
|
6497
|
+
" sv add vitest=\"usages:unit\" tailwindcss=\"plugins:none\"",
|
|
6498
|
+
" sv add drizzle=\"database:postgresql+client:postgres.js+docker:yes\"",
|
|
6304
6499
|
""
|
|
6305
|
-
]);
|
|
6306
|
-
if (helper.showGlobalOptions) {
|
|
6307
|
-
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
6308
|
-
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
6309
|
-
});
|
|
6310
|
-
if (globalOptionList.length > 0) output = output.concat([
|
|
6311
|
-
helper.styleTitle("Global Options:"),
|
|
6312
|
-
...globalOptionList,
|
|
6313
|
-
""
|
|
6314
|
-
]);
|
|
6315
|
-
}
|
|
6316
|
-
const commandList = helper.visibleCommands(cmd).map((cmd$1) => {
|
|
6317
|
-
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(cmd$1)), helper.styleSubcommandDescription(helper.subcommandDescription(cmd$1)));
|
|
6318
|
-
});
|
|
6319
|
-
if (commandList.length > 0) output = output.concat([
|
|
6320
|
-
helper.styleTitle("Commands:"),
|
|
6321
|
-
...commandList,
|
|
6322
|
-
""
|
|
6323
|
-
]);
|
|
6324
|
-
return output.join("\n");
|
|
6500
|
+
].join("\n");
|
|
6325
6501
|
}
|
|
6326
6502
|
}).action(async (addonInputs, opts) => {
|
|
6327
6503
|
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>`");
|
|
6328
6504
|
else if (!fs.existsSync(path.resolve(opts.cwd, "package.json"))) errorAndExit(`Invalid workspace: Path '${path.resolve(opts.cwd)}' is not a valid workspace.`);
|
|
6329
|
-
const options
|
|
6505
|
+
const options = parse$1(OptionsSchema, {
|
|
6330
6506
|
...opts,
|
|
6331
6507
|
addons: {}
|
|
6332
6508
|
});
|
|
6333
|
-
const addonRefs = classifyAddons(addonInputs, options
|
|
6334
|
-
const workspace = await createWorkspace({ cwd: options
|
|
6509
|
+
const addonRefs = classifyAddons(addonInputs, options.cwd);
|
|
6510
|
+
const workspace = await createWorkspace({ cwd: options.cwd });
|
|
6335
6511
|
runCommand(async () => {
|
|
6336
|
-
const loadedAddons = await resolveAddons(addonRefs, options
|
|
6512
|
+
const loadedAddons = await resolveAddons(addonRefs, options.downloadCheck);
|
|
6337
6513
|
for (const loaded of loadedAddons) {
|
|
6338
6514
|
const id = loaded.addon.id;
|
|
6339
|
-
options
|
|
6515
|
+
options.addons[id] = loaded.reference.options;
|
|
6340
6516
|
}
|
|
6341
6517
|
const { answers, loadedAddons: finalAddons } = await promptAddonQuestions({
|
|
6342
|
-
options
|
|
6518
|
+
options,
|
|
6343
6519
|
loadedAddons,
|
|
6344
6520
|
workspace
|
|
6345
6521
|
});
|
|
6346
6522
|
const { nextSteps } = await runAddonsApply({
|
|
6347
6523
|
answers,
|
|
6348
|
-
options
|
|
6524
|
+
options,
|
|
6349
6525
|
loadedAddons: finalAddons,
|
|
6350
6526
|
workspace,
|
|
6351
6527
|
fromCommand: "add"
|
|
@@ -6381,15 +6557,15 @@ async function resolveAddons(refs, downloadCheck) {
|
|
|
6381
6557
|
}
|
|
6382
6558
|
return loaded;
|
|
6383
6559
|
}
|
|
6384
|
-
async function promptAddonQuestions({ options
|
|
6560
|
+
async function promptAddonQuestions({ options, loadedAddons, workspace }) {
|
|
6385
6561
|
const addons = [...loadedAddons];
|
|
6386
6562
|
const emptyAnswersReducer = (acc, id) => {
|
|
6387
6563
|
acc[id] = {};
|
|
6388
6564
|
return acc;
|
|
6389
6565
|
};
|
|
6390
6566
|
const answers = addons.map((a) => a.addon.id).reduce(emptyAnswersReducer, {});
|
|
6391
|
-
for (const addonId of Object.keys(options
|
|
6392
|
-
const specifiedOptions = options
|
|
6567
|
+
for (const addonId of Object.keys(options.addons)) {
|
|
6568
|
+
const specifiedOptions = options.addons[addonId];
|
|
6393
6569
|
if (!specifiedOptions) continue;
|
|
6394
6570
|
const details = addons.find((a) => a.addon.id === addonId)?.addon;
|
|
6395
6571
|
if (!details) continue;
|
|
@@ -6399,15 +6575,15 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6399
6575
|
if (specifiedOptions.length > 0) {
|
|
6400
6576
|
for (const option of specifiedOptions) {
|
|
6401
6577
|
const [optionId, optionValue] = option.split(":", 2);
|
|
6402
|
-
const optionEntry = optionEntries.find(([id, question
|
|
6578
|
+
const optionEntry = optionEntries.find(([id, question]) => {
|
|
6403
6579
|
if (id === optionId) return true;
|
|
6404
|
-
if (question
|
|
6405
|
-
if (question
|
|
6406
|
-
if (!question
|
|
6407
|
-
} else if (question
|
|
6408
|
-
if (!(optionValue === "none" ? [] : optionValue.split(",")).every((val) => question
|
|
6580
|
+
if (question.group === optionId) {
|
|
6581
|
+
if (question.type === "select") {
|
|
6582
|
+
if (!question.options.some((opt) => opt.value === optionValue)) return false;
|
|
6583
|
+
} else if (question.type === "multiselect") {
|
|
6584
|
+
if (!(optionValue === "none" ? [] : optionValue.split(",")).every((val) => question.options.some((opt) => opt.value === val.trim()))) return false;
|
|
6409
6585
|
}
|
|
6410
|
-
if (question
|
|
6586
|
+
if (question.condition) return question.condition(specifiedOptionsObject);
|
|
6411
6587
|
return true;
|
|
6412
6588
|
}
|
|
6413
6589
|
return false;
|
|
@@ -6446,14 +6622,14 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6446
6622
|
if (addons.length > 0) setupResults = setupAddons(addons, workspace);
|
|
6447
6623
|
if (addons.length === 0) {
|
|
6448
6624
|
const results = setupAddons(officialAddons.map((a) => createLoadedAddon(a)), workspace);
|
|
6449
|
-
const addonOptions
|
|
6625
|
+
const addonOptions = officialAddons.filter(({ id, hidden }) => results[id].unsupported.length === 0 && !hidden).map(({ id, homepage, shortDescription }) => ({
|
|
6450
6626
|
label: id,
|
|
6451
6627
|
value: id,
|
|
6452
6628
|
hint: `${shortDescription} - ${homepage}`
|
|
6453
6629
|
}));
|
|
6454
6630
|
const selected = await Lt({
|
|
6455
6631
|
message: `What would you like to add to your project? ${color.dim("(use arrow keys / space bar)")}`,
|
|
6456
|
-
options: addonOptions
|
|
6632
|
+
options: addonOptions,
|
|
6457
6633
|
required: false
|
|
6458
6634
|
});
|
|
6459
6635
|
if (Ct(selected)) {
|
|
@@ -6484,14 +6660,11 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6484
6660
|
const missingDependencies = setupResult.dependsOn.filter((depId) => !addons.some((a) => a.addon.id === depId));
|
|
6485
6661
|
for (const depId of missingDependencies) {
|
|
6486
6662
|
const addonChain = dependencyChains.get(addonId) ?? /* @__PURE__ */ new Set();
|
|
6487
|
-
if (addonChain.has(depId)) {
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6492
|
-
].join(" → ");
|
|
6493
|
-
errorAndExit(`Circular dependency detected: ${cyclePath}\nAdd-ons cannot have circular dependencies.`);
|
|
6494
|
-
}
|
|
6663
|
+
if (addonChain.has(depId)) errorAndExit(`Circular dependency detected: ${[
|
|
6664
|
+
...addonChain,
|
|
6665
|
+
addonId,
|
|
6666
|
+
depId
|
|
6667
|
+
].join(" → ")}\nAdd-ons cannot have circular dependencies.`);
|
|
6495
6668
|
const depChain = new Set(addonChain);
|
|
6496
6669
|
depChain.add(addonId);
|
|
6497
6670
|
dependencyChains.set(depId, depChain);
|
|
@@ -6517,7 +6690,7 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6517
6690
|
}
|
|
6518
6691
|
}
|
|
6519
6692
|
const addonDefinitions = addons.map((a) => a.addon);
|
|
6520
|
-
const verifications = [...verifyCleanWorkingDirectory(options
|
|
6693
|
+
const verifications = [...verifyCleanWorkingDirectory(options.cwd, options.gitCheck), ...verifyUnsupportedAddons(addonDefinitions, setupResults)];
|
|
6521
6694
|
const fails = [];
|
|
6522
6695
|
for (const verification of verifications) {
|
|
6523
6696
|
const { message, success } = await verification.run();
|
|
@@ -6527,8 +6700,7 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6527
6700
|
});
|
|
6528
6701
|
}
|
|
6529
6702
|
if (fails.length > 0) {
|
|
6530
|
-
|
|
6531
|
-
kt(`- ${message}`, "Verifications not met", { format: (line) => line });
|
|
6703
|
+
kt(`- ${fails.map(({ name, message }) => color.warning(`${name} (${message})`)).join("\n- ")}`, "Verifications not met", { format: (line) => line });
|
|
6532
6704
|
const force = await Mt({
|
|
6533
6705
|
message: "Verifications failed. Do you wish to continue?",
|
|
6534
6706
|
initialValue: false
|
|
@@ -6584,7 +6756,7 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6584
6756
|
answers
|
|
6585
6757
|
};
|
|
6586
6758
|
}
|
|
6587
|
-
async function runAddonsApply({ answers, options
|
|
6759
|
+
async function runAddonsApply({ answers, options, loadedAddons, setupResults, workspace, fromCommand }) {
|
|
6588
6760
|
if (!setupResults) setupResults = setupAddons(loadedAddons.length ? loadedAddons : officialAddons.map((a) => createLoadedAddon(a)), workspace);
|
|
6589
6761
|
if (loadedAddons.length === 0) return {
|
|
6590
6762
|
nextSteps: [],
|
|
@@ -6610,7 +6782,7 @@ async function runAddonsApply({ answers, options: options$8, loadedAddons, setup
|
|
|
6610
6782
|
Pt("All selected add-ons were canceled.");
|
|
6611
6783
|
process$1.exit(1);
|
|
6612
6784
|
} else R.success(`Successfully setup add-ons: ${addonSuccess.map((c) => color.addon(c)).join(", ")}`);
|
|
6613
|
-
const packageManager = options
|
|
6785
|
+
const packageManager = options.install === false ? null : options.install === true ? await packageManagerPrompt(options.cwd) : options.install;
|
|
6614
6786
|
await addPnpmBuildDependencies(workspace.cwd, packageManager, ["esbuild", ...pnpmBuildDependencies]);
|
|
6615
6787
|
const argsFormattedAddons = [];
|
|
6616
6788
|
for (const loaded of successfulAddons) {
|
|
@@ -6636,17 +6808,17 @@ async function runAddonsApply({ answers, options: options$8, loadedAddons, setup
|
|
|
6636
6808
|
if (optionParts.length > 0) argsFormattedAddons.push(`${addonSpecifier}="${optionParts.join("+")}"`);
|
|
6637
6809
|
else argsFormattedAddons.push(addonSpecifier);
|
|
6638
6810
|
}
|
|
6639
|
-
if (!options
|
|
6811
|
+
if (!options.downloadCheck) argsFormattedAddons.push("--no-download-check");
|
|
6640
6812
|
if (fromCommand === "add") {
|
|
6641
|
-
if (!options
|
|
6813
|
+
if (!options.gitCheck) argsFormattedAddons.push("--no-git-check");
|
|
6642
6814
|
buildAndLogArgs(packageManager, "add", argsFormattedAddons);
|
|
6643
6815
|
}
|
|
6644
6816
|
if (packageManager) {
|
|
6645
6817
|
workspace.packageManager = packageManager;
|
|
6646
|
-
await installDependencies(packageManager, options
|
|
6818
|
+
await installDependencies(packageManager, options.cwd);
|
|
6647
6819
|
await formatFiles({
|
|
6648
6820
|
packageManager,
|
|
6649
|
-
cwd: options
|
|
6821
|
+
cwd: options.cwd,
|
|
6650
6822
|
filesToFormat
|
|
6651
6823
|
});
|
|
6652
6824
|
}
|
|
@@ -6661,10 +6833,10 @@ function getNextSteps(loadedAddons, workspace, answers) {
|
|
|
6661
6833
|
return loadedAddons.map((loaded) => {
|
|
6662
6834
|
const addon = loaded.addon;
|
|
6663
6835
|
if (!addon.nextSteps) return;
|
|
6664
|
-
const addonOptions
|
|
6836
|
+
const addonOptions = answers[addon.id];
|
|
6665
6837
|
const addonNextSteps = addon.nextSteps({
|
|
6666
6838
|
...workspace,
|
|
6667
|
-
options: addonOptions
|
|
6839
|
+
options: addonOptions
|
|
6668
6840
|
});
|
|
6669
6841
|
if (addonNextSteps.length === 0) return;
|
|
6670
6842
|
let addonMessage = `${color.addon(addon.id)}:\n`;
|
|
@@ -6679,10 +6851,10 @@ function addonArgsHandler(acc, current) {
|
|
|
6679
6851
|
const [addonSpecifier, optionFlags] = current.split("=", 2);
|
|
6680
6852
|
if (acc.find(({ specifier }) => specifier === addonSpecifier)) errorAndExit(`Malformed arguments: Add-on '${addonSpecifier}' is repeated multiple times.`);
|
|
6681
6853
|
try {
|
|
6682
|
-
const options
|
|
6854
|
+
const options = parseAddonOptions(optionFlags);
|
|
6683
6855
|
acc.push({
|
|
6684
6856
|
specifier: addonSpecifier,
|
|
6685
|
-
options: options
|
|
6857
|
+
options: options ?? []
|
|
6686
6858
|
});
|
|
6687
6859
|
} catch (error) {
|
|
6688
6860
|
if (error instanceof Error) errorAndExit(error.message);
|
|
@@ -6691,68 +6863,92 @@ function addonArgsHandler(acc, current) {
|
|
|
6691
6863
|
}
|
|
6692
6864
|
return acc;
|
|
6693
6865
|
}
|
|
6866
|
+
function getOfficialAddonIds() {
|
|
6867
|
+
return officialAddons.map((a) => a.id);
|
|
6868
|
+
}
|
|
6694
6869
|
function getAddonOptionFlags() {
|
|
6695
|
-
const options
|
|
6870
|
+
const options = [];
|
|
6696
6871
|
for (const addon of officialAddons) {
|
|
6697
6872
|
const id = addon.id;
|
|
6698
6873
|
const details = getAddonDetails(id);
|
|
6699
6874
|
if (Object.values(details.options).length === 0) continue;
|
|
6700
|
-
const {
|
|
6701
|
-
const choices = Object.entries(groups).map(([group, choices
|
|
6702
|
-
|
|
6703
|
-
|
|
6875
|
+
const { groups, groupDefaults } = getOptionChoices(details);
|
|
6876
|
+
const choices = Object.entries(groups).map(([group, choices]) => {
|
|
6877
|
+
const defaults = groupDefaults[group];
|
|
6878
|
+
const defaultStr = defaults === void 0 ? "" : defaults.length > 0 ? ` (default: ${defaults.join(", ")})` : " (default: none)";
|
|
6879
|
+
return `${color.optional(`${group}:`)} ${color.dim(choices.join(", "))}${defaultStr}`;
|
|
6880
|
+
}).join("\n");
|
|
6881
|
+
options.push({
|
|
6704
6882
|
id,
|
|
6705
|
-
choices
|
|
6706
|
-
preset
|
|
6883
|
+
choices
|
|
6707
6884
|
});
|
|
6708
6885
|
}
|
|
6709
|
-
return options
|
|
6886
|
+
return options;
|
|
6887
|
+
}
|
|
6888
|
+
/**
|
|
6889
|
+
* Shared addon help section used by `add --help`, `create --help`, and `sv --help`.
|
|
6890
|
+
* Returns formatted lines showing all addons, their options, and syntax examples.
|
|
6891
|
+
*/
|
|
6892
|
+
function formatAddonHelpSection(opts) {
|
|
6893
|
+
const { styleTitle, formatItem } = opts;
|
|
6894
|
+
const output = [];
|
|
6895
|
+
const allIds = getOfficialAddonIds();
|
|
6896
|
+
const withOptionsMap = new Map(addonOptions.map((o) => [o.id, o]));
|
|
6897
|
+
const addonList = allIds.map((id) => {
|
|
6898
|
+
const option = withOptionsMap.get(id);
|
|
6899
|
+
if (!option) return formatItem(id, "(no options)");
|
|
6900
|
+
return formatItem(id, option.choices);
|
|
6901
|
+
});
|
|
6902
|
+
if (addonList.length > 0) output.push(styleTitle("Add-Ons:"), ...addonList, "");
|
|
6903
|
+
output.push(styleTitle("Add-On Syntax:"), " <addon> add with defaults (may still prompt)", " <addon>=<opt>:<val> set a single option", " <addon>=<opt1>:<val1>+<opt2>:<val2> set multiple options", " <addon>=<opt>:none explicitly set no value (for multiselect)", " To skip prompts, explicitly set ALL options (use defaults shown above).", "");
|
|
6904
|
+
return output;
|
|
6710
6905
|
}
|
|
6711
6906
|
function getOptionChoices(details) {
|
|
6712
6907
|
const choices = [];
|
|
6713
|
-
const defaults = [];
|
|
6714
6908
|
const groups = {};
|
|
6715
|
-
const
|
|
6909
|
+
const groupDefaults = {};
|
|
6910
|
+
const options = {};
|
|
6716
6911
|
for (const [id, question] of Object.entries(details.options)) {
|
|
6717
6912
|
let values = [];
|
|
6718
|
-
const applyDefault = question.condition?.(options
|
|
6913
|
+
const applyDefault = question.condition?.(options) !== false;
|
|
6914
|
+
const groupId = question.group ?? id;
|
|
6915
|
+
groupDefaults[groupId] ??= [];
|
|
6719
6916
|
if (question.type === "boolean") {
|
|
6720
6917
|
values = ["yes", `no`];
|
|
6721
6918
|
if (applyDefault) {
|
|
6722
|
-
options
|
|
6723
|
-
|
|
6919
|
+
options[id] = question.default;
|
|
6920
|
+
groupDefaults[groupId].push(question.default ? values[0] : values[1]);
|
|
6724
6921
|
}
|
|
6725
6922
|
}
|
|
6726
6923
|
if (question.type === "select") {
|
|
6727
6924
|
values = question.options.map((o) => o.value);
|
|
6728
6925
|
if (applyDefault) {
|
|
6729
|
-
options
|
|
6730
|
-
|
|
6926
|
+
options[id] = question.default;
|
|
6927
|
+
groupDefaults[groupId].push(question.default);
|
|
6731
6928
|
}
|
|
6732
6929
|
}
|
|
6733
6930
|
if (question.type === "multiselect") {
|
|
6734
6931
|
values = question.options.map((o) => o.value);
|
|
6735
6932
|
if (applyDefault) {
|
|
6736
|
-
options
|
|
6737
|
-
|
|
6933
|
+
options[id] = question.default;
|
|
6934
|
+
groupDefaults[groupId].push(...question.default);
|
|
6738
6935
|
}
|
|
6739
6936
|
}
|
|
6740
6937
|
if (question.type === "string" || question.type === "number") {
|
|
6741
6938
|
values = ["<user-input>"];
|
|
6742
6939
|
if (applyDefault && question.default !== void 0) {
|
|
6743
|
-
options
|
|
6744
|
-
|
|
6940
|
+
options[id] = question.default;
|
|
6941
|
+
groupDefaults[groupId].push(question.default.toString());
|
|
6745
6942
|
}
|
|
6746
6943
|
}
|
|
6747
6944
|
choices.push(...values);
|
|
6748
|
-
const groupId = question.group ?? id;
|
|
6749
6945
|
groups[groupId] ??= [];
|
|
6750
6946
|
groups[groupId].push(...values);
|
|
6751
6947
|
}
|
|
6752
6948
|
return {
|
|
6753
6949
|
choices,
|
|
6754
|
-
|
|
6755
|
-
|
|
6950
|
+
groups,
|
|
6951
|
+
groupDefaults
|
|
6756
6952
|
};
|
|
6757
6953
|
}
|
|
6758
6954
|
async function resolveNonOfficialAddons(refs, downloadCheck) {
|
|
@@ -6799,32 +6995,29 @@ async function resolveNonOfficialAddons(refs, downloadCheck) {
|
|
|
6799
6995
|
stop("Downloaded community add-on packages");
|
|
6800
6996
|
} catch (err) {
|
|
6801
6997
|
stop("Failed to download community add-on packages");
|
|
6802
|
-
|
|
6803
|
-
errorAndExit(msg);
|
|
6998
|
+
errorAndExit(err instanceof Error ? err.message : "Unknown error");
|
|
6804
6999
|
}
|
|
6805
7000
|
return selectedAddons;
|
|
6806
7001
|
}
|
|
6807
|
-
|
|
6808
7002
|
//#endregion
|
|
6809
7003
|
//#region src/core/env.ts
|
|
6810
7004
|
const TESTING = process$1.env.NODE_ENV?.toLowerCase() === "test";
|
|
6811
|
-
|
|
6812
7005
|
//#endregion
|
|
6813
7006
|
//#region src/core/engine.ts
|
|
6814
|
-
async function add({ addons, cwd
|
|
7007
|
+
async function add({ addons, cwd, options, packageManager = "npm" }) {
|
|
6815
7008
|
const workspace = await createWorkspace({
|
|
6816
|
-
cwd
|
|
7009
|
+
cwd,
|
|
6817
7010
|
packageManager
|
|
6818
7011
|
});
|
|
6819
7012
|
const loadedAddons = Object.values(addons).map((addon) => createLoadedAddon(addon));
|
|
6820
7013
|
return await applyAddons({
|
|
6821
7014
|
loadedAddons,
|
|
6822
7015
|
workspace,
|
|
6823
|
-
options
|
|
7016
|
+
options,
|
|
6824
7017
|
setupResults: setupAddons(loadedAddons, workspace)
|
|
6825
7018
|
});
|
|
6826
7019
|
}
|
|
6827
|
-
async function applyAddons({ loadedAddons, workspace, setupResults, options
|
|
7020
|
+
async function applyAddons({ loadedAddons, workspace, setupResults, options }) {
|
|
6828
7021
|
const filesToFormat = /* @__PURE__ */ new Set();
|
|
6829
7022
|
const allPnpmBuildDependencies = [];
|
|
6830
7023
|
const status = {};
|
|
@@ -6832,7 +7025,7 @@ async function applyAddons({ loadedAddons, workspace, setupResults, options: opt
|
|
|
6832
7025
|
let hasFormatter = false;
|
|
6833
7026
|
for (const addon of ordered) {
|
|
6834
7027
|
const loaded = loadedAddons.find((l) => l.addon.id === addon.id);
|
|
6835
|
-
const workspaceOptions = options
|
|
7028
|
+
const workspaceOptions = options[addon.id] || {};
|
|
6836
7029
|
const addonWorkspace = await createWorkspace({
|
|
6837
7030
|
cwd: workspace.cwd,
|
|
6838
7031
|
packageManager: workspace.packageManager
|
|
@@ -6869,16 +7062,16 @@ function setupAddons(loadedAddons, workspace) {
|
|
|
6869
7062
|
try {
|
|
6870
7063
|
addon.setup?.({
|
|
6871
7064
|
...workspace,
|
|
6872
|
-
dependsOn: (name
|
|
6873
|
-
setupResult.dependsOn.push(name
|
|
6874
|
-
setupResult.runsAfter.push(name
|
|
7065
|
+
dependsOn: (name) => {
|
|
7066
|
+
setupResult.dependsOn.push(name);
|
|
7067
|
+
setupResult.runsAfter.push(name);
|
|
6875
7068
|
},
|
|
6876
7069
|
unsupported: (reason) => setupResult.unsupported.push(reason),
|
|
6877
|
-
runsAfter: (name
|
|
7070
|
+
runsAfter: (name) => setupResult.runsAfter.push(name)
|
|
6878
7071
|
});
|
|
6879
7072
|
} catch (err) {
|
|
6880
7073
|
const msg = err instanceof Error ? err.message : String(err);
|
|
6881
|
-
throw new Error(`Add-on '${addon.id}' failed during setup: ${msg}\n\n${getErrorHint(loaded.reference.source)}
|
|
7074
|
+
throw new Error(`Add-on '${addon.id}' failed during setup: ${msg}\n\n${getErrorHint(loaded.reference.source)}`, { cause: err });
|
|
6882
7075
|
}
|
|
6883
7076
|
setupResults[addon.id] = setupResult;
|
|
6884
7077
|
}
|
|
@@ -6886,21 +7079,21 @@ function setupAddons(loadedAddons, workspace) {
|
|
|
6886
7079
|
}
|
|
6887
7080
|
async function runAddon({ addon, loaded, multiple, workspace, workspaceOptions }) {
|
|
6888
7081
|
const files = /* @__PURE__ */ new Set();
|
|
6889
|
-
const options
|
|
6890
|
-
for (const [id, question] of Object.entries(addon.options)) if (question.condition?.(options
|
|
7082
|
+
const options = { ...workspaceOptions };
|
|
7083
|
+
for (const [id, question] of Object.entries(addon.options)) if (question.condition?.(options) !== false) options[id] ??= question.default;
|
|
6891
7084
|
const dependencies = [];
|
|
6892
7085
|
const pnpmBuildDependencies = [];
|
|
6893
7086
|
const sv = {
|
|
6894
|
-
file: (path
|
|
7087
|
+
file: (path, content) => {
|
|
6895
7088
|
try {
|
|
6896
|
-
let fileContent = fileExists(workspace.cwd, path
|
|
7089
|
+
let fileContent = fileExists(workspace.cwd, path) ? readFile(workspace.cwd, path) : "";
|
|
6897
7090
|
fileContent = content(fileContent);
|
|
6898
7091
|
if (!fileContent) return fileContent;
|
|
6899
|
-
writeFile(workspace, path
|
|
6900
|
-
files.add(path
|
|
7092
|
+
writeFile(workspace, path, fileContent);
|
|
7093
|
+
files.add(path);
|
|
6901
7094
|
} catch (e) {
|
|
6902
7095
|
if (e instanceof Error) {
|
|
6903
|
-
e.message = `Unable to process '${path
|
|
7096
|
+
e.message = `Unable to process '${path}'. Reason: ${e.message}`;
|
|
6904
7097
|
throw e;
|
|
6905
7098
|
}
|
|
6906
7099
|
throw e;
|
|
@@ -6913,7 +7106,7 @@ async function runAddon({ addon, loaded, multiple, workspace, workspaceOptions }
|
|
|
6913
7106
|
if (!TESTING) R.step(`${addonPrefix}Running external command ${color.optional(`(${executedCommand})`)}`);
|
|
6914
7107
|
if (workspace.packageManager === "npm") args.unshift("--yes");
|
|
6915
7108
|
try {
|
|
6916
|
-
await
|
|
7109
|
+
await z(command, args, {
|
|
6917
7110
|
nodeOptions: {
|
|
6918
7111
|
cwd: workspace.cwd,
|
|
6919
7112
|
stdio: TESTING ? "pipe" : stdio
|
|
@@ -6922,20 +7115,20 @@ async function runAddon({ addon, loaded, multiple, workspace, workspaceOptions }
|
|
|
6922
7115
|
});
|
|
6923
7116
|
} catch (error) {
|
|
6924
7117
|
const typedError = error;
|
|
6925
|
-
throw new Error(`Failed to execute scripts '${executedCommand}': ${typedError.message}`, { cause:
|
|
7118
|
+
throw new Error(`Failed to execute scripts '${executedCommand}': ${typedError.message}`, { cause: error });
|
|
6926
7119
|
}
|
|
6927
7120
|
},
|
|
6928
|
-
dependency: (pkg, version
|
|
7121
|
+
dependency: (pkg, version) => {
|
|
6929
7122
|
dependencies.push({
|
|
6930
7123
|
pkg,
|
|
6931
|
-
version
|
|
7124
|
+
version,
|
|
6932
7125
|
dev: false
|
|
6933
7126
|
});
|
|
6934
7127
|
},
|
|
6935
|
-
devDependency: (pkg, version
|
|
7128
|
+
devDependency: (pkg, version) => {
|
|
6936
7129
|
dependencies.push({
|
|
6937
7130
|
pkg,
|
|
6938
|
-
version
|
|
7131
|
+
version,
|
|
6939
7132
|
dev: true
|
|
6940
7133
|
});
|
|
6941
7134
|
},
|
|
@@ -6950,12 +7143,12 @@ async function runAddon({ addon, loaded, multiple, workspace, workspaceOptions }
|
|
|
6950
7143
|
cancels.push(reason);
|
|
6951
7144
|
},
|
|
6952
7145
|
...workspace,
|
|
6953
|
-
options
|
|
7146
|
+
options,
|
|
6954
7147
|
sv
|
|
6955
7148
|
});
|
|
6956
7149
|
} catch (err) {
|
|
6957
7150
|
const msg = err instanceof Error ? err.message : String(err);
|
|
6958
|
-
throw new Error(`Add-on '${addon.id}' failed during run: ${msg}\n\n${getErrorHint(loaded.reference.source)}
|
|
7151
|
+
throw new Error(`Add-on '${addon.id}' failed during run: ${msg}\n\n${getErrorHint(loaded.reference.source)}`, { cause: err });
|
|
6959
7152
|
}
|
|
6960
7153
|
if (cancels.length === 0) {
|
|
6961
7154
|
const pkgPath = installPackages(dependencies, workspace);
|
|
@@ -6972,6 +7165,5 @@ function orderAddons(addons, setupResults) {
|
|
|
6972
7165
|
return setupResults[a.id]?.runsAfter?.length - setupResults[b.id]?.runsAfter?.length;
|
|
6973
7166
|
});
|
|
6974
7167
|
}
|
|
6975
|
-
|
|
6976
7168
|
//#endregion
|
|
6977
|
-
export { helpConfig as a, officialAddons$1 as c, forwardExitCode as i, defineAddon as l, add$1 as n, name as o, create as r, version as s, add as t, defineAddonOptions as u };
|
|
7169
|
+
export { helpConfig as a, officialAddons$1 as c, forwardExitCode as i, defineAddon as l, add$1 as n, name as o, create as r, version as s, add as t, defineAddonOptions as u };
|