Skip to content

Commit

Permalink
fix: adapt @microsoft/api-extractor 7.33+
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Oct 13, 2022
1 parent 958c179 commit 5acb4be
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
3 changes: 3 additions & 0 deletions example/tsconfig.json
Expand Up @@ -13,6 +13,9 @@
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"types": [
"vite/client"
],
"baseUrl": ".",
"paths": {
"@/*": ["./*"],
Expand Down
2 changes: 1 addition & 1 deletion example/vite.config.ts
Expand Up @@ -35,7 +35,7 @@ export default defineConfig({
staticImport: true,
skipDiagnostics: false,
logDiagnostics: true,
// rollupTypes: true,
rollupTypes: true,
insertTypesEntry: true
}),
vue()
Expand Down
33 changes: 16 additions & 17 deletions package.json
Expand Up @@ -6,9 +6,8 @@
"url": "https://github.com/qmhc/vite-plugin-dts/issues"
},
"dependencies": {
"@microsoft/api-extractor": "^7.32.0",
"@rushstack/node-core-library": "^3.53.0",
"chalk": "^4.1.2",
"@microsoft/api-extractor": "^7.33.1",
"@rushstack/node-core-library": "^3.53.2",
"debug": "^4.3.4",
"fast-glob": "^3.2.12",
"fs-extra": "^10.1.0",
Expand All @@ -21,37 +20,37 @@
"@types/debug": "^4.1.7",
"@types/fs-extra": "^9.0.13",
"@types/minimist": "^1.2.2",
"@types/node": "^18.7.23",
"@types/prompts": "^2.0.14",
"@types/node": "^18.8.5",
"@types/prompts": "^2.4.1",
"@types/semver": "^7.3.12",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"@vitejs/plugin-vue": "^3.1.0",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"@vitejs/plugin-vue": "^3.1.2",
"@vue/eslint-config-standard": "^8.0.1",
"@vue/eslint-config-typescript": "^11.0.2",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"eslint": "^8.24.0",
"eslint": "^8.25.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.1",
"eslint-plugin-vue": "^9.5.1",
"eslint-plugin-promise": "^6.1.0",
"eslint-plugin-vue": "^9.6.0",
"execa": "^6.1.0",
"husky": "^8.0.1",
"is-ci": "^3.0.1",
"lint-staged": "^13.0.3",
"minimist": "^1.2.6",
"minimist": "^1.2.7",
"pinst": "^3.0.0",
"prettier": "^2.7.1",
"pretty-quick": "^3.1.3",
"prompts": "^2.4.2",
"rimraf": "^3.0.2",
"semver": "^7.3.7",
"tsx": "^3.9.0",
"typescript": "4.7.4",
"semver": "^7.3.8",
"tsx": "^3.10.1",
"typescript": "4.8.4",
"unbuild": "^0.8.11",
"vite": "^3.1.4",
"vitest": "^0.23.4",
"vite": "^3.1.8",
"vitest": "^0.24.1",
"vue": "3.2.40"
},
"engines": {
Expand Down
24 changes: 11 additions & 13 deletions src/plugin.ts
@@ -1,7 +1,7 @@
import { resolve, dirname, relative, basename } from 'node:path'
import fs from 'fs-extra'
import os from 'os'
import chalk from 'chalk'
import { cyan, yellow, red, green } from 'kolorist'
import glob from 'fast-glob'
// import execa from 'execa'
import debug from 'debug'
Expand Down Expand Up @@ -72,7 +72,7 @@ const defaultIndex = 'index.d.ts'
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {}

const logPrefix = chalk.cyan('[vite:dts]')
const logPrefix = cyan('[vite:dts]')
const bundleDebug = debug('vite-plugin-dts:bundle')

export function dtsPlugin(options: PluginOptions = {}): Plugin {
Expand Down Expand Up @@ -155,8 +155,8 @@ export function dtsPlugin(options: PluginOptions = {}): Plugin {

if (!config.build.lib) {
logger.warn(
chalk.yellow(
`\n${chalk.cyan(
yellow(
`\n${cyan(
'[vite:dts]'
)} You building not a library that may not need to generate declaration files.\n`
)
Expand Down Expand Up @@ -184,8 +184,8 @@ export function dtsPlugin(options: PluginOptions = {}): Plugin {

if (!outputDirs[0]) {
logger.error(
chalk.red(
`\n${chalk.cyan(
red(
`\n${cyan(
'[vite:dts]'
)} Can not resolve declaration directory, please check your vite config and plugin options.\n`
)
Expand Down Expand Up @@ -260,7 +260,7 @@ export function dtsPlugin(options: PluginOptions = {}): Plugin {
async closeBundle() {
if (!outputDirs || !project || isBundle) return

logger.info(chalk.green(`\n${logPrefix} Start generate declaration files...`))
logger.info(green(`\n${logPrefix} Start generate declaration files...`))
bundleDebug('start')

isBundle = true
Expand Down Expand Up @@ -317,8 +317,8 @@ export function dtsPlugin(options: PluginOptions = {}): Plugin {
if (hasJsVue) {
if (!allowJs) {
logger.warn(
chalk.yellow(
`${chalk.cyan(
yellow(
`${cyan(
'[vite:dts]'
)} Some js files are referenced, but you may not enable the 'allowJs' option.`
)
Expand Down Expand Up @@ -475,7 +475,7 @@ export function dtsPlugin(options: PluginOptions = {}): Plugin {
bundleDebug('insert index')

if (rollupTypes) {
logger.info(chalk.green(`${logPrefix} Start rollup declaration files...`))
logger.info(green(`${logPrefix} Start rollup declaration files...`))

rollupDeclarationFiles({
root,
Expand Down Expand Up @@ -533,9 +533,7 @@ export function dtsPlugin(options: PluginOptions = {}): Plugin {

bundleDebug('finish')

logger.info(
chalk.green(`${logPrefix} Declaration files built in ${Date.now() - startTime}ms.\n`)
)
logger.info(green(`${logPrefix} Declaration files built in ${Date.now() - startTime}ms.\n`))
}
}
}
9 changes: 7 additions & 2 deletions src/rollup.ts
Expand Up @@ -2,6 +2,7 @@ import { resolve } from 'node:path'
import { ExtractorConfig, CompilerState } from '@microsoft/api-extractor'
import { Collector } from '@microsoft/api-extractor/lib/collector/Collector.js'
import { MessageRouter } from '@microsoft/api-extractor/lib/collector/MessageRouter.js'
import { SourceMapper } from '@microsoft/api-extractor/lib/collector/SourceMapper.js'
import {
DtsRollupGenerator,
DtsRollupKind
Expand Down Expand Up @@ -82,19 +83,23 @@ export function rollupDeclarationFiles({
showVerboseMessages: false
} as IExtractorInvokeOptions)

const sourceMapper = new SourceMapper()

const messageRouter = new MessageRouter({
workingPackageFolder: root,
messageCallback: undefined,
messagesConfig: extractorConfig.messages as any,
showVerboseMessages: false,
showDiagnostics: false,
tsdocConfiguration: extractorConfig.tsdocConfiguration
tsdocConfiguration: extractorConfig.tsdocConfiguration,
sourceMapper
})

const collector = new Collector({
program: compilerState.program as any,
messageRouter,
extractorConfig: extractorConfig as any
extractorConfig: extractorConfig as any,
sourceMapper
})

collector.analyze()
Expand Down

0 comments on commit 5acb4be

Please sign in to comment.