mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[type-summarizer] summarize types with source-maps for @kbn/ace
(#127680)
* [type-summarizer] ignore errors when deleting output dir * [type-summarizer] fix help text * [type-summarizer] add newlines after function declarations * [type-summarizer] summarize types with source-maps for `@kbn/ace`
This commit is contained in:
parent
bbb531af3a
commit
0f35206a4e
7 changed files with 61 additions and 4 deletions
|
@ -67,6 +67,7 @@ ts_project(
|
|||
srcs = SRCS,
|
||||
deps = TYPES_DEPS,
|
||||
declaration = True,
|
||||
declaration_map = True,
|
||||
emit_declaration_only = True,
|
||||
out_dir = "target_types",
|
||||
root_dir = "src",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"extends": "../../tsconfig.bazel.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "./target_types",
|
||||
"stripInternal": true,
|
||||
|
|
|
@ -19,7 +19,7 @@ const HELP = `
|
|||
Script called from bazel to create the summarized version of a package. When called by Bazel
|
||||
config is passed as a JSON encoded object.
|
||||
|
||||
When called via "node scripts/build_type_summarizer_output" pass a path to a package and that
|
||||
When called via "node scripts/type_summarizer" pass a path to a package and that
|
||||
package's types will be read from node_modules and written to data/type-summarizer-output.
|
||||
|
||||
`;
|
||||
|
@ -30,7 +30,14 @@ run(
|
|||
log.debug('argv', process.argv);
|
||||
|
||||
for (const config of parseBazelCliConfigs(argv)) {
|
||||
await Fsp.rm(config.outputDir, { recursive: true });
|
||||
try {
|
||||
await Fsp.rm(config.outputDir, { recursive: true });
|
||||
} catch (error) {
|
||||
if (error && error.code !== 'ENOENT') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
await Fsp.mkdir(config.outputDir, { recursive: true });
|
||||
|
||||
// generate pkg json output
|
||||
|
|
|
@ -17,6 +17,7 @@ const TYPE_SUMMARIZER_PACKAGES = [
|
|||
'@kbn/crypto',
|
||||
'@kbn/generate',
|
||||
'@kbn/mapbox-gl',
|
||||
'@kbn/ace',
|
||||
];
|
||||
|
||||
type TypeSummarizerType = 'api-extractor' | 'type-summarizer';
|
||||
|
|
|
@ -42,7 +42,12 @@ export class ExportInfo {
|
|||
}
|
||||
}
|
||||
|
||||
return new ExportInfo(node.getText(), type, symbol);
|
||||
let name;
|
||||
if ((ts.isFunctionDeclaration(node) || ts.isExportSpecifier(node)) && node.name) {
|
||||
name = node.name.getText();
|
||||
}
|
||||
|
||||
return new ExportInfo(name ?? node.getText(), type, symbol);
|
||||
}
|
||||
|
||||
constructor(
|
||||
|
|
|
@ -305,10 +305,11 @@ export class Printer {
|
|||
return [
|
||||
this.getLeadingComments(node),
|
||||
this.printModifiers(exportInfo, node),
|
||||
this.getMappedSourceNode(node.name),
|
||||
this.getMappedSourceNode(node.name, exportInfo?.name),
|
||||
this.printTypeParameters(node),
|
||||
`(${node.parameters.map((p) => p.getFullText()).join(', ')})`,
|
||||
node.type ? [': ', this.printNode(node.type), ';'] : ';',
|
||||
'\n',
|
||||
].flat();
|
||||
}
|
||||
|
||||
|
|
|
@ -81,3 +81,44 @@ it('prints the function declaration, including comments', async () => {
|
|||
"
|
||||
`);
|
||||
});
|
||||
|
||||
it('uses the export name when it is different', async () => {
|
||||
const output = await run(
|
||||
`
|
||||
export { foo as bar } from './foo';
|
||||
`,
|
||||
{
|
||||
otherFiles: {
|
||||
['foo.ts']: `
|
||||
export function foo() {
|
||||
return 'foo'
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(output.code).toMatchInlineSnapshot(`
|
||||
"export function bar(): string;
|
||||
//# sourceMappingURL=index.d.ts.map"
|
||||
`);
|
||||
expect(output.map).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"file": "index.d.ts",
|
||||
"mappings": "gBAAgB,G",
|
||||
"names": Array [],
|
||||
"sourceRoot": "../../../src",
|
||||
"sources": Array [
|
||||
"foo.ts",
|
||||
],
|
||||
"version": 3,
|
||||
}
|
||||
`);
|
||||
expect(output.logs).toMatchInlineSnapshot(`
|
||||
"debug loaded sourcemaps for [
|
||||
'packages/kbn-type-summarizer/__tmp__/dist_dts/foo.d.ts',
|
||||
'packages/kbn-type-summarizer/__tmp__/dist_dts/index.d.ts'
|
||||
]
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue