Skip to content

Commit

Permalink
add "files" field so that npm pack works (#9084)
Browse files Browse the repository at this point in the history
* add "files" field so that npm pack works

* also pack a bin executable

* - correct process.argv.length

- minor updates
  • Loading branch information
jeremymeng authored Oct 2, 2024
1 parent 955e080 commit db83079
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
8 changes: 8 additions & 0 deletions tools/apiview/parsers/js-api-parser/bin/ts-genapi.cjs
Original file line number Diff line number Diff line change
@@ -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"));
6 changes: 5 additions & 1 deletion tools/apiview/parsers/js-api-parser/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
6 changes: 6 additions & 0 deletions tools/apiview/parsers/js-api-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions tools/apiview/parsers/js-api-parser/readme.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 <Path to api-extractor JSON output> <Path to apiviewFile>
Run `node ./dist/export.js <Path to api-extractor JSON output> <Path to apiviewFile>`

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`
`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 <Path to api-extractor JSON output> <Path to apiviewFile>`.
5 changes: 5 additions & 0 deletions tools/apiview/parsers/js-api-parser/src/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Path to api-extractor JSON output> <Path to apiviewFile>");
process.exit(1);
}
const { Name, PackageName, PackageVersion, dependencies, apiModel } = await loadApiJson(
process.argv[2],
);
Expand Down
5 changes: 5 additions & 0 deletions tools/apiview/parsers/js-api-parser/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ function buildDependencies(reviewLines: ReviewLine[], dependencies: Record<strin
reviewLines.push(emptyLine(header.LineId));
}

/**
* Gets the name of the subpath export given an entrypoint
* @param entryPoint
* @returns
*/
function getSubPathName(entryPoint: ApiEntryPoint): string {
return entryPoint.name.length > 0 ? `./${entryPoint.name}` : ".";
}
Expand Down

0 comments on commit db83079

Please sign in to comment.