diff --git a/.eslintrc.yml b/.eslintrc.yml index 512f8d2863..f2ae14ba54 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -159,3 +159,5 @@ rules: asyncArrow: always named: never '@typescript-eslint/type-annotation-spacing': error + + '@typescript-eslint/no-useless-constructor': off diff --git a/.mocharc.js b/.mocharc.js index 0a26fc5d2f..8aa915e319 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -1,8 +1,7 @@ -process.env.TS_NODE_PROJECT = 'tsconfig.test.json' +process.env.TS_NODE_PROJECT = 'tsconfig.json' const specs = [ 'packages/core/tests/*.spec.ts', - 'packages/segment/tests/*.spec.ts', 'packages/utils/tests/*.spec.ts', 'plugins/a11y/admin/tests/*.spec.ts', 'plugins/a11y/commands/tests/*.spec.ts', diff --git a/build/dep.ts b/build/dep.ts deleted file mode 100644 index 590cfab8cb..0000000000 --- a/build/dep.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { cwd, DependencyType, getWorkspaces, PackageJson } from './utils' -import { cyan, green, yellow } from 'kleur' -import { writeFile } from 'fs-extra' -import { gt, satisfies } from 'semver' -import latest from 'latest-version' -import prompts from 'prompts' -import pMap from 'p-map' -import ora from 'ora' - -interface Workspace { - dirty?: boolean - path: string - meta: PackageJson -} - -interface Dependency { - version?: string - dependents: { - name: string - type: DependencyType - }[] -} - -(async () => { - const workspaces: Record = {} - const dependencies: Record = {} - - function loadPackage(path: string) { - let meta: PackageJson - try { - meta = require(`../${path}/package`) - } catch { - return - } - const { name } = meta - workspaces[name] = { meta, path } - delete dependencies[name] - - for (const type of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] as const) { - for (const dep in meta[type] || {}) { - // skip workspaces and symlinks - const version = meta[type][dep] - if (workspaces[dep] || version === '*' || version.includes(':')) continue - if (!dependencies[dep]) dependencies[dep] = { dependents: [] } - dependencies[dep].dependents.push({ name, type }) - } - } - } - - loadPackage('') - - for (const name of await getWorkspaces()) { - loadPackage(name) - } - - const depNames = Object.keys(dependencies) - const spinner = ora(`progress: 0/${depNames.length}`).start() - let progress = 0 - await pMap(depNames, async (dep) => { - const version = await latest(dep) - progress++ - spinner.text = `progress: ${progress}/${depNames.length}` - return dependencies[dep].version = version.trim() - }, { concurrency: 10 }) - spinner.succeed() - - const bumpMap = new Map() - async function shouldBump(name: string, dep: string, version: string, oldVersion: string) { - if (!gt(version, oldVersion.replace(/^[~^]/, ''))) return - const message = `${name} > ${yellow(dep)}: ${cyan(oldVersion)} -> ${green(version)}` - if (satisfies(version, oldVersion)) return message - let result = bumpMap.get(dep) - if (result === undefined) { - const data = await prompts({ - name: 'value', - type: 'confirm', - message, - }) - result = data.value - bumpMap.set(dep, result) - } - return result && message - } - - const output: string[] = [] - for (const dep in dependencies) { - const { version, dependents } = dependencies[dep] - for (const { name, type } of dependents) { - const workspace = workspaces[name] - const oldVersion = workspace.meta[type][dep] - const message = await shouldBump(name, dep, version, oldVersion) - if (message) { - workspace.dirty = true - workspace.meta[type][dep] = '^' + version - output.push(message) - } - } - } - - await pMap(Object.keys(workspaces), (name) => { - const workspace = workspaces[name] - if (!workspace.dirty) return - return writeFile(`${cwd}/${workspace.path}/package.json`, JSON.stringify(workspace.meta, null, 2)) - }) - - console.log(output.sort().join('\n')) -})() diff --git a/build/tsconfig.json b/build/tsconfig.json new file mode 100644 index 0000000000..fd9a7ec467 --- /dev/null +++ b/build/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../tsconfig.base" +} \ No newline at end of file diff --git a/package.json b/package.json index 4e1f8a700f..314a563ece 100644 --- a/package.json +++ b/package.json @@ -21,22 +21,22 @@ ], "scripts": { "build": "yarn compile && yarn dtsc && yarn fe", - "clean": "node -r ./build/register build/clean", - "compile": "node -r ./build/register build/compile", + "clean": "node -r esbuild-register build/clean", + "compile": "node -r esbuild-register build/compile", + "draft": "node -r esbuild-register build/release", + "fe": "node -r esbuild-register build/frontend", "dtsc": "yakumo tsc", "bump": "yakumo version", "dep": "yakumo upgrade", "pub": "yakumo publish", "docs": "yarn workspace @koishijs/docs", - "draft": "node -r ./build/register build/release", - "fe": "node -r ./build/register build/frontend", "test": "mocha --no-warnings --experimental-vm-modules --enable-source-maps", "test:json": "c8 -r json yarn test", "test:html": "rimraf coverage && c8 -r html yarn test", "test:text": "c8 -r text yarn test", "lint": "eslint packages plugins --ext=ts --cache", "scaffold": "yarn compile koishi && yarn create-koishi test", - "start": "yarn compile && cross-env TS_NODE_PROJECT=../tsconfig.test.json yarn workspace test koishi start --watch .. -r ../build/register --experimental-vm-modules", + "start": "yarn compile && cross-env TS_NODE_PROJECT=../tsconfig.json yarn workspace @koishijs/test koishi start --watch .. -r ../build/register --experimental-vm-modules", "shiki": "yarn workspace bot-shiki" }, "license": "MIT", @@ -63,6 +63,7 @@ "cross-spawn": "^7.0.3", "del": "^6.1.1", "esbuild": "^0.14.48", + "esbuild-register": "^3.3.3", "eslint": "^7.32.0", "eslint-config-standard": "^16.0.3", "eslint-import-resolver-typescript": "^2.7.1", @@ -89,7 +90,8 @@ "yakumo-mocha": "^0.2.5", "yakumo-publish": "^0.2.4", "yakumo-upgrade": "^0.2.3", - "yakumo-version": "^0.2.5" + "yakumo-version": "^0.2.5", + "yml-register": "^1.0.0" }, "yakumo": { "require": [ diff --git a/tsconfig.json b/tsconfig.json index b970589292..bc38a8b7a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,51 @@ { + "extends": "./tsconfig.base", "compilerOptions": { - "target": "esnext", - "module": "commonjs", - "noEmit": true, - "esModuleInterop": true, - "moduleResolution": "node", - "strictBindCallApply": true, + "baseUrl": ".", + "paths": { + "@koishijs/database-tests": [ + "plugins/database/tests/src", + ], + "@koishijs/plugin-adapter-*": [ + "plugins/adapter/*/src", + "external/adapter-*/src", + ], + "@koishijs/plugin-assets-*": [ + "plugins/assets/*/src", + "external/assets-*/src", + ], + "@koishijs/plugin-database-*": [ + "plugins/database/*/src", + "external/database-*/src", + ], + "@koishijs/plugin-*": [ + "plugins/a11y/*/src", + "plugins/common/*/src", + "plugins/frontend/*/src", + "plugins/*/src", + ], + "@koishijs/*": [ + "packages/*/src", + "plugins/a11y/*/src", + "plugins/adapter/*/src", + "plugins/assets/*/src", + "plugins/common/*/src", + "plugins/database/*/src", + "plugins/frontend/*/src", + ], + "koishi-plugin-*": [ + "external/*/src", + ], + "koishi": [ + "packages/koishi/src", + ], + "cordis": [ + "../packages/cordis/src", + ], + "*": [ + "external/*/src", + ], + }, }, - "include": [ - "build", - ], -} \ No newline at end of file + "files": [], +} diff --git a/tsconfig.test.json b/tsconfig.test.json deleted file mode 100644 index 181f824c11..0000000000 --- a/tsconfig.test.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "extends": "./tsconfig.base.json", - "compilerOptions": { - "baseUrl": ".", - "paths": { - "@koishijs/database-tests": [ - "plugins/database/tests/src", - ], - "@koishijs/plugin-adapter-*": [ - "plugins/adapter/*/src", - "community/adapter-*/src", - ], - "@koishijs/plugin-assets-*": [ - "plugins/assets/*/src", - "community/assets-*/src", - ], - "@koishijs/plugin-cache-*": [ - "plugins/cache/*/src", - "community/cache-*/src", - ], - "@koishijs/plugin-database-*": [ - "plugins/database/*/src", - "community/database-*/src", - ], - "@koishijs/plugin-*": [ - "plugins/a11y/*/src", - "plugins/common/*/src", - "plugins/frontend/*/src", - "plugins/*/src", - ], - "@koishijs/*": [ - "packages/*/src", - "plugins/a11y/*/src", - "plugins/adapter/*/src", - "plugins/assets/*/src", - "plugins/cache/*/src", - "plugins/common/*/src", - "plugins/database/*/src", - "plugins/frontend/*/src", - ], - "koishi-plugin-*": [ - "community/*/src", - ], - "koishi": [ - "packages/koishi/src", - ], - "cordis": [ - "../packages/cordis/src", - ], - "*": [ - "community/*/src", - ], - }, - }, -} \ No newline at end of file