diff --git a/packages/cli/.gitignore b/packages/cli/.gitignore index 3e3a1fa6e..5b78a4af2 100644 --- a/packages/cli/.gitignore +++ b/packages/cli/.gitignore @@ -1 +1,2 @@ alteration-scripts/ +src/package-json.ts diff --git a/packages/cli/package.json b/packages/cli/package.json index c59a44acf..9bb6e9054 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -19,7 +19,8 @@ }, "scripts": { "precommit": "lint-staged", - "build": "rimraf lib && tsc -p tsconfig.build.json", + "prepare:package-json": "node -p \"'export const packageJson = ' + JSON.stringify(require('./package.json'), undefined, 2) + ';'\" > src/package-json.ts", + "build": "rimraf lib && pnpm prepare:package-json && tsc -p tsconfig.build.json", "start": "node .", "start:dev": "ts-node --files src/index.ts", "lint": "eslint --ext .ts src", @@ -83,7 +84,8 @@ "error", 7 ] - } + }, + "ignorePatterns": ["src/package-json.ts"] }, "prettier": "@silverhand/eslint-config/.prettierrc" } diff --git a/packages/cli/src/commands/database/alteration/index.ts b/packages/cli/src/commands/database/alteration/index.ts index 9052532b9..6c45de635 100644 --- a/packages/cli/src/commands/database/alteration/index.ts +++ b/packages/cli/src/commands/database/alteration/index.ts @@ -5,7 +5,6 @@ import { findPackage } from '@logto/shared'; import { conditionalString } from '@silverhand/essentials'; import chalk from 'chalk'; import { copy, existsSync, remove, readdir } from 'fs-extra'; -import { SemVer } from 'semver'; import { DatabasePool } from 'slonik'; import { CommandModule } from 'yargs'; @@ -30,12 +29,6 @@ const getTimestampFromFilename = (filename: string) => { return Number(match[1]); }; -const getVersionFromFilename = (filename: string) => { - try { - return new SemVer(filename.split('-')[0]?.replaceAll('_', '-') ?? 'unknown'); - } catch {} -}; - const importAlterationScript = async (filePath: string): Promise => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const module = await import(filePath); diff --git a/packages/cli/src/commands/database/alteration/version.ts b/packages/cli/src/commands/database/alteration/version.ts index 096ff56b1..21605a8ee 100644 --- a/packages/cli/src/commands/database/alteration/version.ts +++ b/packages/cli/src/commands/database/alteration/version.ts @@ -42,6 +42,11 @@ export const chooseAlterationsByVersion = async ( .filter((version, index, self) => index === self.findIndex((another) => eq(version, another))) .slice() .sort((i, j) => compare(j, i)); + const initialSemVersion = conditional(initialVersion && new SemVer(initialVersion)); + + if (!versions[0]) { + return []; + } const { version: targetVersion } = initialVersion === latestTag @@ -57,14 +62,10 @@ export const chooseAlterationsByVersion = async ( })), }, { - version: conditional(initialVersion && new SemVer(initialVersion)), + version: initialSemVersion, } ); - if (!targetVersion) { - return []; - } - log.info(`Deploy target ${chalk.green(targetVersion.version)}`); return alterations.filter(({ filename }) => { diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index f2b831831..e0596c9e4 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -6,7 +6,7 @@ import { hideBin } from 'yargs/helpers'; import connector from './commands/connector'; import database from './commands/database'; import install from './commands/install'; -import packageJson from './package.json'; +import { packageJson } from './package-json'; import { cliConfig, ConfigKey } from './utilities'; void yargs(hideBin(process.argv)) diff --git a/packages/cli/src/package.json b/packages/cli/src/package.json deleted file mode 120000 index 4e26811d4..000000000 --- a/packages/cli/src/package.json +++ /dev/null @@ -1 +0,0 @@ -../package.json \ No newline at end of file diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 3d69fefb3..ef675dbdc 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -4,7 +4,8 @@ "outDir": "lib", "declaration": true, "module": "node16", - "target": "es2022" + "target": "es2022", + "types": ["node", "jest"] }, "include": [ "src", diff --git a/packages/core/package.json b/packages/core/package.json index 0ad97e995..f963760c7 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -87,7 +87,7 @@ "@types/koa-mount": "^4.0.0", "@types/koa-send": "^4.1.3", "@types/lodash.pick": "^4.4.6", - "@types/node": "^16.3.1", + "@types/node": "^16.0.0", "@types/oidc-provider": "^7.11.1", "@types/supertest": "^2.0.11", "copyfiles": "^2.4.1", diff --git a/packages/schemas/package.json b/packages/schemas/package.json index 6583c3509..b4c7b6f82 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -32,7 +32,7 @@ "@silverhand/ts-config": "1.0.0", "@types/jest": "^28.0.0", "@types/lodash.uniq": "^4.5.6", - "@types/node": "16", + "@types/node": "^16.0.0", "@types/pluralize": "^0.0.29", "camelcase": "^6.2.0", "eslint": "^8.21.0", diff --git a/packages/shared/package.json b/packages/shared/package.json index 748f368f4..90fb46d1d 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -23,6 +23,7 @@ "@silverhand/jest-config": "1.0.0", "@silverhand/ts-config": "1.0.0", "@types/jest": "^28.1.6", + "@types/node": "^16.0.0", "eslint": "^8.21.0", "jest": "^28.1.3", "lint-staged": "^13.0.0", diff --git a/packages/shared/src/utils/find-package.ts b/packages/shared/src/utils/find-package.ts index 1b5f92ce1..266e03621 100644 --- a/packages/shared/src/utils/find-package.ts +++ b/packages/shared/src/utils/find-package.ts @@ -1,14 +1,19 @@ +import { lstat } from 'fs/promises'; import path from 'path'; import { conditional } from '@silverhand/essentials'; import findUp, { exists } from 'find-up'; -const findPackage = async (cwd: string) => +const findPackage = async (cwd: string, allowSymlink = false) => findUp( + // Will update to 7 soon + // eslint-disable-next-line complexity async (directory) => { - const hasPackageJson = await exists(path.join(directory, 'package.json')); + const testPath = path.join(directory, 'package.json'); + const hasPackageJson = await exists(testPath); + const stat = conditional(hasPackageJson && !allowSymlink && (await lstat(testPath))); - return conditional(hasPackageJson && directory); + return conditional(hasPackageJson && (allowSymlink || !stat?.isSymbolicLink()) && directory); }, { cwd, diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index 19523840b..00b88e2de 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -2,7 +2,8 @@ "extends": "@silverhand/ts-config/tsconfig.base", "compilerOptions": { "outDir": "lib", - "declaration": true + "declaration": true, + "types": ["node", "jest"] }, "include": [ "src", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 86b29f420..0e6462080 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -262,7 +262,7 @@ importers: '@types/koa-mount': ^4.0.0 '@types/koa-send': ^4.1.3 '@types/lodash.pick': ^4.4.6 - '@types/node': ^16.3.1 + '@types/node': ^16.0.0 '@types/oidc-provider': ^7.11.1 '@types/supertest': ^2.0.11 chalk: ^4 @@ -571,7 +571,7 @@ importers: '@silverhand/ts-config': 1.0.0 '@types/jest': ^28.0.0 '@types/lodash.uniq': ^4.5.6 - '@types/node': '16' + '@types/node': ^16.0.0 '@types/pluralize': ^0.0.29 camelcase: ^6.2.0 eslint: ^8.21.0 @@ -619,6 +619,7 @@ importers: '@silverhand/jest-config': 1.0.0 '@silverhand/ts-config': 1.0.0 '@types/jest': ^28.1.6 + '@types/node': ^16.0.0 dayjs: ^1.10.5 eslint: ^8.21.0 find-up: ^5.0.0 @@ -640,8 +641,9 @@ importers: '@silverhand/jest-config': 1.0.0_bi2kohzqnxavgozw3csgny5hju '@silverhand/ts-config': 1.0.0_typescript@4.7.4 '@types/jest': 28.1.6 + '@types/node': 16.11.12 eslint: 8.21.0 - jest: 28.1.3 + jest: 28.1.3_@types+node@16.11.12 lint-staged: 13.0.0 prettier: 2.7.1 typescript: 4.7.4 @@ -4609,7 +4611,7 @@ packages: '@types/http-errors': 1.8.2 '@types/keygrip': 1.0.2 '@types/koa-compose': 3.2.5 - '@types/node': 16.11.12 + '@types/node': 17.0.23 dev: true /@types/lodash.kebabcase/4.1.6: @@ -4797,7 +4799,7 @@ packages: resolution: {integrity: sha512-mu/N4uvfDN2zVQQ5AYJI/g4qxn2bHB6521t1UuH09ShNWjebTqN0ZFuYK9uYjcgmI0dTQEs+Owi1EO6U0OkOZQ==} dependencies: '@types/cookiejar': 2.1.2 - '@types/node': 16.11.12 + '@types/node': 17.0.23 dev: true /@types/supertest/2.0.11: