Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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/sour-wings-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix: `vite.config.*` file detection works for both .js and .ts variants
6 changes: 2 additions & 4 deletions packages/addons/devtools-json/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ export default defineAddon({
homepage: 'https://github.com/ChromeDevTools/vite-plugin-devtools-json',
options: {},

run: ({ sv, typescript }) => {
const ext = typescript ? 'ts' : 'js';

run: ({ sv, viteConfigFile }) => {
sv.devDependency('vite-plugin-devtools-json', '^1.0.0');

// add the vite plugin
sv.file(`vite.config.${ext}`, (content) => {
sv.file(viteConfigFile, (content) => {
const { ast, generateCode } = parseScript(content);

const vitePluginName = 'devtoolsJson';
Expand Down
4 changes: 2 additions & 2 deletions packages/addons/paraglide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default defineAddon({
setup: ({ kit, unsupported }) => {
if (!kit) unsupported('Requires SvelteKit');
},
run: ({ sv, options, typescript, kit }) => {
run: ({ sv, options, viteConfigFile, typescript, kit }) => {
const ext = typescript ? 'ts' : 'js';
if (!kit) throw new Error('SvelteKit is required');

Expand All @@ -81,7 +81,7 @@ export default defineAddon({
});

// add the vite plugin
sv.file(`vite.config.${ext}`, (content) => {
sv.file(viteConfigFile, (content) => {
const { ast, generateCode } = parseScript(content);

const vitePluginName = 'paraglideVitePlugin';
Expand Down
5 changes: 2 additions & 3 deletions packages/addons/tailwindcss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export default defineAddon({
shortDescription: 'css framework',
homepage: 'https://tailwindcss.com',
options,
run: ({ sv, options, typescript, kit, dependencyVersion }) => {
const ext = typescript ? 'ts' : 'js';
run: ({ sv, options, viteConfigFile, typescript, kit, dependencyVersion }) => {
const prettierInstalled = Boolean(dependencyVersion('prettier'));

sv.devDependency('tailwindcss', '^4.0.0');
Expand All @@ -57,7 +56,7 @@ export default defineAddon({
}

// add the vite plugin
sv.file(`vite.config.${ext}`, (content) => {
sv.file(viteConfigFile, (content) => {
const { ast, generateCode } = parseScript(content);

const vitePluginName = 'tailwindcss';
Expand Down
8 changes: 4 additions & 4 deletions packages/addons/vitest-addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default defineAddon({
shortDescription: 'unit testing',
homepage: 'https://vitest.dev',
options,
run: ({ sv, typescript, kit, options }) => {
run: ({ sv, viteConfigFile, typescript, kit, options }) => {
const ext = typescript ? 'ts' : 'js';
const unitTesting = options.usages.includes('unit');
const componentTesting = options.usages.includes('component');
Expand Down Expand Up @@ -96,11 +96,11 @@ export default defineAddon({
`;
});
}
sv.file(`vite.config.${ext}`, (content) => {
sv.file(viteConfigFile, (content) => {
const { ast, generateCode } = parseScript(content);

const clientObjectExpression = object.create({
extends: `./vite.config.${ext}`,
extends: `./${viteConfigFile}`,
test: {
name: 'client',
environment: 'browser',
Expand All @@ -116,7 +116,7 @@ export default defineAddon({
});

const serverObjectExpression = object.create({
extends: `./vite.config.${ext}`,
extends: `./${viteConfigFile}`,
test: {
name: 'server',
environment: 'node',
Expand Down
1 change: 1 addition & 0 deletions packages/cli/commands/add/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const commonFilePaths = {
packageJson: 'package.json',
svelteConfig: 'svelte.config.js',
tsconfig: 'tsconfig.json',
viteConfig: 'vite.config.js',
viteConfigTS: 'vite.config.ts'
} as const;

Expand Down
3 changes: 3 additions & 0 deletions packages/cli/commands/add/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export async function createWorkspace({
const viteConfigPath = path.join(resolvedCwd, commonFilePaths.viteConfigTS);
let usesTypescript = fs.existsSync(viteConfigPath);

const viteConfigFile = usesTypescript ? commonFilePaths.viteConfigTS : commonFilePaths.viteConfig;

if (TESTING) {
// while executing tests, we only look into the direct `cwd`
// as we might detect the monorepo `tsconfig.json` otherwise.
Expand Down Expand Up @@ -55,6 +57,7 @@ export async function createWorkspace({
options,
packageManager: packageManager ?? (await detect({ cwd }))?.name ?? getUserAgent() ?? 'npm',
typescript: usesTypescript,
viteConfigFile,
kit: dependencies['@sveltejs/kit'] ? parseKitOptions(resolvedCwd) : undefined,
dependencyVersion: (pkg) => dependencies[pkg]
};
Expand Down
1 change: 1 addition & 0 deletions packages/core/addon/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Workspace<Args extends OptionDefinition> = {
*/
dependencyVersion: (pkg: string) => string | undefined;
typescript: boolean;
viteConfigFile: string;
kit: { libDirectory: string; routesDirectory: string } | undefined;
packageManager: PackageManager;
};
Expand Down
Loading