declapract-typescript-ehmpathy 0.47.21 → 0.47.22

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.
@@ -1,3 +1,7 @@
1
1
  # exclude package locks from git diff; https://stackoverflow.com/a/72834452/3068233
2
- pnpm-lock.json -diff
2
+ pnpm-lock.yaml -diff
3
3
  package-lock.json -diff
4
+
5
+ # auto-resolve lock file conflicts by taking theirs; run install after merge
6
+ pnpm-lock.yaml merge=theirs
7
+ package-lock.json merge=theirs
@@ -6,44 +6,50 @@ import { FileCheckType, type FileFixFunction } from 'declapract';
6
6
  export const check: FileCheckType = FileCheckType.CONTAINS;
7
7
 
8
8
  /**
9
- * the header comment for the package lock exclusions section
9
+ * sections of gitattributes entries to ensure exist
10
10
  */
11
- const HEADER =
12
- '# exclude package locks from git diff; https://stackoverflow.com/a/72834452/3068233';
11
+ const SECTIONS = [
12
+ {
13
+ header:
14
+ '# exclude package locks from git diff; https://stackoverflow.com/a/72834452/3068233',
15
+ entries: ['pnpm-lock.yaml -diff', 'package-lock.json -diff'],
16
+ },
17
+ {
18
+ header:
19
+ '# auto-resolve lock file conflicts by taking theirs; run install after merge',
20
+ entries: ['pnpm-lock.yaml merge=theirs', 'package-lock.json merge=theirs'],
21
+ },
22
+ ];
13
23
 
14
24
  /**
15
- * the entries that should appear under the header
25
+ * ensures a section with header and entries exists in the content
16
26
  */
17
- const ENTRIES = ['pnpm-lock.json -diff', 'package-lock.json -diff'];
18
-
19
- /**
20
- * fix by ensuring all entries are present under the header
21
- */
22
- export const fix: FileFixFunction = (contents) => {
23
- // if no contents, create the file with the header and entries
24
- if (!contents) {
25
- return { contents: [HEADER, ...ENTRIES].join('\n') + '\n' };
26
- }
27
-
28
- const lines = contents.split('\n');
27
+ const ensureSection = (
28
+ content: string,
29
+ section: { header: string; entries: string[] },
30
+ ): string => {
31
+ const lines = content.split('\n');
29
32
 
30
33
  // find the header line index
31
- const headerIndex = lines.findIndex((line) => line.trim() === HEADER);
34
+ const headerIndex = lines.findIndex((line) => line.trim() === section.header);
32
35
 
33
36
  // if header not found, append the whole section at the end
34
37
  if (headerIndex === -1) {
35
- const newContent =
36
- contents.trimEnd() + '\n\n' + [HEADER, ...ENTRIES].join('\n') + '\n';
37
- return { contents: newContent };
38
+ return (
39
+ content.trimEnd() +
40
+ '\n\n' +
41
+ [section.header, ...section.entries].join('\n') +
42
+ '\n'
43
+ );
38
44
  }
39
45
 
40
- // find which entries are missing after the header
41
- const missingEntries = ENTRIES.filter((entry) => !contents.includes(entry));
46
+ // find which entries are missing
47
+ const missingEntries = section.entries.filter(
48
+ (entry) => !content.includes(entry),
49
+ );
42
50
 
43
51
  // if no missing entries, nothing to fix
44
- if (missingEntries.length === 0) {
45
- return { contents };
46
- }
52
+ if (missingEntries.length === 0) return content;
47
53
 
48
54
  // insert missing entries right after the header
49
55
  const newLines = [
@@ -52,5 +58,26 @@ export const fix: FileFixFunction = (contents) => {
52
58
  ...lines.slice(headerIndex + 1),
53
59
  ];
54
60
 
55
- return { contents: newLines.join('\n') };
61
+ return newLines.join('\n');
62
+ };
63
+
64
+ /**
65
+ * fix by ensuring all sections are present with their entries
66
+ */
67
+ export const fix: FileFixFunction = (contents) => {
68
+ // if no contents, create the file with all sections
69
+ if (!contents) {
70
+ const allSections = SECTIONS.map((s) =>
71
+ [s.header, ...s.entries].join('\n'),
72
+ ).join('\n\n');
73
+ return { contents: allSections + '\n' };
74
+ }
75
+
76
+ // ensure each section exists
77
+ let result = contents;
78
+ for (const section of SECTIONS) {
79
+ result = ensureSection(result, section);
80
+ }
81
+
82
+ return { contents: result };
56
83
  };
@@ -8,3 +8,7 @@ changed () {
8
8
  if changed 'package-lock.json'; then
9
9
  echo "📦 package-lock.json changed. Run 'npm install' to update your locally installed dependencies."
10
10
  fi
11
+
12
+ if changed 'pnpm-lock.yaml'; then
13
+ echo "📦 pnpm-lock.yaml changed. Run 'pnpm install' to update your locally installed dependencies."
14
+ fi
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "declapract-typescript-ehmpathy",
3
3
  "author": "ehmpathy",
4
4
  "description": "declapract best practices declarations for typescript",
5
- "version": "0.47.21",
5
+ "version": "0.47.22",
6
6
  "license": "MIT",
7
7
  "main": "src/index.js",
8
8
  "repository": "ehmpathy/declapract-typescript-ehmpathy",