@@ -26,13 +26,17 @@ function setArtifactPath(funcName, func, artifactPath) {
26
26
}
27
27
}
28
28
29
+ /**
30
+ * Copy pasted from Serverless
31
+ *
32
+ * @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L65
33
+ */
29
34
function serverlessZip ( args ) {
30
- const artifactFilePath = args . artifactFilePath ;
31
- const directory = args . directory ;
32
- const files = args . files ;
35
+ const { artifactFilePath, directory, files } = args ;
33
36
34
37
const zip = archiver . create ( 'zip' ) ;
35
38
const output = fs . createWriteStream ( artifactFilePath ) ;
39
+
36
40
return new BbPromise ( ( resolve , reject ) => {
37
41
output . on ( 'close' , ( ) => resolve ( artifactFilePath ) ) ;
38
42
output . on ( 'error' , err => reject ( err ) ) ;
@@ -56,7 +60,9 @@ function serverlessZip(args) {
56
60
zip . append ( file . data , {
57
61
name,
58
62
mode,
59
- date : new Date ( 0 ) // necessary to get the same hash when zipping the same content
63
+ // necessary to get the same hash when zipping the same content
64
+ // as well as `contents.sort` few lines above
65
+ date : new Date ( 0 )
60
66
} ) ;
61
67
}
62
68
) ;
@@ -68,8 +74,14 @@ function serverlessZip(args) {
68
74
} ) ;
69
75
}
70
76
77
+ /**
78
+ * Copy pasted from Serverless
79
+ *
80
+ * @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L112
81
+ */
71
82
function getFileContentAndStat ( directory , filePath ) {
72
83
const fullPath = `${ directory } /${ filePath } ` ;
84
+
73
85
return BbPromise . all ( [
74
86
// Get file contents and stat in parallel
75
87
getFileContent ( fullPath ) ,
@@ -89,11 +101,16 @@ function getFileContentAndStat(directory, filePath) {
89
101
) ;
90
102
}
91
103
104
+ /**
105
+ * Copy pasted from Serverless
106
+ *
107
+ * @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L135
108
+ */
92
109
function getFileContent ( fullPath ) {
93
110
return fs . readFileAsync ( fullPath ) ;
94
111
}
95
112
96
- function zip ( directory , name ) {
113
+ function zip ( directory , zipFileName ) {
97
114
// Check that files exist to be zipped
98
115
let files = glob . sync ( '**' , {
99
116
cwd : directory ,
@@ -123,12 +140,12 @@ function zip(directory, name) {
123
140
124
141
// Create artifact in temp path and move it to the package path (if any) later
125
142
// This allows us to persist the webpackOutputPath and re-use the compiled output
126
- const artifactFilePath = path . join ( this . webpackOutputPath , name ) ;
143
+ const artifactFilePath = path . join ( this . webpackOutputPath , zipFileName ) ;
127
144
this . serverless . utils . writeFileDir ( artifactFilePath ) ;
128
145
129
146
return serverlessZip ( {
130
- artifactFilePath,
131
147
directory,
148
+ artifactFilePath,
132
149
files
133
150
} ) ;
134
151
}
0 commit comments