stonyx 0.2.3-beta.76 → 0.2.3-beta.78

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/new.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- interface ModuleOption {
1
+ export interface ModuleOption {
2
2
  question: string;
3
3
  package: string;
4
4
  dirs?: string[];
5
5
  files?: Record<string, () => string>;
6
6
  }
7
+ export declare const MODULE_OPTIONS: ModuleOption[];
7
8
  export declare function generateDbSchema(): string;
8
9
  export declare function generatePackageJson(name: string, selectedModules: ModuleOption[]): string;
9
10
  export declare function generateAppTs(): string;
@@ -23,4 +24,3 @@ export declare function scaffoldProject(projectDir: string, appName: string, sel
23
24
  export default function newCommand({ args }: {
24
25
  args: string[];
25
26
  }): Promise<void>;
26
- export {};
package/dist/cli/new.js CHANGED
@@ -3,7 +3,7 @@ import { createFile, createDirectory, copyFile, fileExists } from '@stonyx/utils
3
3
  import { spawn } from 'child_process';
4
4
  import path from 'path';
5
5
  import { fileURLToPath } from 'url';
6
- const MODULE_OPTIONS = [
6
+ export const MODULE_OPTIONS = [
7
7
  {
8
8
  question: 'Will this project need a REST server?',
9
9
  package: '@stonyx/rest-server',
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
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Shared constants for APP-OWNED `{ts,js}` resolution.
3
+ *
4
+ * Two resolvers pick an extension for a file in the consuming project's own
5
+ * tree — `resolveEntryPoint` (`./resolve-entry-point.ts`, since
6
+ * abofs/stonyx#67) and `importConfig` (`./import-config.ts`, since
7
+ * abofs/stonyx#90). They must agree on the candidate list, on the preference
8
+ * order, and on the wording of the dual-extension warning.
9
+ *
10
+ * They previously agreed by copy. Each string was pinned by its own suite, so
11
+ * editing one file left BOTH suites green while the two messages diverged —
12
+ * which is why this lives here and not at the top of either consumer
13
+ * (`docs/conventions/index.md` § Universal Rules: constants shared across
14
+ * files go in a dedicated constants file).
15
+ *
16
+ * MODULE-OWNED configs are not in scope: `./import-module-config.ts` resolves
17
+ * `.js` only, forever, and deliberately shares nothing with this file.
18
+ */
19
+ /** Candidate extensions in preference order — `.ts` wins over `.js`. */
20
+ export declare const EXTENSIONS: readonly ["ts", "js"];
21
+ /** The warning both app-owned resolvers emit when a `.ts`/`.js` pair exists. */
22
+ export declare function dualExtensionWarning(basePath: string): string;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Shared constants for APP-OWNED `{ts,js}` resolution.
3
+ *
4
+ * Two resolvers pick an extension for a file in the consuming project's own
5
+ * tree — `resolveEntryPoint` (`./resolve-entry-point.ts`, since
6
+ * abofs/stonyx#67) and `importConfig` (`./import-config.ts`, since
7
+ * abofs/stonyx#90). They must agree on the candidate list, on the preference
8
+ * order, and on the wording of the dual-extension warning.
9
+ *
10
+ * They previously agreed by copy. Each string was pinned by its own suite, so
11
+ * editing one file left BOTH suites green while the two messages diverged —
12
+ * which is why this lives here and not at the top of either consumer
13
+ * (`docs/conventions/index.md` § Universal Rules: constants shared across
14
+ * files go in a dedicated constants file).
15
+ *
16
+ * MODULE-OWNED configs are not in scope: `./import-module-config.ts` resolves
17
+ * `.js` only, forever, and deliberately shares nothing with this file.
18
+ */
19
+ /** Candidate extensions in preference order — `.ts` wins over `.js`. */
20
+ export const EXTENSIONS = ['ts', 'js'];
21
+ /** The warning both app-owned resolvers emit when a `.ts`/`.js` pair exists. */
22
+ export function dualExtensionWarning(basePath) {
23
+ return `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).`;
24
+ }
@@ -1 +1,22 @@
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 — the candidate list and the
6
+ * dual-extension warning are shared through `./extension-resolution.ts` so
7
+ * the two cannot drift.
8
+ *
9
+ * These paths live in the consuming project's own tree, never inside
10
+ * `node_modules`, so they load under the app's own loader and Node's type
11
+ * stripping applies to them.
12
+ *
13
+ * MODULE-OWNED configs are NOT this function's business: see
14
+ * `importModuleConfig` in `./import-module-config.ts`, which resolves `.js`
15
+ * only. Routing `src/modules.ts` here re-ships abofs/stonyx-orm#118 — Node
16
+ * refuses to type-strip inside `node_modules`, so a `.ts` module config
17
+ * crashes every consumer at parse time. See abofs/stonyx#90.
18
+ *
19
+ * The "Config not found:" prefix is load-bearing: `src/main.ts` matches on it
20
+ * to tell an absent optional config from a real import failure.
21
+ */
1
22
  export declare function importConfig<T = unknown>(basePath: string): Promise<T>;
@@ -1,10 +1,36 @@
1
1
  import { existsSync } from 'fs';
2
2
  import { pathToFileURL } from 'url';
3
+ import { EXTENSIONS, dualExtensionWarning } from './extension-resolution.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 — the candidate list and the
9
+ * dual-extension warning are shared through `./extension-resolution.ts` so
10
+ * the two cannot drift.
11
+ *
12
+ * These paths live in the consuming project's own tree, never inside
13
+ * `node_modules`, so they load under the app's own loader and Node's type
14
+ * stripping applies to them.
15
+ *
16
+ * MODULE-OWNED configs are NOT this function's business: see
17
+ * `importModuleConfig` in `./import-module-config.ts`, which resolves `.js`
18
+ * only. Routing `src/modules.ts` here re-ships abofs/stonyx-orm#118 — Node
19
+ * refuses to type-strip inside `node_modules`, so a `.ts` module config
20
+ * crashes every consumer at parse time. See abofs/stonyx#90.
21
+ *
22
+ * The "Config not found:" prefix is load-bearing: `src/main.ts` matches on it
23
+ * to tell an absent optional config from a real import failure.
24
+ */
3
25
  export async function importConfig(basePath) {
4
- const path = `${basePath}.js`;
5
- if (!existsSync(path)) {
6
- throw new Error(`Config not found: ${path}`);
26
+ const matches = EXTENSIONS.filter(ext => existsSync(`${basePath}.${ext}`));
27
+ if (matches.length === 0) {
28
+ throw new Error(`Config not found: ${basePath}.{ts,js}`);
7
29
  }
30
+ if (matches.length > 1) {
31
+ console.warn(dualExtensionWarning(basePath));
32
+ }
33
+ const path = `${basePath}.${matches[0]}`;
8
34
  const mod = await import(pathToFileURL(path).href);
9
35
  return mod.default;
10
36
  }
@@ -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
+ }
@@ -1,13 +1,13 @@
1
1
  import { existsSync } from 'fs';
2
2
  import { resolve } from 'path';
3
- const EXTENSIONS = ['ts', 'js'];
3
+ import { EXTENSIONS, dualExtensionWarning } from './extension-resolution.js';
4
4
  export function resolveEntryPoint(basePath) {
5
5
  const matches = EXTENSIONS.filter(ext => existsSync(resolve(`${basePath}.${ext}`)));
6
6
  if (matches.length === 0) {
7
7
  throw new Error(`Entry point not found: ${basePath}.{ts,js}`);
8
8
  }
9
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).`);
10
+ console.warn(dualExtensionWarning(basePath));
11
11
  }
12
12
  const ext = matches[0];
13
13
  return resolve(`${basePath}.${ext}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stonyx",
3
- "version": "0.2.3-beta.76",
3
+ "version": "0.2.3-beta.78",
4
4
  "description": "Base stonyx framework module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -69,6 +69,8 @@
69
69
  "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
70
70
  "start": "node .",
71
71
  "test": "pnpm build && node --import tsx node_modules/qunit/bin/qunit.js 'test/**/*-test.ts'",
72
+ "test:acceptance": "STONYX_ACCEPTANCE=1 node --import tsx node_modules/qunit/bin/qunit.js 'test/acceptance/**/*-test.ts'",
73
+ "test:acceptance:ratchet": "node scripts/acceptance-ratchet.js",
72
74
  "error": "echo \"Error: no error handling\" && exit 1",
73
75
  "postinstall": "node scripts/postinstall.js"
74
76
  }
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Expected-failures ratchet for the fresh-clone scaffold acceptance harness.
4
+ *
5
+ * The harness (abofs/stonyx#89) is RED BY DESIGN until #90, #91 and #92 land.
6
+ * Running it bare in CI produces a permanently-red check, which is the highest-
7
+ * leverage place for a vacuous check to hide: nobody re-examines a check that is
8
+ * always red, and it cannot signal a NEW failure because it is already failing.
9
+ *
10
+ * This wrapper diffs the observed red set against
11
+ * `test/acceptance/expected-failures.json` IN BOTH DIRECTIONS:
12
+ *
13
+ * green today — the known reds are the baseline, so nobody is trained to
14
+ * ignore a red check;
15
+ * red on new — an unlisted failure is a regression;
16
+ * red on fixed — an assertion that starts PASSING while still listed fails the
17
+ * job, which mechanically forces each of #90-#92 to shrink the
18
+ * baseline in its own PR.
19
+ *
20
+ * Usage: pnpm test:acceptance:ratchet
21
+ */
22
+ import { spawn } from 'child_process';
23
+ import { readFileSync } from 'fs';
24
+ import path from 'path';
25
+ import { fileURLToPath } from 'url';
26
+
27
+ const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
28
+ const BASELINE = path.join(REPO_ROOT, 'test', 'acceptance', 'expected-failures.json');
29
+
30
+ // The control flags hand-patch the generated project, so a controlled run says
31
+ // nothing about the baseline. Refuse rather than silently ratchet against it.
32
+ if (process.env.STONYX_ACCEPTANCE_CONTROL) {
33
+ console.error(
34
+ 'STONYX_ACCEPTANCE_CONTROL is set. The ratchet compares an UNMODIFIED run against the\n' +
35
+ 'baseline; a control run hand-patches the generated project and would falsify it.\n' +
36
+ 'Run `pnpm test:acceptance` directly to exercise a control.'
37
+ );
38
+ process.exit(2);
39
+ }
40
+
41
+ const baseline = JSON.parse(readFileSync(BASELINE, 'utf8'));
42
+ const modulePrefix = `${baseline.module} > `;
43
+ const expected = new Map(baseline.expectedFailures.map(entry => [entry.name, entry.issue]));
44
+
45
+ const child = spawn(
46
+ process.execPath,
47
+ ['--import', 'tsx', 'node_modules/qunit/bin/qunit.js', 'test/acceptance/**/*-test.ts'],
48
+ { cwd: REPO_ROOT, env: { ...process.env, STONYX_ACCEPTANCE: '1' }, stdio: ['inherit', 'pipe', 'inherit'] }
49
+ );
50
+
51
+ let tap = '';
52
+
53
+ child.stdout.on('data', chunk => {
54
+ tap += String(chunk);
55
+ process.stdout.write(chunk);
56
+ });
57
+
58
+ child.on('close', () => {
59
+ const observed = new Map();
60
+
61
+ for (const line of tap.split('\n')) {
62
+ const match = /^(not ok|ok) \d+ (.*)$/.exec(line.trim());
63
+ if (!match) continue;
64
+
65
+ const name = match[2].startsWith(modulePrefix) ? match[2].slice(modulePrefix.length) : match[2];
66
+ observed.set(name, match[1] === 'ok');
67
+ }
68
+
69
+ if (observed.size === 0) {
70
+ fail(['The acceptance run produced no TAP assertions at all. This is a harness or setup failure, not a result.']);
71
+ }
72
+
73
+ const problems = [];
74
+
75
+ for (const [name, passed] of observed) {
76
+ if (!passed && !expected.has(name)) {
77
+ problems.push(`NEW FAILURE (not in the baseline): ${name}\n A regression, or an assertion that needs an owning issue before it is baselined.`);
78
+ }
79
+
80
+ if (passed && expected.has(name)) {
81
+ problems.push(
82
+ `NOW PASSING but still baselined (issue #${expected.get(name)}): ${name}\n` +
83
+ ' Delete this entry from test/acceptance/expected-failures.json in the PR that fixed it.'
84
+ );
85
+ }
86
+ }
87
+
88
+ for (const name of expected.keys()) {
89
+ if (!observed.has(name)) {
90
+ problems.push(`BASELINED ASSERTION NOT FOUND: ${name}\n It was renamed or removed. Update the baseline in the same PR.`);
91
+ }
92
+ }
93
+
94
+ if (problems.length) fail(problems);
95
+
96
+ const stillRed = [...expected.keys()].filter(name => observed.get(name) === false);
97
+
98
+ console.log(`\n# acceptance ratchet: OK — ${observed.size} assertions, ${stillRed.length} expected failures, 0 unexpected.`);
99
+ for (const name of stillRed) console.log(`# expected red (#${expected.get(name)}): ${name}`);
100
+ process.exit(0);
101
+ });
102
+
103
+ function fail(problems) {
104
+ console.error('\n# acceptance ratchet: FAILED\n');
105
+ for (const problem of problems) console.error(` - ${problem}\n`);
106
+ console.error('See test/acceptance/expected-failures.json and docs/testing.md.');
107
+ process.exit(1);
108
+ }