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

cpp-814 - bizops key should not be a prerequisite for running nori #181

Merged
merged 1 commit into from
Mar 22, 2022

Conversation

leannecornish-ft
Copy link
Contributor

Users currently need to have a biz ops api key set to run nori. This is because it's exported as an instance on the BizOpsClient class, and is immediately instantiated when the commands that import it are initialised when the program loads.

This pr lazy-loads the bizops module, so that it's only instantiated when the consuming function is used. This felt like a simple way of doing it without changing too much - happier to hear better options though.

@leannecornish-ft leannecornish-ft requested a review from a team as a code owner March 21, 2022 16:25
@@ -82,6 +81,7 @@ function getRepositoryObject(data) {
}

exports.handler = async ({ file }, state) => {
const { bizOps, bizOpsErrorHandler } = require('../lib/bizops')
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: require is event-loop blocking, and if we wanted to migrate to ECMAScript Modules, this wouldn't work, so using await import(...) might be better:

Suggested change
const { bizOps, bizOpsErrorHandler } = require('../lib/bizops')
const { bizOps, bizOpsErrorHandler } = await import('../lib/bizops.js')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's great, I'll do that, thanks Kara!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thoughts - this is going to prove tricky - first we'd need to upgrade eslint and install babel-parser (fine) but second jest does not want to work with mixed cjs and esm, I paired with Serena for a while and eventually agreed it wasn't worth the investment involved. Any thoughts? @apaleslimghost

Copy link
Member

Choose a reason for hiding this comment

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

ah, fair enough!

Copy link
Member

@apaleslimghost apaleslimghost left a comment

Choose a reason for hiding this comment

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

one non-blocking suggestion, this looks great, agree that it's probably the simplest way!

@leannecornish-ft leannecornish-ft merged commit 3fce0a5 into main Mar 22, 2022
@leannecornish-ft leannecornish-ft deleted the cpp-814-bizops-api-key-bug branch March 22, 2022 15:06
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