Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prep work for splitting clis #1086

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/seven-gorillas-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@osdk/cli.cmd.typescript": patch
"@osdk/create-widget": patch
"@osdk/cli.common": patch
"@osdk/create-app": patch
"@osdk/cli": patch
---

Internal: preparation for repo splitting
5 changes: 4 additions & 1 deletion .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ const archetypeRules = archetypes(
skipTypes: true,
},
)
.addArchetype("cli components", ["@osdk/cli.*"], {
...INTERNAL_LIBRARY_RULES,
private: false,
})
.addArchetype(
"internal libraries / templates",
[
"@osdk/cli.*",
"@osdk/client.test.ontology",
"@osdk/create-app.template.*",
"@osdk/create-widget.template.*",
Expand Down
66 changes: 0 additions & 66 deletions babel.config.mjs

This file was deleted.

16 changes: 12 additions & 4 deletions packages/cli.cmd.typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@osdk/cli.cmd.typescript",
"private": true,
"private": false,
"version": "0.25.0-beta.25",
"license": "Apache-2.0",
"repository": {
Expand Down Expand Up @@ -35,8 +35,9 @@
},
"dependencies": {
"@arethetypeswrong/cli": "^0.17.3",
"@osdk/cli.common": "workspace:~",
"@osdk/generator": "workspace:~",
"@osdk/cli.common": "workspace:*",
"@osdk/generator": "workspace:*",
"@osdk/generator-utils": "workspace:*",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these we don't want surprises so we are locking exactly in.

"@osdk/internal.foundry.core": "2.10.0",
"@osdk/internal.foundry.ontologiesv2": "2.10.0",
"@osdk/shared.client.impl": "workspace:~",
Expand All @@ -59,7 +60,14 @@
"bin": {
"osdk-unstable-typescript": "./bin/osdk-unstable-typescript.mjs"
},
"files": [],
"files": [
"build/esm",
"build/types",
"CHANGELOG.md",
"package.json",
"templates",
"*.d.ts"
],
"module": "./build/esm/index.js",
"types": "./build/esm/index.d.ts",
"type": "module"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli.cmd.typescript/src/generate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const generateCommand: CommandModule<
);
},
handler: async (args) => {
const command = await import("./handleGenerate.mjs");
const command = await import("./handleGenerate.js");
await command.handleGenerate(args);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { describe, expect, it } from "vitest";
import { updateVersionsIfTheyExist } from "./handleGenerate.mjs";
import { updateVersionsIfTheyExist } from "./handleGenerate.js";

describe(updateVersionsIfTheyExist, () => {
it("should update versions if they exist", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
generateClientSdkVersionTwoPointZero,
getExpectedDependencies,
} from "@osdk/generator";
import { changeVersionPrefix } from "@osdk/generator-utils";
import type { OntologyIdentifier } from "@osdk/internal.foundry.core";
import { OntologiesV2 } from "@osdk/internal.foundry.ontologiesv2";
import { createSharedClientContext } from "@osdk/shared.client.impl";
Expand Down Expand Up @@ -290,8 +291,16 @@ export async function getDependencyVersions(): Promise<{
const tslibVersion = ourPackageJson.dependencies.tslib;
const areTheTypesWrongVersion =
ourPackageJson.dependencies["@arethetypeswrong/cli"];
const osdkClientVersion = `^${process.env.PACKAGE_CLIENT_VERSION}`;
const osdkApiVersion = `^${process.env.PACKAGE_API_VERSION}`;
const osdkClientVersion = changeVersionPrefix(
process.env.PACKAGE_CLIENT_VERSION!,
"^",
);

const osdkApiVersion = changeVersionPrefix(
process.env.PACKAGE_API_VERSION!,
"^",
);

const osdkLegacyClientVersion =
`^${process.env.PACKAGE_LEGACY_CLIENT_VERSION}`;

Expand Down
11 changes: 9 additions & 2 deletions packages/cli.common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@osdk/cli.common",
"private": true,
"private": false,
"version": "0.25.0-beta.25",
"license": "Apache-2.0",
"repository": {
Expand Down Expand Up @@ -56,7 +56,14 @@
"publishConfig": {
"access": "public"
},
"files": [],
"files": [
"build/esm",
"build/types",
"CHANGELOG.md",
"package.json",
"templates",
"*.d.ts"
],
"module": "./build/esm/index.js",
"types": "./build/esm/index.d.ts",
"type": "module"
Expand Down
4 changes: 2 additions & 2 deletions packages/client.test.ontology/generateMockOntology.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { mkdir, readdir, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const outDir = join(__dirname, "src", "generatedNoCheck");
const THIS_FILE_DIR = dirname(fileURLToPath(import.meta.url));
const outDir = join(THIS_FILE_DIR, "src", "generatedNoCheck");

try {
rmSync(outDir, { recursive: true, force: true });
Expand Down
8 changes: 4 additions & 4 deletions packages/create-app/codegen.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const THIS_FILE_DIR = path.dirname(fileURLToPath(import.meta.url));

export const TEMPLATES = [
{
Expand Down Expand Up @@ -62,14 +62,14 @@ export const TEMPLATES = [
},
];

const packagesDir = path.join(__dirname, "../");
const packagesDir = path.join(THIS_FILE_DIR, "../");

fs.mkdirSync(path.join(__dirname, "./src/generatedNoCheck"), {
fs.mkdirSync(path.join(THIS_FILE_DIR, "./src/generatedNoCheck"), {
recursive: true,
});

fs.writeFileSync(
path.join(__dirname, "./src/generatedNoCheck/templates.ts"),
path.join(THIS_FILE_DIR, "./src/generatedNoCheck/templates.ts"),
dedent`
// THIS FILE IS GENERATED. DO NOT MODIFY.
// You probably want to modify ../../../codegen.mjs instead.
Expand Down
23 changes: 21 additions & 2 deletions packages/create-app/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ import fs from "node:fs";
import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { dirSync } from "tmp";
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
import {
afterAll,
beforeAll,
beforeEach,
describe,
expect,
test,
vi,
} from "vitest";
import { cli } from "./cli.js";
import { TEMPLATES } from "./generatedNoCheck/templates.js";
import type { Template } from "./templates.js";
Expand All @@ -44,9 +52,20 @@ beforeEach(() => {
};
});

const EXPECTED_CLIENT_VERSION = "2.0.11";

describe.each(TEMPLATES)("template $id", (template) => {
const supportedVersions = Object.keys(template.files);

describe.each(supportedVersions)("For SDK version %s", (sdkVersion) => {
beforeAll(() => {
vi.stubEnv("STABLE_PACKAGE_CLIENT_VERSION", EXPECTED_CLIENT_VERSION);
});

afterAll(() => {
vi.unstubAllEnvs();
});

test(`CLI creates ${template.id}`, async () => {
await runTest({
project: `expected-${template.id}`,
Expand Down Expand Up @@ -119,7 +138,7 @@ async function runTest(
// it should be, so that if the create-app code were to change to different behavior
// it would be caught.
expect(packageJson.dependencies["@osdk/client"]).toBe(
`^${createAppVersion}`,
`^${EXPECTED_CLIENT_VERSION}`,
);
} else {
expect(packageJson.dependencies["@osdk/client"]).toBe(
Expand Down
15 changes: 3 additions & 12 deletions packages/create-app/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
*/

import { changeVersionPrefix } from "@osdk/generator-utils";
import { findUpSync } from "find-up";
import Handlebars from "handlebars";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { consola } from "./consola.js";
import {
generateEnvDevelopment,
Expand Down Expand Up @@ -108,16 +106,9 @@ export async function run(
);
}

const ourPackageJsonPath = findUpSync("package.json", {
cwd: fileURLToPath(import.meta.url),
});

const ourPackageJsonVersion: string | undefined = ourPackageJsonPath
? JSON.parse(fs.readFileSync(ourPackageJsonPath, "utf-8")).version
: undefined;

const clientVersion = process.env.PACKAGE_CLIENT_VERSION
?? ourPackageJsonVersion;
// In the future we should try to get this information directly from NPM
// or maybe add it as a devDependency once it moves out of repo
const clientVersion = process.env.STABLE_PACKAGE_CLIENT_VERSION;

if (clientVersion === undefined) {
throw new Error("Could not determine current @osdk/client version");
Expand Down
8 changes: 4 additions & 4 deletions packages/create-widget/codegen.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const THIS_FILE_DIR = path.dirname(fileURLToPath(import.meta.url));

export const TEMPLATES = [
{
Expand All @@ -30,14 +30,14 @@ export const TEMPLATES = [
},
];

const packagesDir = path.join(__dirname, "../");
const packagesDir = path.join(THIS_FILE_DIR, "../");

fs.mkdirSync(path.join(__dirname, "./src/generatedNoCheck"), {
fs.mkdirSync(path.join(THIS_FILE_DIR, "./src/generatedNoCheck"), {
recursive: true,
});

fs.writeFileSync(
path.join(__dirname, "./src/generatedNoCheck/templates.ts"),
path.join(THIS_FILE_DIR, "./src/generatedNoCheck/templates.ts"),
dedent`
// THIS FILE IS GENERATED. DO NOT MODIFY.
// You probably want to modify ../../../codegen.mjs instead.
Expand Down
2 changes: 1 addition & 1 deletion packages/example-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"check-spelling": "cspell --quiet .",
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
"generate": "./bin/exampleGenerator.mjs ../../examples",
"generate": "STABLE_PACKAGE_CLIENT_VERSION='workspace:*' ./bin/exampleGenerator.mjs ../../examples",
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
"test": "vitest run --pool=forks",
"transpileEsm": "monorepo.tool.transpile -f esm -m normal -t node",
Expand Down
7 changes: 4 additions & 3 deletions packages/example-generator/src/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import { fileURLToPath } from "node:url";
import { it } from "vitest";
import { run } from "./run.js";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const THIS_FILE_DIR = path.dirname(fileURLToPath(import.meta.url));

it(
"Generates code that matches the files on disk in the examples dir",
{ timeout: 15_000 },
async () => {
process.env.STABLE_PACKAGE_CLIENT_VERSION = "workspace:*";
await run({
outputDirectory: path.join(__dirname, "..", "..", "..", "examples"),
outputDirectory: path.join(THIS_FILE_DIR, "..", "..", "..", "examples"),
check: true,
});
},
{ timeout: 15000 },
);
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

import commonjs from "@rollup/plugin-commonjs";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import type { ModuleFormat, RollupBuild } from "rollup";
import { rollup } from "rollup";
import nodePolyfill from "rollup-plugin-polyfill-node";

const THIS_FILE_DIR = path.dirname(fileURLToPath(import.meta.url));

async function createRollupBuild(
absolutePackagePath: string,
packageName: string,
Expand All @@ -28,7 +32,7 @@ async function createRollupBuild(

const { findUp } = await import("find-up");
const nodeModulesPath = await findUp("node_modules", {
cwd: __dirname,
cwd: THIS_FILE_DIR,
type: "directory",
});

Expand Down
Loading
Loading