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

Fix runner use of moleculer.config function with default export #1284

Conversation

shawnmcknight
Copy link
Member

📝 Description

When using moleculer-runner and a specified moleculer.config.<ext> file it should support both of the following:

  • Use of default export syntax
  • Exporting a function that returns a configuration object

The current flow of the runner is checking if the required moleculer.config.<ext> is a function prior to the logic which determines if the configuration file has a default export. This prevents the function from being executed if it is a default export.

This PR makes the following changes:

  • Always return a configuration object from loadConfigFile even if a configuration file was not found
  • Pass the configuration object returned from loadConfigFile to mergeOptions
  • Use the passed configuration object in mergeOptions instead of this.configFile
  • Eliminate use of this.configFile
  • Change the order of processing in loadConfigFile so that the default export check precedes the function check and execution
  • Adds support for .mts suffixes to the esm runner
  • Adds new moleculer.config.async.ts and moleculer.config.ts files to the runner examples which validate typescript configurations and default exports for use with the runner

💎 Type of change

  • Bug fix (non-breaking change which fixes an issue)

🚦 How Has This Been Tested?

Tested using the newly created runner examples as well as the existing examples for both cjs and esm variants.

🏁 Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas

@shawnmcknight shawnmcknight requested a review from icebob May 18, 2024 22:35
Copy link
Member

@icebob icebob left a comment

Choose a reason for hiding this comment

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

Good job, thanks!

@icebob icebob merged commit ab3372d into moleculerjs:master May 20, 2024
177 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants