sv 0.12.8 → 0.13.1
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 +13 -18
- package/dist/{engine-BZ0rj9tz.d.mts → engine-fG9K-byo.d.mts} +42 -52
- package/dist/engine-lCnxwqd0.mjs +12404 -0
- package/dist/shared.json +3 -3
- package/dist/src/index.d.mts +1 -1
- package/dist/src/index.mjs +2 -4
- package/dist/src/testing.d.mts +11 -7
- package/dist/src/testing.mjs +124 -47
- package/dist/templates/addon/assets/src/index.js +35 -35
- package/dist/templates/addon/assets/tests/setup/suite.js +3 -128
- package/dist/templates/addon/assets/tsdown.config.js +6 -0
- package/dist/templates/addon/package.json +16 -8
- package/dist/templates/demo/assets/src/app.html +1 -0
- 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/assets/src/app.html +1 -0
- package/dist/templates/library/package.json +1 -1
- package/dist/templates/minimal/assets/src/app.html +1 -0
- package/dist/templates/minimal/package.json +1 -1
- package/dist/templates/svelte/files.types=none.json +1 -1
- package/dist/templates/svelte/files.types=typescript.json +1 -1
- package/package.json +2 -2
- package/dist/engine-DUNH7ELq.mjs +0 -7042
- package/dist/package-manager-BYzDyeam.mjs +0 -5964
package/dist/bin.mjs
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { a as helpConfig, i as forwardExitCode, n as add, o as name, r as create, s as version } from "./engine-DUNH7ELq.mjs";
|
|
2
|
+
import { a as detectPackageManager, c as name, h as program, l as version, m as Command, n as add, o as forwardExitCode, p as from, r as create, s as helpConfig } from "./engine-lCnxwqd0.mjs";
|
|
4
3
|
import { color, resolveCommand } from "@sveltejs/sv-utils";
|
|
5
4
|
import process from "node:process";
|
|
6
5
|
import { execSync } from "node:child_process";
|
|
7
|
-
|
|
8
6
|
//#region src/cli/check.ts
|
|
9
|
-
const check = new Command("check").description("a CLI for checking your Svelte code").allowUnknownOption(true).allowExcessArguments(true).option("-C, --cwd <path>", "path to working directory", process.cwd()).helpOption(false).action(async (options, check
|
|
10
|
-
const cwd
|
|
11
|
-
const args = check
|
|
12
|
-
await runCheck(cwd
|
|
7
|
+
const check = new Command("check").description("a CLI for checking your Svelte code").allowUnknownOption(true).allowExcessArguments(true).option("-C, --cwd <path>", "path to working directory", process.cwd()).helpOption(false).action(async (options, check) => {
|
|
8
|
+
const cwd = options.cwd;
|
|
9
|
+
const args = check.args;
|
|
10
|
+
await runCheck(cwd, args);
|
|
13
11
|
});
|
|
14
|
-
async function runCheck(cwd
|
|
15
|
-
const pm = await detectPackageManager(cwd
|
|
16
|
-
if (!from(cwd
|
|
12
|
+
async function runCheck(cwd, args) {
|
|
13
|
+
const pm = await detectPackageManager(cwd);
|
|
14
|
+
if (!from(cwd, "svelte-check", true)) {
|
|
17
15
|
const cmd = resolveCommand(pm, "add", ["-D", "svelte-check"]);
|
|
18
16
|
console.error(`'svelte-check' is not installed locally. Install it with: ${color.command(`${cmd.command} ${cmd.args.join(" ")}`)}`);
|
|
19
17
|
process.exit(1);
|
|
@@ -26,7 +24,7 @@ async function runCheck(cwd$1, args) {
|
|
|
26
24
|
const cmd = resolveCommand(pm, "execute-local", ["svelte-check", ...args]);
|
|
27
25
|
execSync(`${cmd.command} ${cmd.args.join(" ")}`, {
|
|
28
26
|
stdio: "inherit",
|
|
29
|
-
cwd
|
|
27
|
+
cwd
|
|
30
28
|
});
|
|
31
29
|
} catch (error) {
|
|
32
30
|
forwardExitCode(error);
|
|
@@ -34,27 +32,25 @@ async function runCheck(cwd$1, args) {
|
|
|
34
32
|
if (args.includes("--help")) check.help();
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
//#endregion
|
|
39
36
|
//#region src/cli/migrate.ts
|
|
40
37
|
const migrate = new Command("migrate").description("a CLI for migrating Svelte(Kit) codebases").argument("[migration]", "migration to run").option("-C, --cwd <path>", "path to working directory", process.cwd()).action(async (migration, options) => {
|
|
41
38
|
await runMigrate(options.cwd, [migration]);
|
|
42
39
|
});
|
|
43
|
-
async function runMigrate(cwd
|
|
44
|
-
const pm = await detectPackageManager(cwd
|
|
40
|
+
async function runMigrate(cwd, args) {
|
|
41
|
+
const pm = await detectPackageManager(cwd);
|
|
45
42
|
try {
|
|
46
43
|
const cmdArgs = ["svelte-migrate@latest", ...args];
|
|
47
44
|
if (pm === "npm") cmdArgs.unshift("--yes");
|
|
48
45
|
const cmd = resolveCommand(pm, "execute", cmdArgs);
|
|
49
46
|
execSync(`${cmd.command} ${cmd.args.join(" ")}`, {
|
|
50
47
|
stdio: "inherit",
|
|
51
|
-
cwd
|
|
48
|
+
cwd
|
|
52
49
|
});
|
|
53
50
|
} catch (error) {
|
|
54
51
|
forwardExitCode(error);
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
|
-
|
|
58
54
|
//#endregion
|
|
59
55
|
//#region bin.ts
|
|
60
56
|
console.log();
|
|
@@ -62,6 +58,5 @@ program.name(name).version(version, "-v, --version").configureHelp(helpConfig);
|
|
|
62
58
|
program.addCommand(create).addCommand(add).addCommand(migrate).addCommand(check);
|
|
63
59
|
if (process.argv.includes("--help") || process.argv.includes("-h")) program.addHelpText("after", () => "\n" + create.helpInformation());
|
|
64
60
|
program.parse();
|
|
65
|
-
|
|
66
61
|
//#endregion
|
|
67
|
-
export {
|
|
62
|
+
export {};
|
|
@@ -35,20 +35,20 @@ type NumberQuestion = {
|
|
|
35
35
|
validate?: (value: string | undefined) => string | Error | undefined;
|
|
36
36
|
placeholder?: string;
|
|
37
37
|
};
|
|
38
|
-
type SelectQuestion<Value
|
|
38
|
+
type SelectQuestion<Value> = {
|
|
39
39
|
type: "select";
|
|
40
|
-
default: NoInfer<Value
|
|
40
|
+
default: NoInfer<Value>;
|
|
41
41
|
options: Array<{
|
|
42
|
-
value: Value
|
|
42
|
+
value: Value;
|
|
43
43
|
label?: string;
|
|
44
44
|
hint?: string;
|
|
45
45
|
}>;
|
|
46
46
|
};
|
|
47
|
-
type MultiSelectQuestion<Value
|
|
47
|
+
type MultiSelectQuestion<Value> = {
|
|
48
48
|
type: "multiselect";
|
|
49
|
-
default: NoInfer<Value
|
|
49
|
+
default: NoInfer<Value[]>;
|
|
50
50
|
options: Array<{
|
|
51
|
-
value: Value
|
|
51
|
+
value: Value;
|
|
52
52
|
label?: string;
|
|
53
53
|
hint?: string;
|
|
54
54
|
}>;
|
|
@@ -79,13 +79,12 @@ type Workspace = {
|
|
|
79
79
|
* @param pkg the package to check for
|
|
80
80
|
* @returns the dependency version with any leading characters such as ^ or ~ removed
|
|
81
81
|
*/
|
|
82
|
-
dependencyVersion: (pkg: string) => string | undefined;
|
|
83
|
-
/** to know if the workspace is using typescript or javascript */
|
|
82
|
+
dependencyVersion: (pkg: string) => string | undefined; /** to know if the workspace is using typescript or javascript */
|
|
84
83
|
language: "ts" | "js";
|
|
85
|
-
|
|
84
|
+
file: {
|
|
86
85
|
viteConfig: "vite.config.js" | "vite.config.ts";
|
|
87
86
|
svelteConfig: "svelte.config.js" | "svelte.config.ts";
|
|
88
|
-
/** `${
|
|
87
|
+
typeConfig: "jsconfig.json" | "tsconfig.json" | undefined; /** `${directory.routes}/layout.css` or `src/app.css` */
|
|
89
88
|
stylesheet: `${string}/layout.css` | "src/app.css";
|
|
90
89
|
package: "package.json";
|
|
91
90
|
gitignore: ".gitignore";
|
|
@@ -93,8 +92,7 @@ type Workspace = {
|
|
|
93
92
|
prettierrc: ".prettierrc";
|
|
94
93
|
eslintConfig: "eslint.config.js";
|
|
95
94
|
vscodeSettings: ".vscode/settings.json";
|
|
96
|
-
vscodeExtensions: ".vscode/extensions.json";
|
|
97
|
-
/** Get the relative path between two files */
|
|
95
|
+
vscodeExtensions: ".vscode/extensions.json"; /** Get the relative path between two files */
|
|
98
96
|
getRelative: ({
|
|
99
97
|
from,
|
|
100
98
|
to
|
|
@@ -103,19 +101,20 @@ type Workspace = {
|
|
|
103
101
|
to: string;
|
|
104
102
|
}) => string;
|
|
105
103
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
/** The package manager used to install dependencies */
|
|
104
|
+
isKit: boolean;
|
|
105
|
+
directory: {
|
|
106
|
+
src: string; /** In SvelteKit taking `kit.files.lib` automatically. Falls back to `src/lib` in non-Kit projects */
|
|
107
|
+
lib: string; /** In SvelteKit taking `kit.files.routes` automatically. Falls back to `src/routes` in non-Kit projects */
|
|
108
|
+
kitRoutes: string;
|
|
109
|
+
}; /** The package manager used to install dependencies */
|
|
112
110
|
packageManager: AgentName;
|
|
113
111
|
};
|
|
114
112
|
type CreateWorkspaceOptions = {
|
|
115
113
|
cwd: string;
|
|
116
114
|
packageManager?: AgentName;
|
|
117
115
|
override?: {
|
|
118
|
-
|
|
116
|
+
isKit?: boolean;
|
|
117
|
+
directory?: Workspace["directory"];
|
|
119
118
|
dependencies: Record<string, string>;
|
|
120
119
|
};
|
|
121
120
|
};
|
|
@@ -140,51 +139,43 @@ type Scripts = {
|
|
|
140
139
|
condition?: ConditionDefinition;
|
|
141
140
|
};
|
|
142
141
|
type SvApi = {
|
|
143
|
-
/** Add a package to the pnpm build dependencies. */
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
dependency: (pkg: string, version: string) => void;
|
|
147
|
-
/** Add a package to the dev dependencies. */
|
|
148
|
-
devDependency: (pkg: string, version: string) => void;
|
|
149
|
-
/** Execute a command in the workspace. */
|
|
142
|
+
/** Add a package to the pnpm build dependencies. */pnpmBuildDependency: (pkg: string) => void; /** Add a package to the dependencies. */
|
|
143
|
+
dependency: (pkg: string, version: string) => void; /** Add a package to the dev dependencies. */
|
|
144
|
+
devDependency: (pkg: string, version: string) => void; /** Execute a command in the workspace. */
|
|
150
145
|
execute: (args: string[], stdio: "inherit" | "pipe") => Promise<void>;
|
|
151
|
-
/**
|
|
152
|
-
file
|
|
146
|
+
/**
|
|
147
|
+
* Edit a file in the workspace. (will create it if it doesn't exist)
|
|
148
|
+
*
|
|
149
|
+
* Return `false` from the callback to abort - the original content is returned unchanged.
|
|
150
|
+
*/
|
|
151
|
+
file: (path: string, edit: (content: string) => string | false) => void;
|
|
153
152
|
};
|
|
154
|
-
type Addon<Args extends OptionDefinition, Id
|
|
155
|
-
id: Id
|
|
153
|
+
type Addon<Args extends OptionDefinition, Id extends string = string> = {
|
|
154
|
+
id: Id;
|
|
156
155
|
alias?: string;
|
|
157
156
|
shortDescription?: string;
|
|
158
|
-
homepage?: string;
|
|
159
|
-
/** If true, this addon won't appear in the interactive prompt but can still be used via CLI */
|
|
157
|
+
homepage?: string; /** If true, this addon won't appear in the interactive prompt but can still be used via CLI */
|
|
160
158
|
hidden?: boolean;
|
|
161
|
-
options: Args;
|
|
162
|
-
/** Setup the addon. Will be called before the addon is run. */
|
|
159
|
+
options: Args; /** Setup the addon. Will be called before the addon is run. */
|
|
163
160
|
setup?: (workspace: Workspace & {
|
|
164
|
-
/** On what official addons does this addon depend on? */
|
|
165
|
-
dependsOn: (name: keyof typeof officialAddons) => void;
|
|
161
|
+
/** On what official addons does this addon depend on? */dependsOn: (name: keyof typeof officialAddons) => void;
|
|
166
162
|
/** Why is this addon not supported?
|
|
167
163
|
*
|
|
168
164
|
* @example
|
|
169
|
-
* if (!
|
|
165
|
+
* if (!isKit) unsupported('Requires SvelteKit');
|
|
170
166
|
*/
|
|
171
|
-
unsupported: (reason: string) => void;
|
|
172
|
-
/** On what official addons does this addon run after? */
|
|
167
|
+
unsupported: (reason: string) => void; /** On what official addons does this addon run after? */
|
|
173
168
|
runsAfter: (name: keyof typeof officialAddons) => void;
|
|
174
|
-
}) => MaybePromise<void>;
|
|
175
|
-
/** Run the addon. The actual execution of the addon... Add files, edit files, etc. */
|
|
169
|
+
}) => MaybePromise<void>; /** Run the addon. The actual execution of the addon... Add files, edit files, etc. */
|
|
176
170
|
run: (workspace: Workspace & {
|
|
177
|
-
/** Add-on options */
|
|
178
|
-
options: WorkspaceOptions<Args>;
|
|
179
|
-
/** Api to interact with the workspace. */
|
|
171
|
+
/** Add-on options */options: WorkspaceOptions<Args>; /** Api to interact with the workspace. */
|
|
180
172
|
sv: SvApi;
|
|
181
173
|
/** Cancel the addon at any time!
|
|
182
174
|
* @example
|
|
183
175
|
* return cancel('There is a problem with...');
|
|
184
176
|
*/
|
|
185
177
|
cancel: (reason: string) => void;
|
|
186
|
-
}) => MaybePromise<void>;
|
|
187
|
-
/** Next steps to display after the addon is run. */
|
|
178
|
+
}) => MaybePromise<void>; /** Next steps to display after the addon is run. */
|
|
188
179
|
nextSteps?: (data: Workspace & {
|
|
189
180
|
options: WorkspaceOptions<Args>;
|
|
190
181
|
}) => string[];
|
|
@@ -192,7 +183,7 @@ type Addon<Args extends OptionDefinition, Id$1 extends string = string> = {
|
|
|
192
183
|
/**
|
|
193
184
|
* The entry point for your addon, It will hold every thing! (options, setup, run, nextSteps, ...)
|
|
194
185
|
*/
|
|
195
|
-
declare function defineAddon<const Id
|
|
186
|
+
declare function defineAddon<const Id extends string, Args extends OptionDefinition>(config: Addon<Args, Id>): Addon<Args, Id>;
|
|
196
187
|
/**
|
|
197
188
|
* Stage 1: Raw CLI input - what the user typed
|
|
198
189
|
*/
|
|
@@ -259,7 +250,7 @@ type SetupResult = {
|
|
|
259
250
|
unsupported: string[];
|
|
260
251
|
runsAfter: string[];
|
|
261
252
|
};
|
|
262
|
-
type AddonDefinition<Id
|
|
253
|
+
type AddonDefinition<Id extends string = string> = Addon<Record<string, Question<any>>, Id>;
|
|
263
254
|
type Tests = {
|
|
264
255
|
expectProperty: (selector: string, property: string, expectedValue: string) => Promise<void>;
|
|
265
256
|
elementExists: (selector: string) => Promise<void>;
|
|
@@ -295,8 +286,7 @@ type OptionBuilder<T extends OptionDefinition> = {
|
|
|
295
286
|
* })
|
|
296
287
|
* ```
|
|
297
288
|
*/
|
|
298
|
-
add<K
|
|
299
|
-
/** Finalize all options of your `add-on`. */
|
|
289
|
+
add<K extends string, const Q extends Question<T & Record<K, Q>>>(key: K, question: Q): OptionBuilder<T & Record<K, Q>>; /** Finalize all options of your `add-on`. */
|
|
300
290
|
build(): Prettify<T>;
|
|
301
291
|
};
|
|
302
292
|
/**
|
|
@@ -329,8 +319,8 @@ type InstallOptions<Addons extends AddonMap> = {
|
|
|
329
319
|
packageManager?: AgentName;
|
|
330
320
|
};
|
|
331
321
|
type AddonMap = Record<string, Addon<any, any>>;
|
|
332
|
-
type AddonById<Addons extends AddonMap, Id
|
|
333
|
-
id: Id
|
|
322
|
+
type AddonById<Addons extends AddonMap, Id extends string> = Extract<Addons[keyof Addons], {
|
|
323
|
+
id: Id;
|
|
334
324
|
}>;
|
|
335
325
|
type OptionMap<Addons extends AddonMap> = { [Id in Addons[keyof Addons]["id"]]: Partial<OptionValues<AddonById<Addons, Id>["options"]>> };
|
|
336
326
|
declare function add<Addons extends AddonMap>({
|