Dependencies for the Export Module in Google Labs Design.md
The export module depends on the citty CLI framework, internal linter handlers located in packages/cli/src/linter/, and runtime libraries including unified, yaml, and zod to transform DESIGN.md files into CSS, JSON, or Tailwind formats.
The export command in the @google/design.md CLI toolchain converts Markdown-based design tokens into actionable code for various platforms. Understanding the dependencies for the export module is essential for troubleshooting pipeline failures or extending the tool with custom emitters. This guide maps every internal import and external package required to execute the export functionality.
Core Runtime Dependencies
The export functionality is implemented in packages/cli/src/commands/export.ts and relies on dependencies declared in packages/cli/package.json. These packages provide the parsing, validation, and serialization capabilities used by the export pipeline:
- citty (
^0.1.6): Powers the command-line interface usingdefineCommandto register the export command and validate theformatargument against the closedFORMATSenum. - unified (
^11.0.5): Orchestrates the Markdown processing pipeline alongsideremark-parse(^11.0.0),remark-stringify(^11.0.0), andremark-mdx(^3.1.1). - yaml (
^2.7.1): Parses YAML frontmatter within DESIGN.md files. - zod (
^3.24.0): Validates data structures against schemas during the linting phase. - unist-util-visit (
^5.1.0): Traverses the Markdown AST during the linting process. - remark-frontmatter (
^5.0.0): Handles frontmatter extraction from DESIGN.md files.
Internal Module Dependency Graph
Beyond npm packages, the export command imports several internal modules that form the processing pipeline.
CLI Framework and Input Utilities
The command integrates with the CLI framework through citty and utility functions defined in packages/cli/src/utils.ts:
readInput: Reads DESIGN.md source from a file path orstdin.FileReadError: Error class thrown when input reading fails.
Linter API and Emitter Handlers
The core export logic resides in packages/cli/src/linter/index.js, which re-exports the primary API and all emitter implementations:
lint: The main entry point that parses content and returns aLintReportcontaining aDesignSystemState.TailwindEmitterHandler: Located inpackages/cli/src/linter/tailwind/handler.ts, handles Tailwind v3 JSON exports.TailwindV4EmitterHandler: Located inpackages/cli/src/linter/tailwind/v4/handler.ts, manages Tailwind v4 CSS@themeexports.DtcgEmitterHandler: Located inpackages/cli/src/linter/dtcg/handler.ts, emits W3C Design Tokens (DTCG) JSON.CssVarsEmitterHandler: Located inpackages/cli/src/linter/css-vars/handler.ts, generates CSS custom property declarations.
Format-Specific Serializers
Certain handlers delegate to specialized serializers for final output generation:
serializeTailwindV4: Located inpackages/cli/src/linter/tailwind/v4/serialize.ts, converts internal theme data to CSS@themesyntax.serializeCssVars: Located inpackages/cli/src/linter/css-vars/serialize.ts, transforms declaration maps into CSS strings with optional prefixes.
Export Pipeline Execution Flow
The dependencies work together in a six-stage pipeline defined in packages/cli/src/commands/export.ts:
- Argument parsing:
cittycreates the command and validates theformatargument. - Input loading:
readInputingests the DESIGN.md source from either a file path orstdin. - Linting:
lint(content)builds aLintReportcontaining a fully parsedDesignSystemState. - Export selection: Based on
args.format, the corresponding emitter handler (e.g.,TailwindV4EmitterHandlerorCssVarsEmitterHandler) is instantiated. - Result handling: The handler returns a
successflag and either an error object or exported data (result.data). - Serialization: For Tailwind v4 and CSS Vars, the respective serializer converts internal data structures to the final text format written to
stdout.
Usage Examples
These commands demonstrate how the dependencies process DESIGN.md files:
# Export to Tailwind v4 CSS @theme
design.md export ./design/DESIGN.md --format css-tailwind > tailwind-theme.css
# Export to Tailwind v3 JSON using stdin
design.md export --format json-tailwind < DESIGN.md > tailwind-theme.json
# Export to W3C Design Tokens (DTCG) JSON
design.md export ./DESIGN.md --format dtcg > dtcg.json
# Export CSS custom properties with a prefix
design.md export ./DESIGN.md --format css-vars --prefix --my-prefix- > vars.css
Each command follows the same dependency chain: the CLI parses arguments, readInput loads the source, the linter builds the state, the selected emitter handler processes the format, and the serializer produces the final output.
Summary
- The export module in
packages/cli/src/commands/export.tsrelies on citty for CLI parsing and internal linter modules for format conversion. - Runtime dependencies from
packages/cli/package.jsonincludeunified,yaml,zod, and remark-related packages for Markdown processing. - Emitter handlers in
packages/cli/src/linter/provide specific export formats: Tailwind v3/v4, DTCG, and CSS Variables. - Serializer functions like
serializeTailwindV4andserializeCssVarshandle final text generation for complex formats. - The pipeline executes through six distinct stages from argument parsing to final serialization.
Frequently Asked Questions
What external libraries are required to run the export module?
The export module requires citty for command definition, unified and remark packages for Markdown parsing, yaml for frontmatter processing, and zod for schema validation. These are declared as dependencies in packages/cli/package.json and are installed automatically with the @google/design.md CLI package.
How does the export module handle different output formats?
The module uses a handler-based architecture where args.format determines which emitter class is instantiated. The TailwindEmitterHandler, TailwindV4EmitterHandler, DtcgEmitterHandler, and CssVarsEmitterHandler classes each implement format-specific logic, with some delegating to specialized serializers like serializeTailwindV4 for final output generation.
Can I extend the export module with custom output formats?
Yes, you can extend the pipeline by creating a new emitter handler class following the pattern established in packages/cli/src/linter/dtcg/handler.ts or packages/cli/src/linter/css-vars/handler.ts. Register your handler in packages/cli/src/linter/index.ts and add the format identifier to the FORMATS enum processed by citty in packages/cli/src/commands/export.ts.
Why does the export module depend on remark parsers if it only exports design tokens?
The export process begins with linting the DESIGN.md source to build a DesignSystemState. The linter uses unified, remark-parse, and remark-mdx to parse the Markdown/MDX content, extract YAML frontmatter via remark-frontmatter, and traverse the AST using unist-util-visit before the export handlers can transform the tokens into their target formats.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →