stonyx 0.2.3-alpha.26 → 0.2.3-alpha.28
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 +2 -1
- package/dist/cli/test-setup.js +2 -2
- package/dist/cli.js +2 -1
- package/dist/main.js +7 -2
- package/dist/modules.js +3 -2
- package/dist/util/import-config.d.ts +1 -0
- package/dist/util/import-config.js +15 -0
- package/package.json +2 -2
package/dist/cli/serve.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { runStartupHooks, runShutdownHooks } from '../lifecycle.js';
|
|
2
|
+
import { importConfig } from '../util/import-config.js';
|
|
2
3
|
export function createShutdownHandler(modules) {
|
|
3
4
|
let shuttingDown = false;
|
|
4
5
|
return async () => {
|
|
@@ -26,7 +27,7 @@ export default async function serve({ args }) {
|
|
|
26
27
|
const cwd = process.cwd();
|
|
27
28
|
const entryFlag = args.indexOf('--entry');
|
|
28
29
|
const entryPoint = (entryFlag !== -1 && entryFlag + 1 < args.length) ? args[entryFlag + 1] : 'app.js';
|
|
29
|
-
const
|
|
30
|
+
const config = await importConfig(`${cwd}/config/environment`);
|
|
30
31
|
const { default: Stonyx } = await import('../main.js');
|
|
31
32
|
new Stonyx(config, cwd);
|
|
32
33
|
await Stonyx.ready;
|
package/dist/cli/test-setup.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
|
-
import {
|
|
2
|
+
import { importConfig } from '../util/import-config.js';
|
|
3
3
|
const cwd = process.cwd();
|
|
4
4
|
const { default: Stonyx } = await import('stonyx');
|
|
5
|
-
const
|
|
5
|
+
const config = await importConfig(`${cwd}/config/environment`);
|
|
6
6
|
new Stonyx(config, cwd);
|
|
7
7
|
// Drain the event loop once qunit finishes. Modules loaded by Stonyx
|
|
8
8
|
// (e.g. @stonyx/rest-server) may keep listeners/servers open that would
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import test from './cli/test.js';
|
|
|
4
4
|
import help from './cli/help.js';
|
|
5
5
|
import newCommand from './cli/new.js';
|
|
6
6
|
import loadModuleCommands from './cli/load-commands.js';
|
|
7
|
+
import { importConfig } from './util/import-config.js';
|
|
7
8
|
try {
|
|
8
9
|
process.loadEnvFile();
|
|
9
10
|
}
|
|
@@ -34,7 +35,7 @@ async function main() {
|
|
|
34
35
|
if (moduleCommand) {
|
|
35
36
|
const cwd = process.cwd();
|
|
36
37
|
if (moduleCommand.bootstrap) {
|
|
37
|
-
const
|
|
38
|
+
const config = await importConfig(`${cwd}/config/environment`);
|
|
38
39
|
const { default: Stonyx } = await import('./main.js');
|
|
39
40
|
new Stonyx(config, cwd);
|
|
40
41
|
await Stonyx.ready;
|
package/dist/main.js
CHANGED
|
@@ -17,6 +17,7 @@ import Chronicle from '@stonyx/logs';
|
|
|
17
17
|
import loadModules from './modules.js';
|
|
18
18
|
import { kebabCaseToCamelCase } from '@stonyx/utils/string';
|
|
19
19
|
import { mergeObject } from '@stonyx/utils/object';
|
|
20
|
+
import { importConfig } from './util/import-config.js';
|
|
20
21
|
export default class Stonyx {
|
|
21
22
|
static initialized = false;
|
|
22
23
|
static modulePromises = {};
|
|
@@ -50,11 +51,15 @@ export default class Stonyx {
|
|
|
50
51
|
// Uses in-place mutation to preserve existing references (e.g. stonyx/config export cache)
|
|
51
52
|
if (process.env.NODE_ENV === 'test') {
|
|
52
53
|
try {
|
|
53
|
-
const
|
|
54
|
+
const testOverrides = await importConfig(`${rootPath}/test/config/environment`);
|
|
54
55
|
const merged = mergeObject(config, testOverrides);
|
|
55
56
|
Object.assign(config, merged);
|
|
56
57
|
}
|
|
57
|
-
catch {
|
|
58
|
+
catch (err) {
|
|
59
|
+
// Missing test override is non-fatal; re-throw import errors that aren't "not found"
|
|
60
|
+
if (!(err instanceof Error) || !err.message.startsWith('Config not found:'))
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
this.modules = await loadModules(config, rootPath, this.chronicle);
|
|
60
65
|
this.configureUserLogs();
|
package/dist/modules.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { readFile } from '@stonyx/utils/file';
|
|
6
6
|
import { kebabCaseToCamelCase } from '@stonyx/utils/string';
|
|
7
7
|
import { mergeObject } from '@stonyx/utils/object';
|
|
8
|
+
import { importConfig } from './util/import-config.js';
|
|
8
9
|
const modulePromises = {};
|
|
9
10
|
// Configure module-specific logging
|
|
10
11
|
function configureLog(chronicle, module, config) {
|
|
@@ -63,7 +64,7 @@ export default async function loadModules(config, rootPath, chronicle) {
|
|
|
63
64
|
}
|
|
64
65
|
try {
|
|
65
66
|
// Load & Configure Async Modules
|
|
66
|
-
const
|
|
67
|
+
const moduleConfig = await importConfig(`${rootPath}/node_modules/${moduleName}/config/environment`);
|
|
67
68
|
const module = kebabCaseToCamelCase(moduleName.split('/').pop() ?? moduleName);
|
|
68
69
|
const userConfig = config[module] || {};
|
|
69
70
|
const finalConfig = mergeObject(moduleConfig, userConfig);
|
|
@@ -76,7 +77,7 @@ export default async function loadModules(config, rootPath, chronicle) {
|
|
|
76
77
|
}
|
|
77
78
|
catch (error) {
|
|
78
79
|
console.error(error);
|
|
79
|
-
throw new Error(`Stonyx modules with async loading must have a config/environment.js file with default configurations. Module "${moduleName}" failed to load.`);
|
|
80
|
+
throw new Error(`Stonyx modules with async loading must have a config/environment.{ts,js} file with default configurations. Module "${moduleName}" failed to load.`);
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
// Wait until all modules are initialized
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function importConfig<T = unknown>(basePath: string): Promise<T>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
|
+
const EXTENSIONS = ['ts', 'js'];
|
|
4
|
+
export async function importConfig(basePath) {
|
|
5
|
+
const matches = EXTENSIONS.filter(ext => existsSync(`${basePath}.${ext}`));
|
|
6
|
+
if (matches.length === 0) {
|
|
7
|
+
throw new Error(`Config 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
|
+
const mod = await import(pathToFileURL(`${basePath}.${ext}`).href);
|
|
14
|
+
return mod.default;
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stonyx",
|
|
3
|
-
"version": "0.2.3-alpha.
|
|
3
|
+
"version": "0.2.3-alpha.28",
|
|
4
4
|
"description": "Base stonyx framework module",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"url": "https://github.com/abofs/stonyx/issues"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@stonyx/utils": "0.2.3-beta.
|
|
55
|
+
"@stonyx/utils": "0.2.3-beta.23",
|
|
56
56
|
"@stonyx/logs": "1.0.1-beta.16"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|