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

Add --open flag to open user browser when start serving #12233

Closed
4 tasks
Grubba27 opened this issue Oct 19, 2022 · 10 comments
Closed
4 tasks

Add --open flag to open user browser when start serving #12233

Grubba27 opened this issue Oct 19, 2022 · 10 comments
Labels
good first issue Good first issue or something that should is nice to do. hacktoberfest hacktoberfest issues for contribuition.
Milestone

Comments

@Grubba27
Copy link
Contributor

Grubba27 commented Oct 19, 2022

When you want to run the project and wants to open the browser when it finishes building
it would look like this:

meteor run --open

or

meteor --open

it would start running the server then open your default browser

How to implement?

  • you are going to start here file adding the new option;
  • Maybe make changes here as well
  • Install the open npm package
  • use the ROOT_URLvariable to open in the browser

discussion for more context

Discussed in #12226

@Grubba27 Grubba27 added the hacktoberfest hacktoberfest issues for contribuition. label Oct 19, 2022
@ankitzm
Copy link

ankitzm commented Oct 19, 2022

Would love to take up this issue, can you assign me the same !!

@Grubba27 Grubba27 added this to the Release 2.9 milestone Oct 19, 2022
@Jaya-sys
Copy link

Hi can you assign this issue to me?

@StorytellerCZ
Copy link
Collaborator

@ankitzm how is it looking?

@ankitzm
Copy link

ankitzm commented Oct 24, 2022

Yeah working on it, will be raising a PR soon.
Got a little busy with some other stuff before.

@Grubba27
Copy link
Contributor Author

Grubba27 commented Nov 30, 2022

hey @ankitzm how it is going? it is looking good? can't wait to see it :)

@StorytellerCZ StorytellerCZ removed this from the Release 2.9 milestone Mar 24, 2023
@Grubba27 Grubba27 added this to the Release 2.14 milestone Sep 26, 2023
@StorytellerCZ StorytellerCZ added the good first issue Good first issue or something that should is nice to do. label Sep 28, 2023
@nameception
Copy link
Contributor

Hello, i tried working on this issue but when importing the open package via import { open } from 'open' gives me this error:

Error [ERR_REQUIRE_ESM] [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\user\Desktop\meteor\node_modules\open\index.js
require() of ES modules is not supported.
require() of C:\Users\user\Desktop\meteor\node_modules\open\index.js from C:\Users\user\Desktop\meteor\tools\cli\commands.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\user\Desktop\meteor\node_modules\open\package.json.

I also attempted the solution suggested here: sindresorhus/file-type#525 (comment) but it doesn't seem to work, no errors but the browser window did not open as expected.
Here is how I tried to do it

main.registerCommand({
  name: '--open',
  requiresRelease: false,
  pretty: false,
  catalogRefresh: new catalog.Refresh.Never()
}, function (options) {
  (async () => {
    const { open } = await import('open')
    await open('https://www.google.com')
  });
});

@StorytellerCZ
Copy link
Collaborator

Maybe try the require syntax. Depending on where it is you will have to fall back to basic Node syntax without anything else.

@nameception
Copy link
Contributor

Using open@8.4.2 worked with the require syntax, the following code now executes without any errors:

main.registerCommand({
  name: '--open',
  requiresRelease: false,
  pretty: false,
  catalogRefresh: new catalog.Refresh.Never()
}, function (options) {
  open('https://google.com')
  Console.rawInfo('test')
});

However, despite no errors in the terminal output, it doesn't open any windows, I tested the package on other project and it worked. I'm not sure why it behaves this way, and I might not have the expertise to dig deeper into the issue.

terminal output:

PS C:\Users\andre\Desktop\meteor> ./meteor --open      
test

I hope this helps

@Grubba27
Copy link
Contributor Author

I would ask for a draft pr to see what you are doing!

To add a dependency to the project, you need to add to this file

var packageJson = {
name: "meteor-dev-bundle-tool",
private: true,
dependencies: {
// Explicit dependency because we are replacing it with a bundled version
// and we want to make sure there are no dependencies on a higher version
npm: "6.14.17",

Then run ./scripts/generate-dev-bundle.sh. If you are in Windows without WSL, you can use ./scripts/generate-dev-bundle.ps1.

This will add the library code to the tool, making it possible to be imported.

For adding a command for when you start serving, you should add the code that you commented on here:

options: {
port: { type: String, short: "p", default: DEFAULT_PORT },
'mobile-server': { type: String },
'cordova-server-port': { type: String },
'app-port': { type: String },
'debug-port': { type: String },

    port: { type: String, short: "p", default: DEFAULT_PORT },
    open: { type: Boolean, short: "o", default: false }, // <- your code here for the open flag
    'mobile-server': { type: String },
    'cordova-server-port': { type: String },

Your call to the open library will probably be around here:

var runAll = require('../runners/run-all.js');
return runAll.run({
projectContext: projectContext,
proxyPort: parsedServerUrl.port,

nameception added a commit to nameception/meteor that referenced this issue Oct 10, 2023
nameception added a commit to nameception/meteor that referenced this issue Oct 10, 2023
nameception added a commit to nameception/meteor that referenced this issue Oct 10, 2023
nameception added a commit to nameception/meteor that referenced this issue Oct 10, 2023
nameception added a commit to nameception/meteor that referenced this issue Oct 10, 2023
@amnahid
Copy link

amnahid commented Oct 10, 2023

@Grubba27 is this problem solved?

Grubba27 added a commit that referenced this issue Oct 27, 2023
 Add --open option to run command #12233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good first issue or something that should is nice to do. hacktoberfest hacktoberfest issues for contribuition.
Projects
None yet
Development

No branches or pull requests

6 participants