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

[WIP] Refactor core and frameworks to work with presets #4043

Merged
merged 19 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/angular/src/server/framework-preset-angular-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { logger } from '@storybook/node-logger';

import {
getAngularCliWebpackConfigOptions,
applyAngularCliWebpackConfig,
} from './angular-cli_config';

function extendWebpack(config) {
const cwd = process.cwd();
const cliWebpackConfigOptions = getAngularCliWebpackConfigOptions(cwd);

if (cliWebpackConfigOptions) {
logger.info('=> Loading angular-cli config.');
}

return applyAngularCliWebpackConfig(config, cliWebpackConfigOptions);
}

export default {
extendWebpack,
};
54 changes: 54 additions & 0 deletions app/angular/src/server/framework-preset-angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import path from 'path';
import { ContextReplacementPlugin } from 'webpack';
import loadTsConfig from './ts_config';

function extendWebpack(config, { configDir }) {
return {
...config,
module: {
...config.module,
rules: [
...config.module.rules,
{
test: /\.tsx?$/,
use: [
{
loader: require.resolve('ts-loader'),
options: loadTsConfig(configDir),
},
require.resolve('angular2-template-loader'),
],
},
{
test: /[/\\]@angular[/\\]core[/\\].+\.js$/,
parser: { system: true },
},
{
test: /\.html$/,
loader: 'raw-loader',
exclude: /\.async\.html$/,
},
{
test: /\.scss$/,
use: [require.resolve('raw-loader'), require.resolve('sass-loader')],
},
],
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.ts', '.tsx'],
},
plugins: [
...config.plugins,
// See https://github.com/angular/angular/issues/11580#issuecomment-401127742
new ContextReplacementPlugin(
/@angular(\\|\/)core(\\|\/)fesm5/,
path.resolve(__dirname, '..')
),
],
};
}

export default {
extendWebpack,
};
22 changes: 4 additions & 18 deletions app/angular/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import { logger } from '@storybook/node-logger';

import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

import {
getAngularCliWebpackConfigOptions,
applyAngularCliWebpackConfig,
} from './angular-cli_config';

const cliWebpackConfigOptions = getAngularCliWebpackConfigOptions(process.cwd());

if (cliWebpackConfigOptions) {
logger.info('=> Loading angular-cli config.');
}

export default {
packageJson,
defaultConfigName: 'angular-cli',
wrapInitialConfig,
wrapDefaultConfig: config => applyAngularCliWebpackConfig(config, cliWebpackConfigOptions),
wrapBasicConfig: config => applyAngularCliWebpackConfig(config, cliWebpackConfigOptions),
frameworkPresets: [
require.resolve('./framework-preset-angular.js'),
require.resolve('./framework-preset-angular-cli.js'),
],
};
45 changes: 0 additions & 45 deletions app/angular/src/server/wrapInitialConfig.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default config => ({
const extendWebpack = config => ({
...config,
module: {
...config.module,
Expand All @@ -15,3 +15,7 @@ export default config => ({
],
},
});

export default {
extendWebpack,
};
4 changes: 1 addition & 3 deletions app/html/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

export default {
packageJson,
wrapInitialConfig,
frameworkPresets: [require.resolve('./framework-preset-html.js')],
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default config => ({
const extendWebpack = config => ({
...config,
module: {
...config.module,
Expand All @@ -15,3 +15,7 @@ export default config => ({
extensions: [...config.resolve.extensions, '.marko'],
},
});

export default {
extendWebpack,
};
4 changes: 1 addition & 3 deletions app/marko/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

export default {
packageJson,
wrapInitialConfig,
frameworkPresets: [require.resolve('./framework-preset-marko.js')],
};
13 changes: 13 additions & 0 deletions app/mithril/src/server/framework-preset-mithril.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mergeBabel } from '@storybook/core/server';

function extendBabel(config) {
const patch = {
plugins: [require.resolve('@babel/plugin-transform-react-jsx')],
};

return mergeBabel(patch, config);
}

export default {
extendBabel,
};
4 changes: 1 addition & 3 deletions app/mithril/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapDefaultBabelConfig from './wrapDefaultBabelConfig';

export default {
packageJson,
wrapDefaultBabelConfig,
frameworkPresets: [require.resolve('./framework-preset-mithril.js')],
};
4 changes: 0 additions & 4 deletions app/mithril/src/server/wrapDefaultBabelConfig.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IgnorePlugin } from 'webpack';

export default config => ({
const extendWebpack = config => ({
...config,
module: {
...config.module,
Expand All @@ -24,3 +24,7 @@ export default config => ({
new IgnorePlugin(/^vertx$/),
],
});

export default {
extendWebpack,
};
4 changes: 1 addition & 3 deletions app/polymer/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

export default {
packageJson,
wrapInitialConfig,
frameworkPresets: [require.resolve('./framework-preset-polymer.js')],
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function(config) {
function extendBabel(config) {
// Ensure plugins are defined or fallback to an array to avoid empty values.
const babelConfigPlugins = config.plugins || [];

Expand All @@ -18,3 +18,7 @@ export default function(config) {
plugins: [].concat(babelConfigPlugins, extraPlugins),
};
}

export default {
extendBabel,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import wrapBabelConfig from './wrapBabelConfig';
import preset from './framework-preset-react-docgen';

describe('babel_config', () => {
describe('framework-preset-react-docgen', () => {
const babelPluginReactDocgenPath = require.resolve('babel-plugin-react-docgen');

it('should return the config with the extra plugins when `plugins` is an array.', () => {
Expand All @@ -10,7 +10,7 @@ describe('babel_config', () => {
plugins: ['foo-plugin'],
};

const config = wrapBabelConfig(babelConfig);
const config = preset.extendBabel(babelConfig);

expect(config).toEqual({
babelrc: false,
Expand All @@ -34,7 +34,7 @@ describe('babel_config', () => {
plugins: 'bar-plugin',
};

const config = wrapBabelConfig(babelConfig);
const config = preset.extendBabel(babelConfig);

expect(config).toEqual({
babelrc: false,
Expand All @@ -57,7 +57,7 @@ describe('babel_config', () => {
presets: ['env', 'foo-preset'],
};

const config = wrapBabelConfig(babelConfig);
const config = preset.extendBabel(babelConfig);

expect(config).toEqual({
babelrc: false,
Expand Down
13 changes: 13 additions & 0 deletions app/react/src/server/framework-preset-react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { mergeBabel } from '@storybook/core/server';

function extendBabel(config) {
const patch = {
presets: [require.resolve('@babel/preset-react'), require.resolve('@babel/preset-flow')],
};

return mergeBabel(patch, config);
}

export default {
extendBabel,
};
9 changes: 4 additions & 5 deletions app/react/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import packageJson from '../../package.json';

import wrapBabelConfig from './wrapBabelConfig';
import wrapDefaultBabelConfig from './wrapDefaultBabelConfig';

export default {
packageJson,
defaultConfigName: 'create-react-app',
wrapDefaultBabelConfig,
wrapBabelConfig,
frameworkPresets: [
require.resolve('./framework-preset-react.js'),
require.resolve('./framework-preset-react-docgen.js'),
],
};
8 changes: 0 additions & 8 deletions app/react/src/server/wrapDefaultBabelConfig.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default config => ({
const extendWebpack = config => ({
...config,
module: {
...config.module,
Expand All @@ -15,3 +15,7 @@ export default config => ({
],
},
});

export default {
extendWebpack,
};
4 changes: 1 addition & 3 deletions app/riot/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

export default {
packageJson,
wrapInitialConfig,
frameworkPresets: [require.resolve('./framework-preset-riot.js')],
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default config => ({
const extendWebpack = config => ({
...config,
module: {
...config.module,
Expand All @@ -17,3 +17,7 @@ export default config => ({
alias: config.resolve.alias,
},
});

export default {
extendWebpack,
};
4 changes: 1 addition & 3 deletions app/svelte/src/server/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import packageJson from '../../package.json';

import wrapInitialConfig from './wrapInitialConfig';

export default {
packageJson,
wrapInitialConfig,
frameworkPresets: [require.resolve('./framework-preset-svelte.js')],
};
Loading