locter 4.0.0 → 4.1.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/README.MD +52 -14
- package/dist/index.d.mts +90 -45
- package/dist/index.mjs +146 -102
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/README.MD
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
- ✍️ **Write** — `write()` values back without pulling serializers into your app: comment-preserving YAML, indent-preserving JSON, rc9-style `.conf`.
|
|
40
40
|
- 🔁 **Sync twins** — every operation ships as `fn` / `fnSync`, derived from one shared implementation.
|
|
41
41
|
- 🧩 **Extensible** — register custom formats with independent reader/writer slots; override built-ins per extension.
|
|
42
|
-
- 🚨 **Typed errors** — `
|
|
42
|
+
- 🚨 **Typed errors** — `NotFoundError`, `LoadError`, `WriteError`, … each carrying `path` and `cause`.
|
|
43
43
|
|
|
44
44
|
**Table of Contents**
|
|
45
45
|
|
|
@@ -224,6 +224,28 @@ Bare module specifiers (no file extension) are routed to the module reader, so
|
|
|
224
224
|
`read('yaml')` behaves like `import('yaml')` — note that reading a module
|
|
225
225
|
**executes** it.
|
|
226
226
|
|
|
227
|
+
**Per-call format override**
|
|
228
|
+
|
|
229
|
+
Every read/write verb accepts an options object with a `format` key — a
|
|
230
|
+
registered format id (a built-in: `module`, `conf`, `json`, `yaml`, `text` —
|
|
231
|
+
or the id of a rule registered via `registerFormat`) used *instead* of
|
|
232
|
+
extension dispatch. The most useful consequence: module files become readable
|
|
233
|
+
**without being executed**:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { read } from 'locter';
|
|
237
|
+
|
|
238
|
+
(async () => {
|
|
239
|
+
// the source of a module file — no evaluation, no side effects
|
|
240
|
+
const source = await read('vite.config.ts', { format: 'text' });
|
|
241
|
+
|
|
242
|
+
// extensionless files become readable, too
|
|
243
|
+
const license = await read('LICENSE', { format: 'text' });
|
|
244
|
+
})
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Unknown format ids throw `LocterError`.
|
|
248
|
+
|
|
227
249
|
**Module records — `readAsModule`**
|
|
228
250
|
|
|
229
251
|
Every `readAsModule` / `readAsModuleSync` result is a **module record** — a
|
|
@@ -293,7 +315,7 @@ import { readPackageField } from 'locter';
|
|
|
293
315
|
})
|
|
294
316
|
```
|
|
295
317
|
|
|
296
|
-
Throws `
|
|
318
|
+
Throws `LoadError` if the resolved `package.json` is malformed. A sync variant `readPackageFieldSync` is also available.
|
|
297
319
|
|
|
298
320
|
### Writer
|
|
299
321
|
|
|
@@ -331,7 +353,22 @@ Write semantics:
|
|
|
331
353
|
brand — an `__esModule` key in plain data does **not** count) are unwrapped
|
|
332
354
|
to their `.default` value before serialization.
|
|
333
355
|
- Module formats (`.js`, `.ts`, …) are **read-only**: `write('config.ts', …)`
|
|
334
|
-
throws `
|
|
356
|
+
throws `WriteError`, as does writing to a bare module specifier.
|
|
357
|
+
|
|
358
|
+
An explicit `format` id lifts both restrictions of the last bullet — naming
|
|
359
|
+
the format resolves the ambiguity those guards exist for:
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
import { write } from 'locter';
|
|
363
|
+
|
|
364
|
+
(async () => {
|
|
365
|
+
// scaffold a module file from raw source ('text' bypasses read-only)
|
|
366
|
+
await write('generated/config.ts', 'export default {};', { format: 'text' });
|
|
367
|
+
|
|
368
|
+
// extensionless target, explicit format
|
|
369
|
+
await write('.myapprc', { port: 3000 }, { format: 'json' });
|
|
370
|
+
})
|
|
371
|
+
```
|
|
335
372
|
|
|
336
373
|
Per-format behavior:
|
|
337
374
|
|
|
@@ -380,7 +417,7 @@ import { writePackageField } from 'locter';
|
|
|
380
417
|
})
|
|
381
418
|
```
|
|
382
419
|
|
|
383
|
-
Throws `
|
|
420
|
+
Throws `NotFoundError` when no `package.json` could be located. A sync
|
|
384
421
|
variant `writePackageFieldSync` is also available.
|
|
385
422
|
|
|
386
423
|
### Formats
|
|
@@ -509,24 +546,24 @@ matching on `.message`:
|
|
|
509
546
|
|
|
510
547
|
| Class | When it's thrown |
|
|
511
548
|
|--------------------------------|---------------------------------------------------------|
|
|
512
|
-
| `
|
|
513
|
-
| `
|
|
514
|
-
| `
|
|
515
|
-
| `
|
|
549
|
+
| `NotFoundError` | File or module does not exist (`ENOENT`, `MODULE_NOT_FOUND`, `ERR_MODULE_NOT_FOUND`) |
|
|
550
|
+
| `LoadError` | A reader threw — parse error, runtime/eval error, etc. |
|
|
551
|
+
| `WriteError` | A write failed — serialization error, filesystem error, read-only format, corrupt existing YAML target |
|
|
552
|
+
| `UnknownExtensionError` | No rule matched the file's extension |
|
|
516
553
|
| `LocterError` | Base class; matches all of the above |
|
|
517
554
|
|
|
518
555
|
Each error exposes the offending `path` and preserves the underlying error
|
|
519
556
|
on `cause`:
|
|
520
557
|
|
|
521
558
|
```typescript
|
|
522
|
-
import { read,
|
|
559
|
+
import { read, NotFoundError, LoadError } from 'locter';
|
|
523
560
|
|
|
524
561
|
try {
|
|
525
562
|
await read('config.json');
|
|
526
563
|
} catch (err) {
|
|
527
|
-
if (err instanceof
|
|
564
|
+
if (err instanceof NotFoundError) {
|
|
528
565
|
console.error(`Config file not found: ${err.path}`);
|
|
529
|
-
} else if (err instanceof
|
|
566
|
+
} else if (err instanceof LoadError) {
|
|
530
567
|
console.error(`Failed to parse config: ${err.cause}`);
|
|
531
568
|
} else {
|
|
532
569
|
throw err;
|
|
@@ -534,11 +571,11 @@ try {
|
|
|
534
571
|
}
|
|
535
572
|
```
|
|
536
573
|
|
|
537
|
-
Note that on the write side `ENOENT` stays a `
|
|
574
|
+
Note that on the write side `ENOENT` stays a `WriteError` — a missing
|
|
538
575
|
parent directory is a write failure, not a lookup miss (and `write` creates
|
|
539
576
|
missing parents anyway).
|
|
540
577
|
|
|
541
|
-
`LocterError` extends [`BaseError`](https://github.com/Tada5hi/ebec) from `@ebec/core`, so each instance also carries a `code` (auto-derived from the class name unless overridden — e.g. `'ENOENT'` for `
|
|
578
|
+
`LocterError` extends [`BaseError`](https://github.com/Tada5hi/ebec) from `@ebec/core`, so each instance also carries a `code` (auto-derived from the class name unless overridden — e.g. `'ENOENT'` for `NotFoundError`s thrown by the JSON reader) and a `toJSON()` for structured logging.
|
|
542
579
|
|
|
543
580
|
Each error class also publishes its `Symbol.for(...)` marker (`LOCTER_ERROR_MARKER`, `LOCTER_NOT_FOUND_ERROR_MARKER`, …), which makes `instanceof` work across realms — useful when consumers end up with duplicate copies of locter in their dependency tree.
|
|
544
581
|
|
|
@@ -625,6 +662,7 @@ The list below is exhaustive — no other public APIs changed.
|
|
|
625
662
|
| `ModuleLoader` | `ModuleReader` |
|
|
626
663
|
| `setModuleLoader` | `setModuleReader` |
|
|
627
664
|
| `loadPackageField` / `loadPackageFieldSync` | `readPackageField` / `readPackageFieldSync` |
|
|
665
|
+
| `LocterLoadError` / `LocterNotFoundError` / `LocterUnknownExtensionError` | `LoadError` / `NotFoundError` / `UnknownExtensionError` — the `LocterError` base class keeps its name |
|
|
628
666
|
|
|
629
667
|
**Behavioral changes:**
|
|
630
668
|
|
|
@@ -689,7 +727,7 @@ The list below is exhaustive — no other public APIs changed.
|
|
|
689
727
|
`ConfWriter`), including comment-preserving YAML write-back — see
|
|
690
728
|
[Writer](#writer).
|
|
691
729
|
- `writePackageField` / `writePackageFieldSync`.
|
|
692
|
-
- `
|
|
730
|
+
- `WriteError` + `wrapWriteError`.
|
|
693
731
|
- `isModuleRecord` — brand-based detection of records produced by `read()`.
|
|
694
732
|
- The ports are exported as `IReader` / `IWriter`, alongside `Rule`,
|
|
695
733
|
`ReaderFactory`, `WriterFactory` — so custom formats can be typed against
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseError, ErrorOptions } from "@ebec/core";
|
|
2
|
+
import { TwinBody } from "twinop";
|
|
2
3
|
import { createJiti } from "jiti";
|
|
3
4
|
import { ToStringOptions } from "yaml";
|
|
4
5
|
//#region src/errors/base.d.ts
|
|
@@ -15,21 +16,21 @@ declare class LocterError extends BaseError {
|
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/errors/load.d.ts
|
|
17
18
|
declare const LOCTER_LOAD_ERROR_MARKER: unique symbol;
|
|
18
|
-
declare class
|
|
19
|
+
declare class LoadError extends LocterError {
|
|
19
20
|
static [Symbol.hasInstance](input: unknown): boolean;
|
|
20
21
|
constructor(input?: LocterErrorInput);
|
|
21
22
|
}
|
|
22
23
|
//#endregion
|
|
23
24
|
//#region src/errors/not-found.d.ts
|
|
24
25
|
declare const LOCTER_NOT_FOUND_ERROR_MARKER: unique symbol;
|
|
25
|
-
declare class
|
|
26
|
+
declare class NotFoundError extends LocterError {
|
|
26
27
|
static [Symbol.hasInstance](input: unknown): boolean;
|
|
27
28
|
constructor(input?: LocterErrorInput);
|
|
28
29
|
}
|
|
29
30
|
//#endregion
|
|
30
31
|
//#region src/errors/unknown-extension.d.ts
|
|
31
32
|
declare const LOCTER_UNKNOWN_EXTENSION_ERROR_MARKER: unique symbol;
|
|
32
|
-
declare class
|
|
33
|
+
declare class UnknownExtensionError extends LocterError {
|
|
33
34
|
static [Symbol.hasInstance](input: unknown): boolean;
|
|
34
35
|
constructor(input?: LocterErrorInput);
|
|
35
36
|
}
|
|
@@ -40,7 +41,7 @@ declare function wrapWriteError(input: unknown, path: string): LocterError;
|
|
|
40
41
|
//#endregion
|
|
41
42
|
//#region src/errors/write.d.ts
|
|
42
43
|
declare const LOCTER_WRITE_ERROR_MARKER: unique symbol;
|
|
43
|
-
declare class
|
|
44
|
+
declare class WriteError extends LocterError {
|
|
44
45
|
static [Symbol.hasInstance](input: unknown): boolean;
|
|
45
46
|
constructor(input?: LocterErrorInput);
|
|
46
47
|
}
|
|
@@ -84,24 +85,6 @@ declare function locateUpSync(pattern: string | string[], options?: LocatorUpOpt
|
|
|
84
85
|
declare function isLocatorInfo(input: unknown): input is LocatorInfo;
|
|
85
86
|
declare function buildFilePath(input: LocatorInfo | string): string;
|
|
86
87
|
//#endregion
|
|
87
|
-
//#region src/utils/twin.d.ts
|
|
88
|
-
/**
|
|
89
|
-
* Internal protocol to derive the parallel sync + async public surfaces
|
|
90
|
-
* from one shared body. A body is a generator that yields effect pairs —
|
|
91
|
-
* an async and a sync thunk for the same operation — and the two drivers
|
|
92
|
-
* (runTwinAsync / runTwinSync) execute the side they stand for. Effect
|
|
93
|
-
* errors are re-entered into the body via `Generator.throw`, so try/catch
|
|
94
|
-
* inside a body behaves identically in both variants.
|
|
95
|
-
*
|
|
96
|
-
* Deliberately NOT exported from the utils barrel — this is internal
|
|
97
|
-
* plumbing, not public API.
|
|
98
|
-
*/
|
|
99
|
-
type TwinOp<T = unknown> = {
|
|
100
|
-
async: () => Promise<T>;
|
|
101
|
-
sync: () => T;
|
|
102
|
-
};
|
|
103
|
-
type TwinBody<R> = Generator<TwinOp<any>, R, any>;
|
|
104
|
-
//#endregion
|
|
105
88
|
//#region src/format/type.d.ts
|
|
106
89
|
interface IReader {
|
|
107
90
|
read: (input: string) => Promise<any>;
|
|
@@ -131,7 +114,7 @@ declare abstract class TextFileReader implements IReader {
|
|
|
131
114
|
* Base class for writers of text-based file formats: serializes via
|
|
132
115
|
* `stringify`, creates missing parent directories, writes the file as
|
|
133
116
|
* UTF-8 (always terminated by a single trailing newline), and wraps
|
|
134
|
-
* failures in
|
|
117
|
+
* failures in WriteError. Subclasses implement `stringify` only —
|
|
135
118
|
* both `write` variants are derived from the same body.
|
|
136
119
|
*/
|
|
137
120
|
declare abstract class TextFileWriter implements IWriter {
|
|
@@ -296,7 +279,7 @@ type YAMLWriterOptions = ToStringOptions;
|
|
|
296
279
|
* target file already exists, the new value is grafted into its parsed
|
|
297
280
|
* document, so comments and anchors attached to surviving keys survive
|
|
298
281
|
* the write-back. New files are plain `yaml.stringify` output. An
|
|
299
|
-
* existing file that fails to parse throws (wrapped as
|
|
282
|
+
* existing file that fails to parse throws (wrapped as WriteError)
|
|
300
283
|
* instead of being silently overwritten.
|
|
301
284
|
*/
|
|
302
285
|
declare class YAMLWriter extends TextFileWriter {
|
|
@@ -379,13 +362,40 @@ type Rule = {
|
|
|
379
362
|
/**
|
|
380
363
|
* Stable identity. Registering an existing id REPLACES that rule in
|
|
381
364
|
* place (position preserved, cached instance evicted). Built-in ids
|
|
382
|
-
* ('module', 'conf', 'json', 'yaml') are reserved.
|
|
365
|
+
* ('module', 'conf', 'json', 'yaml', 'text') are reserved.
|
|
366
|
+
* Omitted → auto-generated.
|
|
383
367
|
*/
|
|
384
368
|
id?: string;
|
|
385
369
|
test: RegExp | string[];
|
|
386
370
|
reader?: IReader | ReaderFactory;
|
|
387
371
|
writer?: IWriter | WriterFactory;
|
|
388
372
|
};
|
|
373
|
+
/**
|
|
374
|
+
* Per-call options for read / readAsModule (+Sync).
|
|
375
|
+
*/
|
|
376
|
+
type ReadOptions = {
|
|
377
|
+
/**
|
|
378
|
+
* Read with the format registered under this id — a built-in id
|
|
379
|
+
* ('module', 'conf', 'json', 'yaml', 'text') or a user rule id —
|
|
380
|
+
* INSTEAD of dispatching by extension. This is the evaluation-free
|
|
381
|
+
* escape hatch for module files: read('config.ts', { format: 'text' })
|
|
382
|
+
* returns the source without executing it. Unknown ids throw.
|
|
383
|
+
*/
|
|
384
|
+
format?: string;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* Per-call options for write (+Sync).
|
|
388
|
+
*/
|
|
389
|
+
type WriteOptions = {
|
|
390
|
+
/**
|
|
391
|
+
* Write with the format registered under this id INSTEAD of
|
|
392
|
+
* dispatching by extension. Skips the bare-specifier guard, so
|
|
393
|
+
* extensionless paths become writable ('LICENSE' with 'text') and
|
|
394
|
+
* read-only extensions become targetable (raw source to a '.ts'
|
|
395
|
+
* file with 'text'). Read-only format ids and unknown ids throw.
|
|
396
|
+
*/
|
|
397
|
+
format?: string;
|
|
398
|
+
};
|
|
389
399
|
/**
|
|
390
400
|
* Normalized registration record — returned by register()/entries().
|
|
391
401
|
*/
|
|
@@ -472,36 +482,49 @@ declare class FormatRegistry {
|
|
|
472
482
|
* normalized module record — a module IS a record, and the
|
|
473
483
|
* normalization only irons out the CJS/ESM interop divergence so
|
|
474
484
|
* both twin variants agree on one shape.
|
|
485
|
+
*
|
|
486
|
+
* options.format names a registered format id to use instead of
|
|
487
|
+
* extension dispatch (e.g. { format: 'text' } reads module source
|
|
488
|
+
* without evaluating it).
|
|
475
489
|
*/
|
|
476
|
-
read(input: LocatorInfo | string): Promise<any>;
|
|
477
|
-
readSync(input: LocatorInfo | string): any;
|
|
490
|
+
read(input: LocatorInfo | string, options?: ReadOptions): Promise<any>;
|
|
491
|
+
readSync(input: LocatorInfo | string, options?: ReadOptions): any;
|
|
478
492
|
/**
|
|
479
493
|
* Read a file/module and present the result as a normalized module
|
|
480
494
|
* record — the uniform, frozen shape regardless of format:
|
|
481
495
|
* `.default` always holds the loaded value, top-level keys are
|
|
482
496
|
* re-exposed as named exports.
|
|
483
497
|
*/
|
|
484
|
-
readAsModule(input: LocatorInfo | string): Promise<any>;
|
|
485
|
-
readAsModuleSync(input: LocatorInfo | string): any;
|
|
486
|
-
protected readBody(input: LocatorInfo | string): TwinBody<any>;
|
|
487
|
-
protected readAsModuleBody(input: LocatorInfo | string): TwinBody<any>;
|
|
498
|
+
readAsModule(input: LocatorInfo | string, options?: ReadOptions): Promise<any>;
|
|
499
|
+
readAsModuleSync(input: LocatorInfo | string, options?: ReadOptions): any;
|
|
500
|
+
protected readBody(input: LocatorInfo | string, options: ReadOptions): TwinBody<any>;
|
|
501
|
+
protected readAsModuleBody(input: LocatorInfo | string, options: ReadOptions): TwinBody<any>;
|
|
488
502
|
/**
|
|
489
503
|
* Shared dispatch + execution of both read bodies: resolve the
|
|
490
504
|
* reader, run it, wrap errors. Normalization is the caller's call.
|
|
491
505
|
*/
|
|
492
|
-
protected executeBody(input: LocatorInfo | string): TwinBody<{
|
|
506
|
+
protected executeBody(input: LocatorInfo | string, options: ReadOptions): TwinBody<{
|
|
493
507
|
output: unknown;
|
|
494
508
|
reader: IReader;
|
|
495
509
|
}>;
|
|
496
|
-
|
|
497
|
-
|
|
510
|
+
/**
|
|
511
|
+
* options.format names a registered format id to use instead of
|
|
512
|
+
* extension dispatch — see writeBody for the boundary semantics.
|
|
513
|
+
*/
|
|
514
|
+
write(input: LocatorInfo | string, value: unknown, options?: WriteOptions): Promise<void>;
|
|
515
|
+
writeSync(input: LocatorInfo | string, value: unknown, options?: WriteOptions): void;
|
|
498
516
|
/**
|
|
499
517
|
* Shared body of write/writeSync: dispatch, unwrap records, write, wrap.
|
|
500
518
|
* The inverse boundary of readAsModuleBody: a record produced by
|
|
501
519
|
* readAsModule() (brand detected) is unwrapped to its `.default` value;
|
|
502
520
|
* anything else is written as-is.
|
|
521
|
+
*
|
|
522
|
+
* An explicit options.format skips extension dispatch entirely —
|
|
523
|
+
* including the bare-specifier guard: naming the format resolves the
|
|
524
|
+
* ambiguity the guard exists for, so extensionless paths become
|
|
525
|
+
* writable.
|
|
503
526
|
*/
|
|
504
|
-
protected writeBody(input: LocatorInfo | string, value: unknown): TwinBody<void>;
|
|
527
|
+
protected writeBody(input: LocatorInfo | string, value: unknown, options: WriteOptions): TwinBody<void>;
|
|
505
528
|
/**
|
|
506
529
|
* The single normalization boundary: every readAsModule result becomes a module
|
|
507
530
|
* record (`.default` is always the loaded value, top-level keys stay
|
|
@@ -526,7 +549,7 @@ declare class FormatRegistry {
|
|
|
526
549
|
* 1. bare specifier (no extension) → module reader, always
|
|
527
550
|
* 2. user rules, registration order → first match wins (can override built-ins)
|
|
528
551
|
* 3. built-in extension table
|
|
529
|
-
* 4. undefined → read/readSync throw
|
|
552
|
+
* 4. undefined → read/readSync throw UnknownExtensionError
|
|
530
553
|
*/
|
|
531
554
|
findReader(input: string): IReader | undefined;
|
|
532
555
|
/**
|
|
@@ -535,9 +558,22 @@ declare class FormatRegistry {
|
|
|
535
558
|
* presets that declare a writer.
|
|
536
559
|
*/
|
|
537
560
|
findWriter(input: string): IWriter | undefined;
|
|
561
|
+
/**
|
|
562
|
+
* Resolve a reader by EXPLICIT format id (the per-call override) —
|
|
563
|
+
* a user rule id or a built-in id — bypassing extension dispatch.
|
|
564
|
+
* Unknown ids and writer-only rules throw.
|
|
565
|
+
*/
|
|
566
|
+
protected resolveReader(id: string): IReader;
|
|
567
|
+
/**
|
|
568
|
+
* Write-side counterpart of resolveReader. Reader-only rules and
|
|
569
|
+
* read-only built-ins (module) throw WriteError, mirroring
|
|
570
|
+
* what extension dispatch throws for read-only extensions.
|
|
571
|
+
*/
|
|
572
|
+
protected resolveWriter(id: string, path: string): IWriter;
|
|
538
573
|
protected findRule(input: string, filter: (rule: CompiledRule) => boolean): CompiledRule | undefined;
|
|
539
574
|
protected findBuiltInId(input: string): BuiltInFormatId | undefined;
|
|
540
|
-
protected unknownExtensionError(input: string):
|
|
575
|
+
protected unknownExtensionError(input: string): UnknownExtensionError;
|
|
576
|
+
protected unknownFormatError(id: string): LocterError;
|
|
541
577
|
protected compile(id: string, rule: Rule): CompiledRule;
|
|
542
578
|
protected generateRuleId(): string;
|
|
543
579
|
}
|
|
@@ -557,19 +593,28 @@ declare function unregisterFormat(id: string): boolean;
|
|
|
557
593
|
* (json/yaml/conf and custom readers — mutable, round-trip-symmetric
|
|
558
594
|
* with write); for modules the normalized module record (a module IS a
|
|
559
595
|
* record; normalization only irons out CJS/ESM interop divergence).
|
|
596
|
+
*
|
|
597
|
+
* options.format forces a registered format id instead of extension
|
|
598
|
+
* dispatch — e.g. { format: 'text' } reads a module file's source
|
|
599
|
+
* WITHOUT evaluating it.
|
|
560
600
|
*/
|
|
561
|
-
declare function read(input: LocatorInfo | string): Promise<any>;
|
|
562
|
-
declare function readSync(input: LocatorInfo | string): any;
|
|
601
|
+
declare function read(input: LocatorInfo | string, options?: ReadOptions): Promise<any>;
|
|
602
|
+
declare function readSync(input: LocatorInfo | string, options?: ReadOptions): any;
|
|
563
603
|
/**
|
|
564
604
|
* Read a file/module and present the result as a normalized module
|
|
565
605
|
* record — the uniform, frozen shape regardless of format: `.default`
|
|
566
606
|
* always holds the loaded value, top-level keys are re-exposed as
|
|
567
607
|
* named exports.
|
|
568
608
|
*/
|
|
569
|
-
declare function readAsModule(input: LocatorInfo | string): Promise<any>;
|
|
570
|
-
declare function readAsModuleSync(input: LocatorInfo | string): any;
|
|
571
|
-
|
|
572
|
-
|
|
609
|
+
declare function readAsModule(input: LocatorInfo | string, options?: ReadOptions): Promise<any>;
|
|
610
|
+
declare function readAsModuleSync(input: LocatorInfo | string, options?: ReadOptions): any;
|
|
611
|
+
/**
|
|
612
|
+
* options.format forces a registered format id instead of extension
|
|
613
|
+
* dispatch — this also lifts the bare-specifier guard (extensionless
|
|
614
|
+
* paths) and the read-only block on module extensions.
|
|
615
|
+
*/
|
|
616
|
+
declare function write(input: LocatorInfo | string, value: unknown, options?: WriteOptions): Promise<void>;
|
|
617
|
+
declare function writeSync(input: LocatorInfo | string, value: unknown, options?: WriteOptions): void;
|
|
573
618
|
/**
|
|
574
619
|
* Override the built-in module reader's `import` / `require` calls.
|
|
575
620
|
*
|
|
@@ -609,7 +654,7 @@ declare function readPackageFieldSync<T = unknown>(field: string, options?: Read
|
|
|
609
654
|
* Set a top-level field of the nearest `package.json` (same locate
|
|
610
655
|
* semantics as readPackageField) and write it back, preserving the
|
|
611
656
|
* file's existing indentation. Passing `undefined` removes the field.
|
|
612
|
-
* Throws
|
|
657
|
+
* Throws NotFoundError when no package.json could be located.
|
|
613
658
|
*/
|
|
614
659
|
declare function writePackageField(field: string, value: unknown, options?: WritePackageFieldOptions): Promise<void>;
|
|
615
660
|
declare function writePackageFieldSync(field: string, value: unknown, options?: WritePackageFieldOptions): void;
|
|
@@ -640,5 +685,5 @@ declare function isVitestRuntimeEnvironment(): boolean;
|
|
|
640
685
|
declare function isTsNodeRuntimeEnvironment(): boolean;
|
|
641
686
|
declare function isTsxRuntimeEnvironment(): boolean;
|
|
642
687
|
//#endregion
|
|
643
|
-
export { ConfReader, ConfWriter, type FormatPreset, type FormatRegistration, FormatRegistry, type FormatRegistryOptions, type IReader, type IWriter, JSONReader, JSONWriter, type JSONWriterOptions, LOCTER_ERROR_MARKER, LOCTER_LOAD_ERROR_MARKER, LOCTER_NOT_FOUND_ERROR_MARKER, LOCTER_UNKNOWN_EXTENSION_ERROR_MARKER, LOCTER_WRITE_ERROR_MARKER, type LocatorInfo, type LocatorOptions, type LocatorOptionsInput, type LocatorUpOptionsInput, LocterError, type LocterErrorInput, type LocterErrorOptions,
|
|
688
|
+
export { ConfReader, ConfWriter, type FormatPreset, type FormatRegistration, FormatRegistry, type FormatRegistryOptions, type IReader, type IWriter, JSONReader, JSONWriter, type JSONWriterOptions, LOCTER_ERROR_MARKER, LOCTER_LOAD_ERROR_MARKER, LOCTER_NOT_FOUND_ERROR_MARKER, LOCTER_UNKNOWN_EXTENSION_ERROR_MARKER, LOCTER_WRITE_ERROR_MARKER, LoadError, type LocatorInfo, type LocatorOptions, type LocatorOptionsInput, type LocatorUpOptionsInput, LocterError, type LocterErrorInput, type LocterErrorOptions, MODULE_FILE_EXTENSIONS, type ModuleExport, type ModuleExportFilterFn, type ModuleLoadFn, type ModuleLoadOptions, type ModuleLoadSyncFn, ModuleReader, type ModuleReaderOptions, NotFoundError, type ReadOptions, type ReadPackageFieldOptions, type ReaderFactory, type Rule, TextFileReader, TextFileWriter, TextReader, TextWriter, UnknownExtensionError, WriteError, type WriteOptions, type WritePackageFieldOptions, type WriterFactory, YAMLReader, YAMLWriter, type YAMLWriterOptions, buildFilePath, deserializeValue, getFileNameExtension, getModuleExport, isJestRuntimeEnvironment, isLocatorInfo, isModuleRecord, isTsNodeRuntimeEnvironment, isTsxRuntimeEnvironment, isVitestRuntimeEnvironment, locate, locateMany, locateManySync, locateSync, locateUp, locateUpSync, read, readAsModule, readAsModuleSync, readPackageField, readPackageFieldSync, readSync, registerFormat, removeFileNameExtension, serializeValue, setModuleReader, unregisterFormat, useFormatRegistry, wrapLoaderError, wrapWriteError, write, writePackageField, writePackageFieldSync, writeSync };
|
|
644
689
|
//# sourceMappingURL=index.d.mts.map
|