firefox-location2 2.0.0 → 2.0.1
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/README.md +19 -11
- package/bin.js +4 -1
- package/dist/index.cjs +37 -19
- package/dist/index.d.ts +1 -1
- package/dist/index.js +37 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
|
|
12
12
|
<img alt="Firefox" align="right" src="https://cdn.jsdelivr.net/gh/extension-js/media@db5deb23fbfa85530f8146718812972998e13a4d/browser_logos/svg/firefox.svg" width="10.5%" />
|
|
13
13
|
|
|
14
|
-
*
|
|
14
|
+
* By default checks only `stable`. Optionally can cascade to `esr` / `developer edition` / `nightly`.
|
|
15
15
|
* Supports macOS / Windows / Linux
|
|
16
16
|
* Works both as an ES module or CommonJS
|
|
17
17
|
|
|
18
18
|
## Support table
|
|
19
19
|
|
|
20
|
-
This table lists the default locations where Firefox is typically installed for each supported platform and channel.
|
|
20
|
+
This table lists the default locations where Firefox is typically installed for each supported platform and channel. By default, only the Stable channel is checked. When fallback is enabled, the package checks these paths (in order) and returns the first one found.
|
|
21
21
|
|
|
22
22
|
<table>
|
|
23
23
|
<thead>
|
|
@@ -153,26 +153,34 @@ This table lists the default locations where Firefox is typically installed for
|
|
|
153
153
|
</tbody>
|
|
154
154
|
</table>
|
|
155
155
|
|
|
156
|
-
Returns the first existing path found, or <code>null</code> if none are found.
|
|
156
|
+
Returns the first existing path found (given selected channels), or <code>null</code> if none are found.
|
|
157
157
|
|
|
158
158
|
Note: On Linux, the module first tries to resolve binaries on <code>$PATH</code> (using <code>which</code>) for the common channels listed above, then falls back to checking common filesystem locations like <code>/usr/bin/firefox</code>, <code>/usr/local/bin/firefox</code>, <code>/snap/bin/firefox</code>, and <code>/opt/firefox/firefox</code>.
|
|
159
159
|
|
|
160
160
|
## Usage
|
|
161
161
|
|
|
162
|
-
**Via Node.js:**
|
|
162
|
+
**Via Node.js (strict by default):**
|
|
163
163
|
|
|
164
164
|
```js
|
|
165
165
|
import firefoxLocation from "firefox-location2";
|
|
166
166
|
|
|
167
|
+
// Strict (Stable only)
|
|
167
168
|
console.log(firefoxLocation());
|
|
168
|
-
// /Applications/Firefox.app/Contents/MacOS/firefox
|
|
169
|
+
// => "/Applications/Firefox.app/Contents/MacOS/firefox" or null
|
|
170
|
+
|
|
171
|
+
// Enable fallback (Stable / ESR / Developer Edition / Nightly)
|
|
172
|
+
console.log(firefoxLocation(true));
|
|
173
|
+
// => first found among Stable/ESR/Developer/Nightly or null
|
|
169
174
|
```
|
|
170
175
|
|
|
171
176
|
**Via CLI:**
|
|
172
177
|
|
|
173
178
|
```bash
|
|
174
179
|
npx firefox-location2
|
|
175
|
-
#
|
|
180
|
+
# Strict (Stable only)
|
|
181
|
+
|
|
182
|
+
npx firefox-location2 --fallback
|
|
183
|
+
# Enable cascade (Stable / ESR / Developer / Nightly)
|
|
176
184
|
```
|
|
177
185
|
|
|
178
186
|
## Planned enhancements
|
|
@@ -184,12 +192,12 @@ npx firefox-location2
|
|
|
184
192
|
|
|
185
193
|
## Related projects
|
|
186
194
|
|
|
187
|
-
* [chrome-location2](https://github.com/hughsk/chrome-location2)
|
|
188
|
-
* [edge-location](https://github.com/cezaraugusto/edge-location)
|
|
189
|
-
* [firefox-location](https://github.com/hughsk/firefox-location)
|
|
190
195
|
* [brave-location](https://github.com/cezaraugusto/brave-location)
|
|
191
|
-
* [
|
|
192
|
-
* [
|
|
196
|
+
* [chrome-location2](https://github.com/cezaraugusto/chrome-location2)
|
|
197
|
+
* [edge-location](https://github.com/cezaraugusto/edge-location)
|
|
198
|
+
* [opera-location2](https://github.com/cezaraugusto/opera-location2)
|
|
199
|
+
* [vivaldi-location2](https://github.com/cezaraugusto/vivaldi-location2)
|
|
200
|
+
* [yandex-location2](https://github.com/cezaraugusto/yandex-location2)
|
|
193
201
|
|
|
194
202
|
## License
|
|
195
203
|
|
package/bin.js
CHANGED
|
@@ -3,4 +3,7 @@
|
|
|
3
3
|
const locateFirefox =
|
|
4
4
|
require('./dist/index.cjs').default || require('./dist/index.cjs');
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const argv = process.argv.slice(2);
|
|
7
|
+
const allowFallback = argv.includes('--fallback') || argv.includes('-f');
|
|
8
|
+
|
|
9
|
+
console.log(locateFirefox(allowFallback));
|
package/dist/index.cjs
CHANGED
|
@@ -43,7 +43,10 @@ const external_os_namespaceObject = require("os");
|
|
|
43
43
|
var external_os_default = /*#__PURE__*/ __webpack_require__.n(external_os_namespaceObject);
|
|
44
44
|
const external_which_namespaceObject = require("which");
|
|
45
45
|
var external_which_default = /*#__PURE__*/ __webpack_require__.n(external_which_namespaceObject);
|
|
46
|
-
function locateFirefox(
|
|
46
|
+
function locateFirefox(allowFallbackOrDeps, depsMaybe) {
|
|
47
|
+
const isBoolean = 'boolean' == typeof allowFallbackOrDeps;
|
|
48
|
+
const allowFallback = isBoolean ? allowFallbackOrDeps : false;
|
|
49
|
+
const deps = isBoolean ? depsMaybe : allowFallbackOrDeps;
|
|
47
50
|
const f = (null == deps ? void 0 : deps.fs) ?? external_fs_default();
|
|
48
51
|
const w = (null == deps ? void 0 : deps.which) ?? external_which_default();
|
|
49
52
|
const o = (null == deps ? void 0 : deps.os) ?? external_os_default();
|
|
@@ -54,34 +57,42 @@ function locateFirefox(deps) {
|
|
|
54
57
|
const win = 'win32' === platform;
|
|
55
58
|
const other = !osx && !win;
|
|
56
59
|
if (other) {
|
|
57
|
-
const
|
|
58
|
-
'firefox'
|
|
60
|
+
const stable = [
|
|
61
|
+
'firefox'
|
|
62
|
+
];
|
|
63
|
+
const fallbacks = [
|
|
59
64
|
'firefox-esr',
|
|
60
65
|
'firefox-developer-edition',
|
|
61
66
|
'firefox-devedition',
|
|
62
67
|
'firefox-nightly'
|
|
63
68
|
];
|
|
69
|
+
const candidates = allowFallback ? [
|
|
70
|
+
...stable,
|
|
71
|
+
...fallbacks
|
|
72
|
+
] : stable;
|
|
64
73
|
for (const cmd of candidates)try {
|
|
65
74
|
const resolved = w.sync(cmd);
|
|
66
75
|
if (resolved) return resolved;
|
|
67
76
|
} catch (_) {}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
if (allowFallback) {
|
|
78
|
+
const linuxPaths = [
|
|
79
|
+
'/usr/bin/firefox',
|
|
80
|
+
'/usr/local/bin/firefox',
|
|
81
|
+
'/usr/lib/firefox/firefox',
|
|
82
|
+
'/snap/bin/firefox',
|
|
83
|
+
'/opt/firefox/firefox',
|
|
84
|
+
'/usr/local/firefox/firefox',
|
|
85
|
+
p.join(o.homedir(), 'bin', 'firefox'),
|
|
86
|
+
p.join(o.homedir(), 'Downloads', 'firefox', 'firefox'),
|
|
87
|
+
p.join(o.homedir(), '.local', 'share', 'flatpak', 'exports', 'bin', 'org.mozilla.firefox'),
|
|
88
|
+
'/var/lib/flatpak/exports/bin/org.mozilla.firefox'
|
|
89
|
+
];
|
|
90
|
+
for (const linuxPath of linuxPaths)if (f.existsSync(linuxPath)) return linuxPath;
|
|
91
|
+
}
|
|
81
92
|
return null;
|
|
82
93
|
}
|
|
83
94
|
if (osx) {
|
|
84
|
-
const
|
|
95
|
+
const appsAll = [
|
|
85
96
|
{
|
|
86
97
|
app: 'Firefox.app',
|
|
87
98
|
exec: 'firefox'
|
|
@@ -99,6 +110,9 @@ function locateFirefox(deps) {
|
|
|
99
110
|
exec: 'firefox'
|
|
100
111
|
}
|
|
101
112
|
];
|
|
113
|
+
const apps = allowFallback ? appsAll : [
|
|
114
|
+
appsAll[0]
|
|
115
|
+
];
|
|
102
116
|
const systemBase = '/Applications';
|
|
103
117
|
const userBase = p.join(o.homedir(), 'Applications');
|
|
104
118
|
for (const { app, exec } of apps){
|
|
@@ -115,17 +129,20 @@ function locateFirefox(deps) {
|
|
|
115
129
|
env.PROGRAMFILES,
|
|
116
130
|
env['PROGRAMFILES(X86)']
|
|
117
131
|
].filter(Boolean);
|
|
118
|
-
const
|
|
132
|
+
const suffixesAll = [
|
|
119
133
|
p.join('Mozilla Firefox', 'firefox.exe'),
|
|
120
134
|
p.join('Mozilla Firefox ESR', 'firefox.exe'),
|
|
121
135
|
p.join('Mozilla Firefox Developer Edition', 'firefox.exe'),
|
|
122
136
|
p.join('Firefox Nightly', 'firefox.exe')
|
|
123
137
|
];
|
|
138
|
+
const suffixes = allowFallback ? suffixesAll : [
|
|
139
|
+
suffixesAll[0]
|
|
140
|
+
];
|
|
124
141
|
for (const prefix of prefixes)for (const suffix of suffixes){
|
|
125
142
|
const exePath = p.join(prefix, suffix);
|
|
126
143
|
if (f.existsSync(exePath)) return exePath;
|
|
127
144
|
}
|
|
128
|
-
const
|
|
145
|
+
const defaultPathsAll = [
|
|
129
146
|
'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
|
|
130
147
|
'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe',
|
|
131
148
|
'C:\\Program Files\\Mozilla Firefox ESR\\firefox.exe',
|
|
@@ -135,6 +152,7 @@ function locateFirefox(deps) {
|
|
|
135
152
|
'C:\\Program Files\\Firefox Nightly\\firefox.exe',
|
|
136
153
|
'C:\\Program Files (x86)\\Firefox Nightly\\firefox.exe'
|
|
137
154
|
];
|
|
155
|
+
const defaultPaths = allowFallback ? defaultPathsAll : defaultPathsAll.slice(0, 2);
|
|
138
156
|
for (const defaultPath of defaultPaths)if (f.existsSync(defaultPath)) return defaultPath;
|
|
139
157
|
return null;
|
|
140
158
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,7 +2,10 @@ import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE_os__ from "os";
|
|
4
4
|
import * as __WEBPACK_EXTERNAL_MODULE_which__ from "which";
|
|
5
|
-
function locateFirefox(
|
|
5
|
+
function locateFirefox(allowFallbackOrDeps, depsMaybe) {
|
|
6
|
+
const isBoolean = 'boolean' == typeof allowFallbackOrDeps;
|
|
7
|
+
const allowFallback = isBoolean ? allowFallbackOrDeps : false;
|
|
8
|
+
const deps = isBoolean ? depsMaybe : allowFallbackOrDeps;
|
|
6
9
|
const f = (null == deps ? void 0 : deps.fs) ?? __WEBPACK_EXTERNAL_MODULE_fs__["default"];
|
|
7
10
|
const w = (null == deps ? void 0 : deps.which) ?? __WEBPACK_EXTERNAL_MODULE_which__["default"];
|
|
8
11
|
const o = (null == deps ? void 0 : deps.os) ?? __WEBPACK_EXTERNAL_MODULE_os__["default"];
|
|
@@ -13,34 +16,42 @@ function locateFirefox(deps) {
|
|
|
13
16
|
const win = 'win32' === platform;
|
|
14
17
|
const other = !osx && !win;
|
|
15
18
|
if (other) {
|
|
16
|
-
const
|
|
17
|
-
'firefox'
|
|
19
|
+
const stable = [
|
|
20
|
+
'firefox'
|
|
21
|
+
];
|
|
22
|
+
const fallbacks = [
|
|
18
23
|
'firefox-esr',
|
|
19
24
|
'firefox-developer-edition',
|
|
20
25
|
'firefox-devedition',
|
|
21
26
|
'firefox-nightly'
|
|
22
27
|
];
|
|
28
|
+
const candidates = allowFallback ? [
|
|
29
|
+
...stable,
|
|
30
|
+
...fallbacks
|
|
31
|
+
] : stable;
|
|
23
32
|
for (const cmd of candidates)try {
|
|
24
33
|
const resolved = w.sync(cmd);
|
|
25
34
|
if (resolved) return resolved;
|
|
26
35
|
} catch (_) {}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
if (allowFallback) {
|
|
37
|
+
const linuxPaths = [
|
|
38
|
+
'/usr/bin/firefox',
|
|
39
|
+
'/usr/local/bin/firefox',
|
|
40
|
+
'/usr/lib/firefox/firefox',
|
|
41
|
+
'/snap/bin/firefox',
|
|
42
|
+
'/opt/firefox/firefox',
|
|
43
|
+
'/usr/local/firefox/firefox',
|
|
44
|
+
p.join(o.homedir(), 'bin', 'firefox'),
|
|
45
|
+
p.join(o.homedir(), 'Downloads', 'firefox', 'firefox'),
|
|
46
|
+
p.join(o.homedir(), '.local', 'share', 'flatpak', 'exports', 'bin', 'org.mozilla.firefox'),
|
|
47
|
+
'/var/lib/flatpak/exports/bin/org.mozilla.firefox'
|
|
48
|
+
];
|
|
49
|
+
for (const linuxPath of linuxPaths)if (f.existsSync(linuxPath)) return linuxPath;
|
|
50
|
+
}
|
|
40
51
|
return null;
|
|
41
52
|
}
|
|
42
53
|
if (osx) {
|
|
43
|
-
const
|
|
54
|
+
const appsAll = [
|
|
44
55
|
{
|
|
45
56
|
app: 'Firefox.app',
|
|
46
57
|
exec: 'firefox'
|
|
@@ -58,6 +69,9 @@ function locateFirefox(deps) {
|
|
|
58
69
|
exec: 'firefox'
|
|
59
70
|
}
|
|
60
71
|
];
|
|
72
|
+
const apps = allowFallback ? appsAll : [
|
|
73
|
+
appsAll[0]
|
|
74
|
+
];
|
|
61
75
|
const systemBase = '/Applications';
|
|
62
76
|
const userBase = p.join(o.homedir(), 'Applications');
|
|
63
77
|
for (const { app, exec } of apps){
|
|
@@ -74,17 +88,20 @@ function locateFirefox(deps) {
|
|
|
74
88
|
env.PROGRAMFILES,
|
|
75
89
|
env['PROGRAMFILES(X86)']
|
|
76
90
|
].filter(Boolean);
|
|
77
|
-
const
|
|
91
|
+
const suffixesAll = [
|
|
78
92
|
p.join('Mozilla Firefox', 'firefox.exe'),
|
|
79
93
|
p.join('Mozilla Firefox ESR', 'firefox.exe'),
|
|
80
94
|
p.join('Mozilla Firefox Developer Edition', 'firefox.exe'),
|
|
81
95
|
p.join('Firefox Nightly', 'firefox.exe')
|
|
82
96
|
];
|
|
97
|
+
const suffixes = allowFallback ? suffixesAll : [
|
|
98
|
+
suffixesAll[0]
|
|
99
|
+
];
|
|
83
100
|
for (const prefix of prefixes)for (const suffix of suffixes){
|
|
84
101
|
const exePath = p.join(prefix, suffix);
|
|
85
102
|
if (f.existsSync(exePath)) return exePath;
|
|
86
103
|
}
|
|
87
|
-
const
|
|
104
|
+
const defaultPathsAll = [
|
|
88
105
|
'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
|
|
89
106
|
'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe',
|
|
90
107
|
'C:\\Program Files\\Mozilla Firefox ESR\\firefox.exe',
|
|
@@ -94,6 +111,7 @@ function locateFirefox(deps) {
|
|
|
94
111
|
'C:\\Program Files\\Firefox Nightly\\firefox.exe',
|
|
95
112
|
'C:\\Program Files (x86)\\Firefox Nightly\\firefox.exe'
|
|
96
113
|
];
|
|
114
|
+
const defaultPaths = allowFallback ? defaultPathsAll : defaultPathsAll.slice(0, 2);
|
|
97
115
|
for (const defaultPath of defaultPaths)if (f.existsSync(defaultPath)) return defaultPath;
|
|
98
116
|
return null;
|
|
99
117
|
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "https://github.com/cezaraugusto/firefox-location2.git"
|
|
6
6
|
},
|
|
7
7
|
"name": "firefox-location2",
|
|
8
|
-
"version": "2.0.
|
|
8
|
+
"version": "2.0.1",
|
|
9
9
|
"description": "Approximates the current location of the Firefox browser across platforms.",
|
|
10
10
|
"homepage": "https://www.npmjs.com/package/firefox-location2",
|
|
11
11
|
"type": "module",
|