Skip to content

Commit

Permalink
chore(go): Remove path dependency from @fern-api/go-dynamic-snippets (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Nov 26, 2024
1 parent 56f4491 commit 825b028
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 22 deletions.
6 changes: 6 additions & 0 deletions generators/commons/src/utils/getBasename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Returns the basename of the given path (e.g. "foo/bar/baz" -> "baz").
*/
export function getBasename(path: string): string {
return path.split("/").pop() ?? "";
}
1 change: 1 addition & 0 deletions generators/commons/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { getBasename } from "./getBasename";
export { getPackageName } from "./getPackageName";
export { getSdkVersion } from "./getSdkVersion";
export { parseGeneratorConfig } from "./parseGeneratorConfig";
Expand Down
1 change: 1 addition & 0 deletions generators/go-v2/ast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"zod": "^3.22.3"
},
"devDependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/generator-commons": "workspace:*",
"@fern-fern/ir-sdk": "^53.21.0",
Expand Down
1 change: 0 additions & 1 deletion generators/go-v2/ast/src/ast/MethodInvocation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AstNode } from "./core/AstNode";
import { UnnamedArgument } from "@fern-api/generator-commons";
import { Writer } from "./core/Writer";
import { writeArguments } from "./utils/writeArguments";

Expand Down
2 changes: 0 additions & 2 deletions generators/go-v2/ast/src/ast/Struct.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";
import { CodeBlock } from "./CodeBlock";
import { Parameter } from "./Parameter";
import { Field } from "./Field";
import { Method } from "./Method";
import { Comment } from "./Comment";
Expand Down
6 changes: 2 additions & 4 deletions generators/go-v2/ast/src/ast/core/Writer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { AbstractWriter, NopFormatter } from "@fern-api/generator-commons";
import { AbstractFormatter, AbstractWriter, getBasename, NopFormatter } from "@fern-api/generator-commons";
import { BaseGoCustomConfigSchema } from "../../custom-config/BaseGoCustomConfigSchema";
import path from "path";
import { AbstractFormatter } from "@fern-api/generator-commons";

type Alias = string;
type ImportPath = string;
Expand Down Expand Up @@ -59,7 +57,7 @@ export class Writer extends AbstractWriter {
if (maybeAlias != null) {
return maybeAlias;
}
let alias = this.getValidAlias(path.basename(importPath));
let alias = this.getValidAlias(getBasename(importPath));
while (alias in this.imports) {
alias = "_" + alias;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { RelativeFilePath } from "@fern-api/fs-utils";
import { go } from "..";
import { TimeTypeReference, UuidTypeReference } from "../ast/Type";
import { resolveRootImportPath } from "../custom-config/resolveRootImportPath";

export interface FileLocation {
importPath: string;
directory: RelativeFilePath;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FernGeneratorExec } from "@fern-api/generator-commons";
import path from "path";
import { FernGeneratorExec, getBasename } from "@fern-api/generator-commons";
import { BaseGoCustomConfigSchema } from "./BaseGoCustomConfigSchema";

const DEFAULT_MODULE_PATH = "sdk";
Expand Down Expand Up @@ -65,7 +64,7 @@ function maybeAppendMajorVersionSuffix({
importPath: string;
majorVersion: string;
}): string {
if (path.basename(importPath) === majorVersion) {
if (getBasename(importPath) === majorVersion) {
return importPath;
}
return `${importPath}/${majorVersion}`;
Expand Down
1 change: 0 additions & 1 deletion generators/go-v2/dynamic-snippets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@fern-api/go-formatter": "workspace:*",
"@fern-fern/ir-sdk": "^53.21.0",
"@types/jest": "^29.5.12",
"@types/node": "^18.7.18",
"depcheck": "^1.4.6",
"eslint": "^8.56.0",
"organize-imports-cli": "^0.10.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import path from "path";
import { AbsoluteFilePath } from "@fern-api/fs-utils";

export const DYNAMIC_IR_TEST_DEFINITIONS_DIRECTORY = AbsoluteFilePath.of(
path.join(
__dirname,
"../../../../../../packages/cli/generation/ir-generator/src/dynamic-snippets/__test__/test-definitions"
)
`${__dirname}/../../../../../../packages/cli/generation/ir-generator/src/dynamic-snippets/__test__/test-definitions`
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { DiscriminatedUnionTypeInstance } from "../DiscriminatedUnionTypeInstanc
import { DynamicTypeMapper } from "./DynamicTypeMapper";
import { DynamicTypeInstantiationMapper } from "./DynamicTypeInstantiationMapper";
import { go } from "@fern-api/go-ast";
import path from "path";
import { ErrorReporter, Severity } from "./ErrorReporter";
import { FilePropertyMapper } from "./FilePropertyMapper";
import { AbstractDynamicSnippetsGeneratorContext } from "@fern-api/generator-commons";
Expand Down Expand Up @@ -329,11 +328,11 @@ export class DynamicSnippetsGeneratorContext extends AbstractDynamicSnippetsGene
}

public getClientImportPath(): string {
return path.join(this.rootImportPath, "client");
return `${this.rootImportPath}/client`;
}

public getOptionImportPath(): string {
return path.join(this.rootImportPath, "option");
return `${this.rootImportPath}/option`;
}

public resolveEndpointOrThrow(rawEndpoint: string): DynamicSnippets.Endpoint[] {
Expand Down
3 changes: 0 additions & 3 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 825b028

Please sign in to comment.