Skip to content

Monorepo and ESM (#58) - #59

Merged
mwarman merged 3 commits into
mainfrom
58-monorepo-and-esm
Sep 30, 2026
Merged

mwarman merged 3 commits into
mainfrom
58-monorepo-and-esm

Conversation

@mwarman

@mwarman mwarman commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

🔧 Change Summary

Closes #58

  • Converted the project to an npm workspaces monorepo:
    • packages/api holds the Lambda handlers and all application source.
    • packages/infra holds the AWS CDK infrastructure.
    • Shared dependencies and the common scripts (build, clean, test, test:coverage) live in the root package.json and run in each workspace with --workspaces --if-present. There is a single root package-lock.json.
    • Added a root tsconfig.base.json that both workspaces extend.
  • Switched the whole project to ESM and upgraded TypeScript to 6.0.3:
    • All packages use "type": "module". Relative and alias imports now use .js extensions.
    • The @/ alias is kept per workspace (packages/api/src for the api, the package root for infra). It is configured in each tsconfig, in each Vitest config, and for esbuild via the API tsconfig.
    • The Lambdas are bundled as ESM (index.mjs) with a createRequire banner. lambda-stack.ts no longer uses __dirname.
    • The CDK app runs with tsx instead of ts-node. source-map-support was removed.
    • The api build script is now tsc --noEmit, because the Lambdas are bundled by esbuild during CDK synth and deploy.
  • Migrated all tests from Jest to Vitest:
    • There is a base vitest.config.ts at the root, extended in each workspace with mergeConfig.
    • Mocks now use vi.hoisted, and require() calls became await import().
    • Two test setups changed beyond the mechanical migration. task-service.test.ts now uses fake timers instead of a Date spy, and sns-client.test.ts mocks @leanstacks/lambda-utils. Test names and assertions are unchanged.
  • Updated the GitHub Actions workflows to use a single root npm ci, with the CDK steps running in packages/infra.
  • Updated the documentation (README, docs/, packages/infra/README.md) for the new structure, scripts, ESM conventions, and Vitest.
  • Added AGENTS.md. .github/copilot-instructions.md now points to it.

📝 Checklist

  • Complete a self-review of changes
  • Unit tests have been created or updated
  • The code is free of [new] lint errors and warnings
  • Update project documentation as needed: README, /docs, JSDoc, etc.

🧪 Steps to Test

  1. Run npm ci from the repository root.
  2. Run npm run lint, npm run format:check, npm run build, and npm run test:coverage. All should pass.
  3. Create packages/infra/.env from .env.example, then run npm run synth -w packages/infra. Verify that each Lambda bundles as index.mjs under packages/infra/cdk.out.
  4. Optionally deploy to LocalStack (npm run local:start, then the local:* scripts in packages/infra) and exercise the API.

🔗 Additional Information

  • Not yet verified: the GitHub Actions workflows and a LocalStack deployment. Local cdk synth and loading a bundled handler in Node both worked.
  • deploy-reusable.yml runs npm run bootstrap, which is not a script in the infra package. That predates this change and I left it alone.

mwarman and others added 2 commits September 30, 2026 07:49
- Move application code to packages/api and CDK code to packages/infra
- Add root tsconfig.base.json and vitest.config.ts extended by workspaces
- Switch to ESM, TypeScript 6.0.3, tsx for the CDK app, ESM Lambda bundles
- Migrate tests from Jest to Vitest
- Update CI/CD workflows for the workspace layout

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Update README and docs for the monorepo layout, ESM, and Vitest
- Add AGENTS.md; point copilot-instructions.md to it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mwarman mwarman self-assigned this Sep 30, 2026
@mwarman mwarman linked an issue Sep 30, 2026 that may be closed by this pull request
@mwarman
mwarman marked this pull request as ready for review September 30, 2026 12:44
@mwarman
mwarman merged commit 5f547bf into main Sep 30, 2026
1 check passed
@mwarman
mwarman deleted the 58-monorepo-and-esm branch September 30, 2026 13:12
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.

Monorepo and ESM

1 participant