- add back positronBinding and atomBinding
  - use upstream electron common/reset-search-path.js to work with newer node
This commit is contained in:
Brendan Dahl 2016-08-08 15:22:36 -07:00
Родитель 95fd11f2b7
Коммит cd33abff54
3 изменённых файлов: 54 добавлений и 47 удалений

Просмотреть файл

@ -118,7 +118,11 @@ require('./guest-window-manager');
// Now we try to load app's package.json. // Now we try to load app's package.json.
var packageJson = null; 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; var i, len, packagePath;
for (i = 0, len = searchPaths.length; i < len; i++) { for (i = 0, len = searchPaths.length; i < len; i++) {
packagePath = searchPaths[i]; packagePath = searchPaths[i];
@ -172,11 +176,13 @@ app.setPath('userCache', path.join(app.getPath('cache'), app.getName()));
app.setAppPath(packagePath); app.setAppPath(packagePath);
// TODO: figure out how we want to load extensions
// Load the chrome extension support. // Load the chrome extension support.
require('./chrome-extension'); // require('./chrome-extension');
// TODO: figure out how we implement desktop capturer
// Load internal desktop-capturer module. // Load internal desktop-capturer module.
require('./desktop-capturer'); // require('./desktop-capturer');
// Set main startup script of the app. // Set main startup script of the app.
var mainStartupScript = packageJson.main || 'index.js'; var mainStartupScript = packageJson.main || 'index.js';

Просмотреть файл

@ -1,20 +1,19 @@
const path = require('path');
const timers = require('timers'); const timers = require('timers');
const Module = require('module');
process.atomBinding = function(name) { if (process.type === 'browser') {
try { process.positronBinding = function(name) {
return process.binding("atom_" + process.type + "_" + name); return require("../../../modules/" + name);
} catch (error) { };
if (/No such module/.test(error.message)) {
return process.binding("atom_common_" + 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. // called.
var wrapWithActivateUvLoop = function(func) { var wrapWithActivateUvLoop = function(func) {
return function() { return function() {
process.activateUvLoop(); // TODO: add a binding to do this
// process.activateUvLoop();
return func.apply(this, arguments); return func.apply(this, arguments);
}; };
}; };

Просмотреть файл

@ -1,36 +1,37 @@
const path = require('path'); const path = require('path')
const Module = require('module'); const Module = require('module')
// Clear Node's global search paths. // Clear Node's global search paths.
Module.globalPaths.length = 0; Module.globalPaths.length = 0
// Clear current and parent(init.coffee)'s search paths. // Clear current and parent(init.js)'s search paths.
module.paths = []; module.paths = []
module.parent.paths = []
module.parent.paths = [];
// Prevent Node from adding paths outside this app to search paths. // Prevent Node from adding paths outside this app to search paths.
Module._nodeModulePaths = function(from) { const resourcesPathWithTrailingSlash = process.resourcesPath + path.sep
var dir, i, part, parts, paths, skipOutsidePaths, splitRe, tip; const originalNodeModulePaths = Module._nodeModulePaths
from = path.resolve(from); 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. // If "from" is outside the app then we do nothing.
skipOutsidePaths = from.startsWith(process.resourcesPath); if (fromPath.startsWith(resourcesPathWithTrailingSlash)) {
return paths.filter(function (candidate) {
// Following logoic is copied from module.js. return candidate.startsWith(resourcesPathWithTrailingSlash)
splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//; })
paths = []; } else {
parts = from.split(splitRe); return paths
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'));
} }
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)
}
}