Skip to content

refactor: migrate app imports to @stash/core package boundary - #5

Merged
sergdort merged 3 commits into
mainfrom
refactor-route-dependencies
Mar 5, 2026
Merged

sergdort merged 3 commits into
mainfrom
refactor-route-dependencies

Conversation

@sergdort

@sergdort sergdort commented Mar 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • migrate API/CLI imports from deep relative packages/core/src/... paths to root-only @stash/core
  • convert packages/core package identity to @stash/core with root export map
  • add full package-local builds (packages/core, apps/api, apps/cli) and update root build orchestration
  • switch compiled CLI runtime path references from dist/apps/cli/src/cli.js to apps/cli/dist/cli.js
  • add targeted Vite dep optimizer mitigation for react-router-dom chunk warning

Key Changes

  • package metadata/build configs:
    • packages/core/package.json, packages/core/tsconfig.build.json
    • apps/api/package.json, apps/api/tsconfig.build.json
    • apps/cli/package.json, apps/cli/tsconfig.build.json
    • root package.json build/start/db scripts
  • app import migration to @stash/core across API and CLI sources
  • core public API expansion in packages/core/src/index.ts for app call sites
  • CLI web-stack loading adjusted to work with package-local build outputs
  • docs/test updates for new compiled CLI path (apps/cli/dist/cli.js)

Validation

  • pnpm run build
  • pnpm test
  • pnpm run test:integration
  • STASH_DB_PATH=/tmp/stash-core-pkg/stash.db pnpm run db:doctor -- --json
  • node apps/cli/dist/cli.js --help

Contract Checks

  • no packages/core/src/... imports remain in app source
  • no @stash/core/... subpath imports in app source

Copilot AI 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.

Pull request overview

This PR migrates the monorepo from deep relative imports (packages/core/src/...) to a clean @stash/core package boundary, introducing a CoreServices factory pattern for dependency injection and switching to per-package builds.

Changes:

  • Introduces @stash/core as a proper workspace package with exports map, a CoreServices abstraction (createCoreServices factory + typed service interfaces), and per-package tsconfig.build.json files for core, api, and cli.
  • Migrates all API route handlers and CLI command handlers to consume services via injected interfaces (e.g., Pick<ItemsService, "saveItem">) instead of directly importing feature functions, with the CLI dynamically loading the API web stack module.
  • Updates all references to the compiled CLI path from dist/apps/cli/src/cli.js to apps/cli/dist/cli.js across scripts, docs, and tests, and adds integration tests for both API and CLI response shape stability.

Reviewed changes

Copilot reviewed 35 out of 36 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/core/package.json Rename to @stash/core, add exports map and build script
packages/core/tsconfig.build.json New package-local build config
packages/core/src/index.ts Add named re-exports for migrate/paths members and export new services module
packages/core/src/services/contracts.ts New service interface definitions (CoreServices, ItemsService, etc.)
packages/core/src/services/create-core-services.ts New factory binding context to feature functions
packages/core/src/services/index.ts Barrel export for services
packages/core/test/core-services.test.ts Unit test verifying delegation through the factory
apps/api/package.json Add @stash/core dependency and build script
apps/api/tsconfig.build.json New package-local build config
apps/api/src/app/create-api-app.ts Wire createCoreServices and inject service slices into routes
apps/api/src/app/server.ts Migrate imports to @stash/core
apps/api/src/app/error-handler.ts Migrate import to @stash/core
apps/api/src/features/*/routes.ts Each route file now accepts typed service options instead of ApiRouteOptions
apps/api/src/features/*/dto.ts Migrate imports to @stash/core
apps/api/src/features/inbox/dto.ts Migrate type imports to @stash/core
apps/api/test/integration.test.ts New API integration test covering endpoint response contracts
apps/cli/package.json Add @stash/core dependency and build script
apps/cli/tsconfig.build.json New package-local build config
apps/cli/src/cli.ts Migrate to @stash/core, use createCoreServices, add dynamic API module loading
apps/cli/test/integration.test.ts Update CLI path, add item shape stability test
apps/web/vite.config.ts Exclude react-router-dom from dep optimizer
package.json Update build/start/db scripts for new CLI path and per-package builds
pnpm-lock.yaml Add workspace dependency links
docs/CLI_REFERENCE.md Update CLI path references
AGENTS.md Update CLI path and add DI convention notes
.agents/notes.md Update sandbox notes
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sergdort
sergdort merged commit 0494816 into main Mar 5, 2026
5 checks passed
@sergdort
sergdort deleted the refactor-route-dependencies branch March 6, 2026 16:19
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.

2 participants