stonyx 0.2.3-beta.56 → 0.2.3-beta.58

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,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 { default: config } = await import(`${cwd}/config/environment.js`);
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;
@@ -1,8 +1,8 @@
1
1
  import { createRequire } from 'module';
2
- import { pathToFileURL } from 'url';
2
+ import { importConfig } from '../util/import-config.js';
3
3
  const cwd = process.cwd();
4
4
  const { default: Stonyx } = await import('stonyx');
5
- const { default: config } = await import(pathToFileURL(`${cwd}/config/environment.js`).href);
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
@@ -1,3 +1,4 @@
1
+ export declare const DEFAULT_TEST_GLOB = "test/**/*-test.{js,ts}";
1
2
  export default function test({ args }: {
2
3
  args: string[];
3
4
  }): Promise<void>;
package/dist/cli/test.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { spawn } from 'child_process';
2
2
  import { fileURLToPath, pathToFileURL } from 'url';
3
3
  import path from 'path';
4
+ export const DEFAULT_TEST_GLOB = 'test/**/*-test.{js,ts}';
4
5
  export default async function test({ args }) {
5
6
  const cwd = process.cwd();
6
7
  const setupFile = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'test-setup.js');
7
8
  const setupFileUrl = pathToFileURL(setupFile).href;
8
9
  const qunitBin = path.resolve(cwd, 'node_modules/qunit/bin/qunit.js');
9
- // Default to conventional test glob if no args provided
10
- const testArgs = args.length > 0 ? args : ['test/**/*-test.js'];
10
+ const testArgs = args.length > 0 ? args : [DEFAULT_TEST_GLOB];
11
11
  const child = spawn(process.execPath, [
12
12
  '--import', setupFileUrl,
13
13
  qunitBin,
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 { default: config } = await import(`${cwd}/config/environment.js`);
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 { default: testOverrides } = await import(`${rootPath}/test/config/environment.js`);
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 { /* no test overrides found */ }
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 { default: moduleConfig } = await import(`${rootPath}/node_modules/${moduleName}/config/environment.js`);
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-beta.56",
3
+ "version": "0.2.3-beta.58",
4
4
  "description": "Base stonyx framework module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",