netlify / zip-it-and-ship-it

Intelligently prepare Node.js Lambda functions for deployment
https://www.npmjs.com/package/@netlify/zip-it-and-ship-it
MIT License
316 stars 35 forks source link

feat: support CommonJS syntax in V2 functions #1585

Closed eduardoboucas closed 1 year ago

eduardoboucas commented 1 year ago

Summary

Adds support for CommonJS syntax when authoring V2 functions, including support for the config object in CJS.

It also adds a new inputModuleFormat property that contains cjs or esm based on the syntax used to author the function (which may differ from the module format that is actually generated, represented by outputModuleFormat from https://github.com/netlify/zip-it-and-ship-it/pull/1589).

Most of the PR is actually a cleanup around ISC and the static analysis code. I've added some inline comments that will hopefully make it easier to review, but feel free to ask anything that isn't clear.

github-actions[bot] commented 1 year ago

⏱ Benchmark results

Comparing with 1ea5222b0723885c908642390253f9496f378d5f

largeDepsEsbuild: 2.5s

⬇️ 2.05% decrease vs. 1ea5222b0723885c908642390253f9496f378d5f

^                                                           3.7s                                          
│                                                           ┌──┐                                          
│                                                           |  |                                          
│                                                   3.1s    |  |                                          
│                                                   ┌──┐    |  |                                          
│   2.8s    2.8s            2.7s    2.8s            |  |    |  |    2.7s            2.7s                  
│ ──┌──┐────┌──┐────2.6s────┌──┐────┌──┐────2.6s────┼──┼────┼──┼────┌──┐────────────┌──┐────2.6s────2.5s──
│   |  |    |  |    ┌──┐    |  |    |  |    ┌──┐    |  |    |  |    |  |    2.4s    |  |    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    ┌──┐    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend - T-30 (b5b9b1a41e3c40b4d41e625131cd5e2c1d8e5dd1): 2.7s - T-29 (22967a315e6f619bcbb4d01eba839868fca47bed): 3.2s - T-28 (af1c7e0fb3c5f24139307a0c5a3f199ff9a11ccd): 2.5s - T-27 (909382c875d5162ca98ef0111dd8da877dba384e): 2.8s - T-26 (56767675a84e1625759a8ac74011288075046754): 2.6s - T-25 (364c92a78cd9bfc3d922a064c69a1d830ec23662): 2.4s - T-24 (c9978755768e1f7c2e8b3df00b64da3731190228): 3.1s - T-23 (8803f81ff71856192f9a1d523eb8e2f489ecc36d): 3.7s - T-22 (627fed0c14b94377ce05668ef711afdf0aae69b3): 2.6s - T-21 (a3e629996493877ab8fb5ea29b30eb12ae3ed83a): 3.1s - T-20 (6b6f02a3e5b95e15452e4d03023ba58f90a7c896): 2.6s - T-19 (11d452bd8c4ef7a25655a4d3f2c612c68f7625ba): 2.5s - T-18 (8d205cac41e94785f037d2885d0d9257e7ecd4d4): 2.5s - T-17 (0658e287efca9574ab585df4a96d744834935c41): 2.7s - T-16 (9fa3e37f25b1625fdcf7fd90efc0a6a5effd9818): 2.6s - T-15 (7aeed4d678636a4efd8d6e8f0f3314d242a585de): 3s - T-14 (028da3871932b3775006e6b637f6d81f98cfd905): 2.6s - T-13 (60d1ecb24a678806e75d329da23963c51f246d62): 2.8s - T-12 (4778ed749c03eaae2fb36b42db987364c7e0ecf3): 2.8s - T-11 (f5529d7f1e2008db4ef41392571733250e0b2d12): 2.8s - T-10 (d98dd20825b80d78c6ff0e5c4f2b51c7117d6af5): 2.6s - T-9 (6be379e1499d09e146d718af1957275014d10dd4): 2.7s - T-8 (ad2c55d2db23014e0961a776f860e03d781a8eb1): 2.8s - T-7 (304f7f544dfd99ddd3447e18baa1768e06aa646c): 2.6s - T-6 (45ebfeaa3c41aa0af7e8c4e5f7ad0fd0410e13eb): 3.1s - T-5 (2070b46a2c2949b93f9c98f14135f3f76e7db65d): 3.7s - T-4 (5d277e792ad684d29fb95780d2dee162874d3265): 2.7s - T-3 (360f3733e2db910f8e3372f2765b421065d6bf9b): 2.4s - T-2 (5c6c14a08b9d4868bd26cc989262f9e624251a4a): 2.7s - T-1 (1ea5222b0723885c908642390253f9496f378d5f): 2.6s - **T (current commit): 2.5s**

largeDepsNft: 7.6s

⬇️ 2.12% decrease vs. 1ea5222b0723885c908642390253f9496f378d5f

^                                                          12.1s                                          
│                                                           ┌──┐                                          
│                                                           |  |                                          
│                                                  10.1s    |  |                                          
│                                                   ┌──┐    |  |                                          
│                                                   |  |    |  |                                          
│   8.3s    8.7s            8.5s    8.3s            |  |    |  |    8.3s                                  
│ ──┌──┐────┌──┐────7.6s────┌──┐────┌──┐────8.1s────┼──┼────┼──┼────┌──┐─────────────8s─────7.7s────7.6s──
│   |  |    |  |    ┌──┐    |  |    |  |    ┌──┐    |  |    |  |    |  |    7.5s    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    ┌──┐    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend - T-30 (b5b9b1a41e3c40b4d41e625131cd5e2c1d8e5dd1): 8.2s - T-29 (22967a315e6f619bcbb4d01eba839868fca47bed): 9.9s - T-28 (af1c7e0fb3c5f24139307a0c5a3f199ff9a11ccd): 7.5s - T-27 (909382c875d5162ca98ef0111dd8da877dba384e): 8.5s - T-26 (56767675a84e1625759a8ac74011288075046754): 7.8s - T-25 (364c92a78cd9bfc3d922a064c69a1d830ec23662): 7.5s - T-24 (c9978755768e1f7c2e8b3df00b64da3731190228): 9.8s - T-23 (8803f81ff71856192f9a1d523eb8e2f489ecc36d): 11.7s - T-22 (627fed0c14b94377ce05668ef711afdf0aae69b3): 8.2s - T-21 (a3e629996493877ab8fb5ea29b30eb12ae3ed83a): 9.7s - T-20 (6b6f02a3e5b95e15452e4d03023ba58f90a7c896): 7.9s - T-19 (11d452bd8c4ef7a25655a4d3f2c612c68f7625ba): 7.5s - T-18 (8d205cac41e94785f037d2885d0d9257e7ecd4d4): 7.6s - T-17 (0658e287efca9574ab585df4a96d744834935c41): 8.2s - T-16 (9fa3e37f25b1625fdcf7fd90efc0a6a5effd9818): 8.1s - T-15 (7aeed4d678636a4efd8d6e8f0f3314d242a585de): 9.4s - T-14 (028da3871932b3775006e6b637f6d81f98cfd905): 8.7s - T-13 (60d1ecb24a678806e75d329da23963c51f246d62): 8.2s - T-12 (4778ed749c03eaae2fb36b42db987364c7e0ecf3): 8.3s - T-11 (f5529d7f1e2008db4ef41392571733250e0b2d12): 8.7s - T-10 (d98dd20825b80d78c6ff0e5c4f2b51c7117d6af5): 7.6s - T-9 (6be379e1499d09e146d718af1957275014d10dd4): 8.5s - T-8 (ad2c55d2db23014e0961a776f860e03d781a8eb1): 8.3s - T-7 (304f7f544dfd99ddd3447e18baa1768e06aa646c): 8.1s - T-6 (45ebfeaa3c41aa0af7e8c4e5f7ad0fd0410e13eb): 10.1s - T-5 (2070b46a2c2949b93f9c98f14135f3f76e7db65d): 12.1s - T-4 (5d277e792ad684d29fb95780d2dee162874d3265): 8.3s - T-3 (360f3733e2db910f8e3372f2765b421065d6bf9b): 7.5s - T-2 (5c6c14a08b9d4868bd26cc989262f9e624251a4a): 8s - T-1 (1ea5222b0723885c908642390253f9496f378d5f): 7.7s - **T (current commit): 7.6s**

largeDepsZisi: 15.3s

⬆️ 1.03% increase vs. 1ea5222b0723885c908642390253f9496f378d5f

^                                                          22.4s                                          
│                                                           ┌──┐                                          
│                                                           |  |                                          
│                                                  19.3s    |  |                                          
│                                                   ┌──┐    |  |                                          
│          16.4s                                    |  |    |  |                                          
│ ─16.1s────┌──┐───────────16.1s───15.9s───15.5s────┼──┼────┼──┼───15.7s───────────15.7s───15.1s───15.3s──
│   ┌──┐    |  |   14.8s    ┌──┐    ┌──┐    ┌──┐    |  |    |  |    ┌──┐   14.4s    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    ┌──┐    |  |    |  |    |  |    |  |    |  |    |  |    ┌──┐    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend - T-30 (b5b9b1a41e3c40b4d41e625131cd5e2c1d8e5dd1): 15.8s - T-29 (22967a315e6f619bcbb4d01eba839868fca47bed): 19.3s - T-28 (af1c7e0fb3c5f24139307a0c5a3f199ff9a11ccd): 15s - T-27 (909382c875d5162ca98ef0111dd8da877dba384e): 16.1s - T-26 (56767675a84e1625759a8ac74011288075046754): 14.6s - T-25 (364c92a78cd9bfc3d922a064c69a1d830ec23662): 14.9s - T-24 (c9978755768e1f7c2e8b3df00b64da3731190228): 19.3s - T-23 (8803f81ff71856192f9a1d523eb8e2f489ecc36d): 22.3s - T-22 (627fed0c14b94377ce05668ef711afdf0aae69b3): 15.4s - T-21 (a3e629996493877ab8fb5ea29b30eb12ae3ed83a): 18.3s - T-20 (6b6f02a3e5b95e15452e4d03023ba58f90a7c896): 15.2s - T-19 (11d452bd8c4ef7a25655a4d3f2c612c68f7625ba): 14.4s - T-18 (8d205cac41e94785f037d2885d0d9257e7ecd4d4): 14.9s - T-17 (0658e287efca9574ab585df4a96d744834935c41): 16s - T-16 (9fa3e37f25b1625fdcf7fd90efc0a6a5effd9818): 15.3s - T-15 (7aeed4d678636a4efd8d6e8f0f3314d242a585de): 18s - T-14 (028da3871932b3775006e6b637f6d81f98cfd905): 15.8s - T-13 (60d1ecb24a678806e75d329da23963c51f246d62): 15.8s - T-12 (4778ed749c03eaae2fb36b42db987364c7e0ecf3): 16.1s - T-11 (f5529d7f1e2008db4ef41392571733250e0b2d12): 16.4s - T-10 (d98dd20825b80d78c6ff0e5c4f2b51c7117d6af5): 14.8s - T-9 (6be379e1499d09e146d718af1957275014d10dd4): 16.1s - T-8 (ad2c55d2db23014e0961a776f860e03d781a8eb1): 15.9s - T-7 (304f7f544dfd99ddd3447e18baa1768e06aa646c): 15.5s - T-6 (45ebfeaa3c41aa0af7e8c4e5f7ad0fd0410e13eb): 19.3s - T-5 (2070b46a2c2949b93f9c98f14135f3f76e7db65d): 22.4s - T-4 (5d277e792ad684d29fb95780d2dee162874d3265): 15.7s - T-3 (360f3733e2db910f8e3372f2765b421065d6bf9b): 14.4s - T-2 (5c6c14a08b9d4868bd26cc989262f9e624251a4a): 15.7s - T-1 (1ea5222b0723885c908642390253f9496f378d5f): 15.1s - **T (current commit): 15.3s**
eduardoboucas commented 1 year ago

hard to understand the full context often as the codebase lacks a lot of documentation sadly on what properties are or what they should do

What parts of the codebase do you feel are lacking documentation?

eduardoboucas commented 1 year ago

After discussing with @lukasholzer, we're not sure this is still needed in its current form. I still think some of the cleaning up we're doing here would be great to land, so I'm moving to draft until I have time to pick this up again.