@@ -30,7 +30,6 @@ import { WorkerWithFallback } from 'artichokie'
30
30
import { globSync } from 'tinyglobby'
31
31
import type {
32
32
LessPreprocessorBaseOptions ,
33
- SassLegacyPreprocessBaseOptions ,
34
33
SassModernPreprocessBaseOptions ,
35
34
StylusPreprocessorBaseOptions ,
36
35
} from 'types/internal/cssPreprocessorOptions'
@@ -2252,10 +2251,7 @@ type PreprocessorAdditionalData =
2252
2251
2253
2252
export type SassPreprocessorOptions = {
2254
2253
additionalData ?: PreprocessorAdditionalData
2255
- } & (
2256
- | ( { api : 'legacy' } & SassLegacyPreprocessBaseOptions )
2257
- | ( { api ?: 'modern' | 'modern-compiler' } & SassModernPreprocessBaseOptions )
2258
- )
2254
+ } & ( { api ?: 'modern' | 'modern-compiler' } & SassModernPreprocessBaseOptions )
2259
2255
2260
2256
export type LessPreprocessorOptions = {
2261
2257
additionalData ?: PreprocessorAdditionalData
@@ -2377,149 +2373,8 @@ function cleanScssBugUrl(url: string) {
2377
2373
}
2378
2374
}
2379
2375
2380
- function fixScssBugImportValue (
2381
- data : Sass . LegacyImporterResult ,
2382
- ) : Sass . LegacyImporterResult {
2383
- // the scss bug doesn't load files properly so we have to load it ourselves
2384
- // to prevent internal error when it loads itself
2385
- if (
2386
- // check bug via `window` and `location` global
2387
- typeof window !== 'undefined' &&
2388
- typeof location !== 'undefined' &&
2389
- data &&
2390
- 'file' in data &&
2391
- ( ! ( 'contents' in data ) || data . contents == null )
2392
- ) {
2393
- // @ts -expect-error we need to preserve file property for HMR
2394
- data . contents = fs . readFileSync ( data . file , 'utf-8' )
2395
- }
2396
- return data
2397
- }
2398
-
2399
2376
// #region Sass
2400
2377
// .scss/.sass processor
2401
- const makeScssWorker = (
2402
- environment : PartialEnvironment ,
2403
- resolvers : CSSAtImportResolvers ,
2404
- alias : Alias [ ] ,
2405
- maxWorkers : number | undefined ,
2406
- packageName : 'sass' | 'sass-embedded' ,
2407
- ) => {
2408
- const internalImporter = async (
2409
- url : string ,
2410
- importer : string ,
2411
- filename : string ,
2412
- ) => {
2413
- importer = cleanScssBugUrl ( importer )
2414
- const resolved = await resolvers . sass ( environment , url , importer )
2415
- if ( resolved ) {
2416
- try {
2417
- const data = await rebaseUrls (
2418
- environment ,
2419
- resolved ,
2420
- filename ,
2421
- alias ,
2422
- '$' ,
2423
- resolvers . sass ,
2424
- )
2425
- if ( packageName === 'sass-embedded' ) {
2426
- return data
2427
- }
2428
- return fixScssBugImportValue ( data )
2429
- } catch ( data ) {
2430
- return data
2431
- }
2432
- } else {
2433
- return null
2434
- }
2435
- }
2436
-
2437
- const worker = new WorkerWithFallback (
2438
- ( ) =>
2439
- async (
2440
- sassPath : string ,
2441
- data : string ,
2442
- // additionalData can a function that is not cloneable but it won't be used
2443
- options : SassStylePreprocessorInternalOptions & {
2444
- api : 'legacy'
2445
- additionalData : undefined
2446
- } ,
2447
- ) => {
2448
- // eslint-disable-next-line no-restricted-globals -- this function runs inside a cjs worker
2449
- const sass : typeof Sass = require ( sassPath )
2450
- // eslint-disable-next-line no-restricted-globals
2451
- const path : typeof import ( 'node:path' ) = require ( 'node:path' )
2452
-
2453
- // NOTE: `sass` always runs it's own importer first, and only falls back to
2454
- // the `importer` option when it can't resolve a path
2455
- const _internalImporter : Sass . LegacyAsyncImporter = (
2456
- url ,
2457
- importer ,
2458
- done ,
2459
- ) => {
2460
- internalImporter ( url , importer , options . filename ) . then ( ( data ) =>
2461
- done ( data ) ,
2462
- )
2463
- }
2464
- const importer = [ _internalImporter ]
2465
- if ( options . importer ) {
2466
- if ( Array . isArray ( options . importer ) ) {
2467
- importer . unshift ( ...options . importer )
2468
- } else {
2469
- importer . unshift ( options . importer )
2470
- }
2471
- }
2472
-
2473
- const finalOptions : Sass . LegacyOptions < 'async' > = {
2474
- // support @import from node dependencies by default
2475
- includePaths : [ 'node_modules' ] ,
2476
- ...options ,
2477
- data,
2478
- file : options . filename ,
2479
- outFile : options . filename ,
2480
- importer,
2481
- ...( options . enableSourcemap
2482
- ? {
2483
- sourceMap : true ,
2484
- omitSourceMapUrl : true ,
2485
- sourceMapRoot : path . dirname ( options . filename ) ,
2486
- }
2487
- : { } ) ,
2488
- }
2489
- return new Promise < ScssWorkerResult > ( ( resolve , reject ) => {
2490
- sass . render ( finalOptions , ( err , res ) => {
2491
- if ( err ) {
2492
- reject ( err )
2493
- } else {
2494
- resolve ( {
2495
- css : res ! . css . toString ( ) ,
2496
- map : res ! . map ?. toString ( ) ,
2497
- stats : res ! . stats ,
2498
- } )
2499
- }
2500
- } )
2501
- } )
2502
- } ,
2503
- {
2504
- parentFunctions : { internalImporter } ,
2505
- shouldUseFake ( _sassPath , _data , options ) {
2506
- // functions and importer is a function and is not serializable
2507
- // in that case, fallback to running in main thread
2508
- return ! ! (
2509
- ( options . functions && Object . keys ( options . functions ) . length > 0 ) ||
2510
- ( options . importer &&
2511
- ( ! Array . isArray ( options . importer ) ||
2512
- options . importer . length > 0 ) ) ||
2513
- options . logger ||
2514
- options . pkgImporter
2515
- )
2516
- } ,
2517
- max : maxWorkers ,
2518
- } ,
2519
- )
2520
- return worker
2521
- }
2522
-
2523
2378
const makeModernScssWorker = (
2524
2379
environment : PartialEnvironment ,
2525
2380
resolvers : CSSAtImportResolvers ,
@@ -2741,7 +2596,7 @@ const makeModernCompilerScssWorker = (
2741
2596
type ScssWorkerResult = {
2742
2597
css : string
2743
2598
map ?: string | undefined
2744
- stats : Pick < Sass . LegacyResult [ 'stats' ] , 'includedFiles' >
2599
+ stats : { includedFiles : string [ ] }
2745
2600
}
2746
2601
2747
2602
const scssProcessor = (
@@ -2750,9 +2605,7 @@ const scssProcessor = (
2750
2605
const workerMap = new Map <
2751
2606
unknown ,
2752
2607
ReturnType <
2753
- | typeof makeScssWorker
2754
- | typeof makeModernScssWorker
2755
- | typeof makeModernCompilerScssWorker
2608
+ typeof makeModernScssWorker | typeof makeModernCompilerScssWorker
2756
2609
>
2757
2610
> ( )
2758
2611
@@ -2778,20 +2631,12 @@ const scssProcessor = (
2778
2631
options . alias ,
2779
2632
maxWorkers ,
2780
2633
)
2781
- : api === 'modern'
2782
- ? makeModernScssWorker (
2783
- environment ,
2784
- resolvers ,
2785
- options . alias ,
2786
- maxWorkers ,
2787
- )
2788
- : makeScssWorker (
2789
- environment ,
2790
- resolvers ,
2791
- options . alias ,
2792
- maxWorkers ,
2793
- sassPackage . name ,
2794
- ) ,
2634
+ : makeModernScssWorker (
2635
+ environment ,
2636
+ resolvers ,
2637
+ options . alias ,
2638
+ maxWorkers ,
2639
+ ) ,
2795
2640
)
2796
2641
}
2797
2642
const worker = workerMap . get ( options . alias ) !
@@ -3317,11 +3162,7 @@ const createPreprocessorWorkerController = (maxWorkers: number | undefined) => {
3317
3162
const sassProcess : StylePreprocessor < SassStylePreprocessorInternalOptions > [ 'process' ] =
3318
3163
( environment , source , root , options , resolvers ) => {
3319
3164
const opts : SassStylePreprocessorInternalOptions = { ...options }
3320
- if ( opts . api === 'legacy' ) {
3321
- opts . indentedSyntax = true
3322
- } else {
3323
- opts . syntax = 'indented'
3324
- }
3165
+ opts . syntax = 'indented'
3325
3166
return scss . process ( environment , source , root , opts , resolvers )
3326
3167
}
3327
3168
0 commit comments