serverless / serverless-plugin-typescript

Serverless plugin for zero-config Typescript support
MIT License
781 stars 222 forks source link

Package 'individually=true' not working when setup at function level and 'false' at service level #303

Open bruno-xo7 opened 6 months ago

bruno-xo7 commented 6 months ago

Hello,

I got an issue with the package 'individually' not working. I have setup a simple project to easily test it:

plugins:

provider: name: aws runtime: nodejs18.x package: individually: false patterns:

functions: one: handler: src/main.handler1 two: handler: src/main.handler2 three: handler: src/main.handler3 package: individually: true patterns:

export const handler1: Handler = async () => { console.info("Hello function one!"); };

export const handler2: Handler = async () => { console.info("Hello function two!"); };

export const handler3: Handler = async () => { console.info("Hello function three!"); };


- It also need a file named `src/not_included_in_3`

Then when I type `sls package`, I got this error:
```bash
Running "serverless" from node_modules

Packaging sls-ts-package-individually for stage dev (us-east-1)
Compiling with Typescript...
Using local tsconfig.json - tsconfig.json
Typescript compiled.

Warning: Package patterns at function level are only applicable if package.individually is set to true at service level or function level in serverless.yaml. The framework will ignore the patterns defined at the function level and apply only the service-wide ones.
Environment: linux, node 18.19.0, framework 3.38.0 (local) 3.10.2v (global), plugin 7.2.0, SDK 4.5.1
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Error: Error: Error: ENOENT: no such file or directory, open '/home/user/git/test/test-sls-ts-package-individual/.build/.serverless/three.zip' encountered during hash calculation for provided filePath: /home/user/git/test/test-sls-ts-package-individual/.build/.serverless/three.zip
    at ReadStream.<anonymous> (/home/user/git/test/test-sls-ts-package-individual/node_modules/serverless/lib/plugins/aws/package/lib/get-hash-for-file-path.js:23:13)
    at ReadStream.emit (node:events:517:28)
    at ReadStream.emit (node:domain:489:12)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

If I disable the plugin serverless-plugin-typescript it's working fine. And I got 2 package in .serverless directory without error:

Can this be fixed?

Thank you, Bruno

MishaKav commented 5 months ago

just watching, have similar issue

a-khalilov commented 3 months ago

@bruno-xo7 I apologize, maybe it's wrong, but according to the documentation on the service level individually should be true:

...
package:
  individually: true
...

and remove individually from function level:

...
  three:
    handler: src/main.handler3
    package:
      patterns:
        - "!src/not_included_in_3"
...
a-khalilov commented 3 months ago

@bruno-xo7 But in my case I have the same warning as you, but I configure package on service level, and don't use individual at all

...
package:
  excludeDevDependencies: true
  patterns:
    - '!node_modules/serverless*/**'
    - '!node_modules/aws_sdk/'
    - '!package-lock.json'
...    

VSCode plugin says (regarding the same documentation article mentioned in the comment above) that the package block should be on provider level ((

bruno-xo7 commented 3 months ago

Hello @a-khalilov,

What you describe, it's to have 3 individual packages (in my example), one for each function. My problem is not this case, I want to have one 'global' (a.k.a. not individual) package for functions 'one' and 'two' and one individual package for the function 'three'. This is why I set the 'individually' at false at service level and true at the function 3 level.

a-khalilov commented 3 months ago

@bruno-xo7 I see. You're right, I didn't understand your case correctly. But I can confirm, that with my config I tried to reproduce your case and got 2 packages and the error. I'm guessing that the error makes your pipeline fail. Because I've seen both packages and they're correct

bruno-xo7 commented 3 months ago

Correct @a-khalilov, It's failed at the package step and indeed the deploy is not launched because of the fail

a-khalilov commented 3 months ago

@bruno-xo7 I got your problem. Had something similar with other serverless plugins. I use some pipes as a workaround, something like sls package | tee /dev/tty | grep -q 'anything of command's output that you would like to use as a condition' && exit 1 I'm sure you found a workaround, but anyway maybe it'll be useful for others Cheers!