Skip to content

Commit

Permalink
Add support for node_modules.asar in the shared process
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jan 29, 2018
1 parent e4d6731 commit f7f8e9c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/vs/code/electron-browser/sharedProcess/sharedProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,34 @@ function main() {
const args = parseURLQueryArgs();
const configuration = JSON.parse(args['config'] || '{}') || {};

//#region Add support for using node_modules.asar
(function () {
const path = require('path');
const Module = require('module');
let NODE_MODULES_PATH = path.join(configuration.appRoot, 'node_modules');
if (/[a-z]\:/.test(NODE_MODULES_PATH)) {
// Make drive letter uppercase
NODE_MODULES_PATH = NODE_MODULES_PATH.charAt(0).toUpperCase() + NODE_MODULES_PATH.substr(1);
}
const NODE_MODULES_ASAR_PATH = NODE_MODULES_PATH + '.asar';

const originalResolveLookupPaths = Module._resolveLookupPaths;
Module._resolveLookupPaths = function (request, parent) {
const result = originalResolveLookupPaths(request, parent);

const paths = result[1];
for (let i = 0, len = paths.length; i < len; i++) {
if (paths[i] === NODE_MODULES_PATH) {
paths.splice(i, 0, NODE_MODULES_ASAR_PATH);
break;
}
}

return result;
};
})();
//#endregion

// Correctly inherit the parent's environment
assign(process.env, configuration.userEnv);

Expand Down Expand Up @@ -84,7 +112,7 @@ function main() {
bundles[bundle] = json;
cb(undefined, json);
})
.catch(cb);
.catch(cb);
};
}

Expand Down

0 comments on commit f7f8e9c

Please sign in to comment.