Skip to content

Commit b6f94e2

Browse files
authored
fix: add @types/node to drizzle and storybook add-ons (#541)
* install node types for drizzle and storybook * changeset * exclude minor and patch
1 parent 985dec6 commit b6f94e2

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

.changeset/odd-bikes-like.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
fix: add `@types/node` as a dev dependency to the `drizzle` and `storybook` add-ons

packages/addons/common.ts

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { imports, exports, common } from '@sveltejs/cli-core/js';
22
import { parseScript, parseSvelte } from '@sveltejs/cli-core/parsers';
3+
import process from 'node:process';
34

45
export function addEslintConfigPrettier(content: string): string {
56
const { ast, generateCode } = parseScript(content);
@@ -75,3 +76,22 @@ export function addToDemoPage(content: string, path: string): string {
7576
const src = template.source + `${newLine}<a href="/demo/${path}">${path}</a>`;
7677
return generateCode({ template: src });
7778
}
79+
80+
/**
81+
* Returns the corresponding `@types/node` version for the version of Node.js running in the current process.
82+
*
83+
* If the installed version of Node.js is from a `Current` release, then the major is decremented to
84+
* the nearest `LTS` release version.
85+
*/
86+
export function getNodeTypesVersion(): string {
87+
const nodeVersion = process.versions.node;
88+
const [major] = nodeVersion.split('.');
89+
90+
const isLTS = Number(major) % 2 === 0;
91+
if (isLTS) {
92+
return `^${major}`;
93+
}
94+
95+
const previousLTSMajor = Number(major) - 1;
96+
return `^${previousLTSMajor}`;
97+
}

packages/addons/drizzle/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { common, exports, functions, imports, object, variables } from '@sveltejs/cli-core/js';
22
import { defineAddon, defineAddonOptions, dedent, type OptionValues } from '@sveltejs/cli-core';
33
import { parseJson, parseScript } from '@sveltejs/cli-core/parsers';
4+
import { getNodeTypesVersion } from '../common.ts';
45

56
const PORTS = {
67
mysql: '3306',
@@ -76,6 +77,7 @@ export default defineAddon({
7677

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

8082
// MySQL
8183
if (options.mysql === 'mysql2') sv.dependency('mysql2', '^3.12.0');

packages/addons/storybook/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineAddon } from '@sveltejs/cli-core';
2+
import { getNodeTypesVersion } from '../common.ts';
23

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

0 commit comments

Comments
 (0)