Skip to content

fix: add @types/node to drizzle and storybook add-ons #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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/odd-bikes-like.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix: add `@types/node` as a dev dependency to the `drizzle` and `storybook` add-ons
20 changes: 20 additions & 0 deletions packages/addons/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { imports, exports, common } from '@sveltejs/cli-core/js';
import { parseScript, parseSvelte } from '@sveltejs/cli-core/parsers';
import process from 'node:process';

export function addEslintConfigPrettier(content: string): string {
const { ast, generateCode } = parseScript(content);
Expand Down Expand Up @@ -75,3 +76,22 @@ export function addToDemoPage(content: string, path: string): string {
const src = template.source + `${newLine}<a href="/demo/${path}">${path}</a>`;
return generateCode({ template: src });
}

/**
* Returns the corresponding `@types/node` version for the version of Node.js running in the current process.
*
* If the installed version of Node.js is from a `Current` release, then the major is decremented to
* the nearest `LTS` release version.
*/
export function getNodeTypesVersion(): string {
const nodeVersion = process.versions.node;
const [major] = nodeVersion.split('.');

const isLTS = Number(major) % 2 === 0;
if (isLTS) {
return `^${major}`;
}

const previousLTSMajor = Number(major) - 1;
return `^${previousLTSMajor}`;
}
2 changes: 2 additions & 0 deletions packages/addons/drizzle/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { common, exports, functions, imports, object, variables } from '@sveltejs/cli-core/js';
import { defineAddon, defineAddonOptions, dedent, type OptionValues } from '@sveltejs/cli-core';
import { parseJson, parseScript } from '@sveltejs/cli-core/parsers';
import { getNodeTypesVersion } from '../common.ts';

const PORTS = {
mysql: '3306',
Expand Down Expand Up @@ -76,6 +77,7 @@ export default defineAddon({

sv.dependency('drizzle-orm', '^0.40.0');
sv.devDependency('drizzle-kit', '^0.30.2');
sv.devDependency('@types/node', getNodeTypesVersion());

// MySQL
if (options.mysql === 'mysql2') sv.dependency('mysql2', '^3.12.0');
Expand Down
2 changes: 2 additions & 0 deletions packages/addons/storybook/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineAddon } from '@sveltejs/cli-core';
import { getNodeTypesVersion } from '../common.ts';

export default defineAddon({
id: 'storybook',
Expand All @@ -7,5 +8,6 @@ export default defineAddon({
options: {},
run: async ({ sv }) => {
await sv.execute(['storybook@latest', 'init', '--skip-install', '--no-dev'], 'inherit');
sv.devDependency(`@types/node`, getNodeTypesVersion());
}
});