Skip to content

Commit f0219f5

Browse files
authored
Remove resolve dependency
Add possible locations for the node modules directory
1 parent 041864f commit f0219f5

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const postcss = require("postcss");
33
const util = require("util");
44
const tmp = require("tmp");
55
const path = require("path");
6-
const { sync: resolve } = require("resolve");
76

87
const readFile = util.promisify(fs.readFile);
98
const 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

Comments
 (0)