Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-states-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix(cli): export types
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"pnpm": "^10.0.0"
},
"scripts": {
"build": "rolldown --config",
"build": "tsdown",
"changeset:publish": "changeset publish",
"check": "pnpm --parallel check",
"dev": "rolldown --watch --config",
"dev": "tsdown -w",
"format": "pnpm --parallel format",
"lint": "pnpm --parallel lint && eslint --cache --cache-location node_modules/.eslintcache",
"test": "vitest run --silent",
Expand All @@ -32,12 +32,11 @@
"prettier": "^3.5.3",
"prettier-plugin-packagejson": "^2.5.15",
"prettier-plugin-svelte": "^3.4.0",
"rolldown": "1.0.0-beta.1",
"sv": "workspace:*",
"svelte": "^5.34.6",
"tsdown": "^0.15.2",
"typescript": "^5.8.3",
"typescript-eslint": "^8.34.1",
"unplugin-isolated-decl": "^0.8.3",
"vitest": "4.0.0-beta.6"
},
"packageManager": "[email protected]",
Expand Down
23 changes: 19 additions & 4 deletions packages/addons/_config/official.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AddonWithoutExplicitArgs } from '@sveltejs/cli-core';
import type { Addon, AddonWithoutExplicitArgs } from '@sveltejs/cli-core';

import devtoolsJson from '../devtools-json/index.ts';
import drizzle from '../drizzle/index.ts';
Expand All @@ -13,9 +13,24 @@ import sveltekitAdapter from '../sveltekit-adapter/index.ts';
import tailwindcss from '../tailwindcss/index.ts';
import vitest from '../vitest-addon/index.ts';

type OfficialAddons = {
prettier: Addon<any>;
eslint: Addon<any>;
vitest: Addon<any>;
playwright: Addon<any>;
tailwindcss: Addon<any>;
sveltekitAdapter: Addon<any>;
devtoolsJson: Addon<any>;
drizzle: Addon<any>;
lucia: Addon<any>;
mdsvex: Addon<any>;
paraglide: Addon<any>;
storybook: Addon<any>;
};

// The order of addons here determines the order they are displayed inside the CLI
// We generally try to order them by perceived popularity
export const officialAddons = [
export const officialAddons: OfficialAddons = {
prettier,
eslint,
vitest,
Expand All @@ -28,10 +43,10 @@ export const officialAddons = [
mdsvex,
paraglide,
storybook
] as AddonWithoutExplicitArgs[];
};

export function getAddonDetails(id: string): AddonWithoutExplicitArgs {
const details = officialAddons.find((a) => a.id === id);
const details = Object.values(officialAddons).find((a) => a.id === id);
if (!details) {
throw new Error(`Invalid add-on: ${id}`);
}
Expand Down
13 changes: 8 additions & 5 deletions packages/addons/_tests/all-addons/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import { officialAddons } from '../../index.ts';
import type { AddonMap, OptionMap } from 'sv';

const windowsCI = process.env.CI && process.platform === 'win32';
const addons = officialAddons.reduce<AddonMap>((addonMap, addon) => {
const addons = Object.values(officialAddons).reduce<AddonMap>((addonMap, addon) => {
if (addon.id === 'storybook' && windowsCI) return addonMap;
addonMap[addon.id] = addon;
return addonMap;
}, {});

const defaultOptions = officialAddons.reduce<OptionMap<typeof addons>>((options, addon) => {
options[addon.id] = {};
return options;
}, {});
const defaultOptions = Object.values(officialAddons).reduce<OptionMap<typeof addons>>(
(options, addon) => {
options[addon.id] = {};
return options;
},
{}
);

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

Expand Down
4 changes: 4 additions & 0 deletions packages/addons/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["index.ts"]
}
7 changes: 4 additions & 3 deletions packages/cli/commands/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as pkg from 'empathic/package';
import * as p from '@clack/prompts';
import { Command } from 'commander';
import {
officialAddons,
officialAddons as _officialAddons,
getAddonDetails,
communityAddonIds,
getCommunityAddon
Expand All @@ -28,6 +28,7 @@ import {
import { verifyCleanWorkingDirectory, verifyUnsupportedAddons } from './verifiers.ts';
import { type AddonMap, applyAddons, setupAddons } from '../../lib/install.ts';

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

for (const id of selected) {
const addon = officialAddons.find((addon) => addon.id === id)!;
const addon = getAddonDetails(id);
selectedAddons.push({ type: 'official', addon });
}
}
Expand All @@ -422,7 +423,7 @@ export async function runAddCommand(

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

// prompt to install the dependent
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { create } from '@sveltejs/create';
export { create, type TemplateType, type LanguageType } from '@sveltejs/create';
export { installAddon } from './install.ts';
export type { AddonMap, InstallOptions, OptionMap } from './install.ts';
export { officialAddons } from '@sveltejs/addons';
8 changes: 4 additions & 4 deletions packages/cli/lib/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type {
OptionValues,
Question,
SvApi,
AddonSetupResult,
AddonWithoutExplicitArgs
AddonSetupResult
} from '@sveltejs/cli-core';
import pc from 'picocolors';
import * as p from '@clack/prompts';
Expand All @@ -23,7 +22,8 @@ export type InstallOptions<Addons extends AddonMap> = {
packageManager?: PackageManager;
};

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

export function setupAddons(
addons: AddonWithoutExplicitArgs[],
addons: Array<Addon<any>>,
workspace: Workspace<any>
): Record<string, AddonSetupResult> {
const addonSetupResults: Record<string, AddonSetupResult> = {};
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/cli",
"url": "git+https://github.com/sveltejs/cli.git",
"directory": "packages/cli"
},
"homepage": "https://svelte.dev",
Expand All @@ -22,11 +22,11 @@
"exports": {
".": {
"types": "./dist/lib/index.d.ts",
"default": "./dist/index.js"
"default": "./dist/lib/index.js"
},
"./testing": {
"types": "./dist/lib/testing.d.ts",
"default": "./dist/testing.js"
"default": "./dist/lib/testing.js"
}
},
"devDependencies": {
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
} from 'package-manager-detector';
import { parseJson } from '@sveltejs/cli-core/parsers';

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

export const installOption = new Option(
export const installOption: Option = new Option(
'--install <package-manager>',
'installs dependencies with a specified package manager'
).choices(AGENT_NAMES);
Expand Down Expand Up @@ -91,7 +93,7 @@ export function addPnpmBuildDependencies(
cwd: string,
packageManager: AgentName | null | undefined,
allowedPackages: string[]
) {
): void {
// other package managers are currently not affected by this change
if (!packageManager || packageManager !== 'pnpm') return;

Expand Down
3 changes: 1 addition & 2 deletions packages/core/addon/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export function defineAddon<Args extends OptionDefinition>(config: Addon<Args>):

export type AddonSetupResult = { dependsOn: string[]; unsupported: string[]; runsAfter: string[] };

export type AddonWithoutExplicitArgs = Addon<Record<string, Question>>;
export type AddonConfigWithoutExplicitArgs = Addon<Record<string, Question>>;
export type AddonWithoutExplicitArgs = Addon<Record<string, Question<any>>>;

export type Tests = {
expectProperty: (selector: string, property: string, expectedValue: string) => Promise<void>;
Expand Down
31 changes: 7 additions & 24 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/cli/tree/main/packages/core"
"url": "git+https://github.com/sveltejs/cli.git",
"directory": "packages/core"
},
"bugs": "https://github.com/sveltejs/cli/issues",
"scripts": {
Expand All @@ -16,30 +17,12 @@
"test": "vitest run",
"test:ui": "vitest --ui"
},
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./css": {
"types": "./dist/css.d.ts",
"default": "./dist/css.js"
},
"./html": {
"types": "./dist/html.d.ts",
"default": "./dist/html.js"
},
"./js": {
"types": "./dist/js.d.ts",
"default": "./dist/js.js"
},
"./parsers": {
"types": "./dist/parsers.d.ts",
"default": "./dist/parsers.js"
}
".": "./index.ts",
"./css": "./tooling/css/index.ts",
"./html": "./tooling/html/index.ts",
"./js": "./tooling/js/index.ts",
"./parsers": "./tooling/parsers.ts"
Comment on lines +21 to +25
Copy link
Member

@AdrianGonz97 AdrianGonz97 Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll have to keep in mind that @sveltejs/cli-core will be a public package in the future, so this will have to be updated back to its original state when community add-ons are released

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be @sveltejs/cli-core or maybe under sv like sv/core ?
What about @sveltejs/create & @sveltejs/addons ?

It might be a question for later anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be @sveltejs/cli-core or maybe under sv like sv/core ?

its still TBD, but our plans were to have core be its own standalone package so that community add-ons don't have sv as a direct dependency

What about @sveltejs/create & @sveltejs/addons ?

create should probably stay in sv, but there's an argument to be made as to where addons should go. it may be more useful to have it be part of core but we can figure it out when we get there :p

},
"devDependencies": {
"@clack/prompts": "1.0.0-alpha.1",
Expand Down
19 changes: 4 additions & 15 deletions packages/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/cli",
"url": "git+https://github.com/sveltejs/cli.git",
"directory": "packages/create"
},
"homepage": "https://svelte.dev",
Expand All @@ -19,21 +19,10 @@
"test": "vitest run",
"update-template-repo": "pnpm build:dist && echo \"Updating template repo\" && ./scripts/update-template-repo.sh"
},
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./build": {
"default": "./scripts/build-templates.js"
},
"./playground": {
"types": "./dist/playground.d.ts",
"default": "./dist/playground.js"
}
".": "./index.ts",
"./playground": "./playground.ts",
"./build": "./scripts/build-templates.js"
},
"devDependencies": {
"@sveltejs/cli-core": "workspace:*",
Expand Down
Loading
Loading