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 2 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
1 change: 0 additions & 1 deletion .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const checkApiPackages = [

// Packages that should be private
const privatePackages = [
"@osdk/cli.*",
"@osdk/client.test.ontology",
"@osdk/create-app.template-packager",
"@osdk/create-app.template.*",
Expand Down
2 changes: 2 additions & 0 deletions babel.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { findUp } from "find-up";
import { readFile } from "fs/promises";
import * as path from "node:path";

process.env.STABLE_PACKAGE_CLIENT_VERSION = "~2.0.11";
Copy link
Member Author

Choose a reason for hiding this comment

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

After we move this to the other repo, we can put a devDependency on @osdk/client in the packages that need this and can just read from there instead of doing the hard coding.

process.env.PACKAGE_VERSION = await readPackageVersion(process.cwd());
process.env.PACKAGE_API_VERSION = await readPackageVersion("packages/api");
process.env.PACKAGE_CLIENT_VERSION = await readPackageVersion(
Expand All @@ -40,6 +41,7 @@ const config = function(api) {
"PACKAGE_API_VERSION",
"PACKAGE_CLIENT_VERSION",
"PACKAGE_CLI_VERSION",
"STABLE_PACKAGE_CLIENT_VERSION",
"TARGET",
"MODE",
],
Expand Down
7 changes: 4 additions & 3 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.20",
"license": "Apache-2.0",
"repository": {
Expand Down Expand Up @@ -30,8 +30,9 @@
},
"dependencies": {
"@arethetypeswrong/cli": "^0.15.2",
"@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.8.0",
"@osdk/internal.foundry.ontologiesv2": "2.8.0",
"@osdk/shared.client.impl": "workspace:~",
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 @@ -281,8 +282,16 @@ export async function getDependencyVersions() {
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
2 changes: 1 addition & 1 deletion 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.20",
"license": "Apache-2.0",
"repository": {
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
18 changes: 17 additions & 1 deletion 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 Down Expand Up @@ -47,6 +55,14 @@ beforeEach(() => {
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", "2.1.0-beta.20");
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't run babel or anything for tests

});

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

test(`CLI creates ${template.id}`, async () => {
await runTest({
project: `expected-${template.id}`,
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
18 changes: 17 additions & 1 deletion packages/create-widget/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 Down Expand Up @@ -46,6 +54,14 @@ beforeEach(() => {

for (const template of TEMPLATES) {
describe.each(["2.x"])("For SDK version %s", (sdkVersion) => {
beforeAll(() => {
vi.stubEnv("STABLE_PACKAGE_CLIENT_VERSION", "2.1.0-beta.20");
});

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

test(`CLI creates ${template.id}`, async () => {
await runTest({
project: `expected-${template.id}`,
Expand Down
15 changes: 3 additions & 12 deletions packages/create-widget/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 { generateFoundryConfigJson } from "./generate/generateFoundryConfigJson.js";
import { generateNpmRc } from "./generate/generateNpmRc.js";
Expand Down Expand Up @@ -91,16 +89,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
4 changes: 2 additions & 2 deletions packages/example-generator/src/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ 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",
async () => {
await run({
outputDirectory: path.join(__dirname, "..", "..", "..", "examples"),
outputDirectory: path.join(THIS_FILE_DIR, "..", "..", "..", "examples"),
check: true,
});
},
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ import type {
import { consola } from "consola";
import { mkdir, readdir, rmdir, writeFile } from "fs/promises";
import * as immer from "immer";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { beforeEach, describe, expect, it, test, vi } from "vitest";
import { compileThis } from "../util/test/compileThis.js";
import { createMockMinimalFiles } from "../util/test/createMockMinimalFiles.js";
import { TodoWireOntology } from "../util/test/TodoWireOntology.js";
import type { WireOntologyDefinition } from "../WireOntologyDefinition.js";
import { generateClientSdkVersionTwoPointZero } from "./generateClientSdkVersionTwoPointZero.js";

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

function changeValue<T extends Record<K, any>, K extends keyof immer.Draft<T>>(
draft: immer.Draft<T>,
key: K,
Expand Down Expand Up @@ -1706,10 +1710,10 @@ describe("generator", () => {

test.skip("runs generator locally", async () => {
try {
await rmdir(`${__dirname}/generated`, { recursive: true });
await rmdir(`${THIS_FILE_DIR}/generated`, { recursive: true });
} catch (e) {
}
await mkdir(`${__dirname}/generated`, { recursive: true });
await mkdir(`${THIS_FILE_DIR}/generated`, { recursive: true });
await generateClientSdkVersionTwoPointZero(
TodoWireOntology,
"typescript-sdk/0.0.0 osdk-cli/0.0.0",
Expand All @@ -1722,7 +1726,7 @@ describe("generator", () => {
},
readdir: async (path) => await readdir(path),
},
`${__dirname}/generated/`,
`${THIS_FILE_DIR}/generated/`,
);
});

Expand Down
1 change: 1 addition & 0 deletions packages/monorepo.cspell/cspell.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
const fs = require("fs");
const path = require("path");

// this is okay because this file is a commonjs file
const DICT_FOLDER = __dirname;

const REGEX_OSDK_PACKAGE_NAME = /@osdk\/[\w\d.\-]+/g;
Expand Down
Loading
Loading