Use MAJOR_VERSION from package.json

This commit is contained in:
Surma
2019-02-11 13:07:10 +00:00
parent 7998cf247b
commit efad4f612f
4 changed files with 8 additions and 6 deletions

View File

@@ -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);
}

View File

@@ -70,8 +70,10 @@ export default class App extends Component<Props, State> {
});
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) {

View File

@@ -34,6 +34,7 @@ declare module 'url-loader!*' {
}
declare var VERSION: string;
declare var MAJOR_VERSION: string;
declare var ga: {
(...args: any[]): void;

View File

@@ -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: '{}'