@theholocron/holocron-plugin-bruno 5.0.0-alpha.463 → 5.0.0-alpha.465
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/README.md +7 -6
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +43 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -28,11 +28,12 @@ providers: {
|
|
|
28
28
|
|
|
29
29
|
### Options
|
|
30
30
|
|
|
31
|
-
| Option | Required | Description
|
|
32
|
-
| ----------------- | -------- |
|
|
33
|
-
| `workspaceName` | No | The name Bruno shows for the `.bruno/` workspace `sync requests` keeps (default `Workspace`).
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
31
|
+
| Option | Required | Description |
|
|
32
|
+
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| `workspaceName` | No | The name Bruno shows for the `.bruno/` workspace `sync requests` keeps (default `Workspace`). |
|
|
34
|
+
| `version` | No | The `info.version` each collection's `opencollection.yml` gets when `sync requests` writes it (default: the root `package.json` version). |
|
|
35
|
+
| `collectionFiles` | Yes | The collection JSON files (v2.1), relative to the repo root. Each becomes one JSON file. |
|
|
36
|
+
| `envFiles` | No | The environment JSON files, relative to the repo root. A collection holds the ones in its own folder (all when none is there). |
|
|
36
37
|
|
|
37
38
|
## What it does
|
|
38
39
|
|
|
@@ -46,7 +47,7 @@ providers: {
|
|
|
46
47
|
file writer (`@usebruno/filestore`) and reader (`parseRequest`, `parseFolder`, `parseCollection`, `parseEnvironment`):
|
|
47
48
|
`workspace.yml` (made when missing; when it lacks a collection only that entry is added to its `collections:` list, so the
|
|
48
49
|
`docs`, `specs` and the other settings Bruno keeps there stay as they are), and one folder per collection under `collections/` holding `opencollection.yml`, a `folder.yml` per folder,
|
|
49
|
-
a YAML file per request and an `environments/` folder. A secret variable is written without its value. `.bruno/.sync.json`
|
|
50
|
+
a YAML file per request and an `environments/` folder. Each collection's `opencollection.yml` carries an `info.version`, the root package's version (or the `version` option), written whenever a run that is not a dry run or a check writes the file. It is left out of every comparison and hash, so a release never makes a file out of date or the check fail; it can lag a release behind until the next `sync requests`. A secret variable is written without its value. `.bruno/.sync.json`
|
|
50
51
|
records a hash of both sides of each pair at the last sync, so a run knows which side changed: the request file only
|
|
51
52
|
regenerates the workspace, the workspace only regenerates the request file (through `brunoToPostman`, with the request
|
|
52
53
|
file's untouched entries kept as they were), both is a `conflict` that writes nothing unless `prefer` (`source` or
|
package/dist/index.d.mts
CHANGED
|
@@ -14,6 +14,8 @@ interface BrunoToolingOptions {
|
|
|
14
14
|
envFiles?: string[];
|
|
15
15
|
/** The name Bruno shows for the `.bruno/` workspace that `workspace()` keeps (default `Workspace`). */
|
|
16
16
|
workspaceName?: string;
|
|
17
|
+
/** The `info.version` of each collection `workspace()` writes. Defaults to the version of the root `package.json`. */
|
|
18
|
+
version?: string;
|
|
17
19
|
/** Working repo root. Defaults to `process.cwd()`. */
|
|
18
20
|
repoRoot?: string;
|
|
19
21
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,27 @@ import { basename, dirname, extname, join, relative, resolve, sep } from "node:p
|
|
|
3
3
|
import { brunoToPostman, postmanToBruno, postmanToBrunoEnvironment } from "@usebruno/converters";
|
|
4
4
|
import { parseCollection, parseEnvironment, parseFolder, parseRequest, stringifyCollection, stringifyEnvironment, stringifyFolder, stringifyRequest } from "@usebruno/filestore";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
|
+
// src/collection-version.ts
|
|
7
|
+
/** The `version:` line of the `info:` block at the top of a collection's `opencollection.yml`. */
|
|
8
|
+
const VERSION_LINE = /^(info:\n(?: {2}[^\n]*\n)*?) {2}version: [^\n]*\n/m;
|
|
9
|
+
/** The collection file's text without its `info.version`, which is not part of what the sync compares or hashes. */
|
|
10
|
+
const stripVersion = (text) => text.replace(VERSION_LINE, "$1");
|
|
11
|
+
/**
|
|
12
|
+
* The collection file's text with `info.version` set to `version`, right after the name. A file whose `info:` block has
|
|
13
|
+
* no name on its second line is returned as it is, because its layout is not one the sync wrote.
|
|
14
|
+
*/
|
|
15
|
+
function withVersion(text, version) {
|
|
16
|
+
return stripVersion(text).replace(/^(info:\n {2}name: [^\n]*\n)/m, `$1 version: ${JSON.stringify(version)}\n`);
|
|
17
|
+
}
|
|
18
|
+
/** The `version` of the repo root's `package.json`, or `undefined` when there is no such file or it names none. */
|
|
19
|
+
async function rootVersion(repoRoot) {
|
|
20
|
+
try {
|
|
21
|
+
const { version } = JSON.parse(await readFile(join(repoRoot, "package.json"), "utf8"));
|
|
22
|
+
return typeof version === "string" && version !== "" ? version : void 0;
|
|
23
|
+
} catch {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
6
27
|
// src/describe-issue.ts
|
|
7
28
|
/** One line for a converter's issue, whatever shape it came in. */
|
|
8
29
|
const describeIssue = (issue) => {
|
|
@@ -614,7 +635,10 @@ async function readIfThere(path) {
|
|
|
614
635
|
throw err;
|
|
615
636
|
}
|
|
616
637
|
}
|
|
617
|
-
/**
|
|
638
|
+
/**
|
|
639
|
+
* Every `.yml` file below `dir` (empty when it is not there) with its text, by path from `dir` with `/` separators.
|
|
640
|
+
* The collection's own `opencollection.yml` is read without its `info.version`, which the sync keeps apart.
|
|
641
|
+
*/
|
|
618
642
|
async function ymlFilesBelow(dir) {
|
|
619
643
|
const files = /* @__PURE__ */ new Map();
|
|
620
644
|
let entries;
|
|
@@ -628,7 +652,10 @@ async function ymlFilesBelow(dir) {
|
|
|
628
652
|
throw err;
|
|
629
653
|
}
|
|
630
654
|
const paths = entries.filter((entry) => entry.isFile() && entry.name.endsWith(".yml")).map((entry) => relative(dir, join(entry.parentPath, entry.name)).split(sep).join("/")).filter((path) => !path.split("/").includes("node_modules")).sort();
|
|
631
|
-
for (const path of paths)
|
|
655
|
+
for (const path of paths) {
|
|
656
|
+
const text = await readFile(join(dir, path), "utf8");
|
|
657
|
+
files.set(path, path === "opencollection.yml" ? stripVersion(text) : text);
|
|
658
|
+
}
|
|
632
659
|
return files;
|
|
633
660
|
}
|
|
634
661
|
/** Removes `dir` and each parent up to `stop` while it is empty; a folder that still holds something stays. */
|
|
@@ -787,7 +814,10 @@ async function syncWorkspace(input) {
|
|
|
787
814
|
path: `${WORKSPACE_DIR}/${folder}/${path}`,
|
|
788
815
|
state: now === void 0 ? "new" : now === text ? "unchanged" : "changed"
|
|
789
816
|
});
|
|
790
|
-
if (now !== text)
|
|
817
|
+
if (now !== text) {
|
|
818
|
+
const versioned = path === "opencollection.yml" && input.version ? withVersion(text, input.version) : text;
|
|
819
|
+
plan.write(`${WORKSPACE_DIR}/${folder}/${path}`, versioned);
|
|
820
|
+
}
|
|
791
821
|
}
|
|
792
822
|
for (const path of currentRequests.keys()) {
|
|
793
823
|
if (generatedRequests.has(path)) continue;
|
|
@@ -834,6 +864,14 @@ async function syncWorkspace(input) {
|
|
|
834
864
|
}
|
|
835
865
|
}
|
|
836
866
|
}
|
|
867
|
+
if (input.version !== void 0 && direction !== "conflict") {
|
|
868
|
+
const own = `${WORKSPACE_DIR}/${folder}/opencollection.yml`;
|
|
869
|
+
const raw = await readIfThere(join(repoRoot, own));
|
|
870
|
+
if (raw !== void 0 && !plan.writes.has(own)) {
|
|
871
|
+
const desired = withVersion(raw, input.version);
|
|
872
|
+
if (desired !== raw) plan.write(own, desired);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
837
875
|
listed.push({
|
|
838
876
|
name,
|
|
839
877
|
path: folder
|
|
@@ -1118,10 +1156,12 @@ var BrunoTooling = class {
|
|
|
1118
1156
|
})))
|
|
1119
1157
|
});
|
|
1120
1158
|
}
|
|
1159
|
+
const version = this.options.version ?? await rootVersion(repoRoot);
|
|
1121
1160
|
return syncWorkspace({
|
|
1122
1161
|
workspaceName: this.options.workspaceName ?? "Workspace",
|
|
1123
1162
|
collections,
|
|
1124
1163
|
repoRoot,
|
|
1164
|
+
...version === void 0 ? {} : { version },
|
|
1125
1165
|
...input.dryRun ? { dryRun: true } : {},
|
|
1126
1166
|
...input.prefer ? { prefer: input.prefer } : {}
|
|
1127
1167
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-bruno",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.465",
|
|
4
4
|
"description": "Holocron plugin for Bruno. Implements the tooling capability over files: it exports the repo's request collections as Bruno JSON files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bruno",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
"tsx": "4.23.15",
|
|
45
45
|
"typescript": "^5.9.3",
|
|
46
46
|
"vitest": "^5.1.0",
|
|
47
|
-
"@theholocron/cli": "5.0.0-alpha.463",
|
|
48
47
|
"@theholocron/eslint-config": "^8.9.0-alpha.18",
|
|
48
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.18",
|
|
49
|
+
"@theholocron/cli": "5.0.0-alpha.465",
|
|
49
50
|
"@theholocron/tsconfig": "^8.9.0-alpha.18",
|
|
50
|
-
"@theholocron/tsdown-config": "^8.9.0-alpha.18"
|
|
51
|
-
"@theholocron/vitest-config": "^8.9.0-alpha.18"
|
|
51
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.18"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
54
|
+
"@theholocron/cli": "5.0.0-alpha.465"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=22"
|