Notre avis
Définit des conventions pour les exports de modules et les fichiers barrel dans des projets TypeScript, en mettant l'accent sur les exports nommés et en évitant les ré-exports par wildcard pour un meilleur tree-shaking.
Points forts
- Optimise le tree-shaking en utilisant des exports nommés.
- Structure claire des fichiers barrel avec des commentaires de section.
- Autorise les exports par namespace pour les composants composés comme exception.
- Assure une cohérence dans toute la base de code.
Limites
- Nécessite une discipline pour maintenir l'ordre alphabétique dans les sections.
- Peut être trop strict pour de petits projets où les wildcards sont inoffensifs.
- Non applicable aux projets utilisant CommonJS ou des bundlers anciens.
À utiliser lors de l'organisation d'un grand projet TypeScript avec plusieurs modules pour garantir un bundling efficace et des interfaces d'export claires.
Éviter pour les petits projets ou lors de prototypage rapide où la surcharge de maintenance des fichiers barrel n'est pas justifiée.
Analyse de sécurité
SûrThis skill is a static style guide for TypeScript export patterns. It contains no executable commands, network operations, or file system modifications. There is no risk of executing harmful actions.
Aucun point d'attention détecté
Exemples
Create a barrel index.ts file in the components directory following the named exports convention. Group exports by sections: Components, Hooks, Types. Each export should be on its own line, sorted alphabetically within sections. Do not use wildcard exports. If there are compound components like Dialog or Menu, use export * as Name for them.Refactor the barrel file at src/ui/index.ts to remove all default exports and replace them with named exports. Ensure that source files use named exports instead of default exports. Also replace any export * from wildcards with explicit named exports. Maintain section comments and alphabetical order.Add an export for a new component named 'Button' with its props type 'ButtonProps' in the existing barrel file at src/components/index.ts. Insert it in the Components section in alphabetical order.name: exports description: Export patterns and barrel file conventions. Use when creating/modifying index.ts files or organizing module exports.
Exports & Barrel Files
Standards for module exports and barrel files in the portal app.
Core Principle
Named exports only. No flat wildcards. No default exports in barrels.
Turbopack and modern bundlers handle named exports better for tree-shaking. Flat wildcard export * forces bundlers to include everything and breaks cache invalidation.
Exception: export * as Name is allowed for compound components (Dialog, Menu, etc.) to create namespaces.
Barrel File Structure
Every barrel file follows this structure:
/* eslint-disable */
// Section Name
export { Thing, type ThingProps } from "./thing";
export { Other } from "./other";
// Another Section
export { More } from "./more";
Rules
- ESLint disable at top - Barrel files intentionally re-export
- Section comments - Group related exports with
// Section Name - Alphabetical within sections - Sort exports alphabetically within each group
- Types with values - Export types alongside their values:
export { Foo, type FooProps } - One line per file - Each source file gets one export line
Section Naming
Use these section names consistently:
| Section | Contents |
| ------------ | --------------------------------- |
| Components | React components |
| Hooks | Custom React hooks |
| Types | Type-only exports |
| Constants | Const values, enums, config |
| Utilities | Pure functions |
| Context | React context providers/consumers |
| Mutations | Data mutation hooks (React Query) |
| Queries | Data fetching hooks (React Query) |
| Store | Zustand/state stores |
Examples
Component Barrel
/* eslint-disable */
// Components
export { ActionCard } from "./action-card";
export { ActionList } from "./action-list";
export { ActionPicker } from "./action-picker";
State/Domain Barrel
/* eslint-disable */
// Store
export { useNodesSelection, useNodesSelectionArray } from "./store";
// Types
export {
type NodeOwner,
type NodePermissionRow,
type NodeRow,
type NodeWithMeta,
transformNode,
} from "./types";
UI Library Barrel
For compound components (Dialog, Menu, etc.), export as namespaces using export * as:
/* eslint-disable */
// Simple Components
export { Badge, type BadgeProps } from "./badge";
export { Button, type ButtonProps } from "./button";
export { Input, type InputProps } from "./input";
// Compound Components (namespace exports)
export * as Accordion from "./accordion";
export * as Alert from "./alert";
export * as Dialog from "./dialog";
export * as Menu from "./menu";
// Layout
export { AbsoluteCenter } from "./absolute-center";
export { Group } from "./group";
Note: Compound components use export * as Name to create namespaces (e.g., Dialog.Root, Dialog.Content). This is the ONE exception to the "no wildcards" rule - it creates a namespace, not a flat re-export.
What NOT to Do
No Flat Wildcards
// WRONG - flat wildcard re-exports everything
export * from "./button";
export * from "./card";
// RIGHT - named exports
export { Button, type ButtonProps } from "./button";
// RIGHT - namespace export for compound components
export * as Card from "./card";
No Default Exports in Barrels
// WRONG
export { default as Button } from "./button";
// RIGHT - source file should use named export
export { Button } from "./button";
No Aliasing (Unless Necessary)
// WRONG - unnecessary alias
export { Button as ButtonComponent } from "./button";
// RIGHT
export { Button } from "./button";
// OK - resolving actual name conflict
export { ActionList as ActionListComponent } from "./action-list";
No Mixed Concerns
// WRONG - implementations don't belong in barrel
export { Button } from "./button";
export const DEFAULT_SIZE = "md"; // NO - this belongs in a constants file
// RIGHT - barrel only re-exports
export { Button } from "./button";
export { DEFAULT_SIZE } from "./constants";
When to Create a Barrel
Always. Every directory with exportable code gets an index.ts.
Index Files Are ONLY Barrels
An index.ts file must ONLY contain re-exports. No implementations.
If you find an index.ts with actual code (functions, constants, types defined inline), split it up:
- Move implementations to separate files (e.g.,
utils.ts,types.ts,constants.ts) - Make
index.tsa pure barrel that re-exports from those files
// WRONG - index.ts with implementation
export const FOO = "bar";
export function doThing() { ... }
export interface MyType { ... }
// RIGHT - index.ts as pure barrel
export { FOO } from "./constants";
export { doThing } from "./utils";
export type { MyType } from "./types";
Import Conventions
When importing from barrels:
// GOOD - import from barrel
import { Button, Card, Dialog } from "@/components/ui";
import { useNodes, useNodeMutations } from "@/lib/state";
// AVOID - bypassing barrel for public exports
import { Button } from "@/components/ui/button";
// OK - importing internal/non-exported utilities
import { internalHelper } from "@/components/ui/button/helpers";
Instructions
When creating or modifying barrel files:
- Add
/* eslint-disable */at top - Group exports into logical sections with
// Section Name - Use named exports only - no flat
export *(exception:export * as Namefor compound component namespaces) - Sort exports alphabetically within sections
- Include types with their values on same line
- One export statement per source file
Expert Next.js App Router
Developpement
Un skill qui transforme Claude en expert Next.js App Router.
Générateur de README
Developpement
Crée des README.md professionnels et complets pour vos projets.
Rédacteur de Documentation API
Developpement
Génère de la documentation API complète au format OpenAPI/Swagger.