Barrel Export Operation Tool
Task Objectives
This Skill is used to automatically generate, optimize, fix, and check barrel export files, ensuring all index files comply with unified specifications:
- Core Principle: All index files (index.ts / index.js) must follow the barrel export specification
- Automatically generate compliant index.ts files
- Fix non-compliant exports
- Check export specifications and generate reports
Trigger Conditions
This Skill is triggered when the user has the following needs:
Core Principle: All index files (index.ts / index.js) must follow the barrel export specification.
Scenario 1: Automatically generate/optimize/fix barrel export files
- "Generate barrel export"
- "Optimize barrel export"
- "Fix barrel export"
- "Fix index.ts"
- "Generate index.ts"
- "Update barrel export"
Scenario 2: Check export specifications
- "Check if exports comply with specifications"
- "Check index.ts"
- "Verify barrel export"
- "Check export files"
Operation Steps
Scenario 1: Automatically generate/optimize/fix barrel export files
Step 1: Confirm target directory
The current directory (
) is locked as the operation object by default. If the user specifies a directory, use the specified directory.
Step 2: Scan current directory files
Use system commands to scan all files in the current directory:
bash
# 列出所有文件
ls -1
# 或扫描特定扩展名
ls -1 *.ts *.tsx *.js *.jsx 2>/dev/null
Identify valid source file types:
- (TypeScript)
- (TypeScript + JSX)
- (JavaScript)
- (JavaScript + JSX)
Step 3: Apply filtering rules
Exclude the following file types:
- / (barrel export files themselves)
- (test files, e.g., )
- (spec files, e.g., )
- (Storybook files, e.g., )
- (declaration files, e.g., )
Step 4: Apply _store special rule
Determine if the current directory is a
directory:
- If it is a directory: Only export / and /
- If it is another directory: Export all valid files
Step 5: Generate export statements
Generate export statements for each valid module:
Unified format:
Requirements:
- Use syntax
- Use relative path
- Sort alphabetically
- Keep filename case consistent with actual files
Step 6: Write or update index.ts
If index.ts does not exist:
Create a new file and write the generated export statements
If index.ts already exists:
- Read the existing content
- Compare existing exports with newly generated exports
- Update the file if there are inconsistencies
Step 7: Verify results
Check the following items:
- ✅ All valid modules have been exported
- ✅ Invalid/duplicate exports have been removed
- ✅ _store special rule has been applied (if applicable)
- ✅ Export format is unified and sorted alphabetically
- ✅ Filename case is consistent with actual files
- ✅ No "module not found" errors
Scenario 2: Check export specifications
Step 1: Confirm target directory
Confirm the directory path to be checked with the user. If not specified, use the current directory (
) by default.
Step 2: Check if index.ts exists
Use system commands to check if an
file exists in the target directory:
- If it does not exist: Report an error and suggest generating first
- If it exists: Proceed with subsequent checks
Step 3: Read and parse index.ts
Use the
tool to read the full content of
and parse each line of export statements.
Step 4: Scan directory files
Use system commands to scan all files in the current directory:
bash
ls -1 *.ts *.tsx *.js *.jsx 2>/dev/null
Identify valid source file types:
- (TypeScript)
- (TypeScript + JSX)
- (JavaScript)
- (JavaScript + JSX)
Step 5: Execute core check items
Perform the following checks:
Check Item 1: File existence check
Check Item 2: Export format specification check
- Check if all export statements use the format
- Check for non-standard formats such as , , etc.
Check Item 3: Sorting check
- Check if export statements are sorted alphabetically by module name
Check Item 4: Duplicate export check
- Check for duplicate module exports
Check Item 5: Export validity check
- Check if each exported module actually exists in the directory
- Check if filename case matches
Check Item 6: Exclusion rule check
- Check if excluded files are exported:
- (test files)
- (spec files)
- (Storybook files)
- (declaration files)
Check Item 7: _store special rule check
- If the directory is named , check if only and are exported
Step 6: Generate check report
Generate a detailed check report in the following format:
=== Barrel Export Specification Check Report ===
📁 Check Directory: <Directory Path>
📊 Statistical Information
- Total Exported Modules: X
- Total Issues: X
✅ Passed Checks: <Quantity>
❌ Failed Checks: <Quantity>
---
Detailed Check Results
1. File Existence Check
✅ Passed / ❌ Failed
Description: <Detailed Description>
2. Export Format Specification Check
✅ Passed / ❌ Failed
Description: <Detailed Description>
Issue List: <List all issues if any>
...
---
💡 Fix Recommendations
<Provide fix recommendations if there are issues>
🎯 Overall Evaluation
✅ Fully Compliant / ⚠️ Partially Compliant / ❌ Non-Compliant
Step 7: Provide fix recommendations
For each failed check item, provide specific fix recommendations.
Notes
Core Principles
All index files (index.ts / index.js) must follow the barrel export specification
Regardless of directory type, number of files, or project scale, as long as index files exist, they must:
- Use unified format:
- Sort alphabetically: Export statements are sorted alphabetically by module name
- Exclude non-exportable files: Do not export test, spec, stories, d.ts, etc.
- Follow _store special rule: If it is a directory, only export and
- Ensure export validity: All exported modules must actually exist
Usage Principles
- Barrel export files are only responsible for exports and do not contain any business logic
- Supports directory path and file path input; file paths will automatically locate to the directory they belong to
- Barrel exports for directories only export and ; other files should not be exposed
- Descriptions in documents must be consistent to avoid ambiguity
- Mandatory compliance: All index files must comply with the barrel export specification without exceptions