Skip to content

Commit

Permalink
feat(cli): Add @fern-api/browser-compatible-fern-workspace (fern-api#…
Browse files Browse the repository at this point in the history
…5317)

* chore(cli): Add @fern-api/browser-compatible-fern-workspace

* Add workspace directory

* Update all tsconfig.json references

* Refactor with BaseOpenAPIWorkspace

* Update and move getOSSWorkspaceSettingsFromGeneratorInvocation

* Remove duplicative SpecImportSettings

* Update absoluteFilePath

* Consolidate Source and Spec types

* Fix depcheck

* Remove absoluteFilePath from snapshots

* Add configurable absoluteFilePath for tests
  • Loading branch information
amckinney authored Dec 3, 2024
1 parent 76d320b commit 6fd463a
Show file tree
Hide file tree
Showing 141 changed files with 1,124 additions and 837 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"seed:build": "pnpm --filter @fern-api/seed-cli dist:cli && echo 'Run packages/seed/dist/cli.cjs'",
"publish": "pnpm -r publish --access public --no-git-checks --loglevel=verbose",
"jsonschema": "pnpm definition-yml:jsonschema && pnpm api-yml:jsonschema && pnpm package-yml:jsonschema && pnpm docs-yml:jsonschema && pnpm generators-yml:jsonschema",
"definition-yml:jsonschema": "fern jsonschema fern.schema.json --api fern-definition --type file.DefinitionFileSchema && fern jsonschema packages/cli/lazy-fern-workspace/src/fern.schema.json --api fern-definition --type file.DefinitionFileSchema",
"api-yml:jsonschema": "fern jsonschema api-yml.schema.json --api fern-definition --type file.RootApiFileSchema && fern jsonschema packages/cli/lazy-fern-workspace/src/api-yml.schema.json --api fern-definition --type file.RootApiFileSchema",
"package-yml:jsonschema": "fern jsonschema package-yml.schema.json --api fern-definition --type file.PackageMarkerFileSchema && fern jsonschema packages/cli/lazy-fern-workspace/src/package-yml.schema.json --api fern-definition --type file.PackageMarkerFileSchema",
"definition-yml:jsonschema": "fern jsonschema fern.schema.json --api fern-definition --type file.DefinitionFileSchema && fern jsonschema packages/cli/workspace/lazy-fern-workspace/src/fern.schema.json --api fern-definition --type file.DefinitionFileSchema",
"api-yml:jsonschema": "fern jsonschema api-yml.schema.json --api fern-definition --type file.RootApiFileSchema && fern jsonschema packages/cli/workspace/lazy-fern-workspace/src/api-yml.schema.json --api fern-definition --type file.RootApiFileSchema",
"package-yml:jsonschema": "fern jsonschema package-yml.schema.json --api fern-definition --type file.PackageMarkerFileSchema && fern jsonschema packages/cli/workspace/lazy-fern-workspace/src/package-yml.schema.json --api fern-definition --type file.PackageMarkerFileSchema",
"docs-yml:jsonschema": "fern jsonschema docs-yml.schema.json --api docs-yml --type docs.DocsConfiguration",
"generators-yml:jsonschema": "fern jsonschema generators-yml.schema.json --api generators-yml --type generators.GeneratorsConfigurationSchema",
"check-cli-release-blockers": "pnpm fern-script check-cli-release-blockers",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"references": [
{ "path": "../../../../commons/fs-utils" },
{ "path": "../../../task-context" },
{ "path": "../../../workspace-loader" },
{ "path": "../../../workspace/loader" },
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { type ParseOpenAPIOptions } from "./options";
export { parse, type Document } from "./parse";
export { InMemoryOpenAPILoader } from "./openapi/InMemoryOpenAPILoader";
export { parse, type Document, type OpenAPIDocument, type SpecImportSettings } from "./parse";
export { FernOpenAPIExtension, XFernStreaming, FERN_TYPE_EXTENSIONS } from "./openapi/v3/extensions/fernExtensions";
export * from "./asyncapi/v2";
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-api/browser-compatible-fern-workspace": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-api/task-context": "workspace:*",
"@fern-api/lazy-fern-workspace": "workspace:*",
"@fern-api/openapi-ir-parser": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"js-yaml": "^4.1.0",
"openapi-types": "^12.1.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { createMockTaskContext } from "@fern-api/task-context";
import { loadAPIWorkspace } from "@fern-api/workspace-loader";
import { readdir } from "fs/promises";
import { OSSWorkspace } from "@fern-api/lazy-fern-workspace";
import { InMemoryOpenAPILoader } from "@fern-api/openapi-ir-parser";
import { InMemoryOpenAPILoader } from "@fern-api/browser-compatible-fern-workspace";
import fs from "fs/promises";
import { OpenAPI } from "openapi-types";
import yaml from "js-yaml";

const FIXTURES_DIR = join(AbsoluteFilePath.of(__dirname), RelativeFilePath.of("fixtures"));

// eslint-disable-next-line @typescript-eslint/no-misused-promises
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ describe("openapi-ir-to-fern", async () => {
`Failed to load OpenAPI fixture ${fixture.name}\n${JSON.stringify(workspace.failures)}`
);
}
const definition = await workspace.workspace.getDefinition({ context });
const definition = await workspace.workspace.getDefinition({
context,
absoluteFilePath: AbsoluteFilePath.of("/DUMMY_PATH")
});

// eslint-disable-next-line jest/no-standalone-expect
expect(definition).toMatchFileSnapshot(`./__snapshots__/openapi/${fixture.name}.json`);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ describe("openapi-ir-to-fern docs", async () => {
`Failed to load OpenAPI fixture ${fixture.name}\n${JSON.stringify(workspace.failures)}`
);
}

const definition = await workspace.workspace.getDefinition(
{ context },
{
context,
absoluteFilePath: AbsoluteFilePath.of("/DUMMY_PATH")
},
{ enableUniqueErrorsPerEndpoint: true, preserveSchemaIds: true }
);

// eslint-disable-next-line jest/no-standalone-expect
expect(definition).toMatchFileSnapshot(`./__snapshots__/openapi-docs/${fixture.name}.json`);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"path": "../../../task-context"
},
{
"path": "../../../workspace-loader"
"path": "../../../workspace/browser-compatible-fern-workspace"
},
{
"path": "../../../lazy-fern-workspace"
"path": "../../../workspace/loader"
},
{
"path": "../openapi-ir-parser"
"path": "../../../workspace/lazy-fern-workspace"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
{
"path": "../../../task-context"
},
{
"path": "../../../workspace-commons"
},
{
"path": "../../commons"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/cli-source-resolver/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"path": "../task-context"
},
{
"path": "../workspace-commons"
"path": "../workspace/commons"
}
]
}
6 changes: 3 additions & 3 deletions packages/cli/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@
"path": "../task-context"
},
{
"path": "../workspace-loader"
"path": "../workspace/loader"
},
{
"path": "../workspace-commons"
"path": "../workspace/commons"
},
{
"path": "../lazy-fern-workspace"
"path": "../workspace/lazy-fern-workspace"
},
{
"path": "../yaml/docs-validator"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/docs-resolver/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"path": "../task-context"
},
{
"path": "../workspace-loader"
"path": "../workspace/loader"
}
]
}
2 changes: 1 addition & 1 deletion packages/cli/fern-definition/formatter/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{ "path": "../../../commons/core-utils" },
{ "path": "../../../commons/fs-utils" },
{ "path": "../../task-context" },
{ "path": "../../workspace-commons" },
{ "path": "../../workspace/commons" },
{ "path": "../schema" }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"path": "../../task-context"
},
{
"path": "../../workspace-loader"
"path": "../../workspace/loader"
},
]
}
4 changes: 2 additions & 2 deletions packages/cli/fern-definition/validator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"path": "../../task-context"
},
{
"path": "../../workspace-commons"
"path": "../../workspace/commons"
},
{
"path": "../../lazy-fern-workspace"
"path": "../../workspace/lazy-fern-workspace"
},
{
"path": "../schema"
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/generation/ir-generator-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"path": "../../task-context"
},
{
"path": "../../workspace-loader"
"path": "../../workspace/loader"
},
{
"path": "../../workspace-commons"
"path": "../../workspace/commons"
},
{
"path": "../../fern-definition/schema"
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 @@ -25,7 +25,7 @@
"path": "../../task-context"
},
{
"path": "../../workspace-commons"
"path": "../../workspace/commons"
},
{
"path": "../../fern-definition/schema"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/generation/ir-migrations/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"path": "../../task-context"
},
{
"path": "../../workspace-loader"
"path": "../../workspace/loader"
},
{
"path": "../ir-generator"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { fernConfigJson, generatorsYml } from "@fern-api/configuration";
import { TaskContext } from "@fern-api/task-context";
import { AbstractAPIWorkspace, getOSSWorkspaceSettingsFromGeneratorInvocation } from "@fern-api/workspace-loader";
import {
AbstractAPIWorkspace,
getBaseOpenAPIWorkspaceSettingsFromGeneratorInvocation
} from "@fern-api/workspace-loader";
import chalk from "chalk";
import os from "os";
import path from "path";
Expand Down Expand Up @@ -32,7 +35,7 @@ export async function runLocalGenerationForWorkspace({
} else {
const fernWorkspace = await workspace.toFernWorkspace(
{ context },
getOSSWorkspaceSettingsFromGeneratorInvocation(generatorInvocation)
getBaseOpenAPIWorkspaceSettingsFromGeneratorInvocation(generatorInvocation)
);

await writeFilesToDiskAndRunGenerator({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"path": "../../../task-context"
},
{
"path": "../../../workspace-loader"
"path": "../../../workspace/loader"
},
{
"path": "../../../workspace-commons"
"path": "../../../workspace/commons"
},
{
"path": "../../ir-generator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { FernToken } from "@fern-api/auth";
import { fernConfigJson, generatorsYml } from "@fern-api/configuration";
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { AbstractAPIWorkspace, getOSSWorkspaceSettingsFromGeneratorInvocation } from "@fern-api/workspace-loader";
import {
AbstractAPIWorkspace,
getBaseOpenAPIWorkspaceSettingsFromGeneratorInvocation
} from "@fern-api/workspace-loader";
import { FernFiddle } from "@fern-fern/fiddle-sdk";
import { downloadSnippetsForTask } from "./downloadSnippetsForTask";
import { runRemoteGenerationForGenerator } from "./runRemoteGenerationForGenerator";
Expand Down Expand Up @@ -49,7 +52,7 @@ export async function runRemoteGenerationForAPIWorkspace({
context.runInteractiveTask({ name: generatorInvocation.name }, async (interactiveTaskContext) => {
const fernWorkspace = await workspace.toFernWorkspace(
{ context },
getOSSWorkspaceSettingsFromGeneratorInvocation(generatorInvocation)
getBaseOpenAPIWorkspaceSettingsFromGeneratorInvocation(generatorInvocation)
);

const remoteTaskHandlerResponse = await runRemoteGenerationForGenerator({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"path": "../../../task-context"
},
{
"path": "../../../workspace-loader"
"path": "../../../workspace/loader"
},
{
"path": "../../ir-generator"
Expand Down
1 change: 0 additions & 1 deletion packages/cli/lazy-fern-workspace/.prettierrc.cjs

This file was deleted.

Loading

0 comments on commit 6fd463a

Please sign in to comment.