stonyx 0.2.3-alpha.50 → 0.2.3-alpha.51
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 +27 -4
- package/dist/cli/new.js +86 -12
- package/package.json +1 -1
package/dist/cli/new.d.ts
CHANGED
|
@@ -22,10 +22,28 @@ export declare function readCoreVersion(): string;
|
|
|
22
22
|
* that scaffolded it, so the generated project cannot mix a prerelease core with
|
|
23
23
|
* modules from the stable line (or the reverse).
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
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).
|
|
29
47
|
*/
|
|
30
48
|
export declare function releaseTagFor(version: string): string;
|
|
31
49
|
export declare function generatePackageJson(name: string, selectedModules: ModuleOption[], coreVersion?: string): string;
|
|
@@ -37,6 +55,11 @@ export declare function generateZzExitTestTs(): string;
|
|
|
37
55
|
export declare function generateEnvironmentExampleTs(): string;
|
|
38
56
|
export declare function generateGitignore(): string;
|
|
39
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>;
|
|
40
63
|
/**
|
|
41
64
|
* Write every scaffolded file to disk given a resolved project directory,
|
|
42
65
|
* app name, and pre-selected module options. Factored out of `newCommand`
|
package/dist/cli/new.js
CHANGED
|
@@ -58,6 +58,30 @@ export default class DBModel extends Model {
|
|
|
58
58
|
const STABLE_DIST_TAG = 'latest';
|
|
59
59
|
/** Absolute path to this package's own root, from both `src/` and `dist/`. */
|
|
60
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
|
+
}
|
|
61
85
|
/**
|
|
62
86
|
* The version of the `stonyx` package running this generator, read from its own
|
|
63
87
|
* `package.json` at call time.
|
|
@@ -66,11 +90,10 @@ const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '
|
|
|
66
90
|
* it was written and silently stale on every day after (abofs/stonyx#113).
|
|
67
91
|
*/
|
|
68
92
|
export function readCoreVersion() {
|
|
69
|
-
const
|
|
93
|
+
const manifest = path.join(packageRoot, 'package.json');
|
|
94
|
+
const raw = readFileSync(manifest, 'utf8');
|
|
70
95
|
const version = JSON.parse(raw).version;
|
|
71
|
-
|
|
72
|
-
throw new Error(`Could not read the stonyx version from ${path.join(packageRoot, 'package.json')}`);
|
|
73
|
-
}
|
|
96
|
+
assertVersionShape(version, manifest);
|
|
74
97
|
return version;
|
|
75
98
|
}
|
|
76
99
|
/**
|
|
@@ -81,16 +104,53 @@ export function readCoreVersion() {
|
|
|
81
104
|
* that scaffolded it, so the generated project cannot mix a prerelease core with
|
|
82
105
|
* modules from the stable line (or the reverse).
|
|
83
106
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
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).
|
|
88
129
|
*/
|
|
89
130
|
export function releaseTagFor(version) {
|
|
90
|
-
|
|
91
|
-
|
|
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;
|
|
92
148
|
}
|
|
93
149
|
export function generatePackageJson(name, selectedModules, coreVersion = readCoreVersion()) {
|
|
150
|
+
// `coreVersion` is injectable for tests, so the shape is asserted here too --
|
|
151
|
+
// otherwise an injected non-semver string reaches the manifest verbatim and
|
|
152
|
+
// `releaseTagFor` falls through to `latest`.
|
|
153
|
+
assertVersionShape(coreVersion, 'the supplied core version');
|
|
94
154
|
// The framework is a runtime dependency of the application, pinned exactly to
|
|
95
155
|
// the core that generated the project.
|
|
96
156
|
const dependencies = { stonyx: coreVersion };
|
|
@@ -239,7 +299,11 @@ export function generateTsConfig() {
|
|
|
239
299
|
exclude: ['node_modules', 'test']
|
|
240
300
|
}, null, 2) + '\n';
|
|
241
301
|
}
|
|
242
|
-
|
|
302
|
+
/**
|
|
303
|
+
* Rejects when `pnpm install` fails, either by exiting non-zero or by failing to
|
|
304
|
+
* spawn. Exported so the rejection path is testable without a network round-trip.
|
|
305
|
+
*/
|
|
306
|
+
export function runPnpmInstall(projectDir) {
|
|
243
307
|
return new Promise((resolve, reject) => {
|
|
244
308
|
const child = spawn('pnpm', ['install'], {
|
|
245
309
|
cwd: projectDir,
|
|
@@ -333,7 +397,17 @@ export default async function newCommand({ args }) {
|
|
|
333
397
|
await runPnpmInstall(projectDir);
|
|
334
398
|
}
|
|
335
399
|
catch (error) {
|
|
336
|
-
|
|
400
|
+
// `pnpm`'s own diagnostic already reached the terminal via stdio: 'inherit'.
|
|
401
|
+
// What used to be missing is the exit code: this catch discarded `error` and
|
|
402
|
+
// fell through to the success banner, so `stonyx new` announced success and
|
|
403
|
+
// exited 0 on a project with no node_modules -- loud to a human, silent to any
|
|
404
|
+
// supervisor, CI job or wrapper reading the status.
|
|
405
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
406
|
+
console.error(`\n✗ Project "${appName}" was created, but its dependencies are NOT installed.`);
|
|
407
|
+
console.error(`\n cd ${appName}`);
|
|
408
|
+
console.error(' pnpm install\n');
|
|
409
|
+
process.exitCode = 1;
|
|
410
|
+
return;
|
|
337
411
|
}
|
|
338
412
|
console.log(`\n✓ Project "${appName}" created successfully!`);
|
|
339
413
|
console.log(`\n cd ${appName}`);
|