diff --git a/packages/cli/jest.config.js b/packages/cli/jest.config.js index 3fd28f230..5656d3347 100644 --- a/packages/cli/jest.config.js +++ b/packages/cli/jest.config.js @@ -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)$': '/../shared/lib/esm/module-proxy.js', diff --git a/packages/core/jest.config.js b/packages/core/jest.config.js index fff6b08fe..305244652 100644 --- a/packages/core/jest.config.js +++ b/packages/core/jest.config.js @@ -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'], diff --git a/packages/core/package.json b/packages/core/package.json index 0c5eca54a..7d81303d1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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", diff --git a/packages/core/src/connectors/index.ts b/packages/core/src/connectors/index.ts index 8729f0126..11fd2b365 100644 --- a/packages/core/src/connectors/index.ts +++ b/packages/core/src/connectors/index.ts @@ -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 }, diff --git a/packages/core/src/connectors/utilities/compatibility.ts b/packages/core/src/connectors/utilities/compatibility.ts new file mode 100644 index 000000000..a849b9784 --- /dev/null +++ b/packages/core/src/connectors/utilities/compatibility.ts @@ -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 }; + + 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`); +}; diff --git a/packages/integration-tests/jest.config.js b/packages/integration-tests/jest.config.js index d6e8961c6..ed51ac280 100644 --- a/packages/integration-tests/jest.config.js +++ b/packages/integration-tests/jest.config.js @@ -1,6 +1,8 @@ /** @type {import('jest').Config} */ const config = { + transform: {}, testPathIgnorePatterns: ['/node_modules/'], + coverageProvider: 'v8', setupFilesAfterEnv: ['./jest.setup.js'], roots: ['./lib'], moduleNameMapper: { diff --git a/packages/integration-tests/jest.config.ui.js b/packages/integration-tests/jest.config.ui.js index 2e58afa04..e1e0c5fea 100644 --- a/packages/integration-tests/jest.config.ui.js +++ b/packages/integration-tests/jest.config.ui.js @@ -1,5 +1,6 @@ /** @type {import('jest').Config} */ const config = { + transform: {}, preset: 'jest-puppeteer', setupFilesAfterEnv: ['./jest.setup.js'], moduleNameMapper: { diff --git a/packages/schemas/jest.config.js b/packages/schemas/jest.config.js index 3fd28f230..5656d3347 100644 --- a/packages/schemas/jest.config.js +++ b/packages/schemas/jest.config.js @@ -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)$': '/../shared/lib/esm/module-proxy.js', diff --git a/packages/shared/jest.config.js b/packages/shared/jest.config.js index 3fd28f230..5656d3347 100644 --- a/packages/shared/jest.config.js +++ b/packages/shared/jest.config.js @@ -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)$': '/../shared/lib/esm/module-proxy.js', diff --git a/packages/toolkit/connector-kit/package.json b/packages/toolkit/connector-kit/package.json index 4440b2f72..a58f09271 100644 --- a/packages/toolkit/connector-kit/package.json +++ b/packages/toolkit/connector-kit/package.json @@ -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": [ diff --git a/packages/toolkit/core-kit/jest.config.js b/packages/toolkit/core-kit/jest.config.js index 567c4ad15..23e603a4a 100644 --- a/packages/toolkit/core-kit/jest.config.js +++ b/packages/toolkit/core-kit/jest.config.js @@ -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: { diff --git a/packages/toolkit/language-kit/jest.config.js b/packages/toolkit/language-kit/jest.config.js index 2a6f21ab3..47665f39a 100644 --- a/packages/toolkit/language-kit/jest.config.js +++ b/packages/toolkit/language-kit/jest.config.js @@ -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)$': '/../../shared/lib/esm/module-proxy.js', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 51704dbbc..fc6019eec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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