mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
refactor(core): check connector-kit compatibility when load connector (#2798)
This commit is contained in:
parent
6e56de3583
commit
ab54c38cd5
13 changed files with 63 additions and 4 deletions
|
@ -1,7 +1,9 @@
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
|
transform: {},
|
||||||
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
||||||
coverageReporters: ['text-summary', 'lcov'],
|
coverageReporters: ['text-summary', 'lcov'],
|
||||||
|
coverageProvider: 'v8',
|
||||||
roots: ['./lib'],
|
roots: ['./lib'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',
|
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
|
transform: {},
|
||||||
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
||||||
coverageReporters: ['text-summary', 'lcov'],
|
coverageReporters: ['text-summary', 'lcov'],
|
||||||
|
coverageProvider: 'v8',
|
||||||
testPathIgnorePatterns: ['/node_modules/', '/build/routes/session/'], // `routes/session` is freezed
|
testPathIgnorePatterns: ['/node_modules/', '/build/routes/session/'], // `routes/session` is freezed
|
||||||
setupFilesAfterEnv: ['jest-matcher-specific-error', './jest.setup.js'],
|
setupFilesAfterEnv: ['jest-matcher-specific-error', './jest.setup.js'],
|
||||||
roots: ['./build'],
|
roots: ['./build'],
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
"oidc-provider": "^7.13.0",
|
"oidc-provider": "^7.13.0",
|
||||||
"p-retry": "^5.1.2",
|
"p-retry": "^5.1.2",
|
||||||
"roarr": "^7.11.0",
|
"roarr": "^7.11.0",
|
||||||
|
"semver": "^7.3.8",
|
||||||
"slonik": "^30.0.0",
|
"slonik": "^30.0.0",
|
||||||
"slonik-interceptor-preset": "^1.2.10",
|
"slonik-interceptor-preset": "^1.2.10",
|
||||||
"slonik-sql-tag-raw": "^1.1.4",
|
"slonik-sql-tag-raw": "^1.1.4",
|
||||||
|
@ -85,6 +86,7 @@
|
||||||
"@types/koa-send": "^4.1.3",
|
"@types/koa-send": "^4.1.3",
|
||||||
"@types/node": "^16.0.0",
|
"@types/node": "^16.0.0",
|
||||||
"@types/oidc-provider": "^7.12.0",
|
"@types/oidc-provider": "^7.12.0",
|
||||||
|
"@types/semver": "^7.3.12",
|
||||||
"@types/sinon": "^10.0.13",
|
"@types/sinon": "^10.0.13",
|
||||||
"@types/supertest": "^2.0.11",
|
"@types/supertest": "^2.0.11",
|
||||||
"copyfiles": "^2.4.1",
|
"copyfiles": "^2.4.1",
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { findAllConnectors } from '#src/queries/connector.js';
|
||||||
import { defaultConnectorMethods } from './consts.js';
|
import { defaultConnectorMethods } from './consts.js';
|
||||||
import { metaUrl } from './meta-url.js';
|
import { metaUrl } from './meta-url.js';
|
||||||
import type { ConnectorFactory, LogtoConnector } from './types.js';
|
import type { ConnectorFactory, LogtoConnector } from './types.js';
|
||||||
|
import { checkConnectorKitVersion } from './utilities/compatibility.js';
|
||||||
import { getConnectorConfig, parseMetadata, validateConnectorModule } from './utilities/index.js';
|
import { getConnectorConfig, parseMetadata, validateConnectorModule } from './utilities/index.js';
|
||||||
|
|
||||||
const currentDirname = path.dirname(fileURLToPath(metaUrl));
|
const currentDirname = path.dirname(fileURLToPath(metaUrl));
|
||||||
|
@ -39,6 +40,8 @@ export const loadConnectorFactories = async () => {
|
||||||
const connectorFactories = await Promise.all(
|
const connectorFactories = await Promise.all(
|
||||||
connectorPackages.map(async ({ path: packagePath, name }) => {
|
connectorPackages.map(async ({ path: packagePath, name }) => {
|
||||||
try {
|
try {
|
||||||
|
await checkConnectorKitVersion(packagePath);
|
||||||
|
|
||||||
// TODO: fix type and remove `/lib/index.js` suffix once we upgrade all connectors to ESM
|
// TODO: fix type and remove `/lib/index.js` suffix once we upgrade all connectors to ESM
|
||||||
const {
|
const {
|
||||||
default: { default: createConnector },
|
default: { default: createConnector },
|
||||||
|
|
32
packages/core/src/connectors/utilities/compatibility.ts
Normal file
32
packages/core/src/connectors/utilities/compatibility.ts
Normal 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`);
|
||||||
|
};
|
|
@ -1,6 +1,8 @@
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
|
transform: {},
|
||||||
testPathIgnorePatterns: ['/node_modules/'],
|
testPathIgnorePatterns: ['/node_modules/'],
|
||||||
|
coverageProvider: 'v8',
|
||||||
setupFilesAfterEnv: ['./jest.setup.js'],
|
setupFilesAfterEnv: ['./jest.setup.js'],
|
||||||
roots: ['./lib'],
|
roots: ['./lib'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
|
transform: {},
|
||||||
preset: 'jest-puppeteer',
|
preset: 'jest-puppeteer',
|
||||||
setupFilesAfterEnv: ['./jest.setup.js'],
|
setupFilesAfterEnv: ['./jest.setup.js'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
|
transform: {},
|
||||||
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
||||||
coverageReporters: ['text-summary', 'lcov'],
|
coverageReporters: ['text-summary', 'lcov'],
|
||||||
|
coverageProvider: 'v8',
|
||||||
roots: ['./lib'],
|
roots: ['./lib'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',
|
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
|
transform: {},
|
||||||
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
||||||
coverageReporters: ['text-summary', 'lcov'],
|
coverageReporters: ['text-summary', 'lcov'],
|
||||||
|
coverageProvider: 'v8',
|
||||||
roots: ['./lib'],
|
roots: ['./lib'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',
|
'^(chalk|inquirer)$': '<rootDir>/../shared/lib/esm/module-proxy.js',
|
||||||
|
|
|
@ -11,9 +11,12 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./lib/index.cjs",
|
"main": "./lib/index.cjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
"types": "./lib/index.d.ts",
|
".": {
|
||||||
"import": "./lib/index.js",
|
"types": "./lib/index.d.ts",
|
||||||
"require": "./lib/index.cjs"
|
"import": "./lib/index.js",
|
||||||
|
"require": "./lib/index.cjs"
|
||||||
|
},
|
||||||
|
"./package.json": "./package.json"
|
||||||
},
|
},
|
||||||
"types": "./lib/index.d.ts",
|
"types": "./lib/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
|
transform: {},
|
||||||
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
||||||
coverageReporters: ['text-summary', 'lcov'],
|
coverageReporters: ['text-summary', 'lcov'],
|
||||||
|
coverageProvider: 'v8',
|
||||||
setupFilesAfterEnv: ['jest-matcher-specific-error'],
|
setupFilesAfterEnv: ['jest-matcher-specific-error'],
|
||||||
roots: ['./lib'],
|
roots: ['./lib'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
/** @type {import('jest').Config} */
|
/** @type {import('jest').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
|
transform: {},
|
||||||
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
coveragePathIgnorePatterns: ['/node_modules/', '/src/__mocks__/'],
|
||||||
coverageReporters: ['text-summary', 'lcov'],
|
coverageReporters: ['text-summary', 'lcov'],
|
||||||
|
coverageProvider: 'v8',
|
||||||
roots: ['./lib'],
|
roots: ['./lib'],
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
'^(chalk|inquirer)$': '<rootDir>/../../shared/lib/esm/module-proxy.js',
|
'^(chalk|inquirer)$': '<rootDir>/../../shared/lib/esm/module-proxy.js',
|
||||||
|
|
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
|
@ -270,6 +270,7 @@ importers:
|
||||||
'@types/koa-send': ^4.1.3
|
'@types/koa-send': ^4.1.3
|
||||||
'@types/node': ^16.0.0
|
'@types/node': ^16.0.0
|
||||||
'@types/oidc-provider': ^7.12.0
|
'@types/oidc-provider': ^7.12.0
|
||||||
|
'@types/semver': ^7.3.12
|
||||||
'@types/sinon': ^10.0.13
|
'@types/sinon': ^10.0.13
|
||||||
'@types/supertest': ^2.0.11
|
'@types/supertest': ^2.0.11
|
||||||
'@withtyped/postgres': ^0.3.1
|
'@withtyped/postgres': ^0.3.1
|
||||||
|
@ -310,6 +311,7 @@ importers:
|
||||||
p-retry: ^5.1.2
|
p-retry: ^5.1.2
|
||||||
prettier: ^2.8.1
|
prettier: ^2.8.1
|
||||||
roarr: ^7.11.0
|
roarr: ^7.11.0
|
||||||
|
semver: ^7.3.8
|
||||||
sinon: ^15.0.0
|
sinon: ^15.0.0
|
||||||
slonik: ^30.0.0
|
slonik: ^30.0.0
|
||||||
slonik-interceptor-preset: ^1.2.10
|
slonik-interceptor-preset: ^1.2.10
|
||||||
|
@ -357,6 +359,7 @@ importers:
|
||||||
oidc-provider: 7.13.0
|
oidc-provider: 7.13.0
|
||||||
p-retry: 5.1.2
|
p-retry: 5.1.2
|
||||||
roarr: 7.11.0
|
roarr: 7.11.0
|
||||||
|
semver: 7.3.8
|
||||||
slonik: 30.1.2
|
slonik: 30.1.2
|
||||||
slonik-interceptor-preset: 1.2.10
|
slonik-interceptor-preset: 1.2.10
|
||||||
slonik-sql-tag-raw: 1.1.4_roarr@7.11.0+slonik@30.1.2
|
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/koa-send': 4.1.3
|
||||||
'@types/node': 16.11.12
|
'@types/node': 16.11.12
|
||||||
'@types/oidc-provider': 7.12.0
|
'@types/oidc-provider': 7.12.0
|
||||||
|
'@types/semver': 7.3.12
|
||||||
'@types/sinon': 10.0.13
|
'@types/sinon': 10.0.13
|
||||||
'@types/supertest': 2.0.11
|
'@types/supertest': 2.0.11
|
||||||
copyfiles: 2.4.1
|
copyfiles: 2.4.1
|
||||||
|
@ -13954,7 +13958,7 @@ packages:
|
||||||
mime: 2.6.0
|
mime: 2.6.0
|
||||||
qs: 6.10.2
|
qs: 6.10.2
|
||||||
readable-stream: 3.6.0
|
readable-stream: 3.6.0
|
||||||
semver: 7.3.7
|
semver: 7.3.8
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
dev: true
|
dev: true
|
||||||
|
|
Loading…
Add table
Reference in a new issue