Skip to content

fix: lazy-load scheduler AWS SDK in core and repair frigg init scaffolding - #639

Open
seanspeaks wants to merge 2 commits into
nextfrom
claude/fix-scheduler-lazy-and-frigg-init
Open

fix: lazy-load scheduler AWS SDK in core and repair frigg init scaffolding#639
seanspeaks wants to merge 2 commits into
nextfrom
claude/fix-scheduler-lazy-and-frigg-init

Conversation

@seanspeaks

Copy link
Copy Markdown
Contributor

Summary

Two independent packaging bugs on next, both of which make a clean install unusable before any real work starts.

Fix 1 — @friggframework/core should not require @aws-sdk/client-scheduler unless EventBridge is actually used

infrastructure/scheduler/eventbridge-scheduler-adapter.js did a top-level require('@aws-sdk/client-scheduler'), and scheduler/index.js eagerly requires that adapter (which core loads via application → scheduler-commands). Core never declared the package, so on a clean install merely running require('@friggframework/core') threw MODULE_NOT_FOUND — even on the mock provider or with no AWS at all. This also broke the devtools CLI, which loads core (verified: frigg init --help crashed on the unfixed registry core).

Approach (dep made lazy, not just added):

  • @aws-sdk/client-scheduler is now required lazily through a cached loadSchedulerSdk() helper, called from the EventBridge adapter's constructor and methods — never at module load. Requiring the scheduler module (and thus core) no longer pulls aws-sdk; only instantiating the EventBridge adapter does. A missing package yields a clear, actionable error instead of a raw MODULE_NOT_FOUND.
  • Declared in optionalDependencies so AWS deployments still install it by default, while non-AWS/local consumers aren't forced to. The factory already only instantiates the EventBridge adapter for the eventbridge provider; the mock path never touches aws-sdk.
  • Added a regression test (eventbridge-scheduler-adapter.test.js).

Proof (clean temp install, --omit=optional so client-scheduler is absent):

BEFORE (top-level require): Error: Cannot find module '@aws-sdk/client-scheduler'
AFTER:  require('@friggframework/core') SUCCEEDED without @aws-sdk/client-scheduler
  • Mock provider works and is the dev/test/local default; installing @aws-sdk/client-scheduler and instantiating EventBridgeSchedulerAdapter still constructs a real SchedulerClient.
  • New regression test: 4 passing.

Fix 2 — frigg init is broken in the 2.0-next devtools

frigg init <name> failed two ways:

(a) Backend template not shipped. The handler copies from frigg-cli/templates/backend, but that directory did not exist in the source tree (confirmed absent from the published 2.0.0-next.107 tarball) → "Backend template not found." Added a working backend template (index.js exporting Definition, infrastructure.js, README.md) and listed frigg-cli/templates/ in package files. The template's app definition validates against the current app-definition schema, and carries the exact markers updateAppDefinition() rewrites when integrations are selected.

(b) The --template default routed every init into the dead legacy branch. The CLI registered --template with a default of 'backend-only', but the handler only runs the backend-first path when !options.template, so the truthy default always fell through to "Legacy template system is no longer supported" and exited 1. Removed the default (--template is now an explicit, unsupported legacy opt-in), made the positional the project name (init [projectName]), registered the flags the handler actually reads (--mode, --no-frontend, --force, --verbose), dropped the unused --directory, and removed the dangling options.legacyFrontend reference.

Proof (built devtools tarball installed into a scratch dir):

  • frigg init --help lists the new options.
  • Scaffolding my-frigg-app produces index.js / infrastructure.js / package.json / README.mdno "template not found", no "legacy not supported". Generated index.js exports a valid Definition; infrastructure.js resolves createFriggInfrastructure from devtools.
  • Explicit --template still shows the legacy message (escape hatch preserved).

Files changed

  • packages/core/infrastructure/scheduler/eventbridge-scheduler-adapter.js — lazy SDK load
  • packages/core/infrastructure/scheduler/eventbridge-scheduler-adapter.test.js — new regression test
  • packages/core/package.jsonoptionalDependencies: @aws-sdk/client-scheduler
  • packages/devtools/frigg-cli/templates/backend/{index.js,infrastructure.js,README.md} — new backend template
  • packages/devtools/package.json — ship frigg-cli/templates/
  • packages/devtools/frigg-cli/index.jsinit command definition
  • packages/devtools/frigg-cli/init-command/index.js — default routing + project-name handling

Test plan

  • Clean-install core without client-scheduler → require succeeds (threw before)
  • Mock scheduler works; EventBridge adapter still functions with SDK present
  • Scheduler regression test passes (4/4)
  • frigg init <name> scaffolds a backend app from the built devtools tarball

🤖 Generated with Claude Code


Generated by Claude Code

claude added 2 commits August 19, 2026 05:13
Loading @friggframework/core pulled in @aws-sdk/client-scheduler because
eventbridge-scheduler-adapter.js required it at module top level and
scheduler/index.js eagerly requires that adapter. Core never declared the
package, so a clean install (or any consumer on the mock provider / no AWS)
threw MODULE_NOT_FOUND merely on `require('@friggframework/core')`.

- Require @aws-sdk/client-scheduler lazily via a cached loadSchedulerSdk()
  helper, invoked from the EventBridge adapter's constructor and methods
  rather than at module load. Requiring the scheduler module (and thus core)
  no longer touches aws-sdk; only instantiating the EventBridge adapter does.
  A missing package now yields a clear, actionable error instead of a raw
  MODULE_NOT_FOUND.
- Declare @aws-sdk/client-scheduler in optionalDependencies so AWS
  deployments still install it by default while non-AWS/local consumers are
  not forced to. The factory already only instantiates the EventBridge
  adapter for the eventbridge provider; the mock path never touches aws-sdk.
- Add a regression test asserting the module loads without the SDK, the mock
  provider works, the dev/test/local default is mock, and instantiating the
  EventBridge adapter reaches for the SDK.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JDh45c1vm91ySYtvVv9Z65
…oute)

`frigg init <name>` failed two ways in 2.0-next:

(a) Backend template not shipped. The init handler copies from
    frigg-cli/templates/backend, but that directory did not exist in the
    source tree (and so was absent from the published tarball), producing
    "Backend template not found." Add a working backend template
    (index.js exporting `Definition`, infrastructure.js, README.md) and
    list frigg-cli/templates/ explicitly in package `files`. The template's
    app definition validates against the current app-definition schema and
    carries the exact markers the handler's updateAppDefinition() rewrites
    when integrations are selected.

(b) The default routed every init into the dead legacy branch. The CLI
    registered `--template` with a default of 'backend-only', but the
    handler only runs the backend-first path when `!options.template`, so
    the truthy default always fell through to "Legacy template system is no
    longer supported" and exit 1. Remove the default; `--template` is now an
    explicit (unsupported) legacy opt-in. Make the positional the project
    name (`init [projectName]`), register the flags the handler actually
    reads (`--mode`, `--no-frontend`, `--force`, `--verbose`), drop the
    unused `--directory`, and remove the dangling `options.legacyFrontend`
    reference so the handler and commander definitions are consistent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JDh45c1vm91ySYtvVv9Z65

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.

Tip: disable this comment in your organization's Code Review settings.

@netlify

netlify Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploy Preview for friggframework-org canceled.

Name Link
🔨 Latest commit f788c5e
🔍 Latest deploy log https://app.netlify.com/projects/friggframework-org/deploys/6a853bd821c7540008f66669

@seanspeaks seanspeaks added release Create a release when this pr is merged prerelease This change is available in a prerelease. labels Aug 19, 2026 — with Claude
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prerelease This change is available in a prerelease. release Create a release when this pr is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants