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

Add OpenWhisk sequence support #94

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ServerlessOptions {
export interface ServerlessFunction {
handler: string
package: ServerlessPackage
sequence?: string[]
}

export interface ServerlessPackage {
Expand Down
24 changes: 23 additions & 1 deletion src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ export function extractFileNames(cwd: string, provider: string, functions?: { [k
}
}

// With OpenWhisk not all functions may actually have a code entrypoint - some may be "meta" functions / actions,
// most notably the "sequence" functions that are combinations of other functions. These may not actually
// have any code associated with them, aka no handler
if (provider === 'openwhisk') {
return (
_.values(functions)
// If this function is a sequence and doesn't have a handler defined we'll filter these out
.filter(fn => {
if (fn.sequence && !fn.handler) {
return false
}
return true
})
.map(fn => {
const fnName = _.last(fn.handler.split('.'))
const fnNameLastAppearanceIndex = fn.handler.lastIndexOf(fnName)
// replace only last instance to allow the same name for file and handler
return fn.handler.substring(0, fnNameLastAppearanceIndex) + 'ts'
})
)
}

return _.values(functions)
.map(fn => fn.handler)
.map(h => {
Expand All @@ -69,7 +91,7 @@ export async function run(fileNames: string[], options: ts.CompilerOptions): Pro
if (!diagnostic.file) {
console.log(diagnostic)
}
const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start)
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start)
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`)
})
Expand Down