mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
refactor: fix connector directory
This commit is contained in:
parent
64a0936a77
commit
36d26091e0
7 changed files with 39 additions and 22 deletions
|
@ -41,7 +41,6 @@
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"decamelize": "^5.0.0",
|
"decamelize": "^5.0.0",
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.0",
|
||||||
"find-up": "^5.0.0",
|
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"got": "^11.8.2",
|
"got": "^11.8.2",
|
||||||
"hpagent": "^1.0.0",
|
"hpagent": "^1.0.0",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { AlterationScript } from '@logto/schemas/lib/types/alteration';
|
import { AlterationScript } from '@logto/schemas/lib/types/alteration';
|
||||||
import { conditional, conditionalString } from '@silverhand/essentials';
|
import { findPackage } from '@logto/shared';
|
||||||
|
import { conditionalString } from '@silverhand/essentials';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import findUp, { exists } from 'find-up';
|
|
||||||
import { copy, existsSync, remove, readdir } from 'fs-extra';
|
import { copy, existsSync, remove, readdir } from 'fs-extra';
|
||||||
import { DatabasePool } from 'slonik';
|
import { DatabasePool } from 'slonik';
|
||||||
import { CommandModule } from 'yargs';
|
import { CommandModule } from 'yargs';
|
||||||
|
@ -45,18 +45,10 @@ export const getAlterationFiles = async (): Promise<AlterationFile[]> => {
|
||||||
* since they need a proper context that includes required dependencies (such as slonik) in `node_modules/`.
|
* since they need a proper context that includes required dependencies (such as slonik) in `node_modules/`.
|
||||||
* While the original `@logto/schemas` may remove them in production.
|
* While the original `@logto/schemas` may remove them in production.
|
||||||
*/
|
*/
|
||||||
const packageDirectory = await findUp(
|
const packageDirectory = await findPackage(
|
||||||
async (directory) => {
|
// Until we migrate to ESM
|
||||||
const hasPackageJson = await exists(path.join(directory, 'package.json'));
|
// eslint-disable-next-line unicorn/prefer-module
|
||||||
|
__dirname
|
||||||
return conditional(hasPackageJson && directory);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Until we migrate to ESM
|
|
||||||
// eslint-disable-next-line unicorn/prefer-module
|
|
||||||
cwd: __dirname,
|
|
||||||
type: 'directory',
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const localAlterationDirectory = path.resolve(
|
const localAlterationDirectory = path.resolve(
|
||||||
|
|
|
@ -4,6 +4,7 @@ import path from 'path';
|
||||||
|
|
||||||
import { connectorDirectory } from '@logto/cli/lib/constants';
|
import { connectorDirectory } from '@logto/cli/lib/constants';
|
||||||
import { AllConnector, CreateConnector, validateConfig } from '@logto/connector-kit';
|
import { AllConnector, CreateConnector, validateConfig } from '@logto/connector-kit';
|
||||||
|
import { findPackage } from '@logto/shared';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
|
||||||
import RequestError from '@/errors/RequestError';
|
import RequestError from '@/errors/RequestError';
|
||||||
|
@ -21,16 +22,21 @@ const loadConnectors = async () => {
|
||||||
return cachedConnectors;
|
return cachedConnectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!existsSync(connectorDirectory)) {
|
// Until we migrate to ESM
|
||||||
|
// eslint-disable-next-line unicorn/prefer-module
|
||||||
|
const coreDirectory = await findPackage(__dirname);
|
||||||
|
const directory = coreDirectory && path.join(coreDirectory, connectorDirectory);
|
||||||
|
|
||||||
|
if (!directory || !existsSync(directory)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectorFolders = await readdir(connectorDirectory);
|
const connectorFolders = await readdir(directory);
|
||||||
|
|
||||||
const connectors = await Promise.all(
|
const connectors = await Promise.all(
|
||||||
connectorFolders.map(async (folder) => {
|
connectorFolders.map(async (folder) => {
|
||||||
try {
|
try {
|
||||||
const packagePath = path.join(connectorDirectory, folder);
|
const packagePath = path.join(directory, folder);
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
const { default: createConnector } = (await import(packagePath)) as {
|
const { default: createConnector } = (await import(packagePath)) as {
|
||||||
default: CreateConnector<AllConnector>;
|
default: CreateConnector<AllConnector>;
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
"@logto/schemas": "^1.0.0-beta.10",
|
"@logto/schemas": "^1.0.0-beta.10",
|
||||||
"@silverhand/essentials": "^1.3.0",
|
"@silverhand/essentials": "^1.3.0",
|
||||||
"dayjs": "^1.10.5",
|
"dayjs": "^1.10.5",
|
||||||
|
"find-up": "^5.0.0",
|
||||||
"nanoid": "^3.3.4",
|
"nanoid": "^3.3.4",
|
||||||
"slonik": "^30.0.0"
|
"slonik": "^30.0.0"
|
||||||
}
|
}
|
||||||
|
|
18
packages/shared/src/utils/find-package.ts
Normal file
18
packages/shared/src/utils/find-package.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
import { conditional } from '@silverhand/essentials';
|
||||||
|
import findUp, { exists } from 'find-up';
|
||||||
|
|
||||||
|
const findPackage = async (cwd: string) =>
|
||||||
|
findUp(
|
||||||
|
async (directory) => {
|
||||||
|
const hasPackageJson = await exists(path.join(directory, 'package.json'));
|
||||||
|
|
||||||
|
return conditional(hasPackageJson && directory);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cwd,
|
||||||
|
type: 'directory',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default findPackage;
|
|
@ -1 +1,2 @@
|
||||||
export * from './id';
|
export * from './id';
|
||||||
|
export { default as findPackage } from './find-package';
|
||||||
|
|
|
@ -37,7 +37,6 @@ importers:
|
||||||
decamelize: ^5.0.0
|
decamelize: ^5.0.0
|
||||||
dotenv: ^16.0.0
|
dotenv: ^16.0.0
|
||||||
eslint: ^8.21.0
|
eslint: ^8.21.0
|
||||||
find-up: ^5.0.0
|
|
||||||
fs-extra: ^10.1.0
|
fs-extra: ^10.1.0
|
||||||
got: ^11.8.2
|
got: ^11.8.2
|
||||||
hpagent: ^1.0.0
|
hpagent: ^1.0.0
|
||||||
|
@ -66,7 +65,6 @@ importers:
|
||||||
chalk: 4.1.2
|
chalk: 4.1.2
|
||||||
decamelize: 5.0.1
|
decamelize: 5.0.1
|
||||||
dotenv: 16.0.0
|
dotenv: 16.0.0
|
||||||
find-up: 5.0.0
|
|
||||||
fs-extra: 10.1.0
|
fs-extra: 10.1.0
|
||||||
got: 11.8.3
|
got: 11.8.3
|
||||||
hpagent: 1.0.0
|
hpagent: 1.0.0
|
||||||
|
@ -621,6 +619,7 @@ importers:
|
||||||
'@types/jest': ^28.1.6
|
'@types/jest': ^28.1.6
|
||||||
dayjs: ^1.10.5
|
dayjs: ^1.10.5
|
||||||
eslint: ^8.21.0
|
eslint: ^8.21.0
|
||||||
|
find-up: ^5.0.0
|
||||||
jest: ^28.1.3
|
jest: ^28.1.3
|
||||||
lint-staged: ^13.0.0
|
lint-staged: ^13.0.0
|
||||||
nanoid: ^3.3.4
|
nanoid: ^3.3.4
|
||||||
|
@ -631,6 +630,7 @@ importers:
|
||||||
'@logto/schemas': link:../schemas
|
'@logto/schemas': link:../schemas
|
||||||
'@silverhand/essentials': 1.3.0
|
'@silverhand/essentials': 1.3.0
|
||||||
dayjs: 1.10.7
|
dayjs: 1.10.7
|
||||||
|
find-up: 5.0.0
|
||||||
nanoid: 3.3.4
|
nanoid: 3.3.4
|
||||||
slonik: 30.1.2
|
slonik: 30.1.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
@ -4035,7 +4035,7 @@ packages:
|
||||||
'@jest/types': 28.1.3
|
'@jest/types': 28.1.3
|
||||||
deepmerge: 4.2.2
|
deepmerge: 4.2.2
|
||||||
identity-obj-proxy: 3.0.0
|
identity-obj-proxy: 3.0.0
|
||||||
jest: 28.1.3_@types+node@16.11.12
|
jest: 28.1.3_k5ytkvaprncdyzidqqws5bqksq
|
||||||
jest-matcher-specific-error: 1.0.0
|
jest-matcher-specific-error: 1.0.0
|
||||||
jest-transform-stub: 2.0.0
|
jest-transform-stub: 2.0.0
|
||||||
ts-jest: 28.0.7_lhw3xkmzugq5tscs3x2ndm4sby
|
ts-jest: 28.0.7_lhw3xkmzugq5tscs3x2ndm4sby
|
||||||
|
@ -15215,7 +15215,7 @@ packages:
|
||||||
'@jest/types': 28.1.3
|
'@jest/types': 28.1.3
|
||||||
bs-logger: 0.2.6
|
bs-logger: 0.2.6
|
||||||
fast-json-stable-stringify: 2.1.0
|
fast-json-stable-stringify: 2.1.0
|
||||||
jest: 28.1.3_@types+node@16.11.12
|
jest: 28.1.3_k5ytkvaprncdyzidqqws5bqksq
|
||||||
jest-util: 28.1.3
|
jest-util: 28.1.3
|
||||||
json5: 2.2.1
|
json5: 2.2.1
|
||||||
lodash.memoize: 4.1.2
|
lodash.memoize: 4.1.2
|
||||||
|
|
Loading…
Reference in a new issue