From 9d17dc7ea4b31eb3ab9ecfc5e1c6563af4f880ae Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Tue, 20 Apr 2021 11:32:58 +0200 Subject: [PATCH] getPackagePath: handle the current package not being installed In case we want to get the package path of the current package, but it isn't in node_modules (as is the case with yarn2) we need to find it ourselves. In case the package.json in the current dir has the same name we just use it as a base. This is after rollup lookup failed, so this is just a fallback. --- rollup.utils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rollup.utils.js b/rollup.utils.js index 34533210..1029d63f 100644 --- a/rollup.utils.js +++ b/rollup.utils.js @@ -39,8 +39,14 @@ export async function getPackagePath(packageName, assetPath) { const packageInfo = r.getPackageInfoForId(id); packageRoot = packageInfo.root; } else { - // Non JS packages - packageRoot = path.dirname(require.resolve(packageName + '/package.json')); + let current = require.resolve('./package.json'); + if (require(current).name === packageName) { + // current package + packageRoot = path.dirname(current); + } else { + // Non JS packages + packageRoot = path.dirname(require.resolve(packageName + '/package.json')); + } } return path.relative(process.cwd(), path.join(packageRoot, assetPath)); } -- GitLab