Skip to content

Commit 90fc55d

Browse files
feat: add defineConfig helper (#1551)
Co-authored-by: Raine Revere <[email protected]>
1 parent 71982be commit 90fc55d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,12 +888,24 @@ Some options offer more advanced configuration using a function definition. Thes
888888
For example, `.ncurc.js`:
889889
890890
```js
891+
/** @type {import('npm-check-updates').RcOptions } */
891892
module.exports = {
892893
upgrade: true,
893894
filter: name => name.startsWith('@myorg/'),
894895
}
895896
```
896897
898+
Alternatively, you can use the defineConfig helper which should provide intellisense without the need for jsdoc annotations:
899+
900+
```js
901+
const { defineConfig } = require('npm-check-updates')
902+
903+
module.exports = defineConfig({
904+
upgrade: true,
905+
filter: name => name.startsWith('@myorg/'),
906+
})
907+
```
908+
897909
### JSON Schema
898910
899911
If you write `.ncurc` config files using json or yaml, you can add the JSON Schema to your IDE settings for completions.

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import { PackageInfo } from './types/PackageInfo'
2323
import { RunOptions } from './types/RunOptions'
2424
import { VersionSpec } from './types/VersionSpec'
2525

26+
export { default as defineConfig } from './lib/defineConfig'
27+
export type { RcOptions } from './types/RcOptions'
28+
2629
// allow prompt injection from environment variable for testing purposes
2730
if (process.env.INJECT_PROMPTS) {
2831
prompts.inject(JSON.parse(process.env.INJECT_PROMPTS))

src/lib/defineConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { RcOptions } from '../types/RcOptions'
2+
3+
/**
4+
* TypeScript helper for .npmrc config file. Similar to vite and eslint's
5+
* defineConfig helper
6+
*/
7+
function defineConfig(config: RcOptions) {
8+
return config
9+
}
10+
11+
export default defineConfig

0 commit comments

Comments
 (0)