appflare 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import chokidar from "chokidar";
2
- import { resolve } from "node:path";
2
+ import { existsSync } from "node:fs";
3
+ import { dirname, resolve } from "node:path";
3
4
  import { generateArtifacts } from "../generate";
4
5
  import { loadConfig } from "../load-config";
5
6
 
@@ -9,6 +10,23 @@ type MigrateOptions = {
9
10
  preview?: boolean;
10
11
  };
11
12
 
13
+ function findNearestPackageDir(startDir: string): string {
14
+ let currentDir = startDir;
15
+
16
+ while (true) {
17
+ if (existsSync(resolve(currentDir, "package.json"))) {
18
+ return currentDir;
19
+ }
20
+
21
+ const parentDir = dirname(currentDir);
22
+ if (parentDir === currentDir) {
23
+ return startDir;
24
+ }
25
+
26
+ currentDir = parentDir;
27
+ }
28
+ }
29
+
12
30
  export async function runBuild(configPath?: string): Promise<void> {
13
31
  const loadedConfig = await loadConfig(configPath);
14
32
  await generateArtifacts(loadedConfig);
@@ -75,6 +93,8 @@ export async function runMigrate(
75
93
  options: MigrateOptions = {},
76
94
  ): Promise<void> {
77
95
  const loadedConfig = await loadConfig(configPath);
96
+ const npxCommand = process.platform === "win32" ? "npx.cmd" : "npx";
97
+ const packageDir = findNearestPackageDir(process.cwd());
78
98
  const selectedTargetCount = [
79
99
  Boolean(options.local),
80
100
  Boolean(options.remote),
@@ -90,15 +110,16 @@ export async function runMigrate(
90
110
  "drizzle.config.ts",
91
111
  );
92
112
  const drizzleGenerate = Bun.spawn(
93
- ["npx", "drizzle-kit", "generate", "--config", drizzleConfigPath],
113
+ [npxCommand, "drizzle-kit", "generate", "--config", drizzleConfigPath],
94
114
  {
95
- cwd: loadedConfig.configDir,
115
+ cwd: packageDir,
96
116
  stdin: "inherit",
97
117
  stdout: "inherit",
98
118
  stderr: "inherit",
99
119
  },
100
120
  );
101
121
 
122
+ console.log(`npx drizzle-kit generate --config ${drizzleConfigPath}`);
102
123
  const drizzleExitCode = await drizzleGenerate.exited;
103
124
  if (drizzleExitCode !== 0) {
104
125
  throw new Error(
@@ -108,7 +129,7 @@ export async function runMigrate(
108
129
 
109
130
  const databaseName = loadedConfig.config.database[0].databaseName;
110
131
  const wranglerArgs = [
111
- "npx",
132
+ npxCommand,
112
133
  "wrangler",
113
134
  "d1",
114
135
  "migrations",
@@ -10,7 +10,7 @@ export class AppflareRealtimeDurableObject {
10
10
 
11
11
  if (request.method === "POST" && url.pathname === "/subscribe") {
12
12
  const payload = (await request.json().catch(() => null)) as RealtimeSubscription | null;
13
- if (!payload?.token || !payload.queryName || !payload.authToken) {
13
+ if (!payload?.token || !payload.queryName ) {
14
14
  return new Response(JSON.stringify({ message: "Invalid subscription payload" }), {
15
15
  status: 400,
16
16
  headers: { "content-type": "application/json" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appflare",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "bin": {
5
5
  "appflare": "./cli/index.ts"
6
6
  },