@flowrunner/cli 0.1.19-dev.3 → 0.1.19-dev.5
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/bin/banner.js +36 -0
- package/bin/flowrunner.js +31 -1
- package/dist/cli.js +367 -214
- package/dist/cli.js.map +4 -4
- package/dist/index.js +2 -1
- package/dist/index.js.map +2 -2
- package/dist/types/packages/cli/src/constants/testing.d.ts +10 -4
- package/package.json +1 -1
package/bin/banner.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// The line every run opens with: which CLI is running, and from where.
|
|
4
|
+
//
|
|
5
|
+
// Plain CommonJS for the same reason as ./resolve-local.js: `bin/flowrunner.js` prints it before any build
|
|
6
|
+
// step or loader exists. `src/cli/version-banner.ts` uses the same function, so the two cannot drift.
|
|
7
|
+
//
|
|
8
|
+
// The version alone is not enough. The launcher hands over to a project's own copy when there is one, so
|
|
9
|
+
// `npx @flowrunner/cli@x` run inside a project runs the project's version, not `x`. The location tells an
|
|
10
|
+
// npx cache, a global install and a project's `node_modules` apart, and a hand-over also names the copy that
|
|
11
|
+
// launched it.
|
|
12
|
+
|
|
13
|
+
const os = require('os')
|
|
14
|
+
const path = require('path')
|
|
15
|
+
|
|
16
|
+
/** `~/…` for anything under the home directory, which is where npx caches and most projects live. */
|
|
17
|
+
function shortPath(target, home) {
|
|
18
|
+
return target === home || target.startsWith(home + path.sep) ? '~' + target.slice(home.length) : target
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {{ version: string, root: string, launcher?: { version: string, root: string } }} cli
|
|
23
|
+
* @param {string} [home]
|
|
24
|
+
* @returns {string[]}
|
|
25
|
+
*/
|
|
26
|
+
function versionBanner(cli, home = os.homedir()) {
|
|
27
|
+
const lines = [`FlowRunner CLI ${ cli.version } — ${ shortPath(cli.root, home) }`]
|
|
28
|
+
|
|
29
|
+
if (cli.launcher) {
|
|
30
|
+
lines.push(` this project's copy, started by ${ cli.launcher.version } — ${ shortPath(cli.launcher.root, home) }`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return lines
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { shortPath, versionBanner }
|
package/bin/flowrunner.js
CHANGED
|
@@ -6,6 +6,15 @@ const fs = require('fs')
|
|
|
6
6
|
const { resolveLocalCli } = require('./resolve-local')
|
|
7
7
|
|
|
8
8
|
const cliRoot = path.resolve(__dirname, '..')
|
|
9
|
+
|
|
10
|
+
/** A package's version, or `unknown`: an unreadable manifest makes a less informative banner, never a failed run. */
|
|
11
|
+
function readVersion(manifest) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(fs.readFileSync(manifest, 'utf-8')).version || 'unknown'
|
|
14
|
+
} catch {
|
|
15
|
+
return 'unknown'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
9
18
|
const srcEntry = path.resolve(cliRoot, 'src', 'cli', 'index.ts')
|
|
10
19
|
|
|
11
20
|
// ─── Hand over to the project's own copy, if there is one ────────────────────
|
|
@@ -29,9 +38,30 @@ if (!process.env.FLOWRUNNER_DELEGATED) {
|
|
|
29
38
|
if (resolution.kind === 'delegate') {
|
|
30
39
|
const { spawnSync } = require('child_process')
|
|
31
40
|
|
|
41
|
+
// Printed here, not by the copy that runs: only the launcher knows both copies, and the project's copy
|
|
42
|
+
// may predate the banner — which is exactly when `npx @flowrunner/cli@x` most needs to say that `x` is
|
|
43
|
+
// not what runs. On stderr, so piped output is unchanged.
|
|
44
|
+
const { versionBanner } = require('./banner')
|
|
45
|
+
const versionOf = directory => readVersion(path.join(directory, 'package.json'))
|
|
46
|
+
|
|
47
|
+
for (const line of versionBanner({
|
|
48
|
+
version : versionOf(resolution.packageDirectory),
|
|
49
|
+
root : resolution.packageDirectory,
|
|
50
|
+
launcher: { version: versionOf(cliRoot), root: cliRoot },
|
|
51
|
+
})) {
|
|
52
|
+
console.error(line)
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
const result = spawnSync(process.execPath, [resolution.bin, ...process.argv.slice(2)], {
|
|
33
56
|
stdio: 'inherit',
|
|
34
|
-
env: {
|
|
57
|
+
env: {
|
|
58
|
+
...process.env,
|
|
59
|
+
FLOWRUNNER_DELEGATED : '1',
|
|
60
|
+
FLOWRUNNER_BANNER_SHOWN : '1',
|
|
61
|
+
// For `flowrunner info`, which reports who started the copy that runs.
|
|
62
|
+
FLOWRUNNER_LAUNCHER_VERSION: versionOf(cliRoot),
|
|
63
|
+
FLOWRUNNER_LAUNCHER_ROOT : cliRoot,
|
|
64
|
+
},
|
|
35
65
|
})
|
|
36
66
|
|
|
37
67
|
if (result.error) {
|