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

Performance optimizations on separate manager preview split, improved cold start, restart & rebuild #4834

Merged
merged 29 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
83a1800
CHANGE webpack configs, dev & static build for performance
ndelangen Nov 19, 2018
a78b909
FIX build-static
ndelangen Nov 26, 2018
03abc7e
Merge branch 'next' into separate-manager-preview-p5
ndelangen Nov 26, 2018
cc4fb66
FIX snapshots
ndelangen Nov 26, 2018
d06fe56
CHANGE output of dll to lib/core so it's easier to reference
ndelangen Nov 26, 2018
9b66549
FIX linting
ndelangen Nov 26, 2018
05418b2
cache DLL
Hypnosphi Nov 26, 2018
b198e08
CLEANUP
ndelangen Nov 26, 2018
ce9a748
FIX location of dll
ndelangen Nov 27, 2018
0064293
Merge branch 'next' into separate-manager-preview-p5
ndelangen Nov 27, 2018
4924083
FIX dll cache on teamcity (maybe)
ndelangen Nov 27, 2018
3502bef
CHANGE the dll express route to dev-server
ndelangen Nov 28, 2018
c467818
CLEANUP
ndelangen Nov 28, 2018
e7c24ba
MOVE licence notices into their own file && OPTIMISE the dll by speci…
ndelangen Nov 28, 2018
eaad2e7
Merge branch 'next' into separate-manager-preview-p5
ndelangen Nov 29, 2018
cf8e979
CHANGE to use terser over uglify
ndelangen Nov 29, 2018
7096cf3
RENAME config to webpackDllsConfig for clarity and easier search-ability
ndelangen Nov 29, 2018
b088ed0
RENAME script to createDlls for clarity & search-ability
ndelangen Nov 29, 2018
6efe2a5
Update lib/core/src/server/manager/manager-webpack.config.js
igor-dv Nov 29, 2018
b35aafb
Merge branch 'separate-manager-preview-p5' of github.com:storybooks/s…
ndelangen Nov 29, 2018
7b8c7ae
REFACTOR to use fs-extra because I hear people like async/await && RE…
ndelangen Nov 29, 2018
26e9357
RENAME script to create DLLs && REMOVE unneeded babel loader in DLL c…
ndelangen Nov 29, 2018
4141f48
REMOVE @ndelangen/html-webpack-harddisk-plugin
ndelangen Nov 29, 2018
998dab0
REFACTOR build-static to use fs-extra as well && CLEANUP
ndelangen Nov 29, 2018
8231388
ADD watch mode for static build back
ndelangen Nov 29, 2018
80e4eeb
FIX bug in checks for errors/warnings
ndelangen Nov 30, 2018
d781dc2
FIX dll copy command
ndelangen Nov 30, 2018
0b22923
FIX bootstrap script after rename to createDlls
ndelangen Nov 30, 2018
67d2629
FIX after rename of iframe to preview
ndelangen Nov 30, 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
9 changes: 7 additions & 2 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-flow'],
presets: [
['@babel/preset-env', { shippedProposals: true }],
'@babel/preset-react',
'@babel/preset-flow',
],
plugins: [
'babel-plugin-emotion',
'babel-plugin-macros',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-export-default-from',
[
'@babel/plugin-transform-runtime',
Expand All @@ -20,7 +25,7 @@ module.exports = {
overrides: [
{
test: './examples/vue-kitchen-sink',
presets: ['@babel/preset-env', 'babel-preset-vue'],
presets: [['@babel/preset-env', { shippedProposals: true }], 'babel-preset-vue'],
},
{
test: [
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
lib/**/dll
build
coverage
node_modules
Expand Down
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ module.exports = {
],
},
overrides: [
{
files: ['**/__tests__/**', '**/*.test.js/**', '**/*.spec.js/**'],
rules: {
'import/no-extraneous-dependencies': ignore,
},
},
{
files: ['**/react-native*/**', '**/REACT_NATIVE*/**', '**/crna*/**'],
rules: {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ integration/__image_snapshots__/__diff_output__
.jest-test-results.json
/examples/cra-kitchen-sink/src/__image_snapshots__/__diff_output__/
lib/*.jar
lib/**/dll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object OpenSourceProjects_Storybook_Bootstrap : BuildType({
addons/storyshots/*/dist/** => dist.zip/addons/storyshots
app/*/dist/** => dist.zip/app
lib/*/dist/** => dist.zip/lib
lib/core/dll/** => dist.zip/lib/core/dll
""".trimIndent()

vcs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ object OpenSourceProjects_Storybook_Examples : BuildType({
name = "Examples"

artifactRules = """
${StorybookApp.values().map { it.artifactPath }.joinToString("\n")}
examples/official-storybook/storybook-static => official.zip
examples/official-storybook/image-snapshots/__image_snapshots__ => image-snapshots
""".trimIndent()
${StorybookApp.values().map { it.artifactPath }.joinToString("\n")}
examples/official-storybook/storybook-static => official.zip
examples/official-storybook/image-snapshots/__image_snapshots__ => image-snapshots
""".trimIndent()

vcs {
root(OpenSourceProjects_Storybook.vcsRoots.OpenSourceProjects_Storybook_HttpsGithubComStorybooksStorybookRefsHeadsMaster)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ enum class StorybookApp(val appName: String, val exampleDir: String, val merged:
}

artifacts {
artifactRules = "dist.zip!**"
artifactRules = """
dist.zip!**
""".trimIndent()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@emotion/styled": "^0.10.6",
"@storybook/addons": "4.1.0-alpha.9",
"@storybook/core-events": "4.1.0-alpha.9",
"eventemitter3": "^3.1.0",
"global": "^4.3.2",
"prop-types": "^15.6.2",
"util-deprecate": "^1.0.2"
Expand Down
2 changes: 1 addition & 1 deletion addons/backgrounds/src/__tests__/BackgroundPanel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import EventEmitter from 'events';
import EventEmitter from 'eventemitter3';

import BackgroundPanel from '../BackgroundPanel';
import Events from '../constants';
Expand Down
4 changes: 2 additions & 2 deletions addons/options/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ To install type definitions: `npm install -D @types/storybook__addon-options`

Make sure you also have the type definitions installed for the following libs:

- node
- react
- node
- react

You can install them using `npm install -D @types/node @types/react`, assuming you are using Typescript >2.0.
9 changes: 5 additions & 4 deletions lib/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"storybook"
],
"homepage": "https://github.com/storybooks/storybook/tree/master/lib/core",
"publishConfig": {
"access": "public"
},
"bugs": {
"url": "https://github.com/storybooks/storybook/issues"
},
Expand All @@ -30,7 +27,6 @@
"@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.9",
"@storybook/channel-postmessage": "4.1.0-alpha.9",
"@storybook/client-logger": "4.1.0-alpha.9",
Expand All @@ -53,10 +49,12 @@
"detect-port": "^1.2.3",
"dotenv-webpack": "^1.5.7",
"ejs": "^2.6.1",
"eventemitter3": "^3.1.0",
"express": "^4.16.3",
"file-loader": "^2.0.0",
"file-system-cache": "^1.0.5",
"find-cache-dir": "^2.0.0",
"fs-extra": "^7.0.1",
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
"global": "^4.3.2",
"html-webpack-plugin": "^4.0.0-beta.2",
"inquirer": "^6.2.0",
Expand Down Expand Up @@ -94,5 +92,8 @@
"babel-loader": "^7.0.0 || ^8.0.0",
"react": ">=16.3.0",
"react-dom": ">=16.3.0"
},
"publishConfig": {
"access": "public"
}
}
2 changes: 1 addition & 1 deletion lib/core/src/client/preview/story_store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint no-underscore-dangle: 0 */
import { EventEmitter } from 'events';
import EventEmitter from 'eventemitter3';
import Events from '@storybook/core-events';

let count = 0;
Expand Down
70 changes: 43 additions & 27 deletions lib/core/src/server/build-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import https from 'https';
import ip from 'ip';
import favicon from 'serve-favicon';
import path from 'path';
import fs from 'fs';
import fs from 'fs-extra';
import chalk from 'chalk';
import { logger, colors } from '@storybook/node-logger';
import fetch from 'node-fetch';
Expand All @@ -21,12 +21,21 @@ import { getDevCli } from './cli';

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

const cacheDir = findCacheDir({ name: 'storybook' });
const cache = Cache({
basePath: findCacheDir({ name: 'storybook' }),
basePath: cacheDir,
ns: 'storybook', // Optional. A grouping namespace for items.
});

function getServer(app, options) {
const writeStats = async (name, stats) => {
await fs.writeFile(
path.join(cacheDir, `${name}-stats.json`),
JSON.stringify(stats.toJson(), null, 2),
'utf8'
);
};

async function getServer(app, options) {
if (!options.https) {
return app;
}
Expand All @@ -42,37 +51,40 @@ function getServer(app, options) {
}

const sslOptions = {
ca: (options.sslCa || []).map(ca => fs.readFileSync(ca, 'utf-8')),
cert: fs.readFileSync(options.sslCert, 'utf-8'),
key: fs.readFileSync(options.sslKey, 'utf-8'),
ca: await Promise.all((options.sslCa || []).map(ca => fs.readFile(ca, 'utf-8'))),
cert: await fs.readFile(options.sslCert, 'utf-8'),
key: await fs.readFile(options.sslKey, 'utf-8'),
};

return https.createServer(sslOptions, app);
}

function applyStatic(app, options) {
async function applyStatic(app, options) {
const { staticDir } = options;

let hasCustomFavicon = false;

if (staticDir) {
staticDir.forEach(dir => {
const staticPath = path.resolve(dir);
if (staticDir && staticDir.length) {
await Promise.all(
staticDir.map(async dir => {
const staticPath = path.resolve(dir);

if (!fs.existsSync(staticPath)) {
logger.error(`Error: no such directory to load static files: ${staticPath}`);
process.exit(-1);
}
if (await !fs.exists(staticPath)) {
logger.error(`Error: no such directory to load static files: ${staticPath}`);
process.exit(-1);
}

logger.info(`=> Loading static files from: ${staticPath} .`);
app.use(express.static(staticPath, { index: false }));
logger.info(`=> Loading static files from: ${staticPath} .`);
app.use(express.static(staticPath, { index: false }));

const faviconPath = path.resolve(staticPath, 'favicon.ico');
const faviconPath = path.resolve(staticPath, 'favicon.ico');

if (fs.existsSync(faviconPath)) {
hasCustomFavicon = true;
app.use(favicon(faviconPath));
}
});
if (await fs.exists(faviconPath)) {
hasCustomFavicon = true;
app.use(favicon(faviconPath));
}
})
);
}

if (!hasCustomFavicon) {
Expand Down Expand Up @@ -137,9 +149,9 @@ export async function buildDevStandalone(options) {
}

const app = express();
const server = getServer(app, options);
const server = await getServer(app, options);

applyStatic(app, options);
await applyStatic(app, options);

const storybookMiddleware = await storybook(options);

Expand All @@ -148,7 +160,7 @@ export async function buildDevStandalone(options) {
const serverListening = listenToServer(server, listenAddr);

const [
{ iframeStats, managerStats, managerTotalTime, iframeTotalTime },
{ previewStats, managerStats, managerTotalTime, previewTotalTime },
updateInfo,
] = await Promise.all([
webpackValid,
Expand Down Expand Up @@ -214,7 +226,7 @@ export async function buildDevStandalone(options) {
${colors.green(`Storybook ${chalk.bold(options.packageJson.version)} started`)}
${chalk.gray(stripIndents`
${chalk.underline(prettyTime(managerTotalTime))} for manager and ${chalk.underline(
prettyTime(iframeTotalTime)
prettyTime(previewTotalTime)
)} for preview`)}

${serveMessage.toString()}${updateMessage ? `\n\n${updateMessage}` : ''}
Expand All @@ -224,7 +236,11 @@ export async function buildDevStandalone(options) {
);

if (options.smokeTest) {
process.exit(iframeStats.toJson().warnings.length ? 1 : 0);
await writeStats('preview', previewStats);
await writeStats('manager', managerStats);
logger.info(`stats written to => ${chalk.cyan(path.join(cacheDir, '[name].json'))}`);

process.exit(previewStats.toJson().warnings.length ? 1 : 0);
process.exit(managerStats.toJson().warnings.length ? 1 : 0);
} else if (!options.ci) {
opn(address).catch(() => {
Expand Down
Loading