Skip to content

Commit 69b4c28

Browse files
authored
Merge pull request storybookjs#179 from xeho91/chores
chore: Remove `fs-extra` in favor of `node:fs`
2 parents 400f257 + fc4c90d commit 69b4c28

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.svelte-kit/
12
dist/
23
node_modules/
34
storybook-static/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"dependencies": {
5050
"@babel/runtime": "^7.22.6",
5151
"dedent": "^1.2.0",
52-
"fs-extra": "^11.1.1",
5352
"magic-string": "^0.30.1"
5453
},
5554
"devDependencies": {
@@ -69,6 +68,7 @@
6968
"@storybook/test": "^8.0.0-rc.2",
7069
"@storybook/theming": "^8.0.0-rc.2",
7170
"@storybook/types": "^8.0.0-rc.2",
71+
"@sveltejs/kit": "^2.5.7",
7272
"@sveltejs/package": "^2.2.0",
7373
"@sveltejs/vite-plugin-svelte": "^2.4.2",
7474
"@tsconfig/svelte": "^5.0.0",

src/config-loader.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
// This file is a rewrite of `@sveltejs/vite-plugin-svelte` without the `Vite`
22
// parts: https://github.com/sveltejs/vite-plugin-svelte/blob/e8e52deef93948da735c4ab69c54aced914926cf/packages/vite-plugin-svelte/src/utils/load-svelte-config.ts
3-
import { fileURLToPath, pathToFileURL } from 'url';
3+
import fs from 'node:fs';
4+
import { createRequire } from 'node:module';
5+
import path from 'node:path';
6+
import { fileURLToPath, pathToFileURL } from 'node:url';
47

5-
import { createRequire } from 'module';
6-
import fs from 'fs';
78
import { logger } from '@storybook/node-logger';
8-
import path from 'path';
9-
import { pathExists } from 'fs-extra';
9+
import type { Config } from '@sveltejs/kit';
1010

1111
/**
1212
* Try find svelte config and then load it.
1313
*
14-
* @returns {import('@sveltejs/kit').Config | undefined}
14+
* @returns
1515
* Returns the svelte configuration object.
1616
*/
17-
export async function loadSvelteConfig() {
17+
export async function loadSvelteConfig(): Promise<Config | undefined> {
1818
const configFile = await findSvelteConfig();
1919

2020
// no need to throw error since we handle projects without config files
2121
if (configFile === undefined) {
2222
return undefined;
2323
}
2424

25-
let err;
25+
let err: unknown;
2626

2727
// try to use dynamic import for svelte.config.js first
2828
if (configFile.endsWith('.js') || configFile.endsWith('.mjs')) {
@@ -61,13 +61,13 @@ const importSvelteOptions = (() => {
6161
/**
6262
* Try import specified svelte configuration.
6363
*
64-
* @param {string} configFile
64+
* @param configFile
6565
* Absolute path of the svelte config file to import.
6666
*
67-
* @returns {import('@sveltejs/kit').Config}
67+
* @returns
6868
* Returns the svelte configuration object.
6969
*/
70-
return async (configFile) => {
70+
return async (configFile: string): Promise<Config> => {
7171
const result = await dynamicImportDefault(
7272
pathToFileURL(configFile).href,
7373
fs.statSync(configFile).mtimeMs
@@ -81,19 +81,18 @@ const importSvelteOptions = (() => {
8181
})();
8282

8383
const requireSvelteOptions = (() => {
84-
/** @type {NodeRequire} */
85-
let esmRequire;
84+
let esmRequire: NodeRequire;
8685

8786
/**
8887
* Try import specified svelte configuration.
8988
*
90-
* @param {string} configFile
89+
* @param configFile
9190
* Absolute path of the svelte config file to require.
9291
*
93-
* @returns {import('@sveltejs/kit').Config}
92+
* @returns
9493
* Returns the svelte configuration object.
9594
*/
96-
return (configFile) => {
95+
return (configFile: string): Config => {
9796
// identify which require function to use (esm and cjs mode)
9897
const requireFn = import.meta.url
9998
? (esmRequire = esmRequire ?? createRequire(import.meta.url))
@@ -114,10 +113,10 @@ const requireSvelteOptions = (() => {
114113
* Try find svelte config. First in current working dir otherwise try to
115114
* find it by climbing up the directory tree.
116115
*
117-
* @returns {Promise<string | undefined>}
116+
* @returns
118117
* Returns the absolute path of the config file.
119118
*/
120-
async function findSvelteConfig() {
119+
async function findSvelteConfig(): Promise<string | undefined> {
121120
const lookupDir = process.cwd();
122121
let configFiles = await getConfigFiles(lookupDir);
123122

@@ -140,10 +139,10 @@ async function findSvelteConfig() {
140139
* Returning the first found. Should solves most of monorepos with
141140
* only one config at workspace root.
142141
*
143-
* @returns {Promise<string[]>}
142+
* @returns
144143
* Returns an array containing all available config files.
145144
*/
146-
async function getConfigFilesUp() {
145+
async function getConfigFilesUp(): Promise<string[]> {
147146
const importPath = fileURLToPath(import.meta.url);
148147
const pathChunks = path.dirname(importPath).split(path.sep);
149148

@@ -164,22 +163,21 @@ async function getConfigFilesUp() {
164163
/**
165164
* Gets all svelte config from a specified `lookupDir`.
166165
*
167-
* @param {string} lookupDir
166+
* @param lookupDir
168167
* Directory in which to look for svelte files.
169168
*
170-
* @returns {Promise<string[]>}
169+
* @returns
171170
* Returns an array containing all available config files.
172171
*/
173-
async function getConfigFiles(lookupDir) {
174-
/** @type {[string, boolean][]} */
175-
const fileChecks = await Promise.all(
172+
async function getConfigFiles(lookupDir: string): Promise<string[]> {
173+
const fileChecks: Array<[string, boolean]> = await Promise.all(
176174
knownConfigFiles.map(async (candidate) => {
177175
const filePath = path.resolve(lookupDir, candidate);
178-
return [filePath, await pathExists(filePath)];
176+
return [filePath, fs.existsSync(filePath)];
179177
})
180178
);
181179

182-
return fileChecks.reduce((files, [file, exists]) => {
180+
return fileChecks.reduce((files: string[], [file, exists]) => {
183181
if (exists) files.push(file);
184182
return files;
185183
}, []);

src/preset/indexer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import fs from 'node:fs/promises';
2+
3+
import { storyNameFromExport, toId } from '@storybook/csf';
4+
import type { IndexInput, IndexedCSFFile, IndexerOptions } from '@storybook/types';
15
import * as svelte from 'svelte/compiler';
26

37
import { extractStories } from '../parser/extract-stories.js';
4-
import fs from 'fs-extra';
58
import { loadSvelteConfig } from '../config-loader.js';
6-
import { storyNameFromExport, toId } from '@storybook/csf';
7-
import type { IndexInput, IndexedCSFFile, IndexerOptions } from '@storybook/types';
89

910
export async function readStories(fileName: string) {
1011
let code = (await fs.readFile(fileName, 'utf-8')).toString();

0 commit comments

Comments
 (0)