mirror of
https://github.com/status-im/metro.git
synced 2025-02-06 08:15:01 +00:00
Replace applescript with https://github.com/sindresorhus/opn
Summary: This allows opening the Chrome debugger on OS X, Linux, and Windows, and succeeds the previous PR which used [browser-launcher2](https://github.com/benderjs/browser-launcher2) and included a `--dangerouslyDisableChromeDebuggerWebSecurity` option: https://github.com/facebook/react-native/pull/2406 [opn](https://github.com/sindresorhus/opn) is cross-platform and much simpler than browser-launcher2 (since we don't have to manage the opened Chrome instance; the OS will just use the default instance). Closes https://github.com/facebook/react-native/pull/3394 Reviewed By: mkonicek Differential Revision: D2550996 Pulled By: frantic fb-gh-sync-id: fa4cbe55542562f30f77e0a6ab4bc53980ee13aa
This commit is contained in:
parent
05c282f251
commit
a0b60b1434
@ -10,9 +10,21 @@
|
|||||||
|
|
||||||
var execFile = require('child_process').execFile;
|
var execFile = require('child_process').execFile;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var opn = require('opn');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
module.exports = function(options) {
|
function getChromeAppName() {
|
||||||
|
switch (process.platform) {
|
||||||
|
case 'darwin':
|
||||||
|
return 'google chrome';
|
||||||
|
case 'win32':
|
||||||
|
return 'chrome';
|
||||||
|
default:
|
||||||
|
return 'google-chrome';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = function(options, isDebuggerConnected) {
|
||||||
return function(req, res, next) {
|
return function(req, res, next) {
|
||||||
if (req.url === '/debugger-ui') {
|
if (req.url === '/debugger-ui') {
|
||||||
var debuggerPath = path.join(__dirname, 'debugger.html');
|
var debuggerPath = path.join(__dirname, 'debugger.html');
|
||||||
@ -29,19 +41,18 @@ module.exports = function(options) {
|
|||||||
'If you still need this, please let us know.'
|
'If you still need this, please let us know.'
|
||||||
);
|
);
|
||||||
} else if (req.url === '/launch-chrome-devtools') {
|
} else if (req.url === '/launch-chrome-devtools') {
|
||||||
|
if (isDebuggerConnected()) {
|
||||||
|
// Dev tools are already open; no need to open another session
|
||||||
|
res.end('OK');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var debuggerURL = 'http://localhost:' + options.port + '/debugger-ui';
|
var debuggerURL = 'http://localhost:' + options.port + '/debugger-ui';
|
||||||
var script = 'launchChromeDevTools.applescript';
|
|
||||||
console.log('Launching Dev Tools...');
|
console.log('Launching Dev Tools...');
|
||||||
execFile(
|
opn(debuggerURL, {app: [getChromeAppName()]}, function(err) {
|
||||||
path.join(__dirname, script), [debuggerURL],
|
|
||||||
function(err, stdout, stderr) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('Failed to run ' + script, err);
|
console.error('Google Chrome exited with error:', err);
|
||||||
}
|
}
|
||||||
console.log(stdout);
|
});
|
||||||
console.warn(stderr);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
res.end('OK');
|
res.end('OK');
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env osascript
|
|
||||||
|
|
||||||
-- Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
-- All rights reserved.
|
|
||||||
--
|
|
||||||
-- This source code is licensed under the BSD-style license found in the
|
|
||||||
-- LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
|
|
||||||
on run argv
|
|
||||||
set theURL to item 1 of argv
|
|
||||||
|
|
||||||
tell application "Chrome"
|
|
||||||
|
|
||||||
if (count every window) = 0 then
|
|
||||||
make new window
|
|
||||||
end if
|
|
||||||
|
|
||||||
-- Find a tab currently running the debugger
|
|
||||||
set found to false
|
|
||||||
set theTabIndex to -1
|
|
||||||
repeat with theWindow in every window
|
|
||||||
set theTabIndex to 0
|
|
||||||
repeat with theTab in every tab of theWindow
|
|
||||||
set theTabIndex to theTabIndex + 1
|
|
||||||
if theTab's URL is theURL then
|
|
||||||
set found to true
|
|
||||||
exit repeat
|
|
||||||
end if
|
|
||||||
end repeat
|
|
||||||
|
|
||||||
if found then
|
|
||||||
exit repeat
|
|
||||||
end if
|
|
||||||
end repeat
|
|
||||||
|
|
||||||
if found then
|
|
||||||
set index of theWindow to 1
|
|
||||||
set theWindow's active tab index to theTabIndex
|
|
||||||
else
|
|
||||||
tell window 1
|
|
||||||
activate
|
|
||||||
make new tab with properties {URL:theURL}
|
|
||||||
end tell
|
|
||||||
end if
|
|
||||||
end tell
|
|
||||||
end run
|
|
@ -22,7 +22,7 @@ function attachToServer(server, path) {
|
|||||||
try {
|
try {
|
||||||
cn.send(JSON.stringify(message));
|
cn.send(JSON.stringify(message));
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn('WARN: ' + e.message);
|
// Sometimes this call throws 'not opened'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -57,7 +57,14 @@ function attachToServer(server, path) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return wss;
|
return {
|
||||||
|
server: wss,
|
||||||
|
isChromeConnected: () =>
|
||||||
|
clients
|
||||||
|
.map(ws => ws.upgradeReq.headers['user-agent'])
|
||||||
|
.filter(Boolean)
|
||||||
|
.some(userAgent => userAgent.includes('Chrome'))
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user