diff --git a/packages/cli/.npmrc b/packages/cli/.npmrc new file mode 100644 index 000000000..6c59086d8 --- /dev/null +++ b/packages/cli/.npmrc @@ -0,0 +1 @@ +enable-pre-post-scripts=true diff --git a/packages/cli/package.json b/packages/cli/package.json index c59a44acf..000011f7a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -19,7 +19,9 @@ }, "scripts": { "precommit": "lint-staged", + "//": "Manually ln since `preserveSymlinks` in TSC doesn't work as expected", "build": "rimraf lib && tsc -p tsconfig.build.json", + "postbuild": "unlink ./lib/package.json && ln -s ../package.json ./lib/package.json", "start": "node .", "start:dev": "ts-node --files src/index.ts", "lint": "eslint --ext .ts src", 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/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 93e9ffc90..61eb9f7ad 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 7f8b75ab6..81e7eb23e 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 ae61d4513..5da19a4ab 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 @@ -4618,7 +4620,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: @@ -4806,7 +4808,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: