Repository navigation
feat: ship TypeScript type definitions - #307
Merged
Merged
Conversation
presets.defaults listed 'NVim', but the helper is getNvimInfo and reports 'Nvim', so Neovim was never looked up. Also report 'Nvim' (not 'Vim') on unsupported platforms so it cannot overwrite the Vim entry.
The commonjs2 bundle assigns module.exports at runtime, so Node's
cjs-module-lexer finds no named exports and `import { run } from 'envinfo'`
throws in ESM. Append the no-op `0 && (module.exports = { ... })` hint
after minification so Node can detect cli, helpers, main and run.
Add index.d.ts with category items, presets, options and helpers typed by name, and test it with TypeScript 6 and 7: - test-d/contract.test-d.ts checks the types against src/ (allowJs), so a helper, category item or preset added without types fails to build - test-d/index.test-d.ts covers valid and invalid usage - check:package runs attw on the packed tarball These replace @types/envinfo, which is missing 23 helpers and types helper results as strings.
Also align @types/node with the oldest tested Node.js version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ships type definitions with the package (
index.d.ts), plus tests that keep them in sync withsrc/. The existing@types/envinfohas drifted: it is missing 23 of the 106 helpers (gh, glab, ripgrep, Cursor, Claude Code, bun, Deno, Zig, …) and theMonorepos/pnpmGlobalPackagescategories, and it types helper results asPromise<string>when they resolve to[name, version, path].Category items are typed by name, so typos fail to compile:
How the types are tested
yarn test:typesruns both checks under TypeScript 7 and TypeScript 6:src/(test-d/contract.test-d.ts): withallowJs, tsc infers the exports ofsrc/helpersandsrc/presets, and the test compares them withindex.d.tsin both directions: helper names, categories, the items in each category, preset names, and whether every item has a helper and every preset is a validConfig.presets.jsgets a JSDoc/** @type {const} */cast so tsc keeps the literal names. The cast does nothing at runtime. The errors name what drifted:test-d/index.test-d.ts): the README example, valid calls, and@ts-expect-errorcases understrict+exactOptionalPropertyTypes.yarn check:package): runs attw on the packed tarball. It passes for node10, node16 (CJS and ESM) and bundler resolution.A new
typesCI job runs all three.Fixes found along the way
presets.defaultslisted'NVim', but the helper isgetNvimInfoand it reports'Nvim'. The contract test caught this. The unsupported-platform branch also reported'Vim'instead of'Nvim', so I fixed that too.import { run } from 'envinfo'threwSyntaxError: Named export 'run' not found, because webpack's commonjs2 bundle hides its exports from Node's cjs-module-lexer.@types/envinfoalready allowed this import, so this is not new. A small webpack plugin now appends esbuild's no-op0 && (module.exports = { cli, helpers, main, run })hint after minification. Default import,requireand the CLI are unchanged.Other changes
@types/nodeis aligned to 24.index.d.ts.Not fixed here (found while checking helper names; happy to send follow-ups)
run({ preset: 'cssnano' })throws synchronously ((value || []).map is not a function).run()passes the preset'soptionskey through as a category, whilecli()strips it. This affectscssnano,create-react-appandreact-native-web.getVMwareFusionInforeports'VMWare Fusion', which doesn't match the'VMware Fusion'item, so it never shows up.getEdgeInforesolves to the string'N/A'(not a tuple) on Linux.getPodmanInfoexists but isn't listed in any category.Testing
yarn test(jest, oxlint, prettier, type tests under TS 7 and TS 6) passes on Node 24 and Node 26.yarn build,yarn check:packageandnode src/cli.js --allpass on Node 24 and Node 26.import envinfo from 'envinfo'andimport { run } from 'envinfo'work againstdist/.After release,
@types/envinfoon DefinitelyTyped can be deprecated in favor of the bundled types.BEGIN_COMMIT_OVERRIDE
feat: ship TypeScript type definitions
fix: detect Neovim in the IDEs category
fix: support named imports of envinfo from ESM
END_COMMIT_OVERRIDE