-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
@docsId
and @docsIncludeIds
JSDoc tags to capture…
… documentation relationships in the manifest (#3063)
- Loading branch information
1 parent
847c970
commit ba33999
Showing
23 changed files
with
478 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
libs/components/manifest/src/__snapshots__/get-public-api.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`get-public-api should return the public API for a specific docs ID 1`] = ` | ||
Object { | ||
"packages": Object { | ||
"@company/components": Array [ | ||
Object { | ||
"docsId": "bar", | ||
"docsIncludeIds": Array [ | ||
"foo", | ||
"FooTesting", | ||
"FooTestingInternal", | ||
], | ||
"isInternal": false, | ||
}, | ||
Object { | ||
"docsId": "foo", | ||
"isInternal": false, | ||
}, | ||
], | ||
"@company/components/testing": Array [ | ||
Object { | ||
"docsId": "FooTesting", | ||
"isInternal": false, | ||
}, | ||
], | ||
}, | ||
} | ||
`; |
147 changes: 115 additions & 32 deletions
147
libs/components/manifest/src/generator/__snapshots__/generate-manifest.test.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
libs/components/manifest/src/generator/assign-docs-include-ids.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import fsPromises from 'node:fs/promises'; | ||
import * as ts from 'typescript'; | ||
|
||
import { type PackagesMap } from './get-public-api'; | ||
|
||
/** | ||
* Assign `docsIncludeIds` for each entry-point module, based on the types | ||
* included in its `exports` array. | ||
*/ | ||
export async function assignDocsIncludeIds( | ||
packages: PackagesMap, | ||
): Promise<void> { | ||
for (const [, definitions] of packages) { | ||
for (const definition of definitions) { | ||
if ( | ||
definition.kind !== 'module' || | ||
definition.docsIncludeIds || | ||
definition.isInternal | ||
) { | ||
continue; | ||
} | ||
|
||
const contents = await fsPromises.readFile(definition.filePath, 'utf-8'); | ||
|
||
const sourceFile = ts.createSourceFile( | ||
definition.filePath, | ||
contents, | ||
ts.ScriptTarget.Latest, | ||
); | ||
|
||
let moduleExports: string[] = []; | ||
|
||
// Get the exports from the module. | ||
ts.forEachChild(sourceFile, (node) => { | ||
if ( | ||
ts.isClassDeclaration(node) && | ||
node.name?.escapedText === definition.name | ||
) { | ||
ts.getDecorators(node)?.[0].expression.forEachChild((child) => { | ||
if (ts.isObjectLiteralExpression(child)) { | ||
child.properties.forEach((property) => { | ||
if ( | ||
ts.isPropertyAssignment(property) && | ||
ts.isIdentifier(property.name) && | ||
property.name.escapedText === 'exports' && | ||
ts.isArrayLiteralExpression(property.initializer) | ||
) { | ||
property.initializer.elements.forEach((element) => { | ||
if (ts.isIdentifier(element)) { | ||
const exportName = element.escapedText.toString(); | ||
|
||
if ( | ||
exportName.startsWith('Sky') && | ||
definitions.some( | ||
(definition) => definition.name === exportName, | ||
) | ||
) { | ||
moduleExports.push(element.escapedText.toString()); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
moduleExports = moduleExports.map((exportName) => { | ||
// Map the export name to its corresponding docsId. | ||
const definition = definitions.find( | ||
(definition) => definition.name === exportName, | ||
); | ||
|
||
/* istanbul ignore next: safety check */ | ||
if (!definition?.docsId) { | ||
throw new Error(`Missing @docsId for ${exportName}.`); | ||
} | ||
|
||
return definition.docsId; | ||
}); | ||
|
||
definition.docsIncludeIds = moduleExports; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.