Skip to content

Commit f11dd09

Browse files
refactor: support sass condition name.
1 parent 5a8afef commit f11dd09

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

docs/roadmap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@
1515

1616
- Evaluate promoting `lightningcss` to a peer dependency so consumers can align with their own upgrade cadence.
1717
- Document fallbacks for specificity workflows if teams opt to satisfy the peer via compatible forks or alternative transformers.
18+
19+
## Sass Resolver Options
20+
21+
- Allow configuring conditionNames for `pkg:` resolution (e.g., opt into `sass` or custom priority ordering).
22+
- Allow opting into explicit `tsconfig` selection instead of `tsconfig: auto` when resolving `pkg:` specifiers.

packages/css/src/sassInternals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ export function resolveRelativeSpecifier(
210210
const SASS_EXTENSIONS = ['.scss', '.sass', '.css']
211211

212212
export function createPkgResolver(cwd: string) {
213-
const factory = createResolverFactory(cwd, SASS_EXTENSIONS, SASS_EXTENSIONS)
213+
const factory = createResolverFactory(cwd, SASS_EXTENSIONS, SASS_EXTENSIONS, {
214+
conditions: ['sass', 'import', 'require', 'node', 'default'],
215+
})
214216
return async (specifier: string, containingPath?: string) => {
215217
const importer = containingPath ?? path.join(cwd, 'index.scss')
216218
const resolved = resolveWithFactory(factory, specifier, importer, SASS_EXTENSIONS)

packages/css/test/sassImporter.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,41 @@ test('sass importer resolves pkg: specifiers via oxc-resolver', async () => {
151151
await fs.rm(root, { recursive: true, force: true })
152152
}
153153
})
154+
155+
test('sass importer honors sass condition name', async () => {
156+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'knighted-sass-conditions-'))
157+
try {
158+
const srcDir = path.join(root, 'src')
159+
const stylesDir = path.join(srcDir, 'styles')
160+
await fs.mkdir(stylesDir, { recursive: true })
161+
await fs.writeFile(path.join(stylesDir, 'sass.scss'), '.sass { color: blue; }')
162+
await fs.writeFile(path.join(stylesDir, 'default.scss'), '.default { color: red; }')
163+
await fs.writeFile(
164+
path.join(root, 'package.json'),
165+
JSON.stringify(
166+
{
167+
name: 'knighted-sass-conditions-fixture',
168+
type: 'module',
169+
imports: {
170+
'#styles/entry.scss': {
171+
sass: './src/styles/sass.scss',
172+
default: './src/styles/default.scss',
173+
},
174+
},
175+
},
176+
null,
177+
2,
178+
),
179+
)
180+
181+
const importer = __sassInternals.createSassImporter({ cwd: root })
182+
const containing = pathToFileURL(path.join(srcDir, 'entry.scss'))
183+
const resolved = await importer.canonicalize('pkg:#styles/entry.scss', {
184+
containingUrl: containing,
185+
})
186+
assert.ok(resolved, 'expected pkg: specifier to resolve')
187+
assert.ok(resolved?.href.endsWith('/sass.scss'))
188+
} finally {
189+
await fs.rm(root, { recursive: true, force: true })
190+
}
191+
})

0 commit comments

Comments
 (0)