char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
38d5bbf
main
avril's path build
The lexical operations in lexical.ts are adapted by hand from Node.js
lib/path.js at v22.16.0 (commit
9774069718d9f80578079d252dddf37ae6fd550d, tag v22.16.0, 2025-05-21),
whose MIT license and copyright header are preserved at the top of that
file. urls.ts (file URL conversion) is original avril code; its behavior
follows Node's fileURLToPath/pathToFileURL and the WHATWG URL standard
where noted in docs/path.md.
There is no pristine upstream copy or patch file here: only the path
algorithms and minimal input validators were carried over, not Node's
internal/constants, internal/validators, process, or glob support,
so a mechanical patch would be mostly deletions. lexical.ts keeps the
upstream structure and explanatory comments to stay comparable with the
source; local differences from upstream are:
process.cwd()is avril's permission-checkedop_process_cwd, called only when relative, root-relative, or drive-relative input actually needs it. Fully qualified inputs need no read grant, and a missing grant throws the usualPermissionDeniedinstead of being swallowed.process.env[=${device}](Windows per-drive directories) is not read and introduces no environment permission: a requested drive matching the working directory's drive reuses it, otherwise resolution falls back to that drive's root.- Explicit POSIX semantics on Windows use Node's POSIX view of the working directory (separators converted, drive indicator truncated).
validateString/validateObjectthrow plainTypeErrors; no error codes.validateObjectrejects functions, like Node's default validation.glob/matchesGloband legacy_makeLongare omitted, as are the recursivewin32/posixself-references.- All builtins used during calls are captured through
ext:core/primordials(extended with the string and array helpers path code needs). String splitting uses a smallsplitOnCharhelper rather thanString.prototype.split, so a poisonedSymbol.splithook on the separator cannot dispatch. NoRegExp, nofor-ofover arrays, no guest-global lookups.
urls.ts captures the WHATWG URL class, its property getters, and the
standard encodeURIComponent/decodeURIComponent at module scope.
Percent-decoding delegates malformed-escape, overlong, and range validation
to the standard codec (re-wrapped as TypeError); NUL bytes and lone
surrogates are still checked explicitly, as is the encoded-separator scan.
The kept-literal ASCII set matches Node's pathToFileURL table exactly
(verified differentially over bytes 1-127), with ~ escaped manually
because the standard codec leaves it alone. api.ts builds each frozen
variant namespace once so all three entry modules share identity.
To re-verify against upstream:
git init node&& git -C node remote add origin https://github.com/nodejs/node.gitgit -C node fetch--depth=1 origin v22.16.0git -C node checkout--detach -q FETCH_HEADdiff <( git -C node show HEAD:lib/path.js) exts/path/src/lexical.ts
expecting type annotations and the adaptations listed above (plus the wrapper split into
main.ts/posix.ts/win32.ts/api.ts and the URL helpers in urls.ts).
1# avril's path build 2 3The lexical operations in `lexical.ts` are adapted by hand from Node.js 4`lib/path.js` at v22.16.0 (commit 5`9774069718d9f80578079d252dddf37ae6fd550d`, tag `v22.16.0`, `2025-05-21`), 6whose MIT license and copyright header are preserved at the top of that 7file. `urls.ts` (file URL conversion) is original avril code; its behavior 8follows Node's `fileURLToPath`/`pathToFileURL` and the WHATWG URL standard 9where noted in `docs/path.md`. 10 11There is no pristine upstream copy or patch file here: only the path 12algorithms and minimal input validators were carried over, not Node's 13`internal/constants`, `internal/validators`, `process`, or `glob` support, 14so a mechanical patch would be mostly deletions. `lexical.ts` keeps the 15upstream structure and explanatory comments to stay comparable with the 16source; local differences from upstream are: 17 18- `process.cwd()` is avril's permission-checked `op_process_cwd`, called 19only when relative, root-relative, or drive-relative input actually needs 20 it. Fully qualified inputs need no read grant, and a missing grant throws 21 the usual `PermissionDenied` instead of being swallowed. 22 - `process.env[`=${device}`]` (Windows per-drive directories) is not read 23and introduces no environment permission: a requested drive matching the 24 working directory's drive reuses it, otherwise resolution falls back to 25 that drive's root. 26 - Explicit POSIX semantics on Windows use Node's POSIX view of the working 27directory (separators converted, drive indicator truncated). 28 - `validateString`/`validateObject` throw plain `TypeError`s; no error codes. 29`validateObject` rejects functions, like Node's default validation. 30 - `glob`/`matchesGlob` and legacy `_makeLong` are omitted, as are the 31recursive `win32`/`posix` self-references. 32 - All builtins used during calls are captured through 33`ext:core/primordials` (extended with the string and array helpers path 34 code needs). String splitting uses a small `splitOnChar` helper rather 35 than `String.prototype.split`, so a poisoned `Symbol.split` hook on the 36 separator cannot dispatch. No `RegExp`, no `for`-`of` over arrays, no 37 guest-global lookups. 38 39 `urls.ts` captures the WHATWG URL class, its property getters, and the 40standard `encodeURIComponent`/`decodeURIComponent` at module scope. 41Percent-decoding delegates malformed-escape, overlong, and range validation 42to the standard codec (re-wrapped as `TypeError`); NUL bytes and lone 43surrogates are still checked explicitly, as is the encoded-separator scan. 44The kept-literal ASCII set matches Node's `pathToFileURL` table exactly 45(verified differentially over bytes 1-127), with `~` escaped manually 46because the standard codec leaves it alone. `api.ts` builds each frozen 47variant namespace once so all three entry modules share identity. 48 49To re-verify against upstream: 50 51``` sh 52git init node && git -C node remote add origin https://github.com/nodejs/node.git 53git -C node fetch --depth=1 origin v22.16.0 54git -C node checkout --detach -q FETCH_HEAD 55diff <(git -C node show HEAD:lib/path.js) exts/path/src/lexical.ts 56``` 57 58expecting type annotations and the adaptations listed above (plus the wrapper split into 59`main.ts`/`posix.ts`/`win32.ts`/`api.ts` and the URL helpers in `urls.ts`).