import { SFCDescriptor } from '@vue/compiler-sfc'; import { IVueDtsOptions } from 'gs-rollup-plugin-vue-dts'; import { ExternalOption, InputOption, ModuleFormat, NullValue, OutputOptions, Plugin } from 'rollup'; import { Options } from 'rollup-plugin-esbuild'; import { PackageJson } from 'type-fest'; import { IRawLoaderArg } from './plugins.d.ts'; type CopyRenameFn = (name: string, extension: string, fullPath: string) => string; type ICopyTransformFn = (contents: Buffer, name: string) => Buffer | string; interface ICopyTarget { readonly src: string | readonly string[]; readonly dest?: string | readonly string[]; readonly rename?: string | CopyRenameFn; readonly transform?: ICopyTransformFn; } interface IDefineArg { outputBase?: string; input?: InputOption; outputCodeDir?: string; includeInputDir?: boolean; /** * 是否包含src目录 * - 当 `includeInputDir` 为 `true` 时,此属性才有效 */ includeInputSrc?: boolean; } interface IDefineOutputOptionBase { format: ModuleFormat; extension?: string; /** * 覆盖输出选项 */ overwriteProps?: OutputOptions; } interface IDefineOutputOption extends IDefineArg, IDefineOutputOptionBase { } declare const esFormats: readonly ["es", "esm", "module"]; declare const cjsFormats: readonly ["cjs", "commonjs"]; interface IDefineJsFormat { format: ModuleFormat; extension?: string; } type DefineJsFormat = IDefineJsFormat | ModuleFormat; type DefinePackageJsonFormat = DefineJsFormat | '.d.ts'; type IImportReplaceFn = (modulePath: string, currentFile: string) => string; type CodeModifyFn = (code: string, currentFile: string) => string; interface IImportReplaceRole { search: RegExp; replace: string | ((substring: string, ...args: any[]) => string); ensureExtension?: boolean; } type ImportReplaceRole = IImportReplaceRole[] | IImportReplaceFn; interface IPostCodeModify { importReplace?: RT; codeModify?: CodeModifyFn; } type PostCodeModify = IPostCodeModify | ImportReplaceRole; interface IExternalByInputArg { current: string; currentPath: string; inputs: Record; itemArg: IDefineItemArg; } type FormatInputFn = (arg?: IDefineItemArg) => Record; type ExternalFn = (source: string, importer: string | undefined, isResolved: boolean) => boolean | NullValue; type ExternalByInputFn = (arg: IExternalByInputArg) => ExternalFn; interface IDefineItemArg extends IDefineArg { external?: ExternalOption; plugins?: Plugin[]; postCodeModify?: boolean | PostCodeModify; addPlugins?: Plugin[]; formatInput?: FormatInputFn; addExternal?: ExternalOption; externalByInput?: ExternalByInputFn; } interface IPackageJsonExport { input?: string | string[] | Record; formats?: DefinePackageJsonFormat[]; outputCodeDir?: string; includeInputDir?: boolean; includeInputSrc?: boolean; default?: string; } type PackageJsonExport = false | string | string[] | IPackageJsonExport; interface IPackageJsonArg { minify?: boolean; outputBase?: string; input?: string; overwriteProps?: PackageJson; deleteProps?: false | RegExp; deleteChildProps?: Partial>; before?: (pkg: PackageJson) => PackageJson | void; after?: (pkg: PackageJson) => PackageJson | void; exports?: PackageJsonExport; formatInput?: FormatInputFn; } interface IDefineJsArg extends IDefineItemArg { formats?: DefineJsFormat | DefineJsFormat[]; esbuild?: Options; rawLoader?: IRawLoaderArg; } interface IDefineDtsArg extends IDefineItemArg { exclude?: string | string[]; copyMd?: boolean; output?: OutputOptions; buildPackageJson?: IPackageJsonArg | boolean; vueDts?: IVueDtsOptions | boolean; } interface IConfigToJsonContext { name: string; file: string; } type ConfigToJsonTransform = (data: any, ctx: IConfigToJsonContext) => any | Promise; interface IConfigToJsonArg { transform?: ConfigToJsonTransform; minify?: boolean; } interface IDetectedOption { /** * 仅包含 `string[]` 与 `Record` 类型 * - 分析值逻辑,前一项无结果时使用后一项 * 1. 根据 `package.json` 中的 `file` `main` 、`exports` 、`types` 、排除 `outputBase`,`outputCodeDir` 的后续路径确定,值类型为 `Record` * 2. 上一项不存在时,查找 项目中所有 `index.ts` 文件, 值类型为 `string[]` * 3. 以上都不存在时,默认值为 `["src/index.ts"]` */ input: InputOption; /** * 默认为 `true` * - 仅在 `package.json` 中 * 1. `exports` 中存在js定义,但不存在 `types` 时为 `false` * 2. 存在 `main` 但不存在 `types` 时为 `false` */ types: boolean; /** * 根据 `package.json` 中的 `main` 与 `exports` 确定输入文件 * - 默认值为 `['cjs','es']` */ jsFormats: DefineJsFormat | DefineJsFormat[]; /** * 根据 `package.json` 中的 `file` `main` 、`exports` 、`types` 的完全相同的第一个目录 * - 如果所有前缀皆不同 则值为 空字符串 * - 如果未存在定义,默认值 为 `dist` */ outputBase: string; /** * 根据 `package.json` 中的 `file` `main` 、`exports` 、`types` 的完全相同的第二个起的后续目录确定 * - 如果所有前缀皆不同 则值为 空字符串 * - 如果未存在定义,默认值 为 `lib` */ outputCodeDir: string; /** * 当前项目是否为vue项目 0- 项目中存在vue文件,即认为是vue项目 */ isVue: boolean; } interface IGsRollupDefaults extends IDetectedOption, Pick { external: ExternalOption; formatInput?: FormatInputFn; copyRename?: CopyRenameFn; init(showPattern?: boolean): IDetectedOption; } type VueTsToJsCompileMode = 'vue' | 'esbuild' | 'none'; interface IVueCode extends Pick { } interface IVueTsToJsOption { filename?: string; compile?: VueTsToJsCompileMode; /** * 如果设置了 `compile`, 将在 `compile` 之后执行 */ scriptCodeModify?: PostCodeModify; /** * 最后执行 */ vueCodeModify?: (code: IVueCode) => IVueCode; } interface IVueCopyTargetOption extends Omit, Pick { } interface IFileOperationTarget { src: string | string[]; dest?: string | string[]; rename?: (fullPath: string) => string; transform?: (code: string, file: string) => any; } interface IFileOperationValidTarget extends Omit { src: string[]; dest: string[]; } type FileOperationTarget = string | IFileOperationTarget; type FileOperationOption = FileOperationTarget | FileOperationTarget[]; export { cjsFormats, esFormats }; export type { CodeModifyFn, ConfigToJsonTransform, CopyRenameFn, DefineJsFormat, DefinePackageJsonFormat, ExternalByInputFn, ExternalFn, FileOperationOption, FileOperationTarget, FormatInputFn, IConfigToJsonArg, IConfigToJsonContext, ICopyTarget, ICopyTransformFn, IDefineArg, IDefineDtsArg, IDefineItemArg, IDefineJsArg, IDefineJsFormat, IDefineOutputOption, IDetectedOption, IExternalByInputArg, IFileOperationTarget, IFileOperationValidTarget, IGsRollupDefaults, IImportReplaceFn, IImportReplaceRole, ImportReplaceRole, IPackageJsonArg, IPackageJsonExport, IPostCodeModify, IVueCode, IVueCopyTargetOption, IVueTsToJsOption, PackageJsonExport, PostCodeModify, VueTsToJsCompileMode };