Skip to content

Commit 6665b50

Browse files
authored
fix: add kit check in drizzle add-on (#574)
* fix setups * fix drizzle setup * update changeset * only execute the setups of pre-selected add-ons, if specified
1 parent 365e296 commit 6665b50

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.changeset/new-bats-dress.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: add null check for `kit` in the `drizzle` add-on's setup

packages/addons/drizzle/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ export default defineAddon({
7373
options,
7474
setup: ({ kit, unsupported, cwd, typescript }) => {
7575
const ext = typescript ? 'ts' : 'js';
76-
if (!kit) unsupported('Requires SvelteKit');
76+
if (!kit) {
77+
return unsupported('Requires SvelteKit');
78+
}
7779

78-
const baseDBPath = path.resolve(kit!.libDirectory, 'server', 'db');
80+
const baseDBPath = path.resolve(kit.libDirectory, 'server', 'db');
7981
const paths = {
8082
'drizzle config': path.relative(cwd, path.resolve(cwd, `drizzle.config.${ext}`)),
8183
'database schema': path.relative(cwd, path.resolve(baseDBPath, `schema.${ext}`)),
8284
database: path.relative(cwd, path.resolve(baseDBPath, `index.${ext}`))
8385
};
86+
8487
for (const [fileType, filePath] of Object.entries(paths)) {
8588
if (fs.existsSync(filePath)) {
8689
unsupported(`Preexisting ${fileType} file at '${filePath}'`);

packages/cli/commands/add/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ export async function runAddCommand(
387387

388388
// prepare official addons
389389
let workspace = await createWorkspace({ cwd: options.cwd });
390-
const addonSetupResults = setupAddons(officialAddons, workspace);
390+
const setups = selectedAddons.length ? selectedAddons.map(({ addon }) => addon) : officialAddons;
391+
const addonSetupResults = setupAddons(setups, workspace);
391392

392393
// prompt which addons to apply
393394
if (selectedAddons.length === 0) {

0 commit comments

Comments
 (0)