@aaspai/shared
v0.0.1
Published
Shared utilities and React contexts for AASPAI packages
Readme
@aaspai/shared
Shared utilities, types, and React contexts for Aaspai packages.
Purpose
This package centralizes React Context definitions to prevent duplication issues when using tsup with multiple entry points. By defining contexts here, all Aaspai packages (@aaspai/react, @aaspai/nextjs, etc.) import from the same source, ensuring a single Context instance.
Architecture Pattern
Inspired by @clerk/shared, this package solves the Context duplication problem:
The Problem
When using bundle: true with multiple entry points:
// tsup.config.ts
entry: {
index: 'src/index.ts',
hooks: 'src/hooks/index.ts',
components: 'src/components/index.ts'
}Each entry point bundles its own copy of Context → Provider uses Context instance A, but components use Context instance B → useContext returns undefined.
The Solution
- Centralized Context: Define all Contexts in
@aaspai/shared - External React: Mark
reactas external in tsup config - Shared Import: All packages import Context from
@aaspai/shared
// packages/shared/tsup.config.ts
export default defineConfig({
external: ['react', 'react-dom'], // Critical!
bundle: true,
});Exports
Main Entry (@aaspai/shared)
import type { AaspaiUser, AaspaiContextValue, OAuthProvider } from '@aaspai/shared';React Entry (@aaspai/shared/react)
import { AaspaiContext } from '@aaspai/shared/react';Usage
This package is intended for internal use within the Aaspai monorepo. Application developers should not need to import from it directly.
License
MIT