@dbx-tools/cli 0.3.43 → 0.3.44
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/index.ts +1 -1
- package/package.json +3 -3
- package/src/bootstrap.ts +47 -4
- package/src/cli.ts +9 -2
package/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * as bootstrap from "./src/bootstrap";
|
|
|
6
6
|
export * as cli from "./src/cli";
|
|
7
7
|
export * as pnpm from "./src/pnpm";
|
|
8
8
|
export * as root from "./src/root";
|
|
9
|
-
export { bootstrapWorkspace, seedToolchain, runInitialSynth } from "./src/bootstrap";
|
|
9
|
+
export { ensureEngineCurrent, bootstrapWorkspace, seedToolchain, runInitialSynth } from "./src/bootstrap";
|
|
10
10
|
export { runCli } from "./src/cli";
|
|
11
11
|
export { resolvePnpmArgv, runPnpm, ensureWorkspaceReady, runProjen } from "./src/pnpm";
|
|
12
12
|
export { findWorkspaceRoot, needsBootstrap, needsInstall, needsToolchain, workspaceRoot, rootLabel } from "./src/root";
|
package/package.json
CHANGED
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"commander": "^15.0.0",
|
|
19
19
|
"pnpm": "^11.0.6",
|
|
20
20
|
"tsx": "^4.23.0",
|
|
21
|
-
"@dbx-tools/
|
|
22
|
-
"@dbx-tools/core": "0.3.
|
|
21
|
+
"@dbx-tools/core": "0.3.44",
|
|
22
|
+
"@dbx-tools/shared-core": "0.3.44"
|
|
23
23
|
},
|
|
24
24
|
"main": "index.ts",
|
|
25
25
|
"license": "UNLICENSED",
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
|
-
"version": "0.3.
|
|
29
|
+
"version": "0.3.44",
|
|
30
30
|
"types": "index.ts",
|
|
31
31
|
"type": "module",
|
|
32
32
|
"exports": {
|
package/src/bootstrap.ts
CHANGED
|
@@ -31,17 +31,60 @@ const FALLBACK_PROJEN_SPECIFIER = "@dbx-tools/projen@latest";
|
|
|
31
31
|
* heuristic has nothing older to fall back to.
|
|
32
32
|
*/
|
|
33
33
|
function defaultProjenSpecifier(): string {
|
|
34
|
+
const version = ownVersion();
|
|
35
|
+
return version ? `@dbx-tools/projen@^${version}` : FALLBACK_PROJEN_SPECIFIER;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** This CLI's own released version, or `undefined` for an in-repo `0.0.0` build. */
|
|
39
|
+
function ownVersion(): string | undefined {
|
|
34
40
|
try {
|
|
35
41
|
const manifestPath = fileURLToPath(new URL("../package.json", import.meta.url));
|
|
36
42
|
const version = json.parseRecord(readFileSync(manifestPath, "utf8"))?.version;
|
|
37
|
-
return typeof version === "string" && version !== "0.0.0"
|
|
38
|
-
? `@dbx-tools/projen@^${version}`
|
|
39
|
-
: FALLBACK_PROJEN_SPECIFIER;
|
|
43
|
+
return typeof version === "string" && version !== "0.0.0" ? version : undefined;
|
|
40
44
|
} catch {
|
|
41
|
-
return
|
|
45
|
+
return undefined;
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
/** Compare `x.y.z` triples; returns <0, 0, or >0. Missing parts count as 0. */
|
|
50
|
+
function compareVersions(a: string, b: string): number {
|
|
51
|
+
const parts = (v: string) => v.split(".").map((p) => Number.parseInt(p, 10) || 0);
|
|
52
|
+
const [x, y] = [parts(a), parts(b)];
|
|
53
|
+
return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Version of the engine currently installed at `root`, if any. */
|
|
57
|
+
function installedEngineVersion(root: string): string | undefined {
|
|
58
|
+
try {
|
|
59
|
+
const manifest = join(root, "node_modules", "@dbx-tools", "projen", "package.json");
|
|
60
|
+
const version = json.parseRecord(readFileSync(manifest, "utf8"))?.version;
|
|
61
|
+
return typeof version === "string" ? version : undefined;
|
|
62
|
+
} catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Upgrade an established workspace whose installed engine predates this CLI.
|
|
69
|
+
*
|
|
70
|
+
* Bootstrapping pins the engine once, and nothing afterwards revisits it - so a
|
|
71
|
+
* workspace created months ago kept resolving its original engine no matter how
|
|
72
|
+
* current the CLI invoking it was, and failed inside the OLD engine's code
|
|
73
|
+
* (`sync --watch` dying on a `concurrently` that engine never declared). The two
|
|
74
|
+
* are released in lockstep, so this CLI's version is exactly the engine it
|
|
75
|
+
* expects.
|
|
76
|
+
*
|
|
77
|
+
* Only ever moves FORWARD: an engine at or ahead of this CLI is left alone, so
|
|
78
|
+
* an older CLI cannot downgrade a workspace.
|
|
79
|
+
*/
|
|
80
|
+
export function ensureEngineCurrent(root: string): void {
|
|
81
|
+
const expected = ownVersion();
|
|
82
|
+
if (!expected) return;
|
|
83
|
+
const installed = installedEngineVersion(root);
|
|
84
|
+
if (installed && compareVersions(installed, expected) >= 0) return;
|
|
85
|
+
runPnpm(["add", "-D", defaultProjenSpecifier()], root);
|
|
86
|
+
}
|
|
87
|
+
|
|
45
88
|
// Reach the class through its module NAMESPACE. Current engines also hoist it
|
|
46
89
|
// flat, but every engine ever published exports the namespace, and this template
|
|
47
90
|
// is resolved against `@latest` - a flat import dies on an older one with
|
package/src/cli.ts
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import { Command } from "commander";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
bootstrapWorkspace,
|
|
9
|
+
ensureEngineCurrent,
|
|
10
|
+
runInitialSynth,
|
|
11
|
+
seedToolchain,
|
|
12
|
+
} from "./bootstrap";
|
|
8
13
|
import { ensureWorkspaceReady, runPnpm, runProjen } from "./pnpm";
|
|
9
14
|
import { findWorkspaceRoot, needsBootstrap, needsToolchain } from "./root";
|
|
10
15
|
|
|
@@ -19,7 +24,8 @@ import { findWorkspaceRoot, needsBootstrap, needsToolchain } from "./root";
|
|
|
19
24
|
* the toolchain, then run the INITIAL synth directly (the projen tasks the
|
|
20
25
|
* args would name, like `sync`, don't exist until `.projenrc.ts` has run
|
|
21
26
|
* once), and install. Don't forward `projenArgs` - the synth is the work.
|
|
22
|
-
* - otherwise (established workspace) -> ensure deps,
|
|
27
|
+
* - otherwise (established workspace) -> ensure deps, bring the engine up to
|
|
28
|
+
* this CLI's version, then forward to projen.
|
|
23
29
|
*/
|
|
24
30
|
async function prepareAndRunProjen(projenArgs: string[], startDir?: string): Promise<void> {
|
|
25
31
|
const root = await findWorkspaceRoot(startDir);
|
|
@@ -34,6 +40,7 @@ async function prepareAndRunProjen(projenArgs: string[], startDir?: string): Pro
|
|
|
34
40
|
return;
|
|
35
41
|
}
|
|
36
42
|
ensureWorkspaceReady(root);
|
|
43
|
+
ensureEngineCurrent(root);
|
|
37
44
|
runProjen(projenArgs, root);
|
|
38
45
|
}
|
|
39
46
|
|