stonyx 0.2.3-alpha.36 → 0.2.3-alpha.38

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/modules.js CHANGED
@@ -5,7 +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
+ import { importModuleConfig } from './util/import-module-config.js';
9
9
  const modulePromises = {};
10
10
  // Configure module-specific logging
11
11
  function configureLog(chronicle, module, config) {
@@ -64,7 +64,10 @@ export default async function loadModules(config, rootPath, chronicle) {
64
64
  }
65
65
  try {
66
66
  // Load & Configure Async Modules
67
- const moduleConfig = await importConfig(`${rootPath}/node_modules/${moduleName}/config/environment`);
67
+ // MODULE-OWNED: `.js` only, always. Routing this to the app-owned
68
+ // `importConfig` re-ships abofs/stonyx-orm#118 — Node refuses to
69
+ // type-strip inside `node_modules`. See abofs/stonyx#90.
70
+ const moduleConfig = await importModuleConfig(`${rootPath}/node_modules/${moduleName}/config/environment`);
68
71
  const module = kebabCaseToCamelCase(moduleName.split('/').pop() ?? moduleName);
69
72
  const userConfig = config[module] || {};
70
73
  const finalConfig = mergeObject(moduleConfig, userConfig);
@@ -77,7 +80,9 @@ export default async function loadModules(config, rootPath, chronicle) {
77
80
  }
78
81
  catch (error) {
79
82
  console.error(error);
80
- throw new Error(`Stonyx modules with async loading must have a config/environment.js file with default configurations. Module "${moduleName}" failed to load.`);
83
+ throw new Error('Stonyx modules with async loading must ship a config/environment.js with default configurations. ' +
84
+ 'Module configs resolve as .js only — never .ts, because Node refuses to type-strip inside node_modules. ' +
85
+ `Module "${moduleName}" failed to load.`);
81
86
  }
82
87
  }
83
88
  // Wait until all modules are initialized
@@ -1 +1,20 @@
1
+ /**
2
+ * Resolve an APP-OWNED config — `<cwd>/config/environment`,
3
+ * `<rootPath>/test/config/environment` — as `{ts,js}`, preferring `.ts`.
4
+ * Mirrors `src/util/resolve-entry-point.ts`, which has resolved app-owned
5
+ * entry points this way since abofs/stonyx#67.
6
+ *
7
+ * These paths live in the consuming project's own tree, never inside
8
+ * `node_modules`, so they load under the app's own loader and Node's type
9
+ * stripping applies to them.
10
+ *
11
+ * MODULE-OWNED configs are NOT this function's business: see
12
+ * `importModuleConfig` in `./import-module-config.ts`, which resolves `.js`
13
+ * only. Routing `src/modules.ts` here re-ships abofs/stonyx-orm#118 — Node
14
+ * refuses to type-strip inside `node_modules`, so a `.ts` module config
15
+ * crashes every consumer at parse time. See abofs/stonyx#90.
16
+ *
17
+ * The "Config not found:" prefix is load-bearing: `src/main.ts` matches on it
18
+ * to tell an absent optional config from a real import failure.
19
+ */
1
20
  export declare function importConfig<T = unknown>(basePath: string): Promise<T>;
@@ -1,10 +1,34 @@
1
1
  import { existsSync } from 'fs';
2
2
  import { pathToFileURL } from 'url';
3
+ const EXTENSIONS = ['ts', 'js'];
4
+ /**
5
+ * Resolve an APP-OWNED config — `<cwd>/config/environment`,
6
+ * `<rootPath>/test/config/environment` — as `{ts,js}`, preferring `.ts`.
7
+ * Mirrors `src/util/resolve-entry-point.ts`, which has resolved app-owned
8
+ * entry points this way since abofs/stonyx#67.
9
+ *
10
+ * These paths live in the consuming project's own tree, never inside
11
+ * `node_modules`, so they load under the app's own loader and Node's type
12
+ * stripping applies to them.
13
+ *
14
+ * MODULE-OWNED configs are NOT this function's business: see
15
+ * `importModuleConfig` in `./import-module-config.ts`, which resolves `.js`
16
+ * only. Routing `src/modules.ts` here re-ships abofs/stonyx-orm#118 — Node
17
+ * refuses to type-strip inside `node_modules`, so a `.ts` module config
18
+ * crashes every consumer at parse time. See abofs/stonyx#90.
19
+ *
20
+ * The "Config not found:" prefix is load-bearing: `src/main.ts` matches on it
21
+ * to tell an absent optional config from a real import failure.
22
+ */
3
23
  export async function importConfig(basePath) {
4
- const path = `${basePath}.js`;
5
- if (!existsSync(path)) {
6
- throw new Error(`Config not found: ${path}`);
24
+ const matches = EXTENSIONS.filter(ext => existsSync(`${basePath}.${ext}`));
25
+ if (matches.length === 0) {
26
+ throw new Error(`Config not found: ${basePath}.{ts,js}`);
7
27
  }
28
+ if (matches.length > 1) {
29
+ 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).`);
30
+ }
31
+ const path = `${basePath}.${matches[0]}`;
8
32
  const mod = await import(pathToFileURL(path).href);
9
33
  return mod.default;
10
34
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Resolve a MODULE-OWNED config — `node_modules/<mod>/config/environment` — as
3
+ * `.js` ONLY. There is no `.ts` fallback and there must never be one.
4
+ *
5
+ * Node's type-strip loader refuses to process `.ts` files inside
6
+ * `node_modules`, so a `@stonyx/*` module that ships `config/environment.ts`
7
+ * crashes every consumer at parse time. That is abofs/stonyx-orm#118, the P0
8
+ * `4c80c87` was written to prevent, and this function preserves `4c80c87`'s
9
+ * behaviour byte-for-byte — including the exact `Config not found: <base>.js`
10
+ * message, which `test/unit/import-config-test.ts` pins as a regression guard.
11
+ *
12
+ * App-owned configs resolve `{ts,js}` instead: see `importConfig` in
13
+ * `./import-config.ts`. The boundary is OWNERSHIP, not extension — see
14
+ * abofs/stonyx#90 and `docs/conventions/framework-modules.md`.
15
+ */
16
+ export declare function importModuleConfig<T = unknown>(basePath: string): Promise<T>;
@@ -0,0 +1,25 @@
1
+ import { existsSync } from 'fs';
2
+ import { pathToFileURL } from 'url';
3
+ /**
4
+ * Resolve a MODULE-OWNED config — `node_modules/<mod>/config/environment` — as
5
+ * `.js` ONLY. There is no `.ts` fallback and there must never be one.
6
+ *
7
+ * Node's type-strip loader refuses to process `.ts` files inside
8
+ * `node_modules`, so a `@stonyx/*` module that ships `config/environment.ts`
9
+ * crashes every consumer at parse time. That is abofs/stonyx-orm#118, the P0
10
+ * `4c80c87` was written to prevent, and this function preserves `4c80c87`'s
11
+ * behaviour byte-for-byte — including the exact `Config not found: <base>.js`
12
+ * message, which `test/unit/import-config-test.ts` pins as a regression guard.
13
+ *
14
+ * App-owned configs resolve `{ts,js}` instead: see `importConfig` in
15
+ * `./import-config.ts`. The boundary is OWNERSHIP, not extension — see
16
+ * abofs/stonyx#90 and `docs/conventions/framework-modules.md`.
17
+ */
18
+ export async function importModuleConfig(basePath) {
19
+ const path = `${basePath}.js`;
20
+ if (!existsSync(path)) {
21
+ throw new Error(`Config not found: ${path}`);
22
+ }
23
+ const mod = await import(pathToFileURL(path).href);
24
+ return mod.default;
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stonyx",
3
- "version": "0.2.3-alpha.36",
3
+ "version": "0.2.3-alpha.38",
4
4
  "description": "Base stonyx framework module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",