sv 0.12.8 → 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 +14 -18
- package/dist/{engine-DUNH7ELq.mjs → engine-DOKagHfI.mjs} +1003 -876
- 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 +1 -1
|
@@ -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-";
|
|
@@ -2803,8 +2871,8 @@ function formatDescription(arg) {
|
|
|
2803
2871
|
function getHelpSections(cmd, helper) {
|
|
2804
2872
|
const termWidth = helper.padWidth(cmd, helper);
|
|
2805
2873
|
const helpWidth = helper.helpWidth ?? 80;
|
|
2806
|
-
function formatItem(term, description
|
|
2807
|
-
return helper.formatItem(term, termWidth, description
|
|
2874
|
+
function formatItem(term, description) {
|
|
2875
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
2808
2876
|
}
|
|
2809
2877
|
const usage = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
|
|
2810
2878
|
const descText = helper.commandDescription(cmd);
|
|
@@ -2816,7 +2884,7 @@ function getHelpSections(cmd, helper) {
|
|
|
2816
2884
|
""
|
|
2817
2885
|
] : [];
|
|
2818
2886
|
const optItems = helper.visibleOptions(cmd).map((option) => formatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option))));
|
|
2819
|
-
const options
|
|
2887
|
+
const options = optItems.length > 0 ? [
|
|
2820
2888
|
helper.styleTitle("Options:"),
|
|
2821
2889
|
...optItems,
|
|
2822
2890
|
""
|
|
@@ -2839,7 +2907,7 @@ function getHelpSections(cmd, helper) {
|
|
|
2839
2907
|
usage,
|
|
2840
2908
|
description,
|
|
2841
2909
|
arguments: arguments_,
|
|
2842
|
-
options
|
|
2910
|
+
options,
|
|
2843
2911
|
globalOptions,
|
|
2844
2912
|
commands
|
|
2845
2913
|
};
|
|
@@ -2875,13 +2943,13 @@ function forwardExitCode(error) {
|
|
|
2875
2943
|
}
|
|
2876
2944
|
function parseAddonOptions(optionFlags) {
|
|
2877
2945
|
if (optionFlags === void 0 || optionFlags === "") return;
|
|
2878
|
-
const options
|
|
2879
|
-
const malformed = options
|
|
2946
|
+
const options = optionFlags.split("+");
|
|
2947
|
+
const malformed = options.filter((option) => !/.+:.*/.test(option));
|
|
2880
2948
|
if (malformed.length > 0) {
|
|
2881
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').`;
|
|
2882
2950
|
throw new Error(message);
|
|
2883
2951
|
}
|
|
2884
|
-
return options
|
|
2952
|
+
return options;
|
|
2885
2953
|
}
|
|
2886
2954
|
function buildAndLogArgs(agent, command, args, lastArgs = []) {
|
|
2887
2955
|
const allArgs = [
|
|
@@ -2951,13 +3019,11 @@ function updateAgent(projectPath, language, packageManager, loadedAddons) {
|
|
|
2951
3019
|
fs.writeFileSync(agentPath, content);
|
|
2952
3020
|
}
|
|
2953
3021
|
}
|
|
2954
|
-
|
|
2955
3022
|
//#endregion
|
|
2956
3023
|
//#region ../../node_modules/.pnpm/events-universal@1.0.1/node_modules/events-universal/default.js
|
|
2957
3024
|
var require_default = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2958
3025
|
module.exports = __require("events");
|
|
2959
3026
|
}));
|
|
2960
|
-
|
|
2961
3027
|
//#endregion
|
|
2962
3028
|
//#region ../../node_modules/.pnpm/fast-fifo@1.3.2/node_modules/fast-fifo/fixed-size.js
|
|
2963
3029
|
var require_fixed_size = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -2996,7 +3062,6 @@ var require_fixed_size = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2996
3062
|
}
|
|
2997
3063
|
};
|
|
2998
3064
|
}));
|
|
2999
|
-
|
|
3000
3065
|
//#endregion
|
|
3001
3066
|
//#region ../../node_modules/.pnpm/fast-fifo@1.3.2/node_modules/fast-fifo/index.js
|
|
3002
3067
|
var require_fast_fifo = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -3042,9 +3107,8 @@ var require_fast_fifo = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3042
3107
|
}
|
|
3043
3108
|
};
|
|
3044
3109
|
}));
|
|
3045
|
-
|
|
3046
3110
|
//#endregion
|
|
3047
|
-
//#region ../../node_modules/.pnpm/b4a@1.
|
|
3111
|
+
//#region ../../node_modules/.pnpm/b4a@1.8.0/node_modules/b4a/index.js
|
|
3048
3112
|
var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3049
3113
|
function isBuffer(value) {
|
|
3050
3114
|
return Buffer.isBuffer(value) || value instanceof Uint8Array;
|
|
@@ -3061,8 +3125,8 @@ var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3061
3125
|
function allocUnsafeSlow(size) {
|
|
3062
3126
|
return Buffer.allocUnsafeSlow(size);
|
|
3063
3127
|
}
|
|
3064
|
-
function byteLength(string
|
|
3065
|
-
return Buffer.byteLength(string
|
|
3128
|
+
function byteLength(string, encoding) {
|
|
3129
|
+
return Buffer.byteLength(string, encoding);
|
|
3066
3130
|
}
|
|
3067
3131
|
function compare(a, b) {
|
|
3068
3132
|
return Buffer.compare(a, b);
|
|
@@ -3107,8 +3171,8 @@ var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3107
3171
|
function toString(buffer, encoding, start, end) {
|
|
3108
3172
|
return toBuffer(buffer).toString(encoding, start, end);
|
|
3109
3173
|
}
|
|
3110
|
-
function write(buffer, string
|
|
3111
|
-
return toBuffer(buffer).write(string
|
|
3174
|
+
function write(buffer, string, offset, length, encoding) {
|
|
3175
|
+
return toBuffer(buffer).write(string, offset, length, encoding);
|
|
3112
3176
|
}
|
|
3113
3177
|
function readDoubleBE(buffer, offset) {
|
|
3114
3178
|
return toBuffer(buffer).readDoubleBE(offset);
|
|
@@ -3198,9 +3262,8 @@ var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3198
3262
|
writeUInt32LE
|
|
3199
3263
|
};
|
|
3200
3264
|
}));
|
|
3201
|
-
|
|
3202
3265
|
//#endregion
|
|
3203
|
-
//#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
|
|
3204
3267
|
var require_pass_through_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3205
3268
|
const b4a = require_b4a();
|
|
3206
3269
|
module.exports = class PassThroughDecoder {
|
|
@@ -3210,17 +3273,16 @@ var require_pass_through_decoder = /* @__PURE__ */ __commonJSMin(((exports, modu
|
|
|
3210
3273
|
get remaining() {
|
|
3211
3274
|
return 0;
|
|
3212
3275
|
}
|
|
3213
|
-
decode(
|
|
3214
|
-
return b4a.toString(
|
|
3276
|
+
decode(data) {
|
|
3277
|
+
return b4a.toString(data, this.encoding);
|
|
3215
3278
|
}
|
|
3216
3279
|
flush() {
|
|
3217
3280
|
return "";
|
|
3218
3281
|
}
|
|
3219
3282
|
};
|
|
3220
3283
|
}));
|
|
3221
|
-
|
|
3222
3284
|
//#endregion
|
|
3223
|
-
//#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
|
|
3224
3286
|
var require_utf8_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3225
3287
|
const b4a = require_b4a();
|
|
3226
3288
|
/**
|
|
@@ -3228,80 +3290,147 @@ var require_utf8_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3228
3290
|
*/
|
|
3229
3291
|
module.exports = class UTF8Decoder {
|
|
3230
3292
|
constructor() {
|
|
3231
|
-
this.
|
|
3232
|
-
this.bytesSeen = 0;
|
|
3233
|
-
this.bytesNeeded = 0;
|
|
3234
|
-
this.lowerBoundary = 128;
|
|
3235
|
-
this.upperBoundary = 191;
|
|
3293
|
+
this._reset();
|
|
3236
3294
|
}
|
|
3237
3295
|
get remaining() {
|
|
3238
3296
|
return this.bytesSeen;
|
|
3239
3297
|
}
|
|
3240
3298
|
decode(data) {
|
|
3241
|
-
if (
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
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");
|
|
3245
3303
|
}
|
|
3246
3304
|
let result = "";
|
|
3247
|
-
|
|
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++) {
|
|
3248
3331
|
const byte = data[i];
|
|
3249
3332
|
if (this.bytesNeeded === 0) {
|
|
3250
|
-
if (byte <= 127)
|
|
3251
|
-
|
|
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;
|
|
3252
3350
|
this.bytesSeen = 1;
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
if (byte === 224) this.lowerBoundary = 160;
|
|
3258
|
-
else if (byte === 237) this.upperBoundary = 159;
|
|
3259
|
-
this.bytesNeeded = 3;
|
|
3260
|
-
this.codePoint = byte & 15;
|
|
3261
|
-
} else if (byte >= 240 && byte <= 244) {
|
|
3262
|
-
if (byte === 240) this.lowerBoundary = 144;
|
|
3263
|
-
if (byte === 244) this.upperBoundary = 143;
|
|
3264
|
-
this.bytesNeeded = 4;
|
|
3265
|
-
this.codePoint = byte & 7;
|
|
3266
|
-
} else result += "�";
|
|
3351
|
+
this.codePoint = byte & 7;
|
|
3352
|
+
} else {
|
|
3353
|
+
this.bytesSeen = 1;
|
|
3354
|
+
result += "�";
|
|
3267
3355
|
}
|
|
3268
3356
|
continue;
|
|
3269
3357
|
}
|
|
3270
3358
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
3271
|
-
this.codePoint = 0;
|
|
3272
|
-
this.bytesNeeded = 0;
|
|
3273
|
-
this.bytesSeen = 0;
|
|
3274
|
-
this.lowerBoundary = 128;
|
|
3275
|
-
this.upperBoundary = 191;
|
|
3276
3359
|
result += "�";
|
|
3360
|
+
i--;
|
|
3361
|
+
this._reset();
|
|
3277
3362
|
continue;
|
|
3278
3363
|
}
|
|
3279
3364
|
this.lowerBoundary = 128;
|
|
3280
3365
|
this.upperBoundary = 191;
|
|
3281
3366
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
3282
3367
|
this.bytesSeen++;
|
|
3283
|
-
if (this.bytesSeen
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
this.bytesSeen = 0;
|
|
3368
|
+
if (this.bytesSeen === this.bytesNeeded) {
|
|
3369
|
+
result += String.fromCodePoint(this.codePoint);
|
|
3370
|
+
this._reset();
|
|
3371
|
+
}
|
|
3288
3372
|
}
|
|
3289
3373
|
return result;
|
|
3290
3374
|
}
|
|
3291
3375
|
flush() {
|
|
3292
3376
|
const result = this.bytesNeeded > 0 ? "�" : "";
|
|
3377
|
+
this._reset();
|
|
3378
|
+
return result;
|
|
3379
|
+
}
|
|
3380
|
+
_reset() {
|
|
3293
3381
|
this.codePoint = 0;
|
|
3294
3382
|
this.bytesNeeded = 0;
|
|
3295
3383
|
this.bytesSeen = 0;
|
|
3296
3384
|
this.lowerBoundary = 128;
|
|
3297
3385
|
this.upperBoundary = 191;
|
|
3298
|
-
return result;
|
|
3299
3386
|
}
|
|
3300
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
|
+
}
|
|
3301
3431
|
}));
|
|
3302
|
-
|
|
3303
3432
|
//#endregion
|
|
3304
|
-
//#region ../../node_modules/.pnpm/text-decoder@1.2.
|
|
3433
|
+
//#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/index.js
|
|
3305
3434
|
var require_text_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3306
3435
|
const PassThroughDecoder = require_pass_through_decoder();
|
|
3307
3436
|
const UTF8Decoder = require_utf8_decoder();
|
|
@@ -3352,9 +3481,8 @@ var require_text_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3352
3481
|
}
|
|
3353
3482
|
}
|
|
3354
3483
|
}));
|
|
3355
|
-
|
|
3356
3484
|
//#endregion
|
|
3357
|
-
//#region ../../node_modules/.pnpm/streamx@2.
|
|
3485
|
+
//#region ../../node_modules/.pnpm/streamx@2.25.0/node_modules/streamx/index.js
|
|
3358
3486
|
var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3359
3487
|
const { EventEmitter } = require_default();
|
|
3360
3488
|
const STREAM_DESTROYED = /* @__PURE__ */ new Error("Stream was destroyed");
|
|
@@ -3462,6 +3590,9 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3462
3590
|
this.afterWrite = afterWrite.bind(this);
|
|
3463
3591
|
this.afterUpdateNextTick = updateWriteNT.bind(this);
|
|
3464
3592
|
}
|
|
3593
|
+
get ending() {
|
|
3594
|
+
return (this.stream._duplexState & WRITE_FINISHING) !== 0;
|
|
3595
|
+
}
|
|
3465
3596
|
get ended() {
|
|
3466
3597
|
return (this.stream._duplexState & WRITE_DONE) !== 0;
|
|
3467
3598
|
}
|
|
@@ -3558,6 +3689,9 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3558
3689
|
this.afterRead = afterRead.bind(this);
|
|
3559
3690
|
this.afterUpdateNextTick = updateReadNT.bind(this);
|
|
3560
3691
|
}
|
|
3692
|
+
get ending() {
|
|
3693
|
+
return (this.stream._duplexState & READ_ENDING) !== 0;
|
|
3694
|
+
}
|
|
3561
3695
|
get ended() {
|
|
3562
3696
|
return (this.stream._duplexState & READ_DONE) !== 0;
|
|
3563
3697
|
}
|
|
@@ -3612,9 +3746,9 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3612
3746
|
const pending = [this.map !== null ? this.map(data) : data];
|
|
3613
3747
|
while (this.buffered > 0) pending.push(this.shift());
|
|
3614
3748
|
for (let i = 0; i < pending.length - 1; i++) {
|
|
3615
|
-
const data
|
|
3616
|
-
this.buffered += this.byteLength(data
|
|
3617
|
-
this.queue.push(data
|
|
3749
|
+
const data = pending[i];
|
|
3750
|
+
this.buffered += this.byteLength(data);
|
|
3751
|
+
this.queue.push(data);
|
|
3618
3752
|
}
|
|
3619
3753
|
this.push(pending[pending.length - 1]);
|
|
3620
3754
|
}
|
|
@@ -3817,19 +3951,19 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3817
3951
|
if (data !== void 0 && data !== null) this.push(data);
|
|
3818
3952
|
this._writableState.afterWrite(err);
|
|
3819
3953
|
}
|
|
3820
|
-
function newListener(name
|
|
3954
|
+
function newListener(name) {
|
|
3821
3955
|
if (this._readableState !== null) {
|
|
3822
|
-
if (name
|
|
3956
|
+
if (name === "data") {
|
|
3823
3957
|
this._duplexState |= READ_EMIT_DATA | READ_RESUMED_READ_AHEAD;
|
|
3824
3958
|
this._readableState.updateNextTick();
|
|
3825
3959
|
}
|
|
3826
|
-
if (name
|
|
3960
|
+
if (name === "readable") {
|
|
3827
3961
|
this._duplexState |= READ_EMIT_READABLE;
|
|
3828
3962
|
this._readableState.updateNextTick();
|
|
3829
3963
|
}
|
|
3830
3964
|
}
|
|
3831
3965
|
if (this._writableState !== null) {
|
|
3832
|
-
if (name
|
|
3966
|
+
if (name === "drain") {
|
|
3833
3967
|
this._duplexState |= WRITE_EMIT_DRAIN;
|
|
3834
3968
|
this._writableState.updateNextTick();
|
|
3835
3969
|
}
|
|
@@ -3994,8 +4128,8 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3994
4128
|
return this;
|
|
3995
4129
|
},
|
|
3996
4130
|
next() {
|
|
3997
|
-
return new Promise(function(resolve
|
|
3998
|
-
promiseResolve = resolve
|
|
4131
|
+
return new Promise(function(resolve, reject) {
|
|
4132
|
+
promiseResolve = resolve;
|
|
3999
4133
|
promiseReject = reject;
|
|
4000
4134
|
const data = stream.read();
|
|
4001
4135
|
if (data !== null) ondata(data);
|
|
@@ -4027,14 +4161,14 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4027
4161
|
}
|
|
4028
4162
|
function destroy(err) {
|
|
4029
4163
|
stream.destroy(err);
|
|
4030
|
-
return new Promise((resolve
|
|
4031
|
-
if (stream._duplexState & DESTROYED) return resolve
|
|
4164
|
+
return new Promise((resolve, reject) => {
|
|
4165
|
+
if (stream._duplexState & DESTROYED) return resolve({
|
|
4032
4166
|
value: void 0,
|
|
4033
4167
|
done: true
|
|
4034
4168
|
});
|
|
4035
4169
|
stream.once("close", function() {
|
|
4036
4170
|
if (err) reject(err);
|
|
4037
|
-
else resolve
|
|
4171
|
+
else resolve({
|
|
4038
4172
|
value: void 0,
|
|
4039
4173
|
done: true
|
|
4040
4174
|
});
|
|
@@ -4080,10 +4214,10 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4080
4214
|
const writes = (isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length) + (ws._duplexState & WRITE_WRITING ? 1 : 0);
|
|
4081
4215
|
if (writes === 0) return Promise.resolve(true);
|
|
4082
4216
|
if (state.drains === null) state.drains = [];
|
|
4083
|
-
return new Promise((resolve
|
|
4217
|
+
return new Promise((resolve) => {
|
|
4084
4218
|
state.drains.push({
|
|
4085
4219
|
writes,
|
|
4086
|
-
resolve
|
|
4220
|
+
resolve
|
|
4087
4221
|
});
|
|
4088
4222
|
});
|
|
4089
4223
|
}
|
|
@@ -4182,10 +4316,10 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4182
4316
|
cb(null);
|
|
4183
4317
|
}
|
|
4184
4318
|
function pipelinePromise(...streams) {
|
|
4185
|
-
return new Promise((resolve
|
|
4319
|
+
return new Promise((resolve, reject) => {
|
|
4186
4320
|
return pipeline(...streams, (err) => {
|
|
4187
4321
|
if (err) return reject(err);
|
|
4188
|
-
resolve
|
|
4322
|
+
resolve();
|
|
4189
4323
|
});
|
|
4190
4324
|
});
|
|
4191
4325
|
}
|
|
@@ -4218,12 +4352,12 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4218
4352
|
if (autoDestroy) dest.on("close", () => done(error || (fin ? null : PREMATURE_CLOSE)));
|
|
4219
4353
|
}
|
|
4220
4354
|
return dest;
|
|
4221
|
-
function errorHandle(s, rd, wr, onerror
|
|
4222
|
-
s.on("error", onerror
|
|
4355
|
+
function errorHandle(s, rd, wr, onerror) {
|
|
4356
|
+
s.on("error", onerror);
|
|
4223
4357
|
s.on("close", onclose);
|
|
4224
4358
|
function onclose() {
|
|
4225
|
-
if (rd && s._readableState && !s._readableState.ended) return onerror
|
|
4226
|
-
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);
|
|
4227
4361
|
}
|
|
4228
4362
|
}
|
|
4229
4363
|
function onerror(err) {
|
|
@@ -4241,9 +4375,15 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4241
4375
|
function isStreamx(stream) {
|
|
4242
4376
|
return typeof stream._duplexState === "number" && isStream(stream);
|
|
4243
4377
|
}
|
|
4378
|
+
function isEnding(stream) {
|
|
4379
|
+
return !!stream._readableState && stream._readableState.ending;
|
|
4380
|
+
}
|
|
4244
4381
|
function isEnded(stream) {
|
|
4245
4382
|
return !!stream._readableState && stream._readableState.ended;
|
|
4246
4383
|
}
|
|
4384
|
+
function isFinishing(stream) {
|
|
4385
|
+
return !!stream._writableState && stream._writableState.ending;
|
|
4386
|
+
}
|
|
4247
4387
|
function isFinished(stream) {
|
|
4248
4388
|
return !!stream._writableState && stream._writableState.ended;
|
|
4249
4389
|
}
|
|
@@ -4255,7 +4395,7 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4255
4395
|
return isStreamx(stream) && stream.readable;
|
|
4256
4396
|
}
|
|
4257
4397
|
function isDisturbed(stream) {
|
|
4258
|
-
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;
|
|
4259
4399
|
}
|
|
4260
4400
|
function isTypedArray(data) {
|
|
4261
4401
|
return typeof data === "object" && data !== null && typeof data.byteLength === "number";
|
|
@@ -4275,7 +4415,9 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4275
4415
|
pipelinePromise,
|
|
4276
4416
|
isStream,
|
|
4277
4417
|
isStreamx,
|
|
4418
|
+
isEnding,
|
|
4278
4419
|
isEnded,
|
|
4420
|
+
isFinishing,
|
|
4279
4421
|
isFinished,
|
|
4280
4422
|
isDisturbed,
|
|
4281
4423
|
getStreamError,
|
|
@@ -4287,9 +4429,8 @@ var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4287
4429
|
PassThrough
|
|
4288
4430
|
};
|
|
4289
4431
|
}));
|
|
4290
|
-
|
|
4291
4432
|
//#endregion
|
|
4292
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
4433
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/headers.js
|
|
4293
4434
|
var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4294
4435
|
const b4a = require_b4a();
|
|
4295
4436
|
const ZEROS = "0000000000000000000";
|
|
@@ -4344,19 +4485,19 @@ var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4344
4485
|
};
|
|
4345
4486
|
exports.encode = function encode(opts) {
|
|
4346
4487
|
const buf = b4a.alloc(512);
|
|
4347
|
-
let name
|
|
4488
|
+
let name = opts.name;
|
|
4348
4489
|
let prefix = "";
|
|
4349
|
-
if (opts.typeflag === 5 && name
|
|
4350
|
-
if (b4a.byteLength(name
|
|
4351
|
-
while (b4a.byteLength(name
|
|
4352
|
-
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("/");
|
|
4353
4494
|
if (i === -1) return null;
|
|
4354
|
-
prefix += prefix ? "/" + name
|
|
4355
|
-
name
|
|
4495
|
+
prefix += prefix ? "/" + name.slice(0, i) : name.slice(0, i);
|
|
4496
|
+
name = name.slice(i + 1);
|
|
4356
4497
|
}
|
|
4357
|
-
if (b4a.byteLength(name
|
|
4498
|
+
if (b4a.byteLength(name) > 100 || b4a.byteLength(prefix) > 155) return null;
|
|
4358
4499
|
if (opts.linkname && b4a.byteLength(opts.linkname) > 100) return null;
|
|
4359
|
-
b4a.write(buf, name
|
|
4500
|
+
b4a.write(buf, name);
|
|
4360
4501
|
b4a.write(buf, encodeOct(opts.mode & MASK, 6), 100);
|
|
4361
4502
|
b4a.write(buf, encodeOct(opts.uid, 6), 108);
|
|
4362
4503
|
b4a.write(buf, encodeOct(opts.gid, 6), 116);
|
|
@@ -4376,7 +4517,7 @@ var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4376
4517
|
};
|
|
4377
4518
|
exports.decode = function decode(buf, filenameEncoding, allowUnknownFormat) {
|
|
4378
4519
|
let typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET;
|
|
4379
|
-
let name
|
|
4520
|
+
let name = decodeStr(buf, 0, 100, filenameEncoding);
|
|
4380
4521
|
const mode = decodeOct(buf, 100, 8);
|
|
4381
4522
|
const uid = decodeOct(buf, 108, 8);
|
|
4382
4523
|
const gid = decodeOct(buf, 116, 8);
|
|
@@ -4392,11 +4533,11 @@ var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4392
4533
|
if (c === 256) return null;
|
|
4393
4534
|
if (c !== decodeOct(buf, 148, 8)) throw new Error("Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?");
|
|
4394
4535
|
if (isUSTAR(buf)) {
|
|
4395
|
-
if (buf[345]) name
|
|
4536
|
+
if (buf[345]) name = decodeStr(buf, 345, 155, filenameEncoding) + "/" + name;
|
|
4396
4537
|
} else if (isGNU(buf)) {} else if (!allowUnknownFormat) throw new Error("Invalid tar header: unknown format.");
|
|
4397
|
-
if (typeflag === 0 && name
|
|
4538
|
+
if (typeflag === 0 && name && name[name.length - 1] === "/") typeflag = 5;
|
|
4398
4539
|
return {
|
|
4399
|
-
name
|
|
4540
|
+
name,
|
|
4400
4541
|
mode,
|
|
4401
4542
|
uid,
|
|
4402
4543
|
gid,
|
|
@@ -4523,9 +4664,8 @@ var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4523
4664
|
return len + digits + str;
|
|
4524
4665
|
}
|
|
4525
4666
|
}));
|
|
4526
|
-
|
|
4527
4667
|
//#endregion
|
|
4528
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
4668
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/extract.js
|
|
4529
4669
|
var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4530
4670
|
const { Writable, Readable, getStreamError } = require_streamx();
|
|
4531
4671
|
const FIFO = require_fast_fifo();
|
|
@@ -4769,7 +4909,7 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4769
4909
|
let promiseReject = null;
|
|
4770
4910
|
let entryStream = null;
|
|
4771
4911
|
let entryCallback = null;
|
|
4772
|
-
const extract
|
|
4912
|
+
const extract = this;
|
|
4773
4913
|
this.on("entry", onentry);
|
|
4774
4914
|
this.on("error", (err) => {
|
|
4775
4915
|
error = err;
|
|
@@ -4795,20 +4935,20 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4795
4935
|
entryCallback = null;
|
|
4796
4936
|
cb(err);
|
|
4797
4937
|
}
|
|
4798
|
-
function onnext(resolve
|
|
4938
|
+
function onnext(resolve, reject) {
|
|
4799
4939
|
if (error) return reject(error);
|
|
4800
4940
|
if (entryStream) {
|
|
4801
|
-
resolve
|
|
4941
|
+
resolve({
|
|
4802
4942
|
value: entryStream,
|
|
4803
4943
|
done: false
|
|
4804
4944
|
});
|
|
4805
4945
|
entryStream = null;
|
|
4806
4946
|
return;
|
|
4807
4947
|
}
|
|
4808
|
-
promiseResolve = resolve
|
|
4948
|
+
promiseResolve = resolve;
|
|
4809
4949
|
promiseReject = reject;
|
|
4810
4950
|
consumeCallback(null);
|
|
4811
|
-
if (extract
|
|
4951
|
+
if (extract._finished && promiseResolve) {
|
|
4812
4952
|
promiseResolve({
|
|
4813
4953
|
value: void 0,
|
|
4814
4954
|
done: true
|
|
@@ -4838,16 +4978,16 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4838
4978
|
promiseResolve = promiseReject = null;
|
|
4839
4979
|
}
|
|
4840
4980
|
function destroy(err) {
|
|
4841
|
-
extract
|
|
4981
|
+
extract.destroy(err);
|
|
4842
4982
|
consumeCallback(err);
|
|
4843
|
-
return new Promise((resolve
|
|
4844
|
-
if (extract
|
|
4983
|
+
return new Promise((resolve, reject) => {
|
|
4984
|
+
if (extract.destroyed) return resolve({
|
|
4845
4985
|
value: void 0,
|
|
4846
4986
|
done: true
|
|
4847
4987
|
});
|
|
4848
|
-
extract
|
|
4988
|
+
extract.once("close", function() {
|
|
4849
4989
|
if (err) reject(err);
|
|
4850
|
-
else resolve
|
|
4990
|
+
else resolve({
|
|
4851
4991
|
value: void 0,
|
|
4852
4992
|
done: true
|
|
4853
4993
|
});
|
|
@@ -4856,7 +4996,7 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4856
4996
|
}
|
|
4857
4997
|
}
|
|
4858
4998
|
};
|
|
4859
|
-
module.exports = function extract
|
|
4999
|
+
module.exports = function extract(opts) {
|
|
4860
5000
|
return new Extract(opts);
|
|
4861
5001
|
};
|
|
4862
5002
|
function noop() {}
|
|
@@ -4865,9 +5005,8 @@ var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4865
5005
|
return size && 512 - size;
|
|
4866
5006
|
}
|
|
4867
5007
|
}));
|
|
4868
|
-
|
|
4869
5008
|
//#endregion
|
|
4870
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
5009
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/constants.js
|
|
4871
5010
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4872
5011
|
const constants = {
|
|
4873
5012
|
S_IFMT: 61440,
|
|
@@ -4883,9 +5022,8 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
4883
5022
|
module.exports = constants;
|
|
4884
5023
|
}
|
|
4885
5024
|
}));
|
|
4886
|
-
|
|
4887
5025
|
//#endregion
|
|
4888
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
5026
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/pack.js
|
|
4889
5027
|
var require_pack = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4890
5028
|
const { Readable, Writable, getStreamError } = require_streamx();
|
|
4891
5029
|
const b4a = require_b4a();
|
|
@@ -5105,14 +5243,12 @@ var require_pack = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5105
5243
|
return b4a.isBuffer(buf) ? buf : b4a.from(buf);
|
|
5106
5244
|
}
|
|
5107
5245
|
}));
|
|
5108
|
-
|
|
5109
5246
|
//#endregion
|
|
5110
|
-
//#region ../../node_modules/.pnpm/tar-stream@3.1.
|
|
5247
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/index.js
|
|
5111
5248
|
var require_tar_stream = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
5112
5249
|
exports.extract = require_extract();
|
|
5113
5250
|
exports.pack = require_pack();
|
|
5114
5251
|
}));
|
|
5115
|
-
|
|
5116
5252
|
//#endregion
|
|
5117
5253
|
//#region ../../node_modules/.pnpm/wrappy@1.0.2/node_modules/wrappy/wrappy.js
|
|
5118
5254
|
var require_wrappy = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -5128,15 +5264,14 @@ var require_wrappy = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5128
5264
|
var args = new Array(arguments.length);
|
|
5129
5265
|
for (var i = 0; i < args.length; i++) args[i] = arguments[i];
|
|
5130
5266
|
var ret = fn.apply(this, args);
|
|
5131
|
-
var cb
|
|
5132
|
-
if (typeof ret === "function" && ret !== cb
|
|
5133
|
-
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];
|
|
5134
5270
|
});
|
|
5135
5271
|
return ret;
|
|
5136
5272
|
}
|
|
5137
5273
|
}
|
|
5138
5274
|
}));
|
|
5139
|
-
|
|
5140
5275
|
//#endregion
|
|
5141
5276
|
//#region ../../node_modules/.pnpm/once@1.4.0/node_modules/once/once.js
|
|
5142
5277
|
var require_once = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -5177,7 +5312,6 @@ var require_once = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5177
5312
|
return f;
|
|
5178
5313
|
}
|
|
5179
5314
|
}));
|
|
5180
|
-
|
|
5181
5315
|
//#endregion
|
|
5182
5316
|
//#region ../../node_modules/.pnpm/end-of-stream@1.4.5/node_modules/end-of-stream/index.js
|
|
5183
5317
|
var require_end_of_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -5258,9 +5392,8 @@ var require_end_of_stream = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
5258
5392
|
};
|
|
5259
5393
|
module.exports = eos;
|
|
5260
5394
|
}));
|
|
5261
|
-
|
|
5262
5395
|
//#endregion
|
|
5263
|
-
//#region ../../node_modules/.pnpm/pump@3.0.
|
|
5396
|
+
//#region ../../node_modules/.pnpm/pump@3.0.4/node_modules/pump/index.js
|
|
5264
5397
|
var require_pump = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
5265
5398
|
var once = require_once();
|
|
5266
5399
|
var eos = require_end_of_stream();
|
|
@@ -5332,10 +5465,9 @@ var require_pump = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
5332
5465
|
};
|
|
5333
5466
|
module.exports = pump;
|
|
5334
5467
|
}));
|
|
5335
|
-
|
|
5336
5468
|
//#endregion
|
|
5337
|
-
//#region
|
|
5338
|
-
var
|
|
5469
|
+
//#region src/core/fetch-packages.ts
|
|
5470
|
+
var import_tar_fs = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
5339
5471
|
const tar = require_tar_stream();
|
|
5340
5472
|
const pump = require_pump();
|
|
5341
5473
|
const fs$1 = __require("fs");
|
|
@@ -5350,15 +5482,15 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5350
5482
|
function processUmask() {
|
|
5351
5483
|
return !global.Bare && process.umask ? process.umask() : 0;
|
|
5352
5484
|
}
|
|
5353
|
-
exports.extract = function extract
|
|
5354
|
-
if (!cwd
|
|
5485
|
+
exports.extract = function extract(cwd, opts) {
|
|
5486
|
+
if (!cwd) cwd = ".";
|
|
5355
5487
|
if (!opts) opts = {};
|
|
5356
|
-
cwd
|
|
5488
|
+
cwd = path$1.resolve(cwd);
|
|
5357
5489
|
const xfs = opts.fs || fs$1;
|
|
5358
5490
|
const ignore = opts.ignore || opts.filter || noop;
|
|
5359
5491
|
const mapStream = opts.mapStream || echo;
|
|
5360
5492
|
const own = opts.chown !== false && !win32 && processGetuid() === 0;
|
|
5361
|
-
const extract
|
|
5493
|
+
const extract = opts.extract || tar.extract();
|
|
5362
5494
|
const stack = [];
|
|
5363
5495
|
const now = /* @__PURE__ */ new Date();
|
|
5364
5496
|
const umask = typeof opts.umask === "number" ? ~opts.umask : ~processUmask();
|
|
@@ -5376,24 +5508,24 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5376
5508
|
dmode |= parseInt(333, 8);
|
|
5377
5509
|
fmode |= parseInt(222, 8);
|
|
5378
5510
|
}
|
|
5379
|
-
extract
|
|
5380
|
-
if (opts.finish) extract
|
|
5381
|
-
return extract
|
|
5511
|
+
extract.on("entry", onentry);
|
|
5512
|
+
if (opts.finish) extract.on("finish", opts.finish);
|
|
5513
|
+
return extract;
|
|
5382
5514
|
function onentry(header, stream, next) {
|
|
5383
5515
|
header = map(header) || header;
|
|
5384
5516
|
header.name = normalize(header.name);
|
|
5385
|
-
const name
|
|
5386
|
-
if (ignore(name
|
|
5517
|
+
const name = path$1.join(cwd, path$1.join("/", header.name));
|
|
5518
|
+
if (ignore(name, header)) {
|
|
5387
5519
|
stream.resume();
|
|
5388
5520
|
return next();
|
|
5389
5521
|
}
|
|
5390
|
-
const dir = path$1.join(name
|
|
5391
|
-
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) {
|
|
5392
5524
|
if (err) return next(err);
|
|
5393
5525
|
if (!valid) return next(/* @__PURE__ */ new Error(dir + " is not a valid path"));
|
|
5394
5526
|
if (header.type === "directory") {
|
|
5395
|
-
stack.push([name
|
|
5396
|
-
return mkdirfix(name
|
|
5527
|
+
stack.push([name, header.mtime]);
|
|
5528
|
+
return mkdirfix(name, {
|
|
5397
5529
|
fs: xfs,
|
|
5398
5530
|
own,
|
|
5399
5531
|
uid: header.uid,
|
|
@@ -5407,54 +5539,59 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5407
5539
|
uid: header.uid,
|
|
5408
5540
|
gid: header.gid,
|
|
5409
5541
|
mode: 493
|
|
5410
|
-
}, function(err
|
|
5411
|
-
if (err
|
|
5542
|
+
}, function(err) {
|
|
5543
|
+
if (err) return next(err);
|
|
5412
5544
|
switch (header.type) {
|
|
5413
5545
|
case "file": return onfile();
|
|
5414
5546
|
case "link": return onlink();
|
|
5415
5547
|
case "symlink": return onsymlink();
|
|
5416
5548
|
}
|
|
5417
|
-
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 + ")"));
|
|
5418
5550
|
stream.resume();
|
|
5419
5551
|
next();
|
|
5420
5552
|
});
|
|
5421
5553
|
});
|
|
5422
5554
|
function stat(err) {
|
|
5423
5555
|
if (err) return next(err);
|
|
5424
|
-
utimes(name
|
|
5425
|
-
if (err
|
|
5556
|
+
utimes(name, header, function(err) {
|
|
5557
|
+
if (err) return next(err);
|
|
5426
5558
|
if (win32) return next();
|
|
5427
|
-
chperm(name
|
|
5559
|
+
chperm(name, header, next);
|
|
5428
5560
|
});
|
|
5429
5561
|
}
|
|
5430
5562
|
function onsymlink() {
|
|
5431
5563
|
if (win32) return next();
|
|
5432
|
-
xfs.unlink(name
|
|
5433
|
-
|
|
5434
|
-
|
|
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
|
+
});
|
|
5435
5572
|
});
|
|
5436
5573
|
}
|
|
5437
5574
|
function onlink() {
|
|
5438
5575
|
if (win32) return next();
|
|
5439
|
-
xfs.unlink(name
|
|
5440
|
-
const link = path$1.join(cwd
|
|
5441
|
-
|
|
5442
|
-
if (err || !inCwd(dst)) return next(/* @__PURE__ */ new Error(name
|
|
5443
|
-
xfs.link(dst, name
|
|
5444
|
-
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) {
|
|
5445
5582
|
stream = xfs.createReadStream(dst);
|
|
5446
5583
|
return onfile();
|
|
5447
5584
|
}
|
|
5448
|
-
stat(err
|
|
5585
|
+
stat(err);
|
|
5449
5586
|
});
|
|
5450
5587
|
});
|
|
5451
5588
|
});
|
|
5452
5589
|
}
|
|
5453
5590
|
function inCwd(dst) {
|
|
5454
|
-
return dst === cwd
|
|
5591
|
+
return dst === cwd || dst.startsWith(cwd + path$1.sep);
|
|
5455
5592
|
}
|
|
5456
5593
|
function onfile() {
|
|
5457
|
-
const ws = xfs.createWriteStream(name
|
|
5594
|
+
const ws = xfs.createWriteStream(name);
|
|
5458
5595
|
const rs = mapStream(stream, header);
|
|
5459
5596
|
ws.on("error", function(err) {
|
|
5460
5597
|
rs.destroy(err);
|
|
@@ -5465,63 +5602,72 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5465
5602
|
});
|
|
5466
5603
|
}
|
|
5467
5604
|
}
|
|
5468
|
-
function utimesParent(name
|
|
5605
|
+
function utimesParent(name, cb) {
|
|
5469
5606
|
let top;
|
|
5470
|
-
while ((top = head(stack)) && name
|
|
5607
|
+
while ((top = head(stack)) && name.slice(0, top[0].length) !== top[0]) stack.pop();
|
|
5471
5608
|
if (!top) return cb();
|
|
5472
5609
|
xfs.utimes(top[0], now, top[1], cb);
|
|
5473
5610
|
}
|
|
5474
|
-
function utimes(name
|
|
5611
|
+
function utimes(name, header, cb) {
|
|
5475
5612
|
if (opts.utimes === false) return cb();
|
|
5476
|
-
if (header.type === "directory") return xfs.utimes(name
|
|
5477
|
-
if (header.type === "symlink") return utimesParent(name
|
|
5478
|
-
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) {
|
|
5479
5616
|
if (err) return cb(err);
|
|
5480
|
-
utimesParent(name
|
|
5617
|
+
utimesParent(name, cb);
|
|
5481
5618
|
});
|
|
5482
5619
|
}
|
|
5483
|
-
function chperm(name
|
|
5620
|
+
function chperm(name, header, cb) {
|
|
5484
5621
|
const link = header.type === "symlink";
|
|
5485
5622
|
const chmod = link ? xfs.lchmod : xfs.chmod;
|
|
5486
5623
|
const chown = link ? xfs.lchown : xfs.chown;
|
|
5487
5624
|
if (!chmod) return cb();
|
|
5488
5625
|
const mode = (header.mode | (header.type === "directory" ? dmode : fmode)) & umask;
|
|
5489
|
-
if (chown && own) chown.call(xfs, name
|
|
5626
|
+
if (chown && own) chown.call(xfs, name, header.uid, header.gid, onchown);
|
|
5490
5627
|
else onchown(null);
|
|
5491
5628
|
function onchown(err) {
|
|
5492
5629
|
if (err) return cb(err);
|
|
5493
5630
|
if (!chmod) return cb();
|
|
5494
|
-
chmod.call(xfs, name
|
|
5631
|
+
chmod.call(xfs, name, mode, cb);
|
|
5495
5632
|
}
|
|
5496
5633
|
}
|
|
5497
|
-
function mkdirfix(name
|
|
5498
|
-
xfs.stat(name
|
|
5634
|
+
function mkdirfix(name, opts, cb) {
|
|
5635
|
+
xfs.stat(name, function(err) {
|
|
5499
5636
|
if (!err) return cb(null);
|
|
5500
5637
|
if (err.code !== "ENOENT") return cb(err);
|
|
5501
|
-
xfs.mkdir(name
|
|
5502
|
-
mode: opts
|
|
5638
|
+
xfs.mkdir(name, {
|
|
5639
|
+
mode: opts.mode,
|
|
5503
5640
|
recursive: true
|
|
5504
|
-
}, function(err
|
|
5505
|
-
if (err
|
|
5506
|
-
chperm(name
|
|
5641
|
+
}, function(err, made) {
|
|
5642
|
+
if (err) return cb(err);
|
|
5643
|
+
chperm(name, opts, cb);
|
|
5507
5644
|
});
|
|
5508
5645
|
});
|
|
5509
5646
|
}
|
|
5510
5647
|
};
|
|
5511
|
-
function
|
|
5512
|
-
if (name
|
|
5513
|
-
|
|
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) {
|
|
5514
5652
|
if (err && err.code !== "ENOENT" && err.code !== "EPERM") return cb(err);
|
|
5515
|
-
if (err || st.
|
|
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) {
|
|
5660
|
+
if (err && err.code !== "ENOENT" && err.code !== "EPERM") return cb(err);
|
|
5661
|
+
if (err || st.isDirectory()) return validate(fs, path$1.join(name, ".."), root, cb);
|
|
5516
5662
|
cb(null, false);
|
|
5517
5663
|
});
|
|
5518
5664
|
}
|
|
5519
5665
|
function noop() {}
|
|
5520
|
-
function echo(name
|
|
5521
|
-
return name
|
|
5666
|
+
function echo(name) {
|
|
5667
|
+
return name;
|
|
5522
5668
|
}
|
|
5523
|
-
function normalize(name
|
|
5524
|
-
return win32 ? name
|
|
5669
|
+
function normalize(name) {
|
|
5670
|
+
return win32 ? name.replace(/\\/g, "/").replace(/[:?<>|]/g, "_") : name;
|
|
5525
5671
|
}
|
|
5526
5672
|
function strip(map, level) {
|
|
5527
5673
|
return function(header) {
|
|
@@ -5531,11 +5677,7 @@ var require_tar_fs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
5531
5677
|
return map(header);
|
|
5532
5678
|
};
|
|
5533
5679
|
}
|
|
5534
|
-
}));
|
|
5535
|
-
|
|
5536
|
-
//#endregion
|
|
5537
|
-
//#region src/core/fetch-packages.ts
|
|
5538
|
-
var import_tar_fs = require_tar_fs();
|
|
5680
|
+
})))();
|
|
5539
5681
|
const NODE_MODULES = fileURLToPath(new URL("../../node_modules", import.meta.url));
|
|
5540
5682
|
function verifyPackage(addonPkg, specifier) {
|
|
5541
5683
|
const deps = { ...addonPkg.dependencies };
|
|
@@ -5570,17 +5712,17 @@ function copyDirectorySync(src, dest) {
|
|
|
5570
5712
|
* Downloads and installs the package into the `node_modules` of `sv`.
|
|
5571
5713
|
* @returns the details of the downloaded addon
|
|
5572
5714
|
*/
|
|
5573
|
-
async function downloadPackage(options
|
|
5574
|
-
const { pkg } = options
|
|
5575
|
-
if (options
|
|
5715
|
+
async function downloadPackage(options) {
|
|
5716
|
+
const { pkg } = options;
|
|
5717
|
+
if (options.path) {
|
|
5576
5718
|
const dest = path.join(NODE_MODULES, pkg.name.split("/").join(path.sep));
|
|
5577
5719
|
if (fs.existsSync(dest)) fs.rmSync(dest, { recursive: true });
|
|
5578
5720
|
const dir = path.dirname(dest);
|
|
5579
5721
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
5580
5722
|
try {
|
|
5581
|
-
fs.symlinkSync(options
|
|
5723
|
+
fs.symlinkSync(options.path, dest, "dir");
|
|
5582
5724
|
} catch (error) {
|
|
5583
|
-
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);
|
|
5584
5726
|
else throw error;
|
|
5585
5727
|
}
|
|
5586
5728
|
return await importAddonCode(pkg.name);
|
|
@@ -5596,8 +5738,8 @@ async function downloadPackage(options$8) {
|
|
|
5596
5738
|
}
|
|
5597
5739
|
async function importAddonCode(pkgName) {
|
|
5598
5740
|
try {
|
|
5599
|
-
const { default: details
|
|
5600
|
-
return details
|
|
5741
|
+
const { default: details } = await import(`${pkgName}/sv`);
|
|
5742
|
+
return details;
|
|
5601
5743
|
} catch {}
|
|
5602
5744
|
const { default: details } = await import(pkgName);
|
|
5603
5745
|
return details;
|
|
@@ -5607,14 +5749,14 @@ async function getPackageJSON(ref) {
|
|
|
5607
5749
|
if (source.kind === "official") throw new Error(`Unexpected official addon in non-official getPackageJSON(): ${specifier}`);
|
|
5608
5750
|
if (source.kind === "file") {
|
|
5609
5751
|
const pkgJSONPath = path.resolve(source.path, "package.json");
|
|
5610
|
-
const json
|
|
5611
|
-
const pkg
|
|
5612
|
-
const warning
|
|
5752
|
+
const json = fs.readFileSync(pkgJSONPath, "utf8");
|
|
5753
|
+
const pkg = JSON.parse(json);
|
|
5754
|
+
const warning = verifyPackage(pkg, specifier);
|
|
5613
5755
|
return {
|
|
5614
5756
|
path: source.path,
|
|
5615
|
-
pkg
|
|
5757
|
+
pkg,
|
|
5616
5758
|
repo: source.path,
|
|
5617
|
-
warning
|
|
5759
|
+
warning
|
|
5618
5760
|
};
|
|
5619
5761
|
}
|
|
5620
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.`);
|
|
@@ -5626,17 +5768,16 @@ async function getPackageJSON(ref) {
|
|
|
5626
5768
|
warning
|
|
5627
5769
|
};
|
|
5628
5770
|
}
|
|
5629
|
-
|
|
5630
5771
|
//#endregion
|
|
5631
5772
|
//#region src/core/verifiers.ts
|
|
5632
|
-
function verifyCleanWorkingDirectory(cwd
|
|
5773
|
+
function verifyCleanWorkingDirectory(cwd, gitCheck) {
|
|
5633
5774
|
const verifications = [];
|
|
5634
5775
|
if (gitCheck) verifications.push({
|
|
5635
5776
|
name: "clean working directory",
|
|
5636
5777
|
run: async () => {
|
|
5637
5778
|
try {
|
|
5638
|
-
const { stdout
|
|
5639
|
-
if (stdout
|
|
5779
|
+
const { stdout } = await promisify(exec)("git status --short", { cwd });
|
|
5780
|
+
if (stdout) return {
|
|
5640
5781
|
success: false,
|
|
5641
5782
|
message: "Found modified files"
|
|
5642
5783
|
};
|
|
@@ -5672,12 +5813,11 @@ function verifyUnsupportedAddons(addons, setupResults) {
|
|
|
5672
5813
|
});
|
|
5673
5814
|
return verifications;
|
|
5674
5815
|
}
|
|
5675
|
-
|
|
5676
5816
|
//#endregion
|
|
5677
5817
|
//#region src/core/workspace.ts
|
|
5678
|
-
async function createWorkspace({ cwd
|
|
5679
|
-
const resolvedCwd = path.resolve(cwd
|
|
5680
|
-
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;
|
|
5681
5821
|
const viteConfigPath = path.join(resolvedCwd, commonFilePaths.viteConfigTS);
|
|
5682
5822
|
const viteConfig = fs.existsSync(viteConfigPath) ? commonFilePaths.viteConfigTS : commonFilePaths.viteConfig;
|
|
5683
5823
|
const svelteConfigPath = path.join(resolvedCwd, commonFilePaths.svelteConfigTS);
|
|
@@ -5706,7 +5846,7 @@ async function createWorkspace({ cwd: cwd$1, packageManager, override }) {
|
|
|
5706
5846
|
const stylesheet = kit ? `${kit.routesDirectory}/layout.css` : "src/app.css";
|
|
5707
5847
|
return {
|
|
5708
5848
|
cwd: resolvedCwd,
|
|
5709
|
-
packageManager: packageManager ?? await detectPackageManager(cwd
|
|
5849
|
+
packageManager: packageManager ?? await detectPackageManager(cwd),
|
|
5710
5850
|
language: typescript ? "ts" : "js",
|
|
5711
5851
|
files: {
|
|
5712
5852
|
viteConfig,
|
|
@@ -5730,9 +5870,9 @@ async function createWorkspace({ cwd: cwd$1, packageManager, override }) {
|
|
|
5730
5870
|
dependencyVersion: (pkg) => dependencies[pkg]
|
|
5731
5871
|
};
|
|
5732
5872
|
}
|
|
5733
|
-
function findWorkspaceRoot(cwd
|
|
5734
|
-
const { root } = path.parse(cwd
|
|
5735
|
-
let directory = cwd
|
|
5873
|
+
function findWorkspaceRoot(cwd) {
|
|
5874
|
+
const { root } = path.parse(cwd);
|
|
5875
|
+
let directory = cwd;
|
|
5736
5876
|
while (directory && directory !== root) {
|
|
5737
5877
|
if (fs.existsSync(path.join(directory, commonFilePaths.packageJson))) {
|
|
5738
5878
|
if (fs.existsSync(path.join(directory, "pnpm-workspace.yaml"))) return directory;
|
|
@@ -5743,10 +5883,10 @@ function findWorkspaceRoot(cwd$1) {
|
|
|
5743
5883
|
if (directory.includes(".test-output") && !parent.includes(".test-output")) break;
|
|
5744
5884
|
directory = parent;
|
|
5745
5885
|
}
|
|
5746
|
-
return cwd
|
|
5886
|
+
return cwd;
|
|
5747
5887
|
}
|
|
5748
|
-
function parseKitOptions(cwd
|
|
5749
|
-
const configSource = readFile(cwd
|
|
5888
|
+
function parseKitOptions(cwd, svelteConfigPath) {
|
|
5889
|
+
const configSource = readFile(cwd, svelteConfigPath);
|
|
5750
5890
|
const { ast } = parse.script(configSource);
|
|
5751
5891
|
const defaultExport = ast.body.find((s) => s.type === "ExportDefaultDeclaration");
|
|
5752
5892
|
if (!defaultExport) throw Error(`Missing default export in \`${svelteConfigPath}\``);
|
|
@@ -5783,7 +5923,6 @@ function parseKitOptions(cwd$1, svelteConfigPath) {
|
|
|
5783
5923
|
libDirectory: lib.value || "src/lib"
|
|
5784
5924
|
};
|
|
5785
5925
|
}
|
|
5786
|
-
|
|
5787
5926
|
//#endregion
|
|
5788
5927
|
//#region src/create/playground.ts
|
|
5789
5928
|
function validatePlaygroundUrl(link) {
|
|
@@ -5847,7 +5986,7 @@ function detectPlaygroundDependencies(files) {
|
|
|
5847
5986
|
ast = svelteAst.instance.content;
|
|
5848
5987
|
} else if (file.name.endsWith(".js") || file.name.endsWith(".ts")) ast = parse.script(file.content).ast;
|
|
5849
5988
|
if (!ast) continue;
|
|
5850
|
-
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));
|
|
5851
5990
|
}
|
|
5852
5991
|
return packages;
|
|
5853
5992
|
}
|
|
@@ -5864,36 +6003,36 @@ function extractPackageInfo(importPath) {
|
|
|
5864
6003
|
pkgName = `${org}/${pkg}`;
|
|
5865
6004
|
}
|
|
5866
6005
|
if (!pkgName) [pkgName] = importPath.split("/", 2);
|
|
5867
|
-
const version
|
|
5868
|
-
if (version
|
|
6006
|
+
const version = extractPackageVersion(pkgName);
|
|
6007
|
+
if (version !== "latest") pkgName = pkgName.replace(`@${version}`, "");
|
|
5869
6008
|
return {
|
|
5870
6009
|
pkgName,
|
|
5871
|
-
version
|
|
6010
|
+
version
|
|
5872
6011
|
};
|
|
5873
6012
|
}
|
|
5874
6013
|
function extractPackageVersion(pkgName) {
|
|
5875
|
-
let version
|
|
5876
|
-
if (pkgName.includes("@", 1)) [, version
|
|
5877
|
-
return version
|
|
6014
|
+
let version = "latest";
|
|
6015
|
+
if (pkgName.includes("@", 1)) [, version] = pkgName.split("@");
|
|
6016
|
+
return version;
|
|
5878
6017
|
}
|
|
5879
|
-
function setupPlaygroundProject(url, playground, cwd
|
|
6018
|
+
function setupPlaygroundProject(url, playground, cwd, installDependencies) {
|
|
5880
6019
|
const mainFile = playground.files.find((file) => file.name === "App.svelte");
|
|
5881
6020
|
if (!mainFile) throw new Error("Failed to find `App.svelte` entrypoint.");
|
|
5882
6021
|
const dependencies = detectPlaygroundDependencies(playground.files);
|
|
5883
6022
|
for (const file of playground.files) {
|
|
5884
|
-
for (const [pkg, version
|
|
5885
|
-
const filePath
|
|
5886
|
-
fs.mkdirSync(path.dirname(filePath
|
|
5887
|
-
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");
|
|
5888
6027
|
}
|
|
5889
6028
|
{
|
|
5890
6029
|
const playgroundFiles = getSharedFiles().filter((file) => file.include.includes("playground"));
|
|
5891
6030
|
for (const file of playgroundFiles) {
|
|
5892
6031
|
let contentToWrite = file.contents;
|
|
5893
6032
|
if (file.name === "src/lib/PlaygroundLayout.svelte") {
|
|
5894
|
-
const { ast
|
|
5895
|
-
svelte.ensureScript(ast
|
|
5896
|
-
Walker.walk(ast
|
|
6033
|
+
const { ast, generateCode } = parse.svelte(file.contents);
|
|
6034
|
+
svelte.ensureScript(ast);
|
|
6035
|
+
Walker.walk(ast.instance.content, null, { Literal(node) {
|
|
5897
6036
|
if (node.value === "$sv-title-$sv") {
|
|
5898
6037
|
node.value = playground.name;
|
|
5899
6038
|
node.raw = void 0;
|
|
@@ -5902,12 +6041,12 @@ function setupPlaygroundProject(url, playground, cwd$1, installDependencies$1) {
|
|
|
5902
6041
|
node.raw = void 0;
|
|
5903
6042
|
}
|
|
5904
6043
|
} });
|
|
5905
|
-
contentToWrite = generateCode
|
|
6044
|
+
contentToWrite = generateCode();
|
|
5906
6045
|
}
|
|
5907
|
-
fs.writeFileSync(path.join(cwd
|
|
6046
|
+
fs.writeFileSync(path.join(cwd, file.name), contentToWrite, "utf-8");
|
|
5908
6047
|
}
|
|
5909
6048
|
}
|
|
5910
|
-
const filePath = path.join(cwd
|
|
6049
|
+
const filePath = path.join(cwd, "src/routes/+page.svelte");
|
|
5911
6050
|
const content = fs.readFileSync(filePath, "utf-8");
|
|
5912
6051
|
const { ast, generateCode } = parse.svelte(content);
|
|
5913
6052
|
svelte.ensureScript(ast);
|
|
@@ -5924,37 +6063,36 @@ function setupPlaygroundProject(url, playground, cwd$1, installDependencies$1) {
|
|
|
5924
6063
|
</PlaygroundLayout>`);
|
|
5925
6064
|
const newContent = generateCode();
|
|
5926
6065
|
fs.writeFileSync(filePath, newContent, "utf-8");
|
|
5927
|
-
const pkgPath = path.join(cwd
|
|
6066
|
+
const pkgPath = path.join(cwd, commonFilePaths.packageJson);
|
|
5928
6067
|
const pkgSource = fs.readFileSync(pkgPath, "utf-8");
|
|
5929
6068
|
const pkgJson = parse.json(pkgSource);
|
|
5930
6069
|
let updatePackageJson = false;
|
|
5931
|
-
if (installDependencies
|
|
6070
|
+
if (installDependencies && dependencies.size >= 0) {
|
|
5932
6071
|
updatePackageJson = true;
|
|
5933
6072
|
pkgJson.data.dependencies ??= {};
|
|
5934
|
-
for (const [dep, version
|
|
6073
|
+
for (const [dep, version] of dependencies) pkgJson.data.dependencies[dep] = version;
|
|
5935
6074
|
}
|
|
5936
6075
|
let experimentalAsyncNeeded = true;
|
|
5937
6076
|
const addExperimentalAsync = () => {
|
|
5938
|
-
const svelteConfigPath = path.join(cwd
|
|
6077
|
+
const svelteConfigPath = path.join(cwd, commonFilePaths.svelteConfig);
|
|
5939
6078
|
const svelteConfig = fs.readFileSync(svelteConfigPath, "utf-8");
|
|
5940
|
-
const { ast
|
|
5941
|
-
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({}) });
|
|
5942
6081
|
js.object.overrideProperties(config, { compilerOptions: { experimental: { async: true } } });
|
|
5943
|
-
fs.writeFileSync(svelteConfigPath, generateCode
|
|
6082
|
+
fs.writeFileSync(svelteConfigPath, generateCode(), "utf-8");
|
|
5944
6083
|
};
|
|
5945
6084
|
if (playground.svelteVersion) {
|
|
5946
6085
|
updatePackageJson = true;
|
|
5947
6086
|
const match = /^(pr|commit|branch)-(.+)/.exec(playground.svelteVersion);
|
|
5948
|
-
const version
|
|
5949
|
-
pkgJson.data.devDependencies["svelte"] = version
|
|
5950
|
-
if (!version
|
|
5951
|
-
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;
|
|
5952
6091
|
}
|
|
5953
6092
|
}
|
|
5954
6093
|
if (experimentalAsyncNeeded) addExperimentalAsync();
|
|
5955
6094
|
if (updatePackageJson) fs.writeFileSync(pkgPath, pkgJson.generateCode(), "utf-8");
|
|
5956
6095
|
}
|
|
5957
|
-
|
|
5958
6096
|
//#endregion
|
|
5959
6097
|
//#region src/cli/create.ts
|
|
5960
6098
|
const langs = ["ts", "jsdoc"];
|
|
@@ -5970,16 +6108,16 @@ const noAddonsOption = new Option("--no-add-ons", "do not prompt to add add-ons"
|
|
|
5970
6108
|
const addOption = new Option("--add <addon...>", "add-ons to include (see Add-Ons section below)").default([]);
|
|
5971
6109
|
const noDownloadCheckOption = new Option("--no-download-check", "skip all download confirmation prompts");
|
|
5972
6110
|
const noInstallOption = new Option("--no-install", "skip installing dependencies");
|
|
5973
|
-
const ProjectPathSchema = optional(string());
|
|
5974
|
-
const OptionsSchema$1 = strictObject({
|
|
5975
|
-
types: pipe(optional(union([picklist(langs), boolean()])), transform((lang) => langMap[String(lang)])),
|
|
5976
|
-
addOns: boolean(),
|
|
5977
|
-
add: array(string()),
|
|
5978
|
-
install: union([boolean(), picklist(AGENT_NAMES)]),
|
|
5979
|
-
template: optional(picklist(templateChoices)),
|
|
5980
|
-
fromPlayground: optional(string()),
|
|
5981
|
-
dirCheck: boolean(),
|
|
5982
|
-
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()
|
|
5983
6121
|
});
|
|
5984
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({
|
|
5985
6123
|
...helpConfig,
|
|
@@ -6007,14 +6145,14 @@ const create = new Command("create").description("Scaffold a new project (--add
|
|
|
6007
6145
|
].join("\n");
|
|
6008
6146
|
}
|
|
6009
6147
|
}).action((projectPath, opts) => {
|
|
6010
|
-
const cwd
|
|
6011
|
-
const options
|
|
6012
|
-
if (options
|
|
6013
|
-
console.error(color.error(`Error: Invalid playground URL: ${options
|
|
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}`));
|
|
6014
6152
|
process$1.exit(1);
|
|
6015
6153
|
}
|
|
6016
6154
|
runCommand(async () => {
|
|
6017
|
-
const { directory, addOnNextSteps, packageManager } = await createProject(cwd
|
|
6155
|
+
const { directory, addOnNextSteps, packageManager } = await createProject(cwd, options);
|
|
6018
6156
|
let i = 1;
|
|
6019
6157
|
const initialSteps = ["📁 Project steps", ""];
|
|
6020
6158
|
const relative = path.relative(process$1.cwd(), directory);
|
|
@@ -6024,8 +6162,8 @@ const create = new Command("create").description("Scaffold a new project (--add
|
|
|
6024
6162
|
initialSteps.push(` ${i++}: ${color.command(`cd ${pathHasSpaces ? `"${relative}"` : relative}`)}`);
|
|
6025
6163
|
}
|
|
6026
6164
|
if (!packageManager) {
|
|
6027
|
-
const { args
|
|
6028
|
-
initialSteps.push(` ${i++}: ${color.command(`${command
|
|
6165
|
+
const { args, command } = resolveCommand(pm, "install", []);
|
|
6166
|
+
initialSteps.push(` ${i++}: ${color.command(`${command} ${args.join(" ")}`)}`);
|
|
6029
6167
|
}
|
|
6030
6168
|
const { args, command } = resolveCommand(pm, "run", ["dev", "--open"]);
|
|
6031
6169
|
const pmRunCmd = `${command} ${args.join(" ")}`;
|
|
@@ -6046,22 +6184,22 @@ const create = new Command("create").description("Scaffold a new project (--add
|
|
|
6046
6184
|
kt(steps.join("\n"), "What's next?", { format: (line) => line });
|
|
6047
6185
|
});
|
|
6048
6186
|
}).showHelpAfterError(true);
|
|
6049
|
-
async function createProject(cwd
|
|
6050
|
-
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.");
|
|
6051
6189
|
const promptGroupResult = await Rt({
|
|
6052
6190
|
directory: () => {
|
|
6053
6191
|
const defaultPath = "./";
|
|
6054
|
-
if (cwd
|
|
6192
|
+
if (cwd) return Promise.resolve(normalizePosix(cwd));
|
|
6055
6193
|
return Qt({
|
|
6056
6194
|
message: "Where would you like your project to be created?",
|
|
6057
6195
|
placeholder: ` (hit Enter to use '${defaultPath}')`,
|
|
6058
6196
|
defaultValue: defaultPath
|
|
6059
6197
|
});
|
|
6060
6198
|
},
|
|
6061
|
-
force: async ({ results: { directory
|
|
6062
|
-
if (!options
|
|
6063
|
-
if (!fs.existsSync(directory
|
|
6064
|
-
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;
|
|
6065
6203
|
const force = await Mt({
|
|
6066
6204
|
message: "Directory not empty. Continue?",
|
|
6067
6205
|
initialValue: false
|
|
@@ -6072,13 +6210,12 @@ async function createProject(cwd$1, options$8) {
|
|
|
6072
6210
|
}
|
|
6073
6211
|
},
|
|
6074
6212
|
template: () => {
|
|
6075
|
-
if (options
|
|
6076
|
-
if (options
|
|
6077
|
-
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");
|
|
6078
6215
|
return qt({
|
|
6079
6216
|
message: "Which template would you like?",
|
|
6080
6217
|
initialValue: "minimal",
|
|
6081
|
-
options:
|
|
6218
|
+
options: templates.filter((t) => t.name !== "addon").map((t) => ({
|
|
6082
6219
|
label: t.title,
|
|
6083
6220
|
value: t.name,
|
|
6084
6221
|
hint: t.description
|
|
@@ -6086,7 +6223,7 @@ async function createProject(cwd$1, options$8) {
|
|
|
6086
6223
|
});
|
|
6087
6224
|
},
|
|
6088
6225
|
language: (o) => {
|
|
6089
|
-
if (options
|
|
6226
|
+
if (options.types) return Promise.resolve(options.types);
|
|
6090
6227
|
if (o.results.template === "addon") return Promise.resolve("none");
|
|
6091
6228
|
return qt({
|
|
6092
6229
|
message: "Add type checking with TypeScript?",
|
|
@@ -6117,7 +6254,7 @@ async function createProject(cwd$1, options$8) {
|
|
|
6117
6254
|
const basename = path.basename(projectPath);
|
|
6118
6255
|
const parentDirName = path.basename(path.dirname(projectPath));
|
|
6119
6256
|
const projectName = parentDirName.startsWith("@") ? `${parentDirName}/${basename}` : basename;
|
|
6120
|
-
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.`);
|
|
6121
6258
|
let loadedAddons = [];
|
|
6122
6259
|
let answers = {};
|
|
6123
6260
|
let addonsOptionsMap = {};
|
|
@@ -6126,8 +6263,8 @@ async function createProject(cwd$1, options$8) {
|
|
|
6126
6263
|
template,
|
|
6127
6264
|
type: language
|
|
6128
6265
|
});
|
|
6129
|
-
if (template !== "addon" && (options
|
|
6130
|
-
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);
|
|
6131
6268
|
addonsOptionsMap = {};
|
|
6132
6269
|
for (const loaded of loadedAddons) addonsOptionsMap[loaded.addon.id] = loaded.reference.options;
|
|
6133
6270
|
const result = await promptAddonQuestions({
|
|
@@ -6135,7 +6272,7 @@ async function createProject(cwd$1, options$8) {
|
|
|
6135
6272
|
cwd: projectPath,
|
|
6136
6273
|
install: false,
|
|
6137
6274
|
gitCheck: false,
|
|
6138
|
-
downloadCheck: options
|
|
6275
|
+
downloadCheck: options.downloadCheck,
|
|
6139
6276
|
addons: addonsOptionsMap
|
|
6140
6277
|
},
|
|
6141
6278
|
loadedAddons,
|
|
@@ -6149,19 +6286,19 @@ async function createProject(cwd$1, options$8) {
|
|
|
6149
6286
|
template,
|
|
6150
6287
|
types: language
|
|
6151
6288
|
});
|
|
6152
|
-
if (options
|
|
6289
|
+
if (options.fromPlayground) await createProjectFromPlayground(options.fromPlayground, projectPath);
|
|
6153
6290
|
R.success("Project created");
|
|
6154
6291
|
let argsFormattedAddons = [];
|
|
6155
6292
|
let addOnFilesToFormat = [];
|
|
6156
6293
|
let addOnSuccessfulAddons = [];
|
|
6157
|
-
if (template !== "addon" && (options
|
|
6158
|
-
const { argsFormattedAddons: argsFormatted
|
|
6294
|
+
if (template !== "addon" && (options.addOns || options.add.length > 0)) {
|
|
6295
|
+
const { argsFormattedAddons: argsFormatted, filesToFormat, successfulAddons } = await runAddonsApply({
|
|
6159
6296
|
answers,
|
|
6160
6297
|
options: {
|
|
6161
6298
|
cwd: projectPath,
|
|
6162
6299
|
install: false,
|
|
6163
6300
|
gitCheck: false,
|
|
6164
|
-
downloadCheck: options
|
|
6301
|
+
downloadCheck: options.downloadCheck,
|
|
6165
6302
|
addons: addonsOptionsMap
|
|
6166
6303
|
},
|
|
6167
6304
|
loadedAddons,
|
|
@@ -6169,19 +6306,18 @@ async function createProject(cwd$1, options$8) {
|
|
|
6169
6306
|
workspace,
|
|
6170
6307
|
fromCommand: "create"
|
|
6171
6308
|
});
|
|
6172
|
-
argsFormattedAddons = argsFormatted
|
|
6309
|
+
argsFormattedAddons = argsFormatted;
|
|
6173
6310
|
addOnFilesToFormat = filesToFormat;
|
|
6174
6311
|
addOnSuccessfulAddons = successfulAddons;
|
|
6175
6312
|
}
|
|
6176
|
-
const packageManager = options
|
|
6313
|
+
const packageManager = options.install === false ? null : options.install === true ? await packageManagerPrompt(projectPath) : options.install;
|
|
6177
6314
|
const argsFormatted = [];
|
|
6178
6315
|
argsFormatted.push("--template", template);
|
|
6179
6316
|
if (language === "typescript") argsFormatted.push("--types", "ts");
|
|
6180
6317
|
else if (language === "checkjs") argsFormatted.push("--types", "jsdoc");
|
|
6181
6318
|
else if (language === "none") argsFormatted.push("--no-types");
|
|
6182
6319
|
if (argsFormattedAddons.length > 0) argsFormatted.push("--add", ...argsFormattedAddons);
|
|
6183
|
-
|
|
6184
|
-
updateReadme(directory, prompt);
|
|
6320
|
+
updateReadme(directory, buildAndLogArgs(packageManager, "create", argsFormatted, [directory]));
|
|
6185
6321
|
updateAgent(directory, language, packageManager ?? "npm", loadedAddons);
|
|
6186
6322
|
if (packageManager) workspace.packageManager = packageManager;
|
|
6187
6323
|
const addOnNextSteps = getNextSteps(addOnSuccessfulAddons, workspace, answers);
|
|
@@ -6200,10 +6336,10 @@ async function createProject(cwd$1, options$8) {
|
|
|
6200
6336
|
packageManager
|
|
6201
6337
|
};
|
|
6202
6338
|
}
|
|
6203
|
-
async function createProjectFromPlayground(url, cwd
|
|
6339
|
+
async function createProjectFromPlayground(url, cwd) {
|
|
6204
6340
|
const playground = await downloadPlaygroundData(parsePlaygroundUrl(url));
|
|
6205
6341
|
const dependencies = detectPlaygroundDependencies(playground.files);
|
|
6206
|
-
setupPlaygroundProject(url, playground, cwd
|
|
6342
|
+
setupPlaygroundProject(url, playground, cwd, await confirmExternalDependencies(Array.from(dependencies.keys())));
|
|
6207
6343
|
}
|
|
6208
6344
|
async function confirmExternalDependencies(dependencies) {
|
|
6209
6345
|
if (dependencies.length === 0) return false;
|
|
@@ -6219,7 +6355,7 @@ async function confirmExternalDependencies(dependencies) {
|
|
|
6219
6355
|
}
|
|
6220
6356
|
return installDeps;
|
|
6221
6357
|
}
|
|
6222
|
-
async function createVirtualWorkspace({ cwd
|
|
6358
|
+
async function createVirtualWorkspace({ cwd, template, type }) {
|
|
6223
6359
|
const override = { dependencies: {} };
|
|
6224
6360
|
if (template === "minimal" || template === "demo" || template === "library") override.kit = {
|
|
6225
6361
|
routesDirectory: "src/routes",
|
|
@@ -6232,7 +6368,7 @@ async function createVirtualWorkspace({ cwd: cwd$1, template, type }) {
|
|
|
6232
6368
|
...override.dependencies
|
|
6233
6369
|
};
|
|
6234
6370
|
const tentativeWorkspace = await createWorkspace({
|
|
6235
|
-
cwd
|
|
6371
|
+
cwd,
|
|
6236
6372
|
override
|
|
6237
6373
|
});
|
|
6238
6374
|
return {
|
|
@@ -6245,22 +6381,21 @@ async function createVirtualWorkspace({ cwd: cwd$1, template, type }) {
|
|
|
6245
6381
|
}
|
|
6246
6382
|
};
|
|
6247
6383
|
}
|
|
6248
|
-
|
|
6249
6384
|
//#endregion
|
|
6250
6385
|
//#region src/cli/add.ts
|
|
6251
6386
|
const officialAddons = Object.values(officialAddons$1);
|
|
6252
6387
|
const addonOptions = getAddonOptionFlags();
|
|
6253
|
-
const OptionsSchema = strictObject({
|
|
6254
|
-
cwd: string(),
|
|
6255
|
-
install: union([boolean(), picklist(AGENT_NAMES)]),
|
|
6256
|
-
gitCheck: boolean(),
|
|
6257
|
-
downloadCheck: boolean(),
|
|
6258
|
-
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())))
|
|
6259
6394
|
});
|
|
6260
6395
|
/**
|
|
6261
6396
|
* Classifies addon inputs into AddonReferences with source information.
|
|
6262
6397
|
*/
|
|
6263
|
-
function classifyAddons(inputs, cwd
|
|
6398
|
+
function classifyAddons(inputs, cwd) {
|
|
6264
6399
|
const seen = /* @__PURE__ */ new Map();
|
|
6265
6400
|
const invalidAddons = [];
|
|
6266
6401
|
for (const input of inputs) {
|
|
@@ -6283,7 +6418,7 @@ function classifyAddons(inputs, cwd$1) {
|
|
|
6283
6418
|
}
|
|
6284
6419
|
const source = {
|
|
6285
6420
|
kind: "file",
|
|
6286
|
-
path: path.resolve(cwd
|
|
6421
|
+
path: path.resolve(cwd, relativePath)
|
|
6287
6422
|
};
|
|
6288
6423
|
seen.set(input.specifier, {
|
|
6289
6424
|
specifier: input.specifier,
|
|
@@ -6296,13 +6431,13 @@ function classifyAddons(inputs, cwd$1) {
|
|
|
6296
6431
|
let tag;
|
|
6297
6432
|
if (normalized.startsWith("@")) {
|
|
6298
6433
|
const slashIndex = normalized.indexOf("/");
|
|
6299
|
-
const [name
|
|
6300
|
-
packageName = normalized.slice(0, slashIndex + 1) + name
|
|
6301
|
-
tag = version
|
|
6434
|
+
const [name, version = "latest"] = normalized.slice(slashIndex + 1).split("@");
|
|
6435
|
+
packageName = normalized.slice(0, slashIndex + 1) + name;
|
|
6436
|
+
tag = version;
|
|
6302
6437
|
} else {
|
|
6303
|
-
const [name
|
|
6304
|
-
packageName = name
|
|
6305
|
-
tag = version
|
|
6438
|
+
const [name, version = "latest"] = normalized.split("@");
|
|
6439
|
+
packageName = name;
|
|
6440
|
+
tag = version;
|
|
6306
6441
|
}
|
|
6307
6442
|
const npmUrl = `https://www.npmjs.com/package/${packageName}`;
|
|
6308
6443
|
const registryUrl = `https://registry.npmjs.org/${packageName}/${tag}`;
|
|
@@ -6367,26 +6502,26 @@ const add$1 = new Command("add").description("applies specified add-ons into a p
|
|
|
6367
6502
|
}).action(async (addonInputs, opts) => {
|
|
6368
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>`");
|
|
6369
6504
|
else if (!fs.existsSync(path.resolve(opts.cwd, "package.json"))) errorAndExit(`Invalid workspace: Path '${path.resolve(opts.cwd)}' is not a valid workspace.`);
|
|
6370
|
-
const options
|
|
6505
|
+
const options = parse$1(OptionsSchema, {
|
|
6371
6506
|
...opts,
|
|
6372
6507
|
addons: {}
|
|
6373
6508
|
});
|
|
6374
|
-
const addonRefs = classifyAddons(addonInputs, options
|
|
6375
|
-
const workspace = await createWorkspace({ cwd: options
|
|
6509
|
+
const addonRefs = classifyAddons(addonInputs, options.cwd);
|
|
6510
|
+
const workspace = await createWorkspace({ cwd: options.cwd });
|
|
6376
6511
|
runCommand(async () => {
|
|
6377
|
-
const loadedAddons = await resolveAddons(addonRefs, options
|
|
6512
|
+
const loadedAddons = await resolveAddons(addonRefs, options.downloadCheck);
|
|
6378
6513
|
for (const loaded of loadedAddons) {
|
|
6379
6514
|
const id = loaded.addon.id;
|
|
6380
|
-
options
|
|
6515
|
+
options.addons[id] = loaded.reference.options;
|
|
6381
6516
|
}
|
|
6382
6517
|
const { answers, loadedAddons: finalAddons } = await promptAddonQuestions({
|
|
6383
|
-
options
|
|
6518
|
+
options,
|
|
6384
6519
|
loadedAddons,
|
|
6385
6520
|
workspace
|
|
6386
6521
|
});
|
|
6387
6522
|
const { nextSteps } = await runAddonsApply({
|
|
6388
6523
|
answers,
|
|
6389
|
-
options
|
|
6524
|
+
options,
|
|
6390
6525
|
loadedAddons: finalAddons,
|
|
6391
6526
|
workspace,
|
|
6392
6527
|
fromCommand: "add"
|
|
@@ -6422,15 +6557,15 @@ async function resolveAddons(refs, downloadCheck) {
|
|
|
6422
6557
|
}
|
|
6423
6558
|
return loaded;
|
|
6424
6559
|
}
|
|
6425
|
-
async function promptAddonQuestions({ options
|
|
6560
|
+
async function promptAddonQuestions({ options, loadedAddons, workspace }) {
|
|
6426
6561
|
const addons = [...loadedAddons];
|
|
6427
6562
|
const emptyAnswersReducer = (acc, id) => {
|
|
6428
6563
|
acc[id] = {};
|
|
6429
6564
|
return acc;
|
|
6430
6565
|
};
|
|
6431
6566
|
const answers = addons.map((a) => a.addon.id).reduce(emptyAnswersReducer, {});
|
|
6432
|
-
for (const addonId of Object.keys(options
|
|
6433
|
-
const specifiedOptions = options
|
|
6567
|
+
for (const addonId of Object.keys(options.addons)) {
|
|
6568
|
+
const specifiedOptions = options.addons[addonId];
|
|
6434
6569
|
if (!specifiedOptions) continue;
|
|
6435
6570
|
const details = addons.find((a) => a.addon.id === addonId)?.addon;
|
|
6436
6571
|
if (!details) continue;
|
|
@@ -6440,15 +6575,15 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6440
6575
|
if (specifiedOptions.length > 0) {
|
|
6441
6576
|
for (const option of specifiedOptions) {
|
|
6442
6577
|
const [optionId, optionValue] = option.split(":", 2);
|
|
6443
|
-
const optionEntry = optionEntries.find(([id, question
|
|
6578
|
+
const optionEntry = optionEntries.find(([id, question]) => {
|
|
6444
6579
|
if (id === optionId) return true;
|
|
6445
|
-
if (question
|
|
6446
|
-
if (question
|
|
6447
|
-
if (!question
|
|
6448
|
-
} else if (question
|
|
6449
|
-
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;
|
|
6450
6585
|
}
|
|
6451
|
-
if (question
|
|
6586
|
+
if (question.condition) return question.condition(specifiedOptionsObject);
|
|
6452
6587
|
return true;
|
|
6453
6588
|
}
|
|
6454
6589
|
return false;
|
|
@@ -6487,14 +6622,14 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6487
6622
|
if (addons.length > 0) setupResults = setupAddons(addons, workspace);
|
|
6488
6623
|
if (addons.length === 0) {
|
|
6489
6624
|
const results = setupAddons(officialAddons.map((a) => createLoadedAddon(a)), workspace);
|
|
6490
|
-
const addonOptions
|
|
6625
|
+
const addonOptions = officialAddons.filter(({ id, hidden }) => results[id].unsupported.length === 0 && !hidden).map(({ id, homepage, shortDescription }) => ({
|
|
6491
6626
|
label: id,
|
|
6492
6627
|
value: id,
|
|
6493
6628
|
hint: `${shortDescription} - ${homepage}`
|
|
6494
6629
|
}));
|
|
6495
6630
|
const selected = await Lt({
|
|
6496
6631
|
message: `What would you like to add to your project? ${color.dim("(use arrow keys / space bar)")}`,
|
|
6497
|
-
options: addonOptions
|
|
6632
|
+
options: addonOptions,
|
|
6498
6633
|
required: false
|
|
6499
6634
|
});
|
|
6500
6635
|
if (Ct(selected)) {
|
|
@@ -6525,14 +6660,11 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6525
6660
|
const missingDependencies = setupResult.dependsOn.filter((depId) => !addons.some((a) => a.addon.id === depId));
|
|
6526
6661
|
for (const depId of missingDependencies) {
|
|
6527
6662
|
const addonChain = dependencyChains.get(addonId) ?? /* @__PURE__ */ new Set();
|
|
6528
|
-
if (addonChain.has(depId)) {
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
].join(" → ");
|
|
6534
|
-
errorAndExit(`Circular dependency detected: ${cyclePath}\nAdd-ons cannot have circular dependencies.`);
|
|
6535
|
-
}
|
|
6663
|
+
if (addonChain.has(depId)) errorAndExit(`Circular dependency detected: ${[
|
|
6664
|
+
...addonChain,
|
|
6665
|
+
addonId,
|
|
6666
|
+
depId
|
|
6667
|
+
].join(" → ")}\nAdd-ons cannot have circular dependencies.`);
|
|
6536
6668
|
const depChain = new Set(addonChain);
|
|
6537
6669
|
depChain.add(addonId);
|
|
6538
6670
|
dependencyChains.set(depId, depChain);
|
|
@@ -6558,7 +6690,7 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6558
6690
|
}
|
|
6559
6691
|
}
|
|
6560
6692
|
const addonDefinitions = addons.map((a) => a.addon);
|
|
6561
|
-
const verifications = [...verifyCleanWorkingDirectory(options
|
|
6693
|
+
const verifications = [...verifyCleanWorkingDirectory(options.cwd, options.gitCheck), ...verifyUnsupportedAddons(addonDefinitions, setupResults)];
|
|
6562
6694
|
const fails = [];
|
|
6563
6695
|
for (const verification of verifications) {
|
|
6564
6696
|
const { message, success } = await verification.run();
|
|
@@ -6568,8 +6700,7 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6568
6700
|
});
|
|
6569
6701
|
}
|
|
6570
6702
|
if (fails.length > 0) {
|
|
6571
|
-
|
|
6572
|
-
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 });
|
|
6573
6704
|
const force = await Mt({
|
|
6574
6705
|
message: "Verifications failed. Do you wish to continue?",
|
|
6575
6706
|
initialValue: false
|
|
@@ -6625,7 +6756,7 @@ async function promptAddonQuestions({ options: options$8, loadedAddons, workspac
|
|
|
6625
6756
|
answers
|
|
6626
6757
|
};
|
|
6627
6758
|
}
|
|
6628
|
-
async function runAddonsApply({ answers, options
|
|
6759
|
+
async function runAddonsApply({ answers, options, loadedAddons, setupResults, workspace, fromCommand }) {
|
|
6629
6760
|
if (!setupResults) setupResults = setupAddons(loadedAddons.length ? loadedAddons : officialAddons.map((a) => createLoadedAddon(a)), workspace);
|
|
6630
6761
|
if (loadedAddons.length === 0) return {
|
|
6631
6762
|
nextSteps: [],
|
|
@@ -6651,7 +6782,7 @@ async function runAddonsApply({ answers, options: options$8, loadedAddons, setup
|
|
|
6651
6782
|
Pt("All selected add-ons were canceled.");
|
|
6652
6783
|
process$1.exit(1);
|
|
6653
6784
|
} else R.success(`Successfully setup add-ons: ${addonSuccess.map((c) => color.addon(c)).join(", ")}`);
|
|
6654
|
-
const packageManager = options
|
|
6785
|
+
const packageManager = options.install === false ? null : options.install === true ? await packageManagerPrompt(options.cwd) : options.install;
|
|
6655
6786
|
await addPnpmBuildDependencies(workspace.cwd, packageManager, ["esbuild", ...pnpmBuildDependencies]);
|
|
6656
6787
|
const argsFormattedAddons = [];
|
|
6657
6788
|
for (const loaded of successfulAddons) {
|
|
@@ -6677,17 +6808,17 @@ async function runAddonsApply({ answers, options: options$8, loadedAddons, setup
|
|
|
6677
6808
|
if (optionParts.length > 0) argsFormattedAddons.push(`${addonSpecifier}="${optionParts.join("+")}"`);
|
|
6678
6809
|
else argsFormattedAddons.push(addonSpecifier);
|
|
6679
6810
|
}
|
|
6680
|
-
if (!options
|
|
6811
|
+
if (!options.downloadCheck) argsFormattedAddons.push("--no-download-check");
|
|
6681
6812
|
if (fromCommand === "add") {
|
|
6682
|
-
if (!options
|
|
6813
|
+
if (!options.gitCheck) argsFormattedAddons.push("--no-git-check");
|
|
6683
6814
|
buildAndLogArgs(packageManager, "add", argsFormattedAddons);
|
|
6684
6815
|
}
|
|
6685
6816
|
if (packageManager) {
|
|
6686
6817
|
workspace.packageManager = packageManager;
|
|
6687
|
-
await installDependencies(packageManager, options
|
|
6818
|
+
await installDependencies(packageManager, options.cwd);
|
|
6688
6819
|
await formatFiles({
|
|
6689
6820
|
packageManager,
|
|
6690
|
-
cwd: options
|
|
6821
|
+
cwd: options.cwd,
|
|
6691
6822
|
filesToFormat
|
|
6692
6823
|
});
|
|
6693
6824
|
}
|
|
@@ -6702,10 +6833,10 @@ function getNextSteps(loadedAddons, workspace, answers) {
|
|
|
6702
6833
|
return loadedAddons.map((loaded) => {
|
|
6703
6834
|
const addon = loaded.addon;
|
|
6704
6835
|
if (!addon.nextSteps) return;
|
|
6705
|
-
const addonOptions
|
|
6836
|
+
const addonOptions = answers[addon.id];
|
|
6706
6837
|
const addonNextSteps = addon.nextSteps({
|
|
6707
6838
|
...workspace,
|
|
6708
|
-
options: addonOptions
|
|
6839
|
+
options: addonOptions
|
|
6709
6840
|
});
|
|
6710
6841
|
if (addonNextSteps.length === 0) return;
|
|
6711
6842
|
let addonMessage = `${color.addon(addon.id)}:\n`;
|
|
@@ -6720,10 +6851,10 @@ function addonArgsHandler(acc, current) {
|
|
|
6720
6851
|
const [addonSpecifier, optionFlags] = current.split("=", 2);
|
|
6721
6852
|
if (acc.find(({ specifier }) => specifier === addonSpecifier)) errorAndExit(`Malformed arguments: Add-on '${addonSpecifier}' is repeated multiple times.`);
|
|
6722
6853
|
try {
|
|
6723
|
-
const options
|
|
6854
|
+
const options = parseAddonOptions(optionFlags);
|
|
6724
6855
|
acc.push({
|
|
6725
6856
|
specifier: addonSpecifier,
|
|
6726
|
-
options: options
|
|
6857
|
+
options: options ?? []
|
|
6727
6858
|
});
|
|
6728
6859
|
} catch (error) {
|
|
6729
6860
|
if (error instanceof Error) errorAndExit(error.message);
|
|
@@ -6736,23 +6867,23 @@ function getOfficialAddonIds() {
|
|
|
6736
6867
|
return officialAddons.map((a) => a.id);
|
|
6737
6868
|
}
|
|
6738
6869
|
function getAddonOptionFlags() {
|
|
6739
|
-
const options
|
|
6870
|
+
const options = [];
|
|
6740
6871
|
for (const addon of officialAddons) {
|
|
6741
6872
|
const id = addon.id;
|
|
6742
6873
|
const details = getAddonDetails(id);
|
|
6743
6874
|
if (Object.values(details.options).length === 0) continue;
|
|
6744
6875
|
const { groups, groupDefaults } = getOptionChoices(details);
|
|
6745
|
-
const choices = Object.entries(groups).map(([group, choices
|
|
6876
|
+
const choices = Object.entries(groups).map(([group, choices]) => {
|
|
6746
6877
|
const defaults = groupDefaults[group];
|
|
6747
6878
|
const defaultStr = defaults === void 0 ? "" : defaults.length > 0 ? ` (default: ${defaults.join(", ")})` : " (default: none)";
|
|
6748
|
-
return `${color.optional(`${group}:`)} ${color.dim(choices
|
|
6879
|
+
return `${color.optional(`${group}:`)} ${color.dim(choices.join(", "))}${defaultStr}`;
|
|
6749
6880
|
}).join("\n");
|
|
6750
|
-
options
|
|
6881
|
+
options.push({
|
|
6751
6882
|
id,
|
|
6752
6883
|
choices
|
|
6753
6884
|
});
|
|
6754
6885
|
}
|
|
6755
|
-
return options
|
|
6886
|
+
return options;
|
|
6756
6887
|
}
|
|
6757
6888
|
/**
|
|
6758
6889
|
* Shared addon help section used by `add --help`, `create --help`, and `sv --help`.
|
|
@@ -6776,37 +6907,37 @@ function getOptionChoices(details) {
|
|
|
6776
6907
|
const choices = [];
|
|
6777
6908
|
const groups = {};
|
|
6778
6909
|
const groupDefaults = {};
|
|
6779
|
-
const options
|
|
6910
|
+
const options = {};
|
|
6780
6911
|
for (const [id, question] of Object.entries(details.options)) {
|
|
6781
6912
|
let values = [];
|
|
6782
|
-
const applyDefault = question.condition?.(options
|
|
6913
|
+
const applyDefault = question.condition?.(options) !== false;
|
|
6783
6914
|
const groupId = question.group ?? id;
|
|
6784
6915
|
groupDefaults[groupId] ??= [];
|
|
6785
6916
|
if (question.type === "boolean") {
|
|
6786
6917
|
values = ["yes", `no`];
|
|
6787
6918
|
if (applyDefault) {
|
|
6788
|
-
options
|
|
6919
|
+
options[id] = question.default;
|
|
6789
6920
|
groupDefaults[groupId].push(question.default ? values[0] : values[1]);
|
|
6790
6921
|
}
|
|
6791
6922
|
}
|
|
6792
6923
|
if (question.type === "select") {
|
|
6793
6924
|
values = question.options.map((o) => o.value);
|
|
6794
6925
|
if (applyDefault) {
|
|
6795
|
-
options
|
|
6926
|
+
options[id] = question.default;
|
|
6796
6927
|
groupDefaults[groupId].push(question.default);
|
|
6797
6928
|
}
|
|
6798
6929
|
}
|
|
6799
6930
|
if (question.type === "multiselect") {
|
|
6800
6931
|
values = question.options.map((o) => o.value);
|
|
6801
6932
|
if (applyDefault) {
|
|
6802
|
-
options
|
|
6933
|
+
options[id] = question.default;
|
|
6803
6934
|
groupDefaults[groupId].push(...question.default);
|
|
6804
6935
|
}
|
|
6805
6936
|
}
|
|
6806
6937
|
if (question.type === "string" || question.type === "number") {
|
|
6807
6938
|
values = ["<user-input>"];
|
|
6808
6939
|
if (applyDefault && question.default !== void 0) {
|
|
6809
|
-
options
|
|
6940
|
+
options[id] = question.default;
|
|
6810
6941
|
groupDefaults[groupId].push(question.default.toString());
|
|
6811
6942
|
}
|
|
6812
6943
|
}
|
|
@@ -6864,32 +6995,29 @@ async function resolveNonOfficialAddons(refs, downloadCheck) {
|
|
|
6864
6995
|
stop("Downloaded community add-on packages");
|
|
6865
6996
|
} catch (err) {
|
|
6866
6997
|
stop("Failed to download community add-on packages");
|
|
6867
|
-
|
|
6868
|
-
errorAndExit(msg);
|
|
6998
|
+
errorAndExit(err instanceof Error ? err.message : "Unknown error");
|
|
6869
6999
|
}
|
|
6870
7000
|
return selectedAddons;
|
|
6871
7001
|
}
|
|
6872
|
-
|
|
6873
7002
|
//#endregion
|
|
6874
7003
|
//#region src/core/env.ts
|
|
6875
7004
|
const TESTING = process$1.env.NODE_ENV?.toLowerCase() === "test";
|
|
6876
|
-
|
|
6877
7005
|
//#endregion
|
|
6878
7006
|
//#region src/core/engine.ts
|
|
6879
|
-
async function add({ addons, cwd
|
|
7007
|
+
async function add({ addons, cwd, options, packageManager = "npm" }) {
|
|
6880
7008
|
const workspace = await createWorkspace({
|
|
6881
|
-
cwd
|
|
7009
|
+
cwd,
|
|
6882
7010
|
packageManager
|
|
6883
7011
|
});
|
|
6884
7012
|
const loadedAddons = Object.values(addons).map((addon) => createLoadedAddon(addon));
|
|
6885
7013
|
return await applyAddons({
|
|
6886
7014
|
loadedAddons,
|
|
6887
7015
|
workspace,
|
|
6888
|
-
options
|
|
7016
|
+
options,
|
|
6889
7017
|
setupResults: setupAddons(loadedAddons, workspace)
|
|
6890
7018
|
});
|
|
6891
7019
|
}
|
|
6892
|
-
async function applyAddons({ loadedAddons, workspace, setupResults, options
|
|
7020
|
+
async function applyAddons({ loadedAddons, workspace, setupResults, options }) {
|
|
6893
7021
|
const filesToFormat = /* @__PURE__ */ new Set();
|
|
6894
7022
|
const allPnpmBuildDependencies = [];
|
|
6895
7023
|
const status = {};
|
|
@@ -6897,7 +7025,7 @@ async function applyAddons({ loadedAddons, workspace, setupResults, options: opt
|
|
|
6897
7025
|
let hasFormatter = false;
|
|
6898
7026
|
for (const addon of ordered) {
|
|
6899
7027
|
const loaded = loadedAddons.find((l) => l.addon.id === addon.id);
|
|
6900
|
-
const workspaceOptions = options
|
|
7028
|
+
const workspaceOptions = options[addon.id] || {};
|
|
6901
7029
|
const addonWorkspace = await createWorkspace({
|
|
6902
7030
|
cwd: workspace.cwd,
|
|
6903
7031
|
packageManager: workspace.packageManager
|
|
@@ -6934,16 +7062,16 @@ function setupAddons(loadedAddons, workspace) {
|
|
|
6934
7062
|
try {
|
|
6935
7063
|
addon.setup?.({
|
|
6936
7064
|
...workspace,
|
|
6937
|
-
dependsOn: (name
|
|
6938
|
-
setupResult.dependsOn.push(name
|
|
6939
|
-
setupResult.runsAfter.push(name
|
|
7065
|
+
dependsOn: (name) => {
|
|
7066
|
+
setupResult.dependsOn.push(name);
|
|
7067
|
+
setupResult.runsAfter.push(name);
|
|
6940
7068
|
},
|
|
6941
7069
|
unsupported: (reason) => setupResult.unsupported.push(reason),
|
|
6942
|
-
runsAfter: (name
|
|
7070
|
+
runsAfter: (name) => setupResult.runsAfter.push(name)
|
|
6943
7071
|
});
|
|
6944
7072
|
} catch (err) {
|
|
6945
7073
|
const msg = err instanceof Error ? err.message : String(err);
|
|
6946
|
-
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 });
|
|
6947
7075
|
}
|
|
6948
7076
|
setupResults[addon.id] = setupResult;
|
|
6949
7077
|
}
|
|
@@ -6951,21 +7079,21 @@ function setupAddons(loadedAddons, workspace) {
|
|
|
6951
7079
|
}
|
|
6952
7080
|
async function runAddon({ addon, loaded, multiple, workspace, workspaceOptions }) {
|
|
6953
7081
|
const files = /* @__PURE__ */ new Set();
|
|
6954
|
-
const options
|
|
6955
|
-
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;
|
|
6956
7084
|
const dependencies = [];
|
|
6957
7085
|
const pnpmBuildDependencies = [];
|
|
6958
7086
|
const sv = {
|
|
6959
|
-
file: (path
|
|
7087
|
+
file: (path, content) => {
|
|
6960
7088
|
try {
|
|
6961
|
-
let fileContent = fileExists(workspace.cwd, path
|
|
7089
|
+
let fileContent = fileExists(workspace.cwd, path) ? readFile(workspace.cwd, path) : "";
|
|
6962
7090
|
fileContent = content(fileContent);
|
|
6963
7091
|
if (!fileContent) return fileContent;
|
|
6964
|
-
writeFile(workspace, path
|
|
6965
|
-
files.add(path
|
|
7092
|
+
writeFile(workspace, path, fileContent);
|
|
7093
|
+
files.add(path);
|
|
6966
7094
|
} catch (e) {
|
|
6967
7095
|
if (e instanceof Error) {
|
|
6968
|
-
e.message = `Unable to process '${path
|
|
7096
|
+
e.message = `Unable to process '${path}'. Reason: ${e.message}`;
|
|
6969
7097
|
throw e;
|
|
6970
7098
|
}
|
|
6971
7099
|
throw e;
|
|
@@ -6978,7 +7106,7 @@ async function runAddon({ addon, loaded, multiple, workspace, workspaceOptions }
|
|
|
6978
7106
|
if (!TESTING) R.step(`${addonPrefix}Running external command ${color.optional(`(${executedCommand})`)}`);
|
|
6979
7107
|
if (workspace.packageManager === "npm") args.unshift("--yes");
|
|
6980
7108
|
try {
|
|
6981
|
-
await
|
|
7109
|
+
await z(command, args, {
|
|
6982
7110
|
nodeOptions: {
|
|
6983
7111
|
cwd: workspace.cwd,
|
|
6984
7112
|
stdio: TESTING ? "pipe" : stdio
|
|
@@ -6987,20 +7115,20 @@ async function runAddon({ addon, loaded, multiple, workspace, workspaceOptions }
|
|
|
6987
7115
|
});
|
|
6988
7116
|
} catch (error) {
|
|
6989
7117
|
const typedError = error;
|
|
6990
|
-
throw new Error(`Failed to execute scripts '${executedCommand}': ${typedError.message}`, { cause:
|
|
7118
|
+
throw new Error(`Failed to execute scripts '${executedCommand}': ${typedError.message}`, { cause: error });
|
|
6991
7119
|
}
|
|
6992
7120
|
},
|
|
6993
|
-
dependency: (pkg, version
|
|
7121
|
+
dependency: (pkg, version) => {
|
|
6994
7122
|
dependencies.push({
|
|
6995
7123
|
pkg,
|
|
6996
|
-
version
|
|
7124
|
+
version,
|
|
6997
7125
|
dev: false
|
|
6998
7126
|
});
|
|
6999
7127
|
},
|
|
7000
|
-
devDependency: (pkg, version
|
|
7128
|
+
devDependency: (pkg, version) => {
|
|
7001
7129
|
dependencies.push({
|
|
7002
7130
|
pkg,
|
|
7003
|
-
version
|
|
7131
|
+
version,
|
|
7004
7132
|
dev: true
|
|
7005
7133
|
});
|
|
7006
7134
|
},
|
|
@@ -7015,12 +7143,12 @@ async function runAddon({ addon, loaded, multiple, workspace, workspaceOptions }
|
|
|
7015
7143
|
cancels.push(reason);
|
|
7016
7144
|
},
|
|
7017
7145
|
...workspace,
|
|
7018
|
-
options
|
|
7146
|
+
options,
|
|
7019
7147
|
sv
|
|
7020
7148
|
});
|
|
7021
7149
|
} catch (err) {
|
|
7022
7150
|
const msg = err instanceof Error ? err.message : String(err);
|
|
7023
|
-
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 });
|
|
7024
7152
|
}
|
|
7025
7153
|
if (cancels.length === 0) {
|
|
7026
7154
|
const pkgPath = installPackages(dependencies, workspace);
|
|
@@ -7037,6 +7165,5 @@ function orderAddons(addons, setupResults) {
|
|
|
7037
7165
|
return setupResults[a.id]?.runsAfter?.length - setupResults[b.id]?.runsAfter?.length;
|
|
7038
7166
|
});
|
|
7039
7167
|
}
|
|
7040
|
-
|
|
7041
7168
|
//#endregion
|
|
7042
|
-
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 };
|