GMOD / jbrowse-components

Source code for JBrowse 2, a modern React-based genome browser
https://jbrowse.org/jb2
Apache License 2.0
205 stars 61 forks source link

Fix error launching session on desktop in v2.12.2 #4469

Closed cmdcolin closed 3 months ago

cmdcolin commented 3 months ago

Fixes error "Error: Error invoking remote method 'createInitialAutosaveFile': ReferenceError: Cannot access 'path' before initialization" in v2.12.2

I changed the typescript config in v2.12.2 and so the generated js code for the electron main script was

ipcMain.handle('createInitialAutosaveFile', async (_event, snap) => {
    const rows = await readRecentSessions();
    const idx = rows.findIndex(r => r.path === path);
    const path = getAutosavePath(`${+Date.now()}`);

In v2.11.2 it used a complex down-transpilation that resulted in var declarations that were hoisted

ipcMain.handle('createInitialAutosaveFile', function (_event, snap) { return __awaiter(void 0, void 0, void 0, function () {
    var rows, idx, path, entry;
    var _a;
    return __generator(this, function (_b) {
        switch (_b.label) {
            case 0: return [4 /*yield*/, readRecentSessions()];
            case 1:
                rows = _b.sent();
                idx = rows.findIndex(function (r) { return r.path === path; });
                path = getAutosavePath("".concat(+Date.now()));

this PR fixes the variable declaration order, and also renames path to autosavePath as path is the name of our import from the npm module path

cmdcolin commented 3 months ago

might want to review how eslint didn't catch this perhaps...