@@ -3,7 +3,6 @@ const postcss = require("postcss");
33const util = require ( "util" ) ;
44const tmp = require ( "tmp" ) ;
55const path = require ( "path" ) ;
6- const { sync : resolve } = require ( "resolve" ) ;
76
87const readFile = util . promisify ( fs . readFile ) ;
98const writeFile = util . promisify ( fs . writeFile ) ;
@@ -20,11 +19,28 @@ module.exports = (options = { plugins: [] }) => ({
2019 async ( args ) => {
2120 let sourceFullPath ;
2221
23- // Use Node's module resolution algorithm for modules from node_modules
22+ // Manual attempt at resolving from node_modules and other typical directories
2423 if ( args . path . startsWith ( '.' ) || path . isAbsolute ( args . path ) ) {
2524 sourceFullPath = path . resolve ( args . resolveDir , args . path ) ;
2625 } else {
27- sourceFullPath = resolve ( args . path , { basedir : args . resolveDir } ) ;
26+ const modulePaths = [
27+ // possible locations for node modules, maybe this is not strictly necessary
28+ path . resolve ( args . resolveDir , 'node_modules' , args . path ) ,
29+ path . resolve ( rootDir , 'node_modules' , args . path ) ,
30+ path . resolve ( rootDir , '../node_modules' , args . path )
31+ ] ;
32+
33+ for ( const modulePath of modulePaths ) {
34+ if ( fs . existsSync ( modulePath ) ) {
35+ // if we find the path we need, use it as the sourceFullPath
36+ sourceFullPath = modulePath ;
37+ break ;
38+ }
39+ }
40+
41+ if ( ! sourceFullPath ) {
42+ throw new Error ( `Cannot resolve module: ${ args . path } ` ) ;
43+ }
2844 }
2945
3046 const sourceExt = path . extname ( sourceFullPath ) ;
0 commit comments