Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(zip-it-and-ship-it): add support for event handlers#6976

Merged
eduardoboucas merged 5 commits into
mainfrom
feat/event-subscriptions
Mar 13, 2026
Merged

feat(zip-it-and-ship-it): add support for event handlers#6976
eduardoboucas merged 5 commits into
mainfrom
feat/event-subscriptions

Conversation

@eduardoboucas

Copy link
Copy Markdown
Member

@eduardoboucas eduardoboucas requested a review from a team as a code owner March 12, 2026 22:50
@coderabbitai

coderabbitai Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Functions can now declare event subscriptions (e.g., fetch, deploySucceeded, userSignup); these are detected and included in the generated manifest and packaged results.
  • Tests

    • Added end-to-end and unit tests covering extraction of event subscriptions from various export shapes.
  • Chores

    • Updated a package dependency version.

Walkthrough

Changes add detection and extraction of event subscription slugs from default exports into the Node in-source config parser, by returning and analyzing the default export expression (including CJS and re-exported defaults). Extracted eventSubscriptions are added to StaticAnalysisResult, propagated into FunctionResult/manifest composition, and written into the manifest when present. New tests and an ESM fixture validate extraction from object literals, bindings, CJS defaults, and re-exports. A dependency version for @netlify/serverless-functions-api was updated.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is minimal and only references a Linear issue without explaining the motivation, changes, or implementation details as required by the template. Expand the description to include a summary of changes, motivation for the work, and confirmation that tests and documentation have been updated.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding support for event handlers to the zip-it-and-ship-it package.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/event-subscriptions
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@eduardoboucas eduardoboucas marked this pull request as draft March 12, 2026 22:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts (1)

125-126: Use an own-property check for handler matching.

On Lines 125-126, name in eventHandlers can match prototype properties. Prefer an own-key check to avoid false positives in subscription extraction.

Proposed change
-    if (name && name in eventHandlers) {
+    if (name && Object.prototype.hasOwnProperty.call(eventHandlers, name)) {
       events.push(eventHandlers[name as keyof typeof eventHandlers])
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts`
around lines 125 - 126, The current check uses "name in eventHandlers" which can
match prototype properties; change it to an own-property check when deciding to
push handlers: verify the key exists on eventHandlers itself (e.g., use
Object.prototype.hasOwnProperty.call(eventHandlers, name) or equivalent) before
calling events.push(eventHandlers[name as keyof typeof eventHandlers]) so only
own keys are matched.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts`:
- Line 30: The import "eventHandlers" is invalid because
`@netlify/serverless-functions-api` exports getLambdaHandler, getNetlifyGlobal,
getPath and Context; replace the broken import of eventHandlers with the correct
exported symbol you actually use in this module (for example import
getLambdaHandler if you're wiring a lambda handler, getNetlifyGlobal if you need
Netlify globals, getPath for path resolution, or import type { Context } for
types), then update any usages of eventHandlers in this file to the chosen
exported symbol (or adjust the implementation to call
getLambdaHandler/getNetlifyGlobal/getPath as appropriate).

---

Nitpick comments:
In `@packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts`:
- Around line 125-126: The current check uses "name in eventHandlers" which can
match prototype properties; change it to an own-property check when deciding to
push handlers: verify the key exists on eventHandlers itself (e.g., use
Object.prototype.hasOwnProperty.call(eventHandlers, name) or equivalent) before
calling events.push(eventHandlers[name as keyof typeof eventHandlers]) so only
own keys are matched.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4842c411-fd59-43c3-8f96-0b73750fee40

📥 Commits

Reviewing files that changed from the base of the PR and between 2ea22df and 5e23aff.

📒 Files selected for processing (10)
  • packages/zip-it-and-ship-it/src/feature_flags.ts
  • packages/zip-it-and-ship-it/src/manifest.ts
  • packages/zip-it-and-ship-it/src/runtimes/node/in_source_config/index.ts
  • packages/zip-it-and-ship-it/src/runtimes/node/parser/exports.ts
  • packages/zip-it-and-ship-it/src/utils/format_result.ts
  • packages/zip-it-and-ship-it/src/zip.ts
  • packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-event-handlers/function.js
  • packages/zip-it-and-ship-it/tests/fixtures-esm/v2-api-event-handlers/package.json
  • packages/zip-it-and-ship-it/tests/main.test.ts
  • packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts

@eduardoboucas eduardoboucas marked this pull request as ready for review March 13, 2026 10:12
JakeChampion
JakeChampion previously approved these changes Mar 13, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts (1)

827-892: LGTM! Comprehensive test coverage for event subscriptions extraction.

The tests cover the key scenarios well:

  • Object literal and binding-resolved default exports
  • CJS exports.default pattern
  • export { x as default } re-export syntax
  • Negative case for function exports
  • Filtering of unknown property names

The user*identity_* slug mapping (e.g., userLoginidentity_login) aligns with Netlify Identity events.

Consider adding a test for when all properties are unrecognized to verify eventSubscriptions remains undefined:

💡 Optional: Add edge case test
test('Does not set eventSubscriptions when all properties are unknown', () => {
  const source = `export default { helperOne() {}, helperTwo() {} }`

  const isc = parseSource(source, options)

  expect(isc.eventSubscriptions).toBeUndefined()
  expect(isc.runtimeAPIVersion).toBe(2)
})

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts`
around lines 827 - 892, Add an edge-case unit test in the same "Event
subscriptions" describe block that verifies parseSource (used as
parseSource(source, options)) does not set eventSubscriptions when the
default-exported object only contains unknown helper methods; create a test
named like "Does not set eventSubscriptions when all properties are unknown",
use a source such as `export default { helperOne() {}, helperTwo() {} }`, call
const isc = parseSource(source, options) and assert isc.eventSubscriptions is
undefined and isc.runtimeAPIVersion is 2.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts`:
- Around line 827-892: Add an edge-case unit test in the same "Event
subscriptions" describe block that verifies parseSource (used as
parseSource(source, options)) does not set eventSubscriptions when the
default-exported object only contains unknown helper methods; create a test
named like "Does not set eventSubscriptions when all properties are unknown",
use a source such as `export default { helperOne() {}, helperTwo() {} }`, call
const isc = parseSource(source, options) and assert isc.eventSubscriptions is
undefined and isc.runtimeAPIVersion is 2.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 866d29cd-74a1-4798-bb27-6bbc8dbc8b73

📥 Commits

Reviewing files that changed from the base of the PR and between ef983fb and 2b945dd.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • packages/zip-it-and-ship-it/package.json
  • packages/zip-it-and-ship-it/tests/main.test.ts
  • packages/zip-it-and-ship-it/tests/unit/runtimes/node/in_source_config.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/zip-it-and-ship-it/package.json
  • packages/zip-it-and-ship-it/tests/main.test.ts

@eduardoboucas eduardoboucas merged commit e672c79 into main Mar 13, 2026
78 of 82 checks passed
@eduardoboucas eduardoboucas deleted the feat/event-subscriptions branch March 13, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants