Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support packaging functions individually #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zjye
Copy link

@zjye zjye commented Apr 3, 2019

to fix issue #42

@JackCuthbert
Copy link
Contributor

Looks like a few people are trying to resolve this issue now (#107 is another one). The relevant code looks like it's on src/index.ts:238 and looks good but there's quite a few lines and 2 commits that aren't so relevant to #42. Are you happy to rebase and trim those away?

I'll try to repro and confirm this fix sometime this week, thanks for helping out!

@zjye zjye force-pushed the fix-function-package-individually branch from 5af7c6e to c702a57 Compare April 30, 2019 02:05
@zjye
Copy link
Author

zjye commented Apr 30, 2019

@JackCuthbert , i have reapplied the changes, please review

@JackCuthbert
Copy link
Contributor

JackCuthbert commented Apr 30, 2019

Nice @zjye ! Can you drop the merge commit as well and modify the commit with the fix to be a message like:

feat: Support packaging functions individually (closes #42 #107)

This will cause semantic-release to do it's magic and publish a minor version update (as this is adding support for something it didn't do before) and GitHub to automatically close out any related issues/PRs once this is merged.

@divyenduz I'll be attempting to repro this within the next few days, I'll ping again once this is ready for merge!

@zjye zjye force-pushed the fix-function-package-individually branch from 814f391 to 111a410 Compare April 30, 2019 05:46
@zjye
Copy link
Author

zjye commented Apr 30, 2019

Nice @zjye ! Can you drop the merge commit as well and modify the commit with the fix to be a message like:

feat: Support packaging functions individually (closes #42 #107)

Done

@zjye zjye changed the title 🐛 fix functions package artifact path when it's marked individually Support packaging functions individually May 6, 2019
@JackCuthbert
Copy link
Contributor

JackCuthbert commented May 11, 2019

Hey @zjye I've tested your fix and it looks like it resolves part of the problem defined in the #42 use case where one function is defined as being packaged individually.

What it is not doing is copying anything defined in the include option for each package. I have a small patch here that seems to work but is a little messy, happy for you to include it in your PR if you like:

diff --git a/src/index.ts b/src/index.ts
index 27e1769..9442508 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -149,7 +149,7 @@ export class TypeScriptPlugin {
       await this.linkOrCopy(path.resolve('package.json'), outPkgPath, 'file')
     }
 
-    // include any "extras" from the "include" section
+    // include any "extras" from the "include" section of the main service
     if (this.serverless.service.package.include && this.serverless.service.package.include.length > 0) {
       const files = await globby(this.serverless.service.package.include)
 
@@ -166,6 +166,25 @@ export class TypeScriptPlugin {
         }
       }
     }
+
+    // include any "extras" from the "include" section of each function
+    for (const fnName in this.functions) {
+      const fn = this.functions[fnName]
+      if (fn.package.include !== undefined) {
+        for (const filename of fn.package.include) {
+          const destFileName = path.resolve(path.join(buildFolder, filename))
+          const dirname = path.dirname(destFileName)
+
+          if (!fs.existsSync(dirname)) {
+            fs.mkdirpSync(dirname)
+          }
+
+          if (!fs.existsSync(destFileName)) {
+            fs.copySync(path.resolve(filename), path.resolve(path.join(buildFolder, filename)))
+          }
+        }
+      }
+    }

Additionally, it seems that packaging individually (both at a single function or service-wide level) only duplicates the resulting .zip file with a new name. All code and includes are packaged into each archive, so if you need more control over what goes into each package make sure to use include or exclude options (related documentation), it could get a little finicky.

@JackCuthbert
Copy link
Contributor

Hey @divyenduz, how do you feel about this one?

@divyenduz divyenduz self-requested a review August 7, 2019 21:54
@divyenduz divyenduz removed their request for review August 5, 2021 07:20
@argjentsahiti
Copy link

Do we have an update on this PR? It's such a needed feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants