Skip to content

fix(cli): fall back to plaintext for unknown languages - #1319

Merged
antfu merged 4 commits into
shikijs:mainfrom
Jinjiang:fix/cli-unknown-lang-fallback
Oct 1, 2026
Merged

antfu merged 4 commits into
shikijs:mainfrom
Jinjiang:fix/cli-unknown-lang-fallback

Conversation

@Jinjiang

Copy link
Copy Markdown
Contributor
  • <- Keep this line and put an x between the brackts.

Description

@shikijs/cli currently treats the file extension as a language id. For names like .env.example, that becomes example, which is not a bundled language, so Shiki throws and the file is never printed.

When the CLI is used as a cat replacement (skat), unknown languages should always still print the file. This keeps the empty-extension fallback from #1248 (options.lang || ext || 'text') and adds the missing branch: if the resolved lang is not in bundledLanguages and is not a special language (text / txt / plain / ansi / plaintext), highlight as text.

This is the same idea as @shikijs/rehype's fallbackLanguage, scoped to the CLI. Core still throws for unknown languages (#333). Grammar load/parse failures for known languages are not swallowed. No shebang/content guessing (#1258). Compound suffix mapping (.env.example → dotenv) is intentionally out of scope.

Linked Issues

Additional context

Regressions cover:

When used as a cat replacement, unknown extensions such as
`.env.example` (`example`) should print the file instead of throwing.
Keep the empty-extension fallback from shikijs#1248, and resolve unknown langs
to `text` when they are not bundled and not a special language.
@netlify

netlify Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for shiki-matsu ready!

Name Link
ðŸ”Ļ Latest commit 8a3d2b5
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/6abdec3d0dc3e00008b8375c
😎 Deploy Preview https://deploy-preview-1319--shiki-matsu.netlify.app
ðŸ“ą Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for shiki-next ready!

Name Link
ðŸ”Ļ Latest commit 8a3d2b5
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/6abdec3db0049c0008885887
😎 Deploy Preview https://deploy-preview-1319--shiki-next.netlify.app
ðŸ“ą Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
ðŸĪ– Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.88%. Comparing base (63e6da8) to head (8a3d2b5).
⚠ïļ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1319   +/-   ##
=======================================
  Coverage   89.88%   89.88%           
=======================================
  Files          81       81           
  Lines        3589     3589           
  Branches     1028     1026    -2     
=======================================
  Hits         3226     3226           
  Misses        326      326           
  Partials       37       37           

☔ View full report in Codecov by Harness.
ðŸ“Ē Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄ïļ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • ðŸ“Ķ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Jinjiang and others added 3 commits September 22, 2026 11:27
The extracted helper narrowed theme to string, which failed vue-tsc
against codeToANSI.
`it.compare` is no longer on TestAPI; compare lives on the bench fixture.
This unblocks typecheck, which is already red on main.
â€Ķfallback

# Conflicts:
#	bench/bundle-test/bundle.bench.ts
#	bench/engines/engines.bench.ts
@antfu
antfu merged commit 4eb7c8b into shikijs:main Oct 1, 2026
12 of 13 checks passed
@Jinjiang
Jinjiang deleted the fix/cli-unknown-lang-fallback branch October 1, 2026 05:22
antfu pushed a commit to SHUBHI-KUMARI/shiki that referenced this pull request Oct 1, 2026
Co-authored-by: Anthony Fu (via agent) <reg-github-bot@antfu.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants