Skip to content

Commit

Permalink
Core: Add sbmodern package export, drop modern to chrome 79+
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed May 17, 2021
1 parent 5ceb87e commit 74863b7
Show file tree
Hide file tree
Showing 39 changed files with 77 additions and 35 deletions.
5 changes: 4 additions & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const withTests = {
// type BabelMode = 'cjs' | 'esm' | 'modern';

const modules = process.env.BABEL_MODE === 'cjs' ? 'auto' : false;
const targets = process.env.BABEL_MODE === 'modern' ? { chrome: '80' } : 'defaults';

// FIXME: optional chaining introduced in chrome 80, not supported by wepback4
// https://github.com/webpack/webpack/issues/10227#issuecomment-642734920
const targets = process.env.BABEL_MODE === 'modern' ? { chrome: '79' } : 'defaults';

module.exports = {
ignore: [
Expand Down
1 change: 1 addition & 0 deletions addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js",
"storybook": {
"displayName": "Accessibility",
"icon": "https://user-images.githubusercontent.com/263385/101991665-47042f80-3c7c-11eb-8f00-64b5a18f498a.png",
Expand Down
1 change: 1 addition & 0 deletions addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js",
"storybook": {
"displayName": "Actions",
"unsupportedFrameworks": [
Expand Down
1 change: 1 addition & 0 deletions addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js",
"storybook": {
"displayName": "Backgrounds",
"icon": "https://user-images.githubusercontent.com/263385/101991667-479cc600-3c7c-11eb-96d3-410e936252e7.png",
Expand Down
1 change: 1 addition & 0 deletions addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js",
"storybook": {
"displayName": "Docs",
"icon": "https://user-images.githubusercontent.com/263385/101991672-48355c80-3c7c-11eb-82d9-95fa12438f64.png",
Expand Down
3 changes: 2 additions & 1 deletion addons/essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
1 change: 1 addition & 0 deletions addons/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js",
"storybook": {
"displayName": "Jest",
"icon": "https://pbs.twimg.com/profile_images/821713465245102080/mMtKIMax_400x400.jpg",
Expand Down
1 change: 1 addition & 0 deletions addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js",
"storybook": {
"displayName": "Links",
"icon": "https://user-images.githubusercontent.com/263385/101991673-48355c80-3c7c-11eb-9b6e-b627c96a75f6.png",
Expand Down
1 change: 1 addition & 0 deletions addons/storysource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js",
"storybook": {
"displayName": "Storysource",
"icon": "https://user-images.githubusercontent.com/263385/101991675-48cdf300-3c7c-11eb-9400-58de5ac6daa7.png",
Expand Down
3 changes: 2 additions & 1 deletion lib/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/builder-webpack4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/builder-webpack4/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default async ({
frameworkPath,
presets,
typescriptOptions,
modern,
}: Options & Record<string, any>): Promise<Configuration> => {
const logLevel = await presets.apply('logLevel', undefined);
const frameworkOptions = await presets.apply(`${framework}Options`, {});
Expand Down Expand Up @@ -194,7 +195,7 @@ export default async ({
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
modules: ['node_modules'].concat(envs.NODE_PATH || []),
mainFields: ['browser', 'module', 'main'],
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
alias: {
...themingPaths,
...storybookPaths,
Expand Down
3 changes: 2 additions & 1 deletion lib/builder-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default async ({
frameworkPath,
presets,
typescriptOptions,
modern,
}: Options & Record<string, any>): Promise<Configuration> => {
const envs = await presets.apply<Record<string, string>>('env');
const logLevel = await presets.apply('logLevel', undefined);
Expand Down Expand Up @@ -190,7 +191,7 @@ export default async ({
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.json', '.cjs'],
modules: ['node_modules'].concat(envs.NODE_PATH || []),
mainFields: ['browser', 'module', 'main'],
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
alias: {
...themingPaths,
...storybookPaths,
Expand Down
3 changes: 2 additions & 1 deletion lib/channel-postmessage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/channel-websocket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/channels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/client-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/client-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/core-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
1 change: 1 addition & 0 deletions lib/core-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface CLIOptions {
debugWebpack?: boolean;
webpackStatsJson?: string | boolean;
outputDir?: string;
modern?: boolean;
}

export interface BuilderOptions {
Expand Down
3 changes: 2 additions & 1 deletion lib/core-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
1 change: 1 addition & 0 deletions lib/core-server/src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function getDevCli(packageJson: {
'Disables the default storybook preview and lets your use your own'
)
.option('--docs', 'Build a documentation-only site using addon-docs')
.option('--modern', 'Use modern browser modules')
.parse(process.argv);

logger.setLevel(program.loglevel);
Expand Down
2 changes: 2 additions & 0 deletions lib/core-server/src/cli/prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ProdCliOptions {
debugWebpack?: boolean;
previewUrl?: string;
docs?: boolean;
modern?: boolean;
}

export function getProdCli(packageJson: {
Expand All @@ -42,6 +43,7 @@ export function getProdCli(packageJson: {
'Disables the default storybook preview and lets your use your own'
)
.option('--docs', 'Build a documentation-only site using addon-docs')
.option('--modern', 'Use modern browser modules')
.parse(process.argv);

logger.setLevel(program.loglevel);
Expand Down
3 changes: 2 additions & 1 deletion lib/core-server/src/manager/manager-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default async ({
versionCheck,
releaseNotesData,
presets,
modern,
}: Options & ManagerWebpackOptions): Promise<Configuration> => {
const envs = await presets.apply<Record<string, string>>('env');
const logLevel = await presets.apply('logLevel', undefined);
Expand Down Expand Up @@ -153,7 +154,7 @@ export default async ({
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.json', '.cjs', '.ts', '.tsx'],
modules: ['node_modules'].concat(envs.NODE_PATH || []),
mainFields: ['browser', 'module', 'main'],
mainFields: [modern ? 'sbmodern' : null, 'browser', 'module', 'main'].filter(Boolean),
alias: {
...themingPaths,
...uiPaths,
Expand Down
9 changes: 5 additions & 4 deletions lib/core-server/src/presets/common-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export const previewMainTemplate = () => getPreviewMainTemplate();

export const managerMainTemplate = () => getManagerMainTemplate();

export const previewEntries = () => [
require.resolve('../globals/polyfills'),
require.resolve('../globals/globals'),
];
export const previewEntries = (entries: any[] = [], options: { modern?: boolean }) => {
if (!options.modern) entries.push(require.resolve('../globals/polyfills'));
entries.push(require.resolve('../globals/globals'));
return entries;
};

export const typescript = () => ({
check: false,
Expand Down
4 changes: 2 additions & 2 deletions lib/core-server/src/presets/manager-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export async function managerWebpack(

export async function managerEntries(
installedAddons: string[],
options: { managerEntry: string; configDir: string }
options: { managerEntry: string; configDir: string; modern?: boolean }
): Promise<string[]> {
const { managerEntry = '@storybook/core-client/dist/esm/manager' } = options;
const entries = [require.resolve('../globals/polyfills')];
const entries = options.modern ? [] : [require.resolve('../globals/polyfills')];

if (installedAddons && installedAddons.length) {
entries.push(...installedAddons);
Expand Down
3 changes: 2 additions & 1 deletion lib/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/node-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/postinstall/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/source-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/theming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
3 changes: 2 additions & 1 deletion lib/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@
"publishConfig": {
"access": "public"
},
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241"
"gitHead": "2f7423e38558228c3b5b09a3afc5047ac3523241",
"sbmodern": "dist/modern/index.js"
}
8 changes: 5 additions & 3 deletions scripts/utils/compile-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ async function babelify(options = {}) {
run({ watch, dir: './dist/modern', silent, errorCallback }),
]);
} else {
await run({ dir: './dist/cjs', silent, errorCallback });
await run({ dir: './dist/esm', silent, errorCallback });
await run({ dir: './dist/modern', silent, errorCallback });
await Promise.all([
run({ dir: './dist/cjs', silent, errorCallback }),
run({ dir: './dist/esm', silent, errorCallback }),
run({ dir: './dist/modern', silent, errorCallback }),
]);
}
}

Expand Down

0 comments on commit 74863b7

Please sign in to comment.