Skip to content

Commit

Permalink
fix: consistent way of setting patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Calle Kabo committed Apr 11, 2021
1 parent 6303ad8 commit ece100c
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,30 @@ export class EsbuildPlugin implements Plugin {
fs.mkdirpSync(this.buildDirPath);
fs.mkdirpSync(path.join(this.workDirPath, SERVERLESS_FOLDER));
// exclude serverless-esbuild
this.serverless.service.package = {
...(this.serverless.service.package || {}),
patterns: [
...new Set([
...(this.serverless.service.package?.include || []),
...(this.serverless.service.package?.exclude || []).map(concat('!')),
...(this.serverless.service.package?.patterns || []),
'!node_modules/serverless-esbuild',
]),
]
};

for (const fnName in this.functions) {
const fn = this.serverless.service.getFunction(fnName);
fn.package = fn.package || {
patterns: [],
fn.package = {
...(fn.package || {}),
patterns: [
...new Set([
...(fn.package?.include || []),
...(fn.package?.exclude || []).map(concat('!')),
...(fn.package?.patterns || []),
]),
]
};

// Add plugin to excluded packages or an empty array if exclude is undefined
fn.package.patterns = [
...new Set([ ...(fn.package.exclude || []).map(concat('!')), ...(fn.package.patterns || []), '!node_modules/serverless-esbuild' ]),
];
}
}

Expand Down Expand Up @@ -220,11 +234,8 @@ export class EsbuildPlugin implements Plugin {
const { service } = this.serverless;

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

for (const filename of files) {
const destFileName = path.resolve(path.join(this.buildDirPath, filename));
Expand Down

0 comments on commit ece100c

Please sign in to comment.