Skip to content

Commit

Permalink
(improvement): appending type for type exports
Browse files Browse the repository at this point in the history
  • Loading branch information
bsinghvi committed Apr 23, 2024
1 parent fcc705d commit a2d401e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.15.0-rc1
0.15.0-rc1
9 changes: 6 additions & 3 deletions generators/typescript/sdk/generator/src/SdkGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ export class SdkGenerator {
run: ({ sourceFile, importsManager }) => {
const context = this.generateSdkContext({ sourceFile, importsManager });
context.type.getGeneratedType(typeDeclaration.name).writeToFile(context);
}
},
addExportTypeModifier: true
});
}
}
Expand Down Expand Up @@ -810,10 +811,12 @@ export class SdkGenerator {

private withSourceFile({
run,
filepath
filepath,
addExportTypeModifier
}: {
run: (args: { sourceFile: SourceFile; importsManager: ImportsManager }) => void;
filepath: ExportedFilePath;
addExportTypeModifier?: boolean;
}) {
const filepathStr = convertExportedFilePathToFilePath(filepath);
this.context.logger.debug(`Generating ${filepathStr}`);
Expand All @@ -828,7 +831,7 @@ export class SdkGenerator {
this.context.logger.debug(`Skipping ${filepathStr} (no content)`);
} else {
importsManager.writeImportsToSourceFile(sourceFile);
this.exportsManager.addExportsForFilepath(filepath);
this.exportsManager.addExportsForFilepath(filepath, addExportTypeModifier);

// this needs to be last.
// https://github.com/dsherret/ts-morph/issues/189#issuecomment-414174283
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class ExportsManager {
});
}

public addExportsForFilepath(filepath: ExportedFilePath): void {
this.addExportsForDirectories(filepath.directories);
public addExportsForFilepath(filepath: ExportedFilePath, addExportTypeModifier?: boolean): void {
this.addExportsForDirectories(filepath.directories, addExportTypeModifier);
this.addExport(convertExportedFilePathToFilePath(filepath), filepath.file?.exportDeclaration);
}

public addExportsForDirectories(directories: ExportedDirectory[]): void {
public addExportsForDirectories(directories: ExportedDirectory[], addExportTypeModifier?: boolean): void {
let directoryFilepath = "/src";
for (const part of directories) {
const nextDirectoryPath = path.join(directoryFilepath, part.nameOnDisk);
Expand All @@ -56,7 +56,8 @@ export class ExportsManager {
from: directoryFilepath,
to: nextDirectoryPath
}),
exportDeclaration: part.exportDeclaration
exportDeclaration: part.exportDeclaration,
addExportTypeModifier
});

if (part.subExports != null) {
Expand All @@ -67,7 +68,8 @@ export class ExportsManager {
from: directoryFilepath,
to: path.join(nextDirectoryPath, relativeFilePath)
}),
exportDeclaration
exportDeclaration,
addExportTypeModifier
});
}
}
Expand All @@ -78,11 +80,13 @@ export class ExportsManager {
private addExportDeclarationForDirectory({
directory,
moduleSpecifierToExport,
exportDeclaration
exportDeclaration,
addExportTypeModifier
}: {
directory: Directory | PathToDirectory;
moduleSpecifierToExport: ModuleSpecifier;
exportDeclaration: ExportDeclaration | undefined;
addExportTypeModifier?: boolean;
}): void {
const pathToDirectory = typeof directory === "string" ? directory : directory.getPath();
const exportsForDirectory = (this.exports[pathToDirectory] ??= {});
Expand Down Expand Up @@ -110,7 +114,11 @@ export class ExportsManager {

if (exportDeclaration.namedExports != null) {
for (const namedExport of exportDeclaration.namedExports) {
exportsForModuleSpecifier.namedExports.add(namedExport);
if (addExportTypeModifier) {
exportsForModuleSpecifier.namedExports.add("type " + namedExport);
} else {
exportsForModuleSpecifier.namedExports.add(namedExport);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ groups:
location: local-file-system
path: ../generated/sdks/typescript
- name: fernapi/fern-java-sdk
version: 0.5.7
version: 0.8.7
- name: fernapi/fern-postman
version: 0.0.45
output:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`fern generate missing docs page 1`] = `
"[docs]: Found 1 errors and 0 warnings. Run fern check --warnings to print out the warnings.
[docs]: docs.yml -> navigation -> 0 -> page
Path missing.md does not exist"
`;
exports[`fern generate missing docs page 1`] = `"Login required."`;
24 changes: 12 additions & 12 deletions packages/cli/ete-tests/src/tests/ir/__snapshots__/ir.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31261,15 +31261,15 @@ exports[`ir {"name":"streaming"} 1`] = `
"sdkRequest": null,
"response": {
"type": "streaming",
"value": {
"dataEventType": {
"type": "json",
"payload": {
"json": {
"_type": "primitive",
"primitive": "STRING"
},
"terminator": null,
"docs": null
}
}
},
"terminator": null,
"docs": null
},
"errors": [],
"examples": [
Expand Down Expand Up @@ -31465,15 +31465,15 @@ exports[`ir {"name":"streaming"} 1`] = `
},
"response": {
"type": "streaming",
"value": {
"dataEventType": {
"type": "json",
"payload": {
"json": {
"_type": "primitive",
"primitive": "STRING"
},
"terminator": "[DONE]",
"docs": null
}
}
},
"terminator": "[DONE]",
"docs": null
},
"errors": [],
"examples": [
Expand Down

0 comments on commit a2d401e

Please sign in to comment.