Skip to content

Commit

Permalink
describe-package: document anything with an @function tag
Browse files Browse the repository at this point in the history
Not sure I like this but it's consistent with the main docsite
  • Loading branch information
josephjclark committed Jun 25, 2024
1 parent 5e54e44 commit cb8cc17
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/describe-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"build:worker": "tsm esbuild-worker.ts",
"build:node": "tsup --config tsup.config.js src/index.ts",
"build": "pnpm clean && pnpm build:node && pnpm build:worker",
"pack": "pnpm pack --pack-destination ../../dist"
"pack": "pnpm pack --pack-destination ../../dist",
"cli": "npx tsx src/cli.ts"
},
"keywords": [],
"devDependencies": {
Expand All @@ -44,7 +45,6 @@
"esbuild": "^0.18.14",
"rimraf": "^3.0.2",
"threads": "1.7.0",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"tsm": "^2.2.1",
"tsup": "^7.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/describe-package/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type ParameterDescription = {
*/
export const describePackage = async (
specifier: string,
_options: Options
_options: Options = {}
): Promise<PackageDescription> => {
const { name, version } = getNameAndVersion(specifier);
const project = new Project();
Expand Down
12 changes: 12 additions & 0 deletions packages/describe-package/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describePackage } from './api';

const a = process.argv[2];

async function run(specifier: string) {
const result = await describePackage(specifier, {});

console.log(result);
}

console.log('GENERATING FOR', a);
run(a);
2 changes: 1 addition & 1 deletion packages/describe-package/src/describe-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const describeProject = (
return true;
}
// Return all export aliases and public symbols
return symbol.isExportAlias || symbol.isPublic;
return symbol.isExportAlias || symbol.hasFunctionTag;
})
.reduce((symbols, symbol) => {
if (symbol.isFunctionDeclaration) {
Expand Down
9 changes: 5 additions & 4 deletions packages/describe-package/src/typescript/wrapped-symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ export class WrappedSymbol {
return this.symbol.valueDeclaration?.type;
}

// A function is private unless it has a public tag
public get isPublic(): boolean {
return this.jsDocTags.some(
(tag: ts.JSDocTag) => tag.tagName.escapedText === 'public'
public get hasFunctionTag(): boolean {
return Boolean(
this.jsDocTags.find(
(tag: ts.JSDocTag) => tag.tagName.escapedText === 'function'
)
);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/describe-package/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"exclude": ["node_modules", "**/*.spec.ts", "dist"],
"compilerOptions": {
"typeRoots": ["./node_modules/@types"],
"target": "ESNext"
"target": "ESNext",
"esModuleInterop": true,
}
}
63 changes: 56 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb8cc17

Please sign in to comment.