@cluerise/tools 4.2.1 → 5.0.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.
@@ -9,19 +9,19 @@ class GitProvider {
9
9
  static #origins = gitProviderOrigins;
10
10
  static #names = Object.keys(this.#origins);
11
11
  /**
12
- * Checks if the provided name is a valid Git provider name.
12
+ * Check if the provided name is a valid Git provider name.
13
13
  *
14
- * @param name - The name of the Git provider to validate.
15
- * @returns True if the name is valid, false otherwise.
14
+ * @param name The name to check.
15
+ * @returns True if the name is valid, otherwise false.
16
16
  */
17
17
  static isValidName(name) {
18
18
  return this.#names.includes(name);
19
19
  }
20
20
  /**
21
- * Returns a Git provider origin.
21
+ * Get the origin URL for the given Git provider name.
22
22
  *
23
- * @param name - The name of the Git provider.
24
- * @returns The origin URL of the Git provider.
23
+ * @param name The Git provider name.
24
+ * @returns The origin URL.
25
25
  */
26
26
  static getOrigin(name) {
27
27
  return this.#origins[name];
@@ -48,6 +48,13 @@ class PackageJson {
48
48
  constructor(data) {
49
49
  this.#data = data;
50
50
  }
51
+ /**
52
+ * Load and parse the `package.json` file, returning a `PackageJson` instance.
53
+ *
54
+ * Throws an error if the file is invalid or cannot be parsed.
55
+ *
56
+ * @returns A new `PackageJson` instance with parsed data.
57
+ */
51
58
  static async init() {
52
59
  const content = await FileSystem.readFile("package.json", { encoding: "utf8" });
53
60
  const data = JsonUtils.parse(content);
@@ -60,21 +67,41 @@ class PackageJson {
60
67
  return new PackageJson(data);
61
68
  }
62
69
  /**
63
- * Returns the required engines.
70
+ * Get the package name from `package.json`.
71
+ *
72
+ * @returns The package name.
73
+ */
74
+ get name() {
75
+ return this.#data.name;
76
+ }
77
+ /**
78
+ * Get the package version from `package.json`.
79
+ *
80
+ * @returns The package version.
81
+ */
82
+ get version() {
83
+ return this.#data.version;
84
+ }
85
+ /**
86
+ * Get the engines field from `package.json`, if present.
87
+ *
88
+ * @returns The engines object or undefined.
64
89
  */
65
90
  get engines() {
66
91
  return this.#data.engines;
67
92
  }
68
93
  /**
69
- * Sets the required engines.
94
+ * Set the engines field in `package.json`.
70
95
  *
71
- * @param engines - The engines to set.
96
+ * @param engines The engines object to set.
72
97
  */
73
98
  set engines(engines) {
74
99
  this.#data.engines = engines;
75
100
  }
76
101
  /**
77
- * Returns the repository information.
102
+ * Get the repository field from `package.json`, if present.
103
+ *
104
+ * @returns The repository object or string, or undefined.
78
105
  */
79
106
  get repository() {
80
107
  return this.#data.repository;
@@ -111,9 +138,11 @@ class PackageJson {
111
138
  throw new Error("Unsupported repository URL");
112
139
  }
113
140
  /**
114
- * Parses the repository information from package.json.
141
+ * Parse the repository information from `package.json` and return a `GitRepository` object or null.
142
+ *
143
+ * Returns null if no repository is defined or if parsing fails.
115
144
  *
116
- * @returns The parsed GitRepository or null if no repository is defined.
145
+ * @returns The parsed `GitRepository`, or null if not available.
117
146
  */
118
147
  parseGitRepository() {
119
148
  if (!this.repository) {
@@ -125,7 +154,7 @@ class PackageJson {
125
154
  return this.#parseGitRepository(this.repository.url);
126
155
  }
127
156
  /**
128
- * Saves the package.json file with the current data.
157
+ * Save the current `package.json` data to disk, formatting it as prettified JSON.
129
158
  */
130
159
  async save() {
131
160
  const content = JsonUtils.prettify(this.#data) + "\n";
@@ -176,7 +205,7 @@ const nodeJsReleaseSchema = z.object({
176
205
  class NodeJs {
177
206
  static #releasesUrl = "https://nodejs.org/dist/index.json";
178
207
  /**
179
- * Fetches all Node.js releases.
208
+ * Fetch all Node.js releases.
180
209
  *
181
210
  * @returns A promise that resolves to an array of NodeJsRelease objects.
182
211
  */
@@ -186,7 +215,7 @@ class NodeJs {
186
215
  return z.array(nodeJsReleaseSchema).parse(data);
187
216
  }
188
217
  /**
189
- * Fetches the latest Node.js release.
218
+ * Fetch the latest Node.js release.
190
219
  *
191
220
  * @returns A promise that resolves to the latest NodeJsRelease object or null if no releases are found.
192
221
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cluerise/tools",
3
- "version": "4.2.1",
3
+ "version": "5.0.0",
4
4
  "description": "Tools for maintaining TypeScript projects.",
5
5
  "author": "Branislav Holý <brano@holy.am>",
6
6
  "repository": "github:cluerise/tools",
@@ -31,9 +31,9 @@
31
31
  "conventional-changelog-conventionalcommits": "9.0.0",
32
32
  "eslint": "9.29.0",
33
33
  "eslint-config-prettier": "10.1.5",
34
- "eslint-import-resolver-typescript": "4.4.3",
34
+ "eslint-import-resolver-typescript": "4.4.4",
35
35
  "eslint-plugin-import": "2.32.0",
36
- "eslint-plugin-prettier": "5.5.0",
36
+ "eslint-plugin-prettier": "5.5.1",
37
37
  "eslint-plugin-simple-import-sort": "12.1.1",
38
38
  "eslint-plugin-unicorn": "59.0.1",
39
39
  "eslint-plugin-yml": "1.18.0",
@@ -41,7 +41,7 @@
41
41
  "globals": "16.2.0",
42
42
  "lint-staged": "16.1.2",
43
43
  "prettier": "3.6.1",
44
- "prettier-plugin-sh": "0.17.4",
44
+ "prettier-plugin-sh": "0.18.0",
45
45
  "semantic-release": "24.2.5",
46
46
  "semver": "7.7.2",
47
47
  "smol-toml": "1.3.4",