0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(core): check connector-kit compatibility when load connector (#2798)

This commit is contained in:
Gao Sun 2023-01-01 18:36:46 +08:00 committed by GitHub
parent 6e56de3583
commit ab54c38cd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 63 additions and 4 deletions

View file

@ -1,7 +1,9 @@
/** @type {import('jest').Config} */
const config = {
transform: {},
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
coverageReporters: ['text-summary', 'lcov'],
coverageProvider: 'v8',
roots: ['./lib'],
moduleNameMapper: {
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',

View file

@ -1,7 +1,9 @@
/** @type {import('jest').Config} */
const config = {
transform: {},
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
coverageReporters: ['text-summary', 'lcov'],
coverageProvider: 'v8',
testPathIgnorePatterns: ['/node_modules/', '/build/routes/session/'], // `routes/session` is freezed
setupFilesAfterEnv: ['jest-matcher-specific-error', './jest.setup.js'],
roots: ['./build'],

View file

@ -62,6 +62,7 @@
"oidc-provider": "^7.13.0",
"p-retry": "^5.1.2",
"roarr": "^7.11.0",
"semver": "^7.3.8",
"slonik": "^30.0.0",
"slonik-interceptor-preset": "^1.2.10",
"slonik-sql-tag-raw": "^1.1.4",
@ -85,6 +86,7 @@
"@types/koa-send": "^4.1.3",
"@types/node": "^16.0.0",
"@types/oidc-provider": "^7.12.0",
"@types/semver": "^7.3.12",
"@types/sinon": "^10.0.13",
"@types/supertest": "^2.0.11",
"copyfiles": "^2.4.1",

View file

@ -15,6 +15,7 @@ import { findAllConnectors } from '#src/queries/connector.js';
import { defaultConnectorMethods } from './consts.js';
import { metaUrl } from './meta-url.js';
import type { ConnectorFactory, LogtoConnector } from './types.js';
import { checkConnectorKitVersion } from './utilities/compatibility.js';
import { getConnectorConfig, parseMetadata, validateConnectorModule } from './utilities/index.js';
const currentDirname = path.dirname(fileURLToPath(metaUrl));
@ -39,6 +40,8 @@ export const loadConnectorFactories = async () => {
const connectorFactories = await Promise.all(
connectorPackages.map(async ({ path: packagePath, name }) => {
try {
await checkConnectorKitVersion(packagePath);
// TODO: fix type and remove `/lib/index.js` suffix once we upgrade all connectors to ESM
const {
default: { default: createConnector },

View file

@ -0,0 +1,32 @@
import path from 'path';
import connectorKitMeta from '@logto/connector-kit/package.json' assert { type: 'json' };
import { satisfies } from 'semver';
const connectorKit = '@logto/connector-kit';
const { version: currentVersion } = connectorKitMeta;
export const checkConnectorKitVersion = async (connectorPath: string) => {
const {
default: { dependencies },
// eslint-disable-next-line no-restricted-syntax
} = (await import(path.join(connectorPath, 'package.json'), {
assert: { type: 'json' },
})) as { default: Record<string, unknown> };
if (dependencies !== null && typeof dependencies === 'object' && connectorKit in dependencies) {
const value = dependencies[connectorKit];
if (typeof value === 'string') {
if (satisfies(currentVersion, value)) {
return;
}
throw new Error(
`Connector requires ${connectorKit} to be ${value}, but the version here is ${currentVersion}.`
);
}
}
throw new Error(`Cannot find ${connectorKit} in connector's dependency`);
};

View file

@ -1,6 +1,8 @@
/** @type {import('jest').Config} */
const config = {
transform: {},
testPathIgnorePatterns: ['/node_modules/'],
coverageProvider: 'v8',
setupFilesAfterEnv: ['./jest.setup.js'],
roots: ['./lib'],
moduleNameMapper: {

View file

@ -1,5 +1,6 @@
/** @type {import('jest').Config} */
const config = {
transform: {},
preset: 'jest-puppeteer',
setupFilesAfterEnv: ['./jest.setup.js'],
moduleNameMapper: {

View file

@ -1,7 +1,9 @@
/** @type {import('jest').Config} */
const config = {
transform: {},
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
coverageReporters: ['text-summary', 'lcov'],
coverageProvider: 'v8',
roots: ['./lib'],
moduleNameMapper: {
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',

View file

@ -1,7 +1,9 @@
/** @type {import('jest').Config} */
const config = {
transform: {},
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
coverageReporters: ['text-summary', 'lcov'],
coverageProvider: 'v8',
roots: ['./lib'],
moduleNameMapper: {
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',

View file

@ -11,9 +11,12 @@
"type": "module",
"main": "./lib/index.cjs",
"exports": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"./package.json": "./package.json"
},
"types": "./lib/index.d.ts",
"files": [

View file

@ -1,7 +1,9 @@
/** @type {import('jest').Config} */
const config = {
transform: {},
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
coverageReporters: ['text-summary', 'lcov'],
coverageProvider: 'v8',
setupFilesAfterEnv: ['jest-matcher-specific-error'],
roots: ['./lib'],
moduleNameMapper: {

View file

@ -1,7 +1,9 @@
/** @type {import('jest').Config} */
const config = {
transform: {},
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
coverageReporters: ['text-summary', 'lcov'],
coverageProvider: 'v8',
roots: ['./lib'],
moduleNameMapper: {
'^(chalk|inquirer)$': '<rootDir>/../../shared/lib/esm/module-proxy.js',

View file

@ -270,6 +270,7 @@ importers:
'@types/koa-send': ^4.1.3
'@types/node': ^16.0.0
'@types/oidc-provider': ^7.12.0
'@types/semver': ^7.3.12
'@types/sinon': ^10.0.13
'@types/supertest': ^2.0.11
'@withtyped/postgres': ^0.3.1
@ -310,6 +311,7 @@ importers:
p-retry: ^5.1.2
prettier: ^2.8.1
roarr: ^7.11.0
semver: ^7.3.8
sinon: ^15.0.0
slonik: ^30.0.0
slonik-interceptor-preset: ^1.2.10
@ -357,6 +359,7 @@ importers:
oidc-provider: 7.13.0
p-retry: 5.1.2
roarr: 7.11.0
semver: 7.3.8
slonik: 30.1.2
slonik-interceptor-preset: 1.2.10
slonik-sql-tag-raw: 1.1.4_roarr@7.11.0+slonik@30.1.2
@ -379,6 +382,7 @@ importers:
'@types/koa-send': 4.1.3
'@types/node': 16.11.12
'@types/oidc-provider': 7.12.0
'@types/semver': 7.3.12
'@types/sinon': 10.0.13
'@types/supertest': 2.0.11
copyfiles: 2.4.1
@ -13954,7 +13958,7 @@ packages:
mime: 2.6.0
qs: 6.10.2
readable-stream: 3.6.0
semver: 7.3.7
semver: 7.3.8
transitivePeerDependencies:
- supports-color
dev: true