Skip to content

Commit

Permalink
feat: Recognize package.patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 10, 2021
1 parent 306a839 commit 378c4f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Serverless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ declare namespace Serverless {
interface Package {
include: string[]
exclude: string[]
patterns: string[]
artifact?: string
individually?: boolean
}
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class TypeScriptPlugin {
fn.package = fn.package || {
exclude: [],
include: [],
patterns: []
}

// Add plugin to excluded packages or an empty array if exclude is undefined
Expand Down Expand Up @@ -157,13 +158,14 @@ export class TypeScriptPlugin {
return emitedFiles
}

/** Link or copy extras such as node_modules or package.include definitions */
/** Link or copy extras such as node_modules or package.patterns definitions */
async copyExtras() {
const { service } = this.serverless

const patterns = [...(service.package.include || []), ...(service.package.patterns || [])]
// include any "extras" from the "include" section
if (service.package.include && service.package.include.length > 0) {
const files = await globby(service.package.include)
if (patterns.length > 0) {
const files = await globby(patterns)

for (const filename of files) {
const destFileName = path.resolve(path.join(BUILD_FOLDER, filename))
Expand Down
9 changes: 6 additions & 3 deletions tests/typescript.extractFileName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ const functions: { [key: string]: Serverless.Function } = {
handler: 'tests/assets/hello.handler',
package: {
include: [],
exclude: []
exclude: [],
patterns: []
}
},
world: {
handler: 'tests/assets/world.handler',
package: {
include: [],
exclude: []
exclude: [],
patterns: []
}
},
js: {
handler: 'tests/assets/jsfile.create',
package: {
include: [],
exclude: []
exclude: [],
patterns: []
}
},
}
Expand Down

0 comments on commit 378c4f6

Please sign in to comment.