[Updater > v2] Partial rewriting (commiting modules)
This commit is contained in:
parent
af9bec3783
commit
fe52de3e51
|
@ -1,7 +1,7 @@
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
const { app } = require('electron');
|
const { app } = require('electron');
|
||||||
const { EventEmitter } = require('events');
|
const { EventEmitter } = require('events');
|
||||||
const NodeModule = require('module');
|
const Module = require('module');
|
||||||
const { join, resolve, basename } = require('path');
|
const { join, resolve, basename } = require('path');
|
||||||
const { hrtime } = require('process');
|
const { hrtime } = require('process');
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@ class Updater extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.committedHostVersion = null;
|
this.committedHostVersion = null;
|
||||||
this.committedModules = new Set();
|
|
||||||
this.rootPath = options.root_path;
|
this.rootPath = options.root_path;
|
||||||
this.nextRequestId = 0;
|
this.nextRequestId = 0;
|
||||||
this.requests = new Map();
|
this.requests = new Map();
|
||||||
|
@ -182,18 +181,12 @@ class Updater extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
_commitModulesInner(versions) {
|
_commitModulesInner(versions) {
|
||||||
const hostPath = this._getHostPath();
|
const base = join(this._getHostPath(), 'modules');
|
||||||
|
|
||||||
const modulesPath = join(hostPath, 'modules');
|
for (const mod in versions.current_modules) {
|
||||||
|
const path = join(modulesPath, `${mod}-${versions.current_modules[mod]}`);
|
||||||
|
|
||||||
for (const module in versions.current_modules) {
|
if (!Module.globalPaths.includes(path)) Module.globalPaths.push(path);
|
||||||
const moduleVersion = versions.current_modules[module];
|
|
||||||
const moduleSearchPath = join(modulesPath, `${module}-${moduleVersion}`);
|
|
||||||
|
|
||||||
if (!this.committedModules.has(module) && NodeModule.globalPaths.indexOf(moduleSearchPath) === -1) {
|
|
||||||
this.committedModules.add(module);
|
|
||||||
NodeModule.globalPaths.push(moduleSearchPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,11 +323,7 @@ class Updater extends EventEmitter {
|
||||||
async commitModules(versions) {
|
async commitModules(versions) {
|
||||||
if (this.committedHostVersion == null) throw new Error('Cannot commit modules before host version.');
|
if (this.committedHostVersion == null) throw new Error('Cannot commit modules before host version.');
|
||||||
|
|
||||||
if (versions == null) {
|
this._commitModulesInner(versions ?? await this.queryCurrentVersions());
|
||||||
versions = await this.queryCurrentVersions();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._commitModulesInner(versions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setRunningInBackground() {
|
setRunningInBackground() {
|
||||||
|
|
Loading…
Reference in New Issue