@flex-development/mlly 1.0.0-beta.2 → 1.0.0-beta.4
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/CHANGELOG.md +37 -0
- package/README.md +62 -13
- package/dist/interfaces/buffer-encoding-map.d.mts +29 -0
- package/dist/interfaces/get-source-options.d.mts +9 -1
- package/dist/interfaces/index.d.mts +1 -0
- package/dist/interfaces/is-directory.d.mts +2 -2
- package/dist/interfaces/is-file.d.mts +1 -1
- package/dist/interfaces/read-file.d.mts +24 -10
- package/dist/interfaces/realpath.d.mts +7 -8
- package/dist/interfaces/stat.d.mts +8 -9
- package/dist/internal/fs.browser.mjs +4 -4
- package/dist/lib/get-source.d.mts +3 -3
- package/dist/lib/get-source.mjs +5 -8
- package/dist/lib/read-package-json.mjs +5 -6
- package/dist/types/buffer-encoding.d.mts +13 -0
- package/dist/types/file-content.d.mts +11 -0
- package/dist/types/get-source-handler.d.mts +4 -3
- package/dist/types/index.d.mts +2 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
## [1.0.0-beta.4](https://github.com/flex-development/mlly/compare/1.0.0-beta.3...1.0.0-beta.4) (2026-02-06)
|
|
2
|
+
|
|
3
|
+
### ⚠ BREAKING CHANGES
|
|
4
|
+
|
|
5
|
+
- **ts:** pass type parameters to fs methods
|
|
6
|
+
|
|
7
|
+
### :package: Build
|
|
8
|
+
|
|
9
|
+
- [[`77f0333`](https://github.com/flex-development/mlly/commit/77f0333d3f83eec60d0ee41270d36bd7ac5828a4)] **deps-dev:** Bump @faker-js/faker from 10.2.0 to 10.3.0 ([#966](https://github.com/flex-development/mlly/issues/966))
|
|
10
|
+
- [[`d71a814`](https://github.com/flex-development/mlly/commit/d71a8145cd3773743411d70e84742ec93838af16)] **deps-dev:** Bump cspell from 9.6.3 to 9.6.4 ([#965](https://github.com/flex-development/mlly/issues/965))
|
|
11
|
+
- [[`4f6f9c3`](https://github.com/flex-development/mlly/commit/4f6f9c3fb24a41ce22031a35345c8b85f16ef732)] **deps-dev:** Bump msw from 2.12.7 to 2.12.8 ([#964](https://github.com/flex-development/mlly/issues/964))
|
|
12
|
+
- [[`b08edac`](https://github.com/flex-development/mlly/commit/b08edac9f21e7c91ca554e8938bba0b814605e7d)] **deps-dev:** bump msw from 2.12.8 to 2.12.9
|
|
13
|
+
- [[`893c030`](https://github.com/flex-development/mlly/commit/893c030d8d438871ad94b29a786eb59fa144a571)] **deps:** Bump @isaacs/brace-expansion from 5.0.0 to 5.0.1 ([#963](https://github.com/flex-development/mlly/issues/963))
|
|
14
|
+
|
|
15
|
+
### :mechanical_arm: Refactors
|
|
16
|
+
|
|
17
|
+
- [[`cc5109c`](https://github.com/flex-development/mlly/commit/cc5109cc76949d287f1b53e54e47559ed1a902b3)] **ts:** pass type parameters to fs methods
|
|
18
|
+
|
|
19
|
+
## [1.0.0-beta.3](https://github.com/flex-development/mlly/compare/1.0.0-beta.2...1.0.0-beta.3) (2026-02-03)
|
|
20
|
+
|
|
21
|
+
### ⚠ BREAKING CHANGES
|
|
22
|
+
|
|
23
|
+
- **lib:** [`getSource`] return `FileContent`
|
|
24
|
+
- **ts:** [`ReadFile`] return string given `encoding`
|
|
25
|
+
|
|
26
|
+
### :package: Build
|
|
27
|
+
|
|
28
|
+
- [[`2a5ffdb`](https://github.com/flex-development/mlly/commit/2a5ffdb20ce9b1fc5be481bd1de15cf429d0aafa)] **deps-dev:** Bump cspell from 9.6.2 to 9.6.3 ([#960](https://github.com/flex-development/mlly/issues/960))
|
|
29
|
+
|
|
30
|
+
### :mechanical_arm: Refactors
|
|
31
|
+
|
|
32
|
+
- [[`eaca2a7`](https://github.com/flex-development/mlly/commit/eaca2a7549deadd7362f8a2f5993167d9313bb45)] **lib:** [`getSource`] return `FileContent`
|
|
33
|
+
- [[`490d72c`](https://github.com/flex-development/mlly/commit/490d72cba0f59cb4f2fe4ff27cac4b81fa597cc6)] **ts:** match `this` context to node
|
|
34
|
+
- [[`cd54387`](https://github.com/flex-development/mlly/commit/cd54387ed7324085ed94d7b5ebb996e5cac85b4e)] **ts:** [`ReadFile`] return string given `encoding`
|
|
35
|
+
|
|
1
36
|
## [1.0.0-beta.2](https://github.com/flex-development/mlly/compare/1.0.0-beta.1...1.0.0-beta.2) (2026-02-02)
|
|
2
37
|
|
|
3
38
|
### :sparkles: Features
|
|
@@ -1260,3 +1295,5 @@
|
|
|
1260
1295
|
- [[`36c4b74`](https://github.com/flex-development/mlly/commit/36c4b7475c9bb6c924f5e75c8d6d215a8d23e79c)] **specifiers:** [`toBareSpecifier`] improve `exports` path search
|
|
1261
1296
|
|
|
1262
1297
|
|
|
1298
|
+
|
|
1299
|
+
|
package/README.md
CHANGED
|
@@ -57,6 +57,8 @@
|
|
|
57
57
|
- [Types](#types)
|
|
58
58
|
- [`Aliases`](#aliases)
|
|
59
59
|
- [`Awaitable<T>`](#awaitablet)
|
|
60
|
+
- [`BufferEncodingMap`](#bufferencodingmap)
|
|
61
|
+
- [`BufferEncoding`](#bufferencoding)
|
|
60
62
|
- [`ChangeExtFn<[Ext]>`](#changeextfnext)
|
|
61
63
|
- [`ConditionMap`](#conditionmap)
|
|
62
64
|
- [`Condition`](#condition)
|
|
@@ -65,6 +67,7 @@
|
|
|
65
67
|
- [`EmptyObject`](#emptyobject)
|
|
66
68
|
- [`EmptyString`](#emptystring)
|
|
67
69
|
- [`Ext`](#ext)
|
|
70
|
+
- [`FileContent`](#filecontent)
|
|
68
71
|
- [`FileSystem`](#filesystem)
|
|
69
72
|
- [`GetSourceContext`](#getsourcecontext)
|
|
70
73
|
- [`GetSourceHandler`](#getsourcehandler)
|
|
@@ -84,11 +87,11 @@
|
|
|
84
87
|
- [`PatternMatch`](#patternmatch)
|
|
85
88
|
- [`ProtocolMap`](#protocolmap)
|
|
86
89
|
- [`Protocol`](#protocol)
|
|
87
|
-
- [`ReadFile
|
|
88
|
-
- [`Realpath
|
|
90
|
+
- [`ReadFile`](#readfile)
|
|
91
|
+
- [`Realpath`](#realpath)
|
|
89
92
|
- [`ResolveAliasOptions`](#resolvealiasoptions)
|
|
90
93
|
- [`ResolveModuleOptions`](#resolvemoduleoptions)
|
|
91
|
-
- [`Stat
|
|
94
|
+
- [`Stat`](#stat)
|
|
92
95
|
- [`Stats`](#stats)
|
|
93
96
|
- Additional Documentation
|
|
94
97
|
- [Resolution Algorithm](./docs/resolution-algorithm.md)
|
|
@@ -271,7 +274,7 @@ Get the source code for a module.
|
|
|
271
274
|
|
|
272
275
|
#### Type Parameters
|
|
273
276
|
|
|
274
|
-
- `T` ([`Awaitable<
|
|
277
|
+
- `T` ([`Awaitable<FileContent | null | undefined>`](#filecontent))
|
|
275
278
|
— the module source code
|
|
276
279
|
|
|
277
280
|
#### Parameters
|
|
@@ -1039,6 +1042,31 @@ type Awaitable<T> = PromiseLike<T> | T
|
|
|
1039
1042
|
- `T` (`any`)
|
|
1040
1043
|
- the value
|
|
1041
1044
|
|
|
1045
|
+
### `BufferEncodingMap`
|
|
1046
|
+
|
|
1047
|
+
Registry of character encodings that can be used when working with `Buffer` objects (`interface`).
|
|
1048
|
+
|
|
1049
|
+
When developing extensions that use additional encodings, augment `BufferEncodingMap` to register custom encodings:
|
|
1050
|
+
|
|
1051
|
+
```ts
|
|
1052
|
+
declare module '@flex-development/mlly' {
|
|
1053
|
+
interface BufferEncodingMap {
|
|
1054
|
+
custom: 'custom'
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
```
|
|
1058
|
+
|
|
1059
|
+
### `BufferEncoding`
|
|
1060
|
+
|
|
1061
|
+
Union of values that can occur where a buffer encoding is expected (`type`).
|
|
1062
|
+
|
|
1063
|
+
To register new encodings, augment [`BufferEncodingMap`](#bufferencodingmap).
|
|
1064
|
+
They will be added to this union automatically.
|
|
1065
|
+
|
|
1066
|
+
```ts
|
|
1067
|
+
type BufferEncoding = BufferEncodingMap[keyof BufferEncodingMap]
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1042
1070
|
### `ChangeExtFn<[Ext]>`
|
|
1043
1071
|
|
|
1044
1072
|
Get a new file extension for `url` (`type`).
|
|
@@ -1132,17 +1160,25 @@ A file extension (`type`).
|
|
|
1132
1160
|
type Ext = `${Dot}${string}`
|
|
1133
1161
|
```
|
|
1134
1162
|
|
|
1163
|
+
### `FileContent`
|
|
1164
|
+
|
|
1165
|
+
Union of values that can occur where file content is expected (`type`).
|
|
1166
|
+
|
|
1167
|
+
```ts
|
|
1168
|
+
type FileContent = Uint8Array | string
|
|
1169
|
+
```
|
|
1170
|
+
|
|
1135
1171
|
### `FileSystem`
|
|
1136
1172
|
|
|
1137
1173
|
The file system API (`interface`).
|
|
1138
1174
|
|
|
1139
1175
|
#### Properties
|
|
1140
1176
|
|
|
1141
|
-
- `readFile` ([`ReadFile`](#
|
|
1177
|
+
- `readFile` ([`ReadFile`](#readfile))
|
|
1142
1178
|
— read the entire contents of a file
|
|
1143
|
-
- `realpath` ([`Realpath`](#
|
|
1179
|
+
- `realpath` ([`Realpath`](#realpath))
|
|
1144
1180
|
— compute a canonical pathname by resolving `.`, `..`, and symbolic links
|
|
1145
|
-
- `stat` ([`Stat`](#
|
|
1181
|
+
- `stat` ([`Stat`](#stat))
|
|
1146
1182
|
— get information about a directory or file
|
|
1147
1183
|
|
|
1148
1184
|
### `GetSourceContext`
|
|
@@ -1172,7 +1208,7 @@ Get the source code for a module (`type`).
|
|
|
1172
1208
|
type GetSourceHandler = (
|
|
1173
1209
|
this: GetSourceContext,
|
|
1174
1210
|
url: URL
|
|
1175
|
-
) => Awaitable<
|
|
1211
|
+
) => Awaitable<FileContent | null | undefined>
|
|
1176
1212
|
```
|
|
1177
1213
|
|
|
1178
1214
|
#### Parameters
|
|
@@ -1184,7 +1220,7 @@ type GetSourceHandler = (
|
|
|
1184
1220
|
|
|
1185
1221
|
#### Returns
|
|
1186
1222
|
|
|
1187
|
-
([`Awaitable<
|
|
1223
|
+
([`Awaitable<FileContent | null | undefined>`](#filecontent)) The source code
|
|
1188
1224
|
|
|
1189
1225
|
### `GetSourceHandlers`
|
|
1190
1226
|
|
|
@@ -1202,6 +1238,9 @@ Options for retrieving source code (`interface`).
|
|
|
1202
1238
|
|
|
1203
1239
|
#### Properties
|
|
1204
1240
|
|
|
1241
|
+
- `encoding?` ([`BufferEncoding`](#bufferencoding) | `null` | `undefined`)
|
|
1242
|
+
— the encoding of the result
|
|
1243
|
+
> 👉 **note**: used when the `file:` handler is called
|
|
1205
1244
|
- `format?` ([`ModuleFormat`](#moduleformat) | `null` | `undefined`)
|
|
1206
1245
|
— the module format hint
|
|
1207
1246
|
- `fs?` ([`FileSystem`](#filesystem) | `null` | `undefined`)
|
|
@@ -1372,25 +1411,35 @@ They will be added to this union automatically.
|
|
|
1372
1411
|
type Protocol = ProtocolMap[keyof ProtocolMap]
|
|
1373
1412
|
```
|
|
1374
1413
|
|
|
1375
|
-
### `ReadFile
|
|
1414
|
+
### `ReadFile`
|
|
1376
1415
|
|
|
1377
1416
|
Read the entire contents of a file (`interface`).
|
|
1378
1417
|
|
|
1418
|
+
#### Overloads
|
|
1419
|
+
|
|
1420
|
+
```ts
|
|
1421
|
+
(id: ModuleId, encoding: BufferEncoding): Awaitable<string>
|
|
1422
|
+
<T extends Awaitable<FileContent | null | undefined>>(id: ModuleId, encoding?: BufferEncoding | null | undefined): T
|
|
1423
|
+
```
|
|
1424
|
+
|
|
1379
1425
|
#### Type Parameters
|
|
1380
1426
|
|
|
1381
|
-
- `T` ([`Awaitable<
|
|
1427
|
+
- `T` ([`Awaitable<FileContent | null | undefined>`](#filecontent), optional)
|
|
1382
1428
|
— the file contents
|
|
1429
|
+
- **default**: [`Awaitable<FileContent>`](#filecontent)
|
|
1383
1430
|
|
|
1384
1431
|
#### Parameters
|
|
1385
1432
|
|
|
1386
1433
|
- `id` ([`ModuleId`](#moduleid))
|
|
1387
1434
|
— the module id
|
|
1435
|
+
- `encoding` ([`BufferEncoding`](#bufferencoding))
|
|
1436
|
+
— the encoding of the file contents
|
|
1388
1437
|
|
|
1389
1438
|
#### Returns
|
|
1390
1439
|
|
|
1391
1440
|
(`T`) The file contents
|
|
1392
1441
|
|
|
1393
|
-
### `Realpath
|
|
1442
|
+
### `Realpath`
|
|
1394
1443
|
|
|
1395
1444
|
Compute a canonical pathname by resolving `.`, `..`, and symbolic links (`interface`).
|
|
1396
1445
|
|
|
@@ -1461,7 +1510,7 @@ Options for path alias resolution (`interface`).
|
|
|
1461
1510
|
- `preserveSymlinks?` (`boolean` | `null` | `undefined`)
|
|
1462
1511
|
— whether to keep symlinks instead of resolving them
|
|
1463
1512
|
|
|
1464
|
-
### `Stat
|
|
1513
|
+
### `Stat`
|
|
1465
1514
|
|
|
1466
1515
|
Get information about a directory or file (`interface`).
|
|
1467
1516
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Interfaces - BufferEncodingMap
|
|
3
|
+
* @module mlly/interfaces/BufferEncodingMap
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Registry of character encodings that can be used when working
|
|
7
|
+
* with {@linkcode Buffer} objects.
|
|
8
|
+
*
|
|
9
|
+
* This interface can be augmented to register custom encodings.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* declare module '@flex-development/mlly' {
|
|
13
|
+
* interface BufferEncodingMap {
|
|
14
|
+
* custom: 'custom'
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
interface BufferEncodingMap {
|
|
19
|
+
ascii: 'ascii';
|
|
20
|
+
base64: 'base64';
|
|
21
|
+
base64url: 'base64url';
|
|
22
|
+
binary: 'binary';
|
|
23
|
+
hex: 'hex';
|
|
24
|
+
latin1: 'latin1';
|
|
25
|
+
ucs2: 'ucs2' | 'ucs-2';
|
|
26
|
+
utf16le: 'utf16le' | 'utf-16le';
|
|
27
|
+
utf8: 'utf8' | 'utf-8';
|
|
28
|
+
}
|
|
29
|
+
export type { BufferEncodingMap as default };
|
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
* @file Interfaces - GetSourceOptions
|
|
3
3
|
* @module mlly/interfaces/GetSourceOptions
|
|
4
4
|
*/
|
|
5
|
-
import type { FileSystem, GetSourceHandlers, List, ModuleFormat } from '@flex-development/mlly';
|
|
5
|
+
import type { BufferEncoding, FileSystem, GetSourceHandlers, List, ModuleFormat } from '@flex-development/mlly';
|
|
6
6
|
/**
|
|
7
7
|
* Options for retrieving source code.
|
|
8
8
|
*/
|
|
9
9
|
interface GetSourceOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The encoding of the result.
|
|
12
|
+
*
|
|
13
|
+
* > 👉 **Note**: Used when the `file:` handler is called.
|
|
14
|
+
*
|
|
15
|
+
* @see {@linkcode BufferEncoding}
|
|
16
|
+
*/
|
|
17
|
+
encoding?: BufferEncoding | null | undefined;
|
|
10
18
|
/**
|
|
11
19
|
* The module format hint.
|
|
12
20
|
*
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @module mlly/interfaces
|
|
4
4
|
*/
|
|
5
5
|
export type { default as Aliases } from '#interfaces/aliases';
|
|
6
|
+
export type { default as BufferEncodingMap } from '#interfaces/buffer-encoding-map';
|
|
6
7
|
export type { default as ConditionMap } from '#interfaces/condition-map';
|
|
7
8
|
export type { default as FileSystem } from '#interfaces/file-system';
|
|
8
9
|
export type { default as GetSourceContext } from '#interfaces/get-source-context';
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
interface IsDirectory {
|
|
9
9
|
/**
|
|
10
|
-
* @this {
|
|
10
|
+
* @this {unknown}
|
|
11
11
|
*
|
|
12
12
|
* @return {boolean}
|
|
13
13
|
* `true` if stats describes directory, `false` otherwise
|
|
14
14
|
*/
|
|
15
|
-
(
|
|
15
|
+
(): boolean;
|
|
16
16
|
}
|
|
17
17
|
export type { IsDirectory as default };
|
|
@@ -2,27 +2,41 @@
|
|
|
2
2
|
* @file Interfaces - ReadFile
|
|
3
3
|
* @module mlly/interfaces/ReadFile
|
|
4
4
|
*/
|
|
5
|
-
import type { Awaitable, ModuleId } from '@flex-development/mlly';
|
|
5
|
+
import type { Awaitable, BufferEncoding, FileContent, ModuleId } from '@flex-development/mlly';
|
|
6
6
|
/**
|
|
7
7
|
* Read the entire contents of a file.
|
|
8
|
-
*
|
|
9
|
-
* @see {@linkcode Awaitable}
|
|
10
|
-
* @see {@linkcode Buffer}
|
|
11
|
-
*
|
|
12
|
-
* @template {Awaitable<Buffer | string>} [T]
|
|
13
|
-
* The file contents
|
|
14
8
|
*/
|
|
15
|
-
interface ReadFile
|
|
9
|
+
interface ReadFile {
|
|
16
10
|
/**
|
|
17
11
|
* @see {@linkcode ModuleId}
|
|
18
12
|
*
|
|
19
|
-
* @this {
|
|
13
|
+
* @this {unknown}
|
|
20
14
|
*
|
|
21
15
|
* @param {ModuleId} id
|
|
22
16
|
* The module id
|
|
17
|
+
* @param {BufferEncoding} encoding
|
|
18
|
+
* The encoding of the file contents
|
|
19
|
+
* @return {Awaitable<string>}
|
|
20
|
+
* The file contents
|
|
21
|
+
*/
|
|
22
|
+
(id: ModuleId, encoding: BufferEncoding): Awaitable<string>;
|
|
23
|
+
/**
|
|
24
|
+
* @see {@linkcode Awaitable}
|
|
25
|
+
* @see {@linkcode FileContent}
|
|
26
|
+
* @see {@linkcode ModuleId}
|
|
27
|
+
*
|
|
28
|
+
* @template {Awaitable<FileContent | null | undefined>} T
|
|
29
|
+
* The file contents
|
|
30
|
+
*
|
|
31
|
+
* @this {unknown}
|
|
32
|
+
*
|
|
33
|
+
* @param {ModuleId} id
|
|
34
|
+
* The module id
|
|
35
|
+
* @param {BufferEncoding | null | undefined} [encoding]
|
|
36
|
+
* The encoding of the file contents
|
|
23
37
|
* @return {T}
|
|
24
38
|
* The file contents
|
|
25
39
|
*/
|
|
26
|
-
(
|
|
40
|
+
<T extends Awaitable<FileContent | null | undefined>>(id: ModuleId, encoding?: BufferEncoding | null | undefined): T;
|
|
27
41
|
}
|
|
28
42
|
export type { ReadFile as default };
|
|
@@ -8,23 +8,22 @@ import type { Awaitable, ModuleId } from '@flex-development/mlly';
|
|
|
8
8
|
*
|
|
9
9
|
* > 👉 **Note**: A canonical pathname is not necessarily unique.
|
|
10
10
|
* > Hard links and bind mounts can expose an entity through many pathnames.
|
|
11
|
-
*
|
|
12
|
-
* @see {@linkcode Awaitable}
|
|
13
|
-
*
|
|
14
|
-
* @template {Awaitable<string>} [T]
|
|
15
|
-
* The canonical pathname
|
|
16
11
|
*/
|
|
17
|
-
interface Realpath
|
|
12
|
+
interface Realpath {
|
|
18
13
|
/**
|
|
14
|
+
* @see {@linkcode Awaitable}
|
|
19
15
|
* @see {@linkcode ModuleId}
|
|
20
16
|
*
|
|
21
|
-
* @
|
|
17
|
+
* @template {Awaitable<string>} T
|
|
18
|
+
* The canonical pathname
|
|
19
|
+
*
|
|
20
|
+
* @this {unknown}
|
|
22
21
|
*
|
|
23
22
|
* @param {ModuleId} id
|
|
24
23
|
* The module id
|
|
25
24
|
* @return {T}
|
|
26
25
|
* The canonical pathname
|
|
27
26
|
*/
|
|
28
|
-
|
|
27
|
+
<T extends Awaitable<string>>(id: ModuleId): T;
|
|
29
28
|
}
|
|
30
29
|
export type { Realpath as default };
|
|
@@ -5,24 +5,23 @@
|
|
|
5
5
|
import type { Awaitable, ModuleId, Stats } from '@flex-development/mlly';
|
|
6
6
|
/**
|
|
7
7
|
* Get information about a directory or file.
|
|
8
|
-
*
|
|
9
|
-
* @see {@linkcode Awaitable}
|
|
10
|
-
* @see {@linkcode Stats}
|
|
11
|
-
*
|
|
12
|
-
* @template {Awaitable<Stats>} [T]
|
|
13
|
-
* The info
|
|
14
8
|
*/
|
|
15
|
-
interface Stat
|
|
9
|
+
interface Stat {
|
|
16
10
|
/**
|
|
11
|
+
* @see {@linkcode Awaitable}
|
|
17
12
|
* @see {@linkcode ModuleId}
|
|
13
|
+
* @see {@linkcode Stats}
|
|
18
14
|
*
|
|
19
|
-
* @
|
|
15
|
+
* @template {Awaitable<Stats>} T
|
|
16
|
+
* The info
|
|
17
|
+
*
|
|
18
|
+
* @this {unknown}
|
|
20
19
|
*
|
|
21
20
|
* @param {ModuleId} id
|
|
22
21
|
* The module id
|
|
23
22
|
* @return {T}
|
|
24
23
|
* The info
|
|
25
24
|
*/
|
|
26
|
-
|
|
25
|
+
<T extends Awaitable<Stats>>(id: ModuleId): T;
|
|
27
26
|
}
|
|
28
27
|
export type { Stat as default };
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
const fs = {
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Read the entire contents of a file.
|
|
13
13
|
*
|
|
14
14
|
* @return {never}
|
|
15
15
|
* Never; not implemented
|
|
@@ -19,17 +19,17 @@ const fs = {
|
|
|
19
19
|
throw new Error('[readFile] not implemented');
|
|
20
20
|
},
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Compute a canonical pathname by resolving `.`, `..`, and symbolic links.
|
|
23
23
|
*
|
|
24
24
|
* @return {never}
|
|
25
25
|
* Never; not implemented
|
|
26
26
|
* @throws {Error}
|
|
27
27
|
*/
|
|
28
28
|
realpath() {
|
|
29
|
-
throw new Error('[
|
|
29
|
+
throw new Error('[realpath] not implemented');
|
|
30
30
|
},
|
|
31
31
|
/**
|
|
32
|
-
* Get information about a file.
|
|
32
|
+
* Get information about a directory or file.
|
|
33
33
|
*
|
|
34
34
|
* @return {never}
|
|
35
35
|
* Never; not implemented
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @file getSource
|
|
3
3
|
* @module mlly/lib/getSource
|
|
4
4
|
*/
|
|
5
|
-
import type { Awaitable, EmptyString, GetSourceOptions, ModuleId } from '@flex-development/mlly';
|
|
5
|
+
import type { Awaitable, EmptyString, FileContent, GetSourceOptions, ModuleId } from '@flex-development/mlly';
|
|
6
6
|
export default getSource;
|
|
7
7
|
/**
|
|
8
8
|
* Get the source code for a module.
|
|
@@ -30,7 +30,7 @@ declare function getSource(this: void, id: EmptyString | null | undefined, optio
|
|
|
30
30
|
* @see {@linkcode GetSourceOptions}
|
|
31
31
|
* @see {@linkcode ModuleId}
|
|
32
32
|
*
|
|
33
|
-
* @template {Awaitable<
|
|
33
|
+
* @template {Awaitable<FileContent | null | undefined>} T
|
|
34
34
|
* The module source code
|
|
35
35
|
*
|
|
36
36
|
* @this {void}
|
|
@@ -43,4 +43,4 @@ declare function getSource(this: void, id: EmptyString | null | undefined, optio
|
|
|
43
43
|
* The module source code
|
|
44
44
|
* @throws {ErrUnsupportedEsmUrlScheme}
|
|
45
45
|
*/
|
|
46
|
-
declare function getSource<T extends Awaitable<
|
|
46
|
+
declare function getSource<T extends Awaitable<FileContent | null | undefined>>(this: void, id: ModuleId | null | undefined, options?: GetSourceOptions | null | undefined): T;
|
package/dist/lib/get-source.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export default getSource;
|
|
|
28
28
|
* The module id
|
|
29
29
|
* @param {GetSourceOptions | null | undefined} [options]
|
|
30
30
|
* Source code retrieval options
|
|
31
|
-
* @return {Awaitable<
|
|
31
|
+
* @return {Awaitable<FileContent | null | undefined>}
|
|
32
32
|
* The module source code
|
|
33
33
|
* @throws {ErrUnsupportedEsmUrlScheme}
|
|
34
34
|
*/
|
|
@@ -79,7 +79,7 @@ function getSource(id, options) {
|
|
|
79
79
|
/**
|
|
80
80
|
* The source code.
|
|
81
81
|
*
|
|
82
|
-
* @var {
|
|
82
|
+
* @var {ReturnType<GetSourceHandler>} code
|
|
83
83
|
*/
|
|
84
84
|
let code = handle.call(context, url);
|
|
85
85
|
// resolve source code.
|
|
@@ -87,10 +87,7 @@ function getSource(id, options) {
|
|
|
87
87
|
void code.then(resolved => (code = resolved));
|
|
88
88
|
}
|
|
89
89
|
return chainOrCall(code, () => {
|
|
90
|
-
ok(!isPromise(code), 'expected `code` to be resolved');
|
|
91
|
-
if (code !== null && code !== undefined)
|
|
92
|
-
code = String(code);
|
|
93
|
-
return code;
|
|
90
|
+
return ok(!isPromise(code), 'expected `code` to be resolved'), code;
|
|
94
91
|
});
|
|
95
92
|
}
|
|
96
93
|
/**
|
|
@@ -115,7 +112,7 @@ function data(url) {
|
|
|
115
112
|
*
|
|
116
113
|
* @param {URL} url
|
|
117
114
|
* The module URL
|
|
118
|
-
* @return {Awaitable<
|
|
115
|
+
* @return {Awaitable<FileContent | null>}
|
|
119
116
|
* The source code
|
|
120
117
|
*/
|
|
121
118
|
function file(url) {
|
|
@@ -127,7 +124,7 @@ function file(url) {
|
|
|
127
124
|
*/
|
|
128
125
|
const exists = isFile(url, this.fs);
|
|
129
126
|
return chainOrCall(exists, isFile => {
|
|
130
|
-
return isFile ?? exists ? this.fs.readFile(url) : null;
|
|
127
|
+
return isFile ?? exists ? this.fs.readFile(url, this.encoding) : null;
|
|
131
128
|
});
|
|
132
129
|
}
|
|
133
130
|
/**
|
|
@@ -62,19 +62,18 @@ function readPackageJson(id, specifier, parent, fs) {
|
|
|
62
62
|
/**
|
|
63
63
|
* The stringified contents of the package manifest file.
|
|
64
64
|
*
|
|
65
|
-
* @const {Awaitable<
|
|
65
|
+
* @const {Awaitable<string>} contents
|
|
66
66
|
*/
|
|
67
|
-
const contents = fs.readFile(url);
|
|
67
|
+
const contents = fs.readFile(url, 'utf8');
|
|
68
68
|
// parse file content.
|
|
69
|
-
return chainOrCall(contents, data => {
|
|
70
|
-
data ??= contents;
|
|
69
|
+
return chainOrCall(contents, (data = contents) => {
|
|
71
70
|
try {
|
|
72
71
|
/**
|
|
73
72
|
* The parsed file contents.
|
|
74
73
|
*
|
|
75
|
-
* @const {
|
|
74
|
+
* @const {unknown} parsed
|
|
76
75
|
*/
|
|
77
|
-
const parsed = JSON.parse(
|
|
76
|
+
const parsed = JSON.parse(data);
|
|
78
77
|
if (isPackageJson(parsed))
|
|
79
78
|
return parsed;
|
|
80
79
|
throw new Error('Invalid package manifest object', { cause: parsed });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - BufferEncoding
|
|
3
|
+
* @module mlly/types/BufferEncoding
|
|
4
|
+
*/
|
|
5
|
+
import type { BufferEncodingMap } from '@flex-development/mlly';
|
|
6
|
+
/**
|
|
7
|
+
* Union of values that can occur where a buffer encoding is expected.
|
|
8
|
+
*
|
|
9
|
+
* To register new encodings, augment {@linkcode BufferEncodingMap}.
|
|
10
|
+
* They will be added to this union automatically.
|
|
11
|
+
*/
|
|
12
|
+
type BufferEncoding = BufferEncodingMap[keyof BufferEncodingMap];
|
|
13
|
+
export type { BufferEncoding as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Type Aliases - FileContent
|
|
3
|
+
* @module mlly/types/FileContent
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Union of values that can occur where file content is expected.
|
|
7
|
+
*
|
|
8
|
+
* @see {@linkcode Uint8Array}
|
|
9
|
+
*/
|
|
10
|
+
type FileContent = Uint8Array | string;
|
|
11
|
+
export type { FileContent as default };
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* @file Type Aliases - GetSourceHandler
|
|
3
3
|
* @module mlly/types/GetSourceHandler
|
|
4
4
|
*/
|
|
5
|
-
import type { Awaitable, GetSourceContext } from '@flex-development/mlly';
|
|
5
|
+
import type { Awaitable, FileContent, GetSourceContext } from '@flex-development/mlly';
|
|
6
6
|
/**
|
|
7
7
|
* Get the source code for a module.
|
|
8
8
|
*
|
|
9
9
|
* @see {@linkcode Awaitable}
|
|
10
|
+
* @see {@linkcode FileContent}
|
|
10
11
|
* @see {@linkcode GetSourceContext}
|
|
11
12
|
* @see {@linkcode URL}
|
|
12
13
|
*
|
|
@@ -15,8 +16,8 @@ import type { Awaitable, GetSourceContext } from '@flex-development/mlly';
|
|
|
15
16
|
*
|
|
16
17
|
* @param {URL} url
|
|
17
18
|
* The module URL
|
|
18
|
-
* @return {Awaitable<
|
|
19
|
+
* @return {Awaitable<FileContent | null | undefined>}
|
|
19
20
|
* The source code
|
|
20
21
|
*/
|
|
21
|
-
type GetSourceHandler = (this: GetSourceContext, url: URL) => Awaitable<
|
|
22
|
+
type GetSourceHandler = (this: GetSourceContext, url: URL) => Awaitable<FileContent | null | undefined>;
|
|
22
23
|
export type { GetSourceHandler as default };
|
package/dist/types/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @module mlly/types
|
|
4
4
|
*/
|
|
5
5
|
export type { default as Awaitable } from '#types/awaitable';
|
|
6
|
+
export type { default as BufferEncoding } from '#types/buffer-encoding';
|
|
6
7
|
export type { default as ChangeExtFn } from '#types/change-ext-fn';
|
|
7
8
|
export type { default as Condition } from '#types/condition';
|
|
8
9
|
export type { default as Dot } from '#types/dot';
|
|
@@ -10,6 +11,7 @@ export type { default as EmptyArray } from '#types/empty-array';
|
|
|
10
11
|
export type { default as EmptyObject } from '#types/empty-object';
|
|
11
12
|
export type { default as EmptyString } from '#types/empty-string';
|
|
12
13
|
export type { default as Ext } from '#types/ext';
|
|
14
|
+
export type { default as FileContent } from '#types/file-content';
|
|
13
15
|
export type { default as GetSourceHandler } from '#types/get-source-handler';
|
|
14
16
|
export type { default as GetSourceHandlers } from '#types/get-source-handlers';
|
|
15
17
|
export type { default as List } from '#types/list';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flex-development/mlly",
|
|
3
3
|
"description": "ECMAScript module utilities",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.4",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecmascript",
|
|
7
7
|
"esm",
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
"@arethetypeswrong/cli": "0.18.2",
|
|
159
159
|
"@commitlint/cli": "20.4.1",
|
|
160
160
|
"@commitlint/types": "20.4.0",
|
|
161
|
-
"@faker-js/faker": "10.
|
|
161
|
+
"@faker-js/faker": "10.3.0",
|
|
162
162
|
"@flex-development/commitlint-config": "1.0.1",
|
|
163
163
|
"@flex-development/eslint-config": "1.1.1",
|
|
164
164
|
"@flex-development/grease": "3.0.0-alpha.9",
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
"chai-string": "1.6.0",
|
|
181
181
|
"concat-stream": "2.0.0",
|
|
182
182
|
"cross-env": "10.1.0",
|
|
183
|
-
"cspell": "9.6.
|
|
183
|
+
"cspell": "9.6.4",
|
|
184
184
|
"dprint": "0.51.1",
|
|
185
185
|
"editorconfig": "3.0.1",
|
|
186
186
|
"eslint": "9.39.2",
|
|
@@ -188,7 +188,7 @@
|
|
|
188
188
|
"husky": "9.1.7",
|
|
189
189
|
"import-meta-resolve": "4.2.0",
|
|
190
190
|
"is-ci": "4.1.0",
|
|
191
|
-
"msw": "2.12.
|
|
191
|
+
"msw": "2.12.9",
|
|
192
192
|
"node-notifier": "10.0.1",
|
|
193
193
|
"remark": "15.0.1",
|
|
194
194
|
"remark-cli": "12.0.1",
|