chore: miscellaneous small cleanups#1268
Conversation
- Derive `Clone` for `Resolution` (the manual impl was field-for-field identical to the derive). - Merge the two identical #[cold] empty-error constructors in `Specifier::parse`. - `require_hash`: `ok_or_else` instead of `map_or_else(|| Err(..), Ok)`. - Remove a pointless `Some(owned).as_deref().unwrap()` in the legacy `jest-runner-../..` fallback path. - Drop a redundant `.as_ref()` on `file_name()` in `Cache::value`. - Remove dead napi `EnforceExtension` helpers (no callers, not #[napi]-exported) and a no-op `let _ = meta` in a test. - Fix stale doc comment on `TsConfig::root`: template variable substitution is driven by `should_build` now.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1268 +/- ##
==========================================
- Coverage 93.85% 93.83% -0.03%
==========================================
Files 21 21
Lines 4313 4298 -15
==========================================
- Hits 4048 4033 -15
Misses 265 265 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Two cross-file dedups plus stale-allow removal: - **`push_normalized_component`** existed twice — `path.rs` and `cache/cached_path.rs` — identical except the cached-path copy trims the trailing `\0` that uvwasi appends to directory entries on wasm ([nodejs/uvwasi#262](nodejs/uvwasi#262)). This keeps one `pub` wasm-aware version in `path.rs`. Note this means `path.rs` callers (tsconfig path joins) now also get the `\0`-trim on wasm; on native targets the generated code is unchanged, and the helper stays `#[inline]` so the hot `normalize_with` path keeps its codegen. - **`manual_tsconfig()`**: the "manually configured tsconfig, deliberately skipping `Auto` discovery" match block was duplicated verbatim in `lib.rs` (`resolve`) and `dts_resolver.rs` (`dts_resolve_tsconfig_paths`). One helper in `tsconfig_resolver.rs` now owns it, and `find_tsconfig_manual` drops its `pub(crate)`. - **Stale allows**: `clippy::cognitive_complexity` on `extend_tsconfig` and `clippy::too_many_lines` on `dts_try_extensions`' neighbor no longer suppress anything (verified by removing them and running the CI clippy command); `extend_tsconfig` keeps `too_many_lines` (139/100). Part of a second cleanup pass; follows #1264–#1268.
…#1270) The two "resolve from symlinks" benches did, per timed iteration, 10,000 eager `format!("./file{i}")` allocations plus an `assert!(.. .is_ok())` branch — unlike every sibling bench in the file, which iterates precomputed data and discards results with `_ =`. The asserts also re-checked an invariant already validated once before the benchmark group runs. This precomputes the specifiers once (mirroring the `find tsconfig` bench's hoisting pattern) and drops the in-loop asserts, so the benches measure symlink resolution rather than resolution + allocation noise. The validation pass also now constructs one resolver instead of 10,000. **Heads-up:** this will step-change the CodSpeed series for `resolver_memory/resolve from symlinks` and `resolver_real/resolve from symlinks` downward — that's the removed allocation/assert overhead, not a resolver perf change. Part of a second cleanup pass; follows #1264–#1268.
Small leftovers found while sweeping the test suite and the JS side: - `src/tests/resolve.rs`: the "file in module with query and fragment" table row appeared twice, byte-identical — the upstream enhanced-resolve `resolve.test.js` has the case exactly once, so the second row was a copy-paste in the port. The loop just ran the same assertion twice. - `src/tests/alias.rs`: `#[allow(clippy::too_many_lines)]` no longer suppresses anything (verified by removing it and running the CI clippy command). The same allow in `imports_field.rs` is still load-bearing (1191/100) and stays. - `vite.config.ts`: `"napi/browser.js"` was listed twice in `fmt.ignorePatterns`. - `napi/test.mjs`: removed a stale comment about a `.ts` extension next to code that adds `.mjs` and resolves an already-suffixed specifier. - `napi/webcontainer-fallback.js`: removed an inert lint directive (`// eslint-disable-next-line: no-console`) — the project lints with oxlint, the syntax is invalid even for ESLint, and `no-console` isn't enabled. Part of a second cleanup pass; follows #1264–#1268.
A batch of tiny, independent cleanups:
CloneforResolution— the manual impl was field-for-field identical to what the derive produces (Debug/PartialEqstay manual, they're genuinely custom).#[cold]empty-error constructors inSpecifier::parseinto one.require_hash:.ok_or_else(..)instead of.map_or_else(|| Err(..), Ok).Some(owned).as_deref().unwrap()dance in the legacyjest-runner-../..fallback path..as_ref()onfile_name()inCache::value(&OsStr == &stralready works viaOsStr: PartialEq<str>).EnforceExtension::{is_auto,is_enabled,is_disabled}helpers — zero callers anywhere in the repo and not#[napi]-exported, so they never reached JS.let _ = meta;in themetadatatest.TsConfig::root/root()": it claimed the field drives final template-variable substitution, but that's keyed offshould_buildnow;rootjust records whether the config is the caller's (vs loaded throughextends`).Split out of #1263.