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

ESM: Only generate esm dist #29419

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
097d681
only generate esm
ndelangen Oct 21, 2024
5cdde14
esm only core v2
ndelangen Oct 22, 2024
bd8316b
well..
ndelangen Oct 22, 2024
fe04dfe
just pushing ahead to test things out
ndelangen Oct 22, 2024
943aea3
while I'm at it experimenting with things...
ndelangen Oct 22, 2024
5386cbf
keep going
ndelangen Oct 22, 2024
9ed0481
delete package root js-files
ndelangen Oct 22, 2024
52f75df
remove more root js-files
ndelangen Oct 22, 2024
3f1ea63
cleanup
ndelangen Oct 22, 2024
b96c6c6
adjustments
ndelangen Oct 23, 2024
a71fcf6
fix
ndelangen Oct 23, 2024
93a3d1d
improve debug-ability
ndelangen Oct 23, 2024
9f19440
linting fixes
ndelangen Oct 23, 2024
9eaa148
fix
ndelangen Oct 23, 2024
731e5f7
cleanup
ndelangen Oct 23, 2024
7a10781
make codemod esm
ndelangen Oct 23, 2024
08102f4
fixes
ndelangen Oct 23, 2024
d045b43
fixes
ndelangen Oct 23, 2024
79e16b9
disable addon-onboarding for now
ndelangen Oct 23, 2024
8554e9c
fix
ndelangen Oct 23, 2024
9ea6356
fix
ndelangen Oct 23, 2024
4db5581
fix
ndelangen Oct 23, 2024
2e87a60
add require definition
ndelangen Oct 23, 2024
0ff5697
fix
ndelangen Oct 23, 2024
6e0ffc9
make async and use imperative import in jest config for nextjs test-s…
ndelangen Oct 23, 2024
77fa32f
Merge branch 'norbert/esm-esbuild-direct' into norbert/no-more-cjs-in…
ndelangen Oct 24, 2024
2800098
use addon-bundle script everywhere
ndelangen Oct 24, 2024
6191510
Merge branch 'norbert/no-more-cjs-in-core-dist' of https://github.com…
ndelangen Oct 24, 2024
57b72b4
Merge branch 'norbert/esm-esbuild-direct' into norbert/no-more-cjs-in…
ndelangen Oct 24, 2024
8e186fb
dedupe
ndelangen Oct 24, 2024
6bbad10
Merge branch 'norbert/esm-esbuild-direct' into norbert/no-more-cjs-in…
ndelangen Oct 24, 2024
b1e419b
simpler
ndelangen Oct 25, 2024
505e444
Merge branch 'norbert/no-more-cjs-in-core-dist' of https://github.com…
ndelangen Oct 25, 2024
adea808
simple previewAnnotation loading
ndelangen Oct 25, 2024
1f0ba0d
Merge branch 'norbert/esm-esbuild-direct' into norbert/no-more-cjs-in…
ndelangen Oct 25, 2024
101473e
cleanup
ndelangen Oct 25, 2024
243c51a
fixes
ndelangen Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion code/.storybook/storybook.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { beforeAll, vi, expect as vitestExpect } from 'vitest';
import { setProjectAnnotations } from '@storybook/react';
import { userEvent as storybookEvent, expect as storybookExpect } from '@storybook/test';

// eslint-disable-next-line import/namespace
import * as testAnnotations from '@storybook/experimental-addon-test/preview';

import * as coreAnnotations from '../addons/toolbars/template/stories/preview';
Expand Down
1 change: 0 additions & 1 deletion code/addons/a11y/manager.js

This file was deleted.

9 changes: 3 additions & 6 deletions code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"default": "./dist/index.js"
},
"./preview": {
"types": "./dist/preview.d.ts",
"import": "./dist/preview.mjs",
"require": "./dist/preview.js"
"default": "./dist/preview.js"
},
"./manager": "./dist/manager.js",
"./register": "./dist/manager.js",
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
Expand Down
1 change: 0 additions & 1 deletion code/addons/a11y/preview.js

This file was deleted.

1 change: 0 additions & 1 deletion code/addons/actions/manager.js

This file was deleted.

14 changes: 5 additions & 9 deletions code/addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,25 @@
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"default": "./dist/index.js"
},
"./decorator": {
"types": "./dist/decorator.d.ts",
"import": "./dist/decorator.mjs",
"require": "./dist/decorator.js"
"default": "./dist/decorator.js"
},
"./preview": {
"types": "./dist/preview.d.ts",
"import": "./dist/preview.mjs",
"require": "./dist/preview.js"
"default": "./dist/preview.js"
},
"./manager": "./dist/manager.js",
"./register.js": "./dist/manager.js",
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"react-native": "dist/index.mjs",
"react-native": "dist/index.js",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
Expand Down
1 change: 0 additions & 1 deletion code/addons/actions/preview.js

This file was deleted.

1 change: 0 additions & 1 deletion code/addons/backgrounds/manager.js

This file was deleted.

9 changes: 3 additions & 6 deletions code/addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@
},
"license": "MIT",
"author": "jbaxleyiii",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"default": "./dist/index.js"
},
"./preview": {
"types": "./dist/preview.d.ts",
"import": "./dist/preview.mjs",
"require": "./dist/preview.js"
"default": "./dist/preview.js"
},
"./manager": "./dist/manager.js",
"./register": "./dist/manager.js",
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
Expand Down
1 change: 0 additions & 1 deletion code/addons/backgrounds/preview.js

This file was deleted.

1 change: 0 additions & 1 deletion code/addons/controls/manager.js

This file was deleted.

6 changes: 2 additions & 4 deletions code/addons/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"default": "./dist/index.js"
},
"./manager": "./dist/manager.js",
"./register": "./dist/manager.js",
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
Expand Down
46 changes: 15 additions & 31 deletions code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,27 @@
"url": "https://opencollective.com/storybook"
},
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"default": "./dist/index.js"
},
"./preview": {
"types": "./dist/preview.d.ts",
"import": "./dist/preview.mjs",
"require": "./dist/preview.js"
"default": "./dist/preview.js"
},
"./preset": {
"types": "./dist/preset.d.ts",
"import": "./dist/preset.js",
"require": "./dist/preset.js"
"default": "./dist/preset.js"
},
"./blocks": {
"types": "./dist/blocks.d.ts",
"import": "./dist/blocks.mjs",
"require": "./dist/blocks.js"
},
"./dist/preview": {
"types": "./dist/preview.d.ts",
"import": "./dist/preview.mjs",
"require": "./dist/preview.js"
},
"./dist/preset": {
"types": "./dist/preset.d.ts",
"require": "./dist/preset.js"
},
"./dist/shims/mdx-react-shim": {
"types": "./dist/shims/mdx-react-shim.d.ts",
"import": "./dist/shims/mdx-react-shim.mjs",
"require": "./dist/shims/mdx-react-shim.js"
"default": "./dist/blocks.js"
},
"./mdx-react-shim": {
"types": "./dist/shims/mdx-react-shim.d.ts",
"import": "./dist/shims/mdx-react-shim.mjs",
"require": "./dist/shims/mdx-react-shim.js"
"default": "./dist/shims/mdx-react-shim.js"
},
"./mdx-loader": "./dist/mdx-loader.js",
"./svelte/HOC.svelte": "./svelte/HOC.svelte",
Expand All @@ -73,8 +55,6 @@
"./web-components/index.js": "./web-components/index.js",
"./package.json": "./package.json"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
Expand All @@ -94,7 +74,7 @@
],
"scripts": {
"check": "jiti ../../../scripts/prepare/check.ts",
"prep": "jiti ../../../scripts/prepare/bundle.ts"
"prep": "jiti ../../../scripts/prepare/addon-bundle.ts"
},
"dependencies": {
"@mdx-js/react": "^3.0.0",
Expand Down Expand Up @@ -123,12 +103,16 @@
"access": "public"
},
"bundler": {
"entries": [
"previewEntries": [
"./src/preview.ts"
],
"exportEntries": [
"./src/index.ts",
"./src/preset.ts",
"./src/preview.ts",
"./src/blocks.ts",
"./src/shims/mdx-react-shim.ts",
"./src/shims/mdx-react-shim.ts"
],
"nodeEntries": [
"./src/preset.ts",
"./src/mdx-loader.ts"
]
},
Expand Down
1 change: 0 additions & 1 deletion code/addons/docs/preset.js

This file was deleted.

1 change: 0 additions & 1 deletion code/addons/docs/preview.js

This file was deleted.

6 changes: 3 additions & 3 deletions code/addons/docs/src/plugins/mdx-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

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

Expand Down Expand Up @@ -35,9 +36,8 @@ export async function mdxPlugin(options: Options): Promise<Plugin> {
const mdxLoaderOptions: CompileOptions = await presets.apply('mdxLoaderOptions', {
...mdxPluginOptions,
mdxCompileOptions: {
providerImportSource: join(
dirname(require.resolve('@storybook/addon-docs/package.json')),
'/dist/shims/mdx-react-shim.mjs'
providerImportSource: fileURLToPath(
import.meta.resolve('@storybook/addon-docs/mdx-react-shim')
),
...mdxPluginOptions?.mdxCompileOptions,
rehypePlugins: [
Expand Down
35 changes: 19 additions & 16 deletions code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dirname, isAbsolute, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import { logger } from 'storybook/internal/node-logger';
import type { DocsOptions, Options, PresetProperty } from 'storybook/internal/types';
Expand All @@ -18,14 +19,16 @@ const getResolvedReact = async (options: Options) => {
const resolvedReact = (await options.presets.apply('resolvedReact', {})) as any;
// resolvedReact should always be set by the time we get here, but just in case, we'll default to addon-docs's react dependencies
return {
react: resolvedReact.react ?? dirname(require.resolve('react/package.json')),
reactDom: resolvedReact.reactDom ?? dirname(require.resolve('react-dom/package.json')),
react: resolvedReact.react ?? dirname(fileURLToPath(import.meta.resolve('react/package.json'))),
reactDom:
resolvedReact.reactDom ??
dirname(fileURLToPath(import.meta.resolve('react-dom/package.json'))),
// In Webpack, symlinked MDX files will cause @mdx-js/react to not be resolvable if it is not hoisted
// This happens for the SB monorepo's template stories when a sandbox has a different react version than
// addon-docs, causing addon-docs's dependencies not to be hoisted.
// This might also affect regular users who have a similar setup.
// Explicitly alias @mdx-js/react to avoid this issue.
mdx: resolvedReact.mdx ?? dirname(require.resolve('@mdx-js/react')),
mdx: resolvedReact.mdx ?? fileURLToPath(import.meta.resolve('@mdx-js/react')),
};
};

Expand All @@ -45,9 +48,8 @@ async function webpack(
const mdxLoaderOptions: CompileOptions = await options.presets.apply('mdxLoaderOptions', {
...mdxPluginOptions,
mdxCompileOptions: {
providerImportSource: join(
dirname(require.resolve('@storybook/addon-docs/package.json')),
'/dist/shims/mdx-react-shim.mjs'
providerImportSource: fileURLToPath(
import.meta.resolve('@storybook/addon-docs/mdx-react-shim')
),
...mdxPluginOptions.mdxCompileOptions,
rehypePlugins: [
Expand All @@ -73,12 +75,12 @@ async function webpack(
* In the future the `@storybook/theming` and `@storybook/components` can be removed, as they
* should be singletons in the future due to the peerDependency on `storybook` package.
*/
const cliPath = dirname(require.resolve('storybook/package.json'));
const cliPath = dirname(fileURLToPath(import.meta.resolve('storybook/package.json')));
const themingPath = join(cliPath, 'core', 'theming', 'index.js');
const themingCreatePath = join(cliPath, 'core', 'theming', 'create.js');

const componentsPath = join(cliPath, 'core', 'components', 'index.js');
const blocksPath = dirname(require.resolve('@storybook/blocks/package.json'));
const blocksPath = fileURLToPath(import.meta.resolve('@storybook/blocks'));
if (Array.isArray(webpackConfig.resolve?.alias)) {
alias = [...webpackConfig.resolve?.alias];
alias.push(
Expand Down Expand Up @@ -147,7 +149,7 @@ async function webpack(
exclude: /(stories|story)\.mdx$/,
use: [
{
loader: require.resolve('./mdx-loader'),
loader: fileURLToPath(import.meta.resolve('@storybook/addon-docs/mdx-loader')),
options: mdxLoaderOptions,
},
],
Expand All @@ -168,7 +170,7 @@ const docs = (docsOptions: DocsOptions) => {
};

export const addons: PresetProperty<'addons'> = [
require.resolve('@storybook/react-dom-shim/dist/preset'),
fileURLToPath(import.meta.resolve('@storybook/react-dom-shim/preset')),
];

export const viteFinal = async (config: any, options: Options) => {
Expand All @@ -178,11 +180,11 @@ export const viteFinal = async (config: any, options: Options) => {
// Use the resolvedReact preset to alias react and react-dom to either the users version or the version shipped with addon-docs
const { react, reactDom, mdx } = await getResolvedReact(options);

const cliPath = dirname(require.resolve('storybook/package.json'));
const cliPath = dirname(fileURLToPath(import.meta.resolve('storybook/package.json')));
const themingPath = join(cliPath, 'core', 'theming', 'index.js');
const themingCreatePath = join(cliPath, 'core', 'theming', 'create.js');
const componentsPath = join(cliPath, 'core', 'components', 'index.js');
const blocksPath = dirname(require.resolve('@storybook/blocks/package.json'));
const blocksPath = dirname(fileURLToPath(import.meta.resolve('@storybook/blocks/package.json')));

const packageDeduplicationPlugin = {
name: 'storybook:package-deduplication',
Expand Down Expand Up @@ -236,16 +238,17 @@ const docsX = docs as any;
* is always a resolved react.
*/
export const resolvedReact = async (existing: any) => ({
react: existing?.react ?? dirname(require.resolve('react/package.json')),
reactDom: existing?.reactDom ?? dirname(require.resolve('react-dom/package.json')),
mdx: existing?.mdx ?? dirname(require.resolve('@mdx-js/react')),
react: existing?.react ?? dirname(fileURLToPath(import.meta.resolve('react/package.json'))),
reactDom:
existing?.reactDom ?? dirname(fileURLToPath(import.meta.resolve('react-dom/package.json'))),
mdx: existing?.mdx ?? fileURLToPath(import.meta.resolve('@mdx-js/react')),
});

const optimizeViteDeps = [
'@mdx-js/react',
'@storybook/addon-docs > acorn-jsx',
'@storybook/addon-docs',
'@storybook/addon-essentials/docs/mdx-react-shim',
'@storybook/addon-docs/mdx-react-shim',
'markdown-to-jsx',
];

Expand Down
Loading
Loading