@yutengjing/vscode-icons
v0.1.1
Published
Self-maintained, browser-safe vscode-icons file/folder icon lookup, vendored from the upstream vscode-icons VS Code extension.
Maintainers
Readme
@yutengjing/vscode-icons
Self-maintained, browser-safe file/folder icon lookup, vendored directly from the upstream
vscode-icons VS Code extension.
vscode-icons-ts, an unofficial npm port of the same icon set, stopped receiving updates in 2023.
This package replaces it by vendoring the extension's own assets and regenerating them with
scripts/update-icons.ts instead of relying on a third-party mirror.
Currently vendored version
vscode-icons 12.19.0 (see assets/manifest.json's version field, which is the source of
truth — update this line whenever update-icons runs). 1553 icon SVGs are vendored under
assets/icons/.
Install
npm install @yutengjing/vscode-iconsAPI
getIconForFile(fileName: string): string | undefined— the vendored icon filename (e.g.file_type_typescript.svg), orundefinedwhen nothing matches (fall back toDEFAULT_FILE).getIconForFolder(folderName: string): string— falls back toDEFAULT_FOLDERinternally.getIconForOpenFolder(folderName: string): string— falls back toDEFAULT_FOLDER_OPENEDinternally.DEFAULT_FILE,DEFAULT_FOLDER,DEFAULT_FOLDER_OPENED— the vendored default icon filenames.VSCODE_ICONS_VERSION— the vendored upstream extension version.
Lookup order for getIconForFile mirrors VS Code's own icon-theme resolution:
- An exact, case-insensitive match against
fileNames(e.g.package.json,Cargo.toml,LICENSE). - The longest-to-shortest extension suffix against
fileExtensions(covers compound suffixes vscode-icons ships, such asd.ts,test.tsx, or the three-segmentbuf.gen.yml). - The last extension segment resolved through
src/extension-language-bridge.tsinto alanguageIconsentry.
Step 3 exists because the upstream icon-theme manifest only keys plain, single-segment extensions
(.ts, .py, …) by VS Code language id (typescript, python, …), not by the extension itself
— that resolution normally happens inside VS Code's own language registry, which this package does
not embed. extension-language-bridge.ts is a hand-curated table recreating the subset of that
mapping needed for common languages; see the comment there before extending it.
Consuming the icon SVGs
This package's JS API only resolves filenames (e.g. file_type_typescript.svg); it does not ship
a React component or inline the SVGs. The raw SVG assets live under assets/icons/ inside the
published package, and exports in package.json re-exposes that directory as
@yutengjing/vscode-icons/assets/* so a bundler can resolve them by path.
There are two common ways to consume them:
Copy at build time. Read
assets/icons/<filename>(resolved from the package'sassetsdirectory) and copy or inline the specific SVGs you need into your own build output.Glob with a bundler. With Vite,
import.meta.globcan eagerly or lazily import every vendored icon as a URL:import { getIconForFile, DEFAULT_FILE } from '@yutengjing/vscode-icons'; // Maps '/full/path/to/node_modules/@yutengjing/vscode-icons/assets/icons/file_type_typescript.svg' // -> the built asset URL. const iconUrls = import.meta.glob<string>( '/node_modules/@yutengjing/vscode-icons/assets/icons/*.svg', { eager: true, query: '?url', import: 'default' }, ); function resolveIconUrl(fileName: string): string { const filename = getIconForFile(fileName) ?? DEFAULT_FILE; const entry = Object.entries(iconUrls).find(([path]) => path.endsWith(`/${filename}`)); return entry?.[1] ?? ''; }Adjust the glob root to wherever your bundler resolves
node_modulesfrom; some setups may need a relative glob instead of an absolute one.
Updating the vendored icon set
npm run update-iconsThis runs scripts/update-icons.ts with tsx. It
re-downloads the latest vscode-icons-team.vscode-icons VSIX from open-vsx.org, re-extracts every
icon SVG into assets/icons/, and regenerates assets/manifest.json from the extension's
vsicons-icon-theme.json. Network access only happens while this script runs — the package's
build, typecheck, and test steps never fetch anything.
After running it:
- Update the "Currently vendored version" line above.
- Run
npm testand skim the diff inassets/manifest.jsonandsrc/__tests__/index.test.tsfor icon ids that moved. - Update any downstream icon-id assertions in your own project that reference a specific vscode-icons filename that changed.
Development
npm install
npm run build # emits ESM + .d.ts to dist/
npm test # runs vitest
npm run typecheck # tsc --noEmitLicense
The package source code (everything outside assets/icons/) is licensed under the MIT
License, Copyright (c) YuTengjing.
The icon assets under assets/icons/ are vendored from the vscode-icons
project and are licensed separately under the
Creative Commons Attribution-ShareAlike 4.0 International License. If you
redistribute the icon SVGs (rather than just depending on this package), you must comply with that
license's attribution and share-alike terms.
