@@ -35,31 +35,29 @@ function setFunctionArtifactPath(this: EsbuildServerlessPlugin, func, artifactPa
35
35
}
36
36
}
37
37
38
- const excludedFilesDefault = [ 'package-lock.json' , 'pnpm-lock.yaml' , 'yarn.lock' , 'package.json' ] ;
38
+ const excludedFilesDefault = [
39
+ '!package-lock.json' ,
40
+ '!pnpm-lock.yaml' ,
41
+ '!yarn.lock' ,
42
+ '!package.json' ,
43
+ ] ;
39
44
40
45
export const filterFilesForZipPackage = ( {
41
- files ,
46
+ allPatternFilesToIncludedFiles ,
42
47
functionAlias,
43
- includedFiles,
44
48
excludedFiles,
45
49
hasExternals,
46
50
isGoogleProvider,
47
51
depWhiteList,
48
52
} : {
49
- files : IFiles ;
53
+ allPatternFilesToIncludedFiles : IFiles ;
50
54
functionAlias : string ;
51
- includedFiles : string [ ] ;
52
55
excludedFiles : string [ ] ;
53
56
hasExternals : boolean ;
54
57
isGoogleProvider : boolean ;
55
58
depWhiteList : string [ ] ;
56
59
} ) => {
57
- return files . filter ( ( { localPath } ) => {
58
- // if file is present in patterns it must be included
59
- if ( includedFiles . find ( ( file ) => file === localPath ) ) {
60
- return true ;
61
- }
62
-
60
+ return allPatternFilesToIncludedFiles . filter ( ( { localPath } ) => {
63
61
// exclude non individual files based on file path (and things that look derived, e.g. foo.js => foo.js.map)
64
62
if ( excludedFiles . find ( ( p ) => localPath . startsWith ( `${ p } .` ) ) ) return false ;
65
63
@@ -96,17 +94,16 @@ export async function pack(this: EsbuildServerlessPlugin) {
96
94
'Packaging failed: cannot package function individually when using Google provider'
97
95
) ;
98
96
99
- // get a list of all path in build
100
- const files : IFiles = globby
101
- . sync ( '**' , {
97
+ // get a list of all paths in build that we want
98
+ const patternBasedFilesToIncluded : IFiles = globby
99
+ . sync ( [ '**' , ... excludedFiles , ... ( this . serverless . service . package . patterns ?? [ ] ) ] , {
102
100
cwd : this . buildDirPath ,
103
101
dot : true ,
104
102
onlyFiles : true ,
105
103
} )
106
- . filter ( ( p ) => ! excludedFiles . includes ( p ) )
107
104
. map ( ( localPath ) => ( { localPath, rootPath : path . join ( this . buildDirPath , localPath ) } ) ) ;
108
105
109
- if ( isEmpty ( files ) ) {
106
+ if ( isEmpty ( patternBasedFilesToIncluded ) ) {
110
107
console . log ( 'Packaging: No files found. Skipping esbuild.' ) ;
111
108
return ;
112
109
}
@@ -120,7 +117,7 @@ export async function pack(this: EsbuildServerlessPlugin) {
120
117
const filesPathList = pipe < IFiles , IFiles , IFiles > (
121
118
reject ( test ( / ^ _ _ o n l y _ [ ^ / ] + $ / ) ) as ( x : IFiles ) => IFiles ,
122
119
map ( over ( lensProp ( 'localPath' ) , replace ( / ^ _ _ o n l y _ [ ^ / ] + \/ / , '' ) ) )
123
- ) ( files ) ;
120
+ ) ( patternBasedFilesToIncluded ) ;
124
121
125
122
const startZip = Date . now ( ) ;
126
123
await zip ( artifactPath , filesPathList , this . buildOptions . nativeZip ) ;
@@ -157,18 +154,18 @@ export async function pack(this: EsbuildServerlessPlugin) {
157
154
? await packager . getProdDependencies ( this . buildDirPath )
158
155
: { } ;
159
156
160
- const packageFiles = await globby ( this . serverless . service . package . patterns ) ;
161
-
162
157
// package each function
163
158
await Promise . all (
164
159
buildResults . map ( async ( { func, functionAlias, bundlePath } ) => {
165
160
const excludedFiles = bundlePathList
166
161
. filter ( ( p ) => ! bundlePath . startsWith ( p ) )
167
162
. map ( trimExtension ) ;
168
163
169
- const functionFiles = await globby ( func . package . patterns ) ;
164
+ const functionFiles = globby
165
+ . sync ( func . package . patterns )
166
+ . map ( ( localPath ) => ( { localPath, rootPath : path . join ( this . buildDirPath , localPath ) } ) ) ;
170
167
171
- const includedFiles = [ ...packageFiles , ...functionFiles ] ;
168
+ const allPatternFilesToIncludedFiles = [ ...patternBasedFilesToIncluded , ...functionFiles ] ;
172
169
173
170
// allowed external dependencies in the final zip
174
171
let depWhiteList = [ ] ;
@@ -187,9 +184,8 @@ export async function pack(this: EsbuildServerlessPlugin) {
187
184
188
185
// filter files
189
186
const filesPathList = filterFilesForZipPackage ( {
190
- files ,
187
+ allPatternFilesToIncludedFiles ,
191
188
functionAlias,
192
- includedFiles,
193
189
excludedFiles,
194
190
hasExternals,
195
191
isGoogleProvider,
0 commit comments