Skip to content

Commit

Permalink
feat: support custom api-extractor invoke options
Browse files Browse the repository at this point in the history
fix #270
  • Loading branch information
qmhc committed Sep 26, 2023
1 parent ca742e1 commit f8c61e5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -90,7 +90,7 @@ This is an existing [TypeScript issue](https://github.com/microsoft/TypeScript/i

```ts
import type ts from 'typescript'
import type { IExtractorConfigPrepareOptions } from '@microsoft/api-extractor'
import type { IExtractorConfigPrepareOptions, IExtractorInvokeOptions } from '@microsoft/api-extractor'
import type { LogLevel } from 'vite'

type MaybePromise<T> = T | Promise<T>
Expand Down Expand Up @@ -278,6 +278,14 @@ export interface PluginOptions {
*/
rollupConfig?: RollupConfig,

/**
* Override the invoke options of `@microsoft/api-extractor`
*
* @default null
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
*/
rollupOptions?: IExtractorInvokeOptions,

/**
* Whether to copy .d.ts source files to `outDir`
*
Expand Down
10 changes: 9 additions & 1 deletion README.zh-CN.md
Expand Up @@ -90,7 +90,7 @@ export default defineConfig({

```ts
import type ts from 'typescript'
import type { IExtractorConfigPrepareOptions } from '@microsoft/api-extractor'
import type { IExtractorConfigPrepareOptions, IExtractorInvokeOptions } from '@microsoft/api-extractor'
import type { LogLevel } from 'vite'

type MaybePromise<T> = T | Promise<T>
Expand Down Expand Up @@ -278,6 +278,14 @@ export interface PluginOptions {
*/
rollupConfig?: RollupConfig,

/**
* 覆写 `@microsoft/api-extractor` 的调用选项
*
* @default null
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
*/
rollupOptions?: IExtractorInvokeOptions,

/**
* 是否将源码里的 .d.ts 文件复制到 `outDir`
*
Expand Down
7 changes: 5 additions & 2 deletions src/plugin.ts
Expand Up @@ -76,6 +76,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
rollupTypes = false,
pathsToAliases = true,
aliasesExclude = [],
rollupOptions = {},
copyDtsFiles = false,
declarationOnly = false,
strictOutput = true,
Expand Down Expand Up @@ -625,7 +626,8 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
entryPath: path,
fileName: basename(path),
libFolder,
rollupConfig
rollupConfig,
rollupOptions
})

emittedFiles.delete(path)
Expand All @@ -640,7 +642,8 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
entryPath: typesPath,
fileName: basename(typesPath),
libFolder,
rollupConfig
rollupConfig,
rollupOptions
})

emittedFiles.delete(typesPath)
Expand Down
11 changes: 7 additions & 4 deletions src/rollup.ts
Expand Up @@ -4,7 +4,7 @@ import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'
import { tryGetPkgPath } from './utils'

import type ts from 'typescript'
import type { ExtractorLogLevel } from '@microsoft/api-extractor'
import type { ExtractorLogLevel, IExtractorInvokeOptions } from '@microsoft/api-extractor'
import type { RollupConfig } from './types'

export interface BundleOptions {
Expand All @@ -15,7 +15,8 @@ export interface BundleOptions {
entryPath: string,
fileName: string,
libFolder?: string,
rollupConfig?: RollupConfig
rollupConfig?: RollupConfig,
rollupOptions?: IExtractorInvokeOptions
}

const dtsRE = /\.d\.tsx?$/
Expand All @@ -28,7 +29,8 @@ export function rollupDeclarationFiles({
entryPath,
fileName,
libFolder,
rollupConfig = {}
rollupConfig = {},
rollupOptions = {}
}: BundleOptions) {
const configObjectFullPath = resolve(root, 'api-extractor.json')

Expand Down Expand Up @@ -87,7 +89,8 @@ export function rollupDeclarationFiles({
localBuild: false,
showVerboseMessages: false,
showDiagnostics: false,
typescriptCompilerFolder: libFolder ? resolve(libFolder) : undefined
typescriptCompilerFolder: libFolder ? resolve(libFolder) : undefined,
...rollupOptions
})

return result.succeeded
Expand Down
13 changes: 12 additions & 1 deletion src/types.ts
@@ -1,5 +1,8 @@
import type ts from 'typescript'
import type { IExtractorConfigPrepareOptions } from '@microsoft/api-extractor'
import type {
IExtractorConfigPrepareOptions,
IExtractorInvokeOptions
} from '@microsoft/api-extractor'
import type { LogLevel } from 'vite'

type MaybePromise<T> = T | Promise<T>
Expand Down Expand Up @@ -184,6 +187,14 @@ export interface PluginOptions {
*/
rollupConfig?: RollupConfig,

/**
* Override the invoke options of `@microsoft/api-extractor`
*
* @default null
* @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
*/
rollupOptions?: IExtractorInvokeOptions,

/**
* Whether to copy .d.ts source files to `outDir`
*
Expand Down

0 comments on commit f8c61e5

Please sign in to comment.