Skip to content
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

Maintenance: Add node:-prefix to node core-modules #28860

Merged
merged 3 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions code/addons/controls/src/preset/checkDocsLoaded.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkAddonOrder, serverRequire } from 'storybook/internal/common';
import { isAbsolute, join } from 'node:path';

import path from 'path';
import { checkAddonOrder, serverRequire } from 'storybook/internal/common';

export const checkDocsLoaded = (configDir: string) => {
checkAddonOrder({
Expand All @@ -12,9 +12,9 @@ export const checkDocsLoaded = (configDir: string) => {
name: '@storybook/addon-controls',
inEssentials: true,
},
configFile: path.isAbsolute(configDir)
? path.join(configDir, 'main')
: path.join(process.cwd(), configDir, 'main'),
configFile: isAbsolute(configDir)
? join(configDir, 'main')
: join(process.cwd(), configDir, 'main'),
getConfig: (configFile) => serverRequire(configFile),
});
};
3 changes: 2 additions & 1 deletion code/addons/docs/src/plugins/mdx-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { dirname, join } from 'node:path';

import type { Options } from 'storybook/internal/types';

import { createFilter } from '@rollup/pluginutils';
import { dirname, join } from 'path';
import rehypeExternalLinks from 'rehype-external-links';
import rehypeSlug from 'rehype-slug';
import type { Plugin } from 'vite';
Expand Down
3 changes: 2 additions & 1 deletion code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { dirname, isAbsolute, join } from 'node:path';

import { logger } from 'storybook/internal/node-logger';
import type { DocsOptions, Options, PresetProperty } from 'storybook/internal/types';

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

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

Expand Down
2 changes: 1 addition & 1 deletion code/addons/essentials/src/docs/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, join } from 'path';
import { dirname, join } from 'node:path';

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

Expand Down
10 changes: 4 additions & 6 deletions code/addons/essentials/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isAbsolute, join } from 'node:path';

import { serverRequire } from 'storybook/internal/common';
import { logger } from 'storybook/internal/node-logger';

import path from 'path';

interface PresetOptions {
/**
* Allow to use @storybook/addon-actions
Expand Down Expand Up @@ -57,10 +57,8 @@ interface PresetOptions {
}

const requireMain = (configDir: string) => {
const absoluteConfigDir = path.isAbsolute(configDir)
? configDir
: path.join(process.cwd(), configDir);
const mainFile = path.join(absoluteConfigDir, 'main');
const absoluteConfigDir = isAbsolute(configDir) ? configDir : join(process.cwd(), configDir);
const mainFile = join(absoluteConfigDir, 'main');

return serverRequire(mainFile) ?? {};
};
Expand Down
10 changes: 5 additions & 5 deletions code/addons/interactions/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkAddonOrder, serverRequire } from 'storybook/internal/common';
import { isAbsolute, join } from 'node:path';

import path from 'path';
import { checkAddonOrder, serverRequire } from 'storybook/internal/common';

export const checkActionsLoaded = (configDir: string) => {
checkAddonOrder({
Expand All @@ -12,9 +12,9 @@ export const checkActionsLoaded = (configDir: string) => {
name: '@storybook/addon-interactions',
inEssentials: false,
},
configFile: path.isAbsolute(configDir)
? path.join(configDir, 'main')
: path.join(process.cwd(), configDir, 'main'),
configFile: isAbsolute(configDir)
? join(configDir, 'main')
: join(process.cwd(), configDir, 'main'),
getConfig: (configFile) => serverRequire(configFile),
});
};
6 changes: 3 additions & 3 deletions code/addons/onboarding/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readFileSync } from 'node:fs';

import type { Channel } from 'storybook/internal/channels';
import { telemetry } from 'storybook/internal/telemetry';
import type { CoreConfig, Options } from 'storybook/internal/types';

import fs from 'fs';

import { STORYBOOK_ADDON_ONBOARDING_CHANNEL } from './constants';

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

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

channel.on(STORYBOOK_ADDON_ONBOARDING_CHANNEL, ({ type, ...event }: Event) => {
Expand Down
6 changes: 3 additions & 3 deletions code/builders/builder-vite/src/codegen-importfn-script.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Options } from 'storybook/internal/types';
import { relative } from 'node:path';

import * as path from 'path';
import type { Options } from 'storybook/internal/types';

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

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

return ` '${toImportPath(relativePath)}': async () => import('/@fs/${file}')`;
});
Expand Down
3 changes: 2 additions & 1 deletion code/builders/builder-vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// noinspection JSUnusedGlobalSymbols
import { join, parse } from 'node:path';

import { NoStatsForViteDevError } from 'storybook/internal/server-errors';
import type { Options } from 'storybook/internal/types';

import type { RequestHandler } from 'express';
import express from 'express';
import * as fs from 'fs-extra';
import { join, parse } from 'path';
import { corePath } from 'storybook/core-path';
import type { ViteDevServer } from 'vite';

Expand Down
9 changes: 4 additions & 5 deletions code/builders/builder-vite/src/list-stories.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isAbsolute, join } from 'node:path';

import { commonGlobOptions, normalizeStories } from 'storybook/internal/common';
import type { Options } from 'storybook/internal/types';

import { glob } from 'glob';
import * as path from 'path';
import slash from 'slash';

export async function listStories(options: Options) {
Expand All @@ -15,10 +16,8 @@ export async function listStories(options: Options) {
configDir: options.configDir,
workingDir: options.configDir,
}).map(({ directory, files }) => {
const pattern = path.join(directory, files);
const absolutePattern = path.isAbsolute(pattern)
? pattern
: path.join(options.configDir, pattern);
const pattern = join(directory, files);
const absolutePattern = isAbsolute(pattern) ? pattern : join(options.configDir, pattern);

return glob(slash(absolutePattern), {
...commonGlobOptions(absolutePattern),
Expand Down
5 changes: 3 additions & 2 deletions code/builders/builder-vite/src/optimizeDeps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { relative } from 'node:path';

import type { Options } from 'storybook/internal/types';

import * as path from 'path';
import type { UserConfig, InlineConfig as ViteInlineConfig } from 'vite';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFileSync } from 'node:fs';

import type { Options } from 'storybook/internal/types';

import * as fs from 'fs';
import type { Plugin } from 'vite';

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

if (id === iframeId) {
return fs.readFileSync(
require.resolve('@storybook/builder-vite/input/iframe.html'),
'utf-8'
);
return readFileSync(require.resolve('@storybook/builder-vite/input/iframe.html'), 'utf-8');
}

return undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// This plugin is a direct port of https://github.com/IanVS/vite-plugin-turbosnap
import { relative } from 'node:path';

import type { BuilderStats } from 'storybook/internal/types';

import path from 'path';
import slash from 'slash';
import type { Plugin } from 'vite';

Expand Down Expand Up @@ -57,7 +58,7 @@ export function pluginWebpackStats({ workingDir }: WebpackStatsPluginOptions): W
}
// Otherwise, we need them in the format `./path/to/file.js`.
else {
const relativePath = path.relative(workingDir, stripQueryParams(filename));
const relativePath = relative(workingDir, stripQueryParams(filename));
// This seems hacky, got to be a better way to add a `./` to the start of a path.
return `./${slash(relativePath)}`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { isAbsolute, relative, resolve } from 'node:path';

import { stripAbsNodeModulesPath } from 'storybook/internal/common';
import type { PreviewAnnotation } from 'storybook/internal/types';

import { isAbsolute, relative, resolve } from 'path';
import slash from 'slash';

/**
Expand Down
5 changes: 3 additions & 2 deletions code/builders/builder-vite/src/vite-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve } from 'node:path';

import {
getBuilderOptions,
getFrameworkName,
Expand All @@ -7,7 +9,6 @@ import {
import { globalsNameReferenceMap } from 'storybook/internal/preview/globals';
import type { Options } from 'storybook/internal/types';

import * as path from 'path';
import type {
ConfigEnv,
InlineConfig,
Expand Down Expand Up @@ -50,7 +51,7 @@ export async function commonConfig(

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

const projectRoot = path.resolve(options.configDir, '..');
const projectRoot = resolve(options.configDir, '..');

// I destructure away the `build` property from the user's config object
// I do this because I can contain config that breaks storybook, such as we had in a lit project.
Expand Down
3 changes: 2 additions & 1 deletion code/builders/builder-webpack5/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join, parse } from 'node:path';

import { PREVIEW_BUILDER_PROGRESS } from 'storybook/internal/core-events';
import { logger } from 'storybook/internal/node-logger';
import {
Expand All @@ -11,7 +13,6 @@ import { checkWebpackVersion } from '@storybook/core-webpack';

import express from 'express';
import fs from 'fs-extra';
import { join, parse } from 'path';
import prettyTime from 'pretty-hrtime';
import { corePath } from 'storybook/core-path';
import type { Configuration, Stats, StatsOptions } from 'webpack';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { dirname, join, resolve } from 'node:path';

import {
getBuilderOptions,
isPreservingSymlinks,
Expand All @@ -14,7 +16,6 @@ import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
import type { TransformOptions as EsbuildOptions } from 'esbuild';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { dirname, join, resolve } from 'path';
import TerserWebpackPlugin from 'terser-webpack-plugin';
import { dedent } from 'ts-dedent';
import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join, resolve } from 'node:path';

import {
getBuilderOptions,
handlebars,
Expand All @@ -9,7 +11,6 @@ import type { Options, PreviewAnnotation } from 'storybook/internal/types';

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

import { join, resolve } from 'path';
import slash from 'slash';

import type { BuilderOptions } from '../types';
Expand Down
10 changes: 5 additions & 5 deletions code/core/src/builder-manager/utils/framework.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'node:path';
import { join } from 'node:path';

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

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

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

it('should return undefined if the path is not a storybook package', () => {
const packagePath = path.join(process.cwd(), 'foo');
const packagePath = join(process.cwd(), 'foo');
expect(pluckStorybookPackageFromPath(packagePath)).toBe(undefined);
});
});

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

it('should return the given path if the path is not a third party package', () => {
const packagePath = path.join(process.cwd(), 'foo', 'bar', 'baz');
const packagePath = join(process.cwd(), 'foo', 'bar', 'baz');
expect(pluckThirdPartyPackageFromPath(packagePath)).toBe(packagePath);
});
});
Expand Down
4 changes: 2 additions & 2 deletions code/core/src/builder-manager/utils/framework.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'node:path';
import { sep } from 'node:path';

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

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

export const pluckStorybookPackageFromPath = (packagePath: string) =>
normalizePath(packagePath).match(/(@storybook\/.*)$/)?.[1];
Expand Down
11 changes: 6 additions & 5 deletions code/core/src/cli/angular/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

import { logger } from '@storybook/core/node-logger';
import { MissingAngularJsonError } from '@storybook/core/server-errors';

import boxen from 'boxen';
import fs from 'fs';
import { join } from 'path';
import prompts from 'prompts';
import { dedent } from 'ts-dedent';

Expand Down Expand Up @@ -43,11 +44,11 @@ export class AngularJSON {
};

constructor() {
if (!fs.existsSync(ANGULAR_JSON_PATH)) {
if (!existsSync(ANGULAR_JSON_PATH)) {
throw new MissingAngularJsonError({ path: join(process.cwd(), ANGULAR_JSON_PATH) });
}

const jsonContent = fs.readFileSync(ANGULAR_JSON_PATH, 'utf8');
const jsonContent = readFileSync(ANGULAR_JSON_PATH, 'utf8');
this.json = JSON.parse(jsonContent);
}

Expand Down Expand Up @@ -149,6 +150,6 @@ export class AngularJSON {
}

write() {
fs.writeFileSync(ANGULAR_JSON_PATH, JSON.stringify(this.json, null, 2));
writeFileSync(ANGULAR_JSON_PATH, JSON.stringify(this.json, null, 2));
}
}
Loading
Loading