Skip to content

Commit

Permalink
Merge pull request #2755 from mnahkies/mn/fix/improve-plugin-discovery
Browse files Browse the repository at this point in the history
fix: resolve plugin directories using node
  • Loading branch information
zachstence authored Nov 12, 2024
2 parents a20bae8 + 602f833 commit 18e1b42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-countries-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/sdk': patch
---

fix plugin resolution when hoisted by package managers
6 changes: 3 additions & 3 deletions packages/lib/sdk/src/plugins/loadPluginPackage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import chalk from 'chalk';
import { PluginPackageSchema } from './schemas/plugin-package.schema.js';
import fs from 'fs/promises';
import { createRequire } from 'module';
import path from 'path';
import { projectRoot } from '../lib/projectRoot.js';

/**
*
* @param {string} name
* @returns {Promise<null | import("./schemas/plugin-package.schema.js").PluginPackage & {dir: string}>}
*/
export const loadPluginPackage = async (name) => {
// We have to use this instead of read/resolve PackageJSON because these packages don't have an index file
const packagePath = path.join(projectRoot, 'node_modules', name, 'package.json');
const pluginPackageDirectory = path.dirname(createRequire(import.meta.url).resolve(name));
const packagePath = path.join(pluginPackageDirectory, 'package.json');

const packageContent = JSON.parse(await fs.readFile(packagePath, 'utf-8'));
const pack = PluginPackageSchema.safeParse(packageContent);
Expand Down

0 comments on commit 18e1b42

Please sign in to comment.