stonyx 0.2.3-beta.96 → 0.2.3-beta.97
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 +47 -1
- package/dist/cli/new.js +135 -6
- package/package.json +1 -1
package/dist/cli/new.d.ts
CHANGED
|
@@ -4,8 +4,49 @@ interface ModuleOption {
|
|
|
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
|
+
/**
|
|
10
|
+
* The version of the `stonyx` package running this generator, read from its own
|
|
11
|
+
* `package.json` at call time.
|
|
12
|
+
*
|
|
13
|
+
* Read rather than hardcoded on purpose: a literal would be correct on the day
|
|
14
|
+
* it was written and silently stale on every day after (abofs/stonyx#113).
|
|
15
|
+
*/
|
|
16
|
+
export declare function readCoreVersion(): string;
|
|
17
|
+
/**
|
|
18
|
+
* The npm dist-tag naming the release line a version belongs to:
|
|
19
|
+
* `0.2.3-beta.96` -> `beta`, `0.2.3-alpha.4` -> `alpha`, `0.2.2` -> `latest`.
|
|
20
|
+
*
|
|
21
|
+
* Every scaffolded `@stonyx/*` module is requested on the same line as the core
|
|
22
|
+
* that scaffolded it, so the generated project cannot mix a prerelease core with
|
|
23
|
+
* modules from the stable line (or the reverse).
|
|
24
|
+
*
|
|
25
|
+
* Throws, rather than guessing, when the prerelease identifier is not usable as a
|
|
26
|
+
* dist-tag. Returning it verbatim was only safe for *alphabetic* identifiers: npm
|
|
27
|
+
* parses a numeric or wildcard identifier as a version **range**, so `0.2.3-0`
|
|
28
|
+
* emitted `"0"` and `0.2.3-x` emitted `"x"`, both of which install with rc=0 and
|
|
29
|
+
* silently resolve the module's `latest` release -- for `@stonyx/orm` that is
|
|
30
|
+
* `0.3.1`, which pins `stonyx@0.2.3-beta.11` and so reproduces abofs/stonyx#113
|
|
31
|
+
* through a different door, with no error. `0.2.3-0` is reachable from this
|
|
32
|
+
* repo's own `publish.yml` `custom-version` dispatch input, which accepts any
|
|
33
|
+
* semver string and also expands the keyword `prerelease` to `x.y.z-0`.
|
|
34
|
+
*
|
|
35
|
+
* Two bounds remain, both loud rather than silent:
|
|
36
|
+
*
|
|
37
|
+
* - An alphabetic identifier is assumed to also be a published dist-tag name.
|
|
38
|
+
* True for `beta` and `alpha`, the only two lines the fleet publishes; a core
|
|
39
|
+
* released as e.g. `0.2.3-rc.1` with no `rc` dist-tag scaffolds an unresolvable
|
|
40
|
+
* module specifier, which fails `pnpm install` with
|
|
41
|
+
* `ERR_PNPM_NO_MATCHING_VERSION`. The tag has to exist on every package in
|
|
42
|
+
* `MODULE_OPTIONS`, not only on the core.
|
|
43
|
+
* - On the stable line this returns `latest`, the correct tag for that line -- but
|
|
44
|
+
* only useful once the *modules* have advanced their own `latest` tags. Today
|
|
45
|
+
* `@stonyx/orm@latest` is `0.3.1` and pins `stonyx@0.2.3-beta.11`, so the module
|
|
46
|
+
* `latest` tags must advance before the core's does (abofs/stonyx#115).
|
|
47
|
+
*/
|
|
48
|
+
export declare function releaseTagFor(version: string): string;
|
|
49
|
+
export declare function generatePackageJson(name: string, selectedModules: ModuleOption[], coreVersion?: string): string;
|
|
9
50
|
export declare function generateAppTs(): string;
|
|
10
51
|
export declare function generateEnvironmentTs(): string;
|
|
11
52
|
export declare function generateTestEnvironmentTs(): string;
|
|
@@ -14,6 +55,11 @@ export declare function generateZzExitTestTs(): string;
|
|
|
14
55
|
export declare function generateEnvironmentExampleTs(): string;
|
|
15
56
|
export declare function generateGitignore(): string;
|
|
16
57
|
export declare function generateTsConfig(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Rejects when `pnpm install` fails, either by exiting non-zero or by failing to
|
|
60
|
+
* spawn. Exported so the rejection path is testable without a network round-trip.
|
|
61
|
+
*/
|
|
62
|
+
export declare function runPnpmInstall(projectDir: string): Promise<void>;
|
|
17
63
|
/**
|
|
18
64
|
* Write every scaffolded file to disk given a resolved project directory,
|
|
19
65
|
* app name, and pre-selected module options. Factored out of `newCommand`
|
package/dist/cli/new.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { confirm, prompt } from '@stonyx/utils/prompt';
|
|
2
2
|
import { createFile, createDirectory, copyFile, fileExists } from '@stonyx/utils/file';
|
|
3
3
|
import { spawn } from 'child_process';
|
|
4
|
+
import { readFileSync } from 'fs';
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import { fileURLToPath } from 'url';
|
|
6
|
-
const MODULE_OPTIONS = [
|
|
7
|
+
export const MODULE_OPTIONS = [
|
|
7
8
|
{
|
|
8
9
|
question: 'Will this project need a REST server?',
|
|
9
10
|
package: '@stonyx/rest-server',
|
|
@@ -48,15 +49,128 @@ export default class DBModel extends Model {
|
|
|
48
49
|
}
|
|
49
50
|
`;
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The npm dist-tag that points at a package's stable release line. Only ever
|
|
54
|
+
* used as a *release line* selector for `@stonyx/*` modules (see
|
|
55
|
+
* `releaseTagFor`) -- never as the specifier for the core, which is always
|
|
56
|
+
* pinned exactly.
|
|
57
|
+
*/
|
|
58
|
+
const STABLE_DIST_TAG = 'latest';
|
|
59
|
+
/** Absolute path to this package's own root, from both `src/` and `dist/`. */
|
|
60
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
61
|
+
/** A full semver version: `major.minor.patch`, optional prerelease, optional build. */
|
|
62
|
+
const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
63
|
+
/**
|
|
64
|
+
* A string npm accepts as a *dist-tag* and never reinterprets as a version range.
|
|
65
|
+
* npm requires a tag to be non-numeric, and `x`/`X` are semver wildcards rather
|
|
66
|
+
* than tag names, so both are rejected in `releaseTagFor`.
|
|
67
|
+
*/
|
|
68
|
+
const DIST_TAG = /^[A-Za-z][0-9A-Za-z-]*$/;
|
|
69
|
+
/**
|
|
70
|
+
* Rejects any version this generator must not emit.
|
|
71
|
+
*
|
|
72
|
+
* `readCoreVersion` used to check only that the field was a non-empty string, so
|
|
73
|
+
* `"garbage"`, `"0.2"` and `"latest"` all flowed through to the manifest verbatim
|
|
74
|
+
* and made `releaseTagFor` fall through to `latest` -- the one specifier
|
|
75
|
+
* abofs/stonyx#113 exists to stop emitting.
|
|
76
|
+
*/
|
|
77
|
+
function assertVersionShape(version, source) {
|
|
78
|
+
if (typeof version !== 'string' || !version) {
|
|
79
|
+
throw new Error(`Could not read the stonyx version from ${source}`);
|
|
80
|
+
}
|
|
81
|
+
if (!SEMVER.test(version)) {
|
|
82
|
+
throw new Error(`The stonyx version from ${source} is not a semver version: "${version}"`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The version of the `stonyx` package running this generator, read from its own
|
|
87
|
+
* `package.json` at call time.
|
|
88
|
+
*
|
|
89
|
+
* Read rather than hardcoded on purpose: a literal would be correct on the day
|
|
90
|
+
* it was written and silently stale on every day after (abofs/stonyx#113).
|
|
91
|
+
*/
|
|
92
|
+
export function readCoreVersion() {
|
|
93
|
+
const manifest = path.join(packageRoot, 'package.json');
|
|
94
|
+
const raw = readFileSync(manifest, 'utf8');
|
|
95
|
+
const version = JSON.parse(raw).version;
|
|
96
|
+
assertVersionShape(version, manifest);
|
|
97
|
+
return version;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The npm dist-tag naming the release line a version belongs to:
|
|
101
|
+
* `0.2.3-beta.96` -> `beta`, `0.2.3-alpha.4` -> `alpha`, `0.2.2` -> `latest`.
|
|
102
|
+
*
|
|
103
|
+
* Every scaffolded `@stonyx/*` module is requested on the same line as the core
|
|
104
|
+
* that scaffolded it, so the generated project cannot mix a prerelease core with
|
|
105
|
+
* modules from the stable line (or the reverse).
|
|
106
|
+
*
|
|
107
|
+
* Throws, rather than guessing, when the prerelease identifier is not usable as a
|
|
108
|
+
* dist-tag. Returning it verbatim was only safe for *alphabetic* identifiers: npm
|
|
109
|
+
* parses a numeric or wildcard identifier as a version **range**, so `0.2.3-0`
|
|
110
|
+
* emitted `"0"` and `0.2.3-x` emitted `"x"`, both of which install with rc=0 and
|
|
111
|
+
* silently resolve the module's `latest` release -- for `@stonyx/orm` that is
|
|
112
|
+
* `0.3.1`, which pins `stonyx@0.2.3-beta.11` and so reproduces abofs/stonyx#113
|
|
113
|
+
* through a different door, with no error. `0.2.3-0` is reachable from this
|
|
114
|
+
* repo's own `publish.yml` `custom-version` dispatch input, which accepts any
|
|
115
|
+
* semver string and also expands the keyword `prerelease` to `x.y.z-0`.
|
|
116
|
+
*
|
|
117
|
+
* Two bounds remain, both loud rather than silent:
|
|
118
|
+
*
|
|
119
|
+
* - An alphabetic identifier is assumed to also be a published dist-tag name.
|
|
120
|
+
* True for `beta` and `alpha`, the only two lines the fleet publishes; a core
|
|
121
|
+
* released as e.g. `0.2.3-rc.1` with no `rc` dist-tag scaffolds an unresolvable
|
|
122
|
+
* module specifier, which fails `pnpm install` with
|
|
123
|
+
* `ERR_PNPM_NO_MATCHING_VERSION`. The tag has to exist on every package in
|
|
124
|
+
* `MODULE_OPTIONS`, not only on the core.
|
|
125
|
+
* - On the stable line this returns `latest`, the correct tag for that line -- but
|
|
126
|
+
* only useful once the *modules* have advanced their own `latest` tags. Today
|
|
127
|
+
* `@stonyx/orm@latest` is `0.3.1` and pins `stonyx@0.2.3-beta.11`, so the module
|
|
128
|
+
* `latest` tags must advance before the core's does (abofs/stonyx#115).
|
|
129
|
+
*/
|
|
130
|
+
export function releaseTagFor(version) {
|
|
131
|
+
// Fail closed, not open. Without this the exported function still answered
|
|
132
|
+
// `latest` for `"garbage"`, `"0.2"`, `""` and `"latest"` itself -- the same
|
|
133
|
+
// fall-through-to-`latest` shape this change exists to remove, one level down
|
|
134
|
+
// from the emission path that `generatePackageJson` already guards.
|
|
135
|
+
assertVersionShape(version, 'the supplied version');
|
|
136
|
+
const prerelease = /^\d+\.\d+\.\d+-(.*)$/.exec(version);
|
|
137
|
+
if (!prerelease)
|
|
138
|
+
return STABLE_DIST_TAG;
|
|
139
|
+
const identifier = prerelease[1].split('.')[0];
|
|
140
|
+
if (!DIST_TAG.test(identifier) || /^[xX]$/.test(identifier)) {
|
|
141
|
+
throw new Error(`Cannot derive a dist-tag from the prerelease identifier "${identifier}" in version "${version}": ` +
|
|
142
|
+
'npm reads it as a version range, not a tag.');
|
|
143
|
+
}
|
|
144
|
+
if (identifier === STABLE_DIST_TAG) {
|
|
145
|
+
throw new Error(`A prerelease core must not request modules at "${STABLE_DIST_TAG}" (version "${version}").`);
|
|
146
|
+
}
|
|
147
|
+
return identifier;
|
|
148
|
+
}
|
|
149
|
+
export function generatePackageJson(name, selectedModules, coreVersion = readCoreVersion()) {
|
|
150
|
+
// Resolved first, before anything is emitted, and unconditionally -- deliberately
|
|
151
|
+
// not inside the module loop below. `releaseTagFor` asserts the version's shape as
|
|
152
|
+
// its first act, so this one call is also what stops an injected non-semver
|
|
153
|
+
// `coreVersion` from reaching the manifest verbatim.
|
|
154
|
+
//
|
|
155
|
+
// A second `assertVersionShape(coreVersion, ...)` stood at the top of this function
|
|
156
|
+
// until abofs/stonyx#118's review: deleting it left the suite green, because this
|
|
157
|
+
// call already rejects the same value on every path. It was removed rather than
|
|
158
|
+
// left as decoration. The invariant that replaces it is positional -- keep this
|
|
159
|
+
// call above the emission and the guard stays load-bearing; push it under an
|
|
160
|
+
// `if (selectedModules.length)` and the core becomes unvalidated again.
|
|
161
|
+
const moduleTag = releaseTagFor(coreVersion);
|
|
162
|
+
// The framework is a runtime dependency of the application, pinned exactly to
|
|
163
|
+
// the core that generated the project.
|
|
164
|
+
const dependencies = { stonyx: coreVersion };
|
|
52
165
|
const devDependencies = {
|
|
53
166
|
qunit: '^2.24.1',
|
|
54
|
-
stonyx: 'latest',
|
|
55
167
|
tsx: '^4.21.0',
|
|
56
168
|
typescript: '^5.8.3'
|
|
57
169
|
};
|
|
170
|
+
// Modules are discovered from devDependencies (see docs/modules.md), and are
|
|
171
|
+
// requested on the core's own release line rather than at `latest`.
|
|
58
172
|
for (const mod of selectedModules) {
|
|
59
|
-
devDependencies[mod.package] =
|
|
173
|
+
devDependencies[mod.package] = moduleTag;
|
|
60
174
|
}
|
|
61
175
|
// Sort dependencies alphabetically
|
|
62
176
|
const sorted = Object.fromEntries(Object.entries(devDependencies).sort(([a], [b]) => a.localeCompare(b)));
|
|
@@ -71,6 +185,7 @@ export function generatePackageJson(name, selectedModules) {
|
|
|
71
185
|
start: 'stonyx serve',
|
|
72
186
|
test: "NODE_ENV=test node --import tsx/esm --import ./test/setup.ts node_modules/qunit/bin/qunit.js 'test/**/*-test.ts'"
|
|
73
187
|
},
|
|
188
|
+
dependencies,
|
|
74
189
|
devDependencies: sorted
|
|
75
190
|
}, null, 2) + '\n';
|
|
76
191
|
}
|
|
@@ -191,7 +306,11 @@ export function generateTsConfig() {
|
|
|
191
306
|
exclude: ['node_modules', 'test']
|
|
192
307
|
}, null, 2) + '\n';
|
|
193
308
|
}
|
|
194
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Rejects when `pnpm install` fails, either by exiting non-zero or by failing to
|
|
311
|
+
* spawn. Exported so the rejection path is testable without a network round-trip.
|
|
312
|
+
*/
|
|
313
|
+
export function runPnpmInstall(projectDir) {
|
|
195
314
|
return new Promise((resolve, reject) => {
|
|
196
315
|
const child = spawn('pnpm', ['install'], {
|
|
197
316
|
cwd: projectDir,
|
|
@@ -285,7 +404,17 @@ export default async function newCommand({ args }) {
|
|
|
285
404
|
await runPnpmInstall(projectDir);
|
|
286
405
|
}
|
|
287
406
|
catch (error) {
|
|
288
|
-
|
|
407
|
+
// `pnpm`'s own diagnostic already reached the terminal via stdio: 'inherit'.
|
|
408
|
+
// What used to be missing is the exit code: this catch discarded `error` and
|
|
409
|
+
// fell through to the success banner, so `stonyx new` announced success and
|
|
410
|
+
// exited 0 on a project with no node_modules -- loud to a human, silent to any
|
|
411
|
+
// supervisor, CI job or wrapper reading the status.
|
|
412
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
413
|
+
console.error(`\n✗ Project "${appName}" was created, but its dependencies are NOT installed.`);
|
|
414
|
+
console.error(`\n cd ${appName}`);
|
|
415
|
+
console.error(' pnpm install\n');
|
|
416
|
+
process.exitCode = 1;
|
|
417
|
+
return;
|
|
289
418
|
}
|
|
290
419
|
console.log(`\n✓ Project "${appName}" created successfully!`);
|
|
291
420
|
console.log(`\n cd ${appName}`);
|