Skip to content

Commit

Permalink
chore(cli): @fern-api/ir-generator uses @fern-api/path-utils (#5299)
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Dec 1, 2024
1 parent edc2457 commit d6a7822
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 29 deletions.
3 changes: 1 addition & 2 deletions packages/cli/generation/ir-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@fern-api/configuration": "workspace:*",
"@fern-api/core-utils": "workspace:*",
"@fern-api/fern-definition-schema": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/path-utils": "workspace:*",
"@fern-api/ir-sdk": "workspace:*",
"@fern-api/source-resolver": "workspace:*",
"@fern-api/task-context": "workspace:*",
Expand All @@ -43,7 +43,6 @@
},
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/node": "18.7.18",
"@types/object-hash": "^3.0.6",
"@types/prettier": "^2.7.1",
"@types/url-join": "4.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelativeFilePath } from "@fern-api/fs-utils";
import { RelativeFilePath } from "@fern-api/path-utils";
import { FernFilepath, TypeReference } from "@fern-api/ir-sdk";
import { DefinitionFileSchema, RawSchemas, RootApiFileSchema } from "@fern-api/fern-definition-schema";
import { mapValues } from "lodash-es";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Audiences, FERN_PACKAGE_MARKER_FILENAME, generatorsYml } from "@fern-api/configuration";
import { noop, visitObject } from "@fern-api/core-utils";
import { dirname, join, RelativeFilePath } from "@fern-api/fs-utils";
import { dirname, join, RelativeFilePath } from "@fern-api/path-utils";
import {
ExampleType,
HttpEndpoint,
Expand Down Expand Up @@ -45,7 +45,7 @@ import { ExampleResolverImpl } from "./resolvers/ExampleResolver";
import { PropertyResolverImpl } from "./resolvers/PropertyResolver";
import { TypeResolverImpl } from "./resolvers/TypeResolver";
import { VariableResolverImpl } from "./resolvers/VariableResolver";
import { SourceResolver, NopSourceResolver } from "@fern-api/source-resolver";
import { SourceResolver } from "@fern-api/source-resolver";
import { convertToFernFilepath } from "./utils/convertToFernFilepath";
import { getAudienceForEnvironment } from "./utils/getEnvironmentsByAudience";
import { isGeneric } from "@fern-api/fern-definition-schema";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelativeFilePath } from "@fern-api/fs-utils";
import { RelativeFilePath } from "@fern-api/path-utils";
import { DeclaredTypeName, Literal as IrLiteral, PrimitiveType, TypeReference } from "@fern-api/ir-sdk";
import { RawSchemas } from "@fern-api/fern-definition-schema";
import { FernFileContext } from "../FernFileContext";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FERN_PACKAGE_MARKER_FILENAME } from "@fern-api/configuration";
import { dirname, RelativeFilePath } from "@fern-api/fs-utils";
import { FERN_PACKAGE_MARKER_FILENAME_NO_EXTENSION } from "@fern-api/configuration";
import { basename, dirname, RelativeFilePath, sep } from "@fern-api/path-utils";
import { FernFilepath } from "@fern-api/ir-sdk";
import path, { basename } from "path";
import { CasingsGenerator } from "../casings/CasingsGenerator";

export function convertToFernFilepath({
Expand All @@ -12,15 +11,13 @@ export function convertToFernFilepath({
casingsGenerator: CasingsGenerator;
}): FernFilepath {
const pathToPackage = dirname(relativeFilepath);
const filename = basename(relativeFilepath);
const filename = basename(relativeFilepath, { stripExtension: true });

const packagePath =
pathToPackage === "." ? [] : pathToPackage.split(path.sep).map((part) => casingsGenerator.generateName(part));
pathToPackage === "." ? [] : pathToPackage.split(sep).map((part) => casingsGenerator.generateName(part));

const file =
filename !== FERN_PACKAGE_MARKER_FILENAME
? casingsGenerator.generateName(path.parse(filename).name)
: undefined;
filename !== FERN_PACKAGE_MARKER_FILENAME_NO_EXTENSION ? casingsGenerator.generateName(filename) : undefined;

const allParts = [];
allParts.push(...packagePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelativeFilePath } from "@fern-api/fs-utils";
import { RelativeFilePath } from "@fern-api/path-utils";
import { FernWorkspace, getDefinitionFile } from "@fern-api/api-workspace-commons";
import { isRawObjectDefinition, RawSchemas } from "@fern-api/fern-definition-schema";
import { constructCasingsGenerator } from "../casings/CasingsGenerator";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, join, RelativeFilePath } from "@fern-api/fs-utils";
import { dirname, join, RelativeFilePath } from "@fern-api/path-utils";

export function getResolvedPathOfImportedFile({
referencedIn,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelativeFilePath } from "@fern-api/fs-utils";
import { RelativeFilePath } from "@fern-api/path-utils";
import { getResolvedPathOfImportedFile } from "./getResolvedPathOfImportedFile";

export interface ReferenceToEndpointName {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RelativeFilePath } from "@fern-api/fs-utils";
import { RelativeFilePath } from "@fern-api/path-utils";
import { getResolvedPathOfImportedFile } from "./getResolvedPathOfImportedFile";

export interface ReferenceToTypeName {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/generation/ir-generator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"path": "../../../commons/core-utils"
},
{
"path": "../../../commons/fs-utils"
"path": "../../../commons/path-utils"
},
{
"path": "../../../ir-sdk"
Expand Down
8 changes: 6 additions & 2 deletions packages/commons/path-utils/src/basename.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function basename(path: string): string {
return path.split("/").pop() ?? "";
export function basename(path: string, options?: { stripExtension?: boolean }): string {
const basename = path.split("/").pop() ?? path;
if (options?.stripExtension) {
return basename.split(".")[0] ?? basename;
}
return basename;
}
7 changes: 5 additions & 2 deletions packages/commons/path-utils/src/getPathModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { isBrowser } from "./isBrowser";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function getPathModule() {
export interface PathModule {
isAbsolute: (value: string) => boolean;
}

export function getPathModule(): PathModule {
if (isBrowser()) {
return {
isAbsolute: (value: string): boolean => {
Expand Down
1 change: 1 addition & 0 deletions packages/commons/path-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { basename } from "./basename";
export { convertToOsPath } from "./convertToOsPath";
export { dirname } from "./dirname";
export { join } from "./join";
export { sep } from "./sep";
1 change: 1 addition & 0 deletions packages/commons/path-utils/src/sep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const sep = "/";
9 changes: 3 additions & 6 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 d6a7822

Please sign in to comment.