Skip to content

Commit

Permalink
feat: enabld dts only when typescript is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 29, 2021
1 parent 2c6ad74 commit 6a1a2ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"dependencies": {
"@antfu/utils": "^0.3.0",
"@rollup/pluginutils": "^4.1.1",
"has-pkg": "^0.0.1",
"magic-string": "^0.25.7",
"unplugin": "^0.2.1"
},
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions src/core/options.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { resolve } from 'path'
import { toArray } from '@antfu/utils'
import { createFilter } from '@rollup/pluginutils'
import hasPkg from 'has-pkg'
import { presets } from '../presets'
import { ImportInfo, ImportsFlatMap, Options, ResolvedOptions } from '../types'

export function resolveOptions(options: Options = {}): ResolvedOptions {
const imports = flattenImportsMap(options.imports, options.presetOverriding)

const { dts = hasPkg('typescript') } = options
const resolved: ResolvedOptions = {
sourceMap: false,
...options,
dts: options.dts === false
dts: dts === false
? false
: resolve(options.dts || 'auto-imports.d.ts'),
: dts === true
? resolve('auto-imports.d.ts')
: resolve(dts),
imports,
matchRE: new RegExp(`\\b(${Object.keys(imports).join('|')})\\b`, 'g'),
idFilter: createFilter(
Expand Down
7 changes: 4 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ export interface Options {
imports?: Arrayable<ImportsMap | PresetName>
/**
* Filepath to generate corresponding .d.ts file.
* Default enabled when `typescript` is installed locally.
* Set `false` to disable.
*
* @default './auto-imports.d.ts'
*/
dts?: string | false
dts?: string | boolean
/**
* Allow overriding imports sources from multiple presets.
*
Expand All @@ -52,7 +53,7 @@ export interface Options {
exclude?: FilterPattern
/**
* Generate source map.
*
*
* @default false
*/
sourceMap?: boolean
Expand All @@ -64,7 +65,7 @@ export interface TransformOptions {

/**
* Generate source map.
*
*
* @default false
*/
sourceMap?: boolean
Expand Down

0 comments on commit 6a1a2ac

Please sign in to comment.