mirror of
https://github.com/strapi/strapi.git
synced 2025-08-22 23:59:17 +00:00
Merge pull request #21194 from strapi/chore/strapi-server-resolve
enhancement: resolve strapi-server with exports map too
This commit is contained in:
commit
d7ca1a1259
@ -10,9 +10,9 @@
|
||||
"default": "./admin/src/index.js"
|
||||
},
|
||||
"./strapi-server": {
|
||||
"source": "./strapi-server.js",
|
||||
"require": "./strapi-server.js",
|
||||
"default": "./strapi-server.js"
|
||||
"source": "./server/index.js",
|
||||
"require": "./server/index.js",
|
||||
"default": "./server/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
|
11
examples/plugins/workspace-plugin/server/index.js
Normal file
11
examples/plugins/workspace-plugin/server/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const config = require('./config');
|
||||
const register = require('./register');
|
||||
|
||||
module.exports = () => {
|
||||
return {
|
||||
register,
|
||||
config,
|
||||
};
|
||||
};
|
@ -1,10 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const config = require('./server/config');
|
||||
const register = require('./server/register');
|
||||
module.exports = () => {
|
||||
return {
|
||||
register,
|
||||
config,
|
||||
};
|
||||
};
|
@ -63,4 +63,4 @@ const getAdminEE = () => {
|
||||
return eeAdmin;
|
||||
};
|
||||
|
||||
export default getAdminEE();
|
||||
export default getAdminEE;
|
||||
|
@ -1,14 +1,11 @@
|
||||
import type { Core } from '@strapi/types';
|
||||
|
||||
export const enableFeatureMiddleware: Core.MiddlewareFactory =
|
||||
(featureName: string) => (ctx, next) => {
|
||||
export const enableFeatureMiddleware =
|
||||
(featureName: string): Core.MiddlewareHandler =>
|
||||
(ctx, next) => {
|
||||
if (strapi.ee.features.isEnabled(featureName)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
ctx.status = 404;
|
||||
};
|
||||
|
||||
export default {
|
||||
enableFeatureMiddleware,
|
||||
};
|
||||
|
@ -51,8 +51,9 @@
|
||||
"./strapi-server": {
|
||||
"types": "./dist/server/src/index.d.ts",
|
||||
"source": "./server/src/index.js",
|
||||
"require": "./strapi-server.js",
|
||||
"default": "./strapi-server.js"
|
||||
"import": "./dist/server/index.mjs",
|
||||
"require": "./dist/server/index.js",
|
||||
"default": "./dist/server/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
|
@ -17,12 +17,6 @@ const config: Config = defineConfig({
|
||||
tsconfig: './server/tsconfig.build.json',
|
||||
runtime: 'node',
|
||||
},
|
||||
{
|
||||
source: './ee/server/src/index.ts',
|
||||
import: './dist/ee/server/index.mjs',
|
||||
require: './dist/ee/server/index.js',
|
||||
runtime: 'node',
|
||||
},
|
||||
],
|
||||
dist: './dist',
|
||||
/**
|
||||
|
@ -1,11 +1,37 @@
|
||||
export { default as bootstrap } from './bootstrap';
|
||||
export { default as register } from './register';
|
||||
export { default as destroy } from './destroy';
|
||||
import _ from 'lodash';
|
||||
|
||||
export { default as config } from './config';
|
||||
export { default as policies } from './policies';
|
||||
export { default as routes } from './routes';
|
||||
export { default as services } from './services';
|
||||
export { default as controllers } from './controllers';
|
||||
export { default as contentTypes } from './content-types';
|
||||
export { default as middlewares } from './middlewares';
|
||||
import bootstrap from './bootstrap';
|
||||
import register from './register';
|
||||
import destroy from './destroy';
|
||||
import config from './config';
|
||||
import policies from './policies';
|
||||
import routes from './routes';
|
||||
import services from './services';
|
||||
import controllers from './controllers';
|
||||
import contentTypes from './content-types';
|
||||
import middlewares from './middlewares';
|
||||
import getEEAdmin from '../../ee/server/src';
|
||||
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
let admin = {
|
||||
bootstrap,
|
||||
register,
|
||||
destroy,
|
||||
config,
|
||||
policies,
|
||||
routes,
|
||||
services,
|
||||
controllers,
|
||||
contentTypes,
|
||||
middlewares,
|
||||
};
|
||||
|
||||
const mergeRoutes = (a: any, b: any, key: string) => {
|
||||
return _.isArray(a) && _.isArray(b) && key === 'routes' ? a.concat(b) : undefined;
|
||||
};
|
||||
|
||||
if (strapi.EE) {
|
||||
admin = _.mergeWith({}, admin, getEEAdmin(), mergeRoutes);
|
||||
}
|
||||
|
||||
export default admin;
|
||||
|
@ -1,18 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const admin = require('./dist/server');
|
||||
|
||||
const mergeRoutes = (a, b, key) => {
|
||||
return _.isArray(a) && _.isArray(b) && key === 'routes' ? a.concat(b) : undefined;
|
||||
};
|
||||
|
||||
if (strapi.EE) {
|
||||
const eeAdmin = require('./dist/ee/server');
|
||||
// module.exports = admin;
|
||||
// TODO: change to avoid issue with lodash merging frozen objects
|
||||
module.exports = _.mergeWith({}, admin, eeAdmin, mergeRoutes);
|
||||
} else {
|
||||
module.exports = admin;
|
||||
}
|
@ -37,8 +37,8 @@
|
||||
"./strapi-server": {
|
||||
"types": "./dist/server/src/index.d.ts",
|
||||
"source": "./server/src/index.ts",
|
||||
"require": "./strapi-server.js",
|
||||
"default": "./strapi-server.js"
|
||||
"require": "./dist/server/index.js",
|
||||
"default": "./dist/server/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -99,6 +99,7 @@
|
||||
"package-json": "7.0.0",
|
||||
"pkg-up": "3.1.0",
|
||||
"qs": "6.11.1",
|
||||
"resolve.exports": "2.0.2",
|
||||
"semver": "7.5.4",
|
||||
"statuses": "2.0.1",
|
||||
"typescript": "5.2.2",
|
||||
|
@ -11,6 +11,7 @@ interface PluginMeta {
|
||||
enabled: boolean;
|
||||
pathToPlugin?: string;
|
||||
info: Record<string, unknown>;
|
||||
packageInfo?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
type PluginMetas = Record<string, PluginMeta>;
|
||||
@ -102,6 +103,7 @@ export const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { clie
|
||||
internalPlugins[packageInfo.strapi.name] = {
|
||||
...toDetailedDeclaration({ enabled: true, resolve: packagePath, isModule: client }),
|
||||
info: packageInfo.strapi,
|
||||
packageInfo,
|
||||
};
|
||||
}
|
||||
|
||||
@ -125,6 +127,7 @@ export const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { clie
|
||||
...packageInfo.strapi,
|
||||
packageName: packageInfo.name,
|
||||
},
|
||||
packageInfo,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -149,6 +152,7 @@ export const getEnabledPlugins = async (strapi: Core.Strapi, { client } = { clie
|
||||
|
||||
if (isStrapiPlugin(packageInfo)) {
|
||||
declaredPlugins[pluginName].info = packageInfo.strapi || {};
|
||||
declaredPlugins[pluginName].packageInfo = packageInfo;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { join } from 'path';
|
||||
import fse from 'fs-extra';
|
||||
import { defaultsDeep, defaults, getOr, get } from 'lodash/fp';
|
||||
import * as resolve from 'resolve.exports';
|
||||
|
||||
import { env } from '@strapi/utils';
|
||||
import type { Core, Plugin, Struct } from '@strapi/types';
|
||||
import { loadConfigFile } from '../../utils/load-config-file';
|
||||
@ -94,9 +96,20 @@ export default async function loadPlugins(strapi: Core.Strapi) {
|
||||
const enabledPlugin = enabledPlugins[pluginName];
|
||||
|
||||
let serverEntrypointPath;
|
||||
let resolvedExport = './strapi-server';
|
||||
|
||||
try {
|
||||
serverEntrypointPath = join(enabledPlugin.pathToPlugin, 'strapi-server.js');
|
||||
resolvedExport = (
|
||||
resolve.exports(enabledPlugin.packageInfo, 'strapi-server', {
|
||||
require: true,
|
||||
}) ?? './strapi-server'
|
||||
).toString();
|
||||
} catch (e) {
|
||||
// key missing in exports map or no export map -> let's try the legacy way
|
||||
}
|
||||
|
||||
try {
|
||||
serverEntrypointPath = join(enabledPlugin.pathToPlugin, resolvedExport);
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
`Error loading the plugin ${pluginName} because ${pluginName} is not installed. Please either install the plugin or remove it's configuration.`
|
||||
|
@ -3,6 +3,7 @@ import loadAdmin from '../loaders/admin';
|
||||
|
||||
export default defineProvider({
|
||||
init(strapi) {
|
||||
// eslint-disable-next-line node/no-missing-require
|
||||
strapi.add('admin', () => require('@strapi/admin/strapi-server'));
|
||||
},
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./dist/server');
|
@ -27,9 +27,9 @@
|
||||
"default": "./dist/admin/index.js"
|
||||
},
|
||||
"./strapi-server": {
|
||||
"source": "./strapi-server.js",
|
||||
"require": "./strapi-server.js",
|
||||
"default": "./strapi-server.js"
|
||||
"source": "./server/index.js",
|
||||
"require": "./server/index.js",
|
||||
"default": "./server/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
|
@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./server');
|
@ -8757,6 +8757,7 @@ __metadata:
|
||||
package-json: "npm:7.0.0"
|
||||
pkg-up: "npm:3.1.0"
|
||||
qs: "npm:6.11.1"
|
||||
resolve.exports: "npm:2.0.2"
|
||||
semver: "npm:7.5.4"
|
||||
statuses: "npm:2.0.1"
|
||||
supertest: "npm:6.3.3"
|
||||
@ -28113,7 +28114,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"resolve.exports@npm:^2.0.0":
|
||||
"resolve.exports@npm:2.0.2, resolve.exports@npm:^2.0.0":
|
||||
version: 2.0.2
|
||||
resolution: "resolve.exports@npm:2.0.2"
|
||||
checksum: 10c0/cc4cffdc25447cf34730f388dca5021156ba9302a3bad3d7f168e790dc74b2827dff603f1bc6ad3d299bac269828dca96dd77e036dc9fba6a2a1807c47ab5c98
|
||||
|
Loading…
x
Reference in New Issue
Block a user