Build System (tsup)
Relevant source files
The following files were used as context for generating this wiki page:
The build system for the @pcstyle/auth SDK is powered by tsup, a TypeScript-focused bundler based on esbuild. Its primary purpose is to transform TypeScript source code into highly compatible JavaScript formats (CommonJS and ESM) and generate type definitions for distribution. This setup ensures that the authentication SDK can be seamlessly integrated into various environments, including Next.js applications and Convex backend functions.
Sources: package.json:1-15, tsup.config.ts:1-15
Core Build Configuration
The build process is governed by tsup.config.ts, which defines the entry points, output formats, and dependency handling. The project uses a multi-entry point strategy to allow consumers to import specific modules without pulling in the entire SDK.
Entry Points and Outputs
The build system targets three primary modules within the src directory. Each entry point is compiled into both .js (CommonJS) and .mjs (ESM) formats, located in the dist directory.
| Entry Name | Source Path | Description |
|---|---|---|
index | src/index.ts | Main SDK exports (hooks and types) |
middleware | src/middleware.ts | Next.js authentication middleware |
convex | src/convex.ts | Convex-specific authentication configurations |
Sources: tsup.config.ts:4-8, package.json:7-27
Compilation Pipeline
The following diagram illustrates the flow from TypeScript source files to the final distribution assets:
The build process includes a clean: true step to ensure the dist folder is purged before every build, and sourcemap: true to assist in debugging production issues.
Sources: tsup.config.ts:9-13, tsconfig.json:18-24
Dependency Management
The build system distinguishes between dependencies that should be bundled and those that should be treated as external. Peer dependencies like react and next are explicitly excluded from the bundle to prevent version conflicts in the consuming application.
External Modules
The following packages are marked as external in the build configuration:
reactnext@workos-inc/authkit-nextjs
Sources: tsup.config.ts:14, package.json:28-32
TypeScript Integration
The build system relies on tsconfig.json for base compiler rules, while tsup handles the actual bundling and declaration generation.
| Configuration | Value | Purpose |
|---|---|---|
target | ES2020 | Sets the ECMAScript version for output |
moduleResolution | bundler | Optimizes module lookups for modern tools |
declaration | true | Enables generation of .d.ts files |
jsx | react-jsx | Enables React component compilation |
Sources: tsconfig.json:3-16
Build Commands
Automation is handled via standard npm scripts defined in package.json.
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"typecheck": "tsc --noEmit"
}
- build: Executes a one-time production build.
- dev: Starts a watch mode that recompiles on file changes.
- typecheck: Runs the TypeScript compiler without emitting files to validate code integrity.
Sources: package.json:23-27
Export Mapping
The package.json file defines specific exports that map the build outputs to sub-paths, enabling clean imports for developers.
This configuration ensures that tools can resolve the correct file format based on the environment (Node.js vs. Browser) and the module system (CommonJS vs. ESM) being used by the consumer.
Sources: package.json:7-27, tsup.config.ts:4-9