Beta 7 with some repo names changed.
This commit is contained in:
1 parent
0f7b40cca7
commit
963c19493a
3408 files changed
+462217
-15516
No files matched your search
+134
@@ -0,0 +1,134 @@
|
||||
'use strict';
|
||||
const {promisify} = require('util');
|
||||
const path = require('path');
|
||||
const childProcess = require('child_process');
|
||||
const fs = require('fs');
|
||||
const isWsl = require('is-wsl');
|
||||
|
||||
const pAccess = promisify(fs.access);
|
||||
const pExecFile = promisify(childProcess.execFile);
|
||||
|
||||
// Path to included `xdg-open`
|
||||
const localXdgOpenPath = path.join(__dirname, 'xdg-open');
|
||||
|
||||
// Convert a path from WSL format to Windows format:
|
||||
// `/mnt/c/Program Files/Example/MyApp.exe` → `C:\Program Files\Example\MyApp.exe`
|
||||
const wslToWindowsPath = async path => {
|
||||
const {stdout} = await pExecFile('wslpath', ['-w', path]);
|
||||
return stdout.trim();
|
||||
};
|
||||
|
||||
module.exports = async (target, options) => {
|
||||
if (typeof target !== 'string') {
|
||||
throw new TypeError('Expected a `target`');
|
||||
}
|
||||
|
||||
options = {
|
||||
wait: false,
|
||||
background: false,
|
||||
...options
|
||||
};
|
||||
|
||||
let command;
|
||||
let appArguments = [];
|
||||
const cliArguments = [];
|
||||
const childProcessOptions = {};
|
||||
|
||||
if (Array.isArray(options.app)) {
|
||||
appArguments = options.app.slice(1);
|
||||
options.app = options.app[0];
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
command = 'open';
|
||||
|
||||
if (options.wait) {
|
||||
cliArguments.push('--wait-apps');
|
||||
}
|
||||
|
||||
if (options.background) {
|
||||
cliArguments.push('--background');
|
||||
}
|
||||
|
||||
if (options.app) {
|
||||
cliArguments.push('-a', options.app);
|
||||
}
|
||||
} else if (process.platform === 'win32' || isWsl) {
|
||||
command = 'cmd' + (isWsl ? '.exe' : '');
|
||||
cliArguments.push('/c', 'start', '""', '/b');
|
||||
target = target.replace(/&/g, '^&');
|
||||
|
||||
if (options.wait) {
|
||||
cliArguments.push('/wait');
|
||||
}
|
||||
|
||||
if (options.app) {
|
||||
if (isWsl && options.app.startsWith('/mnt/')) {
|
||||
const windowsPath = await wslToWindowsPath(options.app);
|
||||
options.app = windowsPath;
|
||||
}
|
||||
|
||||
cliArguments.push(options.app);
|
||||
}
|
||||
|
||||
if (appArguments.length > 0) {
|
||||
cliArguments.push(...appArguments);
|
||||
}
|
||||
} else {
|
||||
if (options.app) {
|
||||
command = options.app;
|
||||
} else {
|
||||
// When bundled by Webpack, there's no actual package file path and no local `xdg-open`.
|
||||
const isBundled = !__dirname || __dirname === '/';
|
||||
|
||||
// Check if local `xdg-open` exists and is executable.
|
||||
let exeLocalXdgOpen = false;
|
||||
try {
|
||||
await pAccess(localXdgOpenPath, fs.constants.X_OK);
|
||||
exeLocalXdgOpen = true;
|
||||
} catch (error) {}
|
||||
|
||||
const useSystemXdgOpen = process.versions.electron ||
|
||||
process.platform === 'android' || isBundled || !exeLocalXdgOpen;
|
||||
command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
|
||||
}
|
||||
|
||||
if (appArguments.length > 0) {
|
||||
cliArguments.push(...appArguments);
|
||||
}
|
||||
|
||||
if (!options.wait) {
|
||||
// `xdg-open` will block the process unless stdio is ignored
|
||||
// and it's detached from the parent even if it's unref'd.
|
||||
childProcessOptions.stdio = 'ignore';
|
||||
childProcessOptions.detached = true;
|
||||
}
|
||||
}
|
||||
|
||||
cliArguments.push(target);
|
||||
|
||||
if (process.platform === 'darwin' && appArguments.length > 0) {
|
||||
cliArguments.push('--args', ...appArguments);
|
||||
}
|
||||
|
||||
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
||||
|
||||
if (options.wait) {
|
||||
return new Promise((resolve, reject) => {
|
||||
subprocess.once('error', reject);
|
||||
|
||||
subprocess.once('close', exitCode => {
|
||||
if (exitCode > 0) {
|
||||
reject(new Error(`Exited with code ${exitCode}`));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(subprocess);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
subprocess.unref();
|
||||
|
||||
return subprocess;
|
||||
};
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"_from": "open@^6.4.0",
|
||||
"_id": "open@6.4.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==",
|
||||
"_location": "/open",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "open@^6.4.0",
|
||||
"name": "open",
|
||||
"escapedName": "open",
|
||||
"rawSpec": "^6.4.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^6.4.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz",
|
||||
"_shasum": "5c13e96d0dc894686164f18965ecfe889ecfc8a9",
|
||||
"_spec": "open@^6.4.0",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\BackendServers",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/open/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"is-wsl": "^1.1.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Open stuff like URLs, files, executables. Cross-platform.",
|
||||
"devDependencies": {
|
||||
"@types/node": "^11.13.6",
|
||||
"ava": "^1.4.0",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"xdg-open"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/open#readme",
|
||||
"keywords": [
|
||||
"app",
|
||||
"open",
|
||||
"opener",
|
||||
"opens",
|
||||
"launch",
|
||||
"start",
|
||||
"xdg-open",
|
||||
"xdg",
|
||||
"default",
|
||||
"cmd",
|
||||
"browser",
|
||||
"editor",
|
||||
"executable",
|
||||
"exe",
|
||||
"url",
|
||||
"urls",
|
||||
"arguments",
|
||||
"args",
|
||||
"spawn",
|
||||
"exec",
|
||||
"child",
|
||||
"process",
|
||||
"website",
|
||||
"file"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "open",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/open.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && tsd"
|
||||
},
|
||||
"version": "6.4.0"
|
||||
}
|
||||
Reference in new issue
Block a user