Fix #5970 and forking while debugging (#5965)

* Fix forking while debugging

Debugger address in use no longer happens

* Fix cropper error
v1.18.x
Peter Jaszkowiak 7 years ago committed by Barış Soner Uşaklı
parent bb6dcf3779
commit 1c35213934

@ -37,7 +37,7 @@ var winston = require('winston');
var path = require('path'); var path = require('path');
var pkg = require('./package.json'); var pkg = require('./package.json');
var file = require('./src/file'); var file = require('./src/file');
var debug = require('./src/meta/debugParams')().execArgv.length; var debug = require('./src/meta/debugFork').debugging;
global.env = process.env.NODE_ENV || 'production'; global.env = process.env.NODE_ENV || 'production';

@ -1,7 +1,7 @@
'use strict'; 'use strict';
define('pictureCropper', ['translator', 'cropper', 'benchpress'], function (translator, cropper, Benchpress) { define('pictureCropper', ['translator', 'cropper', 'benchpress'], function (translator, Cropper, Benchpress) {
var module = {}; var module = {};
module.show = function (data, callback) { module.show = function (data, callback) {
@ -46,7 +46,7 @@ define('pictureCropper', ['translator', 'cropper', 'benchpress'], function (tran
var img = document.getElementById('cropped-image'); var img = document.getElementById('cropped-image');
$(img).css('max-height', cropBoxHeight); $(img).css('max-height', cropBoxHeight);
var cropperTool = new cropper.default(img, { var cropperTool = new Cropper(img, {
aspectRatio: data.aspectRatio, aspectRatio: data.aspectRatio,
autoCropArea: 1, autoCropArea: 1,
viewMode: 1, viewMode: 1,
@ -122,7 +122,7 @@ define('pictureCropper', ['translator', 'cropper', 'benchpress'], function (tran
$(this).addClass('disabled'); $(this).addClass('disabled');
cropperTool.destroy(); cropperTool.destroy();
cropperTool = new cropper.default(img, { cropperTool = new Cropper(img, {
viewMode: 1, viewMode: 1,
autoCropArea: 1, autoCropArea: 1,
ready: function () { ready: function () {

@ -0,0 +1,41 @@
'use strict';
var fork = require('child_process').fork;
var debugArg = process.execArgv.find(function (arg) {
return /^--(debug|inspect)/.test(arg);
});
var debugging = !!debugArg;
debugArg = debugArg ? debugArg.replace('-brk', '').split('=') : ['--debug', 5859];
var lastAddress = parseInt(debugArg[1], 10);
/**
* child-process.fork, but safe for use in debuggers
* @param {string} modulePath
* @param {string[]} [args]
* @param {any} [options]
*/
function debugFork(modulePath, args, options) {
var execArgv = [];
if (global.v8debug || debugging) {
lastAddress += 1;
execArgv = [debugArg[0] + '=' + lastAddress, '--nolazy'];
}
if (!Array.isArray(args)) {
options = args;
args = [];
}
options = options || {};
options = Object.assign({}, options, {
execArgv: execArgv,
});
return fork(modulePath, args, options);
}
debugFork.debugging = debugging;
module.exports = debugFork;

@ -1,16 +0,0 @@
'use strict';
module.exports = function (execArgv) {
execArgv = execArgv || process.execArgv;
var debugArg = execArgv.find(function (arg) {
return /^--(debug|inspect)/.test(arg);
});
if (global.v8debug || debugArg) {
debugArg = debugArg ? debugArg.split('=') : ['--debug', 5859];
var num = parseInt(debugArg[1], 10) + 1;
return { execArgv: [debugArg[0] + '=' + num, '--nolazy'] };
}
return { execArgv: [] };
};

@ -1,7 +1,6 @@
'use strict'; 'use strict';
var fs = require('fs'); var fs = require('fs');
var childProcess = require('child_process');
var os = require('os'); var os = require('os');
var uglifyjs = require('uglify-js'); var uglifyjs = require('uglify-js');
var async = require('async'); var async = require('async');
@ -11,7 +10,7 @@ var postcss = require('postcss');
var autoprefixer = require('autoprefixer'); var autoprefixer = require('autoprefixer');
var clean = require('postcss-clean'); var clean = require('postcss-clean');
var debugParams = require('./debugParams'); var fork = require('./debugFork');
var Minifier = module.exports; var Minifier = module.exports;
@ -47,13 +46,12 @@ function getChild() {
return free.shift(); return free.shift();
} }
var forkProcessParams = debugParams(); var proc = fork(__filename, [], {
var proc = childProcess.fork(__filename, [], Object.assign({}, forkProcessParams, {
cwd: __dirname, cwd: __dirname,
env: { env: {
minifier_child: true, minifier_child: true,
}, },
})); });
pool.push(proc); pool.push(proc);
return proc; return proc;

@ -1,9 +1,8 @@
'use strict'; 'use strict';
var fork = require('child_process').fork;
var path = require('path'); var path = require('path');
var debugParams = require('./meta/debugParams'); var fork = require('./meta/debugFork');
exports.hash = function (rounds, password, callback) { exports.hash = function (rounds, password, callback) {
forkChild({ type: 'hash', rounds: rounds, password: password }, callback); forkChild({ type: 'hash', rounds: rounds, password: password }, callback);
@ -17,7 +16,7 @@ exports.compare = function (password, hash, callback) {
}; };
function forkChild(message, callback) { function forkChild(message, callback) {
var child = fork(path.join(__dirname, 'bcrypt'), [], debugParams()); var child = fork(path.join(__dirname, 'bcrypt'));
child.on('message', function (msg) { child.on('message', function (msg) {
if (msg.err) { if (msg.err) {

@ -276,13 +276,28 @@ describe('meta', function () {
}); });
}); });
describe('debug params', function () { describe('debugFork', function () {
it('should return fork arguments for debug', function (done) { var oldArgv;
var debugParams = require('../src/meta/debugParams'); before(function () {
var data = debugParams(['--debug=5858', '--foo=1']); oldArgv = process.execArgv;
assert.equal(data.execArgv[0], '--debug=5859'); process.execArgv = ['--debug=5858', '--foo=1'];
assert.equal(data.execArgv[1], '--nolazy'); });
it('should detect debugging', function (done) {
var debugFork = require('../src/meta/debugFork');
assert(!debugFork.debugging);
var debugForkPath = require.resolve('../src/meta/debugFork');
delete require.cache[debugForkPath];
debugFork = require('../src/meta/debugFork');
assert(debugFork.debugging);
done(); done();
}); });
after(function () {
process.execArgv = oldArgv;
});
}); });
}); });

Loading…
Cancel
Save