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 #271 Skip Non-NodeJS Functions #277

Merged
merged 4 commits into from
Aug 2, 2022
Merged

Conversation

sazzy4o
Copy link
Contributor

@sazzy4o sazzy4o commented Aug 2, 2022

This plugin currently breaks your serverless stack if you have any non-nodejs functions (Python, Java, etc.) also in it. This skips them
This is based on this old PR: #197 (Merge conflicts and some unnecessary changes)
This closes #271

Change summary:

@sazzy4o sazzy4o changed the title Skip Non-NodeJS Functions Fix #271 Skip Non-NodeJS Functions Aug 2, 2022
@sazzy4o
Copy link
Contributor Author

sazzy4o commented Aug 2, 2022

@medikoo Could you please review this PR?
(Sorry, if this is not the right way to request a review)

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thank you @sazzy4o ! Please see my comments

package.json Outdated
@@ -53,13 +53,13 @@
"@types/jest": "24.0.12",
"@types/lodash": "4.14.123",
"@types/node": "12.6.2",
"jest": "24.5.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it required to upgrade jest?

I feel it's a breaking change for the suite, as in current major support for Node.js v10 must be maintained and we should be able to run tests with that version

Copy link
Contributor Author

@sazzy4o sazzy4o Aug 2, 2022

Choose a reason for hiding this comment

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

Good catch, seems like the latest version of jest doesn't support Node.js v10. I rolled back to old version and tested with v10. There is just a warning that typescript version is not officially supported:

ts-jest[versions] (WARN) Version 4.7.4 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, in case you were wondering why typescript was updated. It does not compile with 3.9.*:

node_modules/@sinclair/typebox/typebox.d.ts:66:102 - error TS2574: A rest element type must be an array type.

66 export declare type StaticContructorParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
                                                                                                        ~~~~
67     [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 }];
   ~

node_modules/@sinclair/typebox/typebox.d.ts:87:100 - error TS2574: A rest element type must be an array type.

87 export declare type StaticFunctionParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
                                                                                                      ~~~~
88     [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89 }];
   ~

node_modules/@sinclair/typebox/typebox.d.ts:105:21 - error TS2456: Type alias 'IntersectReduce' circularly references itself.

105 export declare type IntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? IntersectReduce<I & A, B> : I extends object ? I : {};
                        ~~~~~~~~~~~~~~~

node_modules/@sinclair/typebox/typebox.d.ts:105:104 - error TS2574: A rest element type must be an array type.

105 export declare type IntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? IntersectReduce<I & A, B> : I extends object ? I : {};
                                                                                                           ~~~~~~~~~~

node_modules/@sinclair/typebox/typebox.d.ts:105:118 - error TS2315: Type 'IntersectReduce' is not generic.

105 export declare type IntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? IntersectReduce<I & A, B> : I extends object ? I : {};
...

src/index.ts Outdated
Comment on lines 103 to 106
.reduce((obj, key) => {
obj[key] = functions[key]
return obj
}, {})
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not user reduce for that. It'll be clearer to setup loop as follows:

const nodeFunctions = {};
for (const [name, functionObject] of Object.entries(functions)) {
  if (nodeRuntime) nodeFunctions[name] = functionObject;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I refactored the logic

@sazzy4o
Copy link
Contributor Author

sazzy4o commented Aug 2, 2022

@medikoo Thanks for the review! I have made some changes

@sazzy4o sazzy4o requested a review from medikoo August 2, 2022 18:06
Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Thank you @sazzy4o 👍

@avivshafir
Copy link

I'm getting the following error

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined

I think when specifying packaging individually option we reach this line
https://github.com/serverless/serverless-plugin-typescript/blob/master/src/index.ts#L281

and it doesn't seem to include the fix

@sazzy4o
Copy link
Contributor Author

sazzy4o commented Nov 6, 2022

@avivshafir Could you please share your serverless.yml and your package-lock.json (so, I can check your commit hash/version)
Edit: It was released in 2.1.3, so make sure you are running that version or newer (or installing from GitHub)

Get getAllFunctions accesses this.functions which does have the fix (but, maybe there is something else I missed)
https://github.com/serverless/serverless/blob/9a414683090cb3edcac61d9a782c4d136f18c6f6/lib/classes/service.js#L305

@avivshafir
Copy link

@sazzy4o

https://gist.github.com/avivshafir/b984c80879938c44a77dc907e72bc374

running version 2.1.4 of serverless-plugin-typescript
and serverless version 3.23.0

@avivshafir
Copy link

Seems like it's happening only when I'm setting the python lambda to use an image parameter

@sazzy4o
Copy link
Contributor Author

sazzy4o commented Nov 7, 2022

I haven't had time to properly test yet, but you can try this fix:

sazzy4o@b9d3ae4

(I should have some time to test and create a PR over the next few days)

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.

ignore non nodejs functions
3 participants