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

feat: run server init as promise #3210

Merged
merged 18 commits into from Jun 2, 2022
Merged

feat: run server init as promise #3210

merged 18 commits into from Jun 2, 2022

Conversation

juanpicado
Copy link
Member

@juanpicado juanpicado commented Jun 1, 2022

The way to use verdaccio programatically is not very friendly if you are using

const startVerdaccio = require('verdaccio'); 

as this example.

⚠️ Deprecations

  • Using verdaccio with multiples listeners display a deprecation warning
    • (runServer) forbid this and only allows the first one listener listed
  • On verdaccio 6 will be removed and will throw an error

🚀 Feature

runServer method to run verdaccio programatically as a promise

I am looking for a better name, feel free to drop your ideas.

On v6 #2165 this was improved and I am moving the same API to v5 so is much easier to migrate in the future.

It's a bit experimental, it does not replace the old way, so won't break anything, but allows smooth migration

There are three ways to use it:

  • No input, it will find the config.yaml as is you would run verdaccio in the console
  • With a absolute path
  • With an object (there is a catch here, see below)
    const {runServer} = require('verdaccio');
    const app = await runServer(); // default configuration
    const app = await runServer('./config/config.yaml');
    const app = await runServer({ configuration });
    app.listen(4000, (event) => {
      // do something
    });

With an object you need to add self_path, manually (it's not nice but would be a breaking change changing it now) on v6 this is not longer need it.

      const configPath = join(__dirname, './config.yaml');
      const c = parseConfigFile(configPath);
      // workaround
      // on v5 the `self_path` still exists and will be removed in v6
      c.self_path = 'foo';
      runServer(c).then(() => {});

parseConfigFile method

Exposed for easy use parse a yaml file as an object

@juanpicado juanpicado added this to the 5.x milestone Jun 2, 2022
@juanpicado juanpicado added this to In Review in Verdaccio Stable via automation Jun 2, 2022
@juanpicado juanpicado marked this pull request as ready for review June 2, 2022 15:13
@juanpicado juanpicado merged commit 42194c7 into 5.x Jun 2, 2022
Verdaccio Stable automation moved this from In Review to Closed Jun 2, 2022
@delete-merged-branch delete-merged-branch bot deleted the jota/runServer-5.x branch June 2, 2022 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant