From 75ad27658e2e6d6d1cbe7f364f031d311eba00f3 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Tue, 9 May 2017 23:14:24 -0700 Subject: [PATCH] Fix flow errors --- .flowconfig | 5 +- .githooks/pre-commit/flow.sh | 1 + __mocks__/window.js | 2 +- flow-typed/npm/styled-components_v1.4.x.js | 183 ++++++++++++++++++ .../CenteredContent/CenteredContent.js | 1 + .../DocumentHtml/DocumentHtml.test.js | 6 +- .../components/SlackAuthLink/SlackAuthLink.js | 6 +- frontend/scenes/Settings/Settings.js | 4 +- frontend/utils/toc/index.js | 115 +++++------ frontend/utils/toc/utils.js | 24 ++- package.json | 5 +- server/api/middlewares/authentication.js | 19 +- server/api/middlewares/pagination.js | 11 +- server/errors.js | 4 +- server/index.js | 74 ++++--- server/presenters.js | 55 +++--- server/redis.js | 5 +- server/routes.js | 16 +- yarn.lock | 162 ++++++++++++++-- 19 files changed, 519 insertions(+), 179 deletions(-) create mode 100644 .githooks/pre-commit/flow.sh create mode 100644 flow-typed/npm/styled-components_v1.4.x.js diff --git a/.flowconfig b/.flowconfig index 3e6536de..131f2c26 100644 --- a/.flowconfig +++ b/.flowconfig @@ -1,5 +1,7 @@ [ignore] -/node_modules/.* +.*/node_modules/styled-components/.* +.*/node_modules/react-side-effect/.* +.*/node_modules/fbjs/.* [libs] @@ -10,6 +12,7 @@ module.system.node.resolve_dirname=node_modules module.system.node.resolve_dirname=frontend module.name_mapper='^\(.*\)\.s?css$' -> 'empty/object' +module.file_ext=.js module.file_ext=.scss esproposal.decorators=ignore diff --git a/.githooks/pre-commit/flow.sh b/.githooks/pre-commit/flow.sh new file mode 100644 index 00000000..de2b7a79 --- /dev/null +++ b/.githooks/pre-commit/flow.sh @@ -0,0 +1 @@ +yarn flow diff --git a/__mocks__/window.js b/__mocks__/window.js index 7a7b87a2..3b827de3 100644 --- a/__mocks__/window.js +++ b/__mocks__/window.js @@ -1 +1 @@ -window.matchMedia = (data) => data; +window.matchMedia = data => data; diff --git a/flow-typed/npm/styled-components_v1.4.x.js b/flow-typed/npm/styled-components_v1.4.x.js new file mode 100644 index 00000000..e5dc9817 --- /dev/null +++ b/flow-typed/npm/styled-components_v1.4.x.js @@ -0,0 +1,183 @@ +// flow-typed signature: 8e43d27dae79968dc11e73b131ec77da +// flow-typed version: d36e170dab/styled-components_v1.4.x/flow_>=v0.25.x + +// @flow + +declare module 'styled-components' { + declare type Interpolation = + | ((executionContext: Object) => string) + | string + | number; + declare type NameGenerator = (hash: number) => string; + + declare type StyledComponent = ( + strings: Array, + ...interpolations: Array + ) => ReactClass<*>; + + declare type Theme = { [key: string]: mixed }; + declare type ThemeProviderProps = { + theme: ((outerTheme: Theme) => void) | Theme, + }; + declare type Component = + | React$Component<*, *, *> + | ((props: *) => React$Element<*>); + + declare class ThemeProvider extends React$Component { + props: ThemeProviderProps, + } + + declare module.exports: { + (baseComponent: Component): StyledComponent, + injectGlobal: ( + strings: Array, + ...interpolations: Array + ) => void, + css: ( + strings: Array, + ...interpolations: Array + ) => Array, + keyframes: ( + strings: Array, + ...interpolations: Array + ) => string, + withTheme: ( + component: Component + ) => React$Component<*, ThemeProviderProps, *>, + ThemeProvider: typeof ThemeProvider, + a: StyledComponent, + abbr: StyledComponent, + address: StyledComponent, + area: StyledComponent, + article: StyledComponent, + aside: StyledComponent, + audio: StyledComponent, + b: StyledComponent, + base: StyledComponent, + bdi: StyledComponent, + bdo: StyledComponent, + big: StyledComponent, + blockquote: StyledComponent, + body: StyledComponent, + br: StyledComponent, + button: StyledComponent, + canvas: StyledComponent, + caption: StyledComponent, + cite: StyledComponent, + code: StyledComponent, + col: StyledComponent, + colgroup: StyledComponent, + data: StyledComponent, + datalist: StyledComponent, + dd: StyledComponent, + del: StyledComponent, + details: StyledComponent, + dfn: StyledComponent, + dialog: StyledComponent, + div: StyledComponent, + dl: StyledComponent, + dt: StyledComponent, + em: StyledComponent, + embed: StyledComponent, + fieldset: StyledComponent, + figcaption: StyledComponent, + figure: StyledComponent, + footer: StyledComponent, + form: StyledComponent, + h1: StyledComponent, + h2: StyledComponent, + h3: StyledComponent, + h4: StyledComponent, + h5: StyledComponent, + h6: StyledComponent, + head: StyledComponent, + header: StyledComponent, + hgroup: StyledComponent, + hr: StyledComponent, + html: StyledComponent, + i: StyledComponent, + iframe: StyledComponent, + img: StyledComponent, + input: StyledComponent, + ins: StyledComponent, + kbd: StyledComponent, + keygen: StyledComponent, + label: StyledComponent, + legend: StyledComponent, + li: StyledComponent, + link: StyledComponent, + main: StyledComponent, + map: StyledComponent, + mark: StyledComponent, + menu: StyledComponent, + menuitem: StyledComponent, + meta: StyledComponent, + meter: StyledComponent, + nav: StyledComponent, + noscript: StyledComponent, + object: StyledComponent, + ol: StyledComponent, + optgroup: StyledComponent, + option: StyledComponent, + output: StyledComponent, + p: StyledComponent, + param: StyledComponent, + picture: StyledComponent, + pre: StyledComponent, + progress: StyledComponent, + q: StyledComponent, + rp: StyledComponent, + rt: StyledComponent, + ruby: StyledComponent, + s: StyledComponent, + samp: StyledComponent, + script: StyledComponent, + section: StyledComponent, + select: StyledComponent, + small: StyledComponent, + source: StyledComponent, + span: StyledComponent, + strong: StyledComponent, + style: StyledComponent, + sub: StyledComponent, + summary: StyledComponent, + sup: StyledComponent, + table: StyledComponent, + tbody: StyledComponent, + td: StyledComponent, + textarea: StyledComponent, + tfoot: StyledComponent, + th: StyledComponent, + thead: StyledComponent, + time: StyledComponent, + title: StyledComponent, + tr: StyledComponent, + track: StyledComponent, + u: StyledComponent, + ul: StyledComponent, + var: StyledComponent, + video: StyledComponent, + wbr: StyledComponent, + + // SVG + circle: StyledComponent, + clipPath: StyledComponent, + defs: StyledComponent, + ellipse: StyledComponent, + g: StyledComponent, + image: StyledComponent, + line: StyledComponent, + linearGradient: StyledComponent, + mask: StyledComponent, + path: StyledComponent, + pattern: StyledComponent, + polygon: StyledComponent, + polyline: StyledComponent, + radialGradient: StyledComponent, + rect: StyledComponent, + stop: StyledComponent, + svg: StyledComponent, + text: StyledComponent, + tspan: StyledComponent, + }; +} diff --git a/frontend/components/CenteredContent/CenteredContent.js b/frontend/components/CenteredContent/CenteredContent.js index 37ddf991..3c32875d 100644 --- a/frontend/components/CenteredContent/CenteredContent.js +++ b/frontend/components/CenteredContent/CenteredContent.js @@ -5,6 +5,7 @@ import styles from './CenteredContent.scss'; type Props = { children: any, style: Object, + maxWidth: string, }; const CenteredContent = (props: Props) => { diff --git a/frontend/components/Document/components/DocumentHtml/DocumentHtml.test.js b/frontend/components/Document/components/DocumentHtml/DocumentHtml.test.js index 5295115d..520ef061 100644 --- a/frontend/components/Document/components/DocumentHtml/DocumentHtml.test.js +++ b/frontend/components/Document/components/DocumentHtml/DocumentHtml.test.js @@ -11,10 +11,6 @@ const testHtml = ` `; test('renders', () => { - const wrapper = shallow( - - ); + const wrapper = shallow(); expect(wrapper.find('.document').length).toBe(1); }); diff --git a/frontend/components/SlackAuthLink/SlackAuthLink.js b/frontend/components/SlackAuthLink/SlackAuthLink.js index c5edb4f3..0fe8e6b8 100644 --- a/frontend/components/SlackAuthLink/SlackAuthLink.js +++ b/frontend/components/SlackAuthLink/SlackAuthLink.js @@ -1,7 +1,7 @@ // @flow import React from 'react'; import { observer, inject } from 'mobx-react'; -import type { User } from 'types'; +import UserStore from 'stores/UserStore'; @inject('user') @observer @@ -9,7 +9,7 @@ class SlackAuthLink extends React.Component { props: { children: any, scopes: Array, - user: User, + user: UserStore, redirectUri: string, }; @@ -25,8 +25,10 @@ class SlackAuthLink extends React.Component { slackUrl = () => { const baseUrl = 'https://slack.com/oauth/authorize'; const params = { + // $FlowIssue global variable client_id: SLACK_KEY, scope: this.props.scopes.join(' '), + // $FlowIssue global variable redirect_uri: this.props.redirectUri || SLACK_REDIRECT_URI, state: this.props.user.getOauthState(), }; diff --git a/frontend/scenes/Settings/Settings.js b/frontend/scenes/Settings/Settings.js index a1a19500..7b051662 100644 --- a/frontend/scenes/Settings/Settings.js +++ b/frontend/scenes/Settings/Settings.js @@ -27,6 +27,7 @@ import SlackAuthLink from 'components/SlackAuthLink'; ); + // $FlowIssue global variable const showSlackSettings = DEPLOYMENT === 'hosted'; return ( @@ -47,7 +48,8 @@ import SlackAuthLink from 'components/SlackAuthLink'; Add to Slack<%= bullet %>[<%= heading %>](#<%= url %>)\n'; /** * Create the table of contents object that @@ -36,81 +37,83 @@ var defaultTemplate = '<%= depth %><%= bullet %>[<%= heading %>](#<%= url %>)\n' */ function generate(str, options) { - var opts = _.extend({ - firsth1: false, - blacklist: true, - omit: [], - maxDepth: 3, - slugify: function(text) { - return text; // Override this! - } - }, options); + var opts = _.extend( + { + firsth1: false, + blacklist: true, + omit: [], + maxDepth: 3, + slugify: function(text) { + return text; // Override this! + }, + }, + options + ); var toc = ''; var tokens = marked.lexer(str); var tocArray = []; // Remove the very first h1, true by default - if(opts.firsth1 === false) { + if (opts.firsth1 === false) { tokens.shift(); } // Do any h1's still exist? - var h1 = _.some(tokens, {depth: 1}); + var h1 = _.some(tokens, { depth: 1 }); - tokens.filter(function (token) { - // Filter out everything but headings - if (token.type !== 'heading' || token.type === 'code') { - return false; - } + tokens + .filter(function(token) { + // Filter out everything but headings + if (token.type !== 'heading' || token.type === 'code') { + return false; + } - // Since we removed the first h1, we'll check to see if other h1's - // exist. If none exist, then we unindent the rest of the TOC - if(!h1) { - token.depth = token.depth - 1; - } + // Since we removed the first h1, we'll check to see if other h1's + // exist. If none exist, then we unindent the rest of the TOC + if (!h1) { + token.depth = token.depth - 1; + } - // Store original text and create an id for linking - token.heading = opts.strip ? utils.strip(token.text, opts) : token.text; + // Store original text and create an id for linking + token.heading = opts.strip ? utils.strip(token.text, opts) : token.text; - // Create a "slugified" id for linking - token.id = opts.slugify(token.text); + // Create a "slugified" id for linking + token.id = opts.slugify(token.text); - // Omit headings with these strings - var omissions = ['Table of Contents', 'TOC', 'TABLE OF CONTENTS']; - var omit = _.union([], opts.omit, omissions); + // Omit headings with these strings + var omissions = ['Table of Contents', 'TOC', 'TABLE OF CONTENTS']; + var omit = _.union([], opts.omit, omissions); - if (utils.isMatch(omit, token.heading)) { - return; - } + if (utils.isMatch(omit, token.heading)) { + return; + } - return true; - }).forEach(function (h) { + return true; + }) + .forEach(function(h) { + if (h.depth > opts.maxDepth) { + return; + } - if(h.depth > opts.maxDepth) { - return; - } + var bullet = Array.isArray(opts.bullet) + ? opts.bullet[(h.depth - 1) % opts.bullet.length] + : opts.bullet; - var bullet = Array.isArray(opts.bullet) - ? opts.bullet[(h.depth - 1) % opts.bullet.length] - : opts.bullet; + var data = _.extend({}, opts.data, { + depth: new Array((h.depth - 1) * 2 + 1).join(' '), + bullet: bullet ? bullet : '* ', + heading: h.heading, + url: h.id, + }); - var data = _.extend({}, opts.data, { - depth : new Array((h.depth - 1) * 2 + 1).join(' '), - bullet : bullet ? bullet : '* ', - heading: h.heading, - url : h.id + tocArray.push(data); + toc += _.template(opts.template || defaultTemplate)(data); }); - tocArray.push(data); - toc += _.template(opts.template || defaultTemplate)(data); - }); - return { data: tocArray, - toc: opts.strip - ? utils.strip(toc, opts) - : toc + toc: opts.strip ? utils.strip(toc, opts) : toc, }; } @@ -128,17 +131,15 @@ toc.raw = function(str, options) { toc.insert = function(content, options) { var start = ''; - var stop = ''; + var stop = ''; var re = /([\s\S]+?)/; // remove the existing TOC content = content.replace(re, start); // generate new TOC - var newtoc = '\n\n' - + start + '\n\n' - + toc(content, options) + '\n' - + stop + '\n'; + var newtoc = + '\n\n' + start + '\n\n' + toc(content, options) + '\n' + stop + '\n'; // If front-matter existed, put it back return content.replace(start, newtoc); diff --git a/frontend/utils/toc/utils.js b/frontend/utils/toc/utils.js index 6d7d9116..e1cd9177 100644 --- a/frontend/utils/toc/utils.js +++ b/frontend/utils/toc/utils.js @@ -10,8 +10,7 @@ 'use strict'; var _ = require('lodash'); -var utils = module.exports = {}; - +var utils = (module.exports = {}); utils.arrayify = function(arr) { return !Array.isArray(arr) ? [arr] : arr; @@ -25,9 +24,9 @@ utils.isDest = function(dest) { return !dest || dest === 'undefined' || typeof dest === 'object'; }; -utils.isMatch = function (keys, str) { +utils.isMatch = function(keys, str) { keys = utils.arrayify(keys); - keys = (keys.length > 0) ? keys.join('|') : '.*'; + keys = keys.length > 0 ? keys.join('|') : '.*'; // Escape certain characters, like '[', '(' var k = utils.escapeRegex(String(keys)); @@ -57,18 +56,27 @@ utils.slugify = function(str) { return str; }; - /** * Strip certain words from headings. These can be * overridden. Might seem strange but it makes * sense in context. */ -var omit = ['grunt', 'helper', 'handlebars-helper', 'mixin', 'filter', 'assemble-contrib', 'assemble']; +var omit = [ + 'grunt', + 'helper', + 'handlebars-helper', + 'mixin', + 'filter', + 'assemble-contrib', + 'assemble', +]; -utils.strip = function (name, options) { +utils.strip = function(name, options) { var opts = _.extend({}, options); - if(opts.omit === false) {omit = [];} + if (opts.omit === false) { + omit = []; + } var exclusions = _.union(omit, utils.arrayify(opts.strip || [])); var re = new RegExp('^(?:' + exclusions.join('|') + ')[-_]?', 'g'); return name.replace(re, ''); diff --git a/package.json b/package.json index 72296a92..f05f5f60 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "extract-text-webpack-plugin": "1.0.1", "file-loader": "0.9.0", "flow": "^0.2.3", + "flow-typed": "^2.1.2", "highlight.js": "9.4.0", "history": "3.0.0", "html-webpack-plugin": "2.17.0", @@ -173,8 +174,8 @@ "lint-staged": "^3.4.0", "node-dev": "3.1.0", "nodemon": "1.11.0", - "prettier": "^1.2.2", + "prettier": "1.3.1", "react-addons-test-utils": "^15.3.1", "react-test-renderer": "^15.3.1" } -} \ No newline at end of file +} diff --git a/server/api/middlewares/authentication.js b/server/api/middlewares/authentication.js index fa96f5c5..7e033940 100644 --- a/server/api/middlewares/authentication.js +++ b/server/api/middlewares/authentication.js @@ -1,10 +1,7 @@ import httpErrors from 'http-errors'; import JWT from 'jsonwebtoken'; -import { - User, - ApiKey, -} from '../../models'; +import { User, ApiKey } from '../../models'; export default function auth({ require = true } = {}) { return async function authMiddleware(ctx, next) { @@ -22,8 +19,10 @@ export default function auth({ require = true } = {}) { } } else { if (require) { - throw httpErrors.Unauthorized(`Bad Authorization header format. \ - Format is "Authorization: Bearer "\n`); + throw httpErrors.Unauthorized( + `Bad Authorization header format. \ + Format is "Authorization: Bearer "\n` + ); } } } else if (ctx.body.token) { @@ -43,9 +42,11 @@ export default function auth({ require = true } = {}) { // API key let apiKey; try { - apiKey = await ApiKey.findOne({ where: { - secret: token, - } }); + apiKey = await ApiKey.findOne({ + where: { + secret: token, + }, + }); } catch (e) { throw httpErrors.Unauthorized('Invalid api key'); } diff --git a/server/api/middlewares/pagination.js b/server/api/middlewares/pagination.js index 2352d7fc..36e8bc0d 100644 --- a/server/api/middlewares/pagination.js +++ b/server/api/middlewares/pagination.js @@ -18,7 +18,9 @@ export default function pagination(options) { offset = isNaN(offset) ? 0 : offset; if (limit > opts.maxLimit) { - throw httpErrors.BadRequest(`Pagination limit is too large (max ${opts.maxLimit})`); + throw httpErrors.BadRequest( + `Pagination limit is too large (max ${opts.maxLimit})` + ); } ctx.state.pagination = { @@ -28,8 +30,9 @@ export default function pagination(options) { query.limit = ctx.state.pagination.limit; query.offset = ctx.state.pagination.offset + query.limit; - ctx.state.pagination.nextPath = '/api' + ctx.request.path + '?' + querystring.stringify(query); + ctx.state.pagination.nextPath = + '/api' + ctx.request.path + '?' + querystring.stringify(query); return next(); - } -}; + }; +} diff --git a/server/errors.js b/server/errors.js index dae99fee..23ffd9f3 100644 --- a/server/errors.js +++ b/server/errors.js @@ -5,6 +5,4 @@ const apiError = (code, id, message) => { }; export default apiError; -export { - httpErrors, -}; +export { httpErrors }; diff --git a/server/index.js b/server/index.js index 25afafad..a9640fa6 100644 --- a/server/index.js +++ b/server/index.js @@ -22,37 +22,45 @@ if (process.env.NODE_ENV === 'development') { const compile = webpack(config); /* eslint-enable global-require */ - app.use(convert(devMiddleware(compile, { - // display no info to console (only warnings and errors) - noInfo: true, + app.use( + convert( + devMiddleware(compile, { + // display no info to console (only warnings and errors) + noInfo: true, - // display nothing to the console - quiet: false, + // display nothing to the console + quiet: false, - // switch into lazy mode - // that means no watching, but recompilation on every request - lazy: false, + // switch into lazy mode + // that means no watching, but recompilation on every request + lazy: false, - // // watch options (only lazy: false) - // watchOptions: { - // aggregateTimeout: 300, - // poll: true - // }, + // // watch options (only lazy: false) + // watchOptions: { + // aggregateTimeout: 300, + // poll: true + // }, - // public path to bind the middleware to - // use the same as in webpack - publicPath: config.output.publicPath, + // public path to bind the middleware to + // use the same as in webpack + publicPath: config.output.publicPath, - // options for formating the statistics - stats: { - colors: true, - }, - }))); - app.use(convert(hotMiddleware(compile, { - log: console.log, // eslint-disable-line - path: '/__webpack_hmr', - heartbeat: 10 * 1000, - }))); + // options for formating the statistics + stats: { + colors: true, + }, + }) + ) + ); + app.use( + convert( + hotMiddleware(compile, { + log: console.log, // eslint-disable-line + path: '/__webpack_hmr', + heartbeat: 10 * 1000, + }) + ) + ); app.use(logger()); } @@ -63,11 +71,13 @@ if (process.env.NODE_ENV === 'production') { app.use(mount('/api', api)); app.use(mount(routes)); -app.use(helmet.csp({ - directives: { - defaultSrc: ['\'self\''], - styleSrc: ['\'self\'', '\'unsafe-inline\''], - }, -})); +app.use( + helmet.csp({ + directives: { + defaultSrc: ["'self'"], + styleSrc: ["'self'", "'unsafe-inline'"], + }, + }) +); export default app; diff --git a/server/presenters.js b/server/presenters.js index 75ee7dc2..50a1cf10 100644 --- a/server/presenters.js +++ b/server/presenters.js @@ -3,9 +3,7 @@ import { Document, Atlas, User } from './models'; import presentUser from './presenters/user'; -export { - presentUser, -}; +export { presentUser }; export function presentTeam(ctx, team) { ctx.cache.set(team.id, team); @@ -43,15 +41,14 @@ export async function presentDocument(ctx, document, options) { }; if (options.includeCollection) { - data.collection = await ctx.cache.get( - document.atlasId, - async () => { - const collection = await Atlas.findOne({ where: { + data.collection = await ctx.cache.get(document.atlasId, async () => { + const collection = await Atlas.findOne({ + where: { id: document.atlasId, - } }); - return await presentCollection(ctx, collection); - } - ); + }, + }); + return await presentCollection(ctx, collection); + }); } if (options.includeCollaborators) { @@ -62,8 +59,7 @@ export async function presentDocument(ctx, document, options) { $in: document.collaboratorIds || [], }, }, - }) - .map(user => presentUser(ctx, user)); + }).map(user => presentUser(ctx, user)); } const createdBy = await ctx.cache.get( @@ -81,7 +77,11 @@ export async function presentDocument(ctx, document, options) { return data; } -export function presentCollection(ctx, collection, includeRecentDocuments=false) { +export function presentCollection( + ctx, + collection, + includeRecentDocuments = false +) { ctx.cache.set(collection.id, collection); return new Promise(async (resolve, _reject) => { @@ -95,7 +95,8 @@ export function presentCollection(ctx, collection, includeRecentDocuments=false) updatedAt: collection.updatedAt, }; - if (collection.type === 'atlas') data.navigationTree = collection.navigationTree; + if (collection.type === 'atlas') + data.navigationTree = collection.navigationTree; if (includeRecentDocuments) { const documents = await Document.findAll({ @@ -103,18 +104,24 @@ export function presentCollection(ctx, collection, includeRecentDocuments=false) atlasId: collection.id, }, limit: 10, - order: [ - ['updatedAt', 'DESC'], - ], + order: [['updatedAt', 'DESC']], }); const recentDocuments = []; - await Promise.all(documents.map(async (document) => { - recentDocuments.push(await presentDocument(ctx, document, { - includeCollaborators: true, - })); - })); - data.recentDocuments = _.orderBy(recentDocuments, ['updatedAt'], ['desc']); + await Promise.all( + documents.map(async document => { + recentDocuments.push( + await presentDocument(ctx, document, { + includeCollaborators: true, + }) + ); + }) + ); + data.recentDocuments = _.orderBy( + recentDocuments, + ['updatedAt'], + ['desc'] + ); } resolve(data); diff --git a/server/redis.js b/server/redis.js index fcbabbcd..837a4a99 100644 --- a/server/redis.js +++ b/server/redis.js @@ -4,7 +4,4 @@ import redisLock from 'redis-lock'; const client = redis.createClient(process.env.REDIS_URL); const lock = redisLock(client); -export { - client, - lock, -}; +export { client, lock }; diff --git a/server/routes.js b/server/routes.js index 3266e832..5d1987a0 100644 --- a/server/routes.js +++ b/server/routes.js @@ -9,9 +9,10 @@ import subdomainRedirect from './middlewares/subdomainRedirect'; const koa = new Koa(); const router = new Router(); -router.get('/service-worker.js', async (ctx) => { +router.get('/service-worker.js', async ctx => { ctx.set('Content-Type', 'application/javascript'); - if (process.env.NODE_ENV === 'production') ctx.set('Cache-Control', `max-age=${30}`); + if (process.env.NODE_ENV === 'production') + ctx.set('Cache-Control', `max-age=${30}`); await sendfile(ctx, path.join(__dirname, './static/service-worker.js')); if (!ctx.status) ctx.throw(httpErrors.NotFound()); }); @@ -19,22 +20,25 @@ router.get('/service-worker.js', async (ctx) => { router.get('/_health', ctx => (ctx.body = 'OK')); if (process.env.NODE_ENV === 'production') { - router.get('/static/*', async (ctx) => { + router.get('/static/*', async ctx => { ctx.set({ 'Cache-Control': `max-age=${356 * 24 * 60 * 60}`, }); - await sendfile(ctx, path.join(__dirname, '../dist/', ctx.path.substring(8))); + await sendfile( + ctx, + path.join(__dirname, '../dist/', ctx.path.substring(8)) + ); }); - router.get('*', async (ctx) => { + router.get('*', async ctx => { await sendfile(ctx, path.join(__dirname, '../dist/index.html')); if (!ctx.status) ctx.throw(httpErrors.NotFound()); }); koa.use(subdomainRedirect()); } else { - router.get('*', async (ctx) => { + router.get('*', async ctx => { await sendfile(ctx, path.join(__dirname, './static/dev.html')); if (!ctx.status) ctx.throw(httpErrors.NotFound()); }); diff --git a/yarn.lock b/yarn.lock index 36ad258b..40354e2b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -811,7 +811,7 @@ babel-plugin-transform-strict-mode@^6.24.1: babel-runtime "^6.22.0" babel-types "^6.24.1" -babel-polyfill@^6.13.0: +babel-polyfill@^6.13.0, babel-polyfill@^6.6.1: version "6.16.0" resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.16.0.tgz#2d45021df87e26a374b6d4d1a9c65964d17f2422" dependencies: @@ -1020,6 +1020,13 @@ binary-extensions@^1.0.0: version "1.7.0" resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.7.0.tgz#6c1610db163abfb34edfe42fa423343a1e01185d" +"binary@>= 0.3.0 < 1": + version "0.3.0" + resolved "https://registry.yarnpkg.com/binary/-/binary-0.3.0.tgz#9f60553bc5ce8c3386f3b553cff47462adecaa79" + dependencies: + buffers "~0.1.1" + chainsaw "~0.1.0" + bindings@1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11" @@ -1196,6 +1203,10 @@ buffer@^5.0.2: version "3.0.1" resolved "https://registry.yarnpkg.com/bufferjs/-/bufferjs-3.0.1.tgz#0692e829cb10a10550e647390b035eb06c38e8ef" +buffers@~0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/buffers/-/buffers-0.1.1.tgz#b24579c3bed4d6d396aeee6d9a8ae7f5482ab7bb" + "bufferstream@>= 0.6.2": version "0.6.2" resolved "https://registry.yarnpkg.com/bufferstream/-/bufferstream-0.6.2.tgz#a5f27e10d3c760084d14b35126615007319e3731" @@ -1309,6 +1320,12 @@ center-align@^0.1.1: align-text "^0.1.3" lazy-cache "^1.0.3" +chainsaw@~0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/chainsaw/-/chainsaw-0.1.0.tgz#5eab50b28afe58074d0d58291388828b5e5fbc98" + dependencies: + traverse ">=0.3.0 <0.4" + chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" @@ -1342,6 +1359,10 @@ change-case@3.0.x: upper-case "^1.1.1" upper-case-first "^1.1.0" +charenc@~0.0.1: + version "0.0.2" + resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667" + cheerio@0.22.0: version "0.22.0" resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-0.22.0.tgz#a9baa860a3f9b595a6b81b1a86873121ed3a269e" @@ -1554,7 +1575,7 @@ colors@1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" -colors@~1.1.2: +colors@^1.1.2, colors@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63" @@ -1845,6 +1866,10 @@ cross-spawn@^5.0.1: shebang-command "^1.2.0" which "^1.2.9" +crypt@~0.0.1: + version "0.0.2" + resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b" + cryptiles@2.x.x: version "2.0.5" resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8" @@ -3032,9 +3057,29 @@ flow-bin@^0.45.0: version "0.45.0" resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.45.0.tgz#009dd0f577a3f665c74ca8be827ae8c2dd8fd6b5" -flow-parser@0.43.0: - version "0.43.0" - resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.43.0.tgz#e2b8eb1ac83dd53f7b6b04a7c35b6a52c33479b7" +flow-parser@0.45.0: + version "0.45.0" + resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.45.0.tgz#aa29d4ae27f06aa02817772bba0fcbefef7e62f0" + +flow-typed@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/flow-typed/-/flow-typed-2.1.2.tgz#468f7a8b6bc18689856a1d101713b23bb39f01e4" + dependencies: + babel-polyfill "^6.6.1" + colors "^1.1.2" + fs-extra "^2.0.0" + github "^0.2.4" + glob "^7.0.6" + md5 "^2.1.0" + mkdirp "^0.5.1" + request "^2.69.0" + rimraf "^2.6.0" + semver "^5.1.0" + table "^3.7.8" + through "^2.3.8" + unzip "^0.1.11" + which "^1.2.11" + yargs "^4.2.0" flow@^0.2.3: version "0.2.3" @@ -3106,6 +3151,13 @@ fs-extra@^0.28.0: path-is-absolute "^1.0.0" rimraf "^2.2.8" +fs-extra@^2.0.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35" + dependencies: + graceful-fs "^4.1.2" + jsonfile "^2.1.0" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -3125,6 +3177,15 @@ fstream-ignore@~1.0.5: inherits "2" minimatch "^3.0.0" +"fstream@>= 0.1.30 < 1": + version "0.1.31" + resolved "https://registry.yarnpkg.com/fstream/-/fstream-0.1.31.tgz#7337f058fbbbbefa8c9f561a28cab0849202c988" + dependencies: + graceful-fs "~3.0.2" + inherits "~2.0.0" + mkdirp "0.5" + rimraf "2" + fstream@^1.0.0, fstream@^1.0.2, fstream@~1.0.10: version "1.0.10" resolved "https://registry.yarnpkg.com/fstream/-/fstream-1.0.10.tgz#604e8a92fe26ffd9f6fae30399d4984e1ab22822" @@ -3200,6 +3261,12 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" +github@^0.2.4: + version "0.2.4" + resolved "https://registry.yarnpkg.com/github/-/github-0.2.4.tgz#24fa7f0e13fa11b946af91134c51982a91ce538b" + dependencies: + mime "^1.2.11" + glob-base@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4" @@ -3246,7 +3313,7 @@ glob@5.x, glob@^5.0.15: once "^1.3.0" path-is-absolute "^1.0.0" -glob@7.1.1, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1: +glob@7.1.1, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1: version "7.1.1" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" dependencies: @@ -3360,7 +3427,7 @@ got@^3.2.0: read-all-stream "^3.0.0" timed-out "^2.0.0" -graceful-fs@^3.0.0: +graceful-fs@^3.0.0, graceful-fs@~3.0.2: version "3.0.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-3.0.11.tgz#7613c778a1afea62f25c630a086d7f3acbbdd818" dependencies: @@ -3899,7 +3966,7 @@ is-binary-path@^1.0.0: dependencies: binary-extensions "^1.0.0" -is-buffer@^1.0.2: +is-buffer@^1.0.2, is-buffer@~1.1.1: version "1.1.4" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.4.tgz#cfc86ccd5dc5a52fa80489111c6920c457e2d98b" @@ -5378,12 +5445,27 @@ marked@0.3.6, marked@^0.3.6: version "0.3.6" resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.6.tgz#b2c6c618fccece4ef86c4fc6cb8a7cbf5aeda8d7" +"match-stream@>= 0.0.2 < 1": + version "0.0.2" + resolved "https://registry.yarnpkg.com/match-stream/-/match-stream-0.0.2.tgz#99eb050093b34dffade421b9ac0b410a9cfa17cf" + dependencies: + buffers "~0.1.1" + readable-stream "~1.0.0" + math-expression-evaluator@^1.2.14: version "1.2.14" resolved "https://registry.yarnpkg.com/math-expression-evaluator/-/math-expression-evaluator-1.2.14.tgz#39511771ed9602405fba9affff17eb4d2a3843ab" dependencies: lodash.indexof "^4.0.5" +md5@^2.1.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9" + dependencies: + charenc "~0.0.1" + crypt "~0.0.1" + is-buffer "~1.1.1" + media-typer@0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" @@ -5494,7 +5576,7 @@ mime-types@^2.0.7, mime-types@^2.1.11, mime-types@^2.1.12, mime-types@~2.1.11, m dependencies: mime-db "~1.24.0" -mime@1.2.x: +mime@1.2.x, mime@^1.2.11: version "1.2.11" resolved "https://registry.yarnpkg.com/mime/-/mime-1.2.11.tgz#58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10" @@ -5539,7 +5621,7 @@ minimist@1.2.0, minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2 version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" -mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: +mkdirp@0.5, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" dependencies: @@ -6115,6 +6197,10 @@ osenv@0, osenv@^0.1.0, osenv@^0.1.3: os-homedir "^1.0.0" os-tmpdir "^1.0.0" +"over@>= 0.0.5 < 1": + version "0.0.5" + resolved "https://registry.yarnpkg.com/over/-/over-0.0.5.tgz#f29852e70fd7e25f360e013a8ec44c82aedb5708" + p-finally@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" @@ -6620,16 +6706,16 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@^1.2.2: - version "1.2.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.2.2.tgz#22d17c1132faaaea1f1d4faea31f19f7a1959f3e" +prettier@1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.3.1.tgz#fa0ea84b45ac0ba6de6a1e4cecdcff900d563151" dependencies: ast-types "0.9.8" babel-code-frame "6.22.0" babylon "7.0.0-beta.8" chalk "1.1.3" esutils "2.0.2" - flow-parser "0.43.0" + flow-parser "0.45.0" get-stdin "5.0.1" glob "7.1.1" jest-validate "19.0.0" @@ -6716,6 +6802,15 @@ public-encrypt@^4.0.0: parse-asn1 "^5.0.0" randombytes "^2.0.1" +"pullstream@>= 0.4.1 < 1": + version "0.4.1" + resolved "https://registry.yarnpkg.com/pullstream/-/pullstream-0.4.1.tgz#d6fb3bf5aed697e831150eb1002c25a3f8ae1314" + dependencies: + over ">= 0.0.5 < 1" + readable-stream "~1.0.31" + setimmediate ">= 1.0.2 < 2" + slice-stream ">= 1.0.0 < 2" + punycode@1.3.2: version "1.3.2" resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" @@ -6933,7 +7028,7 @@ read-pkg@^1.0.0: normalize-package-data "^2.3.2" path-type "^1.0.0" -readable-stream@1.0, "readable-stream@>=1.0.33-1 <1.1.0-0": +readable-stream@1.0, "readable-stream@>=1.0.33-1 <1.1.0-0", readable-stream@~1.0.0, readable-stream@~1.0.31: version "1.0.34" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c" dependencies: @@ -7203,7 +7298,7 @@ request@2, request@^2.55.0, request@^2.79.0: tunnel-agent "^0.6.0" uuid "^3.0.0" -request@2.x: +request@2.x, request@^2.69.0: version "2.75.0" resolved "https://registry.yarnpkg.com/request/-/request-2.75.0.tgz#d2b8268a286da13eaa5d01adf5d18cc90f657d93" dependencies: @@ -7298,7 +7393,13 @@ right-align@^0.1.1: dependencies: align-text "^0.1.1" -rimraf@2, rimraf@^2.2.8, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.5.4, rimraf@~2.5.0, rimraf@~2.5.1: +rimraf@2, rimraf@^2.2.8, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.6.0: + version "2.6.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d" + dependencies: + glob "^7.0.5" + +rimraf@^2.5.4, rimraf@~2.5.0, rimraf@~2.5.1: version "2.5.4" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04" dependencies: @@ -7517,7 +7618,7 @@ set-immediate-shim@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz#4b2b1b27eb808a9f8dcc481a58e5e56f599f3f61" -setimmediate@^1.0.5: +"setimmediate@>= 1.0.1 < 2", "setimmediate@>= 1.0.2 < 2", setimmediate@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285" @@ -7579,6 +7680,12 @@ slice-ansi@0.0.4: version "0.0.4" resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35" +"slice-stream@>= 1.0.0 < 2": + version "1.0.0" + resolved "https://registry.yarnpkg.com/slice-stream/-/slice-stream-1.0.0.tgz#5b33bd66f013b1a7f86460b03d463dec39ad3ea0" + dependencies: + readable-stream "~1.0.31" + slide@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707" @@ -7979,7 +8086,7 @@ through2@^2.0.0: readable-stream "~2.0.0" xtend "~4.0.0" -through@2, through@^2.3.6, through@~2.3, through@~2.3.1: +through@2, through@^2.3.6, through@^2.3.8, through@~2.3, through@~2.3.1: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" @@ -8053,6 +8160,10 @@ tr46@~0.0.1, tr46@~0.0.3: version "0.0.3" resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" +"traverse@>=0.3.0 <0.4": + version "0.3.9" + resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9" + trim-newlines@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613" @@ -8204,6 +8315,17 @@ unpipe@1.0.0, unpipe@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" +unzip@^0.1.11: + version "0.1.11" + resolved "https://registry.yarnpkg.com/unzip/-/unzip-0.1.11.tgz#89749c63b058d7d90d619f86b98aa1535d3b97f0" + dependencies: + binary ">= 0.3.0 < 1" + fstream ">= 0.1.30 < 1" + match-stream ">= 0.0.2 < 1" + pullstream ">= 0.4.1 < 1" + readable-stream "~1.0.31" + setimmediate ">= 1.0.1 < 2" + update-notifier@0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-0.5.0.tgz#07b5dc2066b3627ab3b4f530130f7eddda07a4cc" @@ -8479,7 +8601,7 @@ which-module@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-1.0.0.tgz#bba63ca861948994ff307736089e3b96026c2a4f" -which@1, which@^1.0.5, which@^1.1.1, which@^1.2.10, which@^1.2.9: +which@1, which@^1.0.5, which@^1.1.1, which@^1.2.10, which@^1.2.11, which@^1.2.9: version "1.2.11" resolved "https://registry.yarnpkg.com/which/-/which-1.2.11.tgz#c8b2eeea6b8c1659fa7c1dd4fdaabe9533dc5e8b" dependencies: