@@ -83,6 +83,7 @@ import {
83
83
} from '../utils'
84
84
import type { Logger } from '../logger'
85
85
import { cleanUrl , isWindows , slash } from '../../shared/utils'
86
+ import { NULL_BYTE_PLACEHOLDER } from '../../shared/constants'
86
87
import { createBackCompatIdResolver } from '../idResolver'
87
88
import type { ResolveIdFn } from '../idResolver'
88
89
import { PartialEnvironment } from '../baseEnvironment'
@@ -3160,10 +3161,9 @@ async function compileLightningCSS(
3160
3161
) : ReturnType < typeof compileCSS > {
3161
3162
const { config } = environment
3162
3163
const deps = new Set < string > ( )
3163
- // Relative path is needed to get stable hash when using CSS modules
3164
- const filename = cleanUrl ( path . relative ( config . root , id ) )
3165
- const toAbsolute = ( filePath : string ) =>
3166
- path . isAbsolute ( filePath ) ? filePath : path . join ( config . root , filePath )
3164
+ // replace null byte as lightningcss treats that as a string terminator
3165
+ // https://github.com/parcel-bundler/lightningcss/issues/874
3166
+ const filename = id . replace ( '\0' , NULL_BYTE_PLACEHOLDER )
3167
3167
3168
3168
let res : LightningCssTransformAttributeResult | LightningCssTransformResult
3169
3169
try {
@@ -3180,16 +3180,14 @@ async function compileLightningCSS(
3180
3180
) . bundleAsync ( {
3181
3181
...config . css . lightningcss ,
3182
3182
filename,
3183
+ // projectRoot is needed to get stable hash when using CSS modules
3184
+ projectRoot : config . root ,
3183
3185
resolver : {
3184
3186
read ( filePath ) {
3185
3187
if ( filePath === filename ) {
3186
3188
return src
3187
3189
}
3188
- // This happens with html-proxy (#13776)
3189
- if ( ! filePath . endsWith ( '.css' ) ) {
3190
- return src
3191
- }
3192
- return fs . readFileSync ( toAbsolute ( filePath ) , 'utf-8' )
3190
+ return fs . readFileSync ( filePath , 'utf-8' )
3193
3191
} ,
3194
3192
async resolve ( id , from ) {
3195
3193
const publicFile = checkPublicFile (
@@ -3202,7 +3200,7 @@ async function compileLightningCSS(
3202
3200
3203
3201
const resolved = await getAtImportResolvers (
3204
3202
environment . getTopLevelConfig ( ) ,
3205
- ) . css ( environment , id , toAbsolute ( from ) )
3203
+ ) . css ( environment , id , from )
3206
3204
3207
3205
if ( resolved ) {
3208
3206
deps . add ( resolved )
@@ -3224,7 +3222,7 @@ async function compileLightningCSS(
3224
3222
} catch ( e ) {
3225
3223
e . message = `[lightningcss] ${ e . message } `
3226
3224
e . loc = {
3227
- file : toAbsolute ( e . fileName ) ,
3225
+ file : e . fileName . replace ( NULL_BYTE_PLACEHOLDER , '\0' ) ,
3228
3226
line : e . loc . line ,
3229
3227
column : e . loc . column - 1 , // 1-based
3230
3228
}
@@ -3242,7 +3240,10 @@ async function compileLightningCSS(
3242
3240
if ( skipUrlReplacer ( dep . url ) ) {
3243
3241
replaceUrl = dep . url
3244
3242
} else if ( urlReplacer ) {
3245
- replaceUrl = await urlReplacer ( dep . url , toAbsolute ( dep . loc . filePath ) )
3243
+ replaceUrl = await urlReplacer (
3244
+ dep . url ,
3245
+ dep . loc . filePath . replace ( NULL_BYTE_PLACEHOLDER , '\0' ) ,
3246
+ )
3246
3247
} else {
3247
3248
replaceUrl = dep . url
3248
3249
}
0 commit comments