versioned-d.ts-tools 0.6.0 → 0.7.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/README.md CHANGED
@@ -105,44 +105,71 @@ whats-new office-scripts.d.ts office-scripts-old.d.ts office-scripts-whats-new j
105
105
 
106
106
  This generates a markdown file (e.g., `excel_whats_new.md`) containing a table showing what's new between the two versions.
107
107
 
108
- #### Link Configuration File
108
+ #### Configuration File
109
109
 
110
- You can provide an optional JSON configuration file to customize how URLs are generated for different API types using flexible templates with placeholders.
110
+ You can provide an optional JSON configuration file to customize the output by excluding specific fields, classes, and controlling what types of declarations are included.
111
111
 
112
112
  **Configuration file format:**
113
113
 
114
114
  ```json
115
115
  {
116
+ "excludedFieldNames": [
117
+ "load", "set", "toJSON", "context", "track", "untrack"
118
+ ],
119
+ "excludedClassPatterns": [
120
+ "LoadOptions$", "Data$"
121
+ ],
122
+ "excludedFieldPatterns": [
123
+ "\\w+\\??:\\s*\".*\""
124
+ ],
125
+ "includeStaticFields": false,
126
+ "includeEnums": false,
116
127
  "linkConfigs": [
117
128
  {
118
- "name": "Office Scripts",
119
129
  "pathPattern": "office-scripts",
120
- "description": "Special URL pattern for Office Scripts",
121
130
  "globalFunctionTemplate": "/{basePath}#officescript-officescript-{fieldName}-function(1)",
122
131
  "classTemplate": "/{basePath}/officescript.{className}",
123
132
  "classMemberTemplate": "/{basePath}/officescript.{className}#officescript-officescript-{className}-{fieldName}{suffix}"
124
- },
125
- {
126
- "name": "Standard Office Applications",
127
- "pathPattern": ".*",
128
- "description": "Standard URL pattern for Excel, Word, PowerPoint, Outlook",
129
- "globalFunctionTemplate": "/{basePath}#{hostName}-{fileName}-{fieldName}-function(1)",
130
- "classTemplate": "/{basePath}.{className}",
131
- "classMemberTemplate": "/{basePath}.{className}#{hostName}-{fileName}-{className}-{fieldName}{suffix}"
132
133
  }
133
134
  ]
134
135
  }
135
136
  ```
136
137
 
138
+ **Configuration Options:**
139
+
140
+ - **`excludedFieldNames`** - Array of exact field names to exclude from output
141
+ - **`excludedClassPatterns`** - Array of regex patterns for class names to exclude
142
+ - **`excludedFieldPatterns`** - Array of regex patterns for field declarations to exclude
143
+ - **`includeStaticFields`** - Boolean to include/exclude static fields (default: true)
144
+ - **`includeEnums`** - Boolean to include/exclude enum declarations (default: true when loading from config, false for backward compatibility when called directly)
145
+ - **`linkConfigs`** - Array of custom URL generation templates (see Link Configuration section below)
146
+
147
+ **Enum Configurability:**
148
+
149
+ The `includeEnums` option provides fine-grained control over enum inclusion:
150
+
151
+ - **Default behavior**: When calling the API directly, enums are excluded by default (`includeEnums: false`) for backward compatibility
152
+ - **Config file behavior**: When loading from a config file, enums are included by default (`includeEnums: true`) unless explicitly set to false
153
+ - **Explicit control**: Set `"includeEnums": true` to include enums, or `"includeEnums": false` to exclude them
154
+
155
+ This dual-default approach ensures existing integrations continue working while enabling new functionality when explicitly configured.
156
+
157
+ #### Link Configuration
158
+
159
+ The `linkConfigs` section allows you to customize how URLs are generated for different API types using flexible templates with placeholders.
160
+ ```
161
+
137
162
  **Available Template Placeholders:**
163
+
138
164
  - `{basePath}` - relativePath without the trailing dot (e.g., 'javascript/api/excel/excel')
139
- - `{hostName}` - extracted host name (e.g., 'excel', 'office-scripts')
165
+ - `{hostName}` - extracted host name (e.g., 'excel', 'office-scripts')
140
166
  - `{fileName}` - extracted file name (e.g., 'excel', 'officescript')
141
167
  - `{className}` - class name in lowercase
142
168
  - `{fieldName}` - field/method name in lowercase
143
169
  - `{suffix}` - '-member(1)' for methods/functions, '-member' for properties
144
170
 
145
171
  **Template Types:**
172
+
146
173
  - `globalFunctionTemplate` - For namespace-level functions (global functions)
147
174
  - `classTemplate` - For class/interface URLs in the first column
148
175
  - `classMemberTemplate` - For class members (methods, properties, events)
@@ -4,6 +4,15 @@ export interface LinkConfig {
4
4
  classTemplate: string;
5
5
  classMemberTemplate: string;
6
6
  }
7
+ export interface WhatsNewConfig {
8
+ excludedFieldNames?: string[];
9
+ excludedClassPatterns?: string[];
10
+ excludedFieldPatterns?: string[];
11
+ includeStaticFields?: boolean;
12
+ includeEnums?: boolean;
13
+ linkConfigs?: LinkConfig[];
14
+ replacements?: any[];
15
+ }
7
16
  export declare const DEFAULT_LINK_CONFIGS: LinkConfig[];
8
17
  declare enum ClassType {
9
18
  Class = "Class",
@@ -42,7 +51,21 @@ export declare class APISet {
42
51
  containsField(clas: ClassStruct, field: FieldStruct): boolean;
43
52
  diff(other: APISet): APISet;
44
53
  getAsDTS(): string;
45
- getAsMarkdown(relativePath: string, linkConfigs?: LinkConfig[]): string;
54
+ /**
55
+ * Generates markdown documentation for API differences.
56
+ * By default, all classes and fields are included in the output.
57
+ * Exclusions must be explicitly configured via the parameters.
58
+ *
59
+ * @param relativePath - The relative path for generating links
60
+ * @param linkConfigs - Link configuration templates (defaults to built-in Office configs)
61
+ * @param excludedFieldNames - Array of field names to exclude (no defaults)
62
+ * @param excludedClassPatterns - Array of regex patterns for classes to exclude (no defaults)
63
+ * @param excludedFieldPatterns - Array of regex patterns for fields to exclude (no defaults)
64
+ * @param includeStaticFields - Whether to include static fields (default: true)
65
+ * @param includeEnums - Whether to include enums (default: true)
66
+ * @returns Markdown table string
67
+ */
68
+ getAsMarkdown(relativePath: string, linkConfigs?: LinkConfig[], excludedFieldNames?: string[], excludedClassPatterns?: string[], excludedFieldPatterns?: string[], includeStaticFields?: boolean, includeEnums?: boolean): string;
46
69
  sort(): void;
47
70
  }
48
71
  export declare function parseDTS(fileName: string, fileContents: string): APISet;
@@ -200,18 +200,40 @@ class APISet {
200
200
  });
201
201
  return output.join("\n");
202
202
  }
203
- getAsMarkdown(relativePath, linkConfigs = exports.DEFAULT_LINK_CONFIGS) {
203
+ /**
204
+ * Generates markdown documentation for API differences.
205
+ * By default, all classes and fields are included in the output.
206
+ * Exclusions must be explicitly configured via the parameters.
207
+ *
208
+ * @param relativePath - The relative path for generating links
209
+ * @param linkConfigs - Link configuration templates (defaults to built-in Office configs)
210
+ * @param excludedFieldNames - Array of field names to exclude (no defaults)
211
+ * @param excludedClassPatterns - Array of regex patterns for classes to exclude (no defaults)
212
+ * @param excludedFieldPatterns - Array of regex patterns for fields to exclude (no defaults)
213
+ * @param includeStaticFields - Whether to include static fields (default: true)
214
+ * @param includeEnums - Whether to include enums (default: true)
215
+ * @returns Markdown table string
216
+ */
217
+ getAsMarkdown(relativePath, linkConfigs = exports.DEFAULT_LINK_CONFIGS, excludedFieldNames = [], excludedClassPatterns = [], excludedFieldPatterns = [], includeStaticFields = true, includeEnums = false) {
204
218
  this.sort();
205
219
  // table header
206
220
  let output = "| Class | Fields | Description |\n|:---|:---|:---|\n";
207
221
  this.api.forEach((clas) => {
208
222
  // Ignore the following:
209
- // - Enums.
210
- // - LoadOptions interfaces
211
- // - *Data classes for set/load methods
212
- if (clas.type !== ClassType.Enum &&
213
- !clas.getClassName().endsWith("LoadOptions") &&
214
- !clas.getClassName().endsWith("Data")) {
223
+ // - Enums (configurable via includeEnums, default: true - enums included by default).
224
+ // - Classes matching excluded patterns (configurable, no defaults - all classes included unless explicitly excluded)
225
+ const className = clas.getClassName();
226
+ const isExcludedByPattern = excludedClassPatterns.some(pattern => {
227
+ try {
228
+ return new RegExp(pattern).test(className);
229
+ }
230
+ catch (error) {
231
+ console.warn(`Invalid regex pattern "${pattern}": ${error.message}`);
232
+ return false;
233
+ }
234
+ });
235
+ const isEnum = clas.type === ClassType.Enum;
236
+ if ((includeEnums || !isEnum) && !isExcludedByPattern) {
215
237
  const className = clas.getClassName();
216
238
  // Special handling for <global> - no link
217
239
  if (className === "<global>") {
@@ -222,20 +244,25 @@ class APISet {
222
244
  + buildClassLink(relativePath, className, linkConfigs) + ")|";
223
245
  }
224
246
  // Ignore the following:
225
- // - String literal overloads.
226
- // - `load`, `set`, `track`, `untrack`, and `toJSON` methods
227
- // - The `context` property.
228
- // - Static fields.
247
+ // - Fields matching excluded patterns (configurable, no defaults - all fields included unless explicitly excluded)
248
+ // - Excluded field names (configurable, no defaults - all field names included unless explicitly excluded)
249
+ // - Static fields (configurable via includeStaticFields, default: true - static fields included by default)
229
250
  let filteredFields = clas.fields.filter((field) => {
230
- let isLiteral = field.declarationString.search(/([a-zA-Z]+)(\??:)([\n]?([ |]*\"[\w]*\"[|,\n]*)+?)([ ]*[\),])/g) >= 0;
231
- return (!isLiteral &&
232
- field.name !== "load" &&
233
- field.name !== "set" &&
234
- field.name !== "toJSON" &&
235
- field.name !== "context" &&
236
- field.name !== "track" &&
237
- field.name !== "untrack" &&
238
- !field.declarationString.includes("static "));
251
+ // Check if field matches any excluded pattern
252
+ const isExcludedByPattern = excludedFieldPatterns.some(pattern => {
253
+ try {
254
+ return new RegExp(pattern, 'g').test(field.declarationString);
255
+ }
256
+ catch (error) {
257
+ console.warn(`Invalid field regex pattern "${pattern}": ${error.message}`);
258
+ return false;
259
+ }
260
+ });
261
+ // Check if field is static and should be excluded
262
+ const isStaticField = field.declarationString.includes("static ");
263
+ return (!isExcludedByPattern &&
264
+ !excludedFieldNames.includes(field.name) &&
265
+ (includeStaticFields || !isStaticField));
239
266
  });
240
267
  let first = true;
241
268
  if (filteredFields.length > 0) {
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import { LinkConfig } from './dts-utilities';
3
- export declare function generateWhatsNew(newDtsPath: string, oldDtsPath: string, outputPath: string, relativePath: string, linkConfigs?: LinkConfig[], configFilePath?: string): void;
3
+ export declare function generateWhatsNew(newDtsPath: string, oldDtsPath: string, outputPath: string, relativePath: string, linkConfigs?: LinkConfig[], configFilePath?: string, excludedFieldNames?: string[], excludedClassPatterns?: string[], excludedFieldPatterns?: string[], includeStaticFields?: boolean, includeEnums?: boolean): void;
package/dist/whats-new.js CHANGED
@@ -38,37 +38,72 @@ exports.generateWhatsNew = generateWhatsNew;
38
38
  const fsx = __importStar(require("fs-extra"));
39
39
  const dts_utilities_1 = require("./dts-utilities");
40
40
  /**
41
- * Loads link configuration from a JSON file
41
+ * Loads configuration from a JSON file
42
42
  * @param configFilePath Path to the configuration file
43
- * @returns Array of LinkConfig objects
43
+ * @returns Configuration object with linkConfigs, excludedFieldNames, excludedClassPatterns, excludedFieldPatterns, includeStaticFields, and includeEnums
44
44
  */
45
- function loadLinkConfig(configFilePath) {
45
+ function loadWhatsNewConfig(configFilePath) {
46
46
  try {
47
47
  const configContent = fsx.readFileSync(configFilePath, 'utf8');
48
48
  const config = JSON.parse(configContent);
49
- // Validate that the config has the required template properties
50
- return config.linkConfigs.map((item) => {
51
- if (!item.globalFunctionTemplate || !item.classTemplate || !item.classMemberTemplate) {
52
- throw new Error(`Configuration item missing required template properties: ${JSON.stringify(item)}`);
53
- }
54
- return {
55
- pathPattern: item.pathPattern,
56
- globalFunctionTemplate: item.globalFunctionTemplate,
57
- classTemplate: item.classTemplate,
58
- classMemberTemplate: item.classMemberTemplate
59
- };
60
- });
49
+ let linkConfigs = undefined;
50
+ // Handle linkConfigs if present
51
+ if (config.linkConfigs) {
52
+ linkConfigs = config.linkConfigs.map((item) => {
53
+ if (!item.globalFunctionTemplate || !item.classTemplate || !item.classMemberTemplate) {
54
+ throw new Error(`Configuration item missing required template properties: ${JSON.stringify(item)}`);
55
+ }
56
+ return {
57
+ pathPattern: item.pathPattern,
58
+ globalFunctionTemplate: item.globalFunctionTemplate,
59
+ classTemplate: item.classTemplate,
60
+ classMemberTemplate: item.classMemberTemplate
61
+ };
62
+ });
63
+ }
64
+ return {
65
+ linkConfigs,
66
+ excludedFieldNames: config.excludedFieldNames,
67
+ excludedClassPatterns: config.excludedClassPatterns,
68
+ excludedFieldPatterns: config.excludedFieldPatterns,
69
+ includeStaticFields: config.includeStaticFields,
70
+ includeEnums: config.includeEnums
71
+ };
61
72
  }
62
73
  catch (error) {
63
74
  console.warn(`Could not load config file ${configFilePath}: ${error}. Using default configuration.`);
64
- return [];
75
+ return {};
65
76
  }
66
77
  }
67
- function generateWhatsNew(newDtsPath, oldDtsPath, outputPath, relativePath, linkConfigs, configFilePath) {
78
+ function generateWhatsNew(newDtsPath, oldDtsPath, outputPath, relativePath, linkConfigs, configFilePath, excludedFieldNames, excludedClassPatterns, excludedFieldPatterns, includeStaticFields, includeEnums) {
68
79
  // Load configuration from file if provided
69
80
  let effectiveLinkConfigs = linkConfigs;
70
- if (configFilePath && !linkConfigs) {
71
- effectiveLinkConfigs = loadLinkConfig(configFilePath);
81
+ let effectiveExcludedFieldNames = excludedFieldNames;
82
+ let effectiveExcludedClassPatterns = excludedClassPatterns;
83
+ let effectiveExcludedFieldPatterns = excludedFieldPatterns;
84
+ let effectiveIncludeStaticFields = includeStaticFields;
85
+ let effectiveIncludeEnums = includeEnums;
86
+ if (configFilePath && (!linkConfigs || !excludedFieldNames || !excludedClassPatterns || !excludedFieldPatterns || includeStaticFields === undefined || includeEnums === undefined)) {
87
+ const config = loadWhatsNewConfig(configFilePath);
88
+ if (!linkConfigs && config.linkConfigs) {
89
+ effectiveLinkConfigs = config.linkConfigs;
90
+ }
91
+ if (!excludedFieldNames && config.excludedFieldNames) {
92
+ effectiveExcludedFieldNames = config.excludedFieldNames;
93
+ }
94
+ if (!excludedClassPatterns && config.excludedClassPatterns) {
95
+ effectiveExcludedClassPatterns = config.excludedClassPatterns;
96
+ }
97
+ if (!excludedFieldPatterns && config.excludedFieldPatterns) {
98
+ effectiveExcludedFieldPatterns = config.excludedFieldPatterns;
99
+ }
100
+ if (includeStaticFields === undefined && config.includeStaticFields !== undefined) {
101
+ effectiveIncludeStaticFields = config.includeStaticFields;
102
+ }
103
+ if (includeEnums === undefined) {
104
+ // Default to true when loading from config (inclusive by default)
105
+ effectiveIncludeEnums = config.includeEnums !== undefined ? config.includeEnums : true;
106
+ }
72
107
  }
73
108
  // read whole files
74
109
  let wholeRelease = fsx.readFileSync(oldDtsPath).toString();
@@ -79,7 +114,7 @@ function generateWhatsNew(newDtsPath, oldDtsPath, outputPath, relativePath, link
79
114
  if (!fsx.existsSync(outputPath + ".md")) {
80
115
  fsx.createFileSync(outputPath + ".md");
81
116
  }
82
- fsx.writeFileSync(outputPath + ".md", diffAPI.getAsMarkdown(relativePath, effectiveLinkConfigs));
117
+ fsx.writeFileSync(outputPath + ".md", diffAPI.getAsMarkdown(relativePath, effectiveLinkConfigs, effectiveExcludedFieldNames, effectiveExcludedClassPatterns, effectiveExcludedFieldPatterns, effectiveIncludeStaticFields, effectiveIncludeEnums));
83
118
  }
84
119
  // CLI entry point
85
120
  if (require.main === module) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versioned-d.ts-tools",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Tools for managing versioned TypeScript definition files",
5
5
  "main": "dist/index.js",
6
6
  "bin": {