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 24, 2024
1 parent c117cf5 commit 6c9bb6d
Show file tree
Hide file tree
Showing 88 changed files with 163 additions and 146 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
12 changes: 8 additions & 4 deletions generators/typescript/sdk/generator/src/SdkGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ export class SdkGenerator {
context.requestWrapper
.getGeneratedRequestWrapper(packageId, endpoint.name)
.writeToFile(context);
}
},
addExportTypeModifier: true
});
}
}
Expand All @@ -523,7 +524,8 @@ export class SdkGenerator {
context.sdkInlinedRequestBodySchema
.getGeneratedInlinedRequestBodySchema(packageId, endpoint.name)
.writeToFile(context);
}
},
addExportTypeModifier: true
});
}
}
Expand Down Expand Up @@ -810,10 +812,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 +832,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 @@ -23,7 +23,11 @@ type PathToDirectory = string;
export class ExportsManager {
private exports: Record<PathToDirectory, Record<ModuleSpecifier, CombinedExportDeclarations>> = {};

public addExport(from: SourceFile | string, exportDeclaration: ExportDeclaration | undefined): void {
public addExport(
from: SourceFile | string,
exportDeclaration: ExportDeclaration | undefined,
addExportTypeModifier?: boolean
): void {
const fromPath = typeof from === "string" ? from : from.getFilePath();
if (path.extname(fromPath).length === 0) {
throw new Error("Cannot export from directory: " + fromPath);
Expand All @@ -37,16 +41,21 @@ export class ExportsManager {
from: pathToDirectory,
to: fromPath
}),
exportDeclaration
exportDeclaration,
addExportTypeModifier
});
}

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

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 +65,8 @@ export class ExportsManager {
from: directoryFilepath,
to: nextDirectoryPath
}),
exportDeclaration: part.exportDeclaration
exportDeclaration: part.exportDeclaration,
addExportTypeModifier
});

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading

0 comments on commit 6c9bb6d

Please sign in to comment.