Skip to content

Commit

Permalink
allow mjs files & externalize @storybook/global
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Aug 25, 2023
1 parent bd55608 commit 8f1ed07
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs-extra';
import { dirname, join } from 'path';
import remarkSlug from 'remark-slug';
import remarkExternalLinks from 'remark-external-links';
import { dedent } from 'ts-dedent';
Expand Down Expand Up @@ -50,7 +51,10 @@ async function webpack(
skipCsf: true,
...mdxPluginOptions,
mdxCompileOptions: {
providerImportSource: require.resolve('@storybook/addon-docs/dist/shims/mdx-react-shim'),
providerImportSource: join(
dirname(require.resolve('@storybook/addon-docs/package.json')),
'/dist/shims/mdx-react-shim'
),
...mdxPluginOptions.mdxCompileOptions,
remarkPlugins: [remarkSlug, remarkExternalLinks].concat(
mdxPluginOptions?.mdxCompileOptions?.remarkPlugins ?? []
Expand Down
9 changes: 6 additions & 3 deletions code/addons/essentials/src/docs/preset.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* eslint-disable import/export */
import { dirname, join } from 'path';

// eslint-disable-next-line import/export
export * from '@storybook/addon-docs/dist/preset';

export const mdxLoaderOptions = async (config: any) => {
// eslint-disable-next-line no-param-reassign
config.mdxCompileOptions.providerImportSource = require.resolve(
'@storybook/addon-docs/dist/shims/mdx-react-shim'
config.mdxCompileOptions.providerImportSource = join(
dirname(require.resolve('@storybook/addon-docs/package.json')),
'/dist/shims/mdx-react-shim'
);
return config;
};
6 changes: 5 additions & 1 deletion code/builders/builder-vite/src/plugins/mdx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Plugin } from 'vite';
import remarkSlug from 'remark-slug';
import remarkExternalLinks from 'remark-external-links';
import { createFilter } from 'vite';
import { dirname, join } from 'path';

const isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');

Expand Down Expand Up @@ -33,7 +34,10 @@ export async function mdxPlugin(options: Options): Promise<Plugin> {
const mdxLoaderOptions = await options.presets.apply('mdxLoaderOptions', {
...mdxPluginOptions,
mdxCompileOptions: {
providerImportSource: require.resolve('@storybook/addon-docs/mdx-react-shim'),
providerImportSource: join(
dirname(require.resolve('@storybook/addon-docs/package.json')),
'/dist/shims/mdx-react-shim'
),
...mdxPluginOptions?.mdxCompileOptions,
remarkPlugins: [remarkSlug, remarkExternalLinks].concat(
mdxPluginOptions?.mdxCompileOptions?.remarkPlugins ?? []
Expand Down
2 changes: 2 additions & 0 deletions code/lib/preview/src/globals/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as CHANNELS from '@storybook/channels';
import * as CLIENT_LOGGER from '@storybook/client-logger';
import * as CORE_EVENTS from '@storybook/core-events';
import * as PREVIEW_API from '@storybook/preview-api';
import * as GLOBAL from '@storybook/global';

// DEPRECATED, remove in 8.0
import * as ADDONS from '@storybook/preview-api/dist/addons';
Expand All @@ -22,6 +23,7 @@ export const values: Required<Record<keyof typeof globals, any>> = {
'@storybook/client-logger': CLIENT_LOGGER,
'@storybook/core-events': CORE_EVENTS,
'@storybook/preview-api': PREVIEW_API,
'@storybook/global': GLOBAL,

// DEPRECATED, remove in 8.0
'@storybook/addons': ADDONS,
Expand Down
1 change: 1 addition & 0 deletions code/lib/preview/src/globals/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Here we map the name of a module to their NAME in the global scope.
export const globals = {
'@storybook/addons': '__STORYBOOK_MODULE_ADDONS__',
'@storybook/global': '__STORYBOOK_MODULE_GLOBAL__',
'@storybook/channel-postmessage': '__STORYBOOK_MODULE_CHANNEL_POSTMESSAGE__', // @deprecated: remove in 8.0
'@storybook/channel-websocket': '__STORYBOOK_MODULE_CHANNEL_WEBSOCKET__', // @deprecated: remove in 8.0
'@storybook/channels': '__STORYBOOK_MODULE_CHANNELS__',
Expand Down

0 comments on commit 8f1ed07

Please sign in to comment.