bdy 1.25.18-master → 1.25.18

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.18-master",
4
+ "version": "1.25.18",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sandboxNameFromFetch = exports.sandboxSlug = void 0;
4
+ const sandbox_1 = require("../../types/sandbox");
5
+ // the API limit on identifier length is not documented, keep the derived part
6
+ // short so the timestamp suffix always fits
7
+ const MAX_SLUG = 40;
8
+ // identifier-safe form of a sandbox name (it must start and end with a letter
9
+ // or digit); empty when nothing usable is left
10
+ const sandboxSlug = (name) => name
11
+ .toLowerCase()
12
+ .replace(/[^a-z0-9_-]+/g, '-')
13
+ .replace(/^[-_]+/, '')
14
+ .substring(0, MAX_SLUG)
15
+ .replace(/[-_]+$/, '');
16
+ exports.sandboxSlug = sandboxSlug;
17
+ // a full commit sha is unreadable in a name, shorten it like git does
18
+ const shortRef = (ref) => ref && /^[0-9a-f]{40}$/i.test(ref) ? ref.substring(0, 7) : ref;
19
+ const repoName = (url) => {
20
+ const last = url.replace(/\/+$/, '').split(/[/:]/).pop() || '';
21
+ return last.replace(/\.git$/, '');
22
+ };
23
+ // Derives a readable sandbox name from the first --fetch entry, so a sandbox
24
+ // created for a repo or branch is recognisable on the list without -n.
25
+ // `project` is the project the sandbox is created in - pass null outside the
26
+ // project scope, a linked project there has nothing to do with the sandbox.
27
+ const sandboxNameFromFetch = (fetch, project) => {
28
+ const f = fetch?.[0];
29
+ if (!f)
30
+ return null;
31
+ let parts = [];
32
+ if (f.type === sandbox_1.SANDBOX_FETCH.PUBLIC_REPO && f.repository) {
33
+ parts = [repoName(f.repository), shortRef(f.ref)];
34
+ }
35
+ else if (f.type === sandbox_1.SANDBOX_FETCH.PROJECT_REPO && project) {
36
+ parts = [project, shortRef(f.ref)];
37
+ }
38
+ else if (f.type === sandbox_1.SANDBOX_FETCH.ARTIFACT && f.artifact) {
39
+ // artifact is given as name@version or name:version
40
+ parts = f.artifact.split(/[@:]/);
41
+ }
42
+ const name = parts.filter(Boolean).join(' ');
43
+ if (!(0, exports.sandboxSlug)(name))
44
+ return null;
45
+ return name;
46
+ };
47
+ exports.sandboxNameFromFetch = sandboxNameFromFetch;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.18-master",
4
+ "version": "1.25.18",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",