Skip to content

Commit 3ff5b3d

Browse files
feat: modernize cross-env with TypeScript, Vitest, and ESM-only build (#261)
NOTE: For the vast majority of users running supported versions of Node.js, this should not require any changes and you can update without issue. BREAKING CHANGE: This is a major rewrite that changes the module format from CommonJS to ESM-only. The package now requires Node.js >=20 and only exports ESM modules (not relevant in most cases). BREAKING CHANGE: The package.json exports have been updated to remove CommonJS support. Only ESM imports are now supported. BREAKING CHANGE: All source files have been converted from JavaScript to TypeScript, requiring TypeScript-aware tooling for development. - Replace Jest with Vitest for testing - Convert all source files from .js to .ts with proper TypeScript types - Use zshy for ESM-only builds (removes CJS support) - Adopt @epic-web/config for TypeScript, ESLint, and Prettier - Update to Node.js >=20 requirement - Remove kcd-scripts dependency - Add comprehensive e2e tests with GitHub Actions matrix testing - Update GitHub workflow with caching and cross-platform testing - Modernize documentation and remove outdated sections - Update all dependencies to latest versions - Add proper TypeScript declarations and exports The tool maintains its original functionality while being completely modernized with the latest tooling and best practices Co-authored-by: GitHub Action <[email protected]>
1 parent ad217a0 commit 3ff5b3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+9438
-1254
lines changed

.all-contributorsrc

Lines changed: 0 additions & 255 deletions
This file was deleted.

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ learn how: http://kcd.im/pull-request
1818
Relevant code or config
1919

2020
```javascript
21+
2122
```
2223

2324
What you did:

.github/workflows/auto-format.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Auto Format
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
format:
16+
name: 🔧 Auto Format
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
steps:
22+
- name: 📥 Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
token: ${{ secrets.GITHUB_TOKEN }}
26+
ref: ${{ github.head_ref || github.ref_name }}
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 24
32+
cache: 'npm'
33+
34+
- name: Cache node_modules
35+
uses: actions/cache@v4
36+
with:
37+
path: node_modules
38+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
39+
restore-keys: |
40+
${{ runner.os }}-node-
41+
42+
- name: Install dependencies
43+
run: npm ci
44+
45+
- name: Check current formatting
46+
id: format-check
47+
run: |
48+
if npm run format:check; then
49+
echo "format_needed=false" >> $GITHUB_OUTPUT
50+
echo "✅ Code is already properly formatted"
51+
else
52+
echo "format_needed=true" >> $GITHUB_OUTPUT
53+
echo "⚠️ Code formatting issues found"
54+
fi
55+
56+
- name: Format code
57+
if: steps.format-check.outputs.format_needed == 'true'
58+
run: npm run format
59+
60+
- name: Check for changes
61+
id: changes
62+
if: steps.format-check.outputs.format_needed == 'true'
63+
run: |
64+
if git diff --quiet; then
65+
echo "has_changes=false" >> $GITHUB_OUTPUT
66+
echo "ℹ️ No formatting changes to commit"
67+
else
68+
echo "has_changes=true" >> $GITHUB_OUTPUT
69+
echo "📝 Formatting changes detected"
70+
fi
71+
72+
# CI cannot commit to workflow files, so we need to check for non-workflow changes
73+
- name: Check for non-workflow changes
74+
id: non-workflow-changes
75+
if: steps.changes.outputs.has_changes == 'true'
76+
run: |
77+
git add -A
78+
git reset .github/workflows/
79+
if git diff --cached --quiet; then
80+
echo "has_non_workflow_changes=false" >> $GITHUB_OUTPUT
81+
echo "ℹ️ Only workflow files have formatting changes - skipping commit"
82+
else
83+
echo "has_non_workflow_changes=true" >> $GITHUB_OUTPUT
84+
echo "📝 Non-workflow formatting changes detected"
85+
fi
86+
87+
- name: Configure Git
88+
if:
89+
steps.non-workflow-changes.outputs.has_non_workflow_changes == 'true'
90+
run: |
91+
git config --local user.email "[email protected]"
92+
git config --local user.name "GitHub Action"
93+
94+
- name: Commit and push changes
95+
if:
96+
steps.non-workflow-changes.outputs.has_non_workflow_changes == 'true'
97+
env:
98+
TARGET_REF: ${{ github.head_ref || github.ref_name }}
99+
run: |
100+
git commit -m "chore: 🔧 Auto-format code with Prettier [skip ci]
101+
102+
This commit was automatically generated by the auto-format workflow.
103+
Changes include:
104+
- Code formatting fixes
105+
- Consistent indentation
106+
- Proper line endings"
107+
git push origin HEAD:"$TARGET_REF"
108+
109+
- name: Comment on PR
110+
if:
111+
steps.non-workflow-changes.outputs.has_non_workflow_changes == 'true'
112+
&& github.event_name == 'pull_request'
113+
uses: actions/github-script@v7
114+
with:
115+
script: |
116+
github.rest.issues.createComment({
117+
issue_number: context.issue.number,
118+
owner: context.repo.owner,
119+
repo: context.repo.repo,
120+
body: '🔧 **Auto-formatting applied!**\n\nI\'ve automatically formatted the code using Prettier and pushed the changes. The formatting is now consistent with the project standards.'
121+
})
122+
123+
- name: Success message
124+
if:
125+
steps.changes.outputs.has_changes == 'false' ||
126+
steps.format-check.outputs.format_needed == 'false' ||
127+
steps.non-workflow-changes.outputs.has_non_workflow_changes == 'false'
128+
run: |
129+
if [ "${{ steps.changes.outputs.has_changes }}" == "true" ] && [ "${{ steps.non-workflow-changes.outputs.has_non_workflow_changes }}" == "false" ]; then
130+
echo "✅ Only workflow files had formatting changes - no commit needed!"
131+
else
132+
echo "✅ No formatting changes needed - code is already properly formatted!"
133+
fi

0 commit comments

Comments
 (0)