UNPKG

rollup-plugin-api-extractor

Version:

A rollupjs plugin for integrating with @microsoft/api-extractor

65 lines 7.8 kB
{ "name": "rollup-plugin-api-extractor", "version": "0.2.5", "description": "A rollupjs plugin for integrating with @microsoft/api-extractor", "keywords": [ "rollup", "plugin", "typescript", "api-extractor", "@types" ], "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ "dist" ], "repository": { "type": "git", "url": "git+https://github.com/blacktau/rollup-plugin-api-extractor.git" }, "bugs": { "url": "https://github.com/blacktau/rollup-plugin-api-extractor/issues" }, "author": "Sean Garrett", "license": "MIT", "devDependencies": { "@jest/types": "^27.4.2", "@rollup/plugin-typescript": "^8.3.0", "@rollup/pluginutils": "^4.1.2", "@types/fs-extra": "^9.0.13", "@types/jest": "^27.4.0", "@types/node": "^17.0.8", "@typescript-eslint/eslint-plugin": "^4.0.1", "@typescript-eslint/parser": "^4.11.0", "eslint": "^7.12.1", "eslint-config-standard-with-typescript": "^21.0.1", "eslint-plugin-import": "^2.22.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.0.0", "jest": "^27.4.0", "rollup": "^2.63.0", "ts-jest": "^27.1.0", "ts-mockery": "^1.2.0", "ts-node": "^10.4.0", "tslib": "^2.3.0", "typescript": "^4.5.0" }, "peerDependencies": { "@microsoft/api-extractor": ">=7.19.0", "rollup": ">=2.63.0", "tslib": "*" }, "dependencies": { "@microsoft/api-extractor": "^7.19.0" }, "packageManager": "yarn@3.1.1", "scripts": { "lint": "eslint", "build": "rollup -c", "test": "jest --coverage", "test:prod": "pnpm lint && jest --coverage", "test:watch": "jest --coverage --watchAll" }, "readme": "# rollup-plugin-api-extractor\n\n![Build Status](https://github.com/blacktau/rollup-plugin-api-extractor/workflows/CI%20Pipeline/badge.svg)\n[![codecov](https://codecov.io/gh/blacktau/rollup-plugin-api-extractor/branch/main/graph/badge.svg?token=O1NDBJ7V2K)](https://codecov.io/gh/blacktau/rollup-plugin-api-extractor)\n\nThis is a [rollup](https://www.rollupjs.org/) plugin to integrate [@microsoft/api-extractor](https://api-extractor.com/) into the rollup build system.\n\n## Usage\n\nInstall the package and @microsoft/api-extractor with npm (or yarn):\n\n`npm`\n\n```bash\nnpm install --save-dev rollup-plugin-api-extractor @microsoft/api-extractor\n```\n\n`yarn`\n\n```bash\nyarn add --dev rollup-plugin-api-extractor @microsoft/api-extractor\n```\n\nAdd to rollup config:\n\n```javascript\nimport typescript from \"@rollup/plugin-typescript\";\nimport { apiExtractor } from \"rollup-plugin-api-extractor\";\n\nexport default [\n {\n input: \"src/index.ts\",\n output: [(dir: \"dist\"), (format: \"esm\")],\n plugins: [typescript(), apiExtractor()],\n },\n];\n```\n\n### Configure for api-extractor\n\nThe below is based on the example at [https://api-extractor.com/pages/setup/invoking/](https://api-extractor.com/pages/setup/invoking/):\n\nAdd the `typings` or `types` field to `package.json`:\n\n```jsonc\n{\n // ...\n \"types\": \"lib/index.d.ts\"\n // ...\n}\n```\n\nMake sure `\"declaration\": true` and `\"declarationMap\": true` are in set in your `tsconfig.json`.\n\nGenerate the api-extractor configuration:\n\n`npx`\n\n```bash\nnpx api-extractor init\n```\n\nor\n\n`yarn`\n\n```bash\nyarn api-extractor init\n```\n\nUpdate the generated `api-extractor.json` so that `mainEntryPointFilePath` matches the `typings`/`types` field in `package.json`\n\n```json\n\"mainEntryPointFilePath\": \"<projectFolder>/lib/index.d.ts\",\n```\n\nIf `api-extractor.json` is not in the `config` folder update the `apiExtractor()` in your `rollup.config.js` to reference it:\n\n```javascript\nimport typescript from \"@rollup/plugin-typescript\";\nimport apiExtractor from \"rollup-plugin-api-extractor\";\n\nexport default [\n {\n input: \"src/index.ts\",\n output: [(dir: \"dist\"), (format: \"esm\")],\n plugins: [\n typescript(),\n apiExtractor({\n configFile: \"./api-extractor.json\",\n }),\n ],\n },\n];\n```\n\n## Plugin Configuration Options\n\nThe plugin Options are as follows:\n\n| Option | Default | Description |\n| ---------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| configFile | './config/api-extractor.json' | The path to the api extractor configuration file. |\n| configuration | | the configuration for `@microsoft/api-extractor`. If both `configFile` and this are specified, parameters specified here will override those in the configuration file. |\n| local | false | Indicates that API Extractor is running as part of a local build. Equates to `--local` in [api-extractor run](https://api-extractor.com/pages/commands/api-extractor_run/) command line. |\n| verbose | false | Show additional informational messages in the output. Equates to `--verbose` in [api-extractor run](https://api-extractor.com/pages/commands/api-extractor_run/) command line. |\n| diagnostics | false | Show diagnostic messages used for troubleshooting problems with API Extractor. Equates to `--diagnostics` in [api-extractor run](https://api-extractor.com/pages/commands/api-extractor_run/) command line. |\n| typescriptFolder | | Used to override the typescript compiler folder for `@microsoft/api-extractor`. Equates to `--typescript-compiler-folder` in [api-extractor run](https://api-extractor.com/pages/commands/) command line. |\n\n### `configuration` and `configFile` parameters\n\nAs mentioned above, the plugin can take the `@microsoft/api-extractor` configuration as part of the options for it. If no `configFile` is specified the below are the minimum configuration parameters currently require by `@microsoft/api-extractor`:\n\n```javascript\nimport typescript from \"@rollup/plugin-typescript\";\nimport apiExtractor from \"rollup-plugin-api-extractor\";\n\nexport default [\n {\n input: \"src/index.ts\",\n output: [(dir: \"dist\"), (format: \"esm\")],\n plugins: [\n typescript(),\n apiExtractor({\n configuration: {\n projectFolder: \".\",\n compiler: {\n tsconfigFilePath: \"<projectFolder>/tsconfig.json\",\n },\n },\n }),\n ],\n },\n];\n```\n\nIf `configFile` and `configuration` are both specified, the configuration file is read with the `configuration` acting as an overlay or override of the parameters that are in the file.\n\n## Why?\n\nWhile there are already [rollup](https://www.rollupjs.org/) plugins for rolling up the type definitions in a package, [@microsoft/api-extractor](https://api-extractor.com/) does more. In addition, `@microsoft/api-extractor` has the ability to \"trim\" the type definitions to excluded APIs not meant for external consumption.\n\n## Alternatives\n\n- [rollup-plugin-dts](https://github.com/Swatinem/rollup-plugin-dts)\n- [rollup-plugin-ts](https://github.com/wessberg/rollup-plugin-ts)\n\n## License\n\nThis code is licensed under the MIT License.\n" }