Skip to content

feat: extract runtime-handler and lazyLoading (#252) #271

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

Merged
merged 14 commits into from
Jun 10, 2021

Conversation

dkundel
Copy link
Contributor

@dkundel dkundel commented May 20, 2021

This change introduces the following features:

  • It adds the local development logic into the public @twilio/runtime-handler
  • Implements lazyLoading for the Twilio client instances constructed within @twilio/runtime-handler to bring parity with the 1.1.0 release in Functions
  • Starts using the customer project's twilio package instead of the one from the Serverless Toolkit

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.

  • I acknowledge that all my contributions will be made under the project's license.

@dkundel dkundel force-pushed the features/runtime-handler branch from 77eefc3 to 981b3b1 Compare May 24, 2021 23:45
@dkundel dkundel force-pushed the features/runtime-handler branch from 981b3b1 to f0ac4c0 Compare May 24, 2021 23:46
@dkundel dkundel marked this pull request as ready for review May 25, 2021 15:11
@dkundel dkundel requested a review from philnash May 25, 2021 15:11
Copy link
Contributor

@philnash philnash left a comment

Choose a reason for hiding this comment

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

For the most part, this is a copy of twilio-run functionality to runtime-handler and that all seems fine to me. Bringing the lazy loading option in looks just fine to me.

We are duplicating some types, which I wonder if we could bring together somewhere.

And there are some unused dependencies in runtime-handler, which we could remove before publishing.

Otherwise, good lift here!

@@ -0,0 +1,88 @@
export type SearchConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

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

runtime-handler is now exporting some duplicate types that also live in serverless-api or twilio-run. Should they be consolidated somewhere?

Also in serverless-api:
SearchConfig, AccessOptions, ServerlessResourceConfig, ServerlessResourceConfigWithFilePath

Also in twilio-run:
EnvironmentVariablesWithAuth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is the way the dependency chain works. twilio-run should rely on serverless-api and runtime-handler (at least during compile time) but runtime-handler shouldn't rely on twilio-run. And similarly I didn't want runtime-handlerto rely on serverless-api since runtime-handler can be different from user to user during runtime so it should be self-contained in general

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact you'll see that runtime-handler is only a devDependency in twilio-run because I do import type as opposed to import.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could runtime-handler take serverless-api as a devDependency and do import type too then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not because some of these are part of ServerConfig which is exported by runtime-handler. Realistically the only thing we could do is to move it into a common dependency that all of them consume. But realistically they are all part of ServerConfig which is basically the "contract" for runtime-handler. So I could see scenarios where they could diverge slightly from the other use cases.

I was able to remove SearchConfig though since it's not being used anymore.

import { join } from 'path';

export function requireFromProject(projectDir: string, packageName: string) {
return createRequire(join(projectDir, 'node_modules'))(packageName);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will still fallback to the version installed by twilio-run if there isn't an explicit dependency on twilio in the project, right? And that is the intention?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the fallback more explicit now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you pushed? The last commits I can see are from 13 days ago.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I was changing around logic afterwards. It's now up-to-date

@dkundel dkundel requested a review from philnash June 9, 2021 21:08
Replaced with a looser test based on the content at the start of the error message that should be thrown.
Copy link
Contributor

@philnash philnash left a comment

Choose a reason for hiding this comment

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

I think this is looking good!

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