stonyx 0.2.3-beta.60 → 0.2.3-beta.61
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/cli/serve.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
1
3
|
import { runStartupHooks, runShutdownHooks } from '../lifecycle.js';
|
|
2
4
|
import { importConfig } from '../util/import-config.js';
|
|
5
|
+
import { resolveEntryPoint } from '../util/resolve-entry-point.js';
|
|
3
6
|
export function createShutdownHandler(modules) {
|
|
4
7
|
let shuttingDown = false;
|
|
5
8
|
return async () => {
|
|
@@ -26,7 +29,8 @@ export function maybeRegisterAppShutdown(modules, appInstance, originalShutdown)
|
|
|
26
29
|
export default async function serve({ args }) {
|
|
27
30
|
const cwd = process.cwd();
|
|
28
31
|
const entryFlag = args.indexOf('--entry');
|
|
29
|
-
const
|
|
32
|
+
const entryArg = (entryFlag !== -1 && entryFlag + 1 < args.length) ? args[entryFlag + 1] : null;
|
|
33
|
+
const entryPoint = entryArg !== null ? resolve(cwd, entryArg) : resolveEntryPoint(`${cwd}/app`);
|
|
30
34
|
const config = await importConfig(`${cwd}/config/environment`);
|
|
31
35
|
const { default: Stonyx } = await import('../main.js');
|
|
32
36
|
new Stonyx(config, cwd);
|
|
@@ -36,7 +40,7 @@ export default async function serve({ args }) {
|
|
|
36
40
|
const shutdown = createShutdownHandler(modules);
|
|
37
41
|
process.on('SIGTERM', shutdown);
|
|
38
42
|
process.on('SIGINT', shutdown);
|
|
39
|
-
const entryModule = await import(
|
|
43
|
+
const entryModule = await import(pathToFileURL(entryPoint).href);
|
|
40
44
|
let appInstance;
|
|
41
45
|
if (entryModule.default) {
|
|
42
46
|
appInstance = new entryModule.default();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveEntryPoint(basePath: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
const EXTENSIONS = ['ts', 'js'];
|
|
4
|
+
export function resolveEntryPoint(basePath) {
|
|
5
|
+
const matches = EXTENSIONS.filter(ext => existsSync(resolve(`${basePath}.${ext}`)));
|
|
6
|
+
if (matches.length === 0) {
|
|
7
|
+
throw new Error(`Entry point not found: ${basePath}.{ts,js}`);
|
|
8
|
+
}
|
|
9
|
+
if (matches.length > 1) {
|
|
10
|
+
console.warn(`Warning: both ${basePath}.ts and ${basePath}.js exist. Using .ts — delete the .js to silence this warning (it is likely a stale compiled artifact or postinstall stub).`);
|
|
11
|
+
}
|
|
12
|
+
const ext = matches[0];
|
|
13
|
+
return resolve(`${basePath}.${ext}`);
|
|
14
|
+
}
|