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

Core separate manager from preview #4590

Merged
merged 37 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dc81f41
Merge branch 'tech/terminal-update-check' into core/separate-manager-…
ndelangen Oct 12, 2018
8c26689
Merge branch 'tech/reapply-html-plugin' into core/separate-manager-fr…
ndelangen Oct 12, 2018
ee2c86e
WIP
ndelangen Oct 12, 2018
a6ce842
WIP
ndelangen Oct 12, 2018
3861fed
Not sure we actually need this, but in the case of a timeout on the f…
ndelangen Oct 12, 2018
d68a106
Merge branch 'master' into core/separate-manager-from-preview
ndelangen Oct 24, 2018
d09ff40
FIX versions
ndelangen Oct 24, 2018
0120686
EXTRACT build of manager into it's own process
ndelangen Oct 24, 2018
750831c
FIX broken build-static - now also has manager in child_process
ndelangen Oct 25, 2018
e2f6220
REFACTOR
ndelangen Oct 26, 2018
def95df
FIX angular && REFACTOR
ndelangen Oct 26, 2018
6fcf4f4
ADD --quiet to not overflow the CI logs
ndelangen Oct 26, 2018
2aad28a
Merge branch 'master' into core/separate-manager-from-preview
ndelangen Oct 26, 2018
f16b2b6
FIX snapshots
ndelangen Oct 26, 2018
5a64f33
WIP
ndelangen Oct 26, 2018
0477097
FIX outputDir
ndelangen Oct 26, 2018
baed105
REFACTOR
ndelangen Oct 26, 2018
27f096d
FIX attempt
ndelangen Oct 27, 2018
3a0f9c9
Fix paths to the renamed presets
igor-dv Oct 28, 2018
76a8660
Remove unneeded extensions from the manager-preset.js
igor-dv Oct 28, 2018
78dd706
Extract manager-config out to the manager dir + use custom-presets in…
igor-dv Oct 28, 2018
d20e8c6
Fox performance.hints issue
igor-dv Oct 28, 2018
a0a2bdf
babel-preset-minify is a preset, not a plugin =)
igor-dv Oct 28, 2018
c962d90
Fix warning in angular.
igor-dv Oct 28, 2018
d53e597
Temp fix for RIOT
igor-dv Oct 28, 2018
042d3bb
Merge remote-tracking branch 'origin/master' into core/separate-manag…
igor-dv Nov 3, 2018
0e01e76
Remove the unneeded comment
igor-dv Nov 3, 2018
73834fc
Merge remote-tracking branch 'origin/master' into core/separate-manag…
igor-dv Nov 5, 2018
825719a
Merge remote-tracking branch 'origin/next' into core/separate-manager…
igor-dv Nov 5, 2018
611a846
Merge remote-tracking branch 'origin/next' into core/separate-manager…
igor-dv Nov 6, 2018
1767405
Remove "quiet" from RN smoke tests - quiet is not supported there
igor-dv Nov 6, 2018
4d54763
Merge remote-tracking branch 'origin/next' into core/separate-manager…
igor-dv Nov 6, 2018
0f29f20
Merge branch 'next' into core/separate-manager-from-preview
ndelangen Nov 9, 2018
31e46a3
FIX the babel6 test
ndelangen Nov 9, 2018
7cd91d4
Merge branch 'next' into core/separate-manager-from-preview
ndelangen Nov 9, 2018
e93d9f3
FIX chromatic by removing some index.html files and correcting the lo…
ndelangen Nov 10, 2018
1f29e4c
Merge branch 'next' into core/separate-manager-from-preview
ndelangen Nov 12, 2018
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
53 changes: 0 additions & 53 deletions .babelrc

This file was deleted.

46 changes: 46 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module.exports = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not it be babel.config.js ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this from here:
https://babeljs.io/docs/en/config-files

Seems to work..

presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-flow'],
plugins: [
'babel-plugin-emotion',
'babel-plugin-macros',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
[
'@babel/plugin-transform-runtime',
{
regenerator: true,
},
],
],
env: {
test: {
plugins: ['babel-plugin-require-context-hook'],
},
},
overrides: [
{
test: './examples/vue-kitchen-sink',
presets: ['@babel/preset-env', 'babel-preset-vue'],
},
{
test: [
'./lib/core/src/server',
'./lib/node-logger',
'./lib/codemod',
'./addons/storyshots',
'./addons/storysource/src/loader',
'./app/**/src/server/**',
],
presets: [
[
'@babel/preset-env',
{
targets: {
node: '8.11',
},
},
],
],
},
],
};
8 changes: 3 additions & 5 deletions app/angular/src/server/angular-cli_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ export function applyAngularCliWebpackConfig(baseConfig, cliWebpackConfigOptions
const rulesExcludingStyles = filterOutStylingRules(baseConfig);

// cliStyleConfig.entry adds global style files to the webpack context
const entry = {
const entry = [
...baseConfig.entry,
iframe: []
.concat(baseConfig.entry.iframe)
.concat(Object.values(cliStyleConfig.entry).reduce((acc, item) => acc.concat(item), [])),
};
...Object.values(cliStyleConfig.entry).reduce((acc, item) => acc.concat(item), []),
];

const module = {
...baseConfig.module,
Expand Down
4 changes: 2 additions & 2 deletions app/angular/src/server/framework-preset-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export function webpack(config, { configDir }) {
},
resolve: {
...config.resolve,
extensions: [...config.resolve.extensions, '.ts', '.tsx'],
extensions: ['.ts', '.tsx', ...config.resolve.extensions],
},
plugins: [
...config.plugins,
// See https://github.com/angular/angular/issues/11580#issuecomment-401127742
new ContextReplacementPlugin(
/@angular(\\|\/)core(\\|\/)fesm5/,
/@angular(\\|\/)core(\\|\/)(fesm5|bundles)/,
path.resolve(__dirname, '..')
),
createForkTsCheckerInstance(tsLoaderOptions),
Expand Down
2 changes: 1 addition & 1 deletion app/react-native/src/server/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import webpack from 'webpack';
import Dotenv from 'dotenv-webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';

import { getManagerHeadHtml } from '@storybook/core/dist/server/utils';
import { getManagerHeadHtml } from '@storybook/core/dist/server/utils/template';
import { version } from '../../../package.json';
import { includePaths, excludePaths, loadEnv } from './utils';

Expand Down
7 changes: 7 additions & 0 deletions app/riot/src/server/framework-preset-riot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ export function webpack(config) {
},
],
},
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,
'riot-compiler': 'riot-compiler/dist/es6.compiler',
Copy link
Member

@igor-dv igor-dv Oct 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what happened (maybe env changes) but riot-compiler is now resolved to riot-compiler/lib/compiler which is a node version and riot app is failing.
This change is a workaround, but must be fixed in this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, I don't know what I can do about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndelangen, this issue was not addressed but introduced in this PR...

},
},
};
}
3 changes: 3 additions & 0 deletions lib/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@emotion/core": "^0.13.1",
"@emotion/provider": "^0.11.2",
"@emotion/styled": "^0.10.6",
"@ndelangen/html-webpack-harddisk-plugin": "^0.2.0",
"@storybook/addons": "4.1.0-alpha.1",
"@storybook/channel-postmessage": "4.1.0-alpha.1",
"@storybook/client-logger": "4.1.0-alpha.1",
Expand All @@ -43,6 +44,7 @@
"boxen": "^2.0.0",
"case-sensitive-paths-webpack-plugin": "^2.1.2",
"chalk": "^2.4.1",
"child-process-promise": "^2.2.1",
"cli-table3": "0.5.1",
"commander": "^2.19.0",
"common-tags": "^1.8.0",
Expand Down Expand Up @@ -75,6 +77,7 @@
"semver": "^5.6.0",
"serve-favicon": "^2.5.0",
"shelljs": "^0.8.2",
"spawn-promise": "^0.1.8",
"style-loader": "^0.23.1",
"svg-url-loader": "^2.3.2",
"url-loader": "^1.1.2",
Expand Down
4 changes: 2 additions & 2 deletions lib/core/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const defaultWebpackConfig = require('./dist/server/config/webpack.config.default.js');
const serverUtils = require('./dist/server/utils');
const defaultWebpackConfig = require('./dist/server/preview/base-webpack.config');
const serverUtils = require('./dist/server/utils/template');
const buildStatic = require('./dist/server/build-static');
const buildDev = require('./dist/server/build-dev');

Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/server/build-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import semver from 'semver';
import { stripIndents } from 'common-tags';
import Table from 'cli-table3';

import storybook, { webpackValid } from './middleware';
import storybook, { webpackValid } from './dev-server';
import { getDevCli } from './cli';

const defaultFavIcon = require.resolve('./public/favicon.ico');
Expand Down
47 changes: 40 additions & 7 deletions lib/core/src/server/build-static.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
import webpack from 'webpack';
import path from 'path';
import fs from 'fs';
import path from 'path';
import webpack from 'webpack';
import shelljs from 'shelljs';
import childProcess from 'child-process-promise';

import { logger } from '@storybook/node-logger';

import { getProdCli } from './cli';
import loadConfig from './config';
import { loadEnv } from './config/utils';

const defaultFavIcon = require.resolve('./public/favicon.ico');

export async function buildStaticStandalone(options) {
const { outputDir, staticDir, watch } = options;
const { outputDir, staticDir, watch, configDir, packageJson } = options;
const environment = loadEnv();

// create output directory if not exists
shelljs.mkdir('-p', path.resolve(outputDir));
// clear the static dir
shelljs.rm('-rf', path.resolve(outputDir, 'static'));
shelljs.cp(defaultFavIcon, outputDir);

logger.info('building manager..');
const managerStartTime = process.hrtime();
await childProcess
.exec(
`node ${path.join(__dirname, 'manager/webpack.js')} dir=${configDir} out=${path.resolve(
outputDir
)}`,
{
env: {
NODE_ENV: 'production',
...environment,
},
}
)
.then(() => {
const managerTotalTime = process.hrtime(managerStartTime);
logger.trace({ message: 'manager built', time: managerTotalTime });
});

// Build the webpack configuration using the `baseConfig`
// custom `.babelrc` file and `webpack.config.js` files
// NOTE changes to env should be done before calling `getBaseConfig`
const config = await loadConfig({
configType: 'PRODUCTION',
corePresets: [require.resolve('./core-preset-prod.js')],
outputDir,
packageJson,
corePresets: [require.resolve('./preview/preview-preset.js')],
overridePresets: [require.resolve('./preview/custom-webpack-preset.js')],
...options,
});

config.output.path = path.resolve(outputDir);
// config.output.path = path.resolve(outputDir);

// copy all static files
if (staticDir) {
Expand All @@ -42,6 +69,8 @@ export async function buildStaticStandalone(options) {

// compile all resources with webpack and write them to the disk.
return new Promise((resolve, reject) => {
const previewStartTime = process.hrtime();

const webpackCb = (err, stats) => {
if (err || stats.hasErrors()) {
logger.error('Failed to build the storybook');
Expand All @@ -52,11 +81,14 @@ export async function buildStaticStandalone(options) {
process.exitCode = 1;
return reject(err);
}
logger.info('Building storybook completed.');

const previewTotalTime = process.hrtime(previewStartTime);
logger.trace({ message: 'preview built', time: previewTotalTime });

return resolve(stats);
};

logger.info('Building storybook ...');
logger.info('building preview..');
const compiler = webpack(config);

if (watch) {
Expand All @@ -73,6 +105,7 @@ export async function buildStatic({ packageJson, ...loadOptions }) {
await buildStaticStandalone({
...cliOptions,
...loadOptions,
packageJson,
configDir: cliOptions.configDir || './.storybook',
outputDir: cliOptions.outputDir || './storybook-static',
});
Expand Down
11 changes: 11 additions & 0 deletions lib/core/src/server/common/babel-cache-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import findCacheDir from 'find-cache-dir';

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' }),
...babelConfig,
});

export { extend as babel, extend as managerBabel };
32 changes: 32 additions & 0 deletions lib/core/src/server/common/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function createProdPresets() {
return [
[
require.resolve('babel-preset-minify'),
{
builtIns: false,
mangle: false,
},
],
];
}

export default ({ configType }) => {
const isProd = configType === 'PRODUCTION';
const prodPresets = isProd ? createProdPresets() : [];

return {
presets: [require.resolve('@babel/preset-env'), ...prodPresets],
plugins: [
require.resolve('babel-plugin-macros'),
require.resolve('@babel/plugin-transform-regenerator'),
require.resolve('@babel/plugin-proposal-class-properties'),
[
require.resolve('@babel/plugin-transform-runtime'),
{
helpers: true,
regenerator: true,
},
],
],
};
};
17 changes: 17 additions & 0 deletions lib/core/src/server/common/custom-presets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'path';
import { logger } from '@storybook/node-logger';
import serverRequire from '../utils/server-require';

export default function loadCustomPresets({ configDir }) {
const presets = serverRequire(path.resolve(configDir, 'presets'));

if (presets) {
logger.warn(
'"Custom presets" is an experimental and undocumented feature that will be changed or deprecated soon. Use it on your own risk.'
);

return presets;
}

return [];
}
Loading