@multiplatform.one/cli 8.3.0 → 8.5.0

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.
@@ -24,6 +24,18 @@ function reportKept(stdout) {
24
24
  console.log(`\nKept ${kept.length} path(s) already here, pinned in .updateignore:`);
25
25
  for (const path of kept) console.log(` ${path}`);
26
26
  }
27
+ const sourceAccessDoc = "https://git.corp.bitspur.com/multiplatform.one/mpo/-/blob/main/docs/init-update.md#source-access";
28
+ /** scaffold.sh's die line first, then what git printed before it. */
29
+ function scaffoldFailure(stderr, fallback) {
30
+ const lines = stderr.split("\n").map((line) => line.trimEnd()).filter((line) => line.trim());
31
+ const reason = lines.pop()?.replace(/^scaffold: /, "") ?? fallback;
32
+ const said = lines.slice(-20).map((line) => ` ${line.trim()}`);
33
+ return [
34
+ reason,
35
+ ...said.length ? ["git said:", ...said] : [],
36
+ `Run again with --verbose for the scaffold's whole log; source access: ${sourceAccessDoc}`
37
+ ].join("\n");
38
+ }
27
39
  /** Run scaffold.sh and return the provenance it wrote. */
28
40
  async function runScaffold(request, script = scaffoldScript()) {
29
41
  await checkSourceAccess(request.source);
@@ -43,7 +55,7 @@ async function runScaffold(request, script = scaffoldScript()) {
43
55
  "pipe"
44
56
  ] })).stdout;
45
57
  } catch (err) {
46
- throw new ScaffoldError(((err.stderr ?? "").trim().split("\n").filter(Boolean).pop() ?? err.message).replace(/^scaffold: /, ""), request);
58
+ throw new ScaffoldError(scaffoldFailure(err.stderr ?? "", err.message), request);
47
59
  }
48
60
  if (request.into && !request.verbose) reportKept(stdout);
49
61
  const provenance = readProvenance(request.target);
@@ -164,4 +176,4 @@ async function archiveSubtree(source, ref, subtree, dest) {
164
176
  }
165
177
 
166
178
  //#endregion
167
- export { ScaffoldError, archiveSubtree, runScaffold, scaffoldScript, scaffoldToTemp };
179
+ export { ScaffoldError, archiveSubtree, runScaffold, scaffoldFailure, scaffoldScript, scaffoldToTemp, sourceAccessDoc };
package/lib/source.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "cliVersion": "8.3.0",
2
+ "cliVersion": "8.5.0",
3
3
  "url": "https://git.corp.bitspur.com/multiplatform.one/mpo.git",
4
- "sha": "1ee03e368ff501d886ec6cb4d02b80218e90d518"
4
+ "sha": "753fc4c186e6237a46d9a8a0a037ea8cdeccc8e9"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/cli",
3
- "version": "8.3.0",
3
+ "version": "8.5.0",
4
4
  "description": "multiplatform.one cli — mpo init clones and prunes the monorepo, mpo update merges it back",
5
5
  "keywords": [
6
6
  "create-multiplatform-app",
@@ -57,7 +57,7 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@multiplatform.one/utils": "^8.3.0",
60
+ "@multiplatform.one/utils": "^8.5.0",
61
61
  "commander": "^15.0.0",
62
62
  "dotenv": "^17.4.2",
63
63
  "inquirer": "^14.2.3",
@@ -65,6 +65,26 @@ sed_file() {
65
65
  sed "$2" "$1" >"$_tmp" && mv "$_tmp" "$1"
66
66
  }
67
67
 
68
+ # Fetch $REF from origin into $REPO and set FETCHED to a name that resolves to
69
+ # it. A proxy or an old git can fail a depth-1 fetch by sha (FZ-9454), so a
70
+ # failure retries it once, then fetches it with full history, then fetches the
71
+ # branches and tags and looks $REF up among them. git's stderr from every
72
+ # attempt stays on stderr.
73
+ fetch_ref() {
74
+ FETCHED=FETCH_HEAD
75
+ git -C "$REPO" fetch -q --depth 1 --filter=blob:none origin "$REF" && return 0
76
+ printf 'scaffold: shallow fetch of %s failed; retrying it once\n' "$REF" >&2
77
+ git -C "$REPO" fetch -q --depth 1 --filter=blob:none origin "$REF" && return 0
78
+ printf 'scaffold: shallow fetch of %s failed again; fetching it with full history\n' "$REF" >&2
79
+ git -C "$REPO" fetch -q --filter=blob:none origin "$REF" && return 0
80
+ printf 'scaffold: fetch of %s failed; fetching the branches and tags\n' "$REF" >&2
81
+ git -C "$REPO" -c gc.auto=0 -c maintenance.auto=false fetch -q --tags --filter=blob:none origin || return 1
82
+ for FETCHED in "$REF" "refs/remotes/origin/$REF"; do
83
+ GIT_NO_LAZY_FETCH=1 git -C "$REPO" rev-parse --verify --quiet "$FETCHED^{commit}" >/dev/null && return 0
84
+ done
85
+ return 1
86
+ }
87
+
68
88
  positional() {
69
89
  if [ -z "$SOURCE" ]; then
70
90
  SOURCE="$1"
@@ -198,9 +218,8 @@ else
198
218
  REPO="$WORK/clone"
199
219
  git init -q "$REPO"
200
220
  git -C "$REPO" remote add origin "$SOURCE"
201
- git -C "$REPO" fetch -q --depth 1 --filter=blob:none origin "$REF" ||
202
- die "could not fetch $REF from $SOURCE"
203
- SHA="$(git -C "$REPO" rev-parse --verify --quiet 'FETCH_HEAD^{commit}')" ||
221
+ fetch_ref || die "could not fetch $REF from $SOURCE"
222
+ SHA="$(git -C "$REPO" rev-parse --verify --quiet "$FETCHED^{commit}")" ||
204
223
  die "$REF at $SOURCE is not a commit"
205
224
  [ -n "$SOURCE_URL" ] || SOURCE_URL="$SOURCE"
206
225
  fi
@@ -0,0 +1,54 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { mkdtempSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
6
+ import { runScaffold, ScaffoldError } from "./scaffold";
7
+
8
+ describe("a scaffold whose fetch fails", () => {
9
+ const sandbox = mkdtempSync(join(tmpdir(), "mpo-scaffold-fetch-"));
10
+ const bare = join(sandbox, "source.git");
11
+ const missing = "0123456789abcdef0123456789abcdef01234567";
12
+ let url = "";
13
+
14
+ beforeAll(() => {
15
+ const git = (...args: string[]) =>
16
+ execFileSync("git", args, {
17
+ env: {
18
+ ...process.env,
19
+ GIT_AUTHOR_NAME: "fixture",
20
+ GIT_AUTHOR_EMAIL: "fixture@example.invalid",
21
+ GIT_COMMITTER_NAME: "fixture",
22
+ GIT_COMMITTER_EMAIL: "fixture@example.invalid",
23
+ },
24
+ stdio: "ignore",
25
+ });
26
+ const work = join(sandbox, "work");
27
+ git("init", "-q", "--bare", bare);
28
+ git("init", "-q", work);
29
+ git("-C", work, "commit", "-q", "--allow-empty", "-m", "fixture");
30
+ git("-C", work, "push", "-q", bare, "HEAD:refs/heads/main");
31
+ url = `file://${bare}`;
32
+ });
33
+
34
+ afterAll(() => {
35
+ rmSync(sandbox, { recursive: true, force: true });
36
+ });
37
+
38
+ it("carries git's own error lines, not only scaffold.sh's die line, and points at --verbose", async () => {
39
+ const error = await runScaffold({
40
+ source: url,
41
+ ref: missing,
42
+ target: join(sandbox, "project"),
43
+ apps: [],
44
+ services: [],
45
+ }).catch((err: unknown) => err);
46
+ expect(error).toBeInstanceOf(ScaffoldError);
47
+ const { message } = error as ScaffoldError;
48
+ expect(message.split("\n")[0]).toBe(`could not fetch ${missing} from ${url}`);
49
+ expect(message).toMatch(/git said:\n(?: {2}.*\n)* {2}fatal: .*not our ref/);
50
+ expect(message).not.toMatch(/^scaffold: /m);
51
+ expect(message).toContain("--verbose");
52
+ expect(message).toContain("docs/init-update.md#source-access");
53
+ }, 30_000);
54
+ });
@@ -52,6 +52,24 @@ function reportKept(stdout: string): void {
52
52
  for (const path of kept) console.log(` ${path}`);
53
53
  }
54
54
 
55
+ export const sourceAccessDoc =
56
+ "https://git.corp.bitspur.com/multiplatform.one/mpo/-/blob/main/docs/init-update.md#source-access";
57
+
58
+ /** scaffold.sh's die line first, then what git printed before it. */
59
+ export function scaffoldFailure(stderr: string, fallback: string): string {
60
+ const lines = stderr
61
+ .split("\n")
62
+ .map((line) => line.trimEnd())
63
+ .filter((line) => line.trim());
64
+ const reason = lines.pop()?.replace(/^scaffold: /, "") ?? fallback;
65
+ const said = lines.slice(-20).map((line) => ` ${line.trim()}`);
66
+ return [
67
+ reason,
68
+ ...(said.length ? ["git said:", ...said] : []),
69
+ `Run again with --verbose for the scaffold's whole log; source access: ${sourceAccessDoc}`,
70
+ ].join("\n");
71
+ }
72
+
55
73
  /** Run scaffold.sh and return the provenance it wrote. */
56
74
  export async function runScaffold(
57
75
  request: ScaffoldRequest,
@@ -73,9 +91,10 @@ export async function runScaffold(
73
91
  });
74
92
  stdout = result.stdout;
75
93
  } catch (err) {
76
- const stderr = ((err as { stderr?: string }).stderr ?? "").trim();
77
- const detail = stderr.split("\n").filter(Boolean).pop() ?? (err as Error).message;
78
- throw new ScaffoldError(detail.replace(/^scaffold: /, ""), request);
94
+ throw new ScaffoldError(
95
+ scaffoldFailure((err as { stderr?: string }).stderr ?? "", (err as Error).message),
96
+ request,
97
+ );
79
98
  }
80
99
  if (request.into && !request.verbose) reportKept(stdout);
81
100
  const provenance = readProvenance(request.target);
@@ -79,9 +79,9 @@ frappe config, scheme adapter).
79
79
  reaches (GTK widget CSS, a content script, Expo build config) opts out with
80
80
  a `// hex-escape: <reason>` comment that says why.
81
81
  4. **Nothing under `packages/` reaches `features/`**: no `@package/features`
82
- import or dependency and no relative path into `features/`. Move the code
83
- into a package and import it from features
84
- (`scripts/verify-packages-direction.mjs`).
82
+ import or dependency, no relative path into `features/`, and no computed
83
+ path that resolves to a file inside it. Move the code into a package and
84
+ import it from features (`scripts/verify-packages-direction.mjs`).
85
85
  5. **No `@multiplatform.one/<pkg>/src/…` imports**: a package's src/ is not
86
86
  its API and its exports map does not resolve one. Import the package or one
87
87
  of its named subpaths.
@@ -26,6 +26,9 @@ export declare class ScaffoldError extends Error {
26
26
  readonly request: ScaffoldRequest;
27
27
  constructor(message: string, request: ScaffoldRequest);
28
28
  }
29
+ export declare const sourceAccessDoc = "https://git.corp.bitspur.com/multiplatform.one/mpo/-/blob/main/docs/init-update.md#source-access";
30
+ /** scaffold.sh's die line first, then what git printed before it. */
31
+ export declare function scaffoldFailure(stderr: string, fallback: string): string;
29
32
  /** Run scaffold.sh and return the provenance it wrote. */
30
33
  export declare function runScaffold(request: ScaffoldRequest, script?: string): Promise<MpoProvenance>;
31
34
  export interface T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