@umijs/utils 4.0.36 → 4.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/open/LICENSE +9 -0
- package/compiled/open/index.d.ts +153 -0
- package/compiled/open/index.js +1 -0
- package/compiled/open/package.json +1 -0
- package/compiled/open/xdg-open +1066 -0
- package/dist/getDevBanner.js +70 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/openBrowser.d.ts +9 -0
- package/dist/openBrowser.js +96 -0
- package/dist/openChrome.applescript +95 -0
- package/package.json +2 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {ChildProcess} from 'child_process';
|
|
2
|
+
|
|
3
|
+
declare namespace open {
|
|
4
|
+
interface Options {
|
|
5
|
+
/**
|
|
6
|
+
Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
|
|
7
|
+
|
|
8
|
+
Note that it waits for the app to exit, not just for the window to close.
|
|
9
|
+
|
|
10
|
+
On Windows, you have to explicitly specify an app for it to be able to wait.
|
|
11
|
+
|
|
12
|
+
@default false
|
|
13
|
+
*/
|
|
14
|
+
readonly wait?: boolean;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
__macOS only__
|
|
18
|
+
|
|
19
|
+
Do not bring the app to the foreground.
|
|
20
|
+
|
|
21
|
+
@default false
|
|
22
|
+
*/
|
|
23
|
+
readonly background?: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
__macOS only__
|
|
27
|
+
|
|
28
|
+
Open a new instance of the app even it's already running.
|
|
29
|
+
|
|
30
|
+
A new instance is always opened on other platforms.
|
|
31
|
+
|
|
32
|
+
@default false
|
|
33
|
+
*/
|
|
34
|
+
readonly newInstance?: boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
Specify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown.
|
|
38
|
+
|
|
39
|
+
The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use.
|
|
40
|
+
|
|
41
|
+
You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome.
|
|
42
|
+
|
|
43
|
+
The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts.
|
|
44
|
+
*/
|
|
45
|
+
readonly app?: App | readonly App[];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
|
|
49
|
+
|
|
50
|
+
We do not recommend setting this option. The convention for success is exit code zero.
|
|
51
|
+
|
|
52
|
+
@default false
|
|
53
|
+
*/
|
|
54
|
+
readonly allowNonzeroExitCode?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface OpenAppOptions extends Omit<Options, 'app'> {
|
|
58
|
+
/**
|
|
59
|
+
Arguments passed to the app.
|
|
60
|
+
|
|
61
|
+
These arguments are app dependent. Check the app's documentation for what arguments it accepts.
|
|
62
|
+
*/
|
|
63
|
+
readonly arguments?: readonly string[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type AppName =
|
|
67
|
+
| 'chrome'
|
|
68
|
+
| 'firefox'
|
|
69
|
+
| 'edge';
|
|
70
|
+
|
|
71
|
+
type App = {
|
|
72
|
+
name: string | readonly string[];
|
|
73
|
+
arguments?: readonly string[];
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// eslint-disable-next-line no-redeclare
|
|
78
|
+
declare const open: {
|
|
79
|
+
/**
|
|
80
|
+
Open stuff like URLs, files, executables. Cross-platform.
|
|
81
|
+
|
|
82
|
+
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
|
|
83
|
+
|
|
84
|
+
There is a caveat for [double-quotes on Windows](https://github.com/sindresorhus/open#double-quotes-on-windows) where all double-quotes are stripped from the `target`.
|
|
85
|
+
|
|
86
|
+
@param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. For example, URLs open in your default browser.
|
|
87
|
+
@returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.
|
|
88
|
+
|
|
89
|
+
@example
|
|
90
|
+
```
|
|
91
|
+
import open = require('./open');
|
|
92
|
+
|
|
93
|
+
// Opens the image in the default image viewer
|
|
94
|
+
await open('unicorn.png', {wait: true});
|
|
95
|
+
console.log('The image viewer app closed');
|
|
96
|
+
|
|
97
|
+
// Opens the url in the default browser
|
|
98
|
+
await open('https://sindresorhus.com');
|
|
99
|
+
|
|
100
|
+
// Opens the URL in a specified browser.
|
|
101
|
+
await open('https://sindresorhus.com', {app: {name: 'firefox'}});
|
|
102
|
+
|
|
103
|
+
// Specify app arguments.
|
|
104
|
+
await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});
|
|
105
|
+
```
|
|
106
|
+
*/
|
|
107
|
+
(
|
|
108
|
+
target: string,
|
|
109
|
+
options?: open.Options
|
|
110
|
+
): Promise<ChildProcess>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
An object containing auto-detected binary names for common apps. Useful to work around cross-platform differences.
|
|
114
|
+
|
|
115
|
+
@example
|
|
116
|
+
```
|
|
117
|
+
import open = require('./open');
|
|
118
|
+
|
|
119
|
+
await open('https://google.com', {
|
|
120
|
+
app: {
|
|
121
|
+
name: open.apps.chrome
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
*/
|
|
126
|
+
apps: Record<open.AppName, string | readonly string[]>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
Open an app. Cross-platform.
|
|
130
|
+
|
|
131
|
+
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
|
|
132
|
+
|
|
133
|
+
@param name - The app you want to open. Can be either builtin supported `open.apps` names or other name supported in platform.
|
|
134
|
+
@returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.
|
|
135
|
+
|
|
136
|
+
@example
|
|
137
|
+
```
|
|
138
|
+
const {apps, openApp} = require('open');
|
|
139
|
+
|
|
140
|
+
// Open Firefox
|
|
141
|
+
await openApp(apps.firefox);
|
|
142
|
+
|
|
143
|
+
// Open Chrome incognito mode
|
|
144
|
+
await openApp(apps.chrome, {arguments: ['--incognito']});
|
|
145
|
+
|
|
146
|
+
// Open Xcode
|
|
147
|
+
await openApp('xcode');
|
|
148
|
+
```
|
|
149
|
+
*/
|
|
150
|
+
openApp: (name: open.App['name'], options?: open.OpenAppOptions) => Promise<ChildProcess>;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export = open;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){var e={34:function(e){"use strict";e.exports=(e,r,t)=>{const define=t=>Object.defineProperty(e,r,{value:t,enumerable:true,writable:true});Object.defineProperty(e,r,{configurable:true,enumerable:true,get(){const e=t();define(e);return e},set(e){define(e)}});return e}},148:function(e,r,t){"use strict";const n=t(147);let o;function hasDockerEnv(){try{n.statSync("/.dockerenv");return true}catch(e){return false}}function hasDockerCGroup(){try{return n.readFileSync("/proc/self/cgroup","utf8").includes("docker")}catch(e){return false}}e.exports=()=>{if(o===undefined){o=hasDockerEnv()||hasDockerCGroup()}return o}},272:function(e,r,t){"use strict";const n=t(37);const o=t(147);const s=t(148);const isWsl=()=>{if(process.platform!=="linux"){return false}if(n.release().toLowerCase().includes("microsoft")){if(s()){return false}return true}try{return o.readFileSync("/proc/version","utf8").toLowerCase().includes("microsoft")?!s():false}catch(e){return false}};if(process.env.__IS_WSL_TEST__){e.exports=isWsl}else{e.exports=isWsl()}},537:function(e,r,t){const n=t(17);const o=t(81);const{promises:s,constants:i}=t(147);const a=t(272);const c=t(148);const u=t(34);const f=t.ab+"xdg-open";const{platform:p,arch:l}=process;const d=(()=>{const e="/mnt/";let r;return async function(){if(r){return r}const t="/etc/wsl.conf";let n=false;try{await s.access(t,i.F_OK);n=true}catch{}if(!n){return e}const o=await s.readFile(t,{encoding:"utf8"});const a=/(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(o);if(!a){return e}r=a.groups.mountPoint.trim();r=r.endsWith("/")?r:`${r}/`;return r}})();const pTryEach=async(e,r)=>{let t;for(const n of e){try{return await r(n)}catch(e){t=e}}throw t};const baseOpen=async e=>{e={wait:false,background:false,newInstance:false,allowNonzeroExitCode:false,...e};if(Array.isArray(e.app)){return pTryEach(e.app,(r=>baseOpen({...e,app:r})))}let{name:r,arguments:n=[]}=e.app||{};n=[...n];if(Array.isArray(r)){return pTryEach(r,(r=>baseOpen({...e,app:{name:r,arguments:n}})))}let u;const l=[];const m={};if(p==="darwin"){u="open";if(e.wait){l.push("--wait-apps")}if(e.background){l.push("--background")}if(e.newInstance){l.push("--new")}if(r){l.push("-a",r)}}else if(p==="win32"||a&&!c()){const t=await d();u=a?`${t}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`:`${process.env.SYSTEMROOT}\\System32\\WindowsPowerShell\\v1.0\\powershell`;l.push("-NoProfile","-NonInteractive","–ExecutionPolicy","Bypass","-EncodedCommand");if(!a){m.windowsVerbatimArguments=true}const o=["Start"];if(e.wait){o.push("-Wait")}if(r){o.push(`"\`"${r}\`""`,"-ArgumentList");if(e.target){n.unshift(e.target)}}else if(e.target){o.push(`"${e.target}"`)}if(n.length>0){n=n.map((e=>`"\`"${e}\`""`));o.push(n.join(","))}e.target=Buffer.from(o.join(" "),"utf16le").toString("base64")}else{if(r){u=r}else{const e=!__dirname||__dirname==="/";let r=false;try{await s.access(t.ab+"xdg-open",i.X_OK);r=true}catch{}const n=process.versions.electron||p==="android"||e||!r;u=n?"xdg-open":f}if(n.length>0){l.push(...n)}if(!e.wait){m.stdio="ignore";m.detached=true}}if(e.target){l.push(e.target)}if(p==="darwin"&&n.length>0){l.push("--args",...n)}const w=o.spawn(u,l,m);if(e.wait){return new Promise(((r,t)=>{w.once("error",t);w.once("close",(n=>{if(e.allowNonzeroExitCode&&n>0){t(new Error(`Exited with code ${n}`));return}r(w)}))}))}w.unref();return w};const open=(e,r)=>{if(typeof e!=="string"){throw new TypeError("Expected a `target`")}return baseOpen({...r,target:e})};const openApp=(e,r)=>{if(typeof e!=="string"){throw new TypeError("Expected a `name`")}const{arguments:t=[]}=r||{};if(t!==undefined&&t!==null&&!Array.isArray(t)){throw new TypeError("Expected `appArguments` as Array type")}return baseOpen({...r,app:{name:e,arguments:t}})};function detectArchBinary(e){if(typeof e==="string"||Array.isArray(e)){return e}const{[l]:r}=e;if(!r){throw new Error(`${l} is not supported`)}return r}function detectPlatformBinary({[p]:e},{wsl:r}){if(r&&a){return detectArchBinary(r)}if(!e){throw new Error(`${p} is not supported`)}return detectArchBinary(e)}const m={};u(m,"chrome",(()=>detectPlatformBinary({darwin:"google chrome",win32:"chrome",linux:["google-chrome","google-chrome-stable","chromium"]},{wsl:{ia32:"/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",x64:["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe","/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]}})));u(m,"firefox",(()=>detectPlatformBinary({darwin:"firefox",win32:"C:\\Program Files\\Mozilla Firefox\\firefox.exe",linux:"firefox"},{wsl:"/mnt/c/Program Files/Mozilla Firefox/firefox.exe"})));u(m,"edge",(()=>detectPlatformBinary({darwin:"microsoft edge",win32:"msedge",linux:["microsoft-edge","microsoft-edge-dev"]},{wsl:"/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"})));open.apps=m;open.openApp=openApp;e.exports=open},81:function(e){"use strict";e.exports=require("child_process")},147:function(e){"use strict";e.exports=require("fs")},37:function(e){"use strict";e.exports=require("os")},17:function(e){"use strict";e.exports=require("path")}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var o=r[t]={exports:{}};var s=true;try{e[t](o,o.exports,__nccwpck_require__);s=false}finally{if(s)delete r[t]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(537);module.exports=t})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"open","version":"8.4.0","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT"}
|