Skip to content

Commit

Permalink
Component definition TypeScript (#26554)
Browse files Browse the repository at this point in the history
First pass of component definition TypeScript: just enough to specify a component definition.

GitOrigin-RevId: 5e60f0009365522c937adea27b2d680e4db7644d
  • Loading branch information
thomasballinger authored and Convex, Inc. committed Jun 5, 2024
1 parent a898d0c commit 697ee9c
Show file tree
Hide file tree
Showing 9 changed files with 661 additions and 317 deletions.
72 changes: 0 additions & 72 deletions src/bundler/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ function warnCrossFilesystem(dstPath: string) {
export interface Filesystem {
listDir(dirPath: string): Dirent[];

// Filtered version of `listDir` that doesn't take a read dependency
// on entries filtered out. Note that `fileFilter` only applies to
// regular files, not directories.
listDirFiltered(
dirPath: string,
fileFilter: (absPath: string) => boolean,
): Dirent[];

exists(path: string): boolean;
stat(path: string): Stats;
readUtf8File(path: string): string;
Expand Down Expand Up @@ -112,21 +104,6 @@ class NodeFs implements Filesystem {
listDir(dirPath: string) {
return stdFs.readdirSync(dirPath, { withFileTypes: true });
}
listDirFiltered(
dirPath: string,
fileFilter: (absPath: string) => boolean,
): stdFs.Dirent[] {
const entries = stdFs.readdirSync(dirPath, { withFileTypes: true });
const filtered = [];
for (const entry of entries) {
const absPath = path.join(dirPath, entry.name);
if (entry.isFile() && !fileFilter(absPath)) {
continue;
}
filtered.push(entry);
}
return filtered;
}
exists(path: string) {
try {
stdFs.statSync(path);
Expand Down Expand Up @@ -276,55 +253,6 @@ export class RecordingFs implements Filesystem {
return entries;
}

listDirFiltered(
dirPath: string,
fileFilter: (absPath: string) => boolean,
): stdFs.Dirent[] {
const absDirPath = path.resolve(dirPath);

// Register observing the directory itself.
const dirSt = nodeFs.stat(absDirPath);
this.registerNormalized(absDirPath, dirSt);

// List the directory, collecting all of its child entries.
const allEntries = nodeFs.listDir(dirPath);

// Filter the entry list, throwing out files that don't pass `fileFilter`.
// Register observing the filtered children.
const filteredEntries = [];
for (const entry of allEntries) {
const childPath = path.join(absDirPath, entry.name);
if (entry.isFile() && !fileFilter(childPath)) {
continue;
}
const childSt = nodeFs.stat(childPath);
this.registerPath(childPath, childSt);
filteredEntries.push(entry);
}

// Register observing the directory's children. Note that
// we use the full entry list here, not the filtered list,
// since we want this observation to be shared across
// `listDirFiltered` calls with different `fileFilter`s.
const observedNames = new Set(allEntries.map((e) => e.name));
const existingNames = this.observedDirectories.get(absDirPath);
if (existingNames) {
if (!setsEqual(observedNames, existingNames)) {
if (this.traceEvents) {
console.log(
"Invalidating due to directory children mismatch",
observedNames,
existingNames,
);
}
this.invalidated = true;
}
}
this.observedDirectories.set(absDirPath, observedNames);

return filteredEntries;
}

exists(path: string): boolean {
try {
const st = nodeFs.stat(path);
Expand Down
21 changes: 2 additions & 19 deletions src/cli/lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
bundleDefinitions,
bundleImplementations,
componentGraph,
// TODO probably just a
} from "./components/definition/bundle.js";
import { isComponentDirectory } from "./components/definition/directoryStructure.js";

Expand Down Expand Up @@ -42,13 +41,6 @@ export async function runComponentsPush(ctx: Context, options: PushOptions) {

const convexDir = functionsDir(configPath, projectConfig);

// TODO
// Note we need to restart this whole process if any of these files change!
// We should track these separately if we can: if any thing observed
// by the definition traversal changes we need to restart at an earlier
// point than if something in one of the implementations changes.
// If one of the implementions changes we should be able to just rebuild that.

// '.' means use the process current working directory, it's the default behavior.
// Spelling it out here to be explicit for a future where this code can run
// from other directories.
Expand Down Expand Up @@ -90,12 +82,10 @@ export async function runComponentsPush(ctx: Context, options: PushOptions) {
absWorkingDir,
dependencyGraph,
rootComponent,
// note this *includes* the root component (TODO update bundleImpls to work this way too)
// Note that this *includes* the root component.
[...components.values()],
);

// Is this possible to run in this world?
// Note that it bundles!!! That's a step we don't need.
const { config: localConfig } = await configFromProjectConfig(
ctx,
projectConfig,
Expand All @@ -111,8 +101,6 @@ export async function runComponentsPush(ctx: Context, options: PushOptions) {
verbose,
);

// This expects an auth (get it the normal way)
// and functions which are pretty normal?
const appDefinition: AppDefinitionSpec = {
...appDefinitionSpecWithoutImpls,
auth: localConfig.authConfig || null,
Expand Down Expand Up @@ -149,7 +137,7 @@ export async function runComponentsPush(ctx: Context, options: PushOptions) {
options.adminKey,
options.url,
projectConfig.functions, // this is where the convex folder is, just 'convex/'
udfServerVersion, // this comes from config?
udfServerVersion,
appDefinition,
componentDefinitions,
);
Expand All @@ -163,9 +151,4 @@ export async function runComponentsPush(ctx: Context, options: PushOptions) {
startPushResponse,
);
console.log("finishPush:", finishPushResponse);

// TODO
// How to make this re-entrant? If there's a change you should be able to stop the current
// deploy and restart. If one component deep in the chain changes, you should be able.
// Cached results should be able to be used.
}
2 changes: 0 additions & 2 deletions src/cli/lib/components/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export const ROOT_DEFINITION_FILENAME = "app.config.ts";
export const DEFINITION_FILENAME = "component.config.ts";

export const IMPLICIT_EVALUATION_RESULT = "component_data.json";
Loading

0 comments on commit 697ee9c

Please sign in to comment.