primitives icon indicating copy to clipboard operation
primitives copied to clipboard

Add GitHub Actions to test package exports with CSS @import validation and fix runtime dependencies

Open Copilot opened this issue 6 months ago • 3 comments

This PR implements automated testing for all package exports to ensure they work correctly for consumers, with comprehensive CSS import validation using actual @import statements.

Problem Solved

The package exports defined in package.json needed validation to ensure they work with pre-release builds and that consumers can properly import CSS files, tokens, and the main API.

Changes Made

Added Explicit Package Exports Added a clear exports field to package.json defining the public API:

{
  "exports": {
    ".": {
      "types": "./dist/build/primerStyleDictionary.d.ts", 
      "import": "./dist/build/primerStyleDictionary.js"
    },
    "./tokens/*": "./src/tokens/*",
    "./dist/*": "./dist/*"
  }
}

Fixed Runtime Dependencies Moved essential dependencies from devDependencies to dependencies:

  • style-dictionary - Required by the main export
  • color2k, json5, prettier, zod - Used by built modules

Added Comprehensive Export Testing

The workflow tests all export patterns with realistic usage:

  • Main API: Validates PrimerStyleDictionary functionality
  • CSS Files: Uses actual @import statements processed with PostCSS to verify CSS imports work correctly:
    @import '@primer/primitives/dist/css/functional/themes/light.css';
    
  • Token Files: Tests source JSON5 token file access
  • Built Files: Validates generated JSON files
  • TypeScript: Ensures type definitions work correctly

Pre-release Testing Added test_exports_prerelease.yml that triggers after Release Candidate workflow to test actual published packages from npm.

Benefits

  • Prevents breaking changes to package exports through automated testing
  • Validates CSS imports realistically using actual @import statements instead of just file existence checks
  • Improves consumer experience with clear, documented exports
  • Catches dependency issues that would cause runtime failures
  • Provides confidence that the package works as intended across different consumption patterns

This ensures reliable consumption of @primer/primitives by other projects and validates that all documented import patterns continue to work.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Aug 05 '25 08:08 Copilot