Get positron working again:
- add back positronBinding and atomBinding - use upstream electron common/reset-search-path.js to work with newer node
This commit is contained in:
Родитель
95fd11f2b7
Коммит
cd33abff54
|
@ -118,7 +118,11 @@ require('./guest-window-manager');
|
|||
|
||||
// Now we try to load app's package.json.
|
||||
var packageJson = null;
|
||||
var searchPaths = ['app', 'app.asar', 'default_app'];
|
||||
// Electron launches it's app that in turn launches the command line app.
|
||||
// Positron directly launches the app for now so we have to add '' to the search
|
||||
// path to look in the current directory.
|
||||
// TODO: launch electron app?
|
||||
var searchPaths = ['', 'app', 'app.asar', 'default_app'];
|
||||
var i, len, packagePath;
|
||||
for (i = 0, len = searchPaths.length; i < len; i++) {
|
||||
packagePath = searchPaths[i];
|
||||
|
@ -172,11 +176,13 @@ app.setPath('userCache', path.join(app.getPath('cache'), app.getName()));
|
|||
|
||||
app.setAppPath(packagePath);
|
||||
|
||||
// TODO: figure out how we want to load extensions
|
||||
// Load the chrome extension support.
|
||||
require('./chrome-extension');
|
||||
// require('./chrome-extension');
|
||||
|
||||
// TODO: figure out how we implement desktop capturer
|
||||
// Load internal desktop-capturer module.
|
||||
require('./desktop-capturer');
|
||||
// require('./desktop-capturer');
|
||||
|
||||
// Set main startup script of the app.
|
||||
var mainStartupScript = packageJson.main || 'index.js';
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
const path = require('path');
|
||||
const timers = require('timers');
|
||||
const Module = require('module');
|
||||
|
||||
process.atomBinding = function(name) {
|
||||
try {
|
||||
return process.binding("atom_" + process.type + "_" + name);
|
||||
} catch (error) {
|
||||
if (/No such module/.test(error.message)) {
|
||||
return process.binding("atom_common_" + name);
|
||||
if (process.type === 'browser') {
|
||||
process.positronBinding = function(name) {
|
||||
return require("../../../modules/" + name);
|
||||
};
|
||||
|
||||
process.atomBinding = function(name) {
|
||||
try {
|
||||
return require("../../../modules/atom_" + process.type + "_" + name);
|
||||
} catch (error) {
|
||||
if (/Cannot find module/.test(error.message)) {
|
||||
return require("../../../modules/atom_common_" + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
||||
// Add common/api/lib to module search paths.
|
||||
Module.globalPaths.push(path.join(__dirname, 'api'));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +25,8 @@ if (!process.env.ELECTRON_HIDE_INTERNAL_MODULES) {
|
|||
// called.
|
||||
var wrapWithActivateUvLoop = function(func) {
|
||||
return function() {
|
||||
process.activateUvLoop();
|
||||
// TODO: add a binding to do this
|
||||
// process.activateUvLoop();
|
||||
return func.apply(this, arguments);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,36 +1,37 @@
|
|||
const path = require('path');
|
||||
const Module = require('module');
|
||||
const path = require('path')
|
||||
const Module = require('module')
|
||||
|
||||
// Clear Node's global search paths.
|
||||
Module.globalPaths.length = 0;
|
||||
Module.globalPaths.length = 0
|
||||
|
||||
// Clear current and parent(init.coffee)'s search paths.
|
||||
module.paths = [];
|
||||
|
||||
module.parent.paths = [];
|
||||
// Clear current and parent(init.js)'s search paths.
|
||||
module.paths = []
|
||||
module.parent.paths = []
|
||||
|
||||
// Prevent Node from adding paths outside this app to search paths.
|
||||
Module._nodeModulePaths = function(from) {
|
||||
var dir, i, part, parts, paths, skipOutsidePaths, splitRe, tip;
|
||||
from = path.resolve(from);
|
||||
|
||||
const resourcesPathWithTrailingSlash = process.resourcesPath + path.sep
|
||||
const originalNodeModulePaths = Module._nodeModulePaths
|
||||
Module._nodeModulePaths = function (from) {
|
||||
const paths = originalNodeModulePaths(from)
|
||||
const fromPath = path.resolve(from) + path.sep
|
||||
// If "from" is outside the app then we do nothing.
|
||||
skipOutsidePaths = from.startsWith(process.resourcesPath);
|
||||
|
||||
// Following logoic is copied from module.js.
|
||||
splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//;
|
||||
paths = [];
|
||||
parts = from.split(splitRe);
|
||||
for (tip = i = parts.length - 1; i >= 0; tip = i += -1) {
|
||||
part = parts[tip];
|
||||
if (part === 'node_modules') {
|
||||
continue;
|
||||
}
|
||||
dir = parts.slice(0, tip + 1).join(path.sep);
|
||||
if (skipOutsidePaths && !dir.startsWith(process.resourcesPath)) {
|
||||
break;
|
||||
}
|
||||
paths.push(path.join(dir, 'node_modules'));
|
||||
if (fromPath.startsWith(resourcesPathWithTrailingSlash)) {
|
||||
return paths.filter(function (candidate) {
|
||||
return candidate.startsWith(resourcesPathWithTrailingSlash)
|
||||
})
|
||||
} else {
|
||||
return paths
|
||||
}
|
||||
return paths;
|
||||
};
|
||||
}
|
||||
|
||||
// Patch Module._resolveFilename to always require the Electron API when
|
||||
// require('electron') is done.
|
||||
const electronPath = path.join(__dirname, '..', process.type, 'api', 'exports', 'electron.js')
|
||||
const originalResolveFilename = Module._resolveFilename
|
||||
Module._resolveFilename = function (request, parent, isMain) {
|
||||
if (request === 'electron') {
|
||||
return electronPath
|
||||
} else {
|
||||
return originalResolveFilename(request, parent, isMain)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче