From db83079eb4e623cb7cd1aa94bf60fbad1c8637c6 Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Wed, 2 Oct 2024 12:24:15 -0700 Subject: [PATCH] add "files" field so that npm pack works (#9084) * add "files" field so that npm pack works * also pack a bin executable * - correct process.argv.length - minor updates --- tools/apiview/parsers/js-api-parser/bin/ts-genapi.cjs | 8 ++++++++ tools/apiview/parsers/js-api-parser/eslint.config.mjs | 6 +++++- tools/apiview/parsers/js-api-parser/package.json | 6 ++++++ tools/apiview/parsers/js-api-parser/readme.md | 10 ++++++---- tools/apiview/parsers/js-api-parser/src/export.ts | 5 +++++ tools/apiview/parsers/js-api-parser/src/generate.ts | 5 +++++ 6 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tools/apiview/parsers/js-api-parser/bin/ts-genapi.cjs diff --git a/tools/apiview/parsers/js-api-parser/bin/ts-genapi.cjs b/tools/apiview/parsers/js-api-parser/bin/ts-genapi.cjs new file mode 100644 index 00000000000..0f59c8736cb --- /dev/null +++ b/tools/apiview/parsers/js-api-parser/bin/ts-genapi.cjs @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +const path = require("path"); + +require(path.join(__dirname, "../", "dist", "export.js")); diff --git a/tools/apiview/parsers/js-api-parser/eslint.config.mjs b/tools/apiview/parsers/js-api-parser/eslint.config.mjs index 2d5a00f9015..dbbcc1726a1 100644 --- a/tools/apiview/parsers/js-api-parser/eslint.config.mjs +++ b/tools/apiview/parsers/js-api-parser/eslint.config.mjs @@ -3,4 +3,8 @@ import eslint from "@eslint/js"; import tsEslint from "typescript-eslint"; -export default tsEslint.config(eslint.configs.recommended, ...tsEslint.configs.recommended); +export default tsEslint.config( + { ignores: ["bin", "dist"] }, + eslint.configs.recommended, + ...tsEslint.configs.recommended, +); diff --git a/tools/apiview/parsers/js-api-parser/package.json b/tools/apiview/parsers/js-api-parser/package.json index e4b2c037639..71357aa8d5d 100644 --- a/tools/apiview/parsers/js-api-parser/package.json +++ b/tools/apiview/parsers/js-api-parser/package.json @@ -10,6 +10,12 @@ "@microsoft/api-extractor-model": "^7.29.8", "js-tokens": "^9.0.0" }, + "files": [ + "dist", + "bin", + "readme.md" + ], + "bin": "bin/ts-genapi.cjs", "devDependencies": { "@eslint/js": "^9.10.0", "@types/eslint__js": "^8.42.3", diff --git a/tools/apiview/parsers/js-api-parser/readme.md b/tools/apiview/parsers/js-api-parser/readme.md index ddf2530e96b..6fe56b9018f 100644 --- a/tools/apiview/parsers/js-api-parser/readme.md +++ b/tools/apiview/parsers/js-api-parser/readme.md @@ -1,6 +1,6 @@ ## Overview -This application tokenises a Javascript project into a format useful for JavaScript API reviews. JavaScript API review parser is used by APIView system and CI pipelines to convert a JSON output file created by `api-extracor` to JSON token file intepreted by APIView to create and present review in APIView system. +This application tokenises a Javascript project into a format useful for JavaScript API reviews. JavaScript API review parser is used by APIView system and CI pipelines to convert a JSON output file created by `api-extractor` to JSON token file interpreted by APIView to create and present review in APIView system. ## Building @@ -10,10 +10,12 @@ This application tokenises a Javascript project into a format useful for JavaScr ## How To Use -Run API extractor step on JS project to create json output file. This step is integrated within build commend for all Azure SDK projects in azure-sdk-for-js monorepo. So running build step is good enough to create input file for APIvIew parser. You can see a JSON file created in temp directory within package root directory once build step is completed succesfully for the package. +Run API extractor step on JS project to create json output file. This step is integrated within build commend for all Azure SDK projects in azure-sdk-for-js monorepo. So running build step is good enough to create input file for APIvIew parser. You can see a JSON file created in temp directory within package root directory once build step is completed successfully for the package. -Run `node ./export.js +Run `node ./dist/export.js ` For e.g. -`node .\export.js C:\git\azure-sdk-for-js\sdk\core\core-client\temp\core-client.api.json C:\git\azure-sdk-for-js\sdk\core\core-client\temp\apiview.json` \ No newline at end of file +`node .\export.js C:\git\azure-sdk-for-js\sdk\core\core-client\temp\core-client.api.json C:\git\azure-sdk-for-js\sdk\core\core-client\temp\apiview.json` + +Or if you have the package installed, you can run `ts-genapi `. \ No newline at end of file diff --git a/tools/apiview/parsers/js-api-parser/src/export.ts b/tools/apiview/parsers/js-api-parser/src/export.ts index 04526eca571..9d0f7143981 100644 --- a/tools/apiview/parsers/js-api-parser/src/export.ts +++ b/tools/apiview/parsers/js-api-parser/src/export.ts @@ -26,6 +26,11 @@ async function loadApiJson(fileName: string) { } async function main() { + if (process.argv.length < 4) { + console.log("Please run this tool with proper input"); + console.log("ts-genapi "); + process.exit(1); + } const { Name, PackageName, PackageVersion, dependencies, apiModel } = await loadApiJson( process.argv[2], ); diff --git a/tools/apiview/parsers/js-api-parser/src/generate.ts b/tools/apiview/parsers/js-api-parser/src/generate.ts index 714e4c5c319..9c4d16203e7 100644 --- a/tools/apiview/parsers/js-api-parser/src/generate.ts +++ b/tools/apiview/parsers/js-api-parser/src/generate.ts @@ -82,6 +82,11 @@ function buildDependencies(reviewLines: ReviewLine[], dependencies: Record 0 ? `./${entryPoint.name}` : "."; }