Skip to content

Commit b48c291

Browse files
jycouetAdrianGonz97sxzz
authored
fix(cli): export types & switch to tsdown (#719)
Co-authored-by: CokaKoala <[email protected]> Co-authored-by: Kevin Deng <[email protected]>
1 parent 0841275 commit b48c291

File tree

16 files changed

+598
-580
lines changed

16 files changed

+598
-580
lines changed

.changeset/olive-states-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
fix(cli): export types

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"pnpm": "^10.0.0"
99
},
1010
"scripts": {
11-
"build": "rolldown --config",
11+
"build": "tsdown",
1212
"changeset:publish": "changeset publish",
1313
"check": "pnpm --parallel check",
14-
"dev": "rolldown --watch --config",
14+
"dev": "tsdown -w",
1515
"format": "pnpm --parallel format",
1616
"lint": "pnpm --parallel lint && eslint --cache --cache-location node_modules/.eslintcache",
1717
"test": "vitest run --silent",
@@ -32,12 +32,11 @@
3232
"prettier": "^3.5.3",
3333
"prettier-plugin-packagejson": "^2.5.15",
3434
"prettier-plugin-svelte": "^3.4.0",
35-
"rolldown": "1.0.0-beta.1",
3635
"sv": "workspace:*",
3736
"svelte": "^5.34.6",
37+
"tsdown": "^0.15.2",
3838
"typescript": "^5.8.3",
3939
"typescript-eslint": "^8.34.1",
40-
"unplugin-isolated-decl": "^0.8.3",
4140
"vitest": "4.0.0-beta.6"
4241
},
4342
"packageManager": "[email protected]",

packages/addons/_config/official.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AddonWithoutExplicitArgs } from '@sveltejs/cli-core';
1+
import type { Addon, AddonWithoutExplicitArgs } from '@sveltejs/cli-core';
22

33
import devtoolsJson from '../devtools-json/index.ts';
44
import drizzle from '../drizzle/index.ts';
@@ -13,9 +13,24 @@ import sveltekitAdapter from '../sveltekit-adapter/index.ts';
1313
import tailwindcss from '../tailwindcss/index.ts';
1414
import vitest from '../vitest-addon/index.ts';
1515

16+
type OfficialAddons = {
17+
prettier: Addon<any>;
18+
eslint: Addon<any>;
19+
vitest: Addon<any>;
20+
playwright: Addon<any>;
21+
tailwindcss: Addon<any>;
22+
sveltekitAdapter: Addon<any>;
23+
devtoolsJson: Addon<any>;
24+
drizzle: Addon<any>;
25+
lucia: Addon<any>;
26+
mdsvex: Addon<any>;
27+
paraglide: Addon<any>;
28+
storybook: Addon<any>;
29+
};
30+
1631
// The order of addons here determines the order they are displayed inside the CLI
1732
// We generally try to order them by perceived popularity
18-
export const officialAddons = [
33+
export const officialAddons: OfficialAddons = {
1934
prettier,
2035
eslint,
2136
vitest,
@@ -28,10 +43,10 @@ export const officialAddons = [
2843
mdsvex,
2944
paraglide,
3045
storybook
31-
] as AddonWithoutExplicitArgs[];
46+
};
3247

3348
export function getAddonDetails(id: string): AddonWithoutExplicitArgs {
34-
const details = officialAddons.find((a) => a.id === id);
49+
const details = Object.values(officialAddons).find((a) => a.id === id);
3550
if (!details) {
3651
throw new Error(`Invalid add-on: ${id}`);
3752
}

packages/addons/_tests/all-addons/test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ import { officialAddons } from '../../index.ts';
55
import type { AddonMap, OptionMap } from 'sv';
66

77
const windowsCI = process.env.CI && process.platform === 'win32';
8-
const addons = officialAddons.reduce<AddonMap>((addonMap, addon) => {
8+
const addons = Object.values(officialAddons).reduce<AddonMap>((addonMap, addon) => {
99
if (addon.id === 'storybook' && windowsCI) return addonMap;
1010
addonMap[addon.id] = addon;
1111
return addonMap;
1212
}, {});
1313

14-
const defaultOptions = officialAddons.reduce<OptionMap<typeof addons>>((options, addon) => {
15-
options[addon.id] = {};
16-
return options;
17-
}, {});
14+
const defaultOptions = Object.values(officialAddons).reduce<OptionMap<typeof addons>>(
15+
(options, addon) => {
16+
options[addon.id] = {};
17+
return options;
18+
},
19+
{}
20+
);
1821

1922
const { test, variants, prepareServer } = setupTest(addons);
2023

packages/addons/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["index.ts"]
4+
}

packages/cli/commands/add/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as pkg from 'empathic/package';
77
import * as p from '@clack/prompts';
88
import { Command } from 'commander';
99
import {
10-
officialAddons,
10+
officialAddons as _officialAddons,
1111
getAddonDetails,
1212
communityAddonIds,
1313
getCommunityAddon
@@ -28,6 +28,7 @@ import {
2828
import { verifyCleanWorkingDirectory, verifyUnsupportedAddons } from './verifiers.ts';
2929
import { type AddonMap, applyAddons, setupAddons } from '../../lib/install.ts';
3030

31+
const officialAddons = Object.values(_officialAddons);
3132
const aliases = officialAddons.map((c) => c.alias).filter((v) => v !== undefined);
3233
const addonOptions = getAddonOptionFlags();
3334
const communityDetails: AddonWithoutExplicitArgs[] = [];
@@ -404,7 +405,7 @@ export async function runAddCommand(
404405
}
405406

406407
for (const id of selected) {
407-
const addon = officialAddons.find((addon) => addon.id === id)!;
408+
const addon = getAddonDetails(id);
408409
selectedAddons.push({ type: 'official', addon });
409410
}
410411
}
@@ -422,7 +423,7 @@ export async function runAddCommand(
422423

423424
for (const depId of missingDependencies) {
424425
// TODO: this will have to be adjusted when we work on community add-ons
425-
const dependency = officialAddons.find((a) => a.id === depId);
426+
const dependency = getAddonDetails(depId);
426427
if (!dependency) throw new Error(`'${addon.id}' depends on an invalid add-on: '${depId}'`);
427428

428429
// prompt to install the dependent

packages/cli/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { create } from '@sveltejs/create';
1+
export { create, type TemplateType, type LanguageType } from '@sveltejs/create';
22
export { installAddon } from './install.ts';
33
export type { AddonMap, InstallOptions, OptionMap } from './install.ts';
44
export { officialAddons } from '@sveltejs/addons';

packages/cli/lib/install.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import type {
55
OptionValues,
66
Question,
77
SvApi,
8-
AddonSetupResult,
9-
AddonWithoutExplicitArgs
8+
AddonSetupResult
109
} from '@sveltejs/cli-core';
1110
import pc from 'picocolors';
1211
import * as p from '@clack/prompts';
@@ -23,7 +22,8 @@ export type InstallOptions<Addons extends AddonMap> = {
2322
packageManager?: PackageManager;
2423
};
2524

26-
export type AddonMap = Record<string, Addon<any>>;
25+
// @ts-expect-error TODO: this _should_ be `Addon<any>`, but the types won't infer properly with it
26+
export type AddonMap = Record<string, Addon>;
2727
export type OptionMap<Addons extends AddonMap> = {
2828
[K in keyof Addons]: Partial<OptionValues<Addons[K]['options']>>;
2929
};
@@ -81,7 +81,7 @@ export async function applyAddons({
8181
}
8282

8383
export function setupAddons(
84-
addons: AddonWithoutExplicitArgs[],
84+
addons: Array<Addon<any>>,
8585
workspace: Workspace<any>
8686
): Record<string, AddonSetupResult> {
8787
const addonSetupResults: Record<string, AddonSetupResult> = {};

packages/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/sveltejs/cli",
9+
"url": "git+https://github.com/sveltejs/cli.git",
1010
"directory": "packages/cli"
1111
},
1212
"homepage": "https://svelte.dev",
@@ -22,11 +22,11 @@
2222
"exports": {
2323
".": {
2424
"types": "./dist/lib/index.d.ts",
25-
"default": "./dist/index.js"
25+
"default": "./dist/lib/index.js"
2626
},
2727
"./testing": {
2828
"types": "./dist/lib/testing.d.ts",
29-
"default": "./dist/testing.js"
29+
"default": "./dist/lib/testing.js"
3030
}
3131
},
3232
"devDependencies": {

packages/cli/utils/package-manager.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import {
1414
} from 'package-manager-detector';
1515
import { parseJson } from '@sveltejs/cli-core/parsers';
1616

17-
export const AGENT_NAMES = AGENTS.filter((agent): agent is AgentName => !agent.includes('@'));
17+
export const AGENT_NAMES: AgentName[] = AGENTS.filter(
18+
(agent): agent is AgentName => !agent.includes('@')
19+
);
1820
const agentOptions: PackageManagerOptions = AGENT_NAMES.map((pm) => ({ value: pm, label: pm }));
1921
agentOptions.unshift({ label: 'None', value: undefined });
2022

21-
export const installOption = new Option(
23+
export const installOption: Option = new Option(
2224
'--install <package-manager>',
2325
'installs dependencies with a specified package manager'
2426
).choices(AGENT_NAMES);
@@ -91,7 +93,7 @@ export function addPnpmBuildDependencies(
9193
cwd: string,
9294
packageManager: AgentName | null | undefined,
9395
allowedPackages: string[]
94-
) {
96+
): void {
9597
// other package managers are currently not affected by this change
9698
if (!packageManager || packageManager !== 'pnpm') return;
9799

0 commit comments

Comments
 (0)