From 5acb4be4d1e4fe41e42a38ec9e92eeeb6f3a9c15 Mon Sep 17 00:00:00 2001 From: qmhc <40221744+qmhc@users.noreply.github.com> Date: Thu, 13 Oct 2022 19:34:39 +0800 Subject: [PATCH] fix: adapt @microsoft/api-extractor 7.33+ --- example/tsconfig.json | 3 +++ example/vite.config.ts | 2 +- package.json | 33 ++++++++++++++++----------------- src/plugin.ts | 24 +++++++++++------------- src/rollup.ts | 9 +++++++-- 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/example/tsconfig.json b/example/tsconfig.json index df0a44e..e2856de 100644 --- a/example/tsconfig.json +++ b/example/tsconfig.json @@ -13,6 +13,9 @@ "resolveJsonModule": true, "esModuleInterop": true, "skipLibCheck": true, + "types": [ + "vite/client" + ], "baseUrl": ".", "paths": { "@/*": ["./*"], diff --git a/example/vite.config.ts b/example/vite.config.ts index 1ec9e9d..bb94693 100644 --- a/example/vite.config.ts +++ b/example/vite.config.ts @@ -35,7 +35,7 @@ export default defineConfig({ staticImport: true, skipDiagnostics: false, logDiagnostics: true, - // rollupTypes: true, + rollupTypes: true, insertTypesEntry: true }), vue() diff --git a/package.json b/package.json index 0822462..bcc405e 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/src/plugin.ts b/src/plugin.ts index de291ea..9511e40 100644 --- a/src/plugin.ts +++ b/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' @@ -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 { @@ -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` ) @@ -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` ) @@ -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 @@ -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.` ) @@ -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, @@ -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`)) } } } diff --git a/src/rollup.ts b/src/rollup.ts index d8563bd..150b1e1 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -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 @@ -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()