stonyx 0.2.3-beta.61 → 0.2.3-beta.63
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/main.js
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import Chronicle from '@stonyx/logs';
|
|
17
17
|
import loadModules from './modules.js';
|
|
18
|
-
import { kebabCaseToCamelCase } from '@stonyx/utils/string';
|
|
19
18
|
import { mergeObject } from '@stonyx/utils/object';
|
|
20
19
|
import { importConfig } from './util/import-config.js';
|
|
20
|
+
import { resolveModuleName } from './util/resolve-module-name.js';
|
|
21
21
|
export default class Stonyx {
|
|
22
22
|
static initialized = false;
|
|
23
23
|
static modulePromises = {};
|
|
@@ -37,11 +37,15 @@ export default class Stonyx {
|
|
|
37
37
|
throw new Error('Stonyx requires full environment configuration on startup');
|
|
38
38
|
if (!rootPath)
|
|
39
39
|
throw new Error('Stonyx requires root project\'s path on startup');
|
|
40
|
-
// Transform config from stonyx-modules running as a standalone
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
// Transform config from stonyx-modules running as a standalone.
|
|
41
|
+
// Signal is the consumer's `package.json#name` (see resolveModuleName);
|
|
42
|
+
// this replaces the brittle `rootPath.includes('stonyx-')` heuristic so
|
|
43
|
+
// non-canonical rootPaths (worktrees, forks, renames) still work.
|
|
44
|
+
const moduleName = resolveModuleName(rootPath);
|
|
45
|
+
if (moduleName) {
|
|
46
|
+
const flatConfig = config;
|
|
47
|
+
const siblingModules = flatConfig.modules || {};
|
|
48
|
+
config = { [moduleName]: config, ...siblingModules };
|
|
45
49
|
delete config.modules;
|
|
46
50
|
}
|
|
47
51
|
this.config = config;
|
package/dist/modules.js
CHANGED
|
@@ -77,7 +77,7 @@ export default async function loadModules(config, rootPath, chronicle) {
|
|
|
77
77
|
}
|
|
78
78
|
catch (error) {
|
|
79
79
|
console.error(error);
|
|
80
|
-
throw new Error(`Stonyx modules with async loading must have a config/environment.
|
|
80
|
+
throw new Error(`Stonyx modules with async loading must have a config/environment.js file with default configurations. Module "${moduleName}" failed to load.`);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
// Wait until all modules are initialized
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { existsSync } from 'fs';
|
|
2
2
|
import { pathToFileURL } from 'url';
|
|
3
|
-
const EXTENSIONS = ['ts', 'js'];
|
|
4
3
|
export async function importConfig(basePath) {
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
throw new Error(`Config not found: ${
|
|
4
|
+
const path = `${basePath}.js`;
|
|
5
|
+
if (!existsSync(path)) {
|
|
6
|
+
throw new Error(`Config not found: ${path}`);
|
|
8
7
|
}
|
|
9
|
-
|
|
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);
|
|
8
|
+
const mod = await import(pathToFileURL(path).href);
|
|
14
9
|
return mod.default;
|
|
15
10
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a stonyx standalone module's camelCase name from the consumer's
|
|
3
|
+
* `package.json#name`. Used by the standalone-config transform to wrap a flat
|
|
4
|
+
* config under the module's key when a stonyx module runs its own tests.
|
|
5
|
+
*
|
|
6
|
+
* Recognises:
|
|
7
|
+
* - `@stonyx/<kebab>` → `<camel>`
|
|
8
|
+
* - `stonyx-<kebab>` → `<camel>` (unscoped fallback)
|
|
9
|
+
* - Anything else → `null` (caller should skip the transform)
|
|
10
|
+
*
|
|
11
|
+
* Missing or malformed `package.json` returns `null` silently — matches the
|
|
12
|
+
* fail-safe semantics of the previous `rootPath.includes('stonyx-')` heuristic.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveModuleName(rootPath: string): string | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { kebabCaseToCamelCase } from '@stonyx/utils/string';
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a stonyx standalone module's camelCase name from the consumer's
|
|
5
|
+
* `package.json#name`. Used by the standalone-config transform to wrap a flat
|
|
6
|
+
* config under the module's key when a stonyx module runs its own tests.
|
|
7
|
+
*
|
|
8
|
+
* Recognises:
|
|
9
|
+
* - `@stonyx/<kebab>` → `<camel>`
|
|
10
|
+
* - `stonyx-<kebab>` → `<camel>` (unscoped fallback)
|
|
11
|
+
* - Anything else → `null` (caller should skip the transform)
|
|
12
|
+
*
|
|
13
|
+
* Missing or malformed `package.json` returns `null` silently — matches the
|
|
14
|
+
* fail-safe semantics of the previous `rootPath.includes('stonyx-')` heuristic.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveModuleName(rootPath) {
|
|
17
|
+
let pkg;
|
|
18
|
+
try {
|
|
19
|
+
const raw = readFileSync(`${rootPath}/package.json`, 'utf8');
|
|
20
|
+
pkg = JSON.parse(raw);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const name = typeof pkg.name === 'string' ? pkg.name : '';
|
|
26
|
+
if (name.startsWith('@stonyx/')) {
|
|
27
|
+
return kebabCaseToCamelCase(name.slice('@stonyx/'.length));
|
|
28
|
+
}
|
|
29
|
+
if (name.startsWith('stonyx-')) {
|
|
30
|
+
return kebabCaseToCamelCase(name.slice('stonyx-'.length));
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|