@tallyrelease/plugins 0.0.0-stage → 0.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.
- package/LICENSE +202 -0
- package/README.md +4 -2
- package/dist/_kit/edges.d.ts +11 -0
- package/dist/_kit/edges.js +22 -0
- package/dist/_kit/manifest.d.ts +5 -0
- package/dist/_kit/manifest.js +19 -0
- package/dist/_kit/paths.d.ts +6 -0
- package/dist/_kit/paths.js +6 -0
- package/dist/_kit/semver.d.ts +6 -0
- package/dist/_kit/semver.js +6 -0
- package/dist/builtin.d.ts +2 -0
- package/dist/builtin.js +14 -0
- package/dist/changesets/plugin.d.ts +5 -0
- package/dist/changesets/plugin.js +95 -0
- package/dist/dart/plugin.d.ts +3 -0
- package/dist/dart/plugin.js +98 -0
- package/dist/go/plugin.d.ts +1 -0
- package/dist/go/plugin.js +118 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/kustomize/plugin.d.ts +3 -0
- package/dist/kustomize/plugin.js +170 -0
- package/dist/node/plugin.d.ts +1 -0
- package/dist/node/plugin.js +120 -0
- package/dist/php/plugin.d.ts +1 -0
- package/dist/php/plugin.js +59 -0
- package/package.json +71 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tallyrelease/plugins
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Built-in ecosystem plugins (`node`, `php`, `kustomize`, `dart`) of [tallyrelease](https://github.com/abinnovision/tallyrelease). They are pure: files are read only through the `Ctx` that `@tallyrelease/core` injects.
|
|
4
|
+
|
|
5
|
+
Most users want [`@tallyrelease/cli`](https://www.npmjs.com/package/@tallyrelease/cli) instead, which bundles these plugins.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EdgeDraft, Unit } from "@tallyrelease/core";
|
|
2
|
+
/** Units of `plugin` keyed by package name; `onDuplicate` sees each shadowed unit. */
|
|
3
|
+
export declare const unitsByPackage: (units: readonly Unit[], plugin: string, onDuplicate?: (name: string, prior: Unit, next: Unit) => void) => Map<string, Unit>;
|
|
4
|
+
/** The edge `from` -> `to`; empty when `from` is unknown or the same unit. */
|
|
5
|
+
export declare const edgeBetween: (from: Unit | undefined, to: Unit, link: Pick<EdgeDraft, "reason" | "pinned">) => EdgeDraft[];
|
|
6
|
+
/** Edges for each entry of `deps` that names a unit in `byName`; `exact` marks pinned ranges. */
|
|
7
|
+
export declare const dependencyEdges: (byName: ReadonlyMap<string, Unit>, to: Unit, { field, deps, exact, }: {
|
|
8
|
+
field: string;
|
|
9
|
+
deps: Record<string, string>;
|
|
10
|
+
exact: RegExp | undefined;
|
|
11
|
+
}) => EdgeDraft[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Units of `plugin` keyed by package name; `onDuplicate` sees each shadowed unit. */
|
|
2
|
+
export const unitsByPackage = (units, plugin, onDuplicate) => {
|
|
3
|
+
const byName = new Map();
|
|
4
|
+
for (const unit of units) {
|
|
5
|
+
const name = unit.meta[plugin]?.["packageName"];
|
|
6
|
+
if (unit.plugin === plugin && typeof name === "string") {
|
|
7
|
+
const prior = byName.get(name);
|
|
8
|
+
if (prior) {
|
|
9
|
+
onDuplicate?.(name, prior, unit);
|
|
10
|
+
}
|
|
11
|
+
byName.set(name, unit);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return byName;
|
|
15
|
+
};
|
|
16
|
+
/** The edge `from` -> `to`; empty when `from` is unknown or the same unit. */
|
|
17
|
+
export const edgeBetween = (from, to, link) => from && from.id !== to.id ? [{ from: from.id, to: to.id, ...link }] : [];
|
|
18
|
+
/** Edges for each entry of `deps` that names a unit in `byName`; `exact` marks pinned ranges. */
|
|
19
|
+
export const dependencyEdges = (byName, to, { field, deps, exact, }) => Object.entries(deps).flatMap(([name, range]) => edgeBetween(byName.get(name), to, {
|
|
20
|
+
reason: `${field}: ${name}`,
|
|
21
|
+
pinned: exact?.test(range) ?? false,
|
|
22
|
+
}));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Ctx } from "@tallyrelease/core";
|
|
2
|
+
/** Parses a JSON manifest; a syntax error names the file. */
|
|
3
|
+
export declare const parseJson: (path: string, raw: string) => unknown;
|
|
4
|
+
/** Reads and parses `file` inside unit `root`; undefined when it is missing. */
|
|
5
|
+
export declare const readManifest: (ctx: Pick<Ctx, "fs">, root: string, file: string) => Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { joinRoot } from "./paths.js";
|
|
2
|
+
/** Parses a JSON manifest; a syntax error names the file. */
|
|
3
|
+
export const parseJson = (path, raw) => {
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(raw);
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
9
|
+
throw new Error(`invalid JSON in ${path}: ${reason}`, { cause: error });
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/** Reads and parses `file` inside unit `root`; undefined when it is missing. */
|
|
13
|
+
export const readManifest = (ctx, root, file) => {
|
|
14
|
+
const path = joinRoot(root, file);
|
|
15
|
+
const raw = ctx.fs.read(path);
|
|
16
|
+
return raw === undefined
|
|
17
|
+
? undefined
|
|
18
|
+
: parseJson(path, raw);
|
|
19
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Repo-relative path of `file` inside unit `root` (`.` is the repo root). */
|
|
2
|
+
export declare const joinRoot: (root: string, file: string) => string;
|
|
3
|
+
/** Glob for `file` inside `dir`, ignoring trailing slashes on `dir`. */
|
|
4
|
+
export declare const globIn: (dir: string, file: string) => string;
|
|
5
|
+
/** Unit root of a matched `<root>/<file>` path. */
|
|
6
|
+
export declare const rootOf: (path: string, file: string) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Repo-relative path of `file` inside unit `root` (`.` is the repo root). */
|
|
2
|
+
export const joinRoot = (root, file) => root === "." ? file : `${root}/${file}`;
|
|
3
|
+
/** Glob for `file` inside `dir`, ignoring trailing slashes on `dir`. */
|
|
4
|
+
export const globIn = (dir, file) => `${dir.replace(/\/+$/, "")}/${file}`;
|
|
5
|
+
/** Unit root of a matched `<root>/<file>` path. */
|
|
6
|
+
export const rootOf = (path, file) => path.slice(0, -`/${file}`.length);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Regex source for `major.minor.patch`. */
|
|
2
|
+
export declare const NUMBERS: string;
|
|
3
|
+
/** Regex source for an optional `-prerelease` suffix. */
|
|
4
|
+
export declare const PRERELEASE: string;
|
|
5
|
+
/** Regex source for an optional `+build` suffix. */
|
|
6
|
+
export declare const BUILD: string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Regex source for `major.minor.patch`. */
|
|
2
|
+
export const NUMBERS = String.raw `\d+\.\d+\.\d+`;
|
|
3
|
+
/** Regex source for an optional `-prerelease` suffix. */
|
|
4
|
+
export const PRERELEASE = String.raw `(?:-[0-9A-Za-z.-]+)?`;
|
|
5
|
+
/** Regex source for an optional `+build` suffix. */
|
|
6
|
+
export const BUILD = String.raw `(?:\+[0-9A-Za-z.-]+)?`;
|
package/dist/builtin.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { changesetsPlugin } from "./changesets/plugin.js";
|
|
2
|
+
import { dartPlugin } from "./dart/plugin.js";
|
|
3
|
+
import { goPlugin } from "./go/plugin.js";
|
|
4
|
+
import { kustomizePlugin } from "./kustomize/plugin.js";
|
|
5
|
+
import { nodePlugin } from "./node/plugin.js";
|
|
6
|
+
import { phpPlugin } from "./php/plugin.js";
|
|
7
|
+
export const builtinPlugins = {
|
|
8
|
+
node: nodePlugin,
|
|
9
|
+
php: phpPlugin,
|
|
10
|
+
go: goPlugin,
|
|
11
|
+
kustomize: kustomizePlugin,
|
|
12
|
+
dart: dartPlugin,
|
|
13
|
+
changesets: changesetsPlugin,
|
|
14
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { definePlugin } from "@tallyrelease/core";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
const FRONTMATTER = /^\uFEFF?\s*---[ \t]*\r?\n(?:([\s\S]*?)\r?\n)?---[ \t]*(?:\r?\n|$)([\s\S]*)$/;
|
|
5
|
+
const KINDS = new Map([
|
|
6
|
+
["major", { type: "feat", breaking: true }],
|
|
7
|
+
["minor", { type: "feat", breaking: false }],
|
|
8
|
+
["patch", { type: "fix", breaking: false }],
|
|
9
|
+
]);
|
|
10
|
+
/** Unit id by unit id, then by any `meta.*.packageName`. */
|
|
11
|
+
const unitKeys = (units) => {
|
|
12
|
+
const keys = new Map(units.map((u) => [u.id, u.id]));
|
|
13
|
+
for (const unit of units) {
|
|
14
|
+
for (const meta of Object.values(unit.meta)) {
|
|
15
|
+
const name = meta["packageName"];
|
|
16
|
+
if (typeof name === "string" && !keys.has(name)) {
|
|
17
|
+
keys.set(name, unit.id);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return keys;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Changes of one changeset, one per bump level; none without frontmatter,
|
|
25
|
+
* which warns except for `README.md`.
|
|
26
|
+
*/
|
|
27
|
+
const changesOf = (ctx, path, keys) => {
|
|
28
|
+
const content = ctx.fs.read(path);
|
|
29
|
+
if (content === undefined) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const match = FRONTMATTER.exec(content);
|
|
33
|
+
if (!match) {
|
|
34
|
+
if (path !== ".changeset/README.md") {
|
|
35
|
+
ctx.log.warn(`${path} has no frontmatter`);
|
|
36
|
+
}
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
let bumps;
|
|
40
|
+
try {
|
|
41
|
+
bumps = parseYaml(match[1] ?? "") ?? {};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
45
|
+
throw new Error(`invalid frontmatter in ${path}: ${reason}`, {
|
|
46
|
+
cause: error,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (typeof bumps !== "object" || bumps === null || Array.isArray(bumps)) {
|
|
50
|
+
throw new Error(`frontmatter of ${path} must map packages to bumps`);
|
|
51
|
+
}
|
|
52
|
+
const byKind = new Map();
|
|
53
|
+
for (const [key, level] of Object.entries(bumps)) {
|
|
54
|
+
const kind = KINDS.get(level);
|
|
55
|
+
const id = keys.get(key) ?? key;
|
|
56
|
+
if (kind) {
|
|
57
|
+
const units = byKind.get(kind) ?? [];
|
|
58
|
+
byKind.set(kind, units.includes(id) ? units : [...units, id]);
|
|
59
|
+
}
|
|
60
|
+
else if (level !== "none") {
|
|
61
|
+
ctx.log.warn(`${path}: "${key}" has unknown bump "${String(level)}"`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const [subject = "", ...rest] = match[2]?.trim().split("\n") ?? [];
|
|
65
|
+
const body = rest.join("\n").trim();
|
|
66
|
+
return [...byKind].map(([kind, units]) => ({
|
|
67
|
+
...kind,
|
|
68
|
+
units,
|
|
69
|
+
subject: subject.trim(),
|
|
70
|
+
...(body === "" ? {} : { body }),
|
|
71
|
+
files: [path],
|
|
72
|
+
}));
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Changes from `.changeset/*.md` files touched in the range; each names its
|
|
76
|
+
* units explicitly and consumes its file.
|
|
77
|
+
*/
|
|
78
|
+
export const changesetsPlugin = definePlugin({
|
|
79
|
+
apiVersion: 1,
|
|
80
|
+
name: "changesets",
|
|
81
|
+
options: z.strictObject({}),
|
|
82
|
+
intent: [
|
|
83
|
+
{
|
|
84
|
+
name: "changesets",
|
|
85
|
+
collect: (ctx, { commits, units }) => {
|
|
86
|
+
const touched = new Set(commits.flatMap((c) => c.files));
|
|
87
|
+
const keys = unitKeys(units);
|
|
88
|
+
return ctx.fs
|
|
89
|
+
.glob([".changeset/*.md"])
|
|
90
|
+
.filter((path) => touched.has(path))
|
|
91
|
+
.flatMap((path) => changesOf(ctx, path, keys));
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { defaultUnitId, definePlugin, flutter } from "@tallyrelease/core";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { edgeBetween, unitsByPackage } from "../_kit/edges.js";
|
|
5
|
+
import { joinRoot, rootOf } from "../_kit/paths.js";
|
|
6
|
+
const optionsSchema = z.strictObject({
|
|
7
|
+
/** Added to the first-parent commit count for flutter build numbers. */
|
|
8
|
+
buildOffset: z.number().int().nonnegative().optional(),
|
|
9
|
+
});
|
|
10
|
+
const PUBSPEC = "pubspec.yaml";
|
|
11
|
+
const DEP_FIELDS = [
|
|
12
|
+
"dependencies",
|
|
13
|
+
"dev_dependencies",
|
|
14
|
+
"dependency_overrides",
|
|
15
|
+
];
|
|
16
|
+
/** The top-level `version:` line; group 3 is the value without quotes. */
|
|
17
|
+
const VERSION_LINE = /^(version:[ \t]*)(["']?)([^\s"'#]+)\2/m;
|
|
18
|
+
const record = (value) => typeof value === "object" && value !== null
|
|
19
|
+
? value
|
|
20
|
+
: {};
|
|
21
|
+
const readPubspec = (ctx, root) => {
|
|
22
|
+
const path = joinRoot(root, PUBSPEC);
|
|
23
|
+
const raw = ctx.fs.read(path);
|
|
24
|
+
if (raw === undefined) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
return record(parseYaml(raw));
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
32
|
+
throw new Error(`invalid YAML in ${path}: ${reason}`, { cause: error });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/** Directories whose pubspecs are never units. */
|
|
36
|
+
const SKIPPED = new Set(["build", "example"]);
|
|
37
|
+
/** Roots of every `pubspec.yaml`, skipping dot, `build` and `example` directories. */
|
|
38
|
+
const pubspecRoots = (ctx) => ctx.fs
|
|
39
|
+
.glob([PUBSPEC, `**/${PUBSPEC}`])
|
|
40
|
+
.filter((p) => p
|
|
41
|
+
.split("/")
|
|
42
|
+
.slice(0, -1)
|
|
43
|
+
.every((s) => !s.startsWith(".") && !SKIPPED.has(s)))
|
|
44
|
+
.map((p) => (p === PUBSPEC ? "." : rootOf(p, PUBSPEC)));
|
|
45
|
+
/** A private app that depends on the Flutter SDK. */
|
|
46
|
+
const isFlutterApp = (pubspec) => pubspec["publish_to"] === "none" &&
|
|
47
|
+
(record(record(pubspec["dependencies"])["flutter"])["sdk"] === "flutter" ||
|
|
48
|
+
record(pubspec["environment"])["flutter"] !== undefined);
|
|
49
|
+
export const dartPlugin = definePlugin({
|
|
50
|
+
apiVersion: 1,
|
|
51
|
+
name: "dart",
|
|
52
|
+
options: optionsSchema,
|
|
53
|
+
schemes: { flutter },
|
|
54
|
+
discover: (ctx) => pubspecRoots(ctx).map((root) => {
|
|
55
|
+
const pubspec = readPubspec(ctx, root) ?? {};
|
|
56
|
+
const packageName = pubspec["name"];
|
|
57
|
+
const { buildOffset } = ctx.options;
|
|
58
|
+
return {
|
|
59
|
+
id: defaultUnitId(root, ctx.repo.name),
|
|
60
|
+
root,
|
|
61
|
+
version: "file",
|
|
62
|
+
scheme: isFlutterApp(pubspec) ? "flutter" : "semver",
|
|
63
|
+
meta: {
|
|
64
|
+
...(typeof packageName === "string" && { packageName }),
|
|
65
|
+
...(buildOffset !== undefined && { buildOffset }),
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}),
|
|
69
|
+
edges: (ctx, units) => {
|
|
70
|
+
const byName = unitsByPackage(units, "dart");
|
|
71
|
+
const edges = [];
|
|
72
|
+
for (const to of byName.values()) {
|
|
73
|
+
const pubspec = readPubspec(ctx, to.root) ?? {};
|
|
74
|
+
for (const field of DEP_FIELDS) {
|
|
75
|
+
for (const [name, spec] of Object.entries(record(pubspec[field]))) {
|
|
76
|
+
if (typeof record(spec)["path"] === "string") {
|
|
77
|
+
edges.push(...edgeBetween(byName.get(name), to, {
|
|
78
|
+
reason: `${field}: ${name}`,
|
|
79
|
+
pinned: false,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return edges;
|
|
86
|
+
},
|
|
87
|
+
versionFiles: (_ctx, unit) => [
|
|
88
|
+
{
|
|
89
|
+
path: joinRoot(unit.root, PUBSPEC),
|
|
90
|
+
read: (content) => VERSION_LINE.exec(content)?.[3],
|
|
91
|
+
// A pubspec without a version line gets one after `name:`.
|
|
92
|
+
write: (content, next) => VERSION_LINE.test(content)
|
|
93
|
+
? content.replace(VERSION_LINE, (_, key, quote) => `${key}${quote}${next}${quote}`)
|
|
94
|
+
: content.replace(/^name:.*$/m, (line) => `${line}\nversion: ${next}`),
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
inputs: () => ({ global: ["pubspec.lock"] }),
|
|
98
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const goPlugin: import("@tallyrelease/core").Plugin<unknown>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { defaultUnitId, definePlugin } from "@tallyrelease/core";
|
|
2
|
+
import { edgeBetween } from "../_kit/edges.js";
|
|
3
|
+
import { joinRoot, rootOf } from "../_kit/paths.js";
|
|
4
|
+
const GO_MOD = "go.mod";
|
|
5
|
+
const MODULE = /^module\s+"?([^\s"]+)"?/;
|
|
6
|
+
const MAJOR_SUFFIX = /\/v(\d+)$/;
|
|
7
|
+
const LOCAL = /^\.{1,2}(\/|$)/;
|
|
8
|
+
const readGoMod = (ctx, root) => ctx.fs.read(joinRoot(root, GO_MOD));
|
|
9
|
+
/** `go.mod` lines without comments and blank lines. */
|
|
10
|
+
const lines = (source) => source
|
|
11
|
+
.split("\n")
|
|
12
|
+
.map((line) => line.replace(/\/\/.*$/, "").trim())
|
|
13
|
+
.filter((line) => line !== "");
|
|
14
|
+
const modulePath = (source) => {
|
|
15
|
+
for (const line of lines(source)) {
|
|
16
|
+
const match = MODULE.exec(line);
|
|
17
|
+
if (match) {
|
|
18
|
+
return match[1];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
|
23
|
+
/** Relative targets of `replace` directives, single-line and block form. */
|
|
24
|
+
const replaceTargets = (source) => {
|
|
25
|
+
const targets = [];
|
|
26
|
+
let block = false;
|
|
27
|
+
for (const line of lines(source)) {
|
|
28
|
+
let spec;
|
|
29
|
+
if (block) {
|
|
30
|
+
if (line === ")") {
|
|
31
|
+
block = false;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
spec = line;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (/^replace\s*\(/.test(line)) {
|
|
38
|
+
block = true;
|
|
39
|
+
}
|
|
40
|
+
else if (line.startsWith("replace ")) {
|
|
41
|
+
spec = line.slice("replace ".length);
|
|
42
|
+
}
|
|
43
|
+
const [from, to] = spec?.split("=>") ?? [];
|
|
44
|
+
const module = from?.trim().split(/\s+/)[0]?.replaceAll('"', "");
|
|
45
|
+
const path = to?.trim().split(/\s+/)[0]?.replaceAll('"', "");
|
|
46
|
+
if (module && path && LOCAL.test(path)) {
|
|
47
|
+
targets.push({ module, path });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return targets;
|
|
51
|
+
};
|
|
52
|
+
/** Joins `rel` onto `root` and normalizes; undefined when it leaves the repo. */
|
|
53
|
+
const resolve = (root, rel) => {
|
|
54
|
+
const out = [];
|
|
55
|
+
for (const part of [...root.split("/"), ...rel.split("/")]) {
|
|
56
|
+
if (part === "..") {
|
|
57
|
+
if (out.pop() === undefined) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (part !== "" && part !== ".") {
|
|
62
|
+
out.push(part);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return out.length === 0 ? "." : out.join("/");
|
|
66
|
+
};
|
|
67
|
+
/** Throws `E_GO_MAJOR_PATH` for the first unit whose module path lacks the `/v<major>` suffix of its next version. */
|
|
68
|
+
const checkMajorPaths = (ctx, plan) => {
|
|
69
|
+
for (const unit of plan.units) {
|
|
70
|
+
if (unit.plugin !== "go" || unit.next === null) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const major = Number.parseInt(unit.next, 10);
|
|
74
|
+
const path = modulePath(readGoMod(ctx, unit.path) ?? "");
|
|
75
|
+
if (path === undefined) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const suffix = Number(MAJOR_SUFFIX.exec(path)?.[1] ?? 0);
|
|
79
|
+
if (major >= 2 ? suffix !== major : suffix >= 2) {
|
|
80
|
+
throw new Error(`E_GO_MAJOR_PATH: unit "${unit.id}" releases ${unit.next} but module path "${path}" ${major >= 2 ? `must end in "/v${String(major)}"` : "must not end in a /vN suffix"}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export const goPlugin = definePlugin({
|
|
85
|
+
apiVersion: 1,
|
|
86
|
+
name: "go",
|
|
87
|
+
discover: (ctx) => {
|
|
88
|
+
const roots = new Set(ctx.fs
|
|
89
|
+
.glob([GO_MOD, `**/${GO_MOD}`])
|
|
90
|
+
.map((p) => (p === GO_MOD ? "." : rootOf(p, GO_MOD))));
|
|
91
|
+
return [...roots].map((root) => {
|
|
92
|
+
const module = modulePath(readGoMod(ctx, root) ?? "");
|
|
93
|
+
return {
|
|
94
|
+
id: defaultUnitId(root, ctx.repo.name),
|
|
95
|
+
root,
|
|
96
|
+
version: "tag",
|
|
97
|
+
tagFormat: root === "." ? "v{version}" : `${root}/v{version}`,
|
|
98
|
+
meta: module === undefined ? {} : { modulePath: module },
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
edges: (ctx, units) => {
|
|
103
|
+
const owned = units.filter((u) => u.plugin === "go");
|
|
104
|
+
const byRoot = new Map(owned.map((u) => [u.root, u]));
|
|
105
|
+
const edges = [];
|
|
106
|
+
for (const to of owned) {
|
|
107
|
+
for (const { module, path } of replaceTargets(readGoMod(ctx, to.root) ?? "")) {
|
|
108
|
+
const target = resolve(to.root, path);
|
|
109
|
+
edges.push(...edgeBetween(target === undefined ? undefined : byRoot.get(target), to, {
|
|
110
|
+
reason: `replace: ${module}`,
|
|
111
|
+
pinned: false,
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return edges;
|
|
116
|
+
},
|
|
117
|
+
validate: checkMajorPaths,
|
|
118
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { builtinPlugins } from "./builtin.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { builtinPlugins } from "./builtin.js";
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { defaultUnitId, definePlugin } from "@tallyrelease/core";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { edgeBetween } from "../_kit/edges.js";
|
|
5
|
+
import { globIn } from "../_kit/paths.js";
|
|
6
|
+
const optionsSchema = z.strictObject({
|
|
7
|
+
paths: z.array(z.string()).optional(),
|
|
8
|
+
});
|
|
9
|
+
const FILE_NAMES = ["kustomization.yaml", "kustomization.yml", "Kustomization"];
|
|
10
|
+
const GLOB_META = /[[\]{}()!*?+@\\]/g;
|
|
11
|
+
const REMOTE = /:\/\/|^git@|^github\.com\/|\?ref=/;
|
|
12
|
+
const escapeGlob = (path) => path.replace(GLOB_META, "\\$&");
|
|
13
|
+
const list = (value) => (Array.isArray(value) ? value : []);
|
|
14
|
+
const strings = (value) => list(value).filter((v) => typeof v === "string");
|
|
15
|
+
const objects = (value) => list(value).filter((v) => typeof v === "object" && v !== null);
|
|
16
|
+
/** Joins `rel` onto `root` and normalizes; undefined when it leaves the repo. */
|
|
17
|
+
const resolve = (root, rel) => {
|
|
18
|
+
const out = [];
|
|
19
|
+
for (const part of [...root.split("/"), ...rel.split("/")]) {
|
|
20
|
+
if (part === "..") {
|
|
21
|
+
if (out.pop() === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (part !== "" && part !== ".") {
|
|
26
|
+
out.push(part);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return out.length === 0 ? "." : out.join("/");
|
|
30
|
+
};
|
|
31
|
+
const isInside = (path, root) => root === "." || path === root || path.startsWith(`${root}/`);
|
|
32
|
+
/** Local path references of a kustomization, relative to its directory. */
|
|
33
|
+
const extractRefs = (k) => {
|
|
34
|
+
const refs = [];
|
|
35
|
+
const add = (field, path, optional) => {
|
|
36
|
+
if (typeof path === "string" && path !== "") {
|
|
37
|
+
refs.push(optional ? { field, path, optional } : { field, path });
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
// Entries with a newline are inline YAML, not paths.
|
|
41
|
+
const addPaths = (field, value) => {
|
|
42
|
+
for (const path of strings(value).filter((s) => !s.includes("\n"))) {
|
|
43
|
+
add(field, path);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
for (const field of [
|
|
47
|
+
"resources",
|
|
48
|
+
"bases",
|
|
49
|
+
"components",
|
|
50
|
+
"crds",
|
|
51
|
+
"patchesStrategicMerge",
|
|
52
|
+
"configurations",
|
|
53
|
+
"transformers",
|
|
54
|
+
"generators",
|
|
55
|
+
"validators",
|
|
56
|
+
]) {
|
|
57
|
+
addPaths(field, k[field]);
|
|
58
|
+
}
|
|
59
|
+
for (const field of ["patches", "patchesJson6902", "replacements"]) {
|
|
60
|
+
for (const entry of objects(k[field])) {
|
|
61
|
+
add(`${field}.path`, entry["path"]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
add("openapi.path", k["openapi"]?.["path"]);
|
|
65
|
+
for (const field of ["configMapGenerator", "secretGenerator"]) {
|
|
66
|
+
for (const gen of objects(k[field])) {
|
|
67
|
+
for (const file of strings(gen["files"])) {
|
|
68
|
+
add(`${field}.files`, file.replace(/^[^=]*=/, ""));
|
|
69
|
+
}
|
|
70
|
+
addPaths(`${field}.envs`, gen["envs"]);
|
|
71
|
+
add(`${field}.env`, gen["env"]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const charts = objects(k["helmCharts"]);
|
|
75
|
+
for (const chart of charts) {
|
|
76
|
+
add("helmCharts.valuesFile", chart["valuesFile"]);
|
|
77
|
+
addPaths("helmCharts.additionalValuesFiles", chart["additionalValuesFiles"]);
|
|
78
|
+
}
|
|
79
|
+
if (charts.length > 0) {
|
|
80
|
+
const globals = k["helmGlobals"];
|
|
81
|
+
const home = globals?.["chartHome"];
|
|
82
|
+
add("helmGlobals.chartHome", typeof home === "string" ? home : "charts", true);
|
|
83
|
+
}
|
|
84
|
+
return refs;
|
|
85
|
+
};
|
|
86
|
+
const readKustomization = (ctx, root, file) => {
|
|
87
|
+
try {
|
|
88
|
+
const doc = parseYaml(ctx.fs.read(file) ?? "");
|
|
89
|
+
return typeof doc === "object" && doc !== null
|
|
90
|
+
? doc
|
|
91
|
+
: {};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
ctx.log.warn(`${root}: cannot parse ${file}: ${String(error)}`);
|
|
95
|
+
return {};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const unitId = (root, repoName) => root === "." ? defaultUnitId(root, repoName) : root.replaceAll("/", "-");
|
|
99
|
+
export const kustomizePlugin = definePlugin({
|
|
100
|
+
apiVersion: 1,
|
|
101
|
+
name: "kustomize",
|
|
102
|
+
options: optionsSchema,
|
|
103
|
+
discover: (ctx) => {
|
|
104
|
+
const paths = ctx.options.paths ?? ["**"];
|
|
105
|
+
const files = new Map();
|
|
106
|
+
for (const file of ctx.fs.glob(paths.flatMap((p) => FILE_NAMES.map((name) => globIn(p, name))))) {
|
|
107
|
+
const root = file.includes("/")
|
|
108
|
+
? file.slice(0, file.lastIndexOf("/"))
|
|
109
|
+
: ".";
|
|
110
|
+
if (!files.has(root)) {
|
|
111
|
+
files.set(root, file);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const roots = new Set(files.keys());
|
|
115
|
+
return [...files].map(([root, file]) => {
|
|
116
|
+
const refs = [];
|
|
117
|
+
const extra = new Set();
|
|
118
|
+
for (const ref of extractRefs(readKustomization(ctx, root, file))) {
|
|
119
|
+
if (REMOTE.test(ref.path) || ref.path.startsWith("/")) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const target = resolve(root, ref.path);
|
|
123
|
+
if (target === undefined) {
|
|
124
|
+
ctx.log.warn(`${root}: ${ref.field} "${ref.path}" leaves the repository`);
|
|
125
|
+
}
|
|
126
|
+
else if (target === root) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
else if (roots.has(target)) {
|
|
130
|
+
refs.push({ path: ref.path, field: ref.field });
|
|
131
|
+
}
|
|
132
|
+
else if (isInside(target, root)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
else if (ref.optional || ctx.fs.exists(target)) {
|
|
136
|
+
extra.add(escapeGlob(target));
|
|
137
|
+
extra.add(`${escapeGlob(target)}/**`);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
ctx.log.warn(`${root}: ${ref.field} "${ref.path}" does not exist`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
id: unitId(root, ctx.repo.name),
|
|
145
|
+
root,
|
|
146
|
+
...(extra.size > 0 && {
|
|
147
|
+
include: [root === "." ? "**" : `${escapeGlob(root)}/**`, ...extra],
|
|
148
|
+
}),
|
|
149
|
+
meta: { refs },
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
edges: (_ctx, units) => {
|
|
154
|
+
const own = units.filter((u) => u.plugin === "kustomize");
|
|
155
|
+
const byRoot = new Map(own.map((u) => [u.root, u]));
|
|
156
|
+
const edges = [];
|
|
157
|
+
for (const to of own) {
|
|
158
|
+
const refs = (to.meta["kustomize"]?.["refs"] ?? []);
|
|
159
|
+
for (const { path, field } of refs) {
|
|
160
|
+
const target = resolve(to.root, path);
|
|
161
|
+
const from = target === undefined ? undefined : byRoot.get(target);
|
|
162
|
+
edges.push(...edgeBetween(from, to, {
|
|
163
|
+
reason: `${field}: ${path}`,
|
|
164
|
+
pinned: false,
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return edges;
|
|
169
|
+
},
|
|
170
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const nodePlugin: import("@tallyrelease/core").Plugin<unknown>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { defaultUnitId, definePlugin } from "@tallyrelease/core";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { dependencyEdges, unitsByPackage } from "../_kit/edges.js";
|
|
4
|
+
import { parseJson, readManifest } from "../_kit/manifest.js";
|
|
5
|
+
import { globIn, joinRoot, rootOf } from "../_kit/paths.js";
|
|
6
|
+
import { BUILD, NUMBERS, PRERELEASE } from "../_kit/semver.js";
|
|
7
|
+
const PINNED_FIELDS = ["dependencies", "optionalDependencies"];
|
|
8
|
+
const UNPINNED_FIELDS = ["peerDependencies", "devDependencies"];
|
|
9
|
+
const EXACT = new RegExp(`^(workspace:)?(\\*|=?v?${NUMBERS}${PRERELEASE}${BUILD})$`);
|
|
10
|
+
/** Pinned version ranges rewritten on release; the prefix is kept. */
|
|
11
|
+
const PINNED_VERSION = new RegExp(`^((?:workspace:)?=?v?)${NUMBERS}${PRERELEASE}${BUILD}$`);
|
|
12
|
+
const MANIFEST = "package.json";
|
|
13
|
+
const manifestPath = (root) => joinRoot(root, MANIFEST);
|
|
14
|
+
const readPackage = (ctx, root) => readManifest(ctx, root, MANIFEST);
|
|
15
|
+
/** Workspace globs from `pnpm-workspace.yaml` or `package.json`, if any. */
|
|
16
|
+
const workspacePatterns = (ctx) => {
|
|
17
|
+
const pnpm = ctx.fs.read("pnpm-workspace.yaml");
|
|
18
|
+
if (pnpm !== undefined) {
|
|
19
|
+
const doc = parseYaml(pnpm);
|
|
20
|
+
return doc?.packages ?? [];
|
|
21
|
+
}
|
|
22
|
+
const { workspaces } = readPackage(ctx, ".") ?? {};
|
|
23
|
+
if (workspaces === undefined) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return Array.isArray(workspaces) ? workspaces : (workspaces.packages ?? []);
|
|
27
|
+
};
|
|
28
|
+
const packageRoots = (ctx, patterns) => {
|
|
29
|
+
const manifests = (list) => ctx.fs.glob(list.map((p) => globIn(p, MANIFEST)));
|
|
30
|
+
const excluded = new Set(manifests(patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1))));
|
|
31
|
+
return manifests(patterns.filter((p) => !p.startsWith("!")))
|
|
32
|
+
.filter((p) => !excluded.has(p))
|
|
33
|
+
.map((p) => rootOf(p, MANIFEST));
|
|
34
|
+
};
|
|
35
|
+
export const nodePlugin = definePlugin({
|
|
36
|
+
apiVersion: 1,
|
|
37
|
+
name: "node",
|
|
38
|
+
discover: (ctx) => {
|
|
39
|
+
const patterns = workspacePatterns(ctx);
|
|
40
|
+
const roots = patterns === undefined
|
|
41
|
+
? ctx.fs.exists("package.json")
|
|
42
|
+
? ["."]
|
|
43
|
+
: []
|
|
44
|
+
: packageRoots(ctx, patterns);
|
|
45
|
+
return roots.map((root) => {
|
|
46
|
+
const packageName = readPackage(ctx, root)?.name;
|
|
47
|
+
return {
|
|
48
|
+
id: defaultUnitId(root, ctx.repo.name),
|
|
49
|
+
root,
|
|
50
|
+
version: "file",
|
|
51
|
+
meta: packageName === undefined ? {} : { packageName },
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
edges: (ctx, units) => {
|
|
56
|
+
const byName = unitsByPackage(units, "node", (name, prior, unit) => {
|
|
57
|
+
ctx.log.warn(`package "${name}" is declared by "${prior.root}" and "${unit.root}"; using "${unit.root}"`);
|
|
58
|
+
});
|
|
59
|
+
const edges = [];
|
|
60
|
+
for (const to of byName.values()) {
|
|
61
|
+
const manifest = readPackage(ctx, to.root) ?? {};
|
|
62
|
+
const fields = [
|
|
63
|
+
...PINNED_FIELDS.map((field) => [field, EXACT]),
|
|
64
|
+
...UNPINNED_FIELDS.map((field) => [field, undefined]),
|
|
65
|
+
];
|
|
66
|
+
for (const [field, exact] of fields) {
|
|
67
|
+
const deps = (manifest[field] ?? {});
|
|
68
|
+
edges.push(...dependencyEdges(byName, to, { field, deps, exact }));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return edges;
|
|
72
|
+
},
|
|
73
|
+
versionFiles: (_ctx, unit) => [
|
|
74
|
+
{
|
|
75
|
+
path: manifestPath(unit.root),
|
|
76
|
+
read: (content) => {
|
|
77
|
+
const { version } = parseJson(manifestPath(unit.root), content);
|
|
78
|
+
return typeof version === "string" ? version : undefined;
|
|
79
|
+
},
|
|
80
|
+
write: (content, next, { units, versions }) => {
|
|
81
|
+
const manifest = parseJson(manifestPath(unit.root), content);
|
|
82
|
+
manifest["version"] = next;
|
|
83
|
+
const released = new Map();
|
|
84
|
+
for (const u of units) {
|
|
85
|
+
const name = u.meta["node"]?.["packageName"];
|
|
86
|
+
const version = versions.get(u.id);
|
|
87
|
+
if (typeof name === "string" && version !== undefined) {
|
|
88
|
+
released.set(name, version);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const field of PINNED_FIELDS) {
|
|
92
|
+
const deps = (manifest[field] ?? {});
|
|
93
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
94
|
+
const version = released.get(name);
|
|
95
|
+
const prefix = PINNED_VERSION.exec(range)?.[1];
|
|
96
|
+
if (version !== undefined && prefix !== undefined) {
|
|
97
|
+
deps[name] = `${prefix}${version}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const indent = /^([ \t]+)"/m.exec(content)?.[1] ?? " ";
|
|
102
|
+
const text = `${JSON.stringify(manifest, null, indent)}${content.endsWith("\n") ? "\n" : ""}`;
|
|
103
|
+
return content.includes("\r\n") ? text.replaceAll("\n", "\r\n") : text;
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
inputs: (ctx) => ({
|
|
108
|
+
global: [
|
|
109
|
+
"yarn.lock",
|
|
110
|
+
"package-lock.json",
|
|
111
|
+
"pnpm-lock.yaml",
|
|
112
|
+
"pnpm-workspace.yaml",
|
|
113
|
+
".yarnrc.yml",
|
|
114
|
+
".yarn/patches/**",
|
|
115
|
+
...(workspacePatterns(ctx) === undefined ? [] : ["package.json"]),
|
|
116
|
+
"tsconfig*.json",
|
|
117
|
+
"turbo.json",
|
|
118
|
+
],
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const phpPlugin: import("@tallyrelease/core").Plugin<unknown>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defaultUnitId, definePlugin } from "@tallyrelease/core";
|
|
2
|
+
import { dependencyEdges, unitsByPackage } from "../_kit/edges.js";
|
|
3
|
+
import { readManifest } from "../_kit/manifest.js";
|
|
4
|
+
import { globIn, rootOf } from "../_kit/paths.js";
|
|
5
|
+
import { NUMBERS, PRERELEASE } from "../_kit/semver.js";
|
|
6
|
+
const EXACT = new RegExp(`^(self\\.version|=?v?${NUMBERS}(\\.\\d+)?${PRERELEASE})$`);
|
|
7
|
+
const COMPOSER = "composer.json";
|
|
8
|
+
const readComposer = (ctx, root) => readManifest(ctx, root, COMPOSER);
|
|
9
|
+
/** Local `repositories[type=path]` url globs, repo-relative. */
|
|
10
|
+
const pathRepoGlobs = (composer) => {
|
|
11
|
+
const repos = Object.values((composer.repositories ?? {}));
|
|
12
|
+
return repos
|
|
13
|
+
.filter((r) => r.type === "path" && typeof r.url === "string")
|
|
14
|
+
.map((r) => (r.url ?? "").replace(/^\.\//, "").replace(/\/+$/, ""))
|
|
15
|
+
.filter((url) => url !== "" && !url.startsWith("../"));
|
|
16
|
+
};
|
|
17
|
+
export const phpPlugin = definePlugin({
|
|
18
|
+
apiVersion: 1,
|
|
19
|
+
name: "php",
|
|
20
|
+
discover: (ctx) => {
|
|
21
|
+
const rootComposer = readComposer(ctx, ".");
|
|
22
|
+
if (!rootComposer) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const roots = [
|
|
26
|
+
".",
|
|
27
|
+
...ctx.fs
|
|
28
|
+
.glob(pathRepoGlobs(rootComposer).map((u) => globIn(u, COMPOSER)))
|
|
29
|
+
.map((p) => rootOf(p, COMPOSER))
|
|
30
|
+
.filter((root) => root !== ""),
|
|
31
|
+
];
|
|
32
|
+
return roots.map((root) => {
|
|
33
|
+
const packageName = readComposer(ctx, root)?.name;
|
|
34
|
+
return {
|
|
35
|
+
id: defaultUnitId(root, ctx.repo.name),
|
|
36
|
+
root,
|
|
37
|
+
version: "tag",
|
|
38
|
+
meta: packageName === undefined ? {} : { packageName },
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
edges: (ctx, units) => {
|
|
43
|
+
const byName = unitsByPackage(units, "php");
|
|
44
|
+
const edges = [];
|
|
45
|
+
for (const to of byName.values()) {
|
|
46
|
+
const composer = readComposer(ctx, to.root) ?? {};
|
|
47
|
+
for (const field of ["require", "require-dev"]) {
|
|
48
|
+
const deps = (composer[field] ?? {});
|
|
49
|
+
edges.push(...dependencyEdges(byName, to, {
|
|
50
|
+
field,
|
|
51
|
+
deps,
|
|
52
|
+
exact: field === "require" ? EXACT : undefined,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return edges;
|
|
57
|
+
},
|
|
58
|
+
inputs: () => ({ global: ["composer.lock"] }),
|
|
59
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyrelease/plugins",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Built-in ecosystem plugins of tallyrelease",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/abinnovision/tallyrelease.git",
|
|
8
|
+
"directory": "packages/plugins"
|
|
9
|
+
},
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "abi group GmbH",
|
|
13
|
+
"email": "info@abigroup.io",
|
|
14
|
+
"url": "https://abigroup.io"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc --build tsconfig.build.json",
|
|
29
|
+
"check:purity": "node ../../tools/check-purity.mjs src/index.ts",
|
|
30
|
+
"format:check": "prettier --check '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml,css,html,gql,graphql}'",
|
|
31
|
+
"format:fix": "prettier --write '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml,css,html,gql,graphql}'",
|
|
32
|
+
"lint:check": "eslint '{{src,test}/**/*,*}.{t,j}s{,x}'",
|
|
33
|
+
"lint:fix": "eslint '{{src,test}/**/*,*}.{t,j}s{,x}' --fix",
|
|
34
|
+
"test-unit": "vitest --passWithNoTests --run --coverage --config vitest.config.ts --project='*#unit'",
|
|
35
|
+
"test-unit:watch": "vitest --passWithNoTests --config vitest.config.ts --project='*#unit'",
|
|
36
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
37
|
+
},
|
|
38
|
+
"lint-staged": {
|
|
39
|
+
"{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml,css,html,gql,graphql}": "prettier --write",
|
|
40
|
+
"{{src,test}/**/*,*}.{t,j}s{,x}": "eslint --fix"
|
|
41
|
+
},
|
|
42
|
+
"prettier": "@abinnovision/prettier-config",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@tallyrelease/core": "^0.4.1",
|
|
45
|
+
"yaml": "^2.9.1",
|
|
46
|
+
"zod": "^4.6.7"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@abinnovision/eslint-config-base": "^3.4.2",
|
|
50
|
+
"@abinnovision/prettier-config": "^2.2.0",
|
|
51
|
+
"@internal/tsconfig": "0.0.0",
|
|
52
|
+
"@types/node": "^26.6.5",
|
|
53
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
54
|
+
"eslint": "^10.13.0",
|
|
55
|
+
"prettier": "^3.9.10",
|
|
56
|
+
"typescript": "^6.0.3",
|
|
57
|
+
"vite": "^8.3.5",
|
|
58
|
+
"vitest": "^5.0.5"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=24"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public",
|
|
65
|
+
"exports": {
|
|
66
|
+
".": {
|
|
67
|
+
"types": "./dist/index.d.ts",
|
|
68
|
+
"import": "./dist/index.js",
|
|
69
|
+
"default": "./dist/index.js"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"npm": true
|
|
73
|
+
}
|
|
6
74
|
}
|