Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Feb 3, 2022
1 parent 1749bed commit abf3f82
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 113 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ custom:
This can be useful, in case you want to upload the source maps to your Error
reporting system, or just have it available for some post processing.


#### Nodejs custom runtime

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

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

#### Examples

You can find an example setups in the [`examples`][link-examples] folder.
Expand Down
31 changes: 24 additions & 7 deletions lib/packageModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ function setArtifactPath(funcName, func, artifactPath) {
}
}

/**
* Copy pasted from Serverless
*
* @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L65
*/
function serverlessZip(args) {
const artifactFilePath = args.artifactFilePath;
const directory = args.directory;
const files = args.files;
const { artifactFilePath, directory, files } = args;

const zip = archiver.create('zip');
const output = fs.createWriteStream(artifactFilePath);

return new BbPromise((resolve, reject) => {
output.on('close', () => resolve(artifactFilePath));
output.on('error', err => reject(err));
Expand All @@ -56,7 +60,9 @@ function serverlessZip(args) {
zip.append(file.data, {
name,
mode,
date: new Date(0) // necessary to get the same hash when zipping the same content
// necessary to get the same hash when zipping the same content
// as well as `contents.sort` few lines above
date: new Date(0)
});
}
);
Expand All @@ -68,8 +74,14 @@ function serverlessZip(args) {
});
}

/**
* Copy pasted from Serverless
*
* @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L112
*/
function getFileContentAndStat(directory, filePath) {
const fullPath = `${directory}/${filePath}`;

return BbPromise.all([
// Get file contents and stat in parallel
getFileContent(fullPath),
Expand All @@ -89,11 +101,16 @@ function getFileContentAndStat(directory, filePath) {
);
}

/**
* Copy pasted from Serverless
*
* @see https://github.com/serverless/serverless/blob/63d54e1537e10ae63c171892edd886f6b81e83f6/lib/plugins/package/lib/zipService.js#L135
*/
function getFileContent(fullPath) {
return fs.readFileAsync(fullPath);
}

function zip(directory, name) {
function zip(directory, zipFileName) {
// Check that files exist to be zipped
let files = glob.sync('**', {
cwd: directory,
Expand Down Expand Up @@ -123,12 +140,12 @@ function zip(directory, name) {

// Create artifact in temp path and move it to the package path (if any) later
// This allows us to persist the webpackOutputPath and re-use the compiled output
const artifactFilePath = path.join(this.webpackOutputPath, name);
const artifactFilePath = path.join(this.webpackOutputPath, zipFileName);
this.serverless.utils.writeFileDir(artifactFilePath);

return serverlessZip({
artifactFilePath,
directory,
artifactFilePath,
files
});
}
Expand Down
Loading

0 comments on commit abf3f82

Please sign in to comment.