@multiplatform.one/cli 7.84.3 → 7.84.4
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/lib/source.json +2 -2
- package/lib/source.mjs +16 -2
- package/package.json +2 -2
- package/src/source.spec.ts +48 -0
- package/src/source.ts +18 -6
- package/types/source.d.ts +1 -0
- package/types/source.d.ts.map +1 -1
package/lib/source.json
CHANGED
package/lib/source.mjs
CHANGED
|
@@ -87,10 +87,24 @@ function classifySourceFailure(stderr) {
|
|
|
87
87
|
if (networkFailures.some((pattern) => pattern.test(stderr))) return "network";
|
|
88
88
|
return "unknown";
|
|
89
89
|
}
|
|
90
|
+
function stripRepositorySuffix(rest) {
|
|
91
|
+
const path = rest.length > 1 && rest.endsWith("/") ? rest.slice(0, -1) : rest;
|
|
92
|
+
return path.length > 4 && path.toLowerCase().endsWith(".git") ? path.slice(0, -4) : path;
|
|
93
|
+
}
|
|
94
|
+
/** The repository path in an https/ssh URL or an scp-style git address, without `.git`. */
|
|
95
|
+
function pathAfter(url, prefix) {
|
|
96
|
+
if (!prefix || url.length === prefix.length) return void 0;
|
|
97
|
+
const rest = url.slice(prefix.length);
|
|
98
|
+
return /[\n\r\u2028\u2029]/.test(rest) ? void 0 : stripRepositorySuffix(rest);
|
|
99
|
+
}
|
|
100
|
+
function repositoryPath(url) {
|
|
101
|
+
const urlPrefix = /^[a-z+]+:\/\/(?:[^@/]*@)?[^/:]+(?::\d+)?\//i.exec(url)?.[0];
|
|
102
|
+
return pathAfter(url, urlPrefix) ?? pathAfter(url, /^[^@]+@[^:]+:/.exec(url)?.[0]);
|
|
103
|
+
}
|
|
90
104
|
var SourceAccessError = class extends Error {
|
|
91
105
|
constructor(url, kind, gitOutput, reason) {
|
|
92
106
|
const host = /^[a-z]+:\/\/(?:[^@/]*@)?([^/:]+)/i.exec(url)?.[1] ?? /@([^:]+):/.exec(url)?.[1];
|
|
93
|
-
const corpPath = host === corpHost ?
|
|
107
|
+
const corpPath = host === corpHost ? repositoryPath(url) : void 0;
|
|
94
108
|
const lines = kind === "network" ? [`Cannot reach the source repository ${url}${reason ? `: ${reason}` : ""}.`, `The CLI scaffolds from this git repository, so it needs a network path to ${host ?? "its host"} (check the connection, proxy or VPN).`] : [
|
|
95
109
|
`Cannot read the source repository ${url}${kind === "auth" ? ": access denied" : ""}.`,
|
|
96
110
|
...kind === "auth" && corpPath ? [`You need read access to ${corpPath} on ${corpHost}; ask the project owner.`] : [],
|
|
@@ -161,4 +175,4 @@ async function checkSourceAccess(source, { timeoutMs = 3e4 } = {}) {
|
|
|
161
175
|
}
|
|
162
176
|
|
|
163
177
|
//#endregion
|
|
164
|
-
export { SourceAccessError, checkSourceAccess, classifySourceFailure, isGitUrl, monorepoCheckout, monorepoUrl, readSourceStamp, resolveSource };
|
|
178
|
+
export { SourceAccessError, checkSourceAccess, classifySourceFailure, isGitUrl, monorepoCheckout, monorepoUrl, readSourceStamp, repositoryPath, resolveSource };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/cli",
|
|
3
|
-
"version": "7.84.
|
|
3
|
+
"version": "7.84.4",
|
|
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": "^7.84.
|
|
60
|
+
"@multiplatform.one/utils": "^7.84.4",
|
|
61
61
|
"commander": "^15.0.0",
|
|
62
62
|
"dotenv": "^17.4.2",
|
|
63
63
|
"inquirer": "^14.2.3",
|
package/src/source.spec.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
classifySourceFailure,
|
|
13
13
|
isGitUrl,
|
|
14
14
|
monorepoCheckout,
|
|
15
|
+
repositoryPath,
|
|
15
16
|
resolveSource,
|
|
16
17
|
SourceAccessError,
|
|
17
18
|
} from "./source";
|
|
@@ -229,3 +230,50 @@ describe("classifySourceFailure", () => {
|
|
|
229
230
|
expect(classifySourceFailure("fatal: something else went wrong")).toBe("unknown");
|
|
230
231
|
});
|
|
231
232
|
});
|
|
233
|
+
|
|
234
|
+
describe("repositoryPath", () => {
|
|
235
|
+
const oracle = (url: string) =>
|
|
236
|
+
/^(?:[a-z+]+:\/\/(?:[^@/]*@)?[^/:]+(?::\d+)?\/|[^@]+@[^:]+:)(.+?)(?:\.git)?\/?$/i.exec(
|
|
237
|
+
url,
|
|
238
|
+
)?.[1];
|
|
239
|
+
|
|
240
|
+
it.each([
|
|
241
|
+
["https://git.corp.bitspur.com/multiplatform.one/mpo.git", "multiplatform.one/mpo"],
|
|
242
|
+
["https://git.corp.bitspur.com/multiplatform.one/mpo", "multiplatform.one/mpo"],
|
|
243
|
+
["https://git.corp.bitspur.com/multiplatform.one/mpo/", "multiplatform.one/mpo"],
|
|
244
|
+
["https://git.corp.bitspur.com/multiplatform.one/mpo.git/", "multiplatform.one/mpo"],
|
|
245
|
+
["https://oauth2:tok@git.corp.bitspur.com/a/b.git", "a/b"],
|
|
246
|
+
["https://git.corp.bitspur.com:8443/a/b.git", "a/b"],
|
|
247
|
+
["ssh://git@git.corp.bitspur.com/a/b.git", "a/b"],
|
|
248
|
+
["ssh://git@git.corp.bitspur.com:2222/a/b.git", "a/b"],
|
|
249
|
+
["git+ssh://git@git.corp.bitspur.com/a/b", "a/b"],
|
|
250
|
+
["git@git.corp.bitspur.com:multiplatform.one/mpo.git", "multiplatform.one/mpo"],
|
|
251
|
+
["git@git.corp.bitspur.com:multiplatform.one/mpo", "multiplatform.one/mpo"],
|
|
252
|
+
["git@git.corp.bitspur.com:multiplatform.one/mpo/", "multiplatform.one/mpo"],
|
|
253
|
+
["ssh://git@host:group/repo.git", "group/repo"],
|
|
254
|
+
["https://x@y:1/", "1"],
|
|
255
|
+
["https://host/", undefined],
|
|
256
|
+
["https://host", undefined],
|
|
257
|
+
["git@host:", undefined],
|
|
258
|
+
["https://host//", "/"],
|
|
259
|
+
["https://host/.git", ".git"],
|
|
260
|
+
["https://host/.git/", ".git"],
|
|
261
|
+
["https://host/a//", "a/"],
|
|
262
|
+
["https://host/a.git.git", "a.git"],
|
|
263
|
+
["https://host/a.git//", "a.git/"],
|
|
264
|
+
["https://host//.git", "/"],
|
|
265
|
+
["HTTPS://HOST/A/B.GIT", "A/B"],
|
|
266
|
+
["https://host/a/b.Git/", "a/b"],
|
|
267
|
+
["https://u:p@host/a/b", "a/b"],
|
|
268
|
+
["https://a@b@c/x.git", "x"],
|
|
269
|
+
["/local/path/mpo", undefined],
|
|
270
|
+
["mpo", undefined],
|
|
271
|
+
["", undefined],
|
|
272
|
+
["https://host/a\nb", undefined],
|
|
273
|
+
["u@h:a\rb", undefined],
|
|
274
|
+
["https://host/a\u2028", undefined],
|
|
275
|
+
])("reads %j as %j, as the single regex did", (url, expected) => {
|
|
276
|
+
expect(repositoryPath(url)).toBe(expected);
|
|
277
|
+
expect(repositoryPath(url)).toBe(oracle(url));
|
|
278
|
+
});
|
|
279
|
+
});
|
package/src/source.ts
CHANGED
|
@@ -122,18 +122,30 @@ export function classifySourceFailure(stderr: string): SourceFailure {
|
|
|
122
122
|
return "unknown";
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
function stripRepositorySuffix(rest: string): string {
|
|
126
|
+
const path = rest.length > 1 && rest.endsWith("/") ? rest.slice(0, -1) : rest;
|
|
127
|
+
return path.length > 4 && path.toLowerCase().endsWith(".git") ? path.slice(0, -4) : path;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The repository path in an https/ssh URL or an scp-style git address, without `.git`. */
|
|
131
|
+
function pathAfter(url: string, prefix: string | undefined): string | undefined {
|
|
132
|
+
if (!prefix || url.length === prefix.length) return undefined;
|
|
133
|
+
const rest = url.slice(prefix.length);
|
|
134
|
+
return /[\n\r\u2028\u2029]/.test(rest) ? undefined : stripRepositorySuffix(rest);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function repositoryPath(url: string): string | undefined {
|
|
138
|
+
const urlPrefix = /^[a-z+]+:\/\/(?:[^@/]*@)?[^/:]+(?::\d+)?\//i.exec(url)?.[0];
|
|
139
|
+
return pathAfter(url, urlPrefix) ?? pathAfter(url, /^[^@]+@[^:]+:/.exec(url)?.[0]);
|
|
140
|
+
}
|
|
141
|
+
|
|
125
142
|
export class SourceAccessError extends Error {
|
|
126
143
|
readonly url: string;
|
|
127
144
|
readonly kind: SourceFailure;
|
|
128
145
|
readonly gitOutput: string;
|
|
129
146
|
constructor(url: string, kind: SourceFailure, gitOutput: string, reason?: string) {
|
|
130
147
|
const host = /^[a-z]+:\/\/(?:[^@/]*@)?([^/:]+)/i.exec(url)?.[1] ?? /@([^:]+):/.exec(url)?.[1];
|
|
131
|
-
const corpPath =
|
|
132
|
-
host === corpHost
|
|
133
|
-
? /^(?:[a-z+]+:\/\/(?:[^@/]*@)?[^/:]+(?::\d+)?\/|[^@]+@[^:]+:)(.+?)(?:\.git)?\/?$/i.exec(
|
|
134
|
-
url,
|
|
135
|
-
)?.[1]
|
|
136
|
-
: undefined;
|
|
148
|
+
const corpPath = host === corpHost ? repositoryPath(url) : undefined;
|
|
137
149
|
const lines =
|
|
138
150
|
kind === "network"
|
|
139
151
|
? [
|
package/types/source.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare function resolveSource(flags?: {
|
|
|
35
35
|
export type SourceFailure = "auth" | "network" | "unknown";
|
|
36
36
|
/** What a failed `git ls-remote` says about why the source is unreadable. */
|
|
37
37
|
export declare function classifySourceFailure(stderr: string): SourceFailure;
|
|
38
|
+
export declare function repositoryPath(url: string): string | undefined;
|
|
38
39
|
export declare class SourceAccessError extends Error {
|
|
39
40
|
readonly url: string;
|
|
40
41
|
readonly kind: SourceFailure;
|
package/types/source.d.ts.map
CHANGED
|
@@ -1 +1 @@
|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