Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented browser and browserPrivate #294

Merged
merged 24 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8b11819
Added browser and browserPrivate under open.apps
leslieyip02 Jan 27, 2023
7253ffc
Switched default browser library
leslieyip02 Jan 30, 2023
5376f3d
Updated docs
leslieyip02 Jan 30, 2023
cc68d5a
Fixed issue with __dirname
leslieyip02 Jan 30, 2023
5828be0
Fix: removed ava test from test script
leslieyip02 Jan 30, 2023
4cf1a6d
Fix the `app` argument with WSL (#295)
kazarmy Jan 30, 2023
5c6582a
Removed unnecessary url import
leslieyip02 Feb 1, 2023
53bb565
Changed exports and specified supported browsers
leslieyip02 Feb 1, 2023
051edca
Fix `allowNonzeroExitCode` option (#296)
xirzec Feb 8, 2023
13a800c
Meta tweaks
sindresorhus Feb 8, 2023
27e4e3a
8.4.1
sindresorhus Feb 8, 2023
51fae87
Fix support for Podman
sindresorhus Feb 20, 2023
cbc008b
8.4.2
sindresorhus Feb 20, 2023
b3212fb
Mapped browser IDs to supported browsers
leslieyip02 Mar 13, 2023
aa21cad
Added browser and browserPrivate under open.apps
leslieyip02 Jan 27, 2023
f7b4c6d
Switched default browser library
leslieyip02 Jan 30, 2023
238770d
Updated docs
leslieyip02 Jan 30, 2023
009b28e
Fixed issue with __dirname
leslieyip02 Jan 30, 2023
69b4bb5
Fix: removed ava test from test script
leslieyip02 Jan 30, 2023
e368f9b
Removed unnecessary url import
leslieyip02 Feb 1, 2023
1af76c2
Changed exports and specified supported browsers
leslieyip02 Feb 1, 2023
a4867a4
Mapped browser IDs to supported browsers
leslieyip02 Mar 13, 2023
b185554
Merge branch 'main' of https://github.com/leslieyip02/open
leslieyip02 Mar 19, 2023
6d9d524
Added documentation for apps export
leslieyip02 Mar 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switched default browser library
  • Loading branch information
leslieyip02 committed Mar 19, 2023
commit f7b4c6ddef0ec7c2ead43686da3c4158dbe03326
56 changes: 22 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require('path');
const childProcess = require('child_process');
const {promises: fs, constants: fsConstants} = require('fs');
const isWsl = require('is-wsl');
const isDocker = require('is-docker');
const defineLazyProperty = require('define-lazy-prop');
const defaultBrowser = require('x-default-browser');
import path from 'path';
import childProcess from 'child_process';
import {promises as fs, constants as fsConstants} from 'fs';
import isWsl from 'is-wsl';
import isDocker from 'is-docker';
import defineLazyProperty from 'define-lazy-prop';
import defaultBrowser from 'default-browser';

// Path to included `xdg-open`.
const localXdgOpenPath = path.join(__dirname, 'xdg-open');
Expand Down Expand Up @@ -119,20 +119,14 @@ const baseOpen = async options => {
}

if (app === 'browser') {
return defaultBrowser((error, browser) => {
if (error) {
throw error;
const browser = await defaultBrowser();
const browserName = browser.name.toLowerCase();
return baseOpen({
...options,
app: {
name: open.apps[browserName],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to do some normalisation of the names. browserName will be different depending on the OS.

arguments: appArguments
}

const browserName = browser.commonName;

baseOpen({
...options,
app: {
name: open.apps[browserName],
arguments: appArguments
}
});
});
}

Expand All @@ -144,20 +138,14 @@ const baseOpen = async options => {
edge: '--inPrivate'
};

return defaultBrowser((error, browser) => {
if (error) {
throw error;
const browser = await defaultBrowser();
const browserName = browser.name.toLowerCase();
return baseOpen({
...options,
app: {
name: open.apps[browserName],
arguments: [...appArguments, flags[browserName]]
}

const browserName = browser.commonName;

baseOpen({
...options,
app: {
name: open.apps[browserName],
arguments: [...appArguments, flags[browserName]]
}
});
});
}

Expand Down Expand Up @@ -379,4 +367,4 @@ defineLazyProperty(apps, 'browserPrivate', () => 'browserPrivate');
open.apps = apps;
open.openApp = openApp;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be named exports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean something like this?

export {apps};
export default open;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes


module.exports = open;
export {open};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export {open};
export default open;

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "open",
"version": "8.4.2",
"version": "8.4.0",
"description": "Open stuff like URLs, files, executables. Cross-platform.",
"license": "MIT",
"repository": "sindresorhus/open",
Expand All @@ -14,7 +14,7 @@
"node": ">=12"
},
"scripts": {
"test": "xo && tsd"
"test": "xo && tsd && ava"
},
"files": [
"index.js",
Expand Down Expand Up @@ -51,6 +51,7 @@
"define-lazy-prop": "^2.0.0",
"is-docker": "^2.1.1",
"is-wsl": "^2.2.0",
"default-browser": "^3.1.0",
"x-default-browser": "^0.5.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const test = require('ava');
const open = require('.');
import test from 'ava';
import {open} from './index.js';
const {openApp} = open;

// Tests only checks that opening doesn't return an error
Expand Down