Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
chore: move cache to global dir
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Sep 12, 2024
1 parent 2c41981 commit b48d9c9
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 105 deletions.
2 changes: 0 additions & 2 deletions examples/basic/.gitignore

This file was deleted.

6 changes: 6 additions & 0 deletions examples/basic/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/backend/cli/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { build, DbDriver, Format, MigrateMode, Runtime } from "../../toolchain/b
import { watch } from "../../toolchain/watch/mod.ts";
import { Project } from "../../toolchain/project/mod.ts";
import { InternalError } from "../../toolchain/error/mod.ts";
import { ENTRYPOINT_PATH, projectGenPath } from "../../toolchain/project/project.ts";
import { ENTRYPOINT_PATH, projectCachePath } from "../../toolchain/project/project.ts";
import { migrateModeSchema } from "./../util.ts";
import { ensurePostgresRunning, getDefaultDatabaseUrl } from "../../toolchain/postgres/mod.ts";

Expand Down Expand Up @@ -56,7 +56,7 @@ export async function execute(opts: Opts) {
if (opts.check) args.push("--check");

// Run entrypoint
const entrypointPath = projectGenPath(project, ENTRYPOINT_PATH);
const entrypointPath = projectCachePath(project, ENTRYPOINT_PATH);
const cmd = await new Deno.Command("deno", {
args: [
"run",
Expand Down
1 change: 1 addition & 0 deletions packages/backend/deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"imports": {
"@asteasolutions/zod-to-openapi": "npm:@asteasolutions/zod-to-openapi@^7.1.1",
"@bartlomieju/postgres": "jsr:@bartlomieju/postgres@^0.17.2",
"@cross/dir": "jsr:@cross/dir@^1.1.0",
"@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3",
"@std/assert": "jsr:@std/assert@^1.0.3",
"@std/async": "jsr:@std/async@^1.0.4",
Expand Down
33 changes: 33 additions & 0 deletions packages/backend/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions packages/backend/toolchain/build/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
genDependencyCaseConversionMapPath,
genRuntimeModPath,
GITIGNORE_PATH,
projectGenPath,
projectCachePath,
RUNTIME_CONFIG_PATH,
PACKAGES_PATH,
} from "../project/project.ts";
Expand All @@ -19,8 +19,8 @@ import { convertSerializedSchemaToZodExpression } from "./schema/mod.ts";
export async function generateEntrypoint(project: Project, opts: BuildOpts) {
const runtimeModPath = genRuntimeModPath(project);

const entrypoint = new GeneratedCodeBuilder(projectGenPath(project, ENTRYPOINT_PATH), 2);
const config = new GeneratedCodeBuilder(projectGenPath(project, RUNTIME_CONFIG_PATH), 2);
const entrypoint = new GeneratedCodeBuilder(projectCachePath(project, ENTRYPOINT_PATH), 2);
const config = new GeneratedCodeBuilder(projectCachePath(project, RUNTIME_CONFIG_PATH), 2);

// Generate module configs
const [modImports, modConfig] = generateModImports(project, entrypoint.path!);
Expand Down Expand Up @@ -106,14 +106,14 @@ export async function generateEntrypoint(project: Project, opts: BuildOpts) {
import type { ActorsSnake, ActorsCamel } from "./actors.d.ts";
import config from "./runtime_config.ts";
import { handleRequest } from ${
JSON.stringify(entrypoint.relative(projectGenPath(project, PACKAGES_PATH, "runtime", "server.ts")))
JSON.stringify(entrypoint.relative(projectCachePath(project, PACKAGES_PATH, "runtime", "server.ts")))
};
import { ActorDriver } from ${JSON.stringify(entrypoint.relative(actorDriverPath))};
import { PathResolver } from ${
JSON.stringify(entrypoint.relative(projectGenPath(project, PACKAGES_PATH, "path_resolver", "mod.ts")))
JSON.stringify(entrypoint.relative(projectCachePath(project, PACKAGES_PATH, "path_resolver", "mod.ts")))
};
import { log } from ${
JSON.stringify(entrypoint.relative(projectGenPath(project, PACKAGES_PATH, "runtime", "logger.ts")))
JSON.stringify(entrypoint.relative(projectCachePath(project, PACKAGES_PATH, "runtime", "logger.ts")))
};
`;

Expand Down Expand Up @@ -159,8 +159,8 @@ export async function generateEntrypoint(project: Project, opts: BuildOpts) {
).finished;
`;
} else if (opts.runtime == Runtime.CloudflareWorkersPlatforms) {
const serverTsPath = projectGenPath(project, PACKAGES_PATH, "runtime", "server.ts");
const errorTsPath = projectGenPath(project, PACKAGES_PATH, "runtime", "error.ts");
const serverTsPath = projectCachePath(project, PACKAGES_PATH, "runtime", "server.ts");
const errorTsPath = projectCachePath(project, PACKAGES_PATH, "runtime", "error.ts");

entrypoint.chunk.withNewlinesPerChunk(1)
.append`
Expand All @@ -181,7 +181,7 @@ export async function generateEntrypoint(project: Project, opts: BuildOpts) {
JSON.stringify(entrypoint.relative(actorDriverPath))
};
import { PathResolver } from ${
JSON.stringify(entrypoint.relative(projectGenPath(project, PACKAGES_PATH, "path_resolver", "mod.ts")))
JSON.stringify(entrypoint.relative(projectCachePath(project, PACKAGES_PATH, "path_resolver", "mod.ts")))
};
`;

Expand Down Expand Up @@ -249,7 +249,7 @@ export async function generateEntrypoint(project: Project, opts: BuildOpts) {
await entrypoint.write();

await Deno.writeTextFile(
projectGenPath(project, GITIGNORE_PATH),
projectCachePath(project, GITIGNORE_PATH),
".",
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/toolchain/build/gen/db_schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dbSchemaHelperPath, DRIZZLE_ORM_REEXPORT, Module, Project, projectGenPath } from "../../project/mod.ts";
import { dbSchemaHelperPath, DRIZZLE_ORM_REEXPORT, Module, Project, projectCachePath } from "../../project/mod.ts";
import { GeneratedCodeBuilder } from "./mod.ts";
import { InternalError } from "../../error/mod.ts";
import drizzleOrmArtifact from "../../../artifacts/drizzle_orm.json" with { type: "json" };
Expand All @@ -23,7 +23,7 @@ export async function compileDbSchemaHelper(
}

const dbPath = opts.overrideDbPath ?? dbSchemaHelperPath(project, module);
const ormReexportPath = opts.overrideOrmReexportPath ?? projectGenPath(project, DRIZZLE_ORM_REEXPORT);
const ormReexportPath = opts.overrideOrmReexportPath ?? projectCachePath(project, DRIZZLE_ORM_REEXPORT);
const ormPackage = opts.forceNodeModules ? DRIZZLE_ORM_PACKAGE_NPM : DRIZZLE_ORM_PACKAGE;

await generateOrmReexport(ormReexportPath, ormPackage);
Expand Down
8 changes: 4 additions & 4 deletions packages/backend/toolchain/build/gen/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
genModulePublicExternal,
genRuntimeModPath,
PACKAGES_PATH,
projectGenPath,
projectCachePath,
RUNTIME_CONFIG_PATH,
} from "../../project/project.ts";
import { camelify } from "../../../case_conversion/mod.ts";
Expand All @@ -30,11 +30,11 @@ export async function compileModuleHelper(

const runtimePath = helper.relative(genRuntimeModPath(project));
const reexportPath = helper.relative(
projectGenPath(project, PACKAGES_PATH, "runtime", "export_to_module.ts"),
projectCachePath(project, PACKAGES_PATH, "runtime", "export_to_module.ts"),
);
const dependencyCaseConversionMapPath = helper.relative(genDependencyCaseConversionMapPath(project));
const actorCaseConversionMapPath = helper.relative(genActorCaseConversionMapPath(project));
const runtimeConfigPath = helper.relative(projectGenPath(project, RUNTIME_CONFIG_PATH));
const runtimeConfigPath = helper.relative(projectCachePath(project, RUNTIME_CONFIG_PATH));

// Import & re-export runtime files
//
Expand Down Expand Up @@ -177,7 +177,7 @@ function genModule(
// Database
if (module.db) {
helper.append`
export * as Query from ${JSON.stringify(helper.relative(projectGenPath(project, DRIZZLE_ORM_REEXPORT)))};
export * as Query from ${JSON.stringify(helper.relative(projectCachePath(project, DRIZZLE_ORM_REEXPORT)))};
export * as Database from "./db/schema.ts";
`;
helper.append`
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/toolchain/build/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ModuleConfig, ScriptConfig } from "../config/module.ts";
import { ProjectConfig } from "../config/project.ts";
import { RegistryConfig } from "../config/project.ts";
import { hasUserConfigSchema, Project } from "../project/mod.ts";
import { META_PATH, projectGenPath } from "../project/project.ts";
import { META_PATH, projectCachePath } from "../project/project.ts";
import { camelify, pascalify } from "../../case_conversion/mod.ts";
import { AnySchemaElement } from "./schema/mod.ts";

Expand Down Expand Up @@ -96,7 +96,7 @@ export async function generateMeta(project: Project) {
};

await Deno.writeTextFile(
projectGenPath(project, META_PATH),
projectCachePath(project, META_PATH),
JSON.stringify(meta, null, 4),
);
}
4 changes: 2 additions & 2 deletions packages/backend/toolchain/build/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Project } from "../project/mod.ts";
import { OPEN_API_PATH, projectGenPath } from "../project/project.ts";
import { OPEN_API_PATH, projectCachePath } from "../project/project.ts";
import { OpenApiGeneratorV31, OpenAPIRegistry } from "@asteasolutions/zod-to-openapi";
import { convertSerializedSchemaToZod } from "./schema/mod.ts";

Expand Down Expand Up @@ -66,7 +66,7 @@ export async function generateOpenApi(project: Project) {
document = flattenOpenAPIConfig(document);

await Deno.writeTextFile(
projectGenPath(project, OPEN_API_PATH),
projectCachePath(project, OPEN_API_PATH),
JSON.stringify(document, null, 4),
);
}
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/toolchain/build/plan/project.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BuildState, buildStep, waitForBuildPromises } from "../../build_state/mod.ts";
import * as glob from "glob";
import { relative, resolve } from "@std/path";
import { Project, projectGenPathRaw } from "../../project/mod.ts";
import { Project } from "../../project/mod.ts";
import { BuildOpts, Format, MigrateMode, Runtime } from "../mod.ts";
import { planModuleBuild } from "./module.ts";
import { compileTypeHelpers } from "../gen/mod.ts";
Expand All @@ -10,7 +10,7 @@ import { generateEntrypoint } from "../entrypoint.ts";
import { generateOpenApi } from "../openapi.ts";
import { UnreachableError, UserError } from "../../error/mod.ts";
import { generateMeta } from "../meta.ts";
import { BUNDLE_PATH, ENTRYPOINT_PATH, MANIFEST_PATH, projectGenPath, PACKAGES_PATH } from "../../project/project.ts";
import { BUNDLE_PATH, ENTRYPOINT_PATH, MANIFEST_PATH, projectCachePath, PACKAGES_PATH } from "../../project/project.ts";
import { compileActorTypeHelpers } from "../gen/mod.ts";
import { inflateArchive } from "../util.ts";
import packagesArchive from "../../../artifacts/packages_archive.json" with { type: "json" };
Expand Down Expand Up @@ -38,7 +38,7 @@ export async function planProjectBuild(
description: "packages/",
async build({ signal }) {
// Writes a copy of the backend runtime bundled with the CLI to the project.
const inflatePackagesPath = projectGenPath(project, PACKAGES_PATH);
const inflatePackagesPath = projectCachePath(project, PACKAGES_PATH);
await inflateArchive(packagesArchive, inflatePackagesPath, "string", signal);
},
});
Expand Down Expand Up @@ -135,15 +135,15 @@ export async function planProjectBuild(
name: "Bundle",
description: "bundle.js",
async build({ signal }) {
const bundledFile = projectGenPath(project, BUNDLE_PATH);
const bundledFile = projectCachePath(project, BUNDLE_PATH);

// See Cloudflare Wrangler implementation:
//
// https://github.com/cloudflare/workers-sdk/blob/e8997b879605fb2eabc3e241086feb7aa219ef03/packages/wrangler/src/deployment-bundle/bundle.ts#L276
const analyzeResult = Deno.env.get("_BACKEND_ESBUILD_META") == "1";
const noMinify = Deno.env.get("_BACKEND_ESBUILD_NO_MINIFY") == "1";
const result = await esbuild.build({
entryPoints: [projectGenPath(project, ENTRYPOINT_PATH)],
entryPoints: [projectCachePath(project, ENTRYPOINT_PATH)],
outfile: bundledFile,
format: "esm",
sourcemap: true,
Expand Down Expand Up @@ -257,7 +257,7 @@ export async function planProjectBuild(
signal.throwIfAborted();

await Deno.writeTextFile(
projectGenPath(project, MANIFEST_PATH),
projectCachePath(project, MANIFEST_PATH),
JSON.stringify(manifest),
);
}
Expand All @@ -275,7 +275,7 @@ export async function planProjectBuild(
description: "entrypoint.ts",
async build() {
const checkOutput = await new Deno.Command("deno", {
args: ["check", "--quiet", projectGenPathRaw(project.path, "entrypoint.ts")],
args: ["check", "--quiet", projectCachePath(project, "entrypoint.ts")],
signal,
}).output();
if (!checkOutput.success) {
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/toolchain/build_state/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AnySchemaElement } from "../build/schema/mod.ts";
import { exists } from "@std/fs";
import { UnreachableError } from "../error/mod.ts";
import { CACHE_PATH, Project, projectGenPath } from "../project/project.ts";
import { CACHE_PATH, Project, projectCachePath } from "../project/project.ts";
import { verbose } from "../term/status.ts";
import { crypto } from "@std/crypto";
import { encodeHex } from "@std/encoding/hex";
Expand Down Expand Up @@ -35,7 +35,7 @@ export interface CacheScriptSchema {
}

export async function loadCache(project: Project): Promise<Cache> {
const buildCachePath = projectGenPath(project, CACHE_PATH);
const buildCachePath = projectCachePath(project, CACHE_PATH);

// Read hashes from file
let persist: CachePersist;
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function loadCache(project: Project): Promise<Cache> {
}

export async function writeCache(project: Project, cache: Cache) {
const buildCachePath = projectGenPath(project, CACHE_PATH);
const buildCachePath = projectCachePath(project, CACHE_PATH);

// Write cache
await Deno.writeTextFile(
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/toolchain/postgres/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { addShutdownHandler } from "../utils/shutdown_handler.ts";
import { getClient, getDatabaseUrl, Manager, setup } from "./manager.ts";
import { createManager } from "./manager.ts";
import { Settings } from "./settings.ts";
import { projectGenPath } from "../project/mod.ts";
import { projectCachePath } from "../project/mod.ts";

export const DEFAULT_VERSION = "16.4.0";
export const DEFAULT_DATABASE = "rivet-backend";
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function ensurePostgresRunning(project: Project) {
}

function defaultSettings(project: Project): Settings {
const postgresRoot = projectGenPath(project, "postgres");
const postgresRoot = projectCachePath(project, "postgres");

const stateFile = resolve(postgresRoot, "manager_state.json");
const passwordFile = resolve(postgresRoot, ".pgpass");
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/toolchain/project/actor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Module } from "./module.ts";
import { Project, projectGenPath } from "./project.ts";
import { Project, projectCachePath } from "./project.ts";
import { ActorConfig } from "../config/module.ts";

export interface Actor {
Expand All @@ -14,7 +14,7 @@ export function actorGenPath(
module: Module,
actor: Actor,
): string {
return projectGenPath(
return projectCachePath(
project,
"modules",
module.name,
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/toolchain/project/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ModuleConfig } from "../config/module.ts";
import { Script } from "./script.ts";
import { Actor } from "./actor.ts";
import { Route } from "./route.ts";
import { Project, projectGenPath } from "./project.ts";
import { Project, projectCachePath } from "./project.ts";
import { Registry } from "./registry.ts";
import { validateIdentifier } from "../types/identifiers/mod.ts";
import { Casing } from "../types/identifiers/defs.ts";
Expand Down Expand Up @@ -73,7 +73,7 @@ function validatePath(

export interface Module {
/**
* The path to the cloned module in the project's .rivet/modules/ directory.
* The path to the cloned module in the project's cache dir.
*
* This path can be modified and will be discarded on the next codegen.
*/
Expand Down Expand Up @@ -431,7 +431,7 @@ export function moduleHelperGen(
}

export function moduleGenPath(project: Project, module: Module, ...pathSegments: string[]): string {
return projectGenPath(project, "modules", module.name, ...pathSegments);
return projectCachePath(project, "modules", module.name, ...pathSegments);
}

export function dbSchemaHelperPath(
Expand Down
Loading

0 comments on commit b48d9c9

Please sign in to comment.