Skip to content

Commit

Permalink
Merge pull request #23897 from storybookjs/revert-23882-revert-23496-…
Browse files Browse the repository at this point in the history
…norbert/react-peerdep-webpack-builder-removal

Maintenance: Remove need for `react` as peerDependency
  • Loading branch information
ndelangen authored Aug 24, 2023
2 parents 86e342c + 6a20ecc commit dfe41f7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
14 changes: 1 addition & 13 deletions code/builders/builder-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,15 @@
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@babel/core": "^7.22.9",
"@storybook/addons": "workspace:*",
"@babel/core": "^7.22.0",
"@storybook/channels": "workspace:*",
"@storybook/client-api": "workspace:*",
"@storybook/client-logger": "workspace:*",
"@storybook/components": "workspace:*",
"@storybook/core-common": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/core-webpack": "workspace:*",
"@storybook/global": "^5.0.0",
"@storybook/manager-api": "workspace:*",
"@storybook/node-logger": "workspace:*",
"@storybook/preview": "workspace:*",
"@storybook/preview-api": "workspace:*",
"@storybook/router": "workspace:*",
"@storybook/store": "workspace:*",
"@storybook/theming": "workspace:*",
"@swc/core": "^1.3.49",
"@types/node": "^16.0.0",
"@types/semver": "^7.3.4",
Expand Down Expand Up @@ -110,10 +102,6 @@
"slash": "^5.0.0",
"typescript": "~4.9.3"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
Expand Down
43 changes: 27 additions & 16 deletions code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,35 @@ import { createBabelLoader, createSWCLoader } from './loaders';

const getAbsolutePath = <I extends string>(input: I): I =>
dirname(require.resolve(join(input, 'package.json'))) as any;
const maybeGetAbsolutePath = <I extends string>(input: I): I | false => {
try {
return getAbsolutePath(input);
} catch (e) {
return false;
}
};

const managerAPIPath = maybeGetAbsolutePath(`@storybook/manager-api`);
const componentsPath = maybeGetAbsolutePath(`@storybook/components`);
const globalPath = maybeGetAbsolutePath(`@storybook/global`);
const routerPath = maybeGetAbsolutePath(`@storybook/router`);
const themingPath = maybeGetAbsolutePath(`@storybook/theming`);

// these packages are not pre-bundled because of react dependencies.
// these are not dependencies of the builder anymore, thus resolving them can fail.
// we should remove the aliases in 8.0, I'm not sure why they are here in the first place.
const storybookPaths: Record<string, string> = {
...[
// these packages are not pre-bundled because of react dependencies
'components',
'global',
'manager-api',
'router',
'theming',
].reduce(
(acc, sbPackage) => ({
...acc,
[`@storybook/${sbPackage}`]: getAbsolutePath(`@storybook/${sbPackage}`),
}),
{}
),
// deprecated, remove in 8.0
[`@storybook/api`]: getAbsolutePath(`@storybook/manager-api`),
...(managerAPIPath
? {
// deprecated, remove in 8.0
[`@storybook/api`]: managerAPIPath,
[`@storybook/manager-api`]: managerAPIPath,
}
: {}),
...(componentsPath ? { [`@storybook/components`]: componentsPath } : {}),
...(globalPath ? { [`@storybook/global`]: globalPath } : {}),
...(routerPath ? { [`@storybook/router`]: routerPath } : {}),
...(themingPath ? { [`@storybook/theming`]: themingPath } : {}),
};

export default async (
Expand Down
8 changes: 4 additions & 4 deletions code/lib/codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"check": "../../../scripts/prepare/check.ts",
"prep": "../../../scripts/prepare/bundle.ts"
},
"files": [
"dist/**/*",
"README.md",
"*.js",
"*.d.ts",
"!src/**/*"
],
"scripts": {
"check": "../../../scripts/prepare/check.ts",
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@babel/core": "^7.22.9",
"@babel/preset-env": "^7.22.9",
Expand Down
15 changes: 2 additions & 13 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/core@npm:^7.11.6, @babel/core@npm:^7.12.0, @babel/core@npm:^7.12.3, @babel/core@npm:^7.13.16, @babel/core@npm:^7.19.6, @babel/core@npm:^7.20.12, @babel/core@npm:^7.22.1, @babel/core@npm:^7.22.9, @babel/core@npm:^7.3.4, @babel/core@npm:^7.7.5":
"@babel/core@npm:^7.11.6, @babel/core@npm:^7.12.0, @babel/core@npm:^7.12.3, @babel/core@npm:^7.13.16, @babel/core@npm:^7.19.6, @babel/core@npm:^7.20.12, @babel/core@npm:^7.22.0, @babel/core@npm:^7.22.1, @babel/core@npm:^7.22.9, @babel/core@npm:^7.3.4, @babel/core@npm:^7.7.5":
version: 7.22.9
resolution: "@babel/core@npm:7.22.9"
dependencies:
Expand Down Expand Up @@ -6466,23 +6466,15 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/builder-webpack5@workspace:builders/builder-webpack5"
dependencies:
"@babel/core": ^7.22.9
"@storybook/addons": "workspace:*"
"@babel/core": ^7.22.0
"@storybook/channels": "workspace:*"
"@storybook/client-api": "workspace:*"
"@storybook/client-logger": "workspace:*"
"@storybook/components": "workspace:*"
"@storybook/core-common": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/core-webpack": "workspace:*"
"@storybook/global": ^5.0.0
"@storybook/manager-api": "workspace:*"
"@storybook/node-logger": "workspace:*"
"@storybook/preview": "workspace:*"
"@storybook/preview-api": "workspace:*"
"@storybook/router": "workspace:*"
"@storybook/store": "workspace:*"
"@storybook/theming": "workspace:*"
"@swc/core": ^1.3.49
"@types/node": ^16.0.0
"@types/pretty-hrtime": ^1.0.0
Expand Down Expand Up @@ -6517,9 +6509,6 @@ __metadata:
webpack-dev-middleware: ^6.1.1
webpack-hot-middleware: ^2.25.1
webpack-virtual-modules: ^0.5.0
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
peerDependenciesMeta:
typescript:
optional: true
Expand Down

0 comments on commit dfe41f7

Please sign in to comment.