versioned-d.ts-tools 0.8.0 → 0.8.2

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.
@@ -36,6 +36,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.APISet = exports.DEFAULT_LINK_CONFIGS = void 0;
37
37
  exports.parseDTS = parseDTS;
38
38
  const ts = __importStar(require("typescript"));
39
+ /**
40
+ * Normalizes line endings in a string to LF (\n) for consistent comparison.
41
+ * This ensures that declaration strings extracted from files with different
42
+ * line endings (CRLF on Windows vs LF on Unix) can be compared accurately.
43
+ */
44
+ function normalizeLineEndings(text) {
45
+ return text.replace(/\r\n/g, '\n');
46
+ }
39
47
  // Available placeholders:
40
48
  // {basePath} - relativePath without the trailing dot
41
49
  // {hostName} - extracted host name (e.g., "excel", "office-scripts")
@@ -553,8 +561,9 @@ function extractFirstSentenceFromComment(commentText) {
553
561
  function removeAtLink(commentText) {
554
562
  // Replace links with the format "{@link Foo}" with "Foo".
555
563
  commentText = commentText.replace(/{@link ([^|]*?)}/gm, "$1");
556
- // Replace links with the format "{@link URL | text}" with just the text part.
557
- commentText = commentText.replace(/{@link ([^}]*?) \| ([^}]*?)}/gm, "$2");
564
+ // Replace links with the format "{@link URL | text}" or "{@link URL| text}" with just the text part.
565
+ // Allow optional whitespace around the pipe separator.
566
+ commentText = commentText.replace(/{@link ([^}]*?)\s*\|\s*([^}]*?)}/gm, "$2");
558
567
  return commentText;
559
568
  }
560
569
  // Cache for compiled link config patterns to avoid recompilation
@@ -670,7 +679,7 @@ function parseDTSTopLevelItem(node, allClasses, type, context) {
670
679
  context.lastItem = context.topClass;
671
680
  }
672
681
  function parseDTSFieldItem(node, type, context) {
673
- const newField = new FieldStruct(node.getText(), "", type, node.name.getText());
682
+ const newField = new FieldStruct(normalizeLineEndings(node.getText()), "", type, node.name.getText());
674
683
  context.topClass.fields.push(newField);
675
684
  context.lastItem = newField;
676
685
  }
@@ -678,7 +687,7 @@ function parseDTSGlobalFunctionItem(node, allClasses, context) {
678
687
  // Create a "<global>" class to hold top-level functions if it doesn't exist
679
688
  const globalClass = context.ensureGlobalFunctionsClass(allClasses);
680
689
  const functionName = node.name ? node.name.getText() : "anonymous";
681
- const newFunction = new FieldStruct(node.getText(), "", FieldType.Function, functionName);
690
+ const newFunction = new FieldStruct(normalizeLineEndings(node.getText()), "", FieldType.Function, functionName);
682
691
  globalClass.fields.push(newFunction);
683
692
  context.lastItem = newFunction;
684
693
  }
@@ -104,11 +104,17 @@ function removeVersion(sourceDtsPath, outputFilePath, versionString, configFileP
104
104
  console.warn(`Warning: Could not parse configuration file ${configFilePath}: ${error.message}`);
105
105
  }
106
106
  }
107
+ // Clean up extra blank lines (reduce 3+ consecutive newlines to max 2)
108
+ wholeDts = removeExtraBlankLines(wholeDts);
107
109
  fsx.writeFileSync(outputFilePath, wholeDts);
108
110
  }
109
111
  function escapeRegExp(string) {
110
112
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
111
113
  }
114
+ function removeExtraBlankLines(content) {
115
+ // Replace 3 or more consecutive newlines with just 2 newlines (1 blank line)
116
+ return content.replace(/\n{3,}/g, '\n\n');
117
+ }
112
118
  // CLI entry point
113
119
  if (require.main === module) {
114
120
  const args = process.argv.slice(2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versioned-d.ts-tools",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Tools for managing versioned TypeScript definition files",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "repository": {
30
30
  "type": "git",
31
- "url": "https://github.com/AlexJerabek/versioned-d.ts-tools.git"
31
+ "url": "git+https://github.com/AlexJerabek/versioned-d.ts-tools.git"
32
32
  },
33
33
  "files": [
34
34
  "dist/**/*.js",