@umijs/utils 4.0.37 → 4.0.39

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.
@@ -28,9 +28,6 @@ module.exports = __toCommonJS(getDevBanner_exports);
28
28
  var import_address = __toESM(require("../compiled/address"));
29
29
  var import_chalk = __toESM(require("../compiled/chalk"));
30
30
  var import_strip_ansi = __toESM(require("../compiled/strip-ansi"));
31
- var logger = __toESM(require("./logger"));
32
- var import_openBrowser = require("./openBrowser");
33
- var import_readline = __toESM(require("readline"));
34
31
  var BORDERS = {
35
32
  TL: import_chalk.default.gray.dim("\u2554"),
36
33
  TR: import_chalk.default.gray.dim("\u2557"),
@@ -42,15 +39,9 @@ var BORDERS = {
42
39
  function getDevBanner(protocol, host = "0.0.0.0", port, offset = 8) {
43
40
  const header = " App listening at:";
44
41
  const footer = import_chalk.default.bold(" Now you can open browser with the above addresses\u2191 ");
45
- const localUrl = `${protocol}//${host === "0.0.0.0" ? "localhost" : host}:${port}`;
46
- const local = ` ${import_chalk.default.gray(">")} Local: ${import_chalk.default.green(localUrl)} `;
42
+ const local = ` ${import_chalk.default.gray(">")} Local: ${import_chalk.default.green(`${protocol}//${host === "0.0.0.0" ? "localhost" : host}:${port}`)} `;
47
43
  const network = ` ${import_chalk.default.gray(">")} Network: ${import_chalk.default.green(`${protocol}//${import_address.default.ip()}:${port}`)} `;
48
- const isOpenShortcuts = !process.env.CI && process.env.UMI_SHORTCUTS !== "none";
49
- const shortcutsHelper = import_chalk.default.gray(` Press ${import_chalk.default.cyan.bold("h")} to show shortcuts help`);
50
- if (isOpenShortcuts) {
51
- initShortcuts({ localUrl });
52
- }
53
- const maxLen = Math.max(...[header, footer, local, network, isOpenShortcuts && shortcutsHelper].filter(Boolean).map((x) => (0, import_strip_ansi.default)(x).length));
44
+ const maxLen = Math.max(...[header, footer, local, network].map((x) => (0, import_strip_ansi.default)(x).length));
54
45
  const beforeLines = [
55
46
  `${BORDERS.TL}${import_chalk.default.gray.dim("".padStart(maxLen, BORDERS.H_PURE))}${BORDERS.TR}`,
56
47
  `${BORDERS.V}${header}${"".padStart(maxLen - header.length)}${BORDERS.V}`,
@@ -59,73 +50,15 @@ function getDevBanner(protocol, host = "0.0.0.0", port, offset = 8) {
59
50
  const mainLine = `${BORDERS.V}${network}${"".padStart(maxLen - (0, import_strip_ansi.default)(network).length)}${BORDERS.V}`;
60
51
  const afterLines = [
61
52
  `${BORDERS.V}${"".padStart(maxLen)}${BORDERS.V}`,
62
- isOpenShortcuts && `${BORDERS.V}${shortcutsHelper}${"".padStart(maxLen - (0, import_strip_ansi.default)(shortcutsHelper).length)}${BORDERS.V}`,
63
53
  `${BORDERS.V}${footer}${"".padStart(maxLen - (0, import_strip_ansi.default)(footer).length)}${BORDERS.V}`,
64
54
  `${BORDERS.BL}${import_chalk.default.gray.dim("".padStart(maxLen, BORDERS.H_PURE))}${BORDERS.BR}`
65
- ].filter(Boolean);
55
+ ];
66
56
  return {
67
57
  before: beforeLines.map((l) => l.padStart(l.length + offset)).join("\n"),
68
58
  main: mainLine,
69
59
  after: afterLines.map((l) => l.padStart(l.length + offset)).join("\n")
70
60
  };
71
61
  }
72
- function initShortcuts(opts) {
73
- const { localUrl } = opts;
74
- const shortcuts = [
75
- {
76
- key: "r" /* r */,
77
- description: "restart the server",
78
- action() {
79
- process.emit("UMI_RESTART_SERVER");
80
- }
81
- },
82
- {
83
- key: "o" /* o */,
84
- description: "open in browser",
85
- action() {
86
- if (!localUrl) {
87
- logger.warn("No URL available to open in browser");
88
- return;
89
- }
90
- (0, import_openBrowser.openBrowser)(localUrl);
91
- }
92
- },
93
- {
94
- key: "q" /* q */,
95
- description: "quit",
96
- action() {
97
- logger.event(`Shutdown server`);
98
- process.exit(1);
99
- }
100
- }
101
- ];
102
- let active = false;
103
- const onKeypress = async (input) => {
104
- if (input === "" || input === "") {
105
- process.exit(1);
106
- }
107
- if (active)
108
- return;
109
- if (input === "h" /* h */) {
110
- console.log(`
111
- ${import_chalk.default.bold("Shortcuts help")}:`);
112
- console.log(shortcuts.map((shortcut2) => import_chalk.default.dim(" Press ") + import_chalk.default.cyan.bold(shortcut2.key) + import_chalk.default.dim(` to ${shortcut2.description}`)).join("\n"));
113
- console.log();
114
- }
115
- const shortcut = shortcuts.find((shortcut2) => shortcut2.key === input);
116
- if (!shortcut) {
117
- return;
118
- }
119
- active = true;
120
- await shortcut.action();
121
- active = false;
122
- };
123
- import_readline.default.emitKeypressEvents(process.stdin);
124
- if (process.stdin.isTTY) {
125
- process.stdin.setRawMode(true);
126
- }
127
- process.stdin.on("keypress", onKeypress);
128
- }
129
62
  // Annotate the CommonJS export names for ESM import in node:
130
63
  0 && (module.exports = {
131
64
  getDevBanner
package/dist/index.d.ts CHANGED
@@ -41,5 +41,4 @@ export * as register from './register';
41
41
  export * from './tryPaths';
42
42
  export * from './winPath';
43
43
  export * from './setNoDeprecation';
44
- export * from './openBrowser';
45
44
  export { address, axios, chalk, cheerio, chokidar, crossSpawn, debug, deepmerge, execa, fsExtra, glob, Generator, BaseGenerator, generateFile, installDeps, lodash, logger, Mustache, pkgUp, portfinder, prompts, resolve, rimraf, semver, stripAnsi, updatePackageJSON, yParser, getGitInfo, printHelp, filesize, gzipSize, fastestLevenshtein, };
package/dist/index.js CHANGED
@@ -101,7 +101,6 @@ var register = __toESM(require("./register"));
101
101
  __reExport(src_exports, require("./tryPaths"), module.exports);
102
102
  __reExport(src_exports, require("./winPath"), module.exports);
103
103
  __reExport(src_exports, require("./setNoDeprecation"), module.exports);
104
- __reExport(src_exports, require("./openBrowser"), module.exports);
105
104
  // Annotate the CommonJS export names for ESM import in node:
106
105
  0 && (module.exports = {
107
106
  BaseGenerator,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/utils",
3
- "version": "4.0.37",
3
+ "version": "4.0.39",
4
4
  "homepage": "https://github.com/umijs/umi/tree/master/packages/utils#readme",
5
5
  "bugs": "https://github.com/umijs/umi/issues",
6
6
  "repository": {
@@ -52,7 +52,6 @@
52
52
  "import-lazy": "4.0.0",
53
53
  "lodash": "4.17.21",
54
54
  "mustache": "4.2.0",
55
- "open": "8.4.0",
56
55
  "pirates": "4.0.5",
57
56
  "pkg-up": "4.0.0",
58
57
  "portfinder": "1.0.28",
@@ -1,9 +0,0 @@
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.
@@ -1,153 +0,0 @@
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;
@@ -1 +0,0 @@
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})();
@@ -1 +0,0 @@
1
- {"name":"open","version":"8.4.0","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT"}