-
Notifications
You must be signed in to change notification settings - Fork 230
Fix #271 Skip Non-NodeJS Functions #277
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,14 +93,25 @@ export class TypeScriptPlugin { | |
get functions() { | ||
const { options } = this | ||
const { service } = this.serverless | ||
const functions = service.functions || {} | ||
|
||
if (options.function) { | ||
const nodeFunctions = Object.keys(functions) | ||
.filter(functionKey => { | ||
const runtime = functions[functionKey].runtime || service.provider.runtime | ||
return runtime.includes('nodejs') | ||
}) | ||
.reduce((obj, key) => { | ||
obj[key] = functions[key] | ||
return obj | ||
}, {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I refactored the logic |
||
|
||
if (options.function && nodeFunctions[options.function]) { | ||
return { | ||
[options.function]: service.functions[this.options.function] | ||
[options.function]: nodeFunctions[options.function] | ||
} | ||
} | ||
|
||
return service.functions | ||
return nodeFunctions | ||
} | ||
|
||
get rootFileNames() { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as TypeScriptPlugin from '../src/index' | ||
|
||
describe('TypeScriptPlugin', () => { | ||
it('rootFileNames includes only node runtimes', () => { | ||
const slsInstance: Serverless.Instance = { | ||
cli: { | ||
log: jest.fn() | ||
}, | ||
config: { | ||
servicePath: 'servicePath' | ||
}, | ||
service: { | ||
provider: { | ||
name: 'aws', | ||
runtime: 'nodejs99' | ||
}, | ||
functions: { | ||
func1: { | ||
handler: 'java-fn', | ||
runtime: 'python3.9', | ||
package:{ | ||
exclude: [], | ||
include: [], | ||
patterns: [] | ||
} | ||
}, | ||
func2: { | ||
handler: 'node-fn', | ||
runtime: 'nodejs16', | ||
package:{ | ||
exclude: [], | ||
include: [], | ||
patterns: [] | ||
} | ||
} | ||
}, | ||
package: { | ||
exclude: [], | ||
include: [], | ||
patterns: [] | ||
}, | ||
layers: {}, | ||
getAllLayers: jest.fn(), | ||
getAllFunctions: jest.fn() | ||
}, | ||
pluginManager: { | ||
spawn: jest.fn() | ||
} | ||
} | ||
|
||
const plugin = new (TypeScriptPlugin as any)(slsInstance, {}) | ||
|
||
expect( | ||
Object.keys(plugin.functions) | ||
).toEqual( | ||
[ | ||
'func2' | ||
], | ||
) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:There was a problem hiding this comment.
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 with3.9.*
: