@nuucognition/ops-cli 0.0.0-stage → 0.1.0-dev.2
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/README.md +914 -2
- package/bin/node-guard.js +61 -0
- package/bin/ops-prod.js +39 -0
- package/dist/.build-stamp.json +7 -0
- package/dist/index.js +97520 -0
- package/package.json +24 -4
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// THE NODE.JS GUARD. ops needs Node.js 24 or newer (`engines.node` of
|
|
2
|
+
// package.json; the bundle targets node24). npm only warns about `engines`,
|
|
3
|
+
// so a global install on an older Node.js works, and the CLI then fails later
|
|
4
|
+
// with an error that names no cause. The `ops` launcher (ops-prod.js) calls
|
|
5
|
+
// this guard FIRST, before it imports a module of the build: on an older
|
|
6
|
+
// Node.js the guard prints one refusal and exits 1.
|
|
7
|
+
//
|
|
8
|
+
// This file must parse and run on an old Node.js. Keep it plain JavaScript:
|
|
9
|
+
// `var`, `function`, and string joins; no optional chaining, no `??`, no
|
|
10
|
+
// class fields, no top-level await, and no import of a module of the build.
|
|
11
|
+
// The model is bin/node-guard.js of the flint CLI.
|
|
12
|
+
|
|
13
|
+
import { writeSync } from 'fs';
|
|
14
|
+
|
|
15
|
+
var MINIMUM = [24, 0];
|
|
16
|
+
var MINIMUM_TEXT = String(MINIMUM[0]);
|
|
17
|
+
var DOWNLOAD = 'https://nodejs.org';
|
|
18
|
+
|
|
19
|
+
/** True when `version` (`20.11.0`, with or without a `v`) is older than the minimum. */
|
|
20
|
+
export function nodeTooOld(version) {
|
|
21
|
+
var parts = String(version).replace(/^v/, '').split('.');
|
|
22
|
+
var major = parseInt(parts[0], 10) || 0;
|
|
23
|
+
var minor = parseInt(parts[1], 10) || 0;
|
|
24
|
+
return major < MINIMUM[0] || (major === MINIMUM[0] && minor < MINIMUM[1]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** True when the arguments ask for JSON: `--json` before a `--` terminator. */
|
|
28
|
+
function wantsJson(args) {
|
|
29
|
+
for (var i = 0; i < args.length; i += 1) {
|
|
30
|
+
if (args[i] === '--') return false;
|
|
31
|
+
if (args[i] === '--json') return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The refusal of an old Node.js, or null when the version is new enough.
|
|
38
|
+
* With `--json` the refusal is one error document on stderr, in the shape of
|
|
39
|
+
* the other errors of ops (`{"error": {code, message, exitCode, hints}}`).
|
|
40
|
+
* Else it is the error lines of ops on stderr: the reason and the next action.
|
|
41
|
+
*/
|
|
42
|
+
export function nodeGuardRefusal(version, args) {
|
|
43
|
+
if (!nodeTooOld(version)) return null;
|
|
44
|
+
var shown = String(version).replace(/^v/, '');
|
|
45
|
+
var message = 'ops needs Node.js ' + MINIMUM_TEXT + ' or newer. This is Node.js ' + shown + '.';
|
|
46
|
+
var hint = 'Install Node.js ' + MINIMUM_TEXT + ' or newer (' + DOWNLOAD + '), then run ops again.';
|
|
47
|
+
if (wantsJson(args)) {
|
|
48
|
+
var report = { code: 'node_too_old', message: message, exitCode: 1, hints: [hint], node: shown, minimum: MINIMUM_TEXT };
|
|
49
|
+
return { exitCode: 1, text: JSON.stringify({ error: report }, null, 2) + '\n' };
|
|
50
|
+
}
|
|
51
|
+
return { exitCode: 1, text: 'error node_too_old: ' + message + '\n ' + hint + '\n' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Refuse and exit 1 on a Node.js that is too old. Else do nothing. */
|
|
55
|
+
export function guardNodeVersion() {
|
|
56
|
+
var refusal = nodeGuardRefusal(process.versions.node, process.argv.slice(2));
|
|
57
|
+
if (refusal === null) return;
|
|
58
|
+
// A write that completes before the exit.
|
|
59
|
+
writeSync(2, refusal.text);
|
|
60
|
+
process.exit(refusal.exitCode);
|
|
61
|
+
}
|
package/bin/ops-prod.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { guardNodeVersion } from './node-guard.js';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
|
|
8
|
+
// The Node.js guard runs first (see node-guard.js): an older Node.js gets one
|
|
9
|
+
// refusal before any module of the build loads. So this file imports no
|
|
10
|
+
// module of the build statically.
|
|
11
|
+
guardNodeVersion();
|
|
12
|
+
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const packageRoot = join(__dirname, '..');
|
|
15
|
+
const launcher = fileURLToPath(import.meta.url);
|
|
16
|
+
const entrypoint = join(packageRoot, 'dist', 'index.js');
|
|
17
|
+
|
|
18
|
+
// The `ops` launcher: the production build (`dist`, build mode baked as
|
|
19
|
+
// production, so it always uses prod data). It is the one bin of the
|
|
20
|
+
// published package.
|
|
21
|
+
//
|
|
22
|
+
// The two stamp checks below apply only in a source checkout (the package
|
|
23
|
+
// has `src/`). An installed npm package has no `src/`, no cli-core, and no
|
|
24
|
+
// bin/stale.js, so it skips them and runs no git command.
|
|
25
|
+
if (existsSync(join(packageRoot, 'src'))) {
|
|
26
|
+
const { warnIfBuildStale } = await import('@nuucognition/cli-core/launch').catch(() => ({ warnIfBuildStale() {} }));
|
|
27
|
+
warnIfBuildStale({ cli: 'ops', distEntry: entrypoint, rebuildHint: 'Run: ndv build ops prod' });
|
|
28
|
+
// The prod bundle keeps its mode, so it never runs the source: when it is
|
|
29
|
+
// older than the source of this checkout, one warning says so (none under --json).
|
|
30
|
+
const stale = await import('./stale.js').catch(() => null);
|
|
31
|
+
const staleSha = stale ? stale.staleAgainstSource(packageRoot, join(packageRoot, 'dist')) : null;
|
|
32
|
+
if (staleSha && !stale.wantsJson()) {
|
|
33
|
+
process.stderr.write(`warning: the ops bundle (dist, built from ${staleSha.slice(0, 7)}) is older than the source of this checkout: a newer command can be missing. Next: ndv build ops prod\n`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
process.env.OPS_CLI_LAUNCHER = launcher;
|
|
38
|
+
process.env.OPS_CLI_ENTRYPOINT = entrypoint;
|
|
39
|
+
await import(pathToFileURL(entrypoint).href);
|