@huxy/open-browser-webpack-plugin
Advanced tools
+3
-653
@@ -1,653 +0,3 @@ | ||
| import { default as l } from "node:process"; | ||
| import { default as I } from "node:path"; | ||
| import { fileURLToPath as z } from "node:url"; | ||
| import { default as C, execFile as S } from "node:child_process"; | ||
| import { constants as L, default as v } from "node:fs/promises"; | ||
| import { default as G } from "node:os"; | ||
| import { default as m } from "node:fs"; | ||
| import { promisify as p } from "node:util"; | ||
| import { Buffer as V } from "node:buffer"; | ||
| ; | ||
| ; | ||
| ; | ||
| ; | ||
| ; | ||
| ; | ||
| ; | ||
| ; | ||
| let O; | ||
| function Y() { | ||
| try { | ||
| m.statSync("/.dockerenv"); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function q() { | ||
| try { | ||
| return m.readFileSync("/proc/self/cgroup", "utf8").includes("docker"); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function j() { | ||
| if (O === void 0) { | ||
| O = Y() || q(); | ||
| } | ||
| return O; | ||
| } | ||
| ; | ||
| let T; | ||
| const J = () => { | ||
| try { | ||
| m.statSync("/run/.containerenv"); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| }; | ||
| function P() { | ||
| if (T === void 0) { | ||
| T = J() || j(); | ||
| } | ||
| return T; | ||
| } | ||
| ; | ||
| const U = () => { | ||
| if (l.platform !== "linux") { | ||
| return false; | ||
| } | ||
| if (G.release().toLowerCase().includes("microsoft")) { | ||
| if (P()) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| try { | ||
| if (m.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft")) { | ||
| return !P(); | ||
| } | ||
| } catch { | ||
| } | ||
| if (m.existsSync("/proc/sys/fs/binfmt_misc/WSLInterop") || m.existsSync("/run/WSL")) { | ||
| return !P(); | ||
| } | ||
| return false; | ||
| }; | ||
| const w = l.env.__IS_WSL_TEST__ ? U : U(); | ||
| ; | ||
| ; | ||
| ; | ||
| var Q; | ||
| var Z; | ||
| const ee = p(C.execFile); | ||
| const M = () => `${l.env.SYSTEMROOT || l.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`; | ||
| let D; | ||
| const De = async () => { | ||
| D ??= (async () => { | ||
| try { | ||
| await Q.access(M(), Z.X_OK); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| })(); | ||
| return D; | ||
| }; | ||
| const u = async (e, r = {}) => { | ||
| const { | ||
| powerShellPath: t, | ||
| ...o | ||
| } = r; | ||
| const n = u.encodeCommand(e); | ||
| return ee( | ||
| t ?? M(), | ||
| [ | ||
| ...u.argumentsPrefix, | ||
| n | ||
| ], | ||
| { | ||
| encoding: "utf8", | ||
| ...o | ||
| } | ||
| ); | ||
| }; | ||
| u.argumentsPrefix = [ | ||
| "-NoProfile", | ||
| "-NonInteractive", | ||
| "-ExecutionPolicy", | ||
| "Bypass", | ||
| "-EncodedCommand" | ||
| ]; | ||
| u.encodeCommand = (e) => V.from(e, "utf16le").toString("base64"); | ||
| u.escapeArgument = (e) => `'${String(e).replaceAll("'", "''")}'`; | ||
| ; | ||
| function re(e) { | ||
| for (const r of e.split("\n")) { | ||
| if (/^\s*#/.test(r)) { | ||
| continue; | ||
| } | ||
| const t = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(r); | ||
| if (!t) { | ||
| continue; | ||
| } | ||
| return t.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, ""); | ||
| } | ||
| } | ||
| ; | ||
| const te = p(C.execFile); | ||
| const oe = /* @__PURE__ */ (() => { | ||
| const e = "/mnt/"; | ||
| let r; | ||
| return async function() { | ||
| if (r) { | ||
| return r; | ||
| } | ||
| const t = "/etc/wsl.conf"; | ||
| let o = false; | ||
| try { | ||
| await v.access(t, L.F_OK); | ||
| o = true; | ||
| } catch { | ||
| } | ||
| if (!o) { | ||
| return e; | ||
| } | ||
| const n = await v.readFile(t, { encoding: "utf8" }); | ||
| const a = re(n); | ||
| if (a === void 0) { | ||
| return e; | ||
| } | ||
| r = a; | ||
| r = r.endsWith("/") ? r : `${r}/`; | ||
| return r; | ||
| }; | ||
| })(); | ||
| const ne = async () => { | ||
| const e = await oe(); | ||
| return `${e}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`; | ||
| }; | ||
| const F = w ? ne : M; | ||
| let N; | ||
| const se = async () => { | ||
| N ??= (async () => { | ||
| try { | ||
| const e = await F(); | ||
| await v.access(e, L.X_OK); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| })(); | ||
| return N; | ||
| }; | ||
| const ae = async () => { | ||
| const e = await F(); | ||
| const r = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`; | ||
| const { stdout: t } = await u(r, { powerShellPath: e }); | ||
| return t.trim(); | ||
| }; | ||
| const ie = async (e) => { | ||
| if (/^[a-z]+:\/\//i.test(e)) { | ||
| return e; | ||
| } | ||
| try { | ||
| const { stdout: r } = await te("wslpath", ["-aw", e], { encoding: "utf8" }); | ||
| return r.trim(); | ||
| } catch { | ||
| return e; | ||
| } | ||
| }; | ||
| ; | ||
| function y(e, r, t) { | ||
| const o = (n) => Object.defineProperty(e, r, { value: n, enumerable: true, writable: true }); | ||
| Object.defineProperty(e, r, { | ||
| configurable: true, | ||
| enumerable: true, | ||
| get() { | ||
| const n = t(); | ||
| o(n); | ||
| return n; | ||
| }, | ||
| set(n) { | ||
| o(n); | ||
| } | ||
| }); | ||
| return e; | ||
| } | ||
| ; | ||
| const ce = p(S); | ||
| const b = { | ||
| MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" }, | ||
| // The missing `L` is correct. | ||
| MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" }, | ||
| MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" }, | ||
| AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" }, | ||
| ChromeHTML: { name: "Chrome", id: "com.google.chrome" }, | ||
| ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" }, | ||
| ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" }, | ||
| ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" }, | ||
| BraveHTML: { name: "Brave", id: "com.brave.Browser" }, | ||
| BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" }, | ||
| BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" }, | ||
| BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" }, | ||
| FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" }, | ||
| OperaStable: { name: "Opera", id: "com.operasoftware.Opera" }, | ||
| VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" }, | ||
| "IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" } | ||
| }; | ||
| const le = new Map(Object.entries(b)); | ||
| class fe extends Error { | ||
| } | ||
| async function ue(e = ce) { | ||
| const { stdout: r } = await e("reg", [ | ||
| "QUERY", | ||
| " HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice", | ||
| "/v", | ||
| "ProgId" | ||
| ]); | ||
| const t = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(r); | ||
| if (!t) { | ||
| throw new fe(`Cannot find Windows browser in stdout: ${JSON.stringify(r)}`); | ||
| } | ||
| const { id: o } = t.groups; | ||
| const n = o.lastIndexOf("."); | ||
| const a = o.lastIndexOf("-"); | ||
| const d = n === -1 ? void 0 : o.slice(0, n); | ||
| const A = a === -1 ? void 0 : o.slice(0, a); | ||
| return b[o] ?? b[d] ?? b[A] ?? { name: o, id: o }; | ||
| } | ||
| ; | ||
| const de = p(S); | ||
| async function me() { | ||
| if (l.platform !== "darwin") { | ||
| throw new Error("macOS only"); | ||
| } | ||
| const { stdout: e } = await de("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]); | ||
| const r = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(e); | ||
| const t = r?.groups.id ?? "com.apple.Safari"; | ||
| if (t === "com.apple.safari") { | ||
| return "com.apple.Safari"; | ||
| } | ||
| return t; | ||
| } | ||
| ; | ||
| var pe; | ||
| var we; | ||
| const ge = p(S); | ||
| async function _e(e, { humanReadableOutput: r = true, signal: t } = {}) { | ||
| if (l.platform !== "darwin") { | ||
| throw new Error("macOS only"); | ||
| } | ||
| const o = r ? [] : ["-ss"]; | ||
| const n = {}; | ||
| if (t) { | ||
| n.signal = t; | ||
| } | ||
| const { stdout: a } = await ge("osascript", ["-e", e, o], n); | ||
| return a.trim(); | ||
| } | ||
| function Ne(e, { humanReadableOutput: r = true } = {}) { | ||
| if (pe.platform !== "darwin") { | ||
| throw new Error("macOS only"); | ||
| } | ||
| const t = r ? [] : ["-ss"]; | ||
| const o = we("osascript", ["-e", e, ...t], { | ||
| encoding: "utf8", | ||
| stdio: ["ignore", "pipe", "ignore"], | ||
| timeout: 500 | ||
| }); | ||
| return o.trim(); | ||
| } | ||
| ; | ||
| async function he(e) { | ||
| return _e(`tell application "Finder" to set app_path to application file id "${e}" as string | ||
| tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`); | ||
| } | ||
| ; | ||
| const ye = p(S); | ||
| const Ee = (e) => e.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (r) => r.toUpperCase()); | ||
| async function xe() { | ||
| if (l.platform === "darwin") { | ||
| const e = await me(); | ||
| const r = await he(e); | ||
| return { name: r, id: e }; | ||
| } | ||
| if (l.platform === "linux") { | ||
| const { stdout: e } = await ye("xdg-mime", ["query", "default", "x-scheme-handler/http"]); | ||
| const r = e.trim(); | ||
| const t = Ee(r.replace(/.desktop$/, "").replace("-", " ")); | ||
| return { name: t, id: r }; | ||
| } | ||
| if (l.platform === "win32") { | ||
| return ue(); | ||
| } | ||
| throw new Error("Only macOS, Linux, and Windows are supported"); | ||
| } | ||
| ; | ||
| const Ae = Boolean(l.env.SSH_CONNECTION || l.env.SSH_CLIENT || l.env.SSH_TTY); | ||
| const Se = Ae; | ||
| ; | ||
| const B = /* @__PURE__ */ Symbol("fallbackAttempt"); | ||
| const W = true ? I.dirname(z("file:///Users/huy/Desktop/huxy/playground/huxy/open-browser-webpack-plugin/node_modules/open/index.js")) : 0; | ||
| const k = I.join(W, "xdg-open"); | ||
| const { platform: g, arch: R } = l; | ||
| const H = async (e, r) => { | ||
| if (e.length === 0) { | ||
| return; | ||
| } | ||
| const t = []; | ||
| for (const o of e) { | ||
| try { | ||
| return await r(o); | ||
| } catch (n) { | ||
| t.push(n); | ||
| } | ||
| } | ||
| throw new AggregateError(t, "Failed to open in all supported apps"); | ||
| }; | ||
| const E = async (e) => { | ||
| e = { | ||
| wait: false, | ||
| background: false, | ||
| newInstance: false, | ||
| allowNonzeroExitCode: false, | ||
| ...e | ||
| }; | ||
| const r = e[B] === true; | ||
| delete e[B]; | ||
| if (Array.isArray(e.app)) { | ||
| return H(e.app, (s) => E({ | ||
| ...e, | ||
| app: s, | ||
| [B]: true | ||
| })); | ||
| } | ||
| let { name: t, arguments: o = [] } = e.app ?? {}; | ||
| o = [...o]; | ||
| if (Array.isArray(t)) { | ||
| return H(t, (s) => E({ | ||
| ...e, | ||
| app: { | ||
| name: s, | ||
| arguments: o | ||
| }, | ||
| [B]: true | ||
| })); | ||
| } | ||
| if (t === "browser" || t === "browserPrivate") { | ||
| const s = { | ||
| "com.google.chrome": "chrome", | ||
| "google-chrome.desktop": "chrome", | ||
| "com.brave.browser": "brave", | ||
| "org.mozilla.firefox": "firefox", | ||
| "firefox.desktop": "firefox", | ||
| "com.microsoft.msedge": "edge", | ||
| "com.microsoft.edge": "edge", | ||
| "com.microsoft.edgemac": "edge", | ||
| "microsoft-edge.desktop": "edge", | ||
| "com.apple.safari": "safari" | ||
| }; | ||
| const i = { | ||
| chrome: "--incognito", | ||
| brave: "--incognito", | ||
| firefox: "--private-window", | ||
| edge: "--inPrivate" | ||
| // Safari doesn't support private mode via command line | ||
| }; | ||
| let f; | ||
| if (w) { | ||
| const h = await ae(); | ||
| const $ = le.get(h); | ||
| f = $ ?? {}; | ||
| } else { | ||
| f = await xe(); | ||
| } | ||
| if (f.id in s) { | ||
| const h = s[f.id.toLowerCase()]; | ||
| if (t === "browserPrivate") { | ||
| if (h === "safari") { | ||
| throw new Error("Safari doesn't support opening in private mode via command line"); | ||
| } | ||
| o.push(i[h]); | ||
| } | ||
| return E({ | ||
| ...e, | ||
| app: { | ||
| name: _[h], | ||
| arguments: o | ||
| } | ||
| }); | ||
| } | ||
| throw new Error(`${f.name} is not supported as a default browser`); | ||
| } | ||
| let n; | ||
| const a = []; | ||
| const d = {}; | ||
| let A = false; | ||
| if (w && !P() && !Se && !t) { | ||
| A = await se(); | ||
| } | ||
| if (g === "darwin") { | ||
| n = "open"; | ||
| if (e.wait) { | ||
| a.push("--wait-apps"); | ||
| } | ||
| if (e.background) { | ||
| a.push("--background"); | ||
| } | ||
| if (e.newInstance) { | ||
| a.push("--new"); | ||
| } | ||
| if (t) { | ||
| a.push("-a", t); | ||
| } | ||
| } else if (g === "win32" || A) { | ||
| n = await F(); | ||
| a.push(...u.argumentsPrefix); | ||
| if (!w) { | ||
| d.windowsVerbatimArguments = true; | ||
| } | ||
| if (w && e.target) { | ||
| e.target = await ie(e.target); | ||
| } | ||
| const s = ["$ProgressPreference = 'SilentlyContinue';", "Start"]; | ||
| if (e.wait) { | ||
| s.push("-Wait"); | ||
| } | ||
| if (t) { | ||
| s.push(u.escapeArgument(t)); | ||
| if (e.target) { | ||
| o.push(e.target); | ||
| } | ||
| } else if (e.target) { | ||
| s.push(u.escapeArgument(e.target)); | ||
| } | ||
| if (o.length > 0) { | ||
| o = o.map((i) => u.escapeArgument(i)); | ||
| s.push("-ArgumentList", o.join(",")); | ||
| } | ||
| e.target = u.encodeCommand(s.join(" ")); | ||
| if (!e.wait) { | ||
| d.stdio = "ignore"; | ||
| } | ||
| } else { | ||
| if (t) { | ||
| n = t; | ||
| } else { | ||
| const s = !W || W === "/"; | ||
| let i = false; | ||
| try { | ||
| await v.access(k, L.X_OK); | ||
| i = true; | ||
| } catch { | ||
| } | ||
| const f = l.versions.electron ?? (g === "android" || s || !i); | ||
| n = f ? "xdg-open" : k; | ||
| } | ||
| if (o.length > 0) { | ||
| a.push(...o); | ||
| } | ||
| if (!e.wait) { | ||
| d.stdio = "ignore"; | ||
| d.detached = true; | ||
| } | ||
| } | ||
| if (g === "darwin" && o.length > 0) { | ||
| a.push("--args", ...o); | ||
| } | ||
| if (e.target) { | ||
| a.push(e.target); | ||
| } | ||
| const c = C.spawn(n, a, d); | ||
| if (e.wait) { | ||
| return new Promise((s, i) => { | ||
| c.once("error", i); | ||
| c.once("close", (f) => { | ||
| if (!e.allowNonzeroExitCode && f !== 0) { | ||
| i(new Error(`Exited with code ${f}`)); | ||
| return; | ||
| } | ||
| s(c); | ||
| }); | ||
| }); | ||
| } | ||
| if (r) { | ||
| return new Promise((s, i) => { | ||
| c.once("error", i); | ||
| c.once("spawn", () => { | ||
| c.once("close", (f) => { | ||
| c.off("error", i); | ||
| if (f !== 0) { | ||
| i(new Error(`Exited with code ${f}`)); | ||
| return; | ||
| } | ||
| c.unref(); | ||
| s(c); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| c.unref(); | ||
| return new Promise((s, i) => { | ||
| c.once("error", i); | ||
| c.once("spawn", () => { | ||
| c.off("error", i); | ||
| s(c); | ||
| }); | ||
| }); | ||
| }; | ||
| const ve = (e, r) => { | ||
| if (typeof e !== "string") { | ||
| throw new TypeError("Expected a `target`"); | ||
| } | ||
| return E({ | ||
| ...r, | ||
| target: e | ||
| }); | ||
| }; | ||
| const ke = (e, r) => { | ||
| if (typeof e !== "string" && !Array.isArray(e)) { | ||
| throw new TypeError("Expected a valid `name`"); | ||
| } | ||
| const { arguments: t = [] } = r ?? {}; | ||
| if (t !== void 0 && t !== null && !Array.isArray(t)) { | ||
| throw new TypeError("Expected `appArguments` as Array type"); | ||
| } | ||
| return E({ | ||
| ...r, | ||
| app: { | ||
| name: e, | ||
| arguments: t | ||
| } | ||
| }); | ||
| }; | ||
| function X(e) { | ||
| if (typeof e === "string" || Array.isArray(e)) { | ||
| return e; | ||
| } | ||
| const { [R]: r } = e; | ||
| if (!r) { | ||
| throw new Error(`${R} is not supported`); | ||
| } | ||
| return r; | ||
| } | ||
| function x({ [g]: e }, { wsl: r } = {}) { | ||
| if (r && w) { | ||
| return X(r); | ||
| } | ||
| if (!e) { | ||
| throw new Error(`${g} is not supported`); | ||
| } | ||
| return X(e); | ||
| } | ||
| const _ = { | ||
| browser: "browser", | ||
| browserPrivate: "browserPrivate" | ||
| }; | ||
| y(_, "chrome", () => x({ | ||
| darwin: "google chrome", | ||
| win32: "chrome", | ||
| // `chromium-browser` is the older deb package name used by Ubuntu/Debian before snap. | ||
| linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"] | ||
| }, { | ||
| 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"] | ||
| } | ||
| })); | ||
| y(_, "brave", () => x({ | ||
| darwin: "brave browser", | ||
| win32: "brave", | ||
| linux: ["brave-browser", "brave"] | ||
| }, { | ||
| wsl: { | ||
| ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe", | ||
| x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"] | ||
| } | ||
| })); | ||
| y(_, "firefox", () => x({ | ||
| darwin: "firefox", | ||
| win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`, | ||
| linux: "firefox" | ||
| }, { | ||
| wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe" | ||
| })); | ||
| y(_, "edge", () => x({ | ||
| darwin: "microsoft edge", | ||
| win32: "msedge", | ||
| linux: ["microsoft-edge", "microsoft-edge-dev"] | ||
| }, { | ||
| wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" | ||
| })); | ||
| y(_, "safari", () => x({ | ||
| darwin: "Safari" | ||
| })); | ||
| const Pe = ve; | ||
| ; | ||
| const be = (e) => { | ||
| let r = false; | ||
| return (...t) => { | ||
| if (!r) { | ||
| r = true; | ||
| return e(...t); | ||
| } | ||
| }; | ||
| }; | ||
| const K = function({ target: e = "http://localhost:8080", options: r = {} }) { | ||
| this.target = e; | ||
| this.options = r; | ||
| }; | ||
| K.prototype.apply = function(e) { | ||
| const r = be(() => Pe(this.target, this.options)); | ||
| e.hooks.done.tap("OpenBrowserPlugin", ({ compilation: t }) => { | ||
| if (!t.errors.length) { | ||
| r(); | ||
| } | ||
| }); | ||
| }; | ||
| const Be = K; | ||
| export { | ||
| Be as default | ||
| }; | ||
| import re from"node:process";import oe from"node:path";import{fileURLToPath as _e}from"node:url";import He from"node:child_process";import ke,{constants as De}from"node:fs/promises";import{promisify as de}from"node:util";import we from"node:child_process";import I,{constants as G}from"node:fs/promises";import U from"node:process";import me from"node:os";import E from"node:fs";import ae from"node:fs";import N from"node:fs";var b;function se(){try{return N.statSync("/.dockerenv"),!0}catch{return!1}}function ie(){try{return N.readFileSync("/proc/self/cgroup","utf8").includes("docker")}catch{return!1}}function B(){return b===void 0&&(b=se()||ie()),b}var C,ce=()=>{try{return ae.statSync("/run/.containerenv"),!0}catch{return!1}};function u(){return C===void 0&&(C=ce()||B()),C}var $=()=>{if(U.platform!=="linux")return!1;if(me.release().toLowerCase().includes("microsoft"))return!u();try{if(E.readFileSync("/proc/version","utf8").toLowerCase().includes("microsoft"))return!u()}catch{}return E.existsSync("/proc/sys/fs/binfmt_misc/WSLInterop")||E.existsSync("/run/WSL")?!u():!1},f=U.env.__IS_WSL_TEST__?$:$();import z from"node:process";import{Buffer as le}from"node:buffer";import{promisify as fe}from"node:util";import pe from"node:child_process";var ue=fe(pe.execFile),F=()=>`${z.env.SYSTEMROOT||z.env.windir||String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;var m=async(e,r={})=>{let{powerShellPath:o,...t}=r,n=m.encodeCommand(e);return ue(o??F(),[...m.argumentsPrefix,n],{encoding:"utf8",...t})};m.argumentsPrefix=["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-EncodedCommand"];m.encodeCommand=e=>le.from(e,"utf16le").toString("base64");m.escapeArgument=e=>`'${String(e).replaceAll("'","''")}'`;function R(e){for(let r of e.split(` | ||
| `)){if(/^\s*#/.test(r))continue;let o=/^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(r);if(o)return o.groups.mountPoint.trim().replaceAll(/^["']|["']$/g,"")}}var ge=de(we.execFile),he=(()=>{let e="/mnt/",r;return async function(){if(r)return r;let o="/etc/wsl.conf",t=!1;try{await I.access(o,G.F_OK),t=!0}catch{}if(!t)return e;let n=await I.readFile(o,{encoding:"utf8"}),i=R(n);return i===void 0?e:(r=i,r=r.endsWith("/")?r:`${r}/`,r)}})(),xe=async()=>`${await he()}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`,S=f?xe:F,X,K=async()=>(X??=(async()=>{try{let e=await S();return await I.access(e,G.X_OK),!0}catch{return!1}})(),X),V=async()=>{let e=await S(),r=String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`,{stdout:o}=await m(r,{powerShellPath:e});return o.trim()},Y=async e=>{if(/^[a-z]+:\/\//i.test(e))return e;try{let{stdout:r}=await ge("wslpath",["-aw",e],{encoding:"utf8"});return r.trim()}catch{return e}};function d(e,r,o){let t=n=>Object.defineProperty(e,r,{value:n,enumerable:!0,writable:!0});return Object.defineProperty(e,r,{configurable:!0,enumerable:!0,get(){let n=o();return t(n),n},set(n){t(n)}}),e}import{promisify as Oe}from"node:util";import _ from"node:process";import{execFile as Me}from"node:child_process";import{promisify as ye}from"node:util";import Se from"node:process";import{execFile as Pe}from"node:child_process";var ve=ye(Pe);async function O(){if(Se.platform!=="darwin")throw new Error("macOS only");let{stdout:e}=await ve("defaults",["read","com.apple.LaunchServices/com.apple.launchservices.secure","LSHandlers"]),o=/LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(e)?.groups.id??"com.apple.Safari";return o==="com.apple.safari"?"com.apple.Safari":o}import Ae from"node:process";import{promisify as be}from"node:util";import{execFile as Be,execFileSync as Sr}from"node:child_process";var Ce=be(Be);async function q(e,{humanReadableOutput:r=!0,signal:o}={}){if(Ae.platform!=="darwin")throw new Error("macOS only");let t=r?[]:["-ss"],n={};o&&(n.signal=o);let{stdout:i}=await Ce("osascript",["-e",e,t],n);return i.trim()}async function M(e){return q(`tell application "Finder" to set app_path to application file id "${e}" as string | ||
| tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`)}import{promisify as Ee}from"node:util";import{execFile as Fe}from"node:child_process";var Ie=Ee(Fe),P={MSEdgeHTM:{name:"Edge",id:"com.microsoft.edge"},MSEdgeBHTML:{name:"Edge Beta",id:"com.microsoft.edge.beta"},MSEdgeDHTML:{name:"Edge Dev",id:"com.microsoft.edge.dev"},AppXq0fevzme2pys62n3e0fbqa7peapykr8v:{name:"Edge",id:"com.microsoft.edge.old"},ChromeHTML:{name:"Chrome",id:"com.google.chrome"},ChromeBHTML:{name:"Chrome Beta",id:"com.google.chrome.beta"},ChromeDHTML:{name:"Chrome Dev",id:"com.google.chrome.dev"},ChromiumHTM:{name:"Chromium",id:"org.chromium.Chromium"},BraveHTML:{name:"Brave",id:"com.brave.Browser"},BraveBHTML:{name:"Brave Beta",id:"com.brave.Browser.beta"},BraveDHTML:{name:"Brave Dev",id:"com.brave.Browser.dev"},BraveSSHTM:{name:"Brave Nightly",id:"com.brave.Browser.nightly"},FirefoxURL:{name:"Firefox",id:"org.mozilla.firefox"},OperaStable:{name:"Opera",id:"com.operasoftware.Opera"},VivaldiHTM:{name:"Vivaldi",id:"com.vivaldi.Vivaldi"},"IE.HTTP":{name:"Internet Explorer",id:"com.microsoft.ie"}},L=new Map(Object.entries(P)),T=class extends Error{};async function W(e=Ie){let{stdout:r}=await e("reg",["QUERY"," HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice","/v","ProgId"]),o=/ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(r);if(!o)throw new T(`Cannot find Windows browser in stdout: ${JSON.stringify(r)}`);let{id:t}=o.groups,n=t.lastIndexOf("."),i=t.lastIndexOf("-"),p=n===-1?void 0:t.slice(0,n),y=i===-1?void 0:t.slice(0,i);return P[t]??P[p]??P[y]??{name:t,id:t}}var Te=Oe(Me),Le=e=>e.toLowerCase().replaceAll(/(?:^|\s|-)\S/g,r=>r.toUpperCase());async function H(){if(_.platform==="darwin"){let e=await O();return{name:await M(e),id:e}}if(_.platform==="linux"){let{stdout:e}=await Te("xdg-mime",["query","default","x-scheme-handler/http"]),r=e.trim();return{name:Le(r.replace(/.desktop$/,"").replace("-"," ")),id:r}}if(_.platform==="win32")return W();throw new Error("Only macOS, Linux, and Windows are supported")}import k from"node:process";var We=!!(k.env.SSH_CONNECTION||k.env.SSH_CLIENT||k.env.SSH_TTY),J=We;var v=Symbol("fallbackAttempt"),D=import.meta.url?oe.dirname(_e(import.meta.url)):"",Q=oe.join(D,"xdg-open"),{platform:w,arch:Z}=re,j=async(e,r)=>{if(e.length===0)return;let o=[];for(let t of e)try{return await r(t)}catch(n){o.push(n)}throw new AggregateError(o,"Failed to open in all supported apps")},A=async e=>{e={wait:!1,background:!1,newInstance:!1,allowNonzeroExitCode:!1,...e};let r=e[v]===!0;if(delete e[v],Array.isArray(e.app))return j(e.app,s=>A({...e,app:s,[v]:!0}));let{name:o,arguments:t=[]}=e.app??{};if(t=[...t],Array.isArray(o))return j(o,s=>A({...e,app:{name:s,arguments:t},[v]:!0}));if(o==="browser"||o==="browserPrivate"){let s={"com.google.chrome":"chrome","google-chrome.desktop":"chrome","com.brave.browser":"brave","org.mozilla.firefox":"firefox","firefox.desktop":"firefox","com.microsoft.msedge":"edge","com.microsoft.edge":"edge","com.microsoft.edgemac":"edge","microsoft-edge.desktop":"edge","com.apple.safari":"safari"},a={chrome:"--incognito",brave:"--incognito",firefox:"--private-window",edge:"--inPrivate"},l;if(f){let h=await V();l=L.get(h)??{}}else l=await H();if(l.id in s){let h=s[l.id.toLowerCase()];if(o==="browserPrivate"){if(h==="safari")throw new Error("Safari doesn't support opening in private mode via command line");t.push(a[h])}return A({...e,app:{name:g[h],arguments:t}})}throw new Error(`${l.name} is not supported as a default browser`)}let n,i=[],p={},y=!1;if(f&&!u()&&!J&&!o&&(y=await K()),w==="darwin")n="open",e.wait&&i.push("--wait-apps"),e.background&&i.push("--background"),e.newInstance&&i.push("--new"),o&&i.push("-a",o);else if(w==="win32"||y){n=await S(),i.push(...m.argumentsPrefix),f||(p.windowsVerbatimArguments=!0),f&&e.target&&(e.target=await Y(e.target));let s=["$ProgressPreference = 'SilentlyContinue';","Start"];e.wait&&s.push("-Wait"),o?(s.push(m.escapeArgument(o)),e.target&&t.push(e.target)):e.target&&s.push(m.escapeArgument(e.target)),t.length>0&&(t=t.map(a=>m.escapeArgument(a)),s.push("-ArgumentList",t.join(","))),e.target=m.encodeCommand(s.join(" ")),e.wait||(p.stdio="ignore")}else{if(o)n=o;else{let s=!D||D==="/",a=!1;try{await ke.access(Q,De.X_OK),a=!0}catch{}n=re.versions.electron??(w==="android"||s||!a)?"xdg-open":Q}t.length>0&&i.push(...t),e.wait||(p.stdio="ignore",p.detached=!0)}w==="darwin"&&t.length>0&&i.push("--args",...t),e.target&&i.push(e.target);let c=He.spawn(n,i,p);return e.wait?new Promise((s,a)=>{c.once("error",a),c.once("close",l=>{if(!e.allowNonzeroExitCode&&l!==0){a(new Error(`Exited with code ${l}`));return}s(c)})}):r?new Promise((s,a)=>{c.once("error",a),c.once("spawn",()=>{c.once("close",l=>{if(c.off("error",a),l!==0){a(new Error(`Exited with code ${l}`));return}c.unref(),s(c)})})}):(c.unref(),new Promise((s,a)=>{c.once("error",a),c.once("spawn",()=>{c.off("error",a),s(c)})}))},Ne=(e,r)=>{if(typeof e!="string")throw new TypeError("Expected a `target`");return A({...r,target:e})};function ee(e){if(typeof e=="string"||Array.isArray(e))return e;let{[Z]:r}=e;if(!r)throw new Error(`${Z} is not supported`);return r}function x({[w]:e},{wsl:r}={}){if(r&&f)return ee(r);if(!e)throw new Error(`${w} is not supported`);return ee(e)}var g={browser:"browser",browserPrivate:"browserPrivate"};d(g,"chrome",()=>x({darwin:"google chrome",win32:"chrome",linux:["google-chrome","google-chrome-stable","chromium","chromium-browser"]},{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"]}}));d(g,"brave",()=>x({darwin:"brave browser",win32:"brave",linux:["brave-browser","brave"]},{wsl:{ia32:"/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",x64:["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe","/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]}}));d(g,"firefox",()=>x({darwin:"firefox",win32:String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,linux:"firefox"},{wsl:"/mnt/c/Program Files/Mozilla Firefox/firefox.exe"}));d(g,"edge",()=>x({darwin:"microsoft edge",win32:"msedge",linux:["microsoft-edge","microsoft-edge-dev"]},{wsl:"/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"}));d(g,"safari",()=>x({darwin:"Safari"}));var te=Ne;var $e=e=>{let r=!1;return(...o)=>{if(!r)return r=!0,e(...o)}},ne=function({target:e="http://localhost:8080",options:r={}}){this.target=e,this.options=r};ne.prototype.apply=function(e){let r=$e(()=>te(this.target,this.options));e.hooks.done.tap("OpenBrowserPlugin",({compilation:o})=>{o.errors.length||r()})};var Jr=ne;export{Jr as default}; |
+2
-2
| { | ||
| "name": "@huxy/open-browser-webpack-plugin", | ||
| "version": "1.1.4", | ||
| "version": "1.1.5", | ||
| "title": "open-browser-webpack-plugin", | ||
@@ -31,5 +31,5 @@ "feature": "0.0.1", | ||
| "engines": { | ||
| "node": ">=18.0.0" | ||
| "node": ">=22.0.0" | ||
| }, | ||
| "author": "yiru" | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances
1
-66.67%1
-50%13600
-26%43
-93.42%2
100%