Use JS only story glob extension patterns in JavaScript projects

This commit is contained in:
Valentin Palkovic 2024-06-25 11:55:20 +02:00
parent aee10a90b8
commit 74646c68da
3 changed files with 10 additions and 4 deletions

View File

@ -29,7 +29,7 @@ describe('configureMain', () => {
expect(mainConfigContent).toMatchInlineSnapshot(`
"/** @type { import('@storybook/react-vite').StorybookConfig } */
const config = {
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs)'],
addons: [],
framework: {
name: '@storybook/react-vite',
@ -95,7 +95,7 @@ describe('configureMain', () => {
/** @type { import('@storybook/react-webpack5').StorybookConfig } */
const config = {
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs)'],
addons: [
path.dirname(require.resolve(path.join('@storybook/addon-links', 'package.json'))),
path.dirname(require.resolve(path.join('@storybook/addon-essentials', 'package.json'))),

View File

@ -49,6 +49,8 @@ const sanitizeFramework = (framework: string) => {
return matches[0];
};
const typescriptExtensions = ['ts', 'tsx', 'mts', 'cts'];
export async function configureMain({
addons,
extensions = ['js', 'jsx', 'mjs', 'ts', 'tsx'],
@ -57,10 +59,14 @@ export async function configureMain({
prefixes = [],
...custom
}: ConfigureMainOptions) {
const isLanguageJavascript = language === SupportedLanguage.JAVASCRIPT;
const filteredExtensions = extensions.filter((extension) =>
isLanguageJavascript ? !typescriptExtensions.includes(extension) : true
);
const srcPath = path.resolve(storybookConfigFolder, '../src');
const prefix = (await fse.pathExists(srcPath)) ? '../src' : '../stories';
const config = {
stories: [`${prefix}/**/*.mdx`, `${prefix}/**/*.stories.@(${extensions.join('|')})`],
stories: [`${prefix}/**/*.mdx`, `${prefix}/**/*.stories.@(${filteredExtensions.join('|')})`],
addons,
...custom,
};

View File

@ -92,7 +92,7 @@ const publish = async (packages: { name: string; location: string }[], url: stri
const command = `cd ${path.resolve(
'../code',
location
)} && yarn pack --out=${PACKS_DIRECTORY}/${tarballFilename} && cd ${PACKS_DIRECTORY} && npm publish ./${tarballFilename} --registry ${url} --force --access restricted --ignore-scripts`;
)} && yarn pack --out=${PACKS_DIRECTORY}/${tarballFilename} && cd ${PACKS_DIRECTORY} && npm publish ./${tarballFilename} --registry ${url} --force --ignore-scripts`;
exec(command, (e) => {
if (e) {
rej(e);