@orion-js/core 4.3.3 → 4.4.1
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/LICENSE +21 -0
- package/dist/build/build.d.ts +3 -0
- package/dist/build/checkTs.d.ts +1 -0
- package/dist/build/index.d.ts +3 -0
- package/dist/check/checkTs.d.ts +1 -0
- package/dist/check/index.d.ts +1 -0
- package/dist/create/index.d.ts +4 -0
- package/dist/dev/devBuildPath.d.ts +1 -0
- package/dist/dev/index.d.ts +2 -0
- package/dist/dev/runner/getArgs.d.ts +5 -0
- package/dist/dev/runner/index.d.ts +13 -0
- package/dist/dev/runner/startProcess.d.ts +2 -0
- package/dist/dev/watchAndCompile/cleanDirectory.d.ts +1 -0
- package/dist/dev/watchAndCompile/ensureConfigComplies.d.ts +1 -0
- package/dist/dev/watchAndCompile/getConfigPath.d.ts +1 -0
- package/dist/dev/watchAndCompile/index.d.ts +2 -0
- package/dist/dev/watchAndCompile/watchAndBundle.d.ts +25 -0
- package/dist/dev/watchAndCompile/watchAndTypecheck.d.ts +11 -0
- package/dist/dev/watchAndCompile/writeEnvFile.d.ts +2 -0
- package/dist/handleErrors.d.ts +1 -0
- package/dist/helpers/ensureDirectory.d.ts +2 -0
- package/dist/helpers/execute.d.ts +1 -0
- package/dist/helpers/getFileContents.d.ts +1 -0
- package/dist/helpers/writeFile.d.ts +1 -0
- package/dist/index.cjs +258 -132
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +246 -120
- package/dist/index.js.map +1 -1
- package/dist/info.d.ts +1 -0
- package/dist/prod/index.d.ts +5 -0
- package/dist/prod/runProd.d.ts +2 -0
- package/dist/repl/index.d.ts +5 -0
- package/dist/version.d.ts +2 -0
- package/package.json +12 -13
- package/dist/index.d.cts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
|
|
25
25
|
// src/index.ts
|
|
26
|
-
var
|
|
26
|
+
var import_chalk14 = __toESM(require("chalk"), 1);
|
|
27
27
|
var import_commander = require("commander");
|
|
28
28
|
|
|
29
29
|
// src/helpers/execute.ts
|
|
@@ -56,7 +56,7 @@ async function create_default({ name, kit }) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/dev/index.ts
|
|
59
|
-
var
|
|
59
|
+
var import_chalk4 = __toESM(require("chalk"), 1);
|
|
60
60
|
|
|
61
61
|
// src/dev/runner/index.ts
|
|
62
62
|
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
@@ -68,10 +68,10 @@ var import_node_fs2 = __toESM(require("fs"), 1);
|
|
|
68
68
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
69
69
|
var import_node_path = __toESM(require("path"), 1);
|
|
70
70
|
var ensureDirectory = (filePath) => {
|
|
71
|
-
const
|
|
72
|
-
if (import_node_fs.default.existsSync(
|
|
73
|
-
ensureDirectory(
|
|
74
|
-
import_node_fs.default.mkdirSync(
|
|
71
|
+
const dirname3 = import_node_path.default.dirname(filePath);
|
|
72
|
+
if (import_node_fs.default.existsSync(dirname3)) return true;
|
|
73
|
+
ensureDirectory(dirname3);
|
|
74
|
+
import_node_fs.default.mkdirSync(dirname3);
|
|
75
75
|
};
|
|
76
76
|
var ensureDirectory_default = ensureDirectory;
|
|
77
77
|
|
|
@@ -85,15 +85,18 @@ async function writeFile_default(path3, content) {
|
|
|
85
85
|
var import_node_child_process2 = require("child_process");
|
|
86
86
|
var import_chalk = __toESM(require("chalk"), 1);
|
|
87
87
|
|
|
88
|
+
// src/dev/devBuildPath.ts
|
|
89
|
+
var devBuildPath = "./.orion/build/index.js";
|
|
90
|
+
|
|
88
91
|
// src/dev/runner/getArgs.ts
|
|
89
92
|
function getArgs(options, command) {
|
|
90
93
|
if (options.node) {
|
|
91
|
-
const startCommand2 = "
|
|
92
|
-
const args2 = ["
|
|
94
|
+
const startCommand2 = "node";
|
|
95
|
+
const args2 = ["--enable-source-maps", ...command.args, devBuildPath];
|
|
93
96
|
return { startCommand: startCommand2, args: args2 };
|
|
94
97
|
}
|
|
95
98
|
const startCommand = "bun";
|
|
96
|
-
const args = ["--watch", ...command.args,
|
|
99
|
+
const args = ["--watch", ...command.args, devBuildPath];
|
|
97
100
|
return { startCommand, args };
|
|
98
101
|
}
|
|
99
102
|
|
|
@@ -121,14 +124,16 @@ function getRunner(options, command) {
|
|
|
121
124
|
console.log(import_chalk2.default.bold("=> Cleaning directory...\n"));
|
|
122
125
|
}
|
|
123
126
|
const startApp = () => {
|
|
124
|
-
|
|
125
|
-
appProcess
|
|
127
|
+
const startedProcess = startProcess(options, command);
|
|
128
|
+
appProcess = startedProcess;
|
|
129
|
+
startedProcess.on("exit", (code, signal) => {
|
|
130
|
+
if (appProcess === startedProcess) appProcess = null;
|
|
126
131
|
if (!code || code === 143 || code === 0 || signal === "SIGTERM" || signal === "SIGINT") {
|
|
127
132
|
} else {
|
|
128
133
|
console.log(import_chalk2.default.bold(`=> Error running app. Exit code: ${code}`));
|
|
129
134
|
}
|
|
130
135
|
});
|
|
131
|
-
writeFile_default(".orion/process", `${
|
|
136
|
+
writeFile_default(".orion/process", `${startedProcess.pid}`);
|
|
132
137
|
};
|
|
133
138
|
const stop = () => {
|
|
134
139
|
if (appProcess) {
|
|
@@ -154,9 +159,6 @@ function getRunner(options, command) {
|
|
|
154
159
|
};
|
|
155
160
|
}
|
|
156
161
|
|
|
157
|
-
// src/dev/watchAndCompile/index.ts
|
|
158
|
-
var import_typescript4 = __toESM(require("typescript"), 1);
|
|
159
|
-
|
|
160
162
|
// src/dev/watchAndCompile/cleanDirectory.ts
|
|
161
163
|
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
162
164
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
@@ -181,20 +183,129 @@ async function cleanDirectory(directory) {
|
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
// src/dev/watchAndCompile/
|
|
185
|
-
var
|
|
186
|
+
// src/dev/watchAndCompile/watchAndBundle.ts
|
|
187
|
+
var import_node_fs4 = require("fs");
|
|
188
|
+
var import_node_module = require("module");
|
|
189
|
+
var import_node_path3 = require("path");
|
|
190
|
+
var import_chokidar = __toESM(require("chokidar"), 1);
|
|
191
|
+
var esbuild = __toESM(require("esbuild"), 1);
|
|
192
|
+
function getPackageName(specifier) {
|
|
193
|
+
const segments = specifier.split("/");
|
|
194
|
+
return specifier.startsWith("@") ? segments.slice(0, 2).join("/") : segments[0];
|
|
195
|
+
}
|
|
196
|
+
function nodeExternalCompatibilityPlugin() {
|
|
197
|
+
const requireFromApp = (0, import_node_module.createRequire)((0, import_node_path3.join)(process.cwd(), "package.json"));
|
|
198
|
+
return {
|
|
199
|
+
name: "orion-node-external-compatibility",
|
|
200
|
+
setup(build3) {
|
|
201
|
+
build3.onResolve({ filter: /^[^./].*\.json$/ }, (args) => {
|
|
202
|
+
try {
|
|
203
|
+
return { path: requireFromApp.resolve(args.path) };
|
|
204
|
+
} catch {
|
|
205
|
+
return void 0;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
build3.onResolve({ filter: /^[^./]/ }, (args) => {
|
|
209
|
+
const packageName = getPackageName(args.path);
|
|
210
|
+
if (args.path === packageName || (0, import_node_path3.extname)(args.path)) return void 0;
|
|
211
|
+
try {
|
|
212
|
+
const packageJsonPath = requireFromApp.resolve(`${packageName}/package.json`);
|
|
213
|
+
const packageJson = JSON.parse((0, import_node_fs4.readFileSync)(packageJsonPath, "utf8"));
|
|
214
|
+
if (packageJson.exports) return void 0;
|
|
215
|
+
const resolvedExtension = (0, import_node_path3.extname)(requireFromApp.resolve(args.path));
|
|
216
|
+
if (!resolvedExtension) return void 0;
|
|
217
|
+
return { path: `${args.path}${resolvedExtension}`, external: true };
|
|
218
|
+
} catch {
|
|
219
|
+
return void 0;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
async function watchAndBundle(runner, options, onFilesChanged) {
|
|
226
|
+
let hasSuccessfulBuild = false;
|
|
227
|
+
let buildStartedAt = Date.now();
|
|
228
|
+
let rebuildInProgress = false;
|
|
229
|
+
let rebuildRequested = false;
|
|
230
|
+
let rebuildTimer;
|
|
231
|
+
const context2 = await esbuild.context({
|
|
232
|
+
entryPoints: ["./app/index.ts"],
|
|
233
|
+
outfile: devBuildPath,
|
|
234
|
+
tsconfig: "./tsconfig.json",
|
|
235
|
+
format: "esm",
|
|
236
|
+
platform: "node",
|
|
237
|
+
bundle: true,
|
|
238
|
+
target: "node22",
|
|
239
|
+
sourcemap: true,
|
|
240
|
+
packages: "external",
|
|
241
|
+
plugins: [
|
|
242
|
+
nodeExternalCompatibilityPlugin(),
|
|
243
|
+
{
|
|
244
|
+
name: "orion-dev-restart",
|
|
245
|
+
setup(build3) {
|
|
246
|
+
build3.onStart(() => {
|
|
247
|
+
buildStartedAt = Date.now();
|
|
248
|
+
});
|
|
249
|
+
build3.onEnd((result) => {
|
|
250
|
+
if (result.errors.length > 0) {
|
|
251
|
+
runner.stop();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
console.log(`=> Application bundled in ${Date.now() - buildStartedAt}ms`);
|
|
255
|
+
if (hasSuccessfulBuild && options.node) {
|
|
256
|
+
runner.restart();
|
|
257
|
+
} else if (!hasSuccessfulBuild) {
|
|
258
|
+
hasSuccessfulBuild = true;
|
|
259
|
+
runner.start();
|
|
260
|
+
} else {
|
|
261
|
+
runner.start();
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
]
|
|
267
|
+
});
|
|
268
|
+
const rebuild = async () => {
|
|
269
|
+
if (rebuildInProgress) {
|
|
270
|
+
rebuildRequested = true;
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
rebuildInProgress = true;
|
|
274
|
+
do {
|
|
275
|
+
rebuildRequested = false;
|
|
276
|
+
try {
|
|
277
|
+
await context2.rebuild();
|
|
278
|
+
} catch {
|
|
279
|
+
}
|
|
280
|
+
} while (rebuildRequested);
|
|
281
|
+
rebuildInProgress = false;
|
|
282
|
+
};
|
|
283
|
+
await rebuild();
|
|
284
|
+
const watcher = import_chokidar.default.watch(["./app", "./tsconfig.json"], { ignoreInitial: true });
|
|
285
|
+
watcher.on("all", () => {
|
|
286
|
+
onFilesChanged == null ? void 0 : onFilesChanged();
|
|
287
|
+
clearTimeout(rebuildTimer);
|
|
288
|
+
rebuildTimer = setTimeout(rebuild, 20);
|
|
289
|
+
});
|
|
290
|
+
watcher.on("error", (error) => console.error(`Unable to watch application files: ${error.message}`));
|
|
291
|
+
return { context: context2, watcher };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/dev/watchAndCompile/watchAndTypecheck.ts
|
|
295
|
+
var import_node_child_process3 = require("child_process");
|
|
186
296
|
|
|
187
297
|
// src/dev/watchAndCompile/getConfigPath.ts
|
|
188
|
-
var
|
|
298
|
+
var import_node_fs6 = require("fs");
|
|
299
|
+
var import_node_path4 = require("path");
|
|
189
300
|
|
|
190
301
|
// src/dev/watchAndCompile/ensureConfigComplies.ts
|
|
191
302
|
var import_comment_json = require("comment-json");
|
|
192
303
|
|
|
193
304
|
// src/helpers/getFileContents.ts
|
|
194
|
-
var
|
|
305
|
+
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
195
306
|
function readFile(filePath) {
|
|
196
|
-
if (!
|
|
197
|
-
return
|
|
307
|
+
if (!import_node_fs5.default.existsSync(filePath)) return null;
|
|
308
|
+
return import_node_fs5.default.readFileSync(filePath).toString();
|
|
198
309
|
}
|
|
199
310
|
|
|
200
311
|
// src/dev/watchAndCompile/ensureConfigComplies.ts
|
|
@@ -203,11 +314,15 @@ function ensureConfigComplies(configPath) {
|
|
|
203
314
|
try {
|
|
204
315
|
const configJSON = readFile(configPath);
|
|
205
316
|
const config = (0, import_comment_json.parse)(configJSON);
|
|
317
|
+
const { baseUrl: _baseUrl, ...compilerOptions } = config.compilerOptions ?? {};
|
|
206
318
|
const newConfig = {
|
|
207
319
|
...config,
|
|
208
320
|
compilerOptions: {
|
|
209
|
-
...
|
|
210
|
-
|
|
321
|
+
...compilerOptions,
|
|
322
|
+
paths: {
|
|
323
|
+
"*": ["./*"],
|
|
324
|
+
...compilerOptions.paths
|
|
325
|
+
},
|
|
211
326
|
noEmit: true
|
|
212
327
|
}
|
|
213
328
|
};
|
|
@@ -224,9 +339,19 @@ function ensureConfigComplies(configPath) {
|
|
|
224
339
|
}
|
|
225
340
|
|
|
226
341
|
// src/dev/watchAndCompile/getConfigPath.ts
|
|
342
|
+
function findConfigFile(startDirectory, fileName) {
|
|
343
|
+
let directory = startDirectory;
|
|
344
|
+
while (true) {
|
|
345
|
+
const candidate = (0, import_node_path4.join)(directory, fileName);
|
|
346
|
+
if ((0, import_node_fs6.existsSync)(candidate)) return candidate;
|
|
347
|
+
const parent = (0, import_node_path4.dirname)(directory);
|
|
348
|
+
if (parent === directory) return void 0;
|
|
349
|
+
directory = parent;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
227
352
|
function getConfigPath() {
|
|
228
353
|
const appBasePath = process.cwd();
|
|
229
|
-
const configPath =
|
|
354
|
+
const configPath = findConfigFile(appBasePath, "tsconfig.server.json") || findConfigFile(appBasePath, "tsconfig.json");
|
|
230
355
|
if (!configPath) {
|
|
231
356
|
throw new Error("Could not find a valid 'tsconfig.json'.");
|
|
232
357
|
}
|
|
@@ -234,106 +359,106 @@ function getConfigPath() {
|
|
|
234
359
|
return configPath;
|
|
235
360
|
}
|
|
236
361
|
|
|
237
|
-
// src/dev/watchAndCompile/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
console.log(import_typescript2.default.formatDiagnosticsWithColorAndContext([diagnostic], format));
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// src/dev/watchAndCompile/getHost.ts
|
|
249
|
-
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
250
|
-
function getHost(runner) {
|
|
251
|
-
let isStopped = true;
|
|
252
|
-
const reportWatchStatusChanged = (diagnostic) => {
|
|
253
|
-
if (diagnostic.category !== 3) return;
|
|
254
|
-
if (diagnostic.code === 6031 || diagnostic.code === 6032) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (diagnostic.code === 6193) {
|
|
258
|
-
runner.stop();
|
|
259
|
-
isStopped = true;
|
|
362
|
+
// src/dev/watchAndCompile/watchAndTypecheck.ts
|
|
363
|
+
function watchAndTypecheck(runner) {
|
|
364
|
+
const configPath = getConfigPath();
|
|
365
|
+
let checkInProgress = false;
|
|
366
|
+
let checkRequested = false;
|
|
367
|
+
const runCheck = () => {
|
|
368
|
+
if (checkInProgress) {
|
|
369
|
+
checkRequested = true;
|
|
260
370
|
return;
|
|
261
371
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
372
|
+
checkInProgress = true;
|
|
373
|
+
const startedAt = Date.now();
|
|
374
|
+
const checker = (0, import_node_child_process3.spawn)("tsc", ["--noEmit", "--project", configPath], {
|
|
375
|
+
env: process.env,
|
|
376
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
377
|
+
});
|
|
378
|
+
let output = "";
|
|
379
|
+
let spawnError;
|
|
380
|
+
checker.stdout.on("data", (chunk) => {
|
|
381
|
+
output += chunk.toString();
|
|
382
|
+
});
|
|
383
|
+
checker.stderr.on("data", (chunk) => {
|
|
384
|
+
output += chunk.toString();
|
|
385
|
+
});
|
|
386
|
+
checker.on("error", (error) => {
|
|
387
|
+
spawnError = error;
|
|
388
|
+
});
|
|
389
|
+
checker.on("close", (code) => {
|
|
390
|
+
checkInProgress = false;
|
|
391
|
+
if (checkRequested) {
|
|
392
|
+
checkRequested = false;
|
|
393
|
+
runCheck();
|
|
394
|
+
return;
|
|
269
395
|
}
|
|
270
|
-
if (
|
|
271
|
-
|
|
396
|
+
if (spawnError) {
|
|
397
|
+
runner.stop();
|
|
398
|
+
console.error(`Unable to run TypeScript: ${spawnError.message}`);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const duration = Date.now() - startedAt;
|
|
402
|
+
if (code === 0) {
|
|
403
|
+
console.log(`=> TypeScript checked in ${duration}ms`);
|
|
272
404
|
runner.start();
|
|
405
|
+
return;
|
|
273
406
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
407
|
+
if (output.trim()) console.error(output.trimEnd());
|
|
408
|
+
console.error(`=> TypeScript found errors in ${duration}ms`);
|
|
409
|
+
runner.stop();
|
|
410
|
+
});
|
|
277
411
|
};
|
|
278
|
-
|
|
279
|
-
const createProgram = import_typescript3.default.createEmitAndSemanticDiagnosticsBuilderProgram;
|
|
280
|
-
const host = import_typescript3.default.createWatchCompilerHost(
|
|
281
|
-
configPath,
|
|
282
|
-
{},
|
|
283
|
-
import_typescript3.default.sys,
|
|
284
|
-
createProgram,
|
|
285
|
-
reportDiagnostic,
|
|
286
|
-
reportWatchStatusChanged
|
|
287
|
-
);
|
|
288
|
-
return host;
|
|
412
|
+
return runCheck;
|
|
289
413
|
}
|
|
290
414
|
|
|
291
415
|
// src/dev/watchAndCompile/writeEnvFile.ts
|
|
292
416
|
var import_env = require("@orion-js/env");
|
|
293
|
-
var
|
|
294
|
-
var
|
|
417
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
418
|
+
var import_chokidar2 = __toESM(require("chokidar"), 1);
|
|
295
419
|
var envFilePath = process.env.ORION_ENV_FILE_PATH;
|
|
296
420
|
var dtsFilePath = "./app/env.d.ts";
|
|
297
421
|
var watchEnvFile = async (runner) => {
|
|
298
422
|
if (!envFilePath) return;
|
|
299
423
|
(0, import_env.writeDtsFileFromConfigFile)(envFilePath, dtsFilePath);
|
|
300
|
-
|
|
301
|
-
console.log(
|
|
424
|
+
import_chokidar2.default.watch(envFilePath, { ignoreInitial: true }).on("change", async () => {
|
|
425
|
+
console.log(import_chalk3.default.bold("=> Environment file changed. Restarting..."));
|
|
302
426
|
(0, import_env.writeDtsFileFromConfigFile)(envFilePath, dtsFilePath);
|
|
303
427
|
runner.restart();
|
|
304
428
|
});
|
|
305
429
|
};
|
|
306
430
|
|
|
307
431
|
// src/dev/watchAndCompile/index.ts
|
|
308
|
-
async function watchAndCompile(runner) {
|
|
432
|
+
async function watchAndCompile(runner, options) {
|
|
309
433
|
await cleanDirectory();
|
|
310
|
-
const
|
|
311
|
-
|
|
434
|
+
const requestTypecheck = options.typecheck ? watchAndTypecheck(runner) : void 0;
|
|
435
|
+
await watchAndBundle(runner, options, requestTypecheck);
|
|
436
|
+
requestTypecheck == null ? void 0 : requestTypecheck();
|
|
312
437
|
watchEnvFile(runner);
|
|
313
438
|
}
|
|
314
439
|
|
|
315
440
|
// src/dev/index.ts
|
|
316
441
|
async function dev_default(options, command) {
|
|
317
|
-
console.log(
|
|
318
|
-
Orionjs App ${
|
|
442
|
+
console.log(import_chalk4.default.bold(`
|
|
443
|
+
Orionjs App ${import_chalk4.default.green(import_chalk4.default.bold("V4"))} Dev mode
|
|
319
444
|
`));
|
|
320
445
|
const runner = getRunner(options, command);
|
|
321
|
-
watchAndCompile(runner);
|
|
446
|
+
await watchAndCompile(runner, options);
|
|
322
447
|
}
|
|
323
448
|
|
|
324
449
|
// src/prod/index.ts
|
|
325
|
-
var
|
|
450
|
+
var import_chalk8 = __toESM(require("chalk"), 1);
|
|
326
451
|
|
|
327
452
|
// src/build/index.ts
|
|
328
|
-
var
|
|
453
|
+
var import_chalk7 = __toESM(require("chalk"), 1);
|
|
329
454
|
|
|
330
455
|
// src/build/build.ts
|
|
331
|
-
var
|
|
332
|
-
var
|
|
456
|
+
var import_chalk5 = __toESM(require("chalk"), 1);
|
|
457
|
+
var esbuild2 = __toESM(require("esbuild"), 1);
|
|
333
458
|
async function build2(options) {
|
|
334
459
|
const { output } = options;
|
|
335
460
|
console.log(`Building with esbuild to ${output}`);
|
|
336
|
-
await
|
|
461
|
+
await esbuild2.build({
|
|
337
462
|
entryPoints: ["./app/index.ts"],
|
|
338
463
|
tsconfig: "./tsconfig.json",
|
|
339
464
|
format: "esm",
|
|
@@ -346,14 +471,14 @@ async function build2(options) {
|
|
|
346
471
|
minify: true,
|
|
347
472
|
packages: "external"
|
|
348
473
|
});
|
|
349
|
-
console.log(
|
|
474
|
+
console.log(import_chalk5.default.green.bold("Build successful"));
|
|
350
475
|
}
|
|
351
476
|
|
|
352
477
|
// src/build/checkTs.ts
|
|
353
|
-
var
|
|
354
|
-
var
|
|
478
|
+
var import_chalk6 = __toESM(require("chalk"), 1);
|
|
479
|
+
var import_node_child_process4 = require("child_process");
|
|
355
480
|
var import_node_util = require("util");
|
|
356
|
-
var execPromise = (0, import_node_util.promisify)(
|
|
481
|
+
var execPromise = (0, import_node_util.promisify)(import_node_child_process4.exec);
|
|
357
482
|
async function checkTs() {
|
|
358
483
|
try {
|
|
359
484
|
console.log("Checking TypeScript...");
|
|
@@ -365,9 +490,9 @@ async function checkTs() {
|
|
|
365
490
|
gid: process.getgid(),
|
|
366
491
|
uid: process.getuid()
|
|
367
492
|
});
|
|
368
|
-
console.log(
|
|
493
|
+
console.log(import_chalk6.default.green.bold("TypeScript check passed"));
|
|
369
494
|
} catch (error) {
|
|
370
|
-
console.log(
|
|
495
|
+
console.log(import_chalk6.default.red.bold("TypeScript compilation failed"));
|
|
371
496
|
console.log(error.stderr || error.stdout || error.message);
|
|
372
497
|
process.exit(1);
|
|
373
498
|
}
|
|
@@ -375,23 +500,23 @@ async function checkTs() {
|
|
|
375
500
|
|
|
376
501
|
// src/build/index.ts
|
|
377
502
|
async function build_default(options) {
|
|
378
|
-
console.log(
|
|
503
|
+
console.log(import_chalk7.default.bold(`Building Orionjs App ${import_chalk7.default.green(import_chalk7.default.bold("V4"))}...`));
|
|
379
504
|
if (!options.output) {
|
|
380
505
|
options.output = "./build";
|
|
381
506
|
}
|
|
382
507
|
await cleanDirectory(options.output);
|
|
383
508
|
await checkTs();
|
|
384
509
|
await build2(options);
|
|
385
|
-
console.log(
|
|
510
|
+
console.log(import_chalk7.default.bold("Build completed"));
|
|
386
511
|
}
|
|
387
512
|
|
|
388
513
|
// src/prod/runProd.ts
|
|
389
|
-
var
|
|
514
|
+
var import_node_child_process5 = require("child_process");
|
|
390
515
|
function runProd(options, command) {
|
|
391
516
|
if (options.node) {
|
|
392
517
|
const indexPath = `${options.path}/index.js`;
|
|
393
518
|
const args2 = ["--import=tsx", ...command.args, indexPath];
|
|
394
|
-
(0,
|
|
519
|
+
(0, import_node_child_process5.spawn)("node", args2, {
|
|
395
520
|
env: {
|
|
396
521
|
NODE_ENV: "production",
|
|
397
522
|
...process.env
|
|
@@ -405,7 +530,7 @@ function runProd(options, command) {
|
|
|
405
530
|
return;
|
|
406
531
|
}
|
|
407
532
|
const args = [...command.args, "./app/index.ts"];
|
|
408
|
-
(0,
|
|
533
|
+
(0, import_node_child_process5.spawn)("bun", args, {
|
|
409
534
|
env: {
|
|
410
535
|
NODE_ENV: "production",
|
|
411
536
|
...process.env
|
|
@@ -420,8 +545,8 @@ function runProd(options, command) {
|
|
|
420
545
|
|
|
421
546
|
// src/prod/index.ts
|
|
422
547
|
async function prod_default(options, command) {
|
|
423
|
-
console.log(
|
|
424
|
-
Orionjs App ${
|
|
548
|
+
console.log(import_chalk8.default.bold(`
|
|
549
|
+
Orionjs App ${import_chalk8.default.green(import_chalk8.default.bold("V4"))} Prod mode
|
|
425
550
|
`));
|
|
426
551
|
if (options.node) {
|
|
427
552
|
if (!options.path) {
|
|
@@ -433,29 +558,29 @@ Orionjs App ${import_chalk9.default.green(import_chalk9.default.bold("V4"))} Pro
|
|
|
433
558
|
}
|
|
434
559
|
|
|
435
560
|
// src/handleErrors.ts
|
|
436
|
-
var
|
|
561
|
+
var import_chalk9 = __toESM(require("chalk"), 1);
|
|
437
562
|
process.on("unhandledRejection", (error) => {
|
|
438
563
|
if (error.codeFrame) {
|
|
439
|
-
console.error(
|
|
564
|
+
console.error(import_chalk9.default.red(error.message));
|
|
440
565
|
console.log(error.codeFrame);
|
|
441
566
|
} else {
|
|
442
|
-
console.error(
|
|
567
|
+
console.error(import_chalk9.default.red(error.message), import_chalk9.default.red("Unhandled promise rejection"));
|
|
443
568
|
}
|
|
444
569
|
}).on("uncaughtException", (error) => {
|
|
445
|
-
console.error(
|
|
570
|
+
console.error(import_chalk9.default.red(error.message));
|
|
446
571
|
process.exit(1);
|
|
447
572
|
});
|
|
448
573
|
|
|
449
574
|
// src/version.ts
|
|
450
|
-
var
|
|
451
|
-
var
|
|
575
|
+
var import_node_fs7 = require("fs");
|
|
576
|
+
var import_node_path5 = require("path");
|
|
452
577
|
var import_node_url = require("url");
|
|
453
578
|
var import_meta = {};
|
|
454
579
|
function getVersion() {
|
|
455
580
|
try {
|
|
456
|
-
const dir = (0,
|
|
457
|
-
const pkgPath = (0,
|
|
458
|
-
const pkg = JSON.parse((0,
|
|
581
|
+
const dir = (0, import_node_path5.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
582
|
+
const pkgPath = (0, import_node_path5.resolve)(dir, "..", "package.json");
|
|
583
|
+
const pkg = JSON.parse((0, import_node_fs7.readFileSync)(pkgPath, "utf-8"));
|
|
459
584
|
return pkg.version;
|
|
460
585
|
} catch {
|
|
461
586
|
return "unknown";
|
|
@@ -467,14 +592,14 @@ var version_default = getVersion();
|
|
|
467
592
|
var import_config = require("dotenv/config");
|
|
468
593
|
|
|
469
594
|
// src/check/index.ts
|
|
470
|
-
var
|
|
595
|
+
var import_chalk11 = __toESM(require("chalk"), 1);
|
|
471
596
|
|
|
472
597
|
// src/check/checkTs.ts
|
|
473
|
-
var
|
|
474
|
-
var
|
|
598
|
+
var import_chalk10 = __toESM(require("chalk"), 1);
|
|
599
|
+
var import_node_child_process6 = require("child_process");
|
|
475
600
|
function checkTs2() {
|
|
476
601
|
try {
|
|
477
|
-
(0,
|
|
602
|
+
(0, import_node_child_process6.execSync)("tsc --noEmit", {
|
|
478
603
|
cwd: process.cwd(),
|
|
479
604
|
env: {
|
|
480
605
|
...process.env
|
|
@@ -484,27 +609,27 @@ function checkTs2() {
|
|
|
484
609
|
stdio: "inherit"
|
|
485
610
|
});
|
|
486
611
|
} catch {
|
|
487
|
-
console.log(
|
|
612
|
+
console.log(import_chalk10.default.red.bold("TypeScript compilation failed"));
|
|
488
613
|
process.exit(1);
|
|
489
614
|
}
|
|
490
615
|
}
|
|
491
616
|
|
|
492
617
|
// src/check/index.ts
|
|
493
618
|
async function check_default() {
|
|
494
|
-
console.log(
|
|
619
|
+
console.log(import_chalk11.default.bold(`Orionjs App ${import_chalk11.default.green(import_chalk11.default.bold("V4"))}
|
|
495
620
|
`));
|
|
496
621
|
console.log("Checking typescript...");
|
|
497
622
|
checkTs2();
|
|
498
|
-
console.log(
|
|
623
|
+
console.log(import_chalk11.default.bold.green("Check passed\n"));
|
|
499
624
|
}
|
|
500
625
|
|
|
501
626
|
// src/info.ts
|
|
502
|
-
var
|
|
503
|
-
var
|
|
627
|
+
var import_chalk12 = __toESM(require("chalk"), 1);
|
|
628
|
+
var import_node_child_process7 = require("child_process");
|
|
504
629
|
function detectRuntime() {
|
|
505
630
|
const runtimes = [];
|
|
506
631
|
try {
|
|
507
|
-
const bunVersion = (0,
|
|
632
|
+
const bunVersion = (0, import_node_child_process7.execSync)("bun --version", { encoding: "utf-8" }).trim();
|
|
508
633
|
runtimes.push(`Bun ${bunVersion}`);
|
|
509
634
|
} catch {
|
|
510
635
|
}
|
|
@@ -512,21 +637,21 @@ function detectRuntime() {
|
|
|
512
637
|
return runtimes.join(", ");
|
|
513
638
|
}
|
|
514
639
|
function info() {
|
|
515
|
-
console.log(`Orion CLI v${version_default} \u2014 Available runtimes: ${
|
|
516
|
-
console.log(`Default runtime: ${
|
|
640
|
+
console.log(`Orion CLI v${version_default} \u2014 Available runtimes: ${import_chalk12.default.bold(detectRuntime())}`);
|
|
641
|
+
console.log(`Default runtime: ${import_chalk12.default.bold("Bun")} (use --node flag to switch to Node.js)`);
|
|
517
642
|
}
|
|
518
643
|
|
|
519
644
|
// src/repl/index.ts
|
|
520
|
-
var
|
|
521
|
-
var
|
|
522
|
-
var
|
|
645
|
+
var import_node_fs8 = require("fs");
|
|
646
|
+
var import_node_path6 = require("path");
|
|
647
|
+
var import_chalk13 = __toESM(require("chalk"), 1);
|
|
523
648
|
function resolvePort(options) {
|
|
524
649
|
if (options.port) {
|
|
525
650
|
return Number(options.port);
|
|
526
651
|
}
|
|
527
652
|
try {
|
|
528
|
-
const portFile = (0,
|
|
529
|
-
const port = (0,
|
|
653
|
+
const portFile = (0, import_node_path6.resolve)(process.cwd(), ".orion/port");
|
|
654
|
+
const port = (0, import_node_fs8.readFileSync)(portFile, "utf-8").trim();
|
|
530
655
|
return Number(port);
|
|
531
656
|
} catch {
|
|
532
657
|
}
|
|
@@ -539,7 +664,7 @@ async function repl(options) {
|
|
|
539
664
|
var _a;
|
|
540
665
|
const expression = options.expression;
|
|
541
666
|
if (!expression) {
|
|
542
|
-
console.error(
|
|
667
|
+
console.error(import_chalk13.default.red('Error: expression is required. Use -e "<expression>"'));
|
|
543
668
|
process.exit(1);
|
|
544
669
|
}
|
|
545
670
|
const port = resolvePort(options);
|
|
@@ -551,9 +676,9 @@ async function repl(options) {
|
|
|
551
676
|
});
|
|
552
677
|
const data = await response.json();
|
|
553
678
|
if (!data.success) {
|
|
554
|
-
console.error(
|
|
679
|
+
console.error(import_chalk13.default.red(`Error: ${data.error}`));
|
|
555
680
|
if (data.stack) {
|
|
556
|
-
console.error(
|
|
681
|
+
console.error(import_chalk13.default.dim(data.stack));
|
|
557
682
|
}
|
|
558
683
|
process.exit(1);
|
|
559
684
|
}
|
|
@@ -563,14 +688,15 @@ async function repl(options) {
|
|
|
563
688
|
);
|
|
564
689
|
}
|
|
565
690
|
} catch (error) {
|
|
566
|
-
|
|
691
|
+
const nodeError = error;
|
|
692
|
+
if (nodeError.code === "ECONNREFUSED" || ((_a = nodeError.cause) == null ? void 0 : _a.code) === "ECONNREFUSED") {
|
|
567
693
|
console.error(
|
|
568
|
-
|
|
694
|
+
import_chalk13.default.red(
|
|
569
695
|
`Could not connect to dev server on port ${port}. Make sure "orion dev --repl" is running.`
|
|
570
696
|
)
|
|
571
697
|
);
|
|
572
698
|
} else {
|
|
573
|
-
console.error(
|
|
699
|
+
console.error(import_chalk13.default.red(`Error: ${nodeError.message}`));
|
|
574
700
|
}
|
|
575
701
|
process.exit(1);
|
|
576
702
|
}
|
|
@@ -582,10 +708,10 @@ var run = (action) => async (...args) => {
|
|
|
582
708
|
try {
|
|
583
709
|
await action(...args);
|
|
584
710
|
} catch (e) {
|
|
585
|
-
console.error(
|
|
711
|
+
console.error(import_chalk14.default.red(`Error: ${e.message}`));
|
|
586
712
|
}
|
|
587
713
|
};
|
|
588
|
-
program.command("dev").description("Run the Orionjs app in development mode").option("--node", "Use Node.js runtime instead of Bun").option("--repl", "Enable REPL endpoint for orion repl").allowUnknownOption().action(run(dev_default));
|
|
714
|
+
program.command("dev").description("Run the Orionjs app in development mode").option("--node", "Use Node.js runtime instead of Bun").option("--repl", "Enable REPL endpoint for orion repl").option("--no-typecheck", "Disable continuous TypeScript diagnostics").allowUnknownOption().action(run(dev_default));
|
|
589
715
|
program.command("check").description("Runs a typescript check").action(run(check_default));
|
|
590
716
|
program.command("build").description("Build the Orionjs app for production").option("--output [path]", "Path of the output file").action(run(build_default));
|
|
591
717
|
program.command("prod").allowUnknownOption().option("--node", "Use Node.js runtime instead of Bun").option(
|