@korajs/cli 0.1.6 → 0.1.8
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.
- package/dist/bin.cjs +84 -73
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +50 -53
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-TZPACPP6.js → chunk-AUDUNRYA.js} +27 -11
- package/dist/chunk-AUDUNRYA.js.map +1 -0
- package/dist/create.cjs.map +1 -1
- package/dist/create.js +1 -1
- package/package.json +1 -1
- package/templates/react-basic/package.json.hbs +2 -0
- package/templates/react-basic/src/kora-worker.ts +3 -0
- package/templates/react-basic/src/main.tsx +7 -2
- package/templates/react-basic/vite.config.ts +3 -0
- package/templates/react-sync/package.json.hbs +2 -0
- package/templates/react-sync/src/kora-worker.ts +3 -0
- package/templates/react-sync/src/main.tsx +4 -1
- package/templates/react-sync/vite.config.ts +3 -0
- package/dist/chunk-TZPACPP6.js.map +0 -1
package/dist/bin.js
CHANGED
|
@@ -4,9 +4,10 @@ import {
|
|
|
4
4
|
createLogger,
|
|
5
5
|
findProjectRoot,
|
|
6
6
|
findSchemaFile,
|
|
7
|
+
hasTsxInstalled,
|
|
7
8
|
promptConfirm,
|
|
8
|
-
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
resolveProjectBinaryEntryPoint
|
|
10
|
+
} from "./chunk-AUDUNRYA.js";
|
|
10
11
|
import {
|
|
11
12
|
generateTypes
|
|
12
13
|
} from "./chunk-N36PFOSA.js";
|
|
@@ -21,7 +22,7 @@ import { defineCommand as defineCommand4, runMain } from "citty";
|
|
|
21
22
|
|
|
22
23
|
// src/commands/dev/dev-command.ts
|
|
23
24
|
import { access as access2 } from "fs/promises";
|
|
24
|
-
import { join as
|
|
25
|
+
import { join as join3 } from "path";
|
|
25
26
|
import { resolve } from "path";
|
|
26
27
|
import { defineCommand } from "citty";
|
|
27
28
|
|
|
@@ -61,14 +62,17 @@ async function findKoraConfigFile(projectRoot) {
|
|
|
61
62
|
return null;
|
|
62
63
|
}
|
|
63
64
|
async function loadTypeScriptConfig(configPath, projectRoot) {
|
|
64
|
-
|
|
65
|
-
if (!tsxBinary) {
|
|
65
|
+
if (!await hasTsxInstalled(projectRoot)) {
|
|
66
66
|
throw new Error(
|
|
67
67
|
`Found TypeScript config at ${configPath}, but "tsx" is not installed in this project. Install tsx or use kora.config.js.`
|
|
68
68
|
);
|
|
69
69
|
}
|
|
70
70
|
const script = "const configPath = process.argv[process.argv.length - 1];import('node:url').then(u => import(u.pathToFileURL(configPath).href)).then(mod => { const v = mod.default ?? mod; process.stdout.write(JSON.stringify(v)) }).catch(e => { process.stderr.write(String(e)); process.exit(1) })";
|
|
71
|
-
const output = await runCommand(
|
|
71
|
+
const output = await runCommand(
|
|
72
|
+
process.execPath,
|
|
73
|
+
["--import", "tsx", "--eval", script, configPath],
|
|
74
|
+
projectRoot
|
|
75
|
+
);
|
|
72
76
|
try {
|
|
73
77
|
return JSON.parse(output);
|
|
74
78
|
} catch {
|
|
@@ -80,8 +84,7 @@ async function runCommand(command, args, cwd) {
|
|
|
80
84
|
const child = spawn(command, args, {
|
|
81
85
|
cwd,
|
|
82
86
|
stdio: ["ignore", "pipe", "pipe"],
|
|
83
|
-
env: process.env
|
|
84
|
-
shell: process.platform === "win32"
|
|
87
|
+
env: process.env
|
|
85
88
|
});
|
|
86
89
|
let stdout = "";
|
|
87
90
|
let stderr = "";
|
|
@@ -122,9 +125,7 @@ var ProcessManager = class {
|
|
|
122
125
|
const options = {
|
|
123
126
|
cwd: config.cwd,
|
|
124
127
|
env: { ...process.env, ...config.env },
|
|
125
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
126
|
-
// On Windows, .cmd shims require shell to execute
|
|
127
|
-
shell: process.platform === "win32"
|
|
128
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
128
129
|
};
|
|
129
130
|
const child = spawnChild(config.command, config.args, options);
|
|
130
131
|
let resolveExit;
|
|
@@ -206,6 +207,7 @@ function delay(ms) {
|
|
|
206
207
|
// src/commands/dev/schema-watcher.ts
|
|
207
208
|
import { spawn as spawn2 } from "child_process";
|
|
208
209
|
import { watch } from "fs";
|
|
210
|
+
import { join as join2 } from "path";
|
|
209
211
|
var SchemaWatcher = class {
|
|
210
212
|
constructor(config) {
|
|
211
213
|
this.config = config;
|
|
@@ -233,16 +235,10 @@ var SchemaWatcher = class {
|
|
|
233
235
|
this.watcher = null;
|
|
234
236
|
}
|
|
235
237
|
async regenerate() {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const tsxBinary = await resolveProjectBinary(this.config.projectRoot, "tsx");
|
|
241
|
-
if (!tsxBinary) {
|
|
242
|
-
process.stderr.write('[kora] Could not find "tsx" binary. Falling back to node.\n');
|
|
243
|
-
}
|
|
244
|
-
const command = tsxBinary ?? process.execPath;
|
|
245
|
-
const args = [koraBinary, "generate", "types", "--schema", this.config.schemaPath];
|
|
238
|
+
const koraBinJs = join2(this.config.projectRoot, "node_modules", "@korajs", "cli", "dist", "bin.js");
|
|
239
|
+
const hasTsx = await hasTsxInstalled(this.config.projectRoot);
|
|
240
|
+
const command = process.execPath;
|
|
241
|
+
const args = hasTsx ? ["--import", "tsx", koraBinJs, "generate", "types", "--schema", this.config.schemaPath] : [koraBinJs, "generate", "types", "--schema", this.config.schemaPath];
|
|
246
242
|
await spawnCommand(command, args, this.config.projectRoot);
|
|
247
243
|
this.config.onRegenerate?.();
|
|
248
244
|
}
|
|
@@ -263,8 +259,7 @@ async function spawnCommand(command, args, cwd) {
|
|
|
263
259
|
const child = spawn2(command, args, {
|
|
264
260
|
cwd,
|
|
265
261
|
stdio: ["ignore", "pipe", "pipe"],
|
|
266
|
-
env: process.env
|
|
267
|
-
shell: process.platform === "win32"
|
|
262
|
+
env: process.env
|
|
268
263
|
});
|
|
269
264
|
child.stdout?.on("data", (chunk) => {
|
|
270
265
|
writePrefixedLines(chunk, false);
|
|
@@ -337,25 +332,25 @@ var devCommand = defineCommand({
|
|
|
337
332
|
const configSyncEnabled = config?.dev?.sync === void 0 || config.dev.sync === true || typeof config.dev.sync === "object" && config.dev.sync.enabled !== false;
|
|
338
333
|
const configWatchEnabled = config?.dev?.watch === void 0 || config.dev.watch === true || typeof config.dev.watch === "object" && config.dev.watch.enabled !== false;
|
|
339
334
|
const watchDebounceMs = typeof config?.dev?.watch === "object" && typeof config.dev.watch.debounceMs === "number" ? config.dev.watch.debounceMs : 300;
|
|
340
|
-
const
|
|
341
|
-
if (!
|
|
342
|
-
throw new DevServerError("vite",
|
|
335
|
+
const viteEntryPoint = await resolveProjectBinaryEntryPoint(projectRoot, "vite", "vite");
|
|
336
|
+
if (!viteEntryPoint) {
|
|
337
|
+
throw new DevServerError("vite", join3(projectRoot, "node_modules", ".bin", "vite"));
|
|
343
338
|
}
|
|
344
339
|
const syncServerFile = await findSyncServerFile(projectRoot);
|
|
345
340
|
let managedSyncStore = normalizeManagedSyncStore(config, projectRoot);
|
|
346
341
|
const postgresEnvRequested = isPostgresEnvRequested(config);
|
|
347
342
|
const syncAllowed = args["no-sync"] !== true && configSyncEnabled;
|
|
348
343
|
let shouldStartSync = syncAllowed && (syncServerFile !== null || managedSyncStore !== null);
|
|
349
|
-
let
|
|
344
|
+
let hasTsx = false;
|
|
350
345
|
if (shouldStartSync && syncServerFile !== null) {
|
|
351
|
-
|
|
352
|
-
if (!
|
|
353
|
-
logger.warn('Sync server detected, but
|
|
346
|
+
hasTsx = await hasTsxInstalled(projectRoot);
|
|
347
|
+
if (!hasTsx) {
|
|
348
|
+
logger.warn('Sync server detected, but "tsx" is not installed. Skipping sync.');
|
|
354
349
|
}
|
|
355
350
|
}
|
|
356
351
|
if (shouldStartSync && syncServerFile === null && managedSyncStore) {
|
|
357
352
|
const hasServerPackage = await fileExists(
|
|
358
|
-
|
|
353
|
+
join3(projectRoot, "node_modules", "@korajs", "server", "package.json")
|
|
359
354
|
);
|
|
360
355
|
if (!hasServerPackage) {
|
|
361
356
|
logger.warn(
|
|
@@ -412,7 +407,7 @@ var devCommand = defineCommand({
|
|
|
412
407
|
logger.info("Starting development environment:");
|
|
413
408
|
logger.blank();
|
|
414
409
|
logger.step(` Vite dev server on port ${vitePort}`);
|
|
415
|
-
if (shouldStartSync &&
|
|
410
|
+
if (shouldStartSync && hasTsx && syncServerFile) {
|
|
416
411
|
logger.step(` Sync server on port ${syncPort}`);
|
|
417
412
|
} else if (shouldStartSync && syncServerFile === null && managedSyncStore !== null) {
|
|
418
413
|
logger.step(` Managed sync server on port ${syncPort} (${managedSyncStore.type})`);
|
|
@@ -431,16 +426,16 @@ var devCommand = defineCommand({
|
|
|
431
426
|
logger.blank();
|
|
432
427
|
processManager.spawn({
|
|
433
428
|
label: "vite",
|
|
434
|
-
command:
|
|
435
|
-
args: ["--port", String(vitePort)],
|
|
429
|
+
command: process.execPath,
|
|
430
|
+
args: [viteEntryPoint, "--port", String(vitePort)],
|
|
436
431
|
cwd: projectRoot,
|
|
437
432
|
onExit: onManagedProcessExit
|
|
438
433
|
});
|
|
439
|
-
if (shouldStartSync &&
|
|
434
|
+
if (shouldStartSync && hasTsx && syncServerFile) {
|
|
440
435
|
processManager.spawn({
|
|
441
436
|
label: "sync",
|
|
442
|
-
command:
|
|
443
|
-
args: [syncServerFile],
|
|
437
|
+
command: process.execPath,
|
|
438
|
+
args: ["--import", "tsx", syncServerFile],
|
|
444
439
|
cwd: projectRoot,
|
|
445
440
|
env: {
|
|
446
441
|
PORT: String(syncPort),
|
|
@@ -484,7 +479,7 @@ var devCommand = defineCommand({
|
|
|
484
479
|
}
|
|
485
480
|
});
|
|
486
481
|
async function findSyncServerFile(projectRoot) {
|
|
487
|
-
const candidates = [
|
|
482
|
+
const candidates = [join3(projectRoot, "server.ts"), join3(projectRoot, "server.js")];
|
|
488
483
|
for (const candidate of candidates) {
|
|
489
484
|
try {
|
|
490
485
|
await access2(candidate);
|
|
@@ -508,7 +503,7 @@ function normalizeManagedSyncStore(config, projectRoot) {
|
|
|
508
503
|
const store = sync.store;
|
|
509
504
|
if (store === void 0) return { type: "memory" };
|
|
510
505
|
if (store === "memory") return { type: "memory" };
|
|
511
|
-
if (store === "sqlite") return { type: "sqlite", filename:
|
|
506
|
+
if (store === "sqlite") return { type: "sqlite", filename: join3(projectRoot, "kora-sync.db") };
|
|
512
507
|
if (store === "postgres") {
|
|
513
508
|
const connectionString = process.env.DATABASE_URL;
|
|
514
509
|
if (!connectionString) return null;
|
|
@@ -517,7 +512,7 @@ function normalizeManagedSyncStore(config, projectRoot) {
|
|
|
517
512
|
if (typeof store === "object" && store !== null) {
|
|
518
513
|
if (store.type === "memory") return { type: "memory" };
|
|
519
514
|
if (store.type === "sqlite") {
|
|
520
|
-
const filename = typeof store.filename === "string" && store.filename.length > 0 ? resolve(projectRoot, store.filename) :
|
|
515
|
+
const filename = typeof store.filename === "string" && store.filename.length > 0 ? resolve(projectRoot, store.filename) : join3(projectRoot, "kora-sync.db");
|
|
521
516
|
return { type: "sqlite", filename };
|
|
522
517
|
}
|
|
523
518
|
if (store.type === "postgres" && typeof store.connectionString === "string") {
|
|
@@ -659,7 +654,7 @@ function isSchemaDefinition(value) {
|
|
|
659
654
|
|
|
660
655
|
// src/commands/migrate/migrate-command.ts
|
|
661
656
|
import { mkdir as mkdir2, readFile, readdir, writeFile as writeFile2 } from "fs/promises";
|
|
662
|
-
import { dirname as dirname2, join as
|
|
657
|
+
import { dirname as dirname2, join as join4, resolve as resolve3 } from "path";
|
|
663
658
|
import { defineCommand as defineCommand3 } from "citty";
|
|
664
659
|
|
|
665
660
|
// src/commands/migrate/migration-generator.ts
|
|
@@ -1252,14 +1247,17 @@ function isSchemaDefinition2(value) {
|
|
|
1252
1247
|
return typeof object.version === "number" && typeof object.collections === "object" && object.collections !== null && typeof object.relations === "object" && object.relations !== null;
|
|
1253
1248
|
}
|
|
1254
1249
|
async function loadTypeScriptModule(schemaPath, projectRoot) {
|
|
1255
|
-
|
|
1256
|
-
if (!tsxBinary) {
|
|
1250
|
+
if (!await hasTsxInstalled(projectRoot)) {
|
|
1257
1251
|
throw new Error(
|
|
1258
1252
|
`Schema file is TypeScript (${schemaPath}) but local "tsx" was not found. Install tsx in the project.`
|
|
1259
1253
|
);
|
|
1260
1254
|
}
|
|
1261
1255
|
const script = "const modulePath = process.argv[process.argv.length - 1];import('node:url').then(u => import(u.pathToFileURL(modulePath).href)).then(mod => { const v = mod.default ?? mod; process.stdout.write(JSON.stringify(v)) }).catch(e => { process.stderr.write(String(e)); process.exit(1) })";
|
|
1262
|
-
const output = await runCommand2(
|
|
1256
|
+
const output = await runCommand2(
|
|
1257
|
+
process.execPath,
|
|
1258
|
+
["--import", "tsx", "--eval", script, schemaPath],
|
|
1259
|
+
projectRoot
|
|
1260
|
+
);
|
|
1263
1261
|
try {
|
|
1264
1262
|
return JSON.parse(output);
|
|
1265
1263
|
} catch {
|
|
@@ -1271,8 +1269,7 @@ async function runCommand2(command, args, cwd) {
|
|
|
1271
1269
|
const child = spawn3(command, args, {
|
|
1272
1270
|
cwd,
|
|
1273
1271
|
stdio: ["ignore", "pipe", "pipe"],
|
|
1274
|
-
env: process.env
|
|
1275
|
-
shell: process.platform === "win32"
|
|
1272
|
+
env: process.env
|
|
1276
1273
|
});
|
|
1277
1274
|
let stdout = "";
|
|
1278
1275
|
let stderr = "";
|
|
@@ -1347,7 +1344,7 @@ var migrateCommand = defineCommand3({
|
|
|
1347
1344
|
throw new SchemaNotFoundError(["src/schema.ts", "schema.ts", "src/schema.js", "schema.js"]);
|
|
1348
1345
|
}
|
|
1349
1346
|
const currentSchema = await loadSchemaDefinition(resolvedSchemaPath, projectRoot);
|
|
1350
|
-
const snapshotFile =
|
|
1347
|
+
const snapshotFile = join4(projectRoot, SNAPSHOT_PATH);
|
|
1351
1348
|
const previousSchema = await readSchemaSnapshot(snapshotFile);
|
|
1352
1349
|
if (!previousSchema) {
|
|
1353
1350
|
if (args["dry-run"] === true) {
|
|
@@ -1472,7 +1469,7 @@ async function writeMigrationFile(outputDir, fromVersion, toVersion, generated)
|
|
|
1472
1469
|
const existing = await readdir(outputDir).catch(() => []);
|
|
1473
1470
|
const sequence = existing.filter((file) => /^\d{3}-/.test(file)).length + 1;
|
|
1474
1471
|
const filename = `${String(sequence).padStart(3, "0")}-v${fromVersion}-to-v${toVersion}.ts`;
|
|
1475
|
-
const path =
|
|
1472
|
+
const path = join4(outputDir, filename);
|
|
1476
1473
|
const migrationId = filename.replace(/\.ts$/, "");
|
|
1477
1474
|
const fileContent = [
|
|
1478
1475
|
`export const up = ${JSON.stringify(generated.up, null, 2)} as const`,
|
|
@@ -1485,7 +1482,7 @@ async function writeMigrationFile(outputDir, fromVersion, toVersion, generated)
|
|
|
1485
1482
|
""
|
|
1486
1483
|
].join("\n");
|
|
1487
1484
|
await writeFile2(path, fileContent, "utf-8");
|
|
1488
|
-
await writeMigrationManifest(
|
|
1485
|
+
await writeMigrationManifest(join4(outputDir, `${migrationId}.json`), {
|
|
1489
1486
|
id: migrationId,
|
|
1490
1487
|
fromVersion,
|
|
1491
1488
|
toVersion,
|
|
@@ -1506,13 +1503,13 @@ async function listMigrationManifests(outputDir) {
|
|
|
1506
1503
|
const manifests = [];
|
|
1507
1504
|
for (const file of migrationFiles) {
|
|
1508
1505
|
const id = file.replace(/\.ts$/, "");
|
|
1509
|
-
const manifestPath =
|
|
1506
|
+
const manifestPath = join4(outputDir, `${id}.json`);
|
|
1510
1507
|
const jsonManifest = await readMigrationManifest(manifestPath);
|
|
1511
1508
|
if (jsonManifest) {
|
|
1512
1509
|
manifests.push({ ...jsonManifest, id });
|
|
1513
1510
|
continue;
|
|
1514
1511
|
}
|
|
1515
|
-
const migrationPath =
|
|
1512
|
+
const migrationPath = join4(outputDir, file);
|
|
1516
1513
|
const sourceManifest = await readMigrationManifestFromSource(migrationPath, id);
|
|
1517
1514
|
manifests.push(sourceManifest);
|
|
1518
1515
|
}
|
|
@@ -1593,13 +1590,13 @@ function resolveSqliteApplyPath(dbArg, projectRoot, config) {
|
|
|
1593
1590
|
const sync = config?.dev?.sync;
|
|
1594
1591
|
if (typeof sync === "object" && sync !== null) {
|
|
1595
1592
|
if (sync.store === "sqlite") {
|
|
1596
|
-
return
|
|
1593
|
+
return join4(projectRoot, "kora-sync.db");
|
|
1597
1594
|
}
|
|
1598
1595
|
if (typeof sync.store === "object" && sync.store !== null && sync.store.type === "sqlite") {
|
|
1599
1596
|
if (typeof sync.store.filename === "string" && sync.store.filename.length > 0) {
|
|
1600
1597
|
return resolve3(projectRoot, sync.store.filename);
|
|
1601
1598
|
}
|
|
1602
|
-
return
|
|
1599
|
+
return join4(projectRoot, "kora-sync.db");
|
|
1603
1600
|
}
|
|
1604
1601
|
}
|
|
1605
1602
|
return void 0;
|