diff --git a/addons/a11y/package.json b/addons/a11y/package.json index 895219c5535b..d398ad611360 100644 --- a/addons/a11y/package.json +++ b/addons/a11y/package.json @@ -54,6 +54,10 @@ "@types/react-redux": "^7.0.6", "@types/webpack-env": "^1.15.1" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/addons/actions/package.json b/addons/actions/package.json index 17a4229c2b1a..b482a6664e7d 100644 --- a/addons/actions/package.json +++ b/addons/actions/package.json @@ -47,6 +47,10 @@ "@types/uuid": "^3.4.7", "@types/webpack-env": "^1.15.1" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/addons/backgrounds/package.json b/addons/backgrounds/package.json index e0bc33c49cad..a3e232c1a354 100644 --- a/addons/backgrounds/package.json +++ b/addons/backgrounds/package.json @@ -46,6 +46,10 @@ "@types/util-deprecate": "^1.0.0", "@types/webpack-env": "^1.15.1" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/addons/centered/package.json b/addons/centered/package.json index 4246d370555e..85e16559de95 100644 --- a/addons/centered/package.json +++ b/addons/centered/package.json @@ -41,5 +41,9 @@ "preact": "*", "react": "*" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "gitHead": "4b9d901add9452525135caae98ae5f78dd8da9ff" } diff --git a/addons/contexts/package.json b/addons/contexts/package.json index 042078ebfbb1..3ade7a737065 100644 --- a/addons/contexts/package.json +++ b/addons/contexts/package.json @@ -41,7 +41,20 @@ "qs": "*", "rax": "*", "react": "*", - "vue": "*" + "vue": "*", + "react-dom": "*", + "regenerator-runtime": "*" + }, + "peerDependenciesMeta": { + "preact": { + "optional": true + }, + "rax": { + "optional": true + }, + "vue": { + "optional": true + } }, "publishConfig": { "access": "public" diff --git a/addons/cssresources/package.json b/addons/cssresources/package.json index 689a251b5be3..f24c796d89f2 100644 --- a/addons/cssresources/package.json +++ b/addons/cssresources/package.json @@ -44,7 +44,9 @@ "@types/webpack-env": "^1.15.1" }, "peerDependencies": { - "react": "*" + "react": "*", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/design-assets/package.json b/addons/design-assets/package.json index 2871d7bde4b7..76d105583939 100644 --- a/addons/design-assets/package.json +++ b/addons/design-assets/package.json @@ -45,6 +45,10 @@ "ts-dedent": "^1.1.1", "use-image": "^1.0.3" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/addons/docs/package.json b/addons/docs/package.json index b2955d883757..29fbed5e7534 100644 --- a/addons/docs/package.json +++ b/addons/docs/package.json @@ -81,9 +81,12 @@ "jest-specific-snapshot": "^2.0.0" }, "peerDependencies": { + "@babel/core": "^7.0.0-0", "babel-loader": "^8.0.0", - "react": "^16.8.0", - "react-is": "^16.8.0" + "react": "^16.9.0", + "react-is": "^16.8.0", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/essentials/package.json b/addons/essentials/package.json index 9606824cee9a..7f4673d48ee9 100644 --- a/addons/essentials/package.json +++ b/addons/essentials/package.json @@ -40,7 +40,9 @@ "peerDependencies": { "babel-loader": "^8.0.0", "react": "^16.8.0", - "react-is": "^16.8.0" + "react-dom": "*", + "react-is": "^16.8.0", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/events/package.json b/addons/events/package.json index 2b0fea457788..72ac1c6f2810 100644 --- a/addons/events/package.json +++ b/addons/events/package.json @@ -48,7 +48,9 @@ "@types/webpack-env": "^1.15.1" }, "peerDependencies": { - "react": "*" + "react": "*", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/google-analytics/package.json b/addons/google-analytics/package.json index ad18ea921802..fc7ef08d3022 100644 --- a/addons/google-analytics/package.json +++ b/addons/google-analytics/package.json @@ -26,6 +26,10 @@ "global": "^4.3.2", "react-ga": "^2.5.7" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/addons/graphql/package.json b/addons/graphql/package.json index 8d17ebbada63..d7a489042115 100644 --- a/addons/graphql/package.json +++ b/addons/graphql/package.json @@ -37,7 +37,9 @@ "prop-types": "^15.7.2" }, "peerDependencies": { - "react": "*" + "react": "*", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/jest/package.json b/addons/jest/package.json index 861df000ab10..6b939aae1d00 100644 --- a/addons/jest/package.json +++ b/addons/jest/package.json @@ -50,7 +50,9 @@ "@types/webpack-env": "^1.15.1" }, "peerDependencies": { - "react": "*" + "react": "*", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/knobs/package.json b/addons/knobs/package.json index cad0d157f886..d037f83d145c 100644 --- a/addons/knobs/package.json +++ b/addons/knobs/package.json @@ -54,7 +54,9 @@ "@types/webpack-env": "^1.15.1" }, "peerDependencies": { - "react": "*" + "react": "*", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/links/package.json b/addons/links/package.json index 2b30b351b66a..9f4a1abae6e9 100644 --- a/addons/links/package.json +++ b/addons/links/package.json @@ -44,7 +44,9 @@ "@types/webpack-env": "^1.15.1" }, "peerDependencies": { - "react": "*" + "react": "*", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/options/package.json b/addons/options/package.json index b0b5662488ff..c213767791fe 100644 --- a/addons/options/package.json +++ b/addons/options/package.json @@ -36,7 +36,9 @@ "@types/webpack-env": "^1.15.1" }, "peerDependencies": { - "react": "*" + "react": "*", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/addons/queryparams/package.json b/addons/queryparams/package.json index 936496226d78..fe5725abbe3e 100644 --- a/addons/queryparams/package.json +++ b/addons/queryparams/package.json @@ -44,6 +44,10 @@ "devDependencies": { "@types/webpack-env": "^1.15.1" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/addons/storyshots/storyshots-core/package.json b/addons/storyshots/storyshots-core/package.json index 325ed434ee75..545f86ed746e 100644 --- a/addons/storyshots/storyshots-core/package.json +++ b/addons/storyshots/storyshots-core/package.json @@ -56,6 +56,10 @@ "jest-emotion": "^10.0.17", "react": "^16.8.3" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/addons/storysource/package.json b/addons/storysource/package.json index d032c9dbc482..ed751af3c0d4 100644 --- a/addons/storysource/package.json +++ b/addons/storysource/package.json @@ -51,7 +51,8 @@ }, "peerDependencies": { "@storybook/source-loader": "*", - "react": "*" + "react": "*", + "react-dom": "*" }, "publishConfig": { "access": "public" diff --git a/addons/viewport/package.json b/addons/viewport/package.json index 54fdd3d2f113..8f8d4cc48135 100644 --- a/addons/viewport/package.json +++ b/addons/viewport/package.json @@ -44,7 +44,9 @@ "@types/util-deprecate": "^1.0.0" }, "peerDependencies": { - "react": "*" + "react": "*", + "react-dom": "*", + "regenerator-runtime": "*" }, "publishConfig": { "access": "public" diff --git a/app/angular/package.json b/app/angular/package.json index 00299ae186fe..f0514d136875 100644 --- a/app/angular/package.json +++ b/app/angular/package.json @@ -59,8 +59,11 @@ "@angular/forms": ">=6.0.0", "@angular/platform-browser": ">=6.0.0", "@angular/platform-browser-dynamic": ">=6.0.0", + "@babel/core": "*", "autoprefixer": "^8.1.0", "babel-loader": "^7.0.0 || ^8.0.0", + "react": "*", + "react-dom": "*", "rxjs": "^6.0.0", "typescript": "^3.4.0", "webpack": "^4.32.0", diff --git a/app/ember/package.json b/app/ember/package.json index c10bf92a9d4f..2efcd1691ca4 100644 --- a/app/ember/package.json +++ b/app/ember/package.json @@ -38,9 +38,12 @@ "ts-dedent": "^1.1.1" }, "peerDependencies": { + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", "babel-plugin-ember-modules-api-polyfill": "^2.12.0", - "ember-source": "^3.16.0" + "ember-source": "^3.16.0", + "react": "*", + "react-dom": "*" }, "engines": { "node": ">=8.0.0" diff --git a/app/html/package.json b/app/html/package.json index bbc05e2bbc61..fa66798b51e0 100644 --- a/app/html/package.json +++ b/app/html/package.json @@ -43,7 +43,10 @@ "ts-dedent": "^1.1.1" }, "peerDependencies": { - "babel-loader": "^7.0.0 || ^8.0.0" + "@babel/core": "*", + "babel-loader": "^7.0.0 || ^8.0.0", + "react": "*", + "react-dom": "*" }, "engines": { "node": ">=8.0.0" diff --git a/app/marionette/package.json b/app/marionette/package.json index 4243efc98c7b..fe34224ee66a 100644 --- a/app/marionette/package.json +++ b/app/marionette/package.json @@ -1,48 +1,53 @@ { - "name": "@storybook/marionette", - "version": "6.0.0-alpha.4", - "description": "Storybook for Marionette: Develop Marionette.js component in isolation with Hot Reloading.", - "keywords": [ - "storybook" - ], - "homepage": "https://github.com/storybookjs/storybook/tree/master/app/marionette", - "bugs": { - "url": "https://github.com/storybookjs/storybook/issues" - }, - "repository": { - "type": "git", - "url": "https://github.com/storybookjs/storybook.git", - "directory": "app/marionette" - }, - "license": "MIT", - "main": "dist/client/index.js", - "bin": { - "build-storybook": "./bin/build.js", - "start-storybook": "./bin/index.js", - "storybook-server": "./bin/index.js" - }, - "scripts": { - "prepare": "node ../../scripts/prepare.js" - }, - "dependencies": { - "@storybook/core": "6.0.0-alpha.4", - "common-tags": "^1.8.0", - "core-js": "^3.0.1", - "global": "^4.3.2", - "html-loader": "^0.5.5", - "regenerator-runtime": "^0.12.1" - }, - "devDependencies": { - "backbone.marionette": "*" - }, - "peerDependencies": { - "babel-loader": "^7.0.0 || ^8.0.0", - "backbone.marionette": "*" - }, - "engines": { - "node": ">=8.0.0" - }, - "publishConfig": { - "access": "public" - } + "name": "@storybook/marionette", + "version": "6.0.0-alpha.4", + "description": "Storybook for Marionette: Develop Marionette.js component in isolation with Hot Reloading.", + "keywords": [ + "storybook" + ], + "homepage": "https://github.com/storybookjs/storybook/tree/master/app/marionette", + "bugs": { + "url": "https://github.com/storybookjs/storybook/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/storybookjs/storybook.git", + "directory": "app/marionette" + }, + "license": "MIT", + "main": "dist/client/index.js", + "bin": { + "build-storybook": "./bin/build.js", + "start-storybook": "./bin/index.js", + "storybook-server": "./bin/index.js" + }, + "scripts": { + "prepare": "node ../../scripts/prepare.js" + }, + "dependencies": { + "@storybook/core": "6.0.0-alpha.4", + "common-tags": "^1.8.0", + "core-js": "^3.0.1", + "global": "^4.3.2", + "html-loader": "^0.5.5", + "regenerator-runtime": "^0.12.1" + }, + "devDependencies": { + "backbone.marionette": "*" + }, + "peerDependencies": { + "@babel/core": "*", + "babel-loader": "^7.0.0 || ^8.0.0", + "backbone": "*", + "backbone.marionette": "*", + "react": "*", + "react-dom": "*", + "underscore": "*" + }, + "engines": { + "node": ">=8.0.0" + }, + "publishConfig": { + "access": "public" + } } diff --git a/app/marko/package.json b/app/marko/package.json index 13f9cfb2aad0..a0c9616520dc 100644 --- a/app/marko/package.json +++ b/app/marko/package.json @@ -41,8 +41,12 @@ "ts-dedent": "^1.1.1" }, "peerDependencies": { + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", - "marko": "^4.15.2" + "marko": "^4.15.2", + "react": "*", + "react-dom": "*", + "webpack": "^4" }, "engines": { "node": ">=8.0.0" diff --git a/app/mithril/package.json b/app/mithril/package.json index f639502c51b1..70af28e0e984 100644 --- a/app/mithril/package.json +++ b/app/mithril/package.json @@ -48,8 +48,11 @@ "mithril": "^1.1.6" }, "peerDependencies": { + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", - "mithril": "^1.1.6" + "mithril": "^1.1.6", + "react": "*", + "react-dom": "*" }, "engines": { "node": ">=8.0.0" diff --git a/app/preact/package.json b/app/preact/package.json index 0250770308f1..dcb6a105b706 100644 --- a/app/preact/package.json +++ b/app/preact/package.json @@ -46,9 +46,11 @@ "preact": "^8.4.2" }, "peerDependencies": { - "@babel/core": "7.0.1", + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", - "preact": "^8.4.2" + "preact": "^8.4.2", + "react": "*", + "react-dom": "*" }, "engines": { "node": ">=8.0.0" diff --git a/app/rax/package.json b/app/rax/package.json index a6fc2dea42d5..8ec1480324cd 100644 --- a/app/rax/package.json +++ b/app/rax/package.json @@ -45,8 +45,11 @@ "rax": "^1.1.0" }, "peerDependencies": { + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", - "rax": "^0.4.0 || ^1.0.0" + "rax": "^0.4.0 || ^1.0.0", + "react": "*", + "react-dom": "*" }, "publishConfig": { "access": "public" diff --git a/app/riot/package.json b/app/riot/package.json index 74849f393015..01d2d6f498b7 100644 --- a/app/riot/package.json +++ b/app/riot/package.json @@ -47,11 +47,15 @@ "@babel/preset-react": "^7.7.0" }, "peerDependencies": { + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", "riot": "^3.0.0 || ^4.0.0", "riot-compiler": "^3.5.1 || ^4.0.0", "riot-hot-reload": "^1.0.0", - "riot-tag-loader": "^2.0.0 || ^3.0.0" + "riot-tag-loader": "^2.0.0 || ^3.0.0", + "react": "*", + "react-dom": "*", + "webpack": "*" }, "engines": { "node": ">=8.0.0" diff --git a/app/svelte/package.json b/app/svelte/package.json index fdb349a59a4e..3a545379ceb7 100644 --- a/app/svelte/package.json +++ b/app/svelte/package.json @@ -46,9 +46,12 @@ "svelte-loader": "^2.13.4" }, "peerDependencies": { + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", "svelte": "^3.1.0", - "svelte-loader": "^2.9.1" + "svelte-loader": "^2.9.1", + "react": "*", + "react-dom": "*" }, "engines": { "node": ">=8.0.0" diff --git a/app/vue/package.json b/app/vue/package.json index 3597e7ba17c5..708df2ab475a 100644 --- a/app/vue/package.json +++ b/app/vue/package.json @@ -52,7 +52,11 @@ "vue-template-compiler": "^2.6.8" }, "peerDependencies": { + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", + "css-loader": "*", + "react": "*", + "react-dom": "*", "vue": "^2.6.8", "vue-loader": "^15.7.0", "vue-template-compiler": "^2.6.8" diff --git a/app/web-components/package.json b/app/web-components/package.json index d2b6d8ad3a58..d9e890e560aa 100644 --- a/app/web-components/package.json +++ b/app/web-components/package.json @@ -50,8 +50,11 @@ "lit-html": "^1.0.0" }, "peerDependencies": { + "@babel/core": "*", "babel-loader": "^7.0.0 || ^8.0.0", - "lit-html": "^1.0.0" + "lit-html": "^1.0.0", + "react": "*", + "react-dom": "*" }, "engines": { "node": ">=8.0.0" diff --git a/lib/addons/package.json b/lib/addons/package.json index 757b164533fa..db51d8adce79 100644 --- a/lib/addons/package.json +++ b/lib/addons/package.json @@ -38,6 +38,10 @@ "devDependencies": { "@types/util-deprecate": "^1.0.0" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/lib/api/package.json b/lib/api/package.json index 67069d349613..fb78d6b00537 100644 --- a/lib/api/package.json +++ b/lib/api/package.json @@ -52,6 +52,7 @@ "@types/semver": "^6.0.0" }, "peerDependencies": { + "react-dom": "*", "regenerator-runtime": "*" }, "publishConfig": { diff --git a/lib/client-api/package.json b/lib/client-api/package.json index 2a3829cf42df..866a8bdfb222 100644 --- a/lib/client-api/package.json +++ b/lib/client-api/package.json @@ -45,6 +45,10 @@ "ts-dedent": "^1.1.1", "util-deprecate": "^1.0.2" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" }, diff --git a/lib/core/package.json b/lib/core/package.json index 16d1f32a4a7a..3065f6a89bc4 100644 --- a/lib/core/package.json +++ b/lib/core/package.json @@ -77,6 +77,7 @@ "micromatch": "^4.0.2", "node-fetch": "^2.6.0", "open": "^7.0.1", + "pkg-dir": "^4.2.0", "pnp-webpack-plugin": "1.6.0", "postcss-flexbugs-fixes": "^4.1.0", "postcss-loader": "^3.0.0", diff --git a/lib/core/src/server/build-dev.js b/lib/core/src/server/build-dev.js index c15d87f9da6f..c9798fa2d3d1 100644 --- a/lib/core/src/server/build-dev.js +++ b/lib/core/src/server/build-dev.js @@ -9,7 +9,6 @@ import chalk from 'chalk'; import { logger, colors, instance as npmLog } from '@storybook/node-logger'; import fetch from 'node-fetch'; import Cache from 'file-system-cache'; -import findCacheDir from 'find-cache-dir'; import open from 'open'; import boxen from 'boxen'; import semver from 'semver'; @@ -21,17 +20,17 @@ import detectFreePort from 'detect-port'; import storybook from './dev-server'; import { getDevCli } from './cli'; +import { resolvePathInStorybookCache } from './utils/resolve-path-in-sb-cache'; const defaultFavIcon = require.resolve('./public/favicon.ico'); -const cacheDir = findCacheDir({ name: 'storybook' }); const cache = Cache({ - basePath: cacheDir, + basePath: resolvePathInStorybookCache('dev-server'), ns: 'storybook', // Optional. A grouping namespace for items. }); const writeStats = async (name, stats) => { await fs.writeFile( - path.join(cacheDir, `${name}-stats.json`), + resolvePathInStorybookCache(`${name}-stats.json`), JSON.stringify(stats.toJson(), null, 2), 'utf8' ); @@ -231,7 +230,7 @@ async function outputStats(previewStats, managerStats) { await writeStats('preview', previewStats); } await writeStats('manager', managerStats); - logger.info(`stats written to => ${chalk.cyan(path.join(cacheDir, '[name].json'))}`); + logger.info(`stats written to => ${chalk.cyan(resolvePathInStorybookCache('[name].json'))}`); } function openInBrowser(address) { diff --git a/lib/core/src/server/common/babel-cache-preset.js b/lib/core/src/server/common/babel-cache-preset.js index a5b798468132..2dac4ff30867 100644 --- a/lib/core/src/server/common/babel-cache-preset.js +++ b/lib/core/src/server/common/babel-cache-preset.js @@ -1,10 +1,9 @@ -import findCacheDir from 'find-cache-dir'; +import { resolvePathInStorybookCache } from '../utils/resolve-path-in-sb-cache'; const extend = babelConfig => ({ // This is a feature of `babel-loader` for webpack (not Babel itself). // It enables a cache directory for faster-rebuilds - // `find-cache-dir` will create the cache directory under the node_modules directory. - cacheDirectory: findCacheDir({ name: 'storybook' }), + cacheDirectory: resolvePathInStorybookCache('babel'), ...babelConfig, }); diff --git a/lib/core/src/server/dev-server.js b/lib/core/src/server/dev-server.js index 4a49a1a6d3ca..36b2eaa09788 100644 --- a/lib/core/src/server/dev-server.js +++ b/lib/core/src/server/dev-server.js @@ -10,6 +10,7 @@ import { getMiddleware } from './utils/middleware'; import { logConfig } from './logConfig'; import loadConfig from './config'; import loadManagerConfig from './manager/manager-config'; +import { resolvePathInStorybookCache } from './utils/resolve-path-in-sb-cache'; const dllPath = path.join(__dirname, '../../dll'); @@ -23,7 +24,7 @@ const router = new Router(); export default function(options) { const configDir = path.resolve(options.configDir); - const outputDir = path.resolve(options.outputDir || path.join(__dirname, '..', 'public')); + const outputDir = path.resolve(options.outputDir || resolvePathInStorybookCache('public')); const configType = 'DEVELOPMENT'; const startTime = process.hrtime(); diff --git a/lib/core/src/server/manager/manager-webpack.config.js b/lib/core/src/server/manager/manager-webpack.config.js index 8516d389317d..32ab49ef0768 100644 --- a/lib/core/src/server/manager/manager-webpack.config.js +++ b/lib/core/src/server/manager/manager-webpack.config.js @@ -4,20 +4,19 @@ import Dotenv from 'dotenv-webpack'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import CoreJSUpgradeWebpackPlugin from 'corejs-upgrade-webpack-plugin'; +import PnpWebpackPlugin from 'pnp-webpack-plugin'; import themingPaths from '@storybook/theming/paths'; import uiPaths from '@storybook/ui/paths'; -import findCacheDir from 'find-cache-dir'; - import { version } from '../../../package.json'; import { getManagerHeadHtml } from '../utils/template'; import { loadEnv } from '../config/utils'; import babelLoader from '../common/babel-loader'; +import { resolvePathInStorybookCache } from '../utils/resolve-path-in-sb-cache'; const coreDirName = path.dirname(require.resolve('@storybook/core/package.json')); const context = path.join(coreDirName, '../../node_modules'); -const cacheDir = findCacheDir({ name: 'storybook' }); export default ({ configDir, @@ -123,8 +122,15 @@ export default ({ ...themingPaths, ...uiPaths, }, + plugins: [ + // Transparently resolve packages via PnP when needed; noop otherwise + PnpWebpackPlugin, + ], + }, + resolveLoader: { + plugins: [PnpWebpackPlugin.moduleLoader(module)], }, - recordsPath: path.join(cacheDir, 'records.json'), + recordsPath: resolvePathInStorybookCache('records.json'), performance: { hints: false, }, diff --git a/lib/core/src/server/preview/iframe-webpack.config.js b/lib/core/src/server/preview/iframe-webpack.config.js index 180f35af3394..fdd7aa9c30ac 100644 --- a/lib/core/src/server/preview/iframe-webpack.config.js +++ b/lib/core/src/server/preview/iframe-webpack.config.js @@ -10,6 +10,7 @@ import VirtualModulePlugin from 'webpack-virtual-modules'; import resolveFrom from 'resolve-from'; +import PnpWebpackPlugin from 'pnp-webpack-plugin'; import createBabelLoader from '../common/babel-loader'; import { nodeModulesPaths, loadEnv } from '../config/utils'; import { getPreviewHeadHtml, getPreviewBodyHtml } from '../utils/template'; @@ -108,6 +109,14 @@ export default ({ 'babel-runtime/core-js/object/assign': require.resolve('core-js/es/object/assign'), ...reactPaths, }, + + plugins: [ + // Transparently resolve packages via PnP when needed; noop otherwise + PnpWebpackPlugin, + ], + }, + resolveLoader: { + plugins: [PnpWebpackPlugin.moduleLoader(module)], }, optimization: { splitChunks: { diff --git a/lib/core/src/server/utils/resolve-path-in-sb-cache.js b/lib/core/src/server/utils/resolve-path-in-sb-cache.js new file mode 100644 index 000000000000..c4ea135606fb --- /dev/null +++ b/lib/core/src/server/utils/resolve-path-in-sb-cache.js @@ -0,0 +1,25 @@ +import path from 'path'; +import pkgDir from 'pkg-dir'; + +/** + * Get the path of the file or directory with input name inside the Storybook cache directory: + * - `node_modules/.cache/storybook/{directoryName}` in a Node.js project or npm package + * - `.cache/storybook/{directoryName}` otherwise + * + * @param fileOrDirectoryName {string} Name of the file or directory + * @return {string} Absolute path to the file or directory + */ +export function resolvePathInStorybookCache(fileOrDirectoryName) { + const cwd = process.cwd(); + const projectDir = pkgDir.sync(cwd); + + let cacheDirectory; + + if (!projectDir) { + cacheDirectory = path.resolve(cwd, '.cache/storybook'); + } else { + cacheDirectory = path.resolve(projectDir, 'node_modules/.cache/storybook'); + } + + return path.join(cacheDirectory, fileOrDirectoryName); +} diff --git a/lib/source-loader/package.json b/lib/source-loader/package.json index 478db98babb8..c65720a1d2c4 100644 --- a/lib/source-loader/package.json +++ b/lib/source-loader/package.json @@ -39,6 +39,10 @@ "prop-types": "^15.7.2", "regenerator-runtime": "^0.13.3" }, + "peerDependencies": { + "react-dom": "*", + "regenerator-runtime": "*" + }, "publishConfig": { "access": "public" },