edge-paths
Advanced tools
Comparing version 2.1.0 to 2.2.0
113
dist/main.js
@@ -6,6 +6,31 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getEdgeCanaryPath = exports.getEdgeBetaPath = exports.getEdgeDevPath = exports.getEdgePath = void 0; | ||
exports.getAnyEdgeStable = exports.getAnyEdgeLatest = exports.getEdgeCanaryPath = exports.getEdgeBetaPath = exports.getEdgeDevPath = exports.getEdgePath = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const which_1 = __importDefault(require("which")); | ||
let platform = process.platform; | ||
function getEdgeLinux(binaryNames) { | ||
if (process.platform !== "linux") { | ||
return null; | ||
} | ||
if (!Array.isArray(binaryNames)) { | ||
binaryNames = [binaryNames]; | ||
} | ||
let paths = []; | ||
for (let name of binaryNames) { | ||
try { | ||
let path = which_1.default.sync(name); | ||
return path; | ||
} | ||
catch (e) { | ||
paths.push(name); | ||
} | ||
} | ||
throw { | ||
package: "edge-paths", | ||
message: "Edge browser not found. Please recheck your installation. \ | ||
Here are list of executable we tried to search", | ||
paths, | ||
}; | ||
} | ||
function getEdgeExe(edgeDirName) { | ||
@@ -17,10 +42,8 @@ if (process.platform !== "win32") { | ||
let suffix = `\\Microsoft\\${edgeDirName}\\Application\\msedge.exe`; | ||
let prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"]]; | ||
let prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"]].filter((v) => !!v); | ||
for (let prefix of prefixes) { | ||
if (prefix) { | ||
let edgePath = path_1.default.join(prefix, suffix); | ||
paths.push(edgePath); | ||
if (fs_1.default.existsSync(edgePath)) { | ||
return edgePath; | ||
} | ||
let edgePath = path_1.default.join(prefix, suffix); | ||
paths.push(edgePath); | ||
if (fs_1.default.existsSync(edgePath)) { | ||
return edgePath; | ||
} | ||
@@ -47,10 +70,5 @@ } | ||
} | ||
function throwInvalidPlatformError() { | ||
throw { | ||
package: "edge-paths", | ||
message: "Your platform is not supported. Only mac and windows are supported currently", | ||
}; | ||
} | ||
function getEdgePath() { | ||
let edge = { | ||
linux: getEdgeLinux(["edge"]), | ||
darwin: getEdgeDarwin("/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"), | ||
@@ -67,2 +85,3 @@ win32: getEdgeExe("Edge"), | ||
let edgeDev = { | ||
linux: getEdgeLinux("microsoft-edge-dev"), | ||
darwin: getEdgeDarwin("/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev"), | ||
@@ -99,27 +118,69 @@ win32: getEdgeExe("Edge Dev"), | ||
exports.getEdgeCanaryPath = getEdgeCanaryPath; | ||
if (require.main === module) { | ||
function getAnyEdgeLatest() { | ||
try { | ||
console.log("Edge Beta", getEdgeBetaPath()); | ||
return getEdgeCanaryPath(); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
catch (e) { } | ||
try { | ||
return getEdgeDevPath(); | ||
} | ||
catch (e) { } | ||
try { | ||
console.log("Edge Canary", getEdgeCanaryPath()); | ||
return getEdgeBetaPath(); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
catch (e) { } | ||
try { | ||
return getEdgeDevPath(); | ||
} | ||
catch (e) { } | ||
throw { | ||
package: "edge-paths", | ||
message: `Unable to find any path`, | ||
}; | ||
} | ||
exports.getAnyEdgeLatest = getAnyEdgeLatest; | ||
function getAnyEdgeStable() { | ||
try { | ||
console.log("Edge Dev", getEdgeDevPath()); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
return getEdgePath(); | ||
} | ||
try { | ||
console.log("Edge", getEdgePath()); | ||
return getEdgeBetaPath(); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
catch (e) { } | ||
try { | ||
return getEdgeDevPath(); | ||
} | ||
catch (e) { } | ||
try { | ||
return getEdgeCanaryPath(); | ||
} | ||
catch (e) { } | ||
throw { | ||
package: "edge-paths", | ||
message: `Unable to find any path`, | ||
}; | ||
} | ||
exports.getAnyEdgeStable = getAnyEdgeStable; | ||
function throwInvalidPlatformError() { | ||
throw { | ||
package: "edge-paths", | ||
message: "Your platform is not supported. Only mac and windows are supported currently", | ||
}; | ||
} | ||
if (require.main === module) { | ||
function findEdge(func) { | ||
try { | ||
let path = func(); | ||
console.log("Found path", path); | ||
} | ||
catch (e) { | ||
console.log("Error on finding path", e); | ||
} | ||
} | ||
findEdge(() => getEdgeBetaPath()); | ||
findEdge(() => getEdgeCanaryPath()); | ||
findEdge(() => getEdgeDevPath()); | ||
findEdge(() => getEdgePath()); | ||
} |
@@ -1,6 +0,34 @@ | ||
let { getEdgeBetaPath, getEdgeCanaryPath, getEdgeDevPath, getEdgePath } = require(".") // Replace with require("edge-paths") | ||
let { | ||
getEdgeBetaPath, | ||
getEdgeCanaryPath, | ||
getEdgeDevPath, | ||
getEdgePath, | ||
getAnyEdgeStable, | ||
getAnyEdgeLatest, | ||
} = require(".") | ||
// don't forget to replace above with following line | ||
// let { getEdgeBetaPath, getEdgeCanaryPath, getEdgeDevPath, getEdgePath } = require("edge-paths") | ||
console.log(getEdgeBetaPath()) | ||
console.log(getEdgeCanaryPath()) | ||
console.log(getEdgeDevPath()) | ||
console.log(getEdgePath()) | ||
// Here is one naive example. Uncomment following line to test | ||
// console.log(getEdgeBetaPath()) | ||
// console.log(getEdgeCanaryPath()) | ||
// console.log(getEdgeDevPath()) | ||
// console.log(getEdgePath()) | ||
// Here is another example with try catch | ||
// This find edge function just ignore the error | ||
function findEdge(func) { | ||
try { | ||
let path = func() | ||
console.log("Found path", path) | ||
} catch (e) { | ||
console.log("Error on finding path", e) | ||
} | ||
} | ||
findEdge(() => getEdgeBetaPath()) | ||
findEdge(() => getEdgeCanaryPath()) | ||
findEdge(() => getEdgeDevPath()) | ||
findEdge(() => getEdgePath()) | ||
findEdge(() => getAnyEdgeStable()) | ||
findEdge(() => getAnyEdgeLatest()) |
@@ -1,2 +0,3 @@ | ||
import { getEdgeBetaPath, getEdgeCanaryPath, getEdgeDevPath, getEdgePath } from "." | ||
// Replace following line "." with "edge-paths" if you are using it as package | ||
import { getEdgeBetaPath, getEdgeCanaryPath, getEdgeDevPath, getEdgePath, getAnyEdgeStable, getAnyEdgeLatest } from "." | ||
@@ -7,1 +8,3 @@ console.log(getEdgeBetaPath()) | ||
console.log(getEdgePath()) | ||
console.log(getAnyEdgeLatest()) | ||
console.log(getAnyEdgeLatest()) |
{ | ||
"name": "edge-paths", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Get the paths of edge browser easily", | ||
@@ -19,3 +19,6 @@ "main": "dist/main.js", | ||
"typescript": "^3.9.3" | ||
}, | ||
"dependencies": { | ||
"which": "^2.0.2" | ||
} | ||
} |
# Edge Paths | ||
[![npm version](https://img.shields.io/npm/v/edge-paths.svg)](https://www.npmjs.com/package/edge-paths) | ||
[![Downloads](https://img.shields.io/npm/dm/edge-paths.svg)](https://npmjs.com/edge-paths) | ||
[![Install size](https://packagephobia.now.sh/badge?p=edge-paths)](https://packagephobia.now.sh/result?p=edge-paths) | ||
![Test Edge Paths](https://github.com/shirshak55/edge-paths/workflows/Test%20Edge%20Paths/badge.svg) | ||
Possible paths or binary names of [Edge](https://www.microsoft.com/en-us/edge) in the current platform | ||
Javascript | ||
### Why? | ||
- Well Documented | ||
- Well Tested | ||
- Used by popular players | ||
- Written with Love <3 | ||
- Fully open sourced | ||
### Usage | ||
- At the moment linux support is only avail for dev channel. Once canary, beta and stable version are release | ||
we shall update the package. | ||
###### Javascript | ||
```javascript | ||
let { getEdgeBetaPath, getEdgeCanaryPath, getEdgeDevPath, getEdgePath } = require("edge-paths") | ||
let { | ||
getEdgeBetaPath, | ||
getEdgeCanaryPath, | ||
getEdgeDevPath, | ||
getEdgePath, | ||
getAnyEdgeStable, | ||
getAnyEdgeLatest, | ||
} = require("edge-paths") | ||
@@ -16,3 +39,9 @@ console.log(getEdgeBetaPath()) | ||
console.log(getEdgePath()) | ||
// console.log(getAnyEdgeStable()) | ||
// console.log(getAnyEdgeLatest()) | ||
``` | ||
The output shall look like this according to your installation | ||
```javascript | ||
// On OSX | ||
@@ -29,5 +58,11 @@ // /Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta | ||
// C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe | ||
// On Linux | ||
// Beta edge not avail yet | ||
// Canary not avail | ||
// /usr/bin/microsoft-edge-dev | ||
// Stable not avail | ||
``` | ||
Typescript | ||
###### Typescript | ||
@@ -47,10 +82,8 @@ ```typescript | ||
``` | ||
```bash | ||
$ npm install edge-paths | ||
npm install edge-paths | ||
// or | ||
or | ||
yarn add edge-paths | ||
$ yarn add edge-paths | ||
``` | ||
@@ -61,7 +94,24 @@ | ||
```javascript | ||
const edgePaths = require("edge-paths") | ||
let { | ||
getEdgeBetaPath, | ||
getEdgeCanaryPath, | ||
getEdgeDevPath, | ||
getEdgePath, | ||
getAnyEdgeStable, | ||
getAnyEdgeLatest, | ||
} = require("edge-paths") | ||
``` | ||
- `getAnyEdgeStable` or `getAnyEdgeLatest` might be more useful if you don't want any specific version. | ||
## Used By | ||
- [devtools](https://www.npmjs.com/package/devtools) | ||
- Please send PR if you are using edge paths. We will be accepting first 10 request. | ||
## License | ||
[MIT License](./LICENSE) © 2020 Shirshak Bajgain | ||
[MIT License](./LICENSE) | ||
© 2020 Shirshak Bajgain |
146
src/main.ts
import fs from "fs" | ||
import path from "path" | ||
import which from "which" | ||
let platform = process.platform | ||
// Return location of msedge.exe file for a given Edge directory (available: "Edge", "Edge Dev","Edge Beta","Edge Canary"). | ||
function getEdgeExe(edgeDirName: string) { | ||
// Only run these checks on win32 | ||
function getEdgeLinux(binaryNames: Array<string> | string): string | null { | ||
if (process.platform !== "linux") { | ||
return null | ||
} | ||
if (!Array.isArray(binaryNames)) { | ||
binaryNames = [binaryNames] | ||
} | ||
let paths = [] | ||
for (let name of binaryNames) { | ||
try { | ||
let path = which.sync(name) | ||
return path | ||
} catch (e) { | ||
// This means path doesn't exists | ||
paths.push(name) | ||
} | ||
} | ||
throw { | ||
package: "edge-paths", | ||
message: | ||
"Edge browser not found. Please recheck your installation. \ | ||
Here are list of executable we tried to search", | ||
paths, | ||
} | ||
} | ||
function getEdgeExe(edgeDirName: "Edge" | "Edge Dev" | "Edge Beta" | "Edge SxS"): string | null { | ||
if (process.platform !== "win32") { | ||
return null | ||
} | ||
let paths = [] | ||
let suffix = `\\Microsoft\\${edgeDirName}\\Application\\msedge.exe` | ||
let prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"]] | ||
let prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env["PROGRAMFILES(X86)"]].filter( | ||
(v) => !!v, | ||
) | ||
for (let prefix of prefixes) { | ||
if (prefix) { | ||
let edgePath = path.join(prefix, suffix) | ||
paths.push(edgePath) | ||
if (fs.existsSync(edgePath)) { | ||
return edgePath | ||
} | ||
let edgePath = path.join(prefix!, suffix) | ||
paths.push(edgePath) | ||
if (fs.existsSync(edgePath)) { | ||
return edgePath | ||
} | ||
@@ -33,3 +63,3 @@ } | ||
function getEdgeDarwin(defaultPath: string) { | ||
function getEdgeDarwin(defaultPath: string): string | null { | ||
if (process.platform !== "darwin") { | ||
@@ -39,3 +69,2 @@ return null | ||
// let homePath = path.join(process.env.HOME!, defaultPath) | ||
if (fs.existsSync(defaultPath)) { | ||
@@ -52,13 +81,5 @@ return defaultPath | ||
function throwInvalidPlatformError() { | ||
throw { | ||
package: "edge-paths", | ||
message: "Your platform is not supported. Only mac and windows are supported currently", | ||
} | ||
} | ||
export function getEdgePath() { | ||
let edge = { | ||
// Todo Uncomment once edge gets released for linux | ||
// linux: getBin(["edge", "edge-stable"]), | ||
linux: getEdgeLinux(["edge"]), | ||
darwin: getEdgeDarwin("/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"), | ||
@@ -77,3 +98,3 @@ win32: getEdgeExe("Edge"), | ||
let edgeDev = { | ||
// linux: getBin(["edge", "edge-stable"]), | ||
linux: getEdgeLinux("microsoft-edge-dev"), | ||
darwin: getEdgeDarwin("/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev"), | ||
@@ -118,23 +139,78 @@ win32: getEdgeExe("Edge Dev"), | ||
if (require.main === module) { | ||
// This will try to get any edge from bleeding edge to most stable version | ||
export function getAnyEdgeLatest(): string { | ||
try { | ||
console.log("Edge Beta", getEdgeBetaPath()) | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
return getEdgeCanaryPath() | ||
} catch (e) {} | ||
try { | ||
console.log("Edge Canary", getEdgeCanaryPath()) | ||
} catch (e) { | ||
console.log(e) | ||
return getEdgeDevPath() | ||
} catch (e) {} | ||
try { | ||
return getEdgeBetaPath() | ||
} catch (e) {} | ||
try { | ||
return getEdgeDevPath() | ||
} catch (e) {} | ||
throw { | ||
package: "edge-paths", | ||
message: `Unable to find any path`, | ||
} | ||
} | ||
// This will try to get edge from stable version to bleeding version | ||
// Useful for playwright, puppeteer related stuff | ||
export function getAnyEdgeStable(): string { | ||
try { | ||
console.log("Edge Dev", getEdgeDevPath()) | ||
} catch (e) { | ||
console.log(e) | ||
return getEdgePath() | ||
} | ||
try { | ||
console.log("Edge", getEdgePath()) | ||
} catch (e) { | ||
console.log(e) | ||
return getEdgeBetaPath() | ||
} catch (e) {} | ||
try { | ||
return getEdgeDevPath() | ||
} catch (e) {} | ||
try { | ||
return getEdgeCanaryPath() | ||
} catch (e) {} | ||
throw { | ||
package: "edge-paths", | ||
message: `Unable to find any path`, | ||
} | ||
} | ||
// Helpers | ||
function throwInvalidPlatformError() { | ||
throw { | ||
package: "edge-paths", | ||
message: "Your platform is not supported. Only mac and windows are supported currently", | ||
} | ||
} | ||
// With this you can directly do node dist/main.js | ||
// (dist/main.js) instead of src/main.ts because | ||
// typescript compiler ultimately returns javascript not typescript | ||
// However you can try ts node if you want to execute | ||
// typescript directly | ||
if (require.main === module) { | ||
function findEdge(func: () => undefined) { | ||
try { | ||
let path = func() | ||
console.log("Found path", path) | ||
} catch (e) { | ||
console.log("Error on finding path", e) | ||
} | ||
} | ||
findEdge(() => getEdgeBetaPath()) | ||
findEdge(() => getEdgeCanaryPath()) | ||
findEdge(() => getEdgeDevPath()) | ||
findEdge(() => getEdgePath()) | ||
} |
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
21106
11
456
114
1
1
+ Addedwhich@^2.0.2
+ Addedisexe@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)