File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 11import path from 'path' ;
2- import fs from 'fs' ;
2+ import fs , { constants } from 'fs' ;
33import matchAll from 'string.prototype.matchall' ;
44import fromEntries from 'object.fromentries' ;
55import { PluginOptions , CSSModuleList } from '../types' ;
@@ -84,8 +84,9 @@ const parseMarkup = async (
8484
8585 parsedContent = parsedContent . replace (
8686 PATTERN_IMPORT ,
87- ( _match , varName , relativePath , extension ) => {
87+ ( match , varName , relativePath , extension ) => {
8888 const absolutePath = path . resolve ( path . dirname ( filename ) , relativePath ) ;
89+ const nodeModulesPath = path . resolve ( `${ path . resolve ( ) } /node_modules` , relativePath ) ;
8990 try {
9091 const fileContent = fs . readFileSync ( absolutePath , 'utf8' ) ;
9192 importedStyleContent . push ( fileContent ) ;
@@ -143,7 +144,12 @@ const parseMarkup = async (
143144
144145 return `const ${ varName } = ${ JSON . stringify ( fromEntries ( classlist ) ) } ;` ;
145146 } catch ( err ) {
146- throw new Error ( err ) ;
147+ fs . access ( nodeModulesPath , constants . F_OK , ( error ) => {
148+ if ( error ) {
149+ throw new Error ( err ) ; // not found in node_modules packages either, throw orignal error
150+ }
151+ } ) ;
152+ return match ;
147153 }
148154 }
149155 ) ;
You can’t perform that action at this time.
0 commit comments