@pkgr/utils
Advanced tools
Comparing version 2.3.1 to 2.4.0
@@ -1,1 +0,1 @@ | ||
export declare function openBrowser(url: string): boolean; | ||
export declare function openBrowser(url: string): Promise<boolean>; |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import { execSync } from 'node:child_process'; | ||
@@ -5,3 +6,2 @@ import path from 'node:path'; | ||
import spawn from 'cross-spawn'; | ||
import open from 'open'; | ||
import picocolors from 'picocolors'; | ||
@@ -51,65 +51,74 @@ const OSX_CHROME = 'google chrome'; | ||
function startBrowserProcess(browser, url, args) { | ||
const shouldTryOpenChromiumWithAppleScript = process.platform === 'darwin' && | ||
(typeof browser !== 'string' || browser === OSX_CHROME); | ||
if (shouldTryOpenChromiumWithAppleScript) { | ||
const supportedChromiumBrowsers = [ | ||
'Google Chrome Canary', | ||
'Google Chrome', | ||
'Microsoft Edge', | ||
'Brave Browser', | ||
'Vivaldi', | ||
'Chromium', | ||
]; | ||
const _dirname = typeof __dirname === 'undefined' | ||
? path.dirname(fileURLToPath(import.meta.url)) | ||
: __dirname; | ||
for (const chromiumBrowser of supportedChromiumBrowsers) { | ||
try { | ||
execSync('ps cax | grep "' + chromiumBrowser + '"'); | ||
execSync('osascript ../openChrome.applescript "' + | ||
encodeURI(url) + | ||
'" "' + | ||
chromiumBrowser + | ||
'"', { | ||
cwd: _dirname, | ||
stdio: 'ignore', | ||
}); | ||
return true; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const shouldTryOpenChromiumWithAppleScript = process.platform === 'darwin' && | ||
(typeof browser !== 'string' || browser === OSX_CHROME); | ||
if (shouldTryOpenChromiumWithAppleScript) { | ||
const supportedChromiumBrowsers = [ | ||
'Google Chrome Canary', | ||
'Google Chrome', | ||
'Microsoft Edge', | ||
'Brave Browser', | ||
'Vivaldi', | ||
'Chromium', | ||
]; | ||
const _dirname = typeof __dirname === 'undefined' | ||
? path.dirname(fileURLToPath(import.meta.url)) | ||
: __dirname; | ||
for (const chromiumBrowser of supportedChromiumBrowsers) { | ||
try { | ||
execSync('ps cax | grep "' + chromiumBrowser + '"'); | ||
execSync('osascript ../openChrome.applescript "' + | ||
encodeURI(url) + | ||
'" "' + | ||
chromiumBrowser + | ||
'"', { | ||
cwd: _dirname, | ||
stdio: 'ignore', | ||
}); | ||
return true; | ||
} | ||
catch (_a) { | ||
} | ||
} | ||
catch (_a) { | ||
} | ||
} | ||
} | ||
if (process.platform === 'darwin' && browser === 'open') { | ||
browser = undefined; | ||
} | ||
try { | ||
open(url, { | ||
app: browser | ||
? { | ||
name: browser, | ||
arguments: args, | ||
} | ||
: undefined, | ||
wait: false, | ||
}).catch(() => { }); | ||
return true; | ||
} | ||
catch (_b) { | ||
return false; | ||
} | ||
if (process.platform === 'darwin' && browser === 'open') { | ||
browser = undefined; | ||
} | ||
try { | ||
const open = (yield import('open')).default; | ||
open(url, { | ||
app: browser | ||
? { | ||
name: browser, | ||
arguments: args, | ||
} | ||
: undefined, | ||
wait: false, | ||
}).catch(() => { }); | ||
return true; | ||
} | ||
catch (_b) { | ||
return false; | ||
} | ||
}); | ||
} | ||
export function openBrowser(url) { | ||
const { action, value, args } = getBrowserEnv(); | ||
switch (action) { | ||
case Action.NONE: | ||
return false; | ||
case Action.SCRIPT: | ||
return executeNodeScript(value, url); | ||
case Action.BROWSER: | ||
return startBrowserProcess(value, url, args); | ||
default: | ||
throw new Error('Not implemented.'); | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { action, value, args } = getBrowserEnv(); | ||
switch (action) { | ||
case Action.NONE: { | ||
return false; | ||
} | ||
case Action.SCRIPT: { | ||
return executeNodeScript(value, url); | ||
} | ||
case Action.BROWSER: { | ||
return startBrowserProcess(value, url, args); | ||
} | ||
default: { | ||
throw new Error('Not implemented.'); | ||
} | ||
} | ||
}); | ||
} | ||
//# sourceMappingURL=browser.js.map |
/// <reference types="node" /> | ||
/// <reference types="webpack-env" /> | ||
export declare const DEV: "development"; | ||
@@ -4,0 +3,0 @@ export declare const PROD: "production"; |
@@ -48,5 +48,6 @@ import fs from 'node:fs'; | ||
...(isGlob(pkg) | ||
? tryRequirePkg('tiny-glob/sync')(pkg, { | ||
? tryRequirePkg('fast-glob').sync(pkg, { | ||
absolute, | ||
cwd: baseDir, | ||
onlyFiles: false, | ||
}) | ||
@@ -53,0 +54,0 @@ : [tryFile(path.resolve(baseDir, pkg), true)]), |
{ | ||
"name": "@pkgr/utils", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"type": "module", | ||
@@ -28,7 +28,7 @@ "description": "Shared utils for `@pkgr` packages or any package else", | ||
"cross-spawn": "^7.0.3", | ||
"fast-glob": "^3.2.12", | ||
"is-glob": "^4.0.3", | ||
"open": "^8.4.0", | ||
"open": "^9.1.0", | ||
"picocolors": "^1.0.0", | ||
"tiny-glob": "^0.2.9", | ||
"tslib": "^2.4.0" | ||
"tslib": "^2.5.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33452
602
+ Addedfast-glob@^3.2.12
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Addedbig-integer@1.6.52(transitive)
+ Addedbplist-parser@0.2.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedbundle-name@3.0.0(transitive)
+ Addeddefault-browser@4.0.0(transitive)
+ Addeddefault-browser-id@3.0.0(transitive)
+ Addeddefine-lazy-prop@3.0.0(transitive)
+ Addedexeca@5.1.17.2.0(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedhuman-signals@2.1.04.3.1(transitive)
+ Addedis-docker@3.0.0(transitive)
+ Addedis-inside-container@1.0.0(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-stream@2.0.13.0.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedmimic-fn@2.1.04.0.0(transitive)
+ Addednpm-run-path@4.0.15.3.0(transitive)
+ Addedonetime@5.1.26.0.0(transitive)
+ Addedopen@9.1.0(transitive)
+ Addedpath-key@4.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrun-applescript@5.0.0(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstrip-final-newline@2.0.03.0.0(transitive)
+ Addedtitleize@3.0.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addeduntildify@4.0.0(transitive)
- Removedtiny-glob@^0.2.9
- Removeddefine-lazy-prop@2.0.0(transitive)
- Removedglobalyzer@0.1.0(transitive)
- Removedglobrex@0.1.2(transitive)
- Removedopen@8.4.2(transitive)
- Removedtiny-glob@0.2.9(transitive)
Updatedopen@^9.1.0
Updatedtslib@^2.5.0