Skip to content

Commit a79242d

Browse files
feat: use oxc-resolver. (#27)
1 parent 7ae85d2 commit a79242d

10 files changed

Lines changed: 1510 additions & 51 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717

1818
## Features
1919

20-
- Traverses module graphs using [`dependency-tree`](https://github.com/dependents/node-dependency-tree) to find transitive style imports.
20+
- Traverses module graphs with a built-in walker to find transitive style imports (no bundler required).
21+
- Resolution parity via [`oxc-resolver`](https://github.com/oxc-project/oxc-resolver): tsconfig `paths`, package `exports` conditions, and extension aliasing (e.g., `.css.js``.css.ts`) are honored without wiring up a bundler.
2122
- Compiles `*.css`, `*.scss`, `*.sass`, `*.less`, and `*.css.ts` (vanilla-extract) files out of the box.
2223
- Optional post-processing via [`lightningcss`](https://github.com/parcel-bundler/lightningcss) for minification, prefixing, media query optimizations, or specificity boosts.
2324
- Pluggable resolver/filter hooks for custom module resolution (e.g., Rspack/Vite/webpack aliases) or selective inclusion.
2425
- First-class loader (`@knighted/css/loader`) so bundlers can import compiled CSS alongside their modules via `?knighted-css`.
2526

2627
## Requirements
2728

28-
- Node.js `>= 22.15.0`
29+
- Node.js `>= 22.17.0`
2930
- npm `>= 10.9.0`
3031
- Install peer toolchains you intend to use (`sass`, `less`, `@vanilla-extract/integration`, etc.).
3132

@@ -66,10 +67,10 @@ type CssOptions = {
6667
strategy?: SpecificityStrategy
6768
match?: SpecificitySelector[]
6869
}
69-
dependencyTree?: DependencyTreeOptions
70+
moduleGraph?: ModuleGraphOptions
7071
resolver?: (
7172
specifier: string,
72-
ctx: { cwd: string },
73+
ctx: { cwd: string; from?: string },
7374
) => string | Promise<string | undefined>
7475
peerResolver?: (name: string) => Promise<unknown> // for custom module loading
7576
}
@@ -81,6 +82,7 @@ Typical customizations:
8182

8283
- **filter**Skip certain paths (e.g., storybook-only styles) before compilation.
8384
- **resolver**Resolve virtual specifiers the way your bundler does (the repo ships test fixtures for webpack, Vite, and Rspack).
85+
- **moduleGraph**Configure tsconfig path aliases, extra script extensions, or custom `package.json` conditions for the built-in dependency walker.
8486
- **lightningcss**Pass `true` for defaults or a config object for minification/autoprefixing.
8587
- **specificityBoost**Provide a Lightning CSS visitor to bump specificity on selected selectors (e.g., duplicate a class for matching selectors).
8688

@@ -388,7 +390,7 @@ That hint keeps the upstream CommonJS helpers intact while still letting the res
388390

389391
### Custom resolver (enhanced-resolve example)
390392

391-
If your project uses aliases or nonstandard resolution, plug in a custom resolver. Heres how to use [`enhanced-resolve`](https://github.com/webpack/enhanced-resolve):
393+
The built-in walker already leans on [`oxc-resolver`](https://github.com/oxc-project/oxc-resolver), so tsconfig `paths`, package `exports` conditions, and common extension aliases work out of the box. If you still need to mirror bespoke behavior (virtual modules, framework-specific loaders, etc.), plug in a custom resolver. Here’s how to use [`enhanced-resolve`](https://github.com/webpack/enhanced-resolve):
392394

393395
```ts
394396
import { ResolverFactory } from 'enhanced-resolve'

docs/how-it-works.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Overview
44

55
- The loader walks the module graph and gathers style-producing files (`.css`, `.scss`, `.sass`, `.less`, `.css.ts`, etc.).
6-
- It uses `dependency-tree` (via `precinct`) to follow imports in the order they appear in source.
6+
- It walks the module graph with a built-in depth-first resolver so imports are visited in source order.
7+
- Resolution is powered by [`oxc-resolver`](https://github.com/oxc-project/oxc-resolver), so tsconfig `paths`, package `exports` conditions, and extension aliasing (like `.css.js``.css.ts`) all map to the same targets you’d get in a bundler.
78
- CSS from those files is concatenated in that discovery order and returned as `knightedCss` for injection (e.g., Lit ` css`` `, SSR, SSG).
89
- We do **not** sort or reorder; first-seen order is kept, so the CSS cascade mirrors the original import sequence.
910

@@ -16,7 +17,7 @@
1617

1718
### Example ordering
1819

19-
We rely on `dependency-tree` (via `precinct`) to follow imports in the order they appear in source. We concatenate CSS in depth-first, preorder (parent before children), preserving sibling order as written. Files are deduped: the first time a file is seen, it’s included; later encounters are skipped to avoid reshuffling the cascade. We never sort the list, and `lightningcss` preserves the rule order we provide.
20+
The walker performs a depth-first, preorder traversal (parent before children) so imports are resolved exactly as they are written in source. Files are deduped: the first time a file is seen, it’s included; later encounters are skipped to avoid reshuffling the cascade. We never sort the list, and `lightningcss` preserves the rule order we provide.
2021

2122
Given:
2223

0 commit comments

Comments
 (0)