Skip to content

Commit 1caffa8

Browse files
authored
Merge pull request #28860 from storybookjs/norbert/add-node-prefix-to-core-modules
Maintenance: Add `node:`-prefix to node core-modules
2 parents e5960ff + 0edd826 commit 1caffa8

File tree

187 files changed

+814
-781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+814
-781
lines changed

code/.storybook/main.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import path from 'path';
1+
import { join } from 'node:path';
2+
23
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
34
import { mergeConfig } from 'vite';
45

56
import type { StorybookConfig } from '../frameworks/react-vite';
67

7-
const componentsPath = path.join(__dirname, '../core/src/components');
8-
const managerApiPath = path.join(__dirname, '../core/src/manager-api');
8+
const componentsPath = join(__dirname, '../core/src/components');
9+
const managerApiPath = join(__dirname, '../core/src/manager-api');
910

1011
const config: StorybookConfig = {
1112
stories: [
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { checkAddonOrder, serverRequire } from 'storybook/internal/common';
1+
import { isAbsolute, join } from 'node:path';
22

3-
import path from 'path';
3+
import { checkAddonOrder, serverRequire } from 'storybook/internal/common';
44

55
export const checkDocsLoaded = (configDir: string) => {
66
checkAddonOrder({
@@ -12,9 +12,9 @@ export const checkDocsLoaded = (configDir: string) => {
1212
name: '@storybook/addon-controls',
1313
inEssentials: true,
1414
},
15-
configFile: path.isAbsolute(configDir)
16-
? path.join(configDir, 'main')
17-
: path.join(process.cwd(), configDir, 'main'),
15+
configFile: isAbsolute(configDir)
16+
? join(configDir, 'main')
17+
: join(process.cwd(), configDir, 'main'),
1818
getConfig: (configFile) => serverRequire(configFile),
1919
});
2020
};

code/addons/docs/src/plugins/mdx-plugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { dirname, join } from 'node:path';
2+
13
import type { Options } from 'storybook/internal/types';
24

35
import { createFilter } from '@rollup/pluginutils';
4-
import { dirname, join } from 'path';
56
import rehypeExternalLinks from 'rehype-external-links';
67
import rehypeSlug from 'rehype-slug';
78
import type { Plugin } from 'vite';

code/addons/docs/src/preset.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { dirname, isAbsolute, join } from 'node:path';
2+
13
import { logger } from 'storybook/internal/node-logger';
24
import type { DocsOptions, Options, PresetProperty } from 'storybook/internal/types';
35

46
import type { CsfPluginOptions } from '@storybook/csf-plugin';
57

6-
import { dirname, isAbsolute, join } from 'path';
78
import rehypeExternalLinks from 'rehype-external-links';
89
import rehypeSlug from 'rehype-slug';
910

code/addons/essentials/src/docs/preset.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dirname, join } from 'path';
1+
import { dirname, join } from 'node:path';
22

33
export * from '@storybook/addon-docs/dist/preset';
44

code/addons/essentials/src/index.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { isAbsolute, join } from 'node:path';
2+
13
import { serverRequire } from 'storybook/internal/common';
24
import { logger } from 'storybook/internal/node-logger';
35

4-
import path from 'path';
5-
66
interface PresetOptions {
77
/**
88
* Allow to use @storybook/addon-actions
@@ -57,10 +57,8 @@ interface PresetOptions {
5757
}
5858

5959
const requireMain = (configDir: string) => {
60-
const absoluteConfigDir = path.isAbsolute(configDir)
61-
? configDir
62-
: path.join(process.cwd(), configDir);
63-
const mainFile = path.join(absoluteConfigDir, 'main');
60+
const absoluteConfigDir = isAbsolute(configDir) ? configDir : join(process.cwd(), configDir);
61+
const mainFile = join(absoluteConfigDir, 'main');
6462

6563
return serverRequire(mainFile) ?? {};
6664
};
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { checkAddonOrder, serverRequire } from 'storybook/internal/common';
1+
import { isAbsolute, join } from 'node:path';
22

3-
import path from 'path';
3+
import { checkAddonOrder, serverRequire } from 'storybook/internal/common';
44

55
export const checkActionsLoaded = (configDir: string) => {
66
checkAddonOrder({
@@ -12,9 +12,9 @@ export const checkActionsLoaded = (configDir: string) => {
1212
name: '@storybook/addon-interactions',
1313
inEssentials: false,
1414
},
15-
configFile: path.isAbsolute(configDir)
16-
? path.join(configDir, 'main')
17-
: path.join(process.cwd(), configDir, 'main'),
15+
configFile: isAbsolute(configDir)
16+
? join(configDir, 'main')
17+
: join(process.cwd(), configDir, 'main'),
1818
getConfig: (configFile) => serverRequire(configFile),
1919
});
2020
};

code/addons/onboarding/src/preset.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { readFileSync } from 'node:fs';
2+
13
import type { Channel } from 'storybook/internal/channels';
24
import { telemetry } from 'storybook/internal/telemetry';
35
import type { CoreConfig, Options } from 'storybook/internal/types';
46

5-
import fs from 'fs';
6-
77
import { STORYBOOK_ADDON_ONBOARDING_CHANNEL } from './constants';
88

99
type Event = {
@@ -20,7 +20,7 @@ export const experimental_serverChannel = async (channel: Channel, options: Opti
2020
const packageJsonPath = require.resolve('@storybook/addon-onboarding/package.json');
2121

2222
const { version: addonVersion } = JSON.parse(
23-
fs.readFileSync(packageJsonPath, { encoding: 'utf-8' })
23+
readFileSync(packageJsonPath, { encoding: 'utf-8' })
2424
);
2525

2626
channel.on(STORYBOOK_ADDON_ONBOARDING_CHANNEL, ({ type, ...event }: Event) => {

code/builders/builder-vite/src/codegen-importfn-script.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Options } from 'storybook/internal/types';
1+
import { relative } from 'node:path';
22

3-
import * as path from 'path';
3+
import type { Options } from 'storybook/internal/types';
44

55
import { listStories } from './list-stories';
66

@@ -27,7 +27,7 @@ function toImportPath(relativePath: string) {
2727
async function toImportFn(stories: string[]) {
2828
const { normalizePath } = await import('vite');
2929
const objectEntries = stories.map((file) => {
30-
const relativePath = normalizePath(path.relative(process.cwd(), file));
30+
const relativePath = normalizePath(relative(process.cwd(), file));
3131

3232
return ` '${toImportPath(relativePath)}': async () => import('/@fs/${file}')`;
3333
});

code/builders/builder-vite/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// noinspection JSUnusedGlobalSymbols
2+
import { join, parse } from 'node:path';
3+
24
import { NoStatsForViteDevError } from 'storybook/internal/server-errors';
35
import type { Options } from 'storybook/internal/types';
46

57
import type { RequestHandler } from 'express';
68
import express from 'express';
79
import * as fs from 'fs-extra';
8-
import { join, parse } from 'path';
910
import { corePath } from 'storybook/core-path';
1011
import type { ViteDevServer } from 'vite';
1112

code/builders/builder-vite/src/list-stories.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { isAbsolute, join } from 'node:path';
2+
13
import { commonGlobOptions, normalizeStories } from 'storybook/internal/common';
24
import type { Options } from 'storybook/internal/types';
35

46
import { glob } from 'glob';
5-
import * as path from 'path';
67
import slash from 'slash';
78

89
export async function listStories(options: Options) {
@@ -15,10 +16,8 @@ export async function listStories(options: Options) {
1516
configDir: options.configDir,
1617
workingDir: options.configDir,
1718
}).map(({ directory, files }) => {
18-
const pattern = path.join(directory, files);
19-
const absolutePattern = path.isAbsolute(pattern)
20-
? pattern
21-
: path.join(options.configDir, pattern);
19+
const pattern = join(directory, files);
20+
const absolutePattern = isAbsolute(pattern) ? pattern : join(options.configDir, pattern);
2221

2322
return glob(slash(absolutePattern), {
2423
...commonGlobOptions(absolutePattern),

code/builders/builder-vite/src/optimizeDeps.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { relative } from 'node:path';
2+
13
import type { Options } from 'storybook/internal/types';
24

3-
import * as path from 'path';
45
import type { UserConfig, InlineConfig as ViteInlineConfig } from 'vite';
56

67
import { listStories } from './list-stories';
@@ -121,7 +122,7 @@ export async function getOptimizeDeps(config: ViteInlineConfig, options: Options
121122
const { root = process.cwd() } = config;
122123
const { normalizePath, resolveConfig } = await import('vite');
123124
const absoluteStories = await listStories(options);
124-
const stories = absoluteStories.map((storyPath) => normalizePath(path.relative(root, storyPath)));
125+
const stories = absoluteStories.map((storyPath) => normalizePath(relative(root, storyPath)));
125126
// TODO: check if resolveConfig takes a lot of time, possible optimizations here
126127
const resolvedConfig = await resolveConfig(config, 'serve', 'development');
127128

code/builders/builder-vite/src/plugins/code-generator-plugin.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { readFileSync } from 'node:fs';
2+
13
import type { Options } from 'storybook/internal/types';
24

3-
import * as fs from 'fs';
45
import type { Plugin } from 'vite';
56

67
import { generateImportFnScriptCode } from '../codegen-importfn-script';
@@ -100,10 +101,7 @@ export function codeGeneratorPlugin(options: Options): Plugin {
100101
}
101102

102103
if (id === iframeId) {
103-
return fs.readFileSync(
104-
require.resolve('@storybook/builder-vite/input/iframe.html'),
105-
'utf-8'
106-
);
104+
return readFileSync(require.resolve('@storybook/builder-vite/input/iframe.html'), 'utf-8');
107105
}
108106

109107
return undefined;

code/builders/builder-vite/src/plugins/webpack-stats-plugin.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// This plugin is a direct port of https://github.com/IanVS/vite-plugin-turbosnap
2+
import { relative } from 'node:path';
3+
24
import type { BuilderStats } from 'storybook/internal/types';
35

4-
import path from 'path';
56
import slash from 'slash';
67
import type { Plugin } from 'vite';
78

@@ -57,7 +58,7 @@ export function pluginWebpackStats({ workingDir }: WebpackStatsPluginOptions): W
5758
}
5859
// Otherwise, we need them in the format `./path/to/file.js`.
5960
else {
60-
const relativePath = path.relative(workingDir, stripQueryParams(filename));
61+
const relativePath = relative(workingDir, stripQueryParams(filename));
6162
// This seems hacky, got to be a better way to add a `./` to the start of a path.
6263
return `./${slash(relativePath)}`;
6364
}

code/builders/builder-vite/src/utils/process-preview-annotation.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { isAbsolute, relative, resolve } from 'node:path';
2+
13
import { stripAbsNodeModulesPath } from 'storybook/internal/common';
24
import type { PreviewAnnotation } from 'storybook/internal/types';
35

4-
import { isAbsolute, relative, resolve } from 'path';
56
import slash from 'slash';
67

78
/**

code/builders/builder-vite/src/vite-config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { resolve } from 'node:path';
2+
13
import {
24
getBuilderOptions,
35
getFrameworkName,
@@ -7,7 +9,6 @@ import {
79
import { globalsNameReferenceMap } from 'storybook/internal/preview/globals';
810
import type { Options } from 'storybook/internal/types';
911

10-
import * as path from 'path';
1112
import type {
1213
ConfigEnv,
1314
InlineConfig,
@@ -50,7 +51,7 @@ export async function commonConfig(
5051

5152
const { viteConfigPath } = await getBuilderOptions<BuilderOptions>(options);
5253

53-
const projectRoot = path.resolve(options.configDir, '..');
54+
const projectRoot = resolve(options.configDir, '..');
5455

5556
// I destructure away the `build` property from the user's config object
5657
// I do this because I can contain config that breaks storybook, such as we had in a lit project.

code/builders/builder-webpack5/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { join, parse } from 'node:path';
2+
13
import { PREVIEW_BUILDER_PROGRESS } from 'storybook/internal/core-events';
24
import { logger } from 'storybook/internal/node-logger';
35
import {
@@ -11,7 +13,6 @@ import { checkWebpackVersion } from '@storybook/core-webpack';
1113

1214
import express from 'express';
1315
import fs from 'fs-extra';
14-
import { join, parse } from 'path';
1516
import prettyTime from 'pretty-hrtime';
1617
import { corePath } from 'storybook/core-path';
1718
import type { Configuration, Stats, StatsOptions } from 'webpack';

code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { dirname, join, resolve } from 'node:path';
2+
13
import {
24
getBuilderOptions,
35
isPreservingSymlinks,
@@ -14,7 +16,6 @@ import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
1416
import type { TransformOptions as EsbuildOptions } from 'esbuild';
1517
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
1618
import HtmlWebpackPlugin from 'html-webpack-plugin';
17-
import { dirname, join, resolve } from 'path';
1819
import TerserWebpackPlugin from 'terser-webpack-plugin';
1920
import { dedent } from 'ts-dedent';
2021
import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';

code/builders/builder-webpack5/src/preview/virtual-module-mapping.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { join, resolve } from 'node:path';
2+
13
import {
24
getBuilderOptions,
35
handlebars,
@@ -9,7 +11,6 @@ import type { Options, PreviewAnnotation } from 'storybook/internal/types';
911

1012
import { toImportFn } from '@storybook/core-webpack';
1113

12-
import { join, resolve } from 'path';
1314
import slash from 'slash';
1415

1516
import type { BuilderOptions } from '../types';

code/core/src/builder-manager/utils/framework.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'node:path';
1+
import { join } from 'node:path';
22

33
import { describe, expect, it } from 'vitest';
44

@@ -25,24 +25,24 @@ describe('UTILITIES: Framework information', () => {
2525

2626
describe('UTILITY: pluckStorybookPackageFromPath', () => {
2727
it('should return the package name if the path is a storybook package', () => {
28-
const packagePath = path.join(process.cwd(), 'node_modules', '@storybook', 'foo');
28+
const packagePath = join(process.cwd(), 'node_modules', '@storybook', 'foo');
2929
expect(pluckStorybookPackageFromPath(packagePath)).toBe('@storybook/foo');
3030
});
3131

3232
it('should return undefined if the path is not a storybook package', () => {
33-
const packagePath = path.join(process.cwd(), 'foo');
33+
const packagePath = join(process.cwd(), 'foo');
3434
expect(pluckStorybookPackageFromPath(packagePath)).toBe(undefined);
3535
});
3636
});
3737

3838
describe('UTILITY: pluckThirdPartyPackageFromPath', () => {
3939
it('should return the package name if the path is a third party package', () => {
40-
const packagePath = path.join(process.cwd(), 'node_modules', 'bar');
40+
const packagePath = join(process.cwd(), 'node_modules', 'bar');
4141
expect(pluckThirdPartyPackageFromPath(packagePath)).toBe('bar');
4242
});
4343

4444
it('should return the given path if the path is not a third party package', () => {
45-
const packagePath = path.join(process.cwd(), 'foo', 'bar', 'baz');
45+
const packagePath = join(process.cwd(), 'foo', 'bar', 'baz');
4646
expect(pluckThirdPartyPackageFromPath(packagePath)).toBe(packagePath);
4747
});
4848
});

code/core/src/builder-manager/utils/framework.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'node:path';
1+
import { sep } from 'node:path';
22

33
import { extractProperRendererNameFromFramework, getFrameworkName } from '@storybook/core/common';
44
import type { Options } from '@storybook/core/types';
@@ -19,7 +19,7 @@ export const pluckNameFromConfigProperty = (property: Property) => {
1919
};
2020

2121
// For replacing Windows backslashes with forward slashes
22-
const normalizePath = (packagePath: string) => packagePath.replaceAll(path.sep, '/');
22+
const normalizePath = (packagePath: string) => packagePath.replaceAll(sep, '/');
2323

2424
export const pluckStorybookPackageFromPath = (packagePath: string) =>
2525
normalizePath(packagePath).match(/(@storybook\/.*)$/)?.[1];

0 commit comments

Comments
 (0)