Add GitHub Actions to test package exports with CSS @import validation and fix runtime dependencies#1244
Add GitHub Actions to test package exports with CSS @import validation and fix runtime dependencies#1244
Conversation
Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
|
Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
There was a problem hiding this comment.
@copilot The test is failing:
0s
Run cd test-exports
cd test-exports
PACKAGE_FILE=$(ls ../@primer-primitives-.tgz | head -1)
npm install "$PACKAGE_FILE"
shell: /usr/bin/bash -e {0}
ls: cannot access '../@primer-primitives-.tgz': No such file or directory
up to date, audited 1 package in 247ms
found 0 vulnerabilities
0s
Run cd test-exports
cd test-exports
cat > test-main.mjs << 'EOF'
// Test main export
try {
const { PrimerStyleDictionary } = await import('@primer/primitives');
console.log('✓ Main export works:', typeof PrimerStyleDictionary);
if (!PrimerStyleDictionary || typeof PrimerStyleDictionary !== 'object') {
throw new Error('PrimerStyleDictionary is not properly exported');
}
// Test that it has expected methods
if (typeof PrimerStyleDictionary.extend !== 'function') {
throw new Error('PrimerStyleDictionary.extend is not a function');
}
console.log('✓ PrimerStyleDictionary has expected API');
} catch (error) {
console.error('✗ Main export failed:', error.message);
process.exit(1);
}
EOF
node test-main.mjs
shell: /usr/bin/bash -e {0}
✗ Main export failed: Cannot find package '@primer/primitives' imported from /home/runner/work/primitives/primitives/test-exports/test-main.mjs
Error: Process completed with exit code 1.
0s
|
@copilot The test is failing: 0s up to date, audited 1 package in 247ms found 0 vulnerabilities } catch (error) { |
Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
|
|
||
| - name: Test CSS exports | ||
| run: | | ||
| cd test-exports |
There was a problem hiding this comment.
Updated in commit 6533023. The CSS testing now uses actual @import statements processed with PostCSS instead of just checking file existence. The test creates CSS files with @import statements like @import '@primer/primitives/dist/css/functional/themes/light.css'; and uses PostCSS with postcss-import to verify they resolve correctly and include the expected content.
Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
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.jsonneeded 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
exportsfield topackage.jsondefining 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
devDependenciestodependencies:style-dictionary- Required by the main exportcolor2k,json5,prettier,zod- Used by built modulesAdded Comprehensive Export Testing
The workflow tests all export patterns with realistic usage:
PrimerStyleDictionaryfunctionality@importstatements processed with PostCSS to verify CSS imports work correctly:Pre-release Testing
Added
test_exports_prerelease.ymlthat triggers after Release Candidate workflow to test actual published packages from npm.Benefits
This ensures reliable consumption of
@primer/primitivesby 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.