1- import type { LoaderContext } from "webpack" ;
2- import { resolveCrossFileConstant } from "./lib/resolveCrossFileSelectors.js" ;
31import { relative } from "path" ;
2+ import type { LoaderContext } from "webpack" ;
43import type { YakConfigOptions } from "../withYak/index.js" ;
4+ import { resolveCrossFileConstant } from "./lib/resolveCrossFileSelectors.js" ;
55
66/**
77 * Transform typescript to css
@@ -22,6 +22,11 @@ export default async function cssExtractLoader(
2222 if ( err ) {
2323 return callback ( err ) ;
2424 }
25+ if ( ! source ) {
26+ return callback (
27+ new Error ( `Source code for ${ this . resourcePath } is empty` ) ,
28+ ) ;
29+ }
2530 const { experiments } = this . getOptions ( ) ;
2631 const debugLog = createDebugLogger ( this , experiments ?. debug ) ;
2732
@@ -36,8 +41,22 @@ export default async function cssExtractLoader(
3641 } ) ;
3742}
3843
39- function extractCss ( code : string ) : string {
40- const codeParts = code . split ( "/*YAK Extracted CSS:\n" ) ;
44+ function extractCss ( code : string | Buffer < ArrayBufferLike > ) : string {
45+ let codeString : string ;
46+
47+ if ( typeof code === "string" ) {
48+ codeString = code ;
49+ } else if ( code instanceof Buffer ) {
50+ codeString = code . toString ( "utf-8" ) ;
51+ } else if ( code instanceof ArrayBuffer ) {
52+ codeString = new TextDecoder ( "utf-8" ) . decode ( code ) ;
53+ } else {
54+ throw new Error (
55+ "Invalid input type: code must be string, Buffer, or ArrayBuffer" ,
56+ ) ;
57+ }
58+
59+ const codeParts = codeString . split ( "/*YAK Extracted CSS:\n" ) ;
4160 let result = "" ;
4261 for ( let i = 1 ; i < codeParts . length ; i ++ ) {
4362 const codeUntilEnd = codeParts [ i ] . split ( "*/" ) [ 0 ] ;
@@ -59,7 +78,10 @@ function createDebugLogger(
5978 return ( ) => { } ;
6079 }
6180 const debugType = debugOptions === true ? "ts" : debugOptions . type ;
62- return ( messageType : "ts" | "css" | "css resolved" , message : string ) => {
81+ return (
82+ messageType : "ts" | "css" | "css resolved" ,
83+ message : string | Buffer < ArrayBufferLike > | undefined ,
84+ ) => {
6385 if ( messageType === debugType || debugType === "all" ) {
6486 console . log (
6587 "🐮 Yak" ,
0 commit comments