Skip to content

Commit f6ba9e1

Browse files
authored
Merge pull request #93 from ficristo/extension-rebuild
Support native module in extensions
2 parents 888644e + 1a9b034 commit f6ba9e1

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/extensibility/Package.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ define(function (require, exports, module) {
3737
ExtensionLoader = require("utils/ExtensionLoader"),
3838
NodeConnection = require("utils/NodeConnection"),
3939
PreferencesManager = require("preferences/PreferencesManager"),
40-
PathUtils = require("thirdparty/path-utils/path-utils");
40+
PathUtils = require("thirdparty/path-utils/path-utils"),
41+
electronVersion = brackets.metadata.devDependencies.electron;
4142

4243
PreferencesManager.definePreference("proxy", "string", undefined, {
4344
description: Strings.DESCRIPTION_PROXY
@@ -115,6 +116,7 @@ define(function (require, exports, module) {
115116
// so npm can use it in the domain
116117
options = options || {};
117118
options.proxy = PreferencesManager.get("proxy");
119+
options.electronVersion = electronVersion;
118120

119121
extensionManager.validate(path, options)
120122
.done(function (result) {
@@ -168,7 +170,8 @@ define(function (require, exports, module) {
168170
systemExtensionDirectory: systemDirectory,
169171
apiVersion: brackets.metadata.apiVersion,
170172
nameHint: nameHint,
171-
proxy: PreferencesManager.get("proxy")
173+
proxy: PreferencesManager.get("proxy"),
174+
electronVersion: electronVersion
172175
})
173176
.done(function (result) {
174177
result.keepFile = false;

src/extensibility/node/npm-installer.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,13 @@ var Errors = {
3737
* Private function to run "npm install --production" command in the extension directory.
3838
*
3939
* @param {string} installDirectory Directory to remove
40+
* @param {array} npmOptions can contain additional options like `--production` or `--proxy http://127.0.0.1:8888`
4041
* @param {function} callback NodeJS style callback to call after finish
4142
*/
4243
function _performNpmInstall(installDirectory, npmOptions, callback) {
4344
var npmPath = path.resolve(path.dirname(require.resolve("npm")), "..", "bin", "npm-cli.js");
44-
var args = [npmPath, "install"];
45-
46-
// npmOptions can contain additional args like { "production": true, "proxy": "http://127.0.0.1:8888" }
47-
Object.keys(npmOptions).forEach(function (key) {
48-
var value = npmOptions[key];
49-
if (value === true) {
50-
args.push("--" + key);
51-
} else if (typeof value === "string" && value.length > 0) {
52-
args.push("--" + key, value);
53-
}
54-
});
55-
45+
var args = [npmPath, "install"].concat(npmOptions);
46+
5647
console.log("running npm " + args.slice(1).join(" ") + " in " + installDirectory);
5748

5849
var child = spawn(process.execPath, args, { cwd: installDirectory });

src/extensibility/node/package-validator.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,23 @@ function extractAndValidateFiles(zipPath, extractDir, options, callback) {
295295
errors.push([Errors.MISSING_MAIN, zipPath, mainJS]);
296296
}
297297

298-
performNpmInstallIfRequired({
299-
production: true,
300-
proxy: options.proxy
301-
}, {
298+
var npmOptions = ['--production'];
299+
300+
if (options.proxy) {
301+
npmOptions.push('--proxy ' + options.proxy);
302+
}
303+
304+
npmOptions.push("--disturl=https://atom.io/download/electron");
305+
npmOptions.push("--runtime=electron");
306+
npmOptions.push("--target=" + options.electronVersion);
307+
308+
if (process.platform === "darwin") {
309+
npmOptions.push("--arch=x64");
310+
} else {
311+
npmOptions.push("--arch=" + process.arch);
312+
}
313+
314+
performNpmInstallIfRequired(npmOptions, {
302315
errors: errors,
303316
metadata: metadata,
304317
commonPrefix: commonPrefix,
@@ -311,7 +324,9 @@ function extractAndValidateFiles(zipPath, extractDir, options, callback) {
311324
unzipper.extract({
312325
path: extractDir,
313326
filter: function (file) {
314-
return file.type !== "SymbolicLink";
327+
return file.type !== "SymbolicLink" &&
328+
// Exclude toplevel .npmrc file
329+
!(file.filename === ".npmrc" && file.path === ".npmrc");
315330
}
316331
});
317332
}

0 commit comments

Comments
 (0)