Skip to content

Commit f35818d

Browse files
committed
Add some comments
1 parent 9676d7c commit f35818d

File tree

8 files changed

+67
-113
lines changed

8 files changed

+67
-113
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ custom:
506506
This can be useful, in case you want to upload the source maps to your Error
507507
reporting system, or just have it available for some post processing.
508508

509-
510509
#### Nodejs custom runtime
511510

512511
If you are using a nodejs custom runtime you can add the property `allowCustomRuntime: true`.
@@ -520,6 +519,7 @@ exampleFunction:
520519

521520
⚠️ **Note: this will only work if your custom runtime and function are written in JavaScript.
522521
Make sure you know what you are doing when this option is set to `true`**
522+
523523
#### Examples
524524

525525
You can find an example setups in the [`examples`][link-examples] folder.

lib/packageModules.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ function setArtifactPath(funcName, func, artifactPath) {
2626
}
2727
}
2828

29+
/**
30+
* Copy pasted from Serverless
31+
*
32+
* @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L65
33+
*/
2934
function serverlessZip(args) {
30-
const artifactFilePath = args.artifactFilePath;
31-
const directory = args.directory;
32-
const files = args.files;
35+
const { artifactFilePath, directory, files } = args;
3336

3437
const zip = archiver.create('zip');
3538
const output = fs.createWriteStream(artifactFilePath);
39+
3640
return new BbPromise((resolve, reject) => {
3741
output.on('close', () => resolve(artifactFilePath));
3842
output.on('error', err => reject(err));
@@ -56,7 +60,9 @@ function serverlessZip(args) {
5660
zip.append(file.data, {
5761
name,
5862
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)
6066
});
6167
}
6268
);
@@ -68,8 +74,14 @@ function serverlessZip(args) {
6874
});
6975
}
7076

77+
/**
78+
* Copy pasted from Serverless
79+
*
80+
* @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L112
81+
*/
7182
function getFileContentAndStat(directory, filePath) {
7283
const fullPath = `${directory}/${filePath}`;
84+
7385
return BbPromise.all([
7486
// Get file contents and stat in parallel
7587
getFileContent(fullPath),
@@ -89,11 +101,16 @@ function getFileContentAndStat(directory, filePath) {
89101
);
90102
}
91103

104+
/**
105+
* Copy pasted from Serverless
106+
*
107+
* @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L135
108+
*/
92109
function getFileContent(fullPath) {
93110
return fs.readFileAsync(fullPath);
94111
}
95112

96-
function zip(directory, name) {
113+
function zip(directory, zipFileName) {
97114
// Check that files exist to be zipped
98115
let files = glob.sync('**', {
99116
cwd: directory,
@@ -123,12 +140,12 @@ function zip(directory, name) {
123140

124141
// Create artifact in temp path and move it to the package path (if any) later
125142
// 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);
127144
this.serverless.utils.writeFileDir(artifactFilePath);
128145

129146
return serverlessZip({
130-
artifactFilePath,
131147
directory,
148+
artifactFilePath,
132149
files
133150
});
134151
}

lib/packagers/yarn.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ describe('yarn', () => {
6363
it('should transform yarn trees to npm dependencies', () => {
6464
const testYarnResult =
6565
'{"type":"activityStart","data":{"id":0}}\n' +
66+
'{"type":"activityTick","data":{"id":0,"name":"bestzip@^2.1.5"}}\n' +
6667
'{"type":"activityTick","data":{"id":0,"name":"bluebird@^3.5.1"}}\n' +
6768
'{"type":"activityTick","data":{"id":0,"name":"fs-extra@^4.0.3"}}\n' +
6869
'{"type":"activityTick","data":{"id":0,"name":"mkdirp@^0.5.1"}}\n' +
6970
'{"type":"activityTick","data":{"id":0,"name":"minimist@^0.0.8"}}\n' +
7071
'{"type":"activityTick","data":{"id":0,"name":"@sls/webpack@^1.0.0"}}\n' +
7172
'{"type":"tree","data":{"type":"list","trees":[' +
72-
'{"name":"[email protected]","children":[],"hint":null,"color":' +
73+
'{"name":"[email protected]","children":[],"hint":null,"color":"bold",' +
74+
'"depth":0},{"name":"[email protected]","children":[],"hint":null,"color":' +
7375
'"bold","depth":0},{"name":"[email protected]","children":[],"hint":null,' +
7476
'"color":"bold","depth":0},{"name":"[email protected]","children":[{"name":' +
7577
'"[email protected]","children":[],"hint":null,"color":"bold","depth":0}],' +
@@ -78,6 +80,10 @@ describe('yarn', () => {
7880
const expectedResult = {
7981
problems: [],
8082
dependencies: {
83+
bestzip: {
84+
version: '2.1.5',
85+
dependencies: {}
86+
},
8187
bluebird: {
8288
version: '3.5.1',
8389
dependencies: {}

0 commit comments

Comments
 (0)