@theholocron/holocron-plugin-bruno 5.0.0-alpha.452 → 5.0.0-alpha.453

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 CHANGED
@@ -28,16 +28,18 @@ providers: {
28
28
 
29
29
  ### Options
30
30
 
31
- | Option | Required | Description |
32
- | ----------------- | -------- | --------------------------------------------------------------------------------------------------- |
33
- | `collectionFiles` | Yes | The collection JSON files (v2.1), relative to the repo root. Each becomes one YAML file. |
34
- | `envFiles` | No | The environment JSON files, relative to the repo root. Every exported collection holds all of them. |
31
+ | Option | Required | Description |
32
+ | ----------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
33
+ | `collectionFiles` | Yes | The collection JSON files (v2.1), relative to the repo root. Each becomes one YAML file. |
34
+ | `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). |
35
35
 
36
36
  ## What it does
37
37
 
38
38
  - `export` converts each collection with Bruno's collection reader (`@usebruno/converters`, which rewrites `pm.*` scripts to
39
39
  `bru.*` / `req.*`) and the OpenCollection writer (`@opencollection/converters`), dumped with `js-yaml`, and writes
40
40
  `<name>.yml` under the folder it is given. Environments are inside the document; a secret-type variable is marked `transient`.
41
+ The same collection is also written as `<name>.bruno.json`, Bruno's own collection export with the environments inside,
42
+ which is the file to import in Bruno (one file for the requests and the environments).
41
43
  Converter issues are returned, not thrown. A dry run converts and writes nothing.
42
44
  - `sync` does nothing and succeeds: Bruno keeps no state, and the files are written by `export`.
43
45
  - `doctor` checks `collectionFiles` is set and every file exists and parses as JSON.
package/dist/index.d.mts CHANGED
@@ -10,7 +10,7 @@ import { Tooling, ToolingDoctorReport, ToolingExportInput, ToolingExportResult }
10
10
  interface BrunoToolingOptions {
11
11
  /** Collection JSON files (v2.1), relative to `repoRoot`. */
12
12
  collectionFiles?: string[];
13
- /** Environment JSON files, relative to `repoRoot`; each goes into every exported collection. */
13
+ /** Environment JSON files, relative to `repoRoot`; each goes into every collection it is exported with (`export requests` hands a folder's collections the files beside them). */
14
14
  envFiles?: string[];
15
15
  /** Working repo root. Defaults to `process.cwd()`. */
16
16
  repoRoot?: string;
@@ -33,6 +33,8 @@ export declare class BrunoTooling implements Tooling {
33
33
  interface ConvertedCollection {
34
34
  /** The OpenCollection document, as YAML. */
35
35
  text: string;
36
+ /** The same collection as one Bruno JSON file, environments inside, which Bruno's collection import reads. */
37
+ json: string;
36
38
  /** What the converters reported they could not carry across, one line each. */
37
39
  issues: string[];
38
40
  }
@@ -44,11 +46,11 @@ interface ConvertedCollection {
44
46
  */
45
47
  export declare function convertCollection(collection: unknown, environments: unknown[]): Promise<ConvertedCollection>;
46
48
  /**
47
- * The YAML file name for each collection file, in order: its own name with `.yml` for `.json` (`collection.json` is
48
- * `collection.yml`). Two files with the same name would overwrite each other, so those use the whole path instead,
49
- * its folders joined with `-` (`apps-a-collection.yml`).
49
+ * The output file name for each collection file, in order: its own name with `extension` in place of `.json`
50
+ * (`collection.json` is `collection.yml` for `.yml`). Two files with the same name would overwrite each other, so those
51
+ * use the whole path instead, its folders joined with `-` (`apps-a-collection.yml`).
50
52
  */
51
- export declare function outputNames(files: string[]): string[];
53
+ export declare function outputNames(files: string[], extension?: string): string[];
52
54
  /** Options for the Bruno plugin; the same as the `tooling` capability's. */
53
55
  export type BrunoPluginOptions = BrunoToolingOptions;
54
56
  /** Builds the `tooling` capability from the plugin options. */
package/dist/index.mjs CHANGED
@@ -10,6 +10,24 @@ const describeIssue = (issue) => {
10
10
  if (issue !== null && typeof issue === "object" && "message" in issue && typeof issue.message === "string") return issue.message;
11
11
  return JSON.stringify(issue);
12
12
  };
13
+ /** The collection as Bruno's own JSON export lays it out: one file, with the environments inside it. */
14
+ function brunoJson(bruno) {
15
+ const environments = (bruno.environments ?? []).map(({ filename: _filename, ...env }) => env);
16
+ const exported = {
17
+ name: bruno.name,
18
+ version: "1",
19
+ items: bruno.items,
20
+ environments,
21
+ root: bruno.root,
22
+ brunoConfig: {
23
+ version: "1",
24
+ name: bruno.name,
25
+ type: "collection",
26
+ ignore: ["node_modules", ".git"]
27
+ }
28
+ };
29
+ return `${JSON.stringify(exported, null, 2)}\n`;
30
+ }
13
31
  /**
14
32
  * Converts one v2.1 collection (and the environments that go with it) to an OpenCollection YAML document: Bruno's
15
33
  * reader turns it into a Bruno collection and rewrites its `pm.*` scripts to `bru.*` / `req.*`, then the OpenCollection
@@ -26,22 +44,23 @@ async function convertCollection(collection, environments) {
26
44
  }));
27
45
  return {
28
46
  text: dump(brunoToOpenCollection(bruno), { lineWidth: 120 }),
47
+ json: brunoJson(bruno),
29
48
  issues: (read.issues ?? []).map(describeIssue)
30
49
  };
31
50
  }
32
51
  // src/output-names.ts
33
52
  /**
34
- * The YAML file name for each collection file, in order: its own name with `.yml` for `.json` (`collection.json` is
35
- * `collection.yml`). Two files with the same name would overwrite each other, so those use the whole path instead,
36
- * its folders joined with `-` (`apps-a-collection.yml`).
53
+ * The output file name for each collection file, in order: its own name with `extension` in place of `.json`
54
+ * (`collection.json` is `collection.yml` for `.yml`). Two files with the same name would overwrite each other, so those
55
+ * use the whole path instead, its folders joined with `-` (`apps-a-collection.yml`).
37
56
  */
38
- function outputNames(files) {
57
+ function outputNames(files, extension = ".yml") {
39
58
  const stem = (file) => basename(file, extname(file));
40
59
  const counts = /* @__PURE__ */ new Map();
41
60
  for (const file of files) counts.set(stem(file), (counts.get(stem(file)) ?? 0) + 1);
42
61
  return files.map((file) => {
43
- if (counts.get(stem(file)) === 1) return `${stem(file)}.yml`;
44
- return `${file.slice(0, file.length - extname(file).length).split("/").filter(Boolean).join("-")}.yml`;
62
+ if (counts.get(stem(file)) === 1) return `${stem(file)}${extension}`;
63
+ return `${file.slice(0, file.length - extname(file).length).split("/").filter(Boolean).join("-")}${extension}`;
45
64
  });
46
65
  }
47
66
  // src/capabilities/tooling.ts
@@ -50,7 +69,8 @@ function outputNames(files) {
50
69
  *
51
70
  * Bruno has no HTTP API and no account to push to: it reads a folder of files. So this provider works on files only,
52
71
  * with no token and no network, and its one real job is `export()`: it writes each of the repo's collection files as
53
- * an OpenCollection YAML document (with the environments inside it), for `holocron export requests`.
72
+ * an OpenCollection YAML document and a Bruno JSON file, each with the environments inside it, for
73
+ * `holocron export requests`.
54
74
  *
55
75
  * `sync()` has nothing to reconcile, so it does nothing and succeeds: `holocron setup` calls it on every `tooling`
56
76
  * provider, and the files are written by `export()`, which is the person's call, never a side effect of `setup`.
@@ -105,6 +125,7 @@ var BrunoTooling = class {
105
125
  const { collectionFiles, envFiles, outDir, repoRoot } = input;
106
126
  const environments = await Promise.all(envFiles.map((file) => readJson(repoRoot, file)));
107
127
  const names = outputNames(collectionFiles);
128
+ const jsonNames = outputNames(collectionFiles, ".bruno.json");
108
129
  const files = [];
109
130
  const issues = [];
110
131
  for (const [index, file] of collectionFiles.entries()) {
@@ -116,11 +137,13 @@ var BrunoTooling = class {
116
137
  message: issue
117
138
  });
118
139
  const name = names[index];
140
+ const jsonName = jsonNames[index];
119
141
  if (!input.dryRun) {
120
142
  await mkdir(outDir, { recursive: true });
121
143
  await writeFile(join(outDir, name), converted.text);
144
+ await writeFile(join(outDir, jsonName), converted.json);
122
145
  }
123
- files.push(name);
146
+ files.push(name, jsonName);
124
147
  }
125
148
  return {
126
149
  files,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-bruno",
3
- "version": "5.0.0-alpha.452",
3
+ "version": "5.0.0-alpha.453",
4
4
  "description": "Holocron plugin for Bruno. Implements the tooling capability over files: it exports the repo's request collections as OpenCollection YAML.",
5
5
  "keywords": [
6
6
  "bruno",
@@ -45,14 +45,14 @@
45
45
  "tsx": "4.23.15",
46
46
  "typescript": "^5.9.3",
47
47
  "vitest": "^5.1.0",
48
- "@theholocron/cli": "5.0.0-alpha.452",
49
- "@theholocron/eslint-config": "^8.9.0-alpha.17",
50
- "@theholocron/tsconfig": "^8.9.0-alpha.17",
51
- "@theholocron/tsdown-config": "^8.9.0-alpha.17",
52
- "@theholocron/vitest-config": "^8.9.0-alpha.17"
48
+ "@theholocron/cli": "5.0.0-alpha.453",
49
+ "@theholocron/tsconfig": "^8.9.0-alpha.18",
50
+ "@theholocron/eslint-config": "^8.9.0-alpha.18",
51
+ "@theholocron/tsdown-config": "^8.9.0-alpha.18",
52
+ "@theholocron/vitest-config": "^8.9.0-alpha.18"
53
53
  },
54
54
  "peerDependencies": {
55
- "@theholocron/cli": "5.0.0-alpha.452"
55
+ "@theholocron/cli": "5.0.0-alpha.453"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=22"