Skip to content

Commit

Permalink
Merge pull request #21535 from storybookjs/norbert/enable-wrapforpnp-…
Browse files Browse the repository at this point in the history
…again

Fix: vite dev and yarn pnp + vite by unreverting and adding lodash files to optimizeDeps.include
  • Loading branch information
ndelangen authored Mar 15, 2023
2 parents 808e26d + 68e78f0 commit 0b6f67b
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 83 deletions.
8 changes: 4 additions & 4 deletions code/frameworks/angular/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from 'path';
import { dirname, join } from 'path';
import { PresetProperty } from '@storybook/types';
import { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
require.resolve('./server/framework-preset-angular-cli'),
require.resolve('./server/framework-preset-angular-ivy'),
Expand All @@ -19,9 +21,7 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
};
Expand Down
8 changes: 4 additions & 4 deletions code/frameworks/ember/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
require.resolve('./server/framework-preset-babel-ember'),
require.resolve('./server/framework-preset-ember-docs'),
Expand All @@ -13,9 +15,7 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
};
Expand Down
12 changes: 6 additions & 6 deletions code/frameworks/html-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
path.dirname(require.resolve(path.join('@storybook/preset-html-webpack', 'package.json'))),
wrapForPnP('@storybook/preset-html-webpack'),
];

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
Expand All @@ -12,11 +14,9 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
renderer: path.dirname(require.resolve(path.join('@storybook/html', 'package.json'))),
renderer: wrapForPnP('@storybook/html'),
};
};
12 changes: 6 additions & 6 deletions code/frameworks/preact-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
path.dirname(require.resolve(path.join('@storybook/preset-preact-webpack', 'package.json'))),
wrapForPnP('@storybook/preset-preact-webpack'),
];

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
Expand All @@ -12,11 +14,9 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
renderer: path.dirname(require.resolve(path.join('@storybook/preact', 'package.json'))),
renderer: wrapForPnP('@storybook/preact'),
};
};
7 changes: 5 additions & 2 deletions code/frameworks/react-vite/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-disable global-require */
import type { PresetProperty } from '@storybook/types';
import { hasVitePlugins } from '@storybook/builder-vite';
import { dirname, join } from 'path';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const core: PresetProperty<'core', StorybookConfig> = {
builder: '@storybook/builder-vite',
renderer: '@storybook/react',
builder: wrapForPnP('@storybook/builder-vite') as '@storybook/builder-vite',
renderer: wrapForPnP('@storybook/react'),
};

export const viteFinal: StorybookConfig['viteFinal'] = async (config, { presets }) => {
Expand Down
18 changes: 8 additions & 10 deletions code/frameworks/react-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-disable no-param-reassign */

import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty, Options } from '@storybook/types';
import type { FrameworkOptions, StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
path.dirname(require.resolve(path.join('@storybook/preset-react-webpack', 'package.json'))),
wrapForPnP('@storybook/preset-react-webpack'),
];

const defaultFrameworkOptions: FrameworkOptions = {
Expand All @@ -26,7 +28,7 @@ export const frameworkOptions = async (
}
if (typeof config === 'undefined') {
return {
name: require.resolve('@storybook/react-webpack5') as '@storybook/react-webpack5',
name: wrapForPnP('@storybook/react-webpack5') as '@storybook/react-webpack5',
options: defaultFrameworkOptions,
};
}
Expand All @@ -46,12 +48,10 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
renderer: path.dirname(require.resolve(path.join('@storybook/react', 'package.json'))),
renderer: wrapForPnP('@storybook/react'),
};
};

Expand All @@ -60,9 +60,7 @@ export const webpack: StorybookConfig['webpack'] = async (config) => {

config.resolve.alias = {
...config.resolve?.alias,
'@storybook/react': path.dirname(
require.resolve(path.join('@storybook/react', 'package.json'))
),
'@storybook/react': wrapForPnP('@storybook/react'),
};
return config;
};
12 changes: 6 additions & 6 deletions code/frameworks/server-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
path.dirname(require.resolve(path.join('@storybook/preset-server-webpack', 'package.json'))),
wrapForPnP('@storybook/preset-server-webpack'),
];

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
Expand All @@ -12,11 +14,9 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
renderer: path.dirname(require.resolve(path.join('@storybook/server', 'package.json'))),
renderer: wrapForPnP('@storybook/server'),
};
};
12 changes: 6 additions & 6 deletions code/frameworks/svelte-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
path.dirname(require.resolve(path.join('@storybook/preset-svelte-webpack', 'package.json'))),
wrapForPnP('@storybook/preset-svelte-webpack'),
];

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
Expand All @@ -12,11 +14,9 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
renderer: path.dirname(require.resolve(path.join('@storybook/svelte', 'package.json'))),
renderer: wrapForPnP('@storybook/svelte'),
};
};
12 changes: 6 additions & 6 deletions code/frameworks/vue-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
path.dirname(require.resolve(path.join('@storybook/preset-vue-webpack', 'package.json'))),
wrapForPnP('@storybook/preset-vue-webpack'),
];

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
Expand All @@ -12,12 +14,10 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
renderer: path.dirname(require.resolve(path.join('@storybook/vue', 'package.json'))),
renderer: wrapForPnP('@storybook/vue'),
};
};

Expand Down
12 changes: 6 additions & 6 deletions code/frameworks/vue3-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
path.dirname(require.resolve(path.join('@storybook/preset-vue3-webpack', 'package.json'))),
wrapForPnP('@storybook/preset-vue3-webpack'),
];

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
Expand All @@ -12,12 +14,10 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
renderer: path.dirname(require.resolve(path.join('@storybook/vue3', 'package.json'))),
renderer: wrapForPnP('@storybook/vue3'),
};
};

Expand Down
14 changes: 6 additions & 8 deletions code/frameworks/web-components-webpack5/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path';
import { dirname, join } from 'path';
import type { PresetProperty } from '@storybook/types';
import type { StorybookConfig } from './types';

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

export const addons: PresetProperty<'addons', StorybookConfig> = [
path.dirname(
require.resolve(path.join('@storybook/preset-web-components-webpack', 'package.json'))
),
wrapForPnP('@storybook/preset-web-components-webpack'),
];

export const core: PresetProperty<'core', StorybookConfig> = async (config, options) => {
Expand All @@ -14,11 +14,9 @@ export const core: PresetProperty<'core', StorybookConfig> = async (config, opti
return {
...config,
builder: {
name: path.dirname(
require.resolve(path.join('@storybook/builder-webpack5', 'package.json'))
) as '@storybook/builder-webpack5',
name: wrapForPnP('@storybook/builder-webpack5') as '@storybook/builder-webpack5',
options: typeof framework === 'string' ? {} : framework.options.builder || {},
},
renderer: path.dirname(require.resolve(path.join('@storybook/web-components', 'package.json'))),
renderer: wrapForPnP('@storybook/web-components'),
};
};
6 changes: 4 additions & 2 deletions code/lib/builder-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export * from './types';
*/
export type StorybookViteConfig = StorybookBaseConfig & StorybookConfigVite;

const wrapForPnP = (input: string) => dirname(require.resolve(join(input, 'package.json')));

function iframeMiddleware(options: Options, server: ViteDevServer): RequestHandler {
return async (req, res, next) => {
if (!req.url.match(/^\/iframe\.html($|\?)/)) {
Expand Down Expand Up @@ -64,7 +66,7 @@ export const start: ViteBuilder['start'] = async ({
}) => {
server = await createViteServer(options as Options, devServer);

const previewResolvedDir = dirname(require.resolve('@storybook/preview/package.json'));
const previewResolvedDir = wrapForPnP('@storybook/preview');
const previewDirOrigin = join(previewResolvedDir, 'dist');

router.use(`/sb-preview`, express.static(previewDirOrigin, { immutable: true, maxAge: '5m' }));
Expand All @@ -82,7 +84,7 @@ export const start: ViteBuilder['start'] = async ({
export const build: ViteBuilder['build'] = async ({ options }) => {
const viteCompilation = viteBuild(options as Options);

const previewResolvedDir = dirname(require.resolve('@storybook/preview/package.json'));
const previewResolvedDir = wrapForPnP('@storybook/preview');
const previewDirOrigin = join(previewResolvedDir, 'dist');
const previewDirTarget = join(options.outputDir || '', `sb-preview`);

Expand Down
27 changes: 27 additions & 0 deletions code/lib/builder-vite/src/optimizeDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,44 @@ const INCLUDE_CANDIDATES = [
'isobject',
'jest-mock',
'loader-utils',
'lodash/camelCase.js',
'lodash/camelCase',
'lodash/cloneDeep.js',
'lodash/cloneDeep',
'lodash/countBy.js',
'lodash/countBy',
'lodash/debounce.js',
'lodash/debounce',
'lodash/isEqual.js',
'lodash/isEqual',
'lodash/isFunction.js',
'lodash/isFunction',
'lodash/isPlainObject.js',
'lodash/isPlainObject',
'lodash/isString.js',
'lodash/isString',
'lodash/kebabCase.js',
'lodash/kebabCase',
'lodash/mapKeys.js',
'lodash/mapKeys',
'lodash/mapValues.js',
'lodash/mapValues',
'lodash/merge.js',
'lodash/merge',
'lodash/mergeWith.js',
'lodash/mergeWith',
'lodash/pick.js',
'lodash/pick',
'lodash/pickBy.js',
'lodash/pickBy',
'lodash/startCase.js',
'lodash/startCase',
'lodash/throttle.js',
'lodash/throttle',
'lodash/uniq.js',
'lodash/uniq',
'lodash/upperFirst.js',
'lodash/upperFirst',
'markdown-to-jsx',
'memoizerific',
'overlayscrollbars',
Expand Down
Loading

0 comments on commit 0b6f67b

Please sign in to comment.