Merge pull request #10868 from strapi/v4/plugin-api/local-plugin-loading

Append strapi.dir to plugin path if relative
This commit is contained in:
Alexandre BODIN 2021-09-06 07:56:33 +00:00 committed by GitHub
commit 52bc4642b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -15,7 +15,7 @@ module.exports = ({ env }) => ({
},
myplugin: {
enabled: true,
resolve: `${__dirname}/../plugins/myplugin`,
resolve: `./plugins/myplugin`, // From the root of the project
config: {
testConf: 3,
},

View File

@ -1,6 +1,6 @@
'use strict';
const { dirname, join } = require('path');
const { dirname, join, resolve } = require('path');
const { statSync, existsSync } = require('fs');
const _ = require('lodash');
const { get, has, pick, pickBy, defaultsDeep, map, prop, pipe } = require('lodash/fp');
@ -29,9 +29,9 @@ const toDetailedDeclaration = declaration => {
try {
pathToPlugin = dirname(require.resolve(declaration.resolve));
} catch (e) {
if (existsSync(declaration.resolve) && statSync(declaration.resolve).isDirectory()) {
pathToPlugin = declaration.resolve;
} else {
pathToPlugin = resolve(strapi.dir, declaration.resolve);
if (!existsSync(pathToPlugin) || !statSync(pathToPlugin).isDirectory()) {
throw new Error(`${declaration.resolve} couldn't be resolved`);
}
}