@rohal12/twee-ts 1.16.0 → 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
@@ -195,6 +195,12 @@ interface SFAIndex {
195
195
  }
196
196
  interface FileCacheEntry {
197
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;
198
204
  readonly passages: readonly Passage[];
199
205
  readonly diagnostics: readonly Diagnostic[];
200
206
  }
@@ -259,9 +265,10 @@ interface StoryMap {
259
265
  tagsByPassage: Map<string, string[]>;
260
266
  /**
261
267
  * Map of passage name → passage names it links to.
262
- * Parses `[[target]]`, `[[display->target]]`, `[[display|target]]`,
263
- * and SugarCube's `<<goto "target">>` / `<<link "display" "target">>`,
264
- * 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.
265
272
  */
266
273
  links: Map<string, string[]>;
267
274
  /** Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage. */
@@ -350,7 +357,8 @@ interface LintResult {
350
357
  }
351
358
  /**
352
359
  * Lint a story: compile without output rendering, then inspect structure.
353
- * 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.
354
362
  */
355
363
  export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
356
364
  /**
@@ -400,16 +408,23 @@ interface ParseResult {
400
408
  }
401
409
  /**
402
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.
403
414
  */
404
415
  export declare function parseTwee(source: string, options?: ParseOptions): ParseResult;
405
416
  //#endregion
406
417
  //#region src/formats.d.ts
407
418
  /**
408
419
  * Parse the Twine 2 format.js JSON chunk.
409
- * 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.
410
423
  * Per spec, the name key is Optional.
424
+ *
425
+ * @param _formatId No longer used; kept so existing callers keep compiling.
411
426
  */
412
- export declare function parseFormatJSON(source: string, formatId: string): Twine2FormatJSON | null;
427
+ export declare function parseFormatJSON(source: string, _formatId?: string): Twine2FormatJSON | null;
413
428
  /**
414
429
  * Discover all story formats in the given search directories.
415
430
  * Implements SemVer-based version pruning: within each (name, major) group,
@@ -456,9 +471,11 @@ export declare function fetchAndCacheFormat(entry: SFAIndexEntry, downloadUrl: s
456
471
  export declare function fetchDirectFormat(url: string): Promise<StoryFormatInfo>;
457
472
  /**
458
473
  * Try to resolve a remote story format by name and version.
474
+ * 0. Use an exactly matching cached download, without touching the network
459
475
  * 1. Try direct format URLs
460
476
  * 2. Try custom index URLs
461
477
  * 3. Try default SFA indices
478
+ * 4. Fall back to a compatible cached download (e.g. when offline)
462
479
  */
463
480
  export declare function resolveRemoteFormat(name: string, version: string, indices?: string[], urls?: string[]): Promise<StoryFormatInfo | undefined>;
464
481
  /** Discover all cached remote formats. Returns a Map like discoverFormats(). */
@@ -472,7 +489,11 @@ interface CachedFormatEntry {
472
489
  }
473
490
  /** List all cached formats with size and modification date. */
474
491
  export declare function listCachedFormats(): readonly CachedFormatEntry[];
475
- /** 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
+ */
476
497
  export declare function clearCachedFormats(name?: string): number;
477
498
  /** Get total cache size in bytes and format count. */
478
499
  export declare function getCacheSize(): {
package/dist/index.d.ts CHANGED
@@ -195,6 +195,12 @@ interface SFAIndex {
195
195
  }
196
196
  interface FileCacheEntry {
197
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;
198
204
  readonly passages: readonly Passage[];
199
205
  readonly diagnostics: readonly Diagnostic[];
200
206
  }
@@ -259,9 +265,10 @@ interface StoryMap {
259
265
  tagsByPassage: Map<string, string[]>;
260
266
  /**
261
267
  * Map of passage name → passage names it links to.
262
- * Parses `[[target]]`, `[[display->target]]`, `[[display|target]]`,
263
- * and SugarCube's `<<goto "target">>` / `<<link "display" "target">>`,
264
- * 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.
265
272
  */
266
273
  links: Map<string, string[]>;
267
274
  /** Broken links: `{ from, to }` pairs where `to` doesn't exist as a passage. */
@@ -350,7 +357,8 @@ interface LintResult {
350
357
  }
351
358
  /**
352
359
  * Lint a story: compile without output rendering, then inspect structure.
353
- * 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.
354
362
  */
355
363
  export declare function lint(options: Omit<CompileOptions, 'outputMode'>): Promise<LintResult>;
356
364
  /**
@@ -400,16 +408,23 @@ interface ParseResult {
400
408
  }
401
409
  /**
402
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.
403
414
  */
404
415
  export declare function parseTwee(source: string, options?: ParseOptions): ParseResult;
405
416
  //#endregion
406
417
  //#region src/formats.d.ts
407
418
  /**
408
419
  * Parse the Twine 2 format.js JSON chunk.
409
- * 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.
410
423
  * Per spec, the name key is Optional.
424
+ *
425
+ * @param _formatId No longer used; kept so existing callers keep compiling.
411
426
  */
412
- export declare function parseFormatJSON(source: string, formatId: string): Twine2FormatJSON | null;
427
+ export declare function parseFormatJSON(source: string, _formatId?: string): Twine2FormatJSON | null;
413
428
  /**
414
429
  * Discover all story formats in the given search directories.
415
430
  * Implements SemVer-based version pruning: within each (name, major) group,
@@ -456,9 +471,11 @@ export declare function fetchAndCacheFormat(entry: SFAIndexEntry, downloadUrl: s
456
471
  export declare function fetchDirectFormat(url: string): Promise<StoryFormatInfo>;
457
472
  /**
458
473
  * Try to resolve a remote story format by name and version.
474
+ * 0. Use an exactly matching cached download, without touching the network
459
475
  * 1. Try direct format URLs
460
476
  * 2. Try custom index URLs
461
477
  * 3. Try default SFA indices
478
+ * 4. Fall back to a compatible cached download (e.g. when offline)
462
479
  */
463
480
  export declare function resolveRemoteFormat(name: string, version: string, indices?: string[], urls?: string[]): Promise<StoryFormatInfo | undefined>;
464
481
  /** Discover all cached remote formats. Returns a Map like discoverFormats(). */
@@ -472,7 +489,11 @@ interface CachedFormatEntry {
472
489
  }
473
490
  /** List all cached formats with size and modification date. */
474
491
  export declare function listCachedFormats(): readonly CachedFormatEntry[];
475
- /** 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
+ */
476
497
  export declare function clearCachedFormats(name?: string): number;
477
498
  /** Get total cache size in bytes and format count. */
478
499
  export declare function getCacheSize(): {