@rohal12/twee-ts 1.15.4 → 1.16.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/dist/index.d.cts CHANGED
@@ -12,6 +12,11 @@ type SourceInput = string | InlineSource;
12
12
  interface CompileOptions {
13
13
  /** Files, directories, or inline sources to compile. */
14
14
  sources: SourceInput[];
15
+ /**
16
+ * Glob patterns for files to leave out of `sources`, matched against each file's
17
+ * path relative to the working directory (as `stats.files` lists it). Modules are not affected.
18
+ */
19
+ exclude?: string[];
15
20
  /** Output mode. Default: 'html'. */
16
21
  outputMode?: OutputMode;
17
22
  /** Story format directory ID (e.g. 'sugarcube-2'). */
@@ -190,11 +195,18 @@ interface SFAIndex {
190
195
  }
191
196
  interface FileCacheEntry {
192
197
  readonly mtimeMs: number;
198
+ /**
199
+ * Identity of the parse options (`trim`, `twee2Compat`) the entry was parsed with. An entry is
200
+ * reused only when this matches the current options; an entry without it is treated as stale
201
+ * and reparsed. The value is opaque: leave it to twee-ts to set.
202
+ */
203
+ readonly parseOptionsKey?: string;
193
204
  readonly passages: readonly Passage[];
194
205
  readonly diagnostics: readonly Diagnostic[];
195
206
  }
196
207
  interface TweeTsConfig {
197
208
  sources?: string[];
209
+ exclude?: string[];
198
210
  output?: string;
199
211
  outputMode?: OutputMode;
200
212
  formatId?: string;
@@ -253,9 +265,10 @@ interface StoryMap {
253
265
  tagsByPassage: Map<string, string[]>;
254
266
  /**
255
267
  * Map of passage name → passage names it links to.
256
- * Parses `[[target]]`, `[[display->target]]`, `[[display|target]]`,
257
- * and SugarCube's `<<goto "target">>` / `<<link "display" "target">>`,
258
- * whose arguments are read as SugarCube 2 reads them (see `sugarcube-macros.ts`).
268
+ * Parses `[[target]]`, `[[display->target]]`, `[[target<-display]]`, `[[display|target]]`,
269
+ * each with or without a setter (`[[display|target][$x to 1]]`), and SugarCube's
270
+ * `<<goto "target">>` / `<<link "display" "target">>`, read as SugarCube 2 reads them
271
+ * (see `sugarcube-macros.ts`). Links and calls in comments are not read.
259
272
  */
260
273
  links: Map<string, string[]>;
261
274
  /** Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage. */
@@ -344,7 +357,8 @@ interface LintResult {
344
357
  }
345
358
  /**
346
359
  * Lint a story: compile without output rendering, then inspect structure.
347
- * Uses JSON output mode internally to avoid format resolution.
360
+ * Uses JSON output mode internally to avoid format resolution, so it checks
361
+ * the starting passage itself, against the Twine 2 passage rules.
348
362
  */
349
363
  export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
350
364
  /**
@@ -394,16 +408,23 @@ interface ParseResult {
394
408
  }
395
409
  /**
396
410
  * Parse Twee source text into passages.
411
+ *
412
+ * The source is normalized first, as files are when they are read: a leading UTF-8 BOM is
413
+ * removed and CRLF and bare CR line endings become LF.
397
414
  */
398
415
  export declare function parseTwee(source: string, options?: ParseOptions): ParseResult;
399
416
  //#endregion
400
417
  //#region src/formats.d.ts
401
418
  /**
402
419
  * Parse the Twine 2 format.js JSON chunk.
403
- * Handles Harlowe's malformed JSON by stripping the "setup" function property.
420
+ * Handles Harlowe's malformed JSON by stripping the "setup" function property. The workaround
421
+ * keys on the property itself, so the same bytes parse whether they come from a `harlowe-3`
422
+ * directory or a direct download.
404
423
  * Per spec, the name key is Optional.
424
+ *
425
+ * @param _formatId No longer used; kept so existing callers keep compiling.
405
426
  */
406
- export declare function parseFormatJSON(source: string, formatId: string): Twine2FormatJSON | null;
427
+ export declare function parseFormatJSON(source: string, _formatId?: string): Twine2FormatJSON | null;
407
428
  /**
408
429
  * Discover all story formats in the given search directories.
409
430
  * Implements SemVer-based version pruning: within each (name, major) group,
@@ -450,9 +471,11 @@ export declare function fetchAndCacheFormat(entry: SFAIndexEntry, downloadUrl: s
450
471
  export declare function fetchDirectFormat(url: string): Promise<StoryFormatInfo>;
451
472
  /**
452
473
  * Try to resolve a remote story format by name and version.
474
+ * 0. Use an exactly matching cached download, without touching the network
453
475
  * 1. Try direct format URLs
454
476
  * 2. Try custom index URLs
455
477
  * 3. Try default SFA indices
478
+ * 4. Fall back to a compatible cached download (e.g. when offline)
456
479
  */
457
480
  export declare function resolveRemoteFormat(name: string, version: string, indices?: string[], urls?: string[]): Promise<StoryFormatInfo | undefined>;
458
481
  /** Discover all cached remote formats. Returns a Map like discoverFormats(). */
@@ -466,7 +489,11 @@ interface CachedFormatEntry {
466
489
  }
467
490
  /** List all cached formats with size and modification date. */
468
491
  export declare function listCachedFormats(): readonly CachedFormatEntry[];
469
- /** Clear all cached formats, or only those matching a given name. Returns the number of entries removed. */
492
+ /**
493
+ * Clear all cached formats, or only those matching a given name. Returns the number of entries removed.
494
+ * A name must be a single cache entry name (as `listCachedFormats()` reports it); anything with a
495
+ * path separator or `.`/`..` throws instead of deleting outside the format's own directory.
496
+ */
470
497
  export declare function clearCachedFormats(name?: string): number;
471
498
  /** Get total cache size in bytes and format count. */
472
499
  export declare function getCacheSize(): {
package/dist/index.d.ts CHANGED
@@ -12,6 +12,11 @@ type SourceInput = string | InlineSource;
12
12
  interface CompileOptions {
13
13
  /** Files, directories, or inline sources to compile. */
14
14
  sources: SourceInput[];
15
+ /**
16
+ * Glob patterns for files to leave out of `sources`, matched against each file's
17
+ * path relative to the working directory (as `stats.files` lists it). Modules are not affected.
18
+ */
19
+ exclude?: string[];
15
20
  /** Output mode. Default: 'html'. */
16
21
  outputMode?: OutputMode;
17
22
  /** Story format directory ID (e.g. 'sugarcube-2'). */
@@ -190,11 +195,18 @@ interface SFAIndex {
190
195
  }
191
196
  interface FileCacheEntry {
192
197
  readonly mtimeMs: number;
198
+ /**
199
+ * Identity of the parse options (`trim`, `twee2Compat`) the entry was parsed with. An entry is
200
+ * reused only when this matches the current options; an entry without it is treated as stale
201
+ * and reparsed. The value is opaque: leave it to twee-ts to set.
202
+ */
203
+ readonly parseOptionsKey?: string;
193
204
  readonly passages: readonly Passage[];
194
205
  readonly diagnostics: readonly Diagnostic[];
195
206
  }
196
207
  interface TweeTsConfig {
197
208
  sources?: string[];
209
+ exclude?: string[];
198
210
  output?: string;
199
211
  outputMode?: OutputMode;
200
212
  formatId?: string;
@@ -253,9 +265,10 @@ interface StoryMap {
253
265
  tagsByPassage: Map<string, string[]>;
254
266
  /**
255
267
  * Map of passage name → passage names it links to.
256
- * Parses `[[target]]`, `[[display->target]]`, `[[display|target]]`,
257
- * and SugarCube's `<<goto "target">>` / `<<link "display" "target">>`,
258
- * whose arguments are read as SugarCube 2 reads them (see `sugarcube-macros.ts`).
268
+ * Parses `[[target]]`, `[[display->target]]`, `[[target<-display]]`, `[[display|target]]`,
269
+ * each with or without a setter (`[[display|target][$x to 1]]`), and SugarCube's
270
+ * `<<goto "target">>` / `<<link "display" "target">>`, read as SugarCube 2 reads them
271
+ * (see `sugarcube-macros.ts`). Links and calls in comments are not read.
259
272
  */
260
273
  links: Map<string, string[]>;
261
274
  /** Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage. */
@@ -344,7 +357,8 @@ interface LintResult {
344
357
  }
345
358
  /**
346
359
  * Lint a story: compile without output rendering, then inspect structure.
347
- * Uses JSON output mode internally to avoid format resolution.
360
+ * Uses JSON output mode internally to avoid format resolution, so it checks
361
+ * the starting passage itself, against the Twine 2 passage rules.
348
362
  */
349
363
  export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
350
364
  /**
@@ -394,16 +408,23 @@ interface ParseResult {
394
408
  }
395
409
  /**
396
410
  * Parse Twee source text into passages.
411
+ *
412
+ * The source is normalized first, as files are when they are read: a leading UTF-8 BOM is
413
+ * removed and CRLF and bare CR line endings become LF.
397
414
  */
398
415
  export declare function parseTwee(source: string, options?: ParseOptions): ParseResult;
399
416
  //#endregion
400
417
  //#region src/formats.d.ts
401
418
  /**
402
419
  * Parse the Twine 2 format.js JSON chunk.
403
- * Handles Harlowe's malformed JSON by stripping the "setup" function property.
420
+ * Handles Harlowe's malformed JSON by stripping the "setup" function property. The workaround
421
+ * keys on the property itself, so the same bytes parse whether they come from a `harlowe-3`
422
+ * directory or a direct download.
404
423
  * Per spec, the name key is Optional.
424
+ *
425
+ * @param _formatId No longer used; kept so existing callers keep compiling.
405
426
  */
406
- export declare function parseFormatJSON(source: string, formatId: string): Twine2FormatJSON | null;
427
+ export declare function parseFormatJSON(source: string, _formatId?: string): Twine2FormatJSON | null;
407
428
  /**
408
429
  * Discover all story formats in the given search directories.
409
430
  * Implements SemVer-based version pruning: within each (name, major) group,
@@ -450,9 +471,11 @@ export declare function fetchAndCacheFormat(entry: SFAIndexEntry, downloadUrl: s
450
471
  export declare function fetchDirectFormat(url: string): Promise<StoryFormatInfo>;
451
472
  /**
452
473
  * Try to resolve a remote story format by name and version.
474
+ * 0. Use an exactly matching cached download, without touching the network
453
475
  * 1. Try direct format URLs
454
476
  * 2. Try custom index URLs
455
477
  * 3. Try default SFA indices
478
+ * 4. Fall back to a compatible cached download (e.g. when offline)
456
479
  */
457
480
  export declare function resolveRemoteFormat(name: string, version: string, indices?: string[], urls?: string[]): Promise<StoryFormatInfo | undefined>;
458
481
  /** Discover all cached remote formats. Returns a Map like discoverFormats(). */
@@ -466,7 +489,11 @@ interface CachedFormatEntry {
466
489
  }
467
490
  /** List all cached formats with size and modification date. */
468
491
  export declare function listCachedFormats(): readonly CachedFormatEntry[];
469
- /** Clear all cached formats, or only those matching a given name. Returns the number of entries removed. */
492
+ /**
493
+ * Clear all cached formats, or only those matching a given name. Returns the number of entries removed.
494
+ * A name must be a single cache entry name (as `listCachedFormats()` reports it); anything with a
495
+ * path separator or `.`/`..` throws instead of deleting outside the format's own directory.
496
+ */
470
497
  export declare function clearCachedFormats(name?: string): number;
471
498
  /** Get total cache size in bytes and format count. */
472
499
  export declare function getCacheSize(): {