@savvy-web/changesets 0.1.0 → 0.1.1

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/cjs/remark.cjs ADDED
@@ -0,0 +1,559 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ SilkChangesetTransformPreset: ()=>SilkChangesetTransformPreset,
28
+ NormalizeFormatPlugin: ()=>NormalizeFormatPlugin,
29
+ IssueLinkRefsPlugin: ()=>IssueLinkRefsPlugin,
30
+ MergeSectionsPlugin: ()=>MergeSectionsPlugin,
31
+ ContentStructureRule: ()=>ContentStructureRule,
32
+ HeadingHierarchyRule: ()=>HeadingHierarchyRule,
33
+ DeduplicateItemsPlugin: ()=>DeduplicateItemsPlugin,
34
+ ReorderSectionsPlugin: ()=>ReorderSectionsPlugin,
35
+ ContributorFootnotesPlugin: ()=>ContributorFootnotesPlugin,
36
+ SilkChangesetPreset: ()=>SilkChangesetPreset,
37
+ RequiredSectionsRule: ()=>RequiredSectionsRule
38
+ });
39
+ const external_unist_util_visit_namespaceObject = require("unist-util-visit");
40
+ const external_mdast_util_to_string_namespaceObject = require("mdast-util-to-string");
41
+ function getVersionBlocks(tree) {
42
+ const blocks = [];
43
+ for(let i = 0; i < tree.children.length; i++){
44
+ const node = tree.children[i];
45
+ if ("heading" === node.type && 2 === node.depth) blocks.push({
46
+ headingIndex: i,
47
+ startIndex: i + 1,
48
+ endIndex: tree.children.length
49
+ });
50
+ }
51
+ for(let i = 0; i < blocks.length - 1; i++)blocks[i].endIndex = blocks[i + 1].headingIndex;
52
+ return blocks;
53
+ }
54
+ function getBlockSections(tree, block) {
55
+ const sections = [];
56
+ for(let i = block.startIndex; i < block.endIndex; i++){
57
+ const node = tree.children[i];
58
+ if ("heading" === node.type && 3 === node.depth) sections.push({
59
+ heading: node,
60
+ headingIndex: i,
61
+ contentNodes: []
62
+ });
63
+ else if (sections.length > 0) sections[sections.length - 1].contentNodes.push(node);
64
+ }
65
+ return sections;
66
+ }
67
+ function getHeadingText(heading) {
68
+ return (0, external_mdast_util_to_string_namespaceObject.toString)(heading);
69
+ }
70
+ const ATTRIBUTION_PLAIN_RE = /\s*Thanks @(\w[\w-]*)!$/;
71
+ function extractLinkedAttribution(children) {
72
+ if (children.length < 3) return;
73
+ const last = children[children.length - 1];
74
+ const secondLast = children[children.length - 2];
75
+ const thirdLast = children[children.length - 3];
76
+ if ("text" !== last.type || "!" !== last.value) return;
77
+ if ("link" !== secondLast.type) return;
78
+ const linkNode = secondLast;
79
+ if (1 !== linkNode.children.length || "text" !== linkNode.children[0].type) return;
80
+ const linkText = linkNode.children[0].value;
81
+ if (!linkText.startsWith("@")) return;
82
+ const username = linkText.slice(1);
83
+ if ("text" !== thirdLast.type) return;
84
+ const textNode = thirdLast;
85
+ if (!/\s*Thanks $/.test(textNode.value)) return;
86
+ return {
87
+ contributor: {
88
+ username,
89
+ url: linkNode.url
90
+ },
91
+ removeFrom: children.length - 3
92
+ };
93
+ }
94
+ const ContributorFootnotesPlugin = ()=>(tree)=>{
95
+ const blocks = getVersionBlocks(tree);
96
+ for(let b = blocks.length - 1; b >= 0; b--){
97
+ const block = blocks[b];
98
+ const contributors = new Map();
99
+ for(let i = block.startIndex; i < block.endIndex; i++){
100
+ const node = tree.children[i];
101
+ if ("list" === node.type) (0, external_unist_util_visit_namespaceObject.visit)(node, "paragraph", (para)=>{
102
+ const linked = extractLinkedAttribution(para.children);
103
+ if (linked) {
104
+ const key = linked.contributor.username.toLowerCase();
105
+ if (!contributors.has(key)) contributors.set(key, linked.contributor);
106
+ const textNode = para.children[linked.removeFrom];
107
+ textNode.value = textNode.value.replace(/\s*Thanks $/, "");
108
+ para.children.splice(linked.removeFrom + 1, 2);
109
+ if ("" === textNode.value) para.children.splice(linked.removeFrom, 1);
110
+ return;
111
+ }
112
+ const last = para.children[para.children.length - 1];
113
+ if (last?.type === "text") {
114
+ const textNode = last;
115
+ const match = textNode.value.match(ATTRIBUTION_PLAIN_RE);
116
+ if (match) {
117
+ const username = match[1];
118
+ const key = username.toLowerCase();
119
+ if (!contributors.has(key)) contributors.set(key, {
120
+ username,
121
+ url: void 0
122
+ });
123
+ textNode.value = textNode.value.replace(ATTRIBUTION_PLAIN_RE, "");
124
+ }
125
+ }
126
+ });
127
+ }
128
+ if (0 === contributors.size) continue;
129
+ const sorted = [
130
+ ...contributors.values()
131
+ ].sort((a, b)=>a.username.toLowerCase().localeCompare(b.username.toLowerCase()));
132
+ const phrasingChildren = [];
133
+ phrasingChildren.push({
134
+ type: "text",
135
+ value: "Thanks to "
136
+ });
137
+ for(let i = 0; i < sorted.length; i++){
138
+ const contrib = sorted[i];
139
+ if (i > 0 && sorted.length > 2) phrasingChildren.push({
140
+ type: "text",
141
+ value: ", "
142
+ });
143
+ if (i > 0 && i === sorted.length - 1) phrasingChildren.push({
144
+ type: "text",
145
+ value: 2 === sorted.length ? " and " : "and "
146
+ });
147
+ if (contrib.url) phrasingChildren.push({
148
+ type: "link",
149
+ url: contrib.url,
150
+ children: [
151
+ {
152
+ type: "text",
153
+ value: `@${contrib.username}`
154
+ }
155
+ ]
156
+ });
157
+ else phrasingChildren.push({
158
+ type: "text",
159
+ value: `@${contrib.username}`
160
+ });
161
+ }
162
+ phrasingChildren.push({
163
+ type: "text",
164
+ value: " for their contributions!"
165
+ });
166
+ const paragraph = {
167
+ type: "paragraph",
168
+ children: phrasingChildren
169
+ };
170
+ tree.children.splice(block.endIndex, 0, paragraph);
171
+ }
172
+ };
173
+ const DeduplicateItemsPlugin = ()=>(tree)=>{
174
+ const blocks = getVersionBlocks(tree);
175
+ for (const block of blocks){
176
+ const sections = getBlockSections(tree, block);
177
+ for (const section of sections)for (const node of section.contentNodes){
178
+ if ("list" !== node.type) continue;
179
+ const list = node;
180
+ const seen = new Set();
181
+ list.children = list.children.filter((item)=>{
182
+ const text = (0, external_mdast_util_to_string_namespaceObject.toString)(item);
183
+ if (seen.has(text)) return false;
184
+ seen.add(text);
185
+ return true;
186
+ });
187
+ }
188
+ }
189
+ tree.children = tree.children.filter((node)=>{
190
+ if ("list" === node.type) return node.children.length > 0;
191
+ return true;
192
+ });
193
+ };
194
+ const ISSUE_RE = /^#\d+$/;
195
+ const IssueLinkRefsPlugin = ()=>(tree)=>{
196
+ const blocks = getVersionBlocks(tree);
197
+ for(let b = blocks.length - 1; b >= 0; b--){
198
+ const block = blocks[b];
199
+ const definitions = new Map();
200
+ for(let i = block.startIndex; i < block.endIndex; i++){
201
+ const node = tree.children[i];
202
+ (0, external_unist_util_visit_namespaceObject.visit)(node, "link", (linkNode, index, parent)=>{
203
+ if (!parent || void 0 === index) return;
204
+ if (1 !== linkNode.children.length || "text" !== linkNode.children[0].type) return;
205
+ const text = linkNode.children[0].value;
206
+ if (!ISSUE_RE.test(text)) return;
207
+ const label = text;
208
+ if (!definitions.has(label)) definitions.set(label, {
209
+ label,
210
+ url: linkNode.url
211
+ });
212
+ const ref = {
213
+ type: "linkReference",
214
+ identifier: label,
215
+ label,
216
+ referenceType: "full",
217
+ children: [
218
+ {
219
+ type: "text",
220
+ value: label
221
+ }
222
+ ]
223
+ };
224
+ parent.children[index] = ref;
225
+ return external_unist_util_visit_namespaceObject.SKIP;
226
+ });
227
+ }
228
+ if (0 === definitions.size) continue;
229
+ const sorted = [
230
+ ...definitions.values()
231
+ ].sort((a, b)=>{
232
+ const aNum = Number.parseInt(a.label.slice(1), 10);
233
+ const bNum = Number.parseInt(b.label.slice(1), 10);
234
+ return aNum - bNum;
235
+ });
236
+ const defNodes = sorted.map((def)=>({
237
+ type: "definition",
238
+ identifier: def.label,
239
+ label: def.label,
240
+ url: def.url
241
+ }));
242
+ tree.children.splice(block.endIndex, 0, ...defNodes);
243
+ }
244
+ };
245
+ const BREAKING_CHANGES = {
246
+ heading: "Breaking Changes",
247
+ priority: 1,
248
+ commitTypes: [],
249
+ description: "Backward-incompatible changes"
250
+ };
251
+ const FEATURES = {
252
+ heading: "Features",
253
+ priority: 2,
254
+ commitTypes: [
255
+ "feat"
256
+ ],
257
+ description: "New functionality"
258
+ };
259
+ const BUG_FIXES = {
260
+ heading: "Bug Fixes",
261
+ priority: 3,
262
+ commitTypes: [
263
+ "fix"
264
+ ],
265
+ description: "Bug corrections"
266
+ };
267
+ const PERFORMANCE = {
268
+ heading: "Performance",
269
+ priority: 4,
270
+ commitTypes: [
271
+ "perf"
272
+ ],
273
+ description: "Performance improvements"
274
+ };
275
+ const DOCUMENTATION = {
276
+ heading: "Documentation",
277
+ priority: 5,
278
+ commitTypes: [
279
+ "docs"
280
+ ],
281
+ description: "Documentation changes"
282
+ };
283
+ const REFACTORING = {
284
+ heading: "Refactoring",
285
+ priority: 6,
286
+ commitTypes: [
287
+ "refactor"
288
+ ],
289
+ description: "Code restructuring"
290
+ };
291
+ const TESTS = {
292
+ heading: "Tests",
293
+ priority: 7,
294
+ commitTypes: [
295
+ "test"
296
+ ],
297
+ description: "Test additions or modifications"
298
+ };
299
+ const BUILD_SYSTEM = {
300
+ heading: "Build System",
301
+ priority: 8,
302
+ commitTypes: [
303
+ "build"
304
+ ],
305
+ description: "Build configuration changes"
306
+ };
307
+ const CI = {
308
+ heading: "CI",
309
+ priority: 9,
310
+ commitTypes: [
311
+ "ci"
312
+ ],
313
+ description: "Continuous integration changes"
314
+ };
315
+ const DEPENDENCIES = {
316
+ heading: "Dependencies",
317
+ priority: 10,
318
+ commitTypes: [
319
+ "deps"
320
+ ],
321
+ description: "Dependency updates"
322
+ };
323
+ const MAINTENANCE = {
324
+ heading: "Maintenance",
325
+ priority: 11,
326
+ commitTypes: [
327
+ "chore",
328
+ "style"
329
+ ],
330
+ description: "General maintenance"
331
+ };
332
+ const REVERTS = {
333
+ heading: "Reverts",
334
+ priority: 12,
335
+ commitTypes: [
336
+ "revert"
337
+ ],
338
+ description: "Reverted changes"
339
+ };
340
+ const OTHER = {
341
+ heading: "Other",
342
+ priority: 13,
343
+ commitTypes: [],
344
+ description: "Uncategorized changes"
345
+ };
346
+ const CATEGORIES = [
347
+ BREAKING_CHANGES,
348
+ FEATURES,
349
+ BUG_FIXES,
350
+ PERFORMANCE,
351
+ DOCUMENTATION,
352
+ REFACTORING,
353
+ TESTS,
354
+ BUILD_SYSTEM,
355
+ CI,
356
+ DEPENDENCIES,
357
+ MAINTENANCE,
358
+ REVERTS,
359
+ OTHER
360
+ ];
361
+ const headingToCategory = new Map(CATEGORIES.map((cat)=>[
362
+ cat.heading.toLowerCase(),
363
+ cat
364
+ ]));
365
+ const commitTypeToCategory = new Map();
366
+ for (const cat of CATEGORIES)for (const commitType of cat.commitTypes)commitTypeToCategory.set(commitType, cat);
367
+ function fromHeading(heading) {
368
+ return headingToCategory.get(heading.toLowerCase());
369
+ }
370
+ function isValidHeading(heading) {
371
+ return headingToCategory.has(heading.toLowerCase());
372
+ }
373
+ function allHeadings() {
374
+ return CATEGORIES.map((cat)=>cat.heading);
375
+ }
376
+ const MergeSectionsPlugin = ()=>(tree)=>{
377
+ const blocks = getVersionBlocks(tree);
378
+ for(let b = blocks.length - 1; b >= 0; b--){
379
+ const sections = getBlockSections(tree, blocks[b]);
380
+ if (sections.length <= 1) continue;
381
+ const groups = new Map();
382
+ for(let s = 0; s < sections.length; s++){
383
+ const text = getHeadingText(sections[s].heading);
384
+ const category = fromHeading(text);
385
+ const key = category ? category.heading.toLowerCase() : text.toLowerCase();
386
+ const existing = groups.get(key);
387
+ if (existing) existing.push(s);
388
+ else groups.set(key, [
389
+ s
390
+ ]);
391
+ }
392
+ const indicesToRemove = [];
393
+ for (const indices of groups.values()){
394
+ if (indices.length <= 1) continue;
395
+ const target = sections[indices[0]];
396
+ const targetEndIndex = target.headingIndex + 1 + target.contentNodes.length;
397
+ const mergedContent = [];
398
+ for(let d = 1; d < indices.length; d++){
399
+ const dup = sections[indices[d]];
400
+ mergedContent.push(...dup.contentNodes);
401
+ indicesToRemove.push(dup.headingIndex);
402
+ for(let c = 0; c < dup.contentNodes.length; c++)indicesToRemove.push(dup.headingIndex + 1 + c);
403
+ }
404
+ tree.children.splice(targetEndIndex, 0, ...mergedContent);
405
+ const shift = mergedContent.length;
406
+ for(let r = 0; r < indicesToRemove.length; r++)if (indicesToRemove[r] >= targetEndIndex) indicesToRemove[r] += shift;
407
+ }
408
+ indicesToRemove.sort((a, b)=>b - a);
409
+ for (const idx of indicesToRemove)tree.children.splice(idx, 1);
410
+ }
411
+ };
412
+ function isHeadingAtDepth(node, depths) {
413
+ return "heading" === node.type && depths.includes(node.depth);
414
+ }
415
+ const NormalizeFormatPlugin = ()=>(tree)=>{
416
+ const blocks = getVersionBlocks(tree);
417
+ const indicesToRemove = new Set();
418
+ for (const block of blocks)for(let i = block.startIndex; i < block.endIndex; i++){
419
+ const node = tree.children[i];
420
+ if ("list" === node.type && 0 === node.children.length) {
421
+ indicesToRemove.add(i);
422
+ continue;
423
+ }
424
+ if (!isHeadingAtDepth(node, [
425
+ 3
426
+ ])) continue;
427
+ let hasContent = false;
428
+ for(let j = i + 1; j < block.endIndex; j++){
429
+ const next = tree.children[j];
430
+ if ("paragraph" === next.type && "" === (0, external_mdast_util_to_string_namespaceObject.toString)(next).trim()) {
431
+ indicesToRemove.add(j);
432
+ continue;
433
+ }
434
+ if (isHeadingAtDepth(next, [
435
+ 2,
436
+ 3
437
+ ])) break;
438
+ hasContent = true;
439
+ break;
440
+ }
441
+ if (!hasContent) indicesToRemove.add(i);
442
+ }
443
+ const sorted = [
444
+ ...indicesToRemove
445
+ ].sort((a, b)=>b - a);
446
+ for (const idx of sorted)tree.children.splice(idx, 1);
447
+ };
448
+ const UNKNOWN_PRIORITY = 999;
449
+ const ReorderSectionsPlugin = ()=>(tree)=>{
450
+ const blocks = getVersionBlocks(tree);
451
+ for(let b = blocks.length - 1; b >= 0; b--){
452
+ const block = blocks[b];
453
+ const sections = getBlockSections(tree, block);
454
+ if (sections.length <= 1) continue;
455
+ const preamble = [];
456
+ for(let i = block.startIndex; i < block.endIndex; i++)if (i < sections[0].headingIndex) preamble.push(tree.children[i]);
457
+ else break;
458
+ const sorted = [
459
+ ...sections
460
+ ].sort((a, b)=>{
461
+ const aPriority = fromHeading(getHeadingText(a.heading))?.priority ?? UNKNOWN_PRIORITY;
462
+ const bPriority = fromHeading(getHeadingText(b.heading))?.priority ?? UNKNOWN_PRIORITY;
463
+ return aPriority - bPriority;
464
+ });
465
+ const alreadySorted = sorted.every((s, i)=>s.headingIndex === sections[i].headingIndex);
466
+ if (alreadySorted) continue;
467
+ const newChildren = [
468
+ ...preamble
469
+ ];
470
+ for (const section of sorted)newChildren.push(section.heading, ...section.contentNodes);
471
+ const blockLength = block.endIndex - block.startIndex;
472
+ tree.children.splice(block.startIndex, blockLength, ...newChildren);
473
+ }
474
+ };
475
+ const external_unified_lint_rule_namespaceObject = require("unified-lint-rule");
476
+ const ContentStructureRule = (0, external_unified_lint_rule_namespaceObject.lintRule)("remark-lint:changeset-content-structure", (tree, file)=>{
477
+ (0, external_unist_util_visit_namespaceObject.visit)(tree, "heading", (node, index, parent)=>{
478
+ if (2 !== node.depth || null == parent || null == index) return;
479
+ const next = parent.children[index + 1];
480
+ if (!next || "heading" === next.type && 2 === next.depth) file.message("Empty section: heading has no content before the next section or end of file", node);
481
+ });
482
+ (0, external_unist_util_visit_namespaceObject.visit)(tree, "code", (node)=>{
483
+ if (!node.lang) file.message("Code block is missing a language identifier", node);
484
+ });
485
+ (0, external_unist_util_visit_namespaceObject.visit)(tree, "listItem", (node)=>{
486
+ const text = (0, external_mdast_util_to_string_namespaceObject.toString)(node).trim();
487
+ if (!text) file.message("Empty list item", node);
488
+ });
489
+ });
490
+ const HeadingHierarchyRule = (0, external_unified_lint_rule_namespaceObject.lintRule)("remark-lint:changeset-heading-hierarchy", (tree, file)=>{
491
+ let prevDepth = 0;
492
+ (0, external_unist_util_visit_namespaceObject.visit)(tree, "heading", (node)=>{
493
+ if (1 === node.depth) return void file.message("h1 headings are not allowed in changeset files", node);
494
+ if (prevDepth > 0 && node.depth > prevDepth + 1) file.message(`Heading level skipped: expected h${prevDepth + 1} or lower, found h${node.depth}`, node);
495
+ prevDepth = node.depth;
496
+ });
497
+ });
498
+ const RequiredSectionsRule = (0, external_unified_lint_rule_namespaceObject.lintRule)("remark-lint:changeset-required-sections", (tree, file)=>{
499
+ (0, external_unist_util_visit_namespaceObject.visit)(tree, "heading", (node)=>{
500
+ if (2 !== node.depth) return;
501
+ const text = (0, external_mdast_util_to_string_namespaceObject.toString)(node);
502
+ if (!isValidHeading(text)) file.message(`Unknown section "${text}". Valid sections: ${allHeadings().join(", ")}`, node);
503
+ });
504
+ });
505
+ const SilkChangesetPreset = [
506
+ HeadingHierarchyRule,
507
+ RequiredSectionsRule,
508
+ ContentStructureRule
509
+ ];
510
+ const SilkChangesetTransformPreset = [
511
+ MergeSectionsPlugin,
512
+ ReorderSectionsPlugin,
513
+ DeduplicateItemsPlugin,
514
+ ContributorFootnotesPlugin,
515
+ IssueLinkRefsPlugin,
516
+ NormalizeFormatPlugin
517
+ ];
518
+ exports.ContentStructureRule = __webpack_exports__.ContentStructureRule;
519
+ exports.ContributorFootnotesPlugin = __webpack_exports__.ContributorFootnotesPlugin;
520
+ exports.DeduplicateItemsPlugin = __webpack_exports__.DeduplicateItemsPlugin;
521
+ exports.HeadingHierarchyRule = __webpack_exports__.HeadingHierarchyRule;
522
+ exports.IssueLinkRefsPlugin = __webpack_exports__.IssueLinkRefsPlugin;
523
+ exports.MergeSectionsPlugin = __webpack_exports__.MergeSectionsPlugin;
524
+ exports.NormalizeFormatPlugin = __webpack_exports__.NormalizeFormatPlugin;
525
+ exports.ReorderSectionsPlugin = __webpack_exports__.ReorderSectionsPlugin;
526
+ exports.RequiredSectionsRule = __webpack_exports__.RequiredSectionsRule;
527
+ exports.SilkChangesetPreset = __webpack_exports__.SilkChangesetPreset;
528
+ exports.SilkChangesetTransformPreset = __webpack_exports__.SilkChangesetTransformPreset;
529
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
530
+ "ContentStructureRule",
531
+ "ContributorFootnotesPlugin",
532
+ "DeduplicateItemsPlugin",
533
+ "HeadingHierarchyRule",
534
+ "IssueLinkRefsPlugin",
535
+ "MergeSectionsPlugin",
536
+ "NormalizeFormatPlugin",
537
+ "ReorderSectionsPlugin",
538
+ "RequiredSectionsRule",
539
+ "SilkChangesetPreset",
540
+ "SilkChangesetTransformPreset"
541
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
542
+ Object.defineProperty(exports, '__esModule', {
543
+ value: true
544
+ });
545
+
546
+
547
+ if (module.exports && module.exports.__esModule && 'default' in module.exports) {
548
+ var _def = module.exports.default;
549
+ if (_def !== null && _def !== undefined && (typeof _def === 'object' || typeof _def === 'function')) {
550
+ var _keys = Object.keys(module.exports);
551
+ for (var _i = 0; _i < _keys.length; _i++) {
552
+ var _key = _keys[_i];
553
+ if (_key !== 'default' && _key !== '__esModule' && !(_key in _def)) {
554
+ _def[_key] = module.exports[_key];
555
+ }
556
+ }
557
+ }
558
+ module.exports = _def;
559
+ }