From efad4f612f191cfaab709b274ef8f6a36cfec53c Mon Sep 17 00:00:00 2001 From: Surma Date: Mon, 11 Feb 2019 13:07:10 +0000 Subject: [PATCH] Use MAJOR_VERSION from package.json --- src/components/App/client-api.ts | 6 ++---- src/components/App/index.tsx | 6 ++++-- src/missing-types.d.ts | 1 + webpack.config.js | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/App/client-api.ts b/src/components/App/client-api.ts index b993cbc5..3f3dc9bc 100644 --- a/src/components/App/client-api.ts +++ b/src/components/App/client-api.ts @@ -3,16 +3,14 @@ import { SideEvent, SideEventType } from '../compress/index'; import { expose } from 'comlink'; -const API_VERSION = 1; - export function exposeAPI(app: App) { - self.parent.postMessage({ type: 'READY', version: API_VERSION }, '*'); + self.parent.postMessage({ type: 'READY', version: MAJOR_VERSION }, '*'); self.addEventListener('message', (event: MessageEvent) => { if (event.data !== 'READY?') { return; } event.stopImmediatePropagation(); - self.parent.postMessage({ type: 'READY', version: API_VERSION }, '*'); + self.parent.postMessage({ type: 'READY', version: MAJOR_VERSION }, '*'); }); expose(new API(app), self.parent); } diff --git a/src/components/App/index.tsx b/src/components/App/index.tsx index 851e831c..e7819200 100644 --- a/src/components/App/index.tsx +++ b/src/components/App/index.tsx @@ -70,8 +70,10 @@ export default class App extends Component { }); window.addEventListener('popstate', this.onPopState); - /* webpackChunkName: "client-api" */ - import('./client-api').then(m => m.exposeAPI(this)); + import( + /* webpackChunkName: "client-api" */ + './client-api', + ).then(m => m.exposeAPI(this)); } @bind openFile(file: File | Fileish) { diff --git a/src/missing-types.d.ts b/src/missing-types.d.ts index 8d8366ae..496c33bc 100644 --- a/src/missing-types.d.ts +++ b/src/missing-types.d.ts @@ -34,6 +34,7 @@ declare module 'url-loader!*' { } declare var VERSION: string; +declare var MAJOR_VERSION: string; declare var ga: { (...args: any[]): void; diff --git a/webpack.config.js b/webpack.config.js index fe52f705..74364e88 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -263,6 +263,7 @@ module.exports = async function (_, env) { // Inline constants during build, so they can be folded by UglifyJS. new webpack.DefinePlugin({ VERSION: JSON.stringify(VERSION), + MAJOR_VERSION: JSON.stringify(VERSION.split(".")[0]), // We set node.process=false later in this config. // Here we make sure if (process && process.foo) still works: process: '{}'