@korajs/cli 0.1.5 → 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 +83 -81
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +49 -61
- 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,20 +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
|
-
const script = [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
].join(";");
|
|
77
|
-
const output = await runCommand(tsxBinary, ["--eval", script, configPath], projectRoot);
|
|
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(
|
|
72
|
+
process.execPath,
|
|
73
|
+
["--import", "tsx", "--eval", script, configPath],
|
|
74
|
+
projectRoot
|
|
75
|
+
);
|
|
78
76
|
try {
|
|
79
77
|
return JSON.parse(output);
|
|
80
78
|
} catch {
|
|
@@ -127,9 +125,7 @@ var ProcessManager = class {
|
|
|
127
125
|
const options = {
|
|
128
126
|
cwd: config.cwd,
|
|
129
127
|
env: { ...process.env, ...config.env },
|
|
130
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
131
|
-
// On Windows, .cmd shims require shell to execute
|
|
132
|
-
shell: process.platform === "win32"
|
|
128
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
133
129
|
};
|
|
134
130
|
const child = spawnChild(config.command, config.args, options);
|
|
135
131
|
let resolveExit;
|
|
@@ -211,6 +207,7 @@ function delay(ms) {
|
|
|
211
207
|
// src/commands/dev/schema-watcher.ts
|
|
212
208
|
import { spawn as spawn2 } from "child_process";
|
|
213
209
|
import { watch } from "fs";
|
|
210
|
+
import { join as join2 } from "path";
|
|
214
211
|
var SchemaWatcher = class {
|
|
215
212
|
constructor(config) {
|
|
216
213
|
this.config = config;
|
|
@@ -238,16 +235,10 @@ var SchemaWatcher = class {
|
|
|
238
235
|
this.watcher = null;
|
|
239
236
|
}
|
|
240
237
|
async regenerate() {
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const tsxBinary = await resolveProjectBinary(this.config.projectRoot, "tsx");
|
|
246
|
-
if (!tsxBinary) {
|
|
247
|
-
process.stderr.write('[kora] Could not find "tsx" binary. Falling back to node.\n');
|
|
248
|
-
}
|
|
249
|
-
const command = tsxBinary ?? process.execPath;
|
|
250
|
-
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];
|
|
251
242
|
await spawnCommand(command, args, this.config.projectRoot);
|
|
252
243
|
this.config.onRegenerate?.();
|
|
253
244
|
}
|
|
@@ -341,25 +332,25 @@ var devCommand = defineCommand({
|
|
|
341
332
|
const configSyncEnabled = config?.dev?.sync === void 0 || config.dev.sync === true || typeof config.dev.sync === "object" && config.dev.sync.enabled !== false;
|
|
342
333
|
const configWatchEnabled = config?.dev?.watch === void 0 || config.dev.watch === true || typeof config.dev.watch === "object" && config.dev.watch.enabled !== false;
|
|
343
334
|
const watchDebounceMs = typeof config?.dev?.watch === "object" && typeof config.dev.watch.debounceMs === "number" ? config.dev.watch.debounceMs : 300;
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
346
|
-
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"));
|
|
347
338
|
}
|
|
348
339
|
const syncServerFile = await findSyncServerFile(projectRoot);
|
|
349
340
|
let managedSyncStore = normalizeManagedSyncStore(config, projectRoot);
|
|
350
341
|
const postgresEnvRequested = isPostgresEnvRequested(config);
|
|
351
342
|
const syncAllowed = args["no-sync"] !== true && configSyncEnabled;
|
|
352
343
|
let shouldStartSync = syncAllowed && (syncServerFile !== null || managedSyncStore !== null);
|
|
353
|
-
let
|
|
344
|
+
let hasTsx = false;
|
|
354
345
|
if (shouldStartSync && syncServerFile !== null) {
|
|
355
|
-
|
|
356
|
-
if (!
|
|
357
|
-
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.');
|
|
358
349
|
}
|
|
359
350
|
}
|
|
360
351
|
if (shouldStartSync && syncServerFile === null && managedSyncStore) {
|
|
361
352
|
const hasServerPackage = await fileExists(
|
|
362
|
-
|
|
353
|
+
join3(projectRoot, "node_modules", "@korajs", "server", "package.json")
|
|
363
354
|
);
|
|
364
355
|
if (!hasServerPackage) {
|
|
365
356
|
logger.warn(
|
|
@@ -416,7 +407,7 @@ var devCommand = defineCommand({
|
|
|
416
407
|
logger.info("Starting development environment:");
|
|
417
408
|
logger.blank();
|
|
418
409
|
logger.step(` Vite dev server on port ${vitePort}`);
|
|
419
|
-
if (shouldStartSync &&
|
|
410
|
+
if (shouldStartSync && hasTsx && syncServerFile) {
|
|
420
411
|
logger.step(` Sync server on port ${syncPort}`);
|
|
421
412
|
} else if (shouldStartSync && syncServerFile === null && managedSyncStore !== null) {
|
|
422
413
|
logger.step(` Managed sync server on port ${syncPort} (${managedSyncStore.type})`);
|
|
@@ -435,16 +426,16 @@ var devCommand = defineCommand({
|
|
|
435
426
|
logger.blank();
|
|
436
427
|
processManager.spawn({
|
|
437
428
|
label: "vite",
|
|
438
|
-
command:
|
|
439
|
-
args: ["--port", String(vitePort)],
|
|
429
|
+
command: process.execPath,
|
|
430
|
+
args: [viteEntryPoint, "--port", String(vitePort)],
|
|
440
431
|
cwd: projectRoot,
|
|
441
432
|
onExit: onManagedProcessExit
|
|
442
433
|
});
|
|
443
|
-
if (shouldStartSync &&
|
|
434
|
+
if (shouldStartSync && hasTsx && syncServerFile) {
|
|
444
435
|
processManager.spawn({
|
|
445
436
|
label: "sync",
|
|
446
|
-
command:
|
|
447
|
-
args: [syncServerFile],
|
|
437
|
+
command: process.execPath,
|
|
438
|
+
args: ["--import", "tsx", syncServerFile],
|
|
448
439
|
cwd: projectRoot,
|
|
449
440
|
env: {
|
|
450
441
|
PORT: String(syncPort),
|
|
@@ -488,7 +479,7 @@ var devCommand = defineCommand({
|
|
|
488
479
|
}
|
|
489
480
|
});
|
|
490
481
|
async function findSyncServerFile(projectRoot) {
|
|
491
|
-
const candidates = [
|
|
482
|
+
const candidates = [join3(projectRoot, "server.ts"), join3(projectRoot, "server.js")];
|
|
492
483
|
for (const candidate of candidates) {
|
|
493
484
|
try {
|
|
494
485
|
await access2(candidate);
|
|
@@ -512,7 +503,7 @@ function normalizeManagedSyncStore(config, projectRoot) {
|
|
|
512
503
|
const store = sync.store;
|
|
513
504
|
if (store === void 0) return { type: "memory" };
|
|
514
505
|
if (store === "memory") return { type: "memory" };
|
|
515
|
-
if (store === "sqlite") return { type: "sqlite", filename:
|
|
506
|
+
if (store === "sqlite") return { type: "sqlite", filename: join3(projectRoot, "kora-sync.db") };
|
|
516
507
|
if (store === "postgres") {
|
|
517
508
|
const connectionString = process.env.DATABASE_URL;
|
|
518
509
|
if (!connectionString) return null;
|
|
@@ -521,7 +512,7 @@ function normalizeManagedSyncStore(config, projectRoot) {
|
|
|
521
512
|
if (typeof store === "object" && store !== null) {
|
|
522
513
|
if (store.type === "memory") return { type: "memory" };
|
|
523
514
|
if (store.type === "sqlite") {
|
|
524
|
-
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");
|
|
525
516
|
return { type: "sqlite", filename };
|
|
526
517
|
}
|
|
527
518
|
if (store.type === "postgres" && typeof store.connectionString === "string") {
|
|
@@ -663,7 +654,7 @@ function isSchemaDefinition(value) {
|
|
|
663
654
|
|
|
664
655
|
// src/commands/migrate/migrate-command.ts
|
|
665
656
|
import { mkdir as mkdir2, readFile, readdir, writeFile as writeFile2 } from "fs/promises";
|
|
666
|
-
import { dirname as dirname2, join as
|
|
657
|
+
import { dirname as dirname2, join as join4, resolve as resolve3 } from "path";
|
|
667
658
|
import { defineCommand as defineCommand3 } from "citty";
|
|
668
659
|
|
|
669
660
|
// src/commands/migrate/migration-generator.ts
|
|
@@ -1256,20 +1247,17 @@ function isSchemaDefinition2(value) {
|
|
|
1256
1247
|
return typeof object.version === "number" && typeof object.collections === "object" && object.collections !== null && typeof object.relations === "object" && object.relations !== null;
|
|
1257
1248
|
}
|
|
1258
1249
|
async function loadTypeScriptModule(schemaPath, projectRoot) {
|
|
1259
|
-
|
|
1260
|
-
if (!tsxBinary) {
|
|
1250
|
+
if (!await hasTsxInstalled(projectRoot)) {
|
|
1261
1251
|
throw new Error(
|
|
1262
1252
|
`Schema file is TypeScript (${schemaPath}) but local "tsx" was not found. Install tsx in the project.`
|
|
1263
1253
|
);
|
|
1264
1254
|
}
|
|
1265
|
-
const script = [
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
"
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
].join(";");
|
|
1272
|
-
const output = await runCommand2(tsxBinary, ["--eval", script, schemaPath], projectRoot);
|
|
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) })";
|
|
1256
|
+
const output = await runCommand2(
|
|
1257
|
+
process.execPath,
|
|
1258
|
+
["--import", "tsx", "--eval", script, schemaPath],
|
|
1259
|
+
projectRoot
|
|
1260
|
+
);
|
|
1273
1261
|
try {
|
|
1274
1262
|
return JSON.parse(output);
|
|
1275
1263
|
} catch {
|
|
@@ -1356,7 +1344,7 @@ var migrateCommand = defineCommand3({
|
|
|
1356
1344
|
throw new SchemaNotFoundError(["src/schema.ts", "schema.ts", "src/schema.js", "schema.js"]);
|
|
1357
1345
|
}
|
|
1358
1346
|
const currentSchema = await loadSchemaDefinition(resolvedSchemaPath, projectRoot);
|
|
1359
|
-
const snapshotFile =
|
|
1347
|
+
const snapshotFile = join4(projectRoot, SNAPSHOT_PATH);
|
|
1360
1348
|
const previousSchema = await readSchemaSnapshot(snapshotFile);
|
|
1361
1349
|
if (!previousSchema) {
|
|
1362
1350
|
if (args["dry-run"] === true) {
|
|
@@ -1481,7 +1469,7 @@ async function writeMigrationFile(outputDir, fromVersion, toVersion, generated)
|
|
|
1481
1469
|
const existing = await readdir(outputDir).catch(() => []);
|
|
1482
1470
|
const sequence = existing.filter((file) => /^\d{3}-/.test(file)).length + 1;
|
|
1483
1471
|
const filename = `${String(sequence).padStart(3, "0")}-v${fromVersion}-to-v${toVersion}.ts`;
|
|
1484
|
-
const path =
|
|
1472
|
+
const path = join4(outputDir, filename);
|
|
1485
1473
|
const migrationId = filename.replace(/\.ts$/, "");
|
|
1486
1474
|
const fileContent = [
|
|
1487
1475
|
`export const up = ${JSON.stringify(generated.up, null, 2)} as const`,
|
|
@@ -1494,7 +1482,7 @@ async function writeMigrationFile(outputDir, fromVersion, toVersion, generated)
|
|
|
1494
1482
|
""
|
|
1495
1483
|
].join("\n");
|
|
1496
1484
|
await writeFile2(path, fileContent, "utf-8");
|
|
1497
|
-
await writeMigrationManifest(
|
|
1485
|
+
await writeMigrationManifest(join4(outputDir, `${migrationId}.json`), {
|
|
1498
1486
|
id: migrationId,
|
|
1499
1487
|
fromVersion,
|
|
1500
1488
|
toVersion,
|
|
@@ -1515,13 +1503,13 @@ async function listMigrationManifests(outputDir) {
|
|
|
1515
1503
|
const manifests = [];
|
|
1516
1504
|
for (const file of migrationFiles) {
|
|
1517
1505
|
const id = file.replace(/\.ts$/, "");
|
|
1518
|
-
const manifestPath =
|
|
1506
|
+
const manifestPath = join4(outputDir, `${id}.json`);
|
|
1519
1507
|
const jsonManifest = await readMigrationManifest(manifestPath);
|
|
1520
1508
|
if (jsonManifest) {
|
|
1521
1509
|
manifests.push({ ...jsonManifest, id });
|
|
1522
1510
|
continue;
|
|
1523
1511
|
}
|
|
1524
|
-
const migrationPath =
|
|
1512
|
+
const migrationPath = join4(outputDir, file);
|
|
1525
1513
|
const sourceManifest = await readMigrationManifestFromSource(migrationPath, id);
|
|
1526
1514
|
manifests.push(sourceManifest);
|
|
1527
1515
|
}
|
|
@@ -1602,13 +1590,13 @@ function resolveSqliteApplyPath(dbArg, projectRoot, config) {
|
|
|
1602
1590
|
const sync = config?.dev?.sync;
|
|
1603
1591
|
if (typeof sync === "object" && sync !== null) {
|
|
1604
1592
|
if (sync.store === "sqlite") {
|
|
1605
|
-
return
|
|
1593
|
+
return join4(projectRoot, "kora-sync.db");
|
|
1606
1594
|
}
|
|
1607
1595
|
if (typeof sync.store === "object" && sync.store !== null && sync.store.type === "sqlite") {
|
|
1608
1596
|
if (typeof sync.store.filename === "string" && sync.store.filename.length > 0) {
|
|
1609
1597
|
return resolve3(projectRoot, sync.store.filename);
|
|
1610
1598
|
}
|
|
1611
|
-
return
|
|
1599
|
+
return join4(projectRoot, "kora-sync.db");
|
|
1612
1600
|
}
|
|
1613
1601
|
}
|
|
1614
1602
|
return void 0;
|