diff --git a/.oxlintrc.json b/.oxlintrc.json new file mode 100644 index 00000000..e64d0020 --- /dev/null +++ b/.oxlintrc.json @@ -0,0 +1,6 @@ +{ + "plugins": ["import"], + "rules": { + "import/no-cycle": "error" + } +} diff --git a/app.ts b/app.ts index fbd3d65c..8e7fe910 100644 --- a/app.ts +++ b/app.ts @@ -1,7 +1,7 @@ import path from 'node:path'; import { readFile } from 'node:fs/promises'; -import { Application } from 'egg'; -import { ChangesStreamService } from './app/core/service/ChangesStreamService'; +import { Application, ILifecycleBoot } from 'egg'; +import { ChangesStreamService } from './app/core/service/ChangesStreamService.js'; declare module 'egg' { interface Application { @@ -9,7 +9,7 @@ declare module 'egg' { } } -export default class CnpmcoreAppHook { +export default class CnpmcoreAppHook implements ILifecycleBoot { private readonly app: Application; constructor(app: Application) { @@ -17,7 +17,7 @@ export default class CnpmcoreAppHook { this.app.binaryHTML = ''; } - async configWillLoad() { + configWillLoad() { const app = this.app; // https://github.com/eggjs/tegg/blob/master/plugin/orm/app.ts#L37 // store query sql to log diff --git a/app/common/FileUtil.ts b/app/common/FileUtil.ts index 6d350612..181cf535 100644 --- a/app/common/FileUtil.ts +++ b/app/common/FileUtil.ts @@ -6,7 +6,7 @@ import url from 'node:url'; import { randomBytes } from 'node:crypto'; import { EggContextHttpClient, HttpClientResponse } from 'egg'; import mime from 'mime-types'; -import dayjs from './dayjs'; +import dayjs from './dayjs.js'; interface DownloadToTempfileOptionalConfig { retries?: number, diff --git a/app/common/PackageUtil.ts b/app/common/PackageUtil.ts index ae38a538..1c17fd1a 100644 --- a/app/common/PackageUtil.ts +++ b/app/common/PackageUtil.ts @@ -2,8 +2,9 @@ import { createReadStream } from 'node:fs'; import { Readable } from 'node:stream'; import { pipeline } from 'node:stream/promises'; import * as ssri from 'ssri'; +// @ts-expect-error type error import tar from '@fengmk2/tar'; -import { AuthorType, PackageJSONType } from '../repository/PackageRepository'; +import type { AuthorType, PackageJSONType } from '../repository/PackageRepository.js'; // /@cnpm%2ffoo @@ -12,7 +13,7 @@ import { AuthorType, PackageJSONType } from '../repository/PackageRepository'; // /foo // name max length is 214 chars // https://www.npmjs.com/package/path-to-regexp#custom-matching-parameters -export const FULLNAME_REG_STRING = '@[^/]{1,220}\/[^/]{1,220}|@[^%]+\%2[fF][^/]{1,220}|[^@/]{1,220}'; +export const FULLNAME_REG_STRING = '@[^/]{1,220}/[^/]{1,220}|@[^%]+%2[fF][^/]{1,220}|[^@/]{1,220}'; export function getScopeAndName(fullname: string): string[] { if (fullname.startsWith('@')) { @@ -86,7 +87,7 @@ export async function hasShrinkWrapInTgz(contentOrFile: Uint8Array | string): Pr const parser = tar.t({ // options.strict 默认为 false,会忽略 Recoverable errors,例如 tar 解析失败 // 详见 https://github.com/isaacs/node-tar#warnings-and-errors - onentry(entry) { + onentry(entry: any) { if (entry.path === 'package/npm-shrinkwrap.json') { hasShrinkWrap = true; abortController.abort(); @@ -122,8 +123,8 @@ export async function extractPackageJSON(tarballBytes: Buffer): Promise { Readable.from(tarballBytes) .pipe(tar.t({ - filter: name => name === 'package/package.json', - onentry: async entry => { + filter: (name: string) => name === 'package/package.json', + onentry: async (entry: any) => { const chunks: Buffer[] = []; for await (const chunk of entry) { chunks.push(chunk); @@ -131,7 +132,7 @@ export async function extractPackageJSON(tarballBytes: Buffer): Promise124.0.2478.97/edgedriver_arm64.ziphttps://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver/124.0.2478.97/edgedriver_arm64.zipFri, 10 May 2024 18:35:44 GMT0x8DC712000713C139191362application/octet-stream1tjPTf5JU6KKB06Qf1JOGw==BlockBlobunlocked - const fileRe = /([^<]+?)<\/Name>([^<]+?)<\/Url>([^<]+?)<\/Last\-Modified>(?:[^<]+?)<\/Etag>(\d+)<\/Content\-Length>/g; + const fileRe = /([^<]+?)<\/Name>([^<]+?)<\/Url>([^<]+?)<\/Last-Modified>(?:[^<]+?)<\/Etag>(\d+)<\/Content-Length>/g; const matchItems = xml.matchAll(fileRe); for (const m of matchItems) { const fullname = m[1].trim(); diff --git a/app/common/adapter/binary/ElectronBinary.ts b/app/common/adapter/binary/ElectronBinary.ts index 3258b76f..bb91cd66 100644 --- a/app/common/adapter/binary/ElectronBinary.ts +++ b/app/common/adapter/binary/ElectronBinary.ts @@ -1,8 +1,8 @@ import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import binaries, { BinaryName } from '../../../../config/binaries'; -import { BinaryAdapter, BinaryItem, FetchResult } from './AbstractBinary'; -import { GithubBinary } from './GithubBinary'; +import binaries, { BinaryName } from '../../../../config/binaries.js'; +import { BinaryType } from '../../enum/Binary.js'; +import { BinaryAdapter, BinaryItem, FetchResult } from './AbstractBinary.js'; +import { GithubBinary } from './GithubBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.Electron) diff --git a/app/common/adapter/binary/GithubBinary.ts b/app/common/adapter/binary/GithubBinary.ts index b2d311ff..51ec989a 100644 --- a/app/common/adapter/binary/GithubBinary.ts +++ b/app/common/adapter/binary/GithubBinary.ts @@ -1,7 +1,7 @@ import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import binaries, { BinaryName, BinaryTaskConfig } from '../../../../config/binaries'; -import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; +import binaries, { BinaryName, BinaryTaskConfig } from '../../../../config/binaries.js'; +import { BinaryType } from '../../enum/Binary.js'; +import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.GitHub) diff --git a/app/common/adapter/binary/ImageminBinary.ts b/app/common/adapter/binary/ImageminBinary.ts index f089b696..efd2abb0 100644 --- a/app/common/adapter/binary/ImageminBinary.ts +++ b/app/common/adapter/binary/ImageminBinary.ts @@ -1,7 +1,7 @@ import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import binaries, { BinaryName } from '../../../../config/binaries'; -import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; +import binaries, { BinaryName } from '../../../../config/binaries.js'; +import { BinaryType } from '../../enum/Binary.js'; +import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.Imagemin) diff --git a/app/common/adapter/binary/NodeBinary.ts b/app/common/adapter/binary/NodeBinary.ts index 73134bd0..9bd23cf1 100644 --- a/app/common/adapter/binary/NodeBinary.ts +++ b/app/common/adapter/binary/NodeBinary.ts @@ -1,8 +1,8 @@ import { basename } from 'node:path'; import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import binaries, { BinaryName } from '../../../../config/binaries'; -import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; +import { BinaryType } from '../../enum/Binary.js'; +import binaries, { BinaryName } from '../../../../config/binaries.js'; +import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.Node) @@ -30,7 +30,7 @@ export class NodeBinary extends AbstractBinary { // SHASUMS256.txt.asc 04-Nov-2024 17:29 3.7 KB // SHASUMS256.txt.sig 04-Nov-2024 17:29 310 B // SHASUMS256.txt 04-Nov-2024 17:29 3.2 KB - const re = /]*?>[^<]+?<\/a>\s+?((?:[\w\-]+? \w{2}\:\d{2})|\-)\s+?([\d\.\-\s\w]+)/ig; + const re = /]*?>[^<]+?<\/a>\s+?((?:[\w-]+? \w{2}:\d{2})|-)\s+?([\d.\-\s\w]+)/ig; const matchs = html.matchAll(re); const items: BinaryItem[] = []; for (const m of matchs) { diff --git a/app/common/adapter/binary/NodePreGypBinary.ts b/app/common/adapter/binary/NodePreGypBinary.ts index b568bdc7..9d6696c3 100644 --- a/app/common/adapter/binary/NodePreGypBinary.ts +++ b/app/common/adapter/binary/NodePreGypBinary.ts @@ -1,8 +1,8 @@ -import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import binaries, { BinaryName } from '../../../../config/binaries'; import { join } from 'node:path'; -import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; +import { SingletonProto } from '@eggjs/tegg'; +import binaries, { BinaryName } from '../../../../config/binaries.js'; +import { BinaryType } from '../../enum/Binary.js'; +import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.NodePreGyp) diff --git a/app/common/adapter/binary/NwjsBinary.ts b/app/common/adapter/binary/NwjsBinary.ts index 6fb675e9..a73a5492 100644 --- a/app/common/adapter/binary/NwjsBinary.ts +++ b/app/common/adapter/binary/NwjsBinary.ts @@ -1,8 +1,8 @@ import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import binaries from '../../../../config/binaries'; -import { FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; -import { BucketBinary } from './BucketBinary'; +import binaries from '../../../../config/binaries.js'; +import { BinaryType } from '../../enum/Binary.js'; +import { FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary.js'; +import { BucketBinary } from './BucketBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.Nwjs) diff --git a/app/common/adapter/binary/PlaywrightBinary.ts b/app/common/adapter/binary/PlaywrightBinary.ts index ee95efe9..b0f88086 100644 --- a/app/common/adapter/binary/PlaywrightBinary.ts +++ b/app/common/adapter/binary/PlaywrightBinary.ts @@ -1,9 +1,8 @@ - -import { AbstractBinary, BinaryAdapter, BinaryItem, FetchResult } from './AbstractBinary'; import util from 'node:util'; import path from 'node:path'; import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; +import { BinaryType } from '../../enum/Binary.js'; +import { AbstractBinary, BinaryAdapter, BinaryItem, FetchResult } from './AbstractBinary.js'; const PACKAGE_URL = 'https://registry.npmjs.com/playwright-core'; const DOWNLOAD_HOST = 'https://playwright.azureedge.net/'; diff --git a/app/common/adapter/binary/PrismaBinary.ts b/app/common/adapter/binary/PrismaBinary.ts index fe85b4fd..42b63fbb 100644 --- a/app/common/adapter/binary/PrismaBinary.ts +++ b/app/common/adapter/binary/PrismaBinary.ts @@ -1,8 +1,8 @@ import path from 'node:path'; import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import binaries, { BinaryName } from '../../../../config/binaries'; -import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; +import { BinaryType } from '../../enum/Binary.js'; +import binaries, { BinaryName } from '../../../../config/binaries.js'; +import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.Prisma) diff --git a/app/common/adapter/binary/PuppeteerBinary.ts b/app/common/adapter/binary/PuppeteerBinary.ts index 92b49fc0..4f3bc4f4 100644 --- a/app/common/adapter/binary/PuppeteerBinary.ts +++ b/app/common/adapter/binary/PuppeteerBinary.ts @@ -1,6 +1,6 @@ import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; +import { BinaryType } from '../../enum/Binary.js'; +import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.Puppeteer) @@ -37,7 +37,7 @@ export class PuppeteerBinary extends AbstractBinary { // }; const unpkgURL = 'https://unpkg.com/puppeteer-core@latest/lib/cjs/puppeteer/revisions.js'; const text = await this.requestXml(unpkgURL); - const m = /chromium:\s+\'(\d+)\'\,/.exec(text); + const m = /chromium:\s+'(\d+)',/.exec(text); if (m && !chromiumRevisions.has(m[1])) { chromiumRevisions.set(m[1], new Date().toISOString()); } diff --git a/app/common/adapter/binary/SqlcipherBinary.ts b/app/common/adapter/binary/SqlcipherBinary.ts index f6f752a2..a80e4ed8 100644 --- a/app/common/adapter/binary/SqlcipherBinary.ts +++ b/app/common/adapter/binary/SqlcipherBinary.ts @@ -1,6 +1,6 @@ import { SingletonProto } from '@eggjs/tegg'; -import { BinaryType } from '../../enum/Binary'; -import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary'; +import { BinaryType } from '../../enum/Binary.js'; +import { AbstractBinary, FetchResult, BinaryItem, BinaryAdapter } from './AbstractBinary.js'; @SingletonProto() @BinaryAdapter(BinaryType.Sqlcipher) diff --git a/app/common/adapter/changesStream/AbstractChangesStream.ts b/app/common/adapter/changesStream/AbstractChangesStream.ts index 5c274592..5aa2b8fa 100644 --- a/app/common/adapter/changesStream/AbstractChangesStream.ts +++ b/app/common/adapter/changesStream/AbstractChangesStream.ts @@ -3,8 +3,8 @@ import { Inject, QualifierImplDecoratorUtil, } from '@eggjs/tegg'; -import { RegistryType } from '../../../common/enum/Registry'; -import { Registry } from '../../../core/entity/Registry'; +import { RegistryType } from '../../../common/enum/Registry.js'; +import { Registry } from '../../../core/entity/Registry.js'; import { EggHttpClient, EggLogger, diff --git a/app/common/adapter/changesStream/CnpmcoreChangesStream.ts b/app/common/adapter/changesStream/CnpmcoreChangesStream.ts index f4a913f7..91ed1944 100644 --- a/app/common/adapter/changesStream/CnpmcoreChangesStream.ts +++ b/app/common/adapter/changesStream/CnpmcoreChangesStream.ts @@ -1,8 +1,8 @@ import { SingletonProto } from '@eggjs/tegg'; -import { RegistryType } from '../../../common/enum/Registry'; -import { Registry } from '../../../core/entity/Registry'; import { E500 } from 'egg-errors'; -import { AbstractChangeStream, RegistryChangesStream } from './AbstractChangesStream'; +import { RegistryType } from '../../../common/enum/Registry.js'; +import { Registry } from '../../../core/entity/Registry.js'; +import { AbstractChangeStream, RegistryChangesStream } from './AbstractChangesStream.js'; @SingletonProto() @RegistryChangesStream(RegistryType.Cnpmcore) diff --git a/app/common/adapter/changesStream/CnpmjsorgChangesStream.ts b/app/common/adapter/changesStream/CnpmjsorgChangesStream.ts index 82460de3..d032deae 100644 --- a/app/common/adapter/changesStream/CnpmjsorgChangesStream.ts +++ b/app/common/adapter/changesStream/CnpmjsorgChangesStream.ts @@ -1,8 +1,8 @@ import { SingletonProto } from '@eggjs/tegg'; -import { RegistryType } from '../../../common/enum/Registry'; -import { Registry } from '../../../core/entity/Registry'; import { E500 } from 'egg-errors'; -import { AbstractChangeStream, RegistryChangesStream } from './AbstractChangesStream'; +import { RegistryType } from '../../../common/enum/Registry.js'; +import { Registry } from '../../../core/entity/Registry.js'; +import { AbstractChangeStream, RegistryChangesStream } from './AbstractChangesStream.js'; const MAX_LIMIT = 10000; diff --git a/app/common/adapter/changesStream/NpmChangesStream.ts b/app/common/adapter/changesStream/NpmChangesStream.ts index b5c66df2..36efdc86 100644 --- a/app/common/adapter/changesStream/NpmChangesStream.ts +++ b/app/common/adapter/changesStream/NpmChangesStream.ts @@ -1,8 +1,8 @@ import { SingletonProto } from '@eggjs/tegg'; import { E500 } from 'egg-errors'; -import { RegistryType } from '../../../common/enum/Registry'; -import { Registry } from '../../../core/entity/Registry'; -import { AbstractChangeStream, ChangesStreamChange, RegistryChangesStream } from './AbstractChangesStream'; +import { RegistryType } from '../../../common/enum/Registry.js'; +import { Registry } from '../../../core/entity/Registry.js'; +import { AbstractChangeStream, ChangesStreamChange, RegistryChangesStream } from './AbstractChangesStream.js'; @SingletonProto() @RegistryChangesStream(RegistryType.Npm) diff --git a/app/common/dayjs.ts b/app/common/dayjs.ts index 393e4ca0..fdc5299f 100644 --- a/app/common/dayjs.ts +++ b/app/common/dayjs.ts @@ -1,5 +1,5 @@ import dayjs from 'dayjs'; -import customParseFormat from 'dayjs/plugin/customParseFormat'; +import customParseFormat from 'dayjs/plugin/customParseFormat.js'; dayjs.extend(customParseFormat); export default dayjs; diff --git a/app/common/package.json b/app/common/package.json index 32561aa1..8091fb2f 100644 --- a/app/common/package.json +++ b/app/common/package.json @@ -2,5 +2,6 @@ "name": "cnpmcore-common", "eggModule": { "name": "cnpmcoreCommon" - } + }, + "type": "module" } diff --git a/app/common/typing.ts b/app/common/typing.ts index 9d99c6c4..76627c61 100644 --- a/app/common/typing.ts +++ b/app/common/typing.ts @@ -2,7 +2,7 @@ import { Readable } from 'node:stream'; import { IncomingHttpHeaders } from 'node:http'; import { EggContext } from '@eggjs/tegg'; import { estypes } from '@elastic/elasticsearch'; -import { CnpmcoreConfig } from '../port/config'; +import { CnpmcoreConfig } from '../port/config.js'; export interface UploadResult { key: string; diff --git a/app/core/entity/Binary.ts b/app/core/entity/Binary.ts index 15b00428..f59b1933 100644 --- a/app/core/entity/Binary.ts +++ b/app/core/entity/Binary.ts @@ -1,5 +1,5 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface BinaryData extends EntityData { binaryId: string; diff --git a/app/core/entity/Change.ts b/app/core/entity/Change.ts index ced07d24..fb97bc62 100644 --- a/app/core/entity/Change.ts +++ b/app/core/entity/Change.ts @@ -1,5 +1,5 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface ChangeData extends EntityData { changeId: string; diff --git a/app/core/entity/Dist.ts b/app/core/entity/Dist.ts index ce5c03d8..1cd18acb 100644 --- a/app/core/entity/Dist.ts +++ b/app/core/entity/Dist.ts @@ -1,5 +1,5 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface DistData extends EntityData { distId: string; diff --git a/app/core/entity/Hook.ts b/app/core/entity/Hook.ts index 4624aa4e..1f0e2f95 100644 --- a/app/core/entity/Hook.ts +++ b/app/core/entity/Hook.ts @@ -1,7 +1,7 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; -import { HookType } from '../../common/enum/Hook'; import crypto from 'node:crypto'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; +import { HookType } from '../../common/enum/Hook.js'; export type CreateHookData = Omit, 'enable' | 'latestTaskId'>; diff --git a/app/core/entity/HookEvent.ts b/app/core/entity/HookEvent.ts index 614bce4b..537a61f4 100644 --- a/app/core/entity/HookEvent.ts +++ b/app/core/entity/HookEvent.ts @@ -1,4 +1,4 @@ -import { HookEventType } from '../../common/enum/Hook'; +import { HookEventType } from '../../common/enum/Hook.js'; export interface PublishChangePayload { 'dist-tag'?: string; diff --git a/app/core/entity/Package.ts b/app/core/entity/Package.ts index f63bf373..e5175750 100644 --- a/app/core/entity/Package.ts +++ b/app/core/entity/Package.ts @@ -1,7 +1,7 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; -import { Dist } from './Dist'; -import { getFullname } from '../../common/PackageUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; +import { Dist } from './Dist.js'; +import { getFullname } from '../../common/PackageUtil.js'; interface PackageData extends EntityData { scope: string; @@ -22,6 +22,10 @@ export enum DIST_NAMES { ABBREVIATED_MANIFESTS = 'abbreviated_manifests.json', } +export function isPkgManifest(fileType: DIST_NAMES) { + return fileType === DIST_NAMES.FULL_MANIFESTS || fileType === DIST_NAMES.ABBREVIATED_MANIFESTS; +} + interface FileInfo { size: number; shasum: string; diff --git a/app/core/entity/PackageTag.ts b/app/core/entity/PackageTag.ts index d60b8e1e..b5850876 100644 --- a/app/core/entity/PackageTag.ts +++ b/app/core/entity/PackageTag.ts @@ -1,5 +1,5 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface PackageTagData extends EntityData { packageId: string; diff --git a/app/core/entity/PackageVersion.ts b/app/core/entity/PackageVersion.ts index d50b21f5..549c2677 100644 --- a/app/core/entity/PackageVersion.ts +++ b/app/core/entity/PackageVersion.ts @@ -1,7 +1,7 @@ -import { Dist } from './Dist'; -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; -import { PaddingSemVer } from './PaddingSemVer'; +import { Dist } from './Dist.js'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; +import { PaddingSemVer } from './PaddingSemVer.js'; interface PackageVersionData extends EntityData { packageId: string; diff --git a/app/core/entity/PackageVersionBlock.ts b/app/core/entity/PackageVersionBlock.ts index 1316fb33..b9fe19b3 100644 --- a/app/core/entity/PackageVersionBlock.ts +++ b/app/core/entity/PackageVersionBlock.ts @@ -1,5 +1,5 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface PackageVersionBlockData extends EntityData { packageVersionBlockId: string; diff --git a/app/core/entity/PackageVersionFile.ts b/app/core/entity/PackageVersionFile.ts index 4cc3ff17..52977cd5 100644 --- a/app/core/entity/PackageVersionFile.ts +++ b/app/core/entity/PackageVersionFile.ts @@ -1,6 +1,6 @@ -import { Dist } from './Dist'; -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Dist } from './Dist.js'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface PackageVersionFileData extends EntityData { packageVersionFileId: string; diff --git a/app/core/entity/PackageVersionManifest.ts b/app/core/entity/PackageVersionManifest.ts index c270ed8c..3c26901d 100644 --- a/app/core/entity/PackageVersionManifest.ts +++ b/app/core/entity/PackageVersionManifest.ts @@ -1,5 +1,5 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface PackageVersionManifestData extends EntityData { packageId: string; diff --git a/app/core/entity/ProxyCache.ts b/app/core/entity/ProxyCache.ts index 7e6cea00..61f6921e 100644 --- a/app/core/entity/ProxyCache.ts +++ b/app/core/entity/ProxyCache.ts @@ -1,8 +1,7 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData } from '../util/EntityUtil'; -import { DIST_NAMES } from './Package'; -import { isPkgManifest } from '../service/ProxyCacheService'; -import { PROXY_CACHE_DIR_NAME } from '../../common/constants'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData } from '../util/EntityUtil.js'; +import { DIST_NAMES, isPkgManifest } from './Package.js'; +import { PROXY_CACHE_DIR_NAME } from '../../common/constants.js'; interface ProxyCacheData extends EntityData { fullname: string; fileType: DIST_NAMES; diff --git a/app/core/entity/Registry.ts b/app/core/entity/Registry.ts index 0ec43c17..dbc5f9cf 100644 --- a/app/core/entity/Registry.ts +++ b/app/core/entity/Registry.ts @@ -1,6 +1,6 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; -import type { RegistryType } from '../../common/enum/Registry'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; +import type { RegistryType } from '../../common/enum/Registry.js'; interface RegistryData extends EntityData { name: string; diff --git a/app/core/entity/Scope.ts b/app/core/entity/Scope.ts index d9b8e1f6..bda1a8bd 100644 --- a/app/core/entity/Scope.ts +++ b/app/core/entity/Scope.ts @@ -1,5 +1,5 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface ScopeData extends EntityData { name: string; diff --git a/app/core/entity/SqlRange.ts b/app/core/entity/SqlRange.ts index ca47a4df..f9b50a01 100644 --- a/app/core/entity/SqlRange.ts +++ b/app/core/entity/SqlRange.ts @@ -1,5 +1,5 @@ import { Range, Comparator } from 'semver'; -import { PaddingSemVer } from './PaddingSemVer'; +import { PaddingSemVer } from './PaddingSemVer.js'; const OPERATOR_MAP = { '<': '$lt', diff --git a/app/core/entity/Task.ts b/app/core/entity/Task.ts index d0eee118..0aa8888c 100644 --- a/app/core/entity/Task.ts +++ b/app/core/entity/Task.ts @@ -1,14 +1,13 @@ import os from 'node:os'; import path from 'node:path'; -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; -import { TaskType, TaskState } from '../../common/enum/Task'; -import { PROXY_CACHE_DIR_NAME } from '../../common/constants'; -import dayjs from '../../common/dayjs'; -import { HookEvent } from './HookEvent'; -import { DIST_NAMES } from './Package'; -import { isPkgManifest } from '../service/ProxyCacheService'; import { InternalServerError } from 'egg-errors'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; +import { TaskType, TaskState } from '../../common/enum/Task.js'; +import { PROXY_CACHE_DIR_NAME } from '../../common/constants.js'; +import dayjs from '../../common/dayjs.js'; +import { HookEvent } from './HookEvent.js'; +import { DIST_NAMES, isPkgManifest } from './Package.js'; export const HOST_NAME = os.hostname(); export const PID = process.pid; diff --git a/app/core/entity/Token.ts b/app/core/entity/Token.ts index cdd7b68a..c42f5ec0 100644 --- a/app/core/entity/Token.ts +++ b/app/core/entity/Token.ts @@ -1,6 +1,6 @@ import dayjs from 'dayjs'; -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; export enum TokenType { granular = 'granular', diff --git a/app/core/entity/User.ts b/app/core/entity/User.ts index aeed68b5..5837ee7a 100644 --- a/app/core/entity/User.ts +++ b/app/core/entity/User.ts @@ -1,6 +1,6 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; -import { cleanUserPrefix } from '../../common/PackageUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; +import { cleanUserPrefix } from '../../common/PackageUtil.js'; interface UserData extends EntityData { userId: string; diff --git a/app/core/entity/WebauthnCredential.ts b/app/core/entity/WebauthnCredential.ts index ceef9aac..8e8d684a 100644 --- a/app/core/entity/WebauthnCredential.ts +++ b/app/core/entity/WebauthnCredential.ts @@ -1,5 +1,5 @@ -import { Entity, EntityData } from './Entity'; -import { EasyData, EntityUtil } from '../util/EntityUtil'; +import { Entity, EntityData } from './Entity.js'; +import { EasyData, EntityUtil } from '../util/EntityUtil.js'; interface WebauthnCredentialData extends EntityData { wancId: string; diff --git a/app/core/event/BugVersionFixHandler.ts b/app/core/event/BugVersionFixHandler.ts index 7e677173..5d46b612 100644 --- a/app/core/event/BugVersionFixHandler.ts +++ b/app/core/event/BugVersionFixHandler.ts @@ -1,8 +1,8 @@ import { Event, Inject } from '@eggjs/tegg'; import { EggLogger } from 'egg'; -import { PACKAGE_VERSION_ADDED } from './index'; -import { BUG_VERSIONS } from '../../common/constants'; -import { BugVersionService } from '../service/BugVersionService'; +import { PACKAGE_VERSION_ADDED } from './index.js'; +import { BUG_VERSIONS } from '../../common/constants.js'; +import { BugVersionService } from '../service/BugVersionService.js'; @Event(PACKAGE_VERSION_ADDED) export class BugVersionFixHandler { diff --git a/app/core/event/CacheCleaner.ts b/app/core/event/CacheCleaner.ts index 731f1a24..cf51c4fd 100644 --- a/app/core/event/CacheCleaner.ts +++ b/app/core/event/CacheCleaner.ts @@ -11,8 +11,8 @@ import { PACKAGE_MAINTAINER_CHANGED, PACKAGE_MAINTAINER_REMOVED, PACKAGE_META_CHANGED, -} from './index'; -import { CacheService } from '../../core/service/CacheService'; +} from './index.js'; +import { CacheService } from '../../core/service/CacheService.js'; class CacheCleanerEvent { @Inject() diff --git a/app/core/event/ChangesStream.ts b/app/core/event/ChangesStream.ts index 458b21e5..58b1448a 100644 --- a/app/core/event/ChangesStream.ts +++ b/app/core/event/ChangesStream.ts @@ -10,13 +10,13 @@ import { PACKAGE_MAINTAINER_CHANGED, PACKAGE_MAINTAINER_REMOVED, PACKAGE_META_CHANGED, PackageMetaChange, -} from './index'; -import { ChangeRepository } from '../../repository/ChangeRepository'; -import { Change } from '../entity/Change'; -import { HookEvent } from '../entity/HookEvent'; -import { Task } from '../entity/Task'; -import { User } from '../entity/User'; -import { TaskService } from '../service/TaskService'; +} from './index.js'; +import { ChangeRepository } from '../../repository/ChangeRepository.js'; +import { Change } from '../entity/Change.js'; +import { HookEvent } from '../entity/HookEvent.js'; +import { Task } from '../entity/Task.js'; +import { User } from '../entity/User.js'; +import { TaskService } from '../service/TaskService.js'; class ChangesStreamEvent { @Inject() diff --git a/app/core/event/StoreManifest.ts b/app/core/event/StoreManifest.ts index b2e2793d..a5bea817 100644 --- a/app/core/event/StoreManifest.ts +++ b/app/core/event/StoreManifest.ts @@ -2,11 +2,11 @@ import { Event, Inject } from '@eggjs/tegg'; import { EggAppConfig, } from 'egg'; -import { PACKAGE_VERSION_ADDED } from './index'; -import { getScopeAndName } from '../../common/PackageUtil'; -import { PackageVersionManifest as PackageVersionManifestEntity } from '../entity/PackageVersionManifest'; -import { PackageRepository } from '../../repository/PackageRepository'; -import { DistRepository } from '../../repository/DistRepository'; +import { PACKAGE_VERSION_ADDED } from './index.js'; +import { getScopeAndName } from '../../common/PackageUtil.js'; +import { PackageVersionManifest as PackageVersionManifestEntity } from '../entity/PackageVersionManifest.js'; +import { PackageRepository } from '../../repository/PackageRepository.js'; +import { DistRepository } from '../../repository/DistRepository.js'; class StoreManifestEvent { @Inject() diff --git a/app/core/event/SyncESPackage.ts b/app/core/event/SyncESPackage.ts index f1210954..63a888c0 100644 --- a/app/core/event/SyncESPackage.ts +++ b/app/core/event/SyncESPackage.ts @@ -14,9 +14,8 @@ import { PACKAGE_META_CHANGED, PACKAGE_BLOCKED, PACKAGE_UNBLOCKED, -} from './index'; - -import { PackageSearchService } from '../service/PackageSearchService'; +} from './index.js'; +import { PackageSearchService } from '../service/PackageSearchService.js'; class SyncESPackage { @Inject() diff --git a/app/core/event/SyncPackageVersionFile.ts b/app/core/event/SyncPackageVersionFile.ts index c97f7548..ae1a2c02 100644 --- a/app/core/event/SyncPackageVersionFile.ts +++ b/app/core/event/SyncPackageVersionFile.ts @@ -3,10 +3,10 @@ import { EggAppConfig, EggLogger, } from 'egg'; import { ForbiddenError } from 'egg-errors'; -import { PACKAGE_VERSION_ADDED, PACKAGE_TAG_ADDED, PACKAGE_TAG_CHANGED } from './index'; -import { getScopeAndName } from '../../common/PackageUtil'; -import { PackageManagerService } from '../service/PackageManagerService'; -import { PackageVersionFileService } from '../service/PackageVersionFileService'; +import { PACKAGE_VERSION_ADDED, PACKAGE_TAG_ADDED, PACKAGE_TAG_CHANGED } from './index.js'; +import { getScopeAndName } from '../../common/PackageUtil.js'; +import { PackageManagerService } from '../service/PackageManagerService.js'; +import { PackageVersionFileService } from '../service/PackageVersionFileService.js'; class SyncPackageVersionFileEvent { @Inject() diff --git a/app/core/event/index.ts b/app/core/event/index.ts index d2121cf9..61a3f9aa 100644 --- a/app/core/event/index.ts +++ b/app/core/event/index.ts @@ -1,5 +1,5 @@ import '@eggjs/tegg'; -import { User } from '../entity/User'; +import { User } from '../entity/User.js'; export const PACKAGE_UNPUBLISHED = 'PACKAGE_UNPUBLISHED'; export const PACKAGE_BLOCKED = 'PACKAGE_BLOCKED'; diff --git a/app/core/package.json b/app/core/package.json index 10e04fc7..910e8bca 100644 --- a/app/core/package.json +++ b/app/core/package.json @@ -2,5 +2,6 @@ "name": "cnpmcore-core", "eggModule": { "name": "cnpmcoreCore" - } + }, + "type": "module" } diff --git a/app/core/service/BinarySyncerService.ts b/app/core/service/BinarySyncerService.ts index 0dd3e0f0..ecfe7273 100644 --- a/app/core/service/BinarySyncerService.ts +++ b/app/core/service/BinarySyncerService.ts @@ -8,19 +8,19 @@ import { EggHttpClient, } from 'egg'; import fs from 'node:fs/promises'; -import { sortBy } from 'lodash'; -import binaries, { BinaryName, CategoryName } from '../../../config/binaries'; -import { BinaryRepository } from '../../repository/BinaryRepository'; -import { Task } from '../entity/Task'; -import { Binary } from '../entity/Binary'; -import { TaskService } from './TaskService'; -import { NFSAdapter } from '../../common/adapter/NFSAdapter'; -import { downloadToTempfile } from '../../common/FileUtil'; -import { isTimeoutError } from '../../common/ErrorUtil'; -import { AbstractBinary, BinaryItem } from '../../common/adapter/binary/AbstractBinary'; -import { AbstractService } from '../../common/AbstractService'; -import { BinaryType } from '../../common/enum/Binary'; -import { TaskType, TaskState } from '../../common/enum/Task'; +import { sortBy } from 'lodash-es'; +import binaries, { BinaryName, CategoryName } from '../../../config/binaries.js'; +import { BinaryRepository } from '../../repository/BinaryRepository.js'; +import { Task } from '../entity/Task.js'; +import { Binary } from '../entity/Binary.js'; +import { TaskService } from './TaskService.js'; +import { NFSAdapter } from '../../common/adapter/NFSAdapter.js'; +import { downloadToTempfile } from '../../common/FileUtil.js'; +import { isTimeoutError } from '../../common/ErrorUtil.js'; +import { AbstractBinary, BinaryItem } from '../../common/adapter/binary/AbstractBinary.js'; +import { AbstractService } from '../../common/AbstractService.js'; +import { BinaryType } from '../../common/enum/Binary.js'; +import { TaskType, TaskState } from '../../common/enum/Task.js'; function isoNow() { return new Date().toISOString(); diff --git a/app/core/service/BugVersionService.ts b/app/core/service/BugVersionService.ts index 4e6b1016..319ef9e1 100644 --- a/app/core/service/BugVersionService.ts +++ b/app/core/service/BugVersionService.ts @@ -1,13 +1,13 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import { EggLogger } from 'egg'; import pMap from 'p-map'; -import { BugVersion } from '../entity/BugVersion'; -import { PackageJSONType, PackageRepository } from '../../repository/PackageRepository'; -import { DistRepository } from '../../repository/DistRepository'; -import { getScopeAndName } from '../../common/PackageUtil'; -import { CacheService } from './CacheService'; -import { BUG_VERSIONS, LATEST_TAG } from '../../common/constants'; -import { BugVersionStore } from '../../common/adapter/BugVersionStore'; +import { BugVersion } from '../entity/BugVersion.js'; +import { PackageJSONType, PackageRepository } from '../../repository/PackageRepository.js'; +import { DistRepository } from '../../repository/DistRepository.js'; +import { getScopeAndName } from '../../common/PackageUtil.js'; +import { CacheService } from './CacheService.js'; +import { BUG_VERSIONS, LATEST_TAG } from '../../common/constants.js'; +import { BugVersionStore } from '../../common/adapter/BugVersionStore.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/core/service/CacheService.ts b/app/core/service/CacheService.ts index 76e50c38..8a8fc143 100644 --- a/app/core/service/CacheService.ts +++ b/app/core/service/CacheService.ts @@ -3,11 +3,11 @@ import { SingletonProto, Inject, } from '@eggjs/tegg'; -import { CacheAdapter } from '../../common/adapter/CacheAdapter'; -import { AbstractService } from '../../common/AbstractService'; -import { ChangesStreamTaskData } from '../entity/Task'; +import { CacheAdapter } from '../../common/adapter/CacheAdapter.js'; +import { AbstractService } from '../../common/AbstractService.js'; +import { ChangesStreamTaskData } from '../entity/Task.js'; -type PackageCacheAttribe = 'etag' | 'manifests'; +type PackageCacheAttribute = 'etag' | 'manifests'; export type UpstreamRegistryInfo = { registry_name: string; @@ -95,14 +95,14 @@ export class CacheService extends AbstractService { public async removeCache(fullname: string) { await Promise.all([ - await this.cacheAdapter.delete(this.cacheKey(fullname, true, 'etag')), - await this.cacheAdapter.delete(this.cacheKey(fullname, true, 'manifests')), - await this.cacheAdapter.delete(this.cacheKey(fullname, false, 'etag')), - await this.cacheAdapter.delete(this.cacheKey(fullname, false, 'manifests')), + this.cacheAdapter.delete(this.cacheKey(fullname, true, 'etag')), + this.cacheAdapter.delete(this.cacheKey(fullname, true, 'manifests')), + this.cacheAdapter.delete(this.cacheKey(fullname, false, 'etag')), + this.cacheAdapter.delete(this.cacheKey(fullname, false, 'manifests')), ]); } - private cacheKey(fullname: string, isFullManifests: boolean, attribute: PackageCacheAttribe) { + private cacheKey(fullname: string, isFullManifests: boolean, attribute: PackageCacheAttribute) { return `${fullname}|${isFullManifests ? 'full' : 'abbr'}:${attribute}`; } } diff --git a/app/core/service/ChangesStreamService.ts b/app/core/service/ChangesStreamService.ts index f8f821df..38a1b2a9 100644 --- a/app/core/service/ChangesStreamService.ts +++ b/app/core/service/ChangesStreamService.ts @@ -7,20 +7,20 @@ import { Inject, } from '@eggjs/tegg'; import { E500 } from 'egg-errors'; -import { PackageSyncerService, RegistryNotMatchError } from './PackageSyncerService'; -import { TaskService } from './TaskService'; -import { RegistryManagerService } from './RegistryManagerService'; -import { ScopeManagerService } from './ScopeManagerService'; -import { PackageRepository } from '../../repository/PackageRepository'; -import { TaskRepository } from '../../repository/TaskRepository'; -import { HOST_NAME, ChangesStreamTask, Task } from '../entity/Task'; -import { Registry } from '../entity/Registry'; -import { AbstractChangeStream } from '../../common/adapter/changesStream/AbstractChangesStream'; -import { getScopeAndName } from '../../common/PackageUtil'; -import { isTimeoutError } from '../../common/ErrorUtil'; -import { GLOBAL_WORKER } from '../../common/constants'; -import { TaskState, TaskType } from '../../common/enum/Task'; -import { AbstractService } from '../../common/AbstractService'; +import { PackageSyncerService, RegistryNotMatchError } from './PackageSyncerService.js'; +import { TaskService } from './TaskService.js'; +import { RegistryManagerService } from './RegistryManagerService.js'; +import { ScopeManagerService } from './ScopeManagerService.js'; +import { PackageRepository } from '../../repository/PackageRepository.js'; +import { TaskRepository } from '../../repository/TaskRepository.js'; +import { HOST_NAME, ChangesStreamTask, Task } from '../entity/Task.js'; +import { Registry } from '../entity/Registry.js'; +import { AbstractChangeStream } from '../../common/adapter/changesStream/AbstractChangesStream.js'; +import { getScopeAndName } from '../../common/PackageUtil.js'; +import { isTimeoutError } from '../../common/ErrorUtil.js'; +import { GLOBAL_WORKER } from '../../common/constants.js'; +import { TaskState, TaskType } from '../../common/enum/Task.js'; +import { AbstractService } from '../../common/AbstractService.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/core/service/CreateHookTriggerService.ts b/app/core/service/CreateHookTriggerService.ts index 6762d0c0..c96379be 100644 --- a/app/core/service/CreateHookTriggerService.ts +++ b/app/core/service/CreateHookTriggerService.ts @@ -1,16 +1,16 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { AbstractService } from '../../common/AbstractService'; -import { HookType } from '../../common/enum/Hook'; -import { TaskState } from '../../common/enum/Task'; -import { HookEvent } from '../entity/HookEvent'; -import { CreateHookTask, Task } from '../entity/Task'; -import { HookRepository } from '../../repository/HookRepository'; -import { PackageRepository } from '../../repository/PackageRepository'; import pMap from 'p-map'; -import { Hook } from '../entity/Hook'; -import { TaskService } from './TaskService'; -import { isoNow } from '../../common/LogUtil'; -import { getScopeAndName } from '../../common/PackageUtil'; +import { AbstractService } from '../../common/AbstractService.js'; +import { HookType } from '../../common/enum/Hook.js'; +import { TaskState } from '../../common/enum/Task.js'; +import { HookEvent } from '../entity/HookEvent.js'; +import { CreateHookTask, Task } from '../entity/Task.js'; +import { HookRepository } from '../../repository/HookRepository.js'; +import { PackageRepository } from '../../repository/PackageRepository.js'; +import { Hook } from '../entity/Hook.js'; +import { TaskService } from './TaskService.js'; +import { isoNow } from '../../common/LogUtil.js'; +import { getScopeAndName } from '../../common/PackageUtil.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/core/service/FixNoPaddingVersionService.ts b/app/core/service/FixNoPaddingVersionService.ts index 232e7486..4add282d 100644 --- a/app/core/service/FixNoPaddingVersionService.ts +++ b/app/core/service/FixNoPaddingVersionService.ts @@ -1,8 +1,8 @@ import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg'; import { EggLogger } from 'egg'; import pMap from 'p-map'; -import { PackageVersionRepository } from '../../repository/PackageVersionRepository'; -import { PaddingSemVer } from '../entity/PaddingSemVer'; +import { PackageVersionRepository } from '../../repository/PackageVersionRepository.js'; +import { PaddingSemVer } from '../entity/PaddingSemVer.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/core/service/HomeService.ts b/app/core/service/HomeService.ts index 2e2c0e1a..e3de3ea0 100644 --- a/app/core/service/HomeService.ts +++ b/app/core/service/HomeService.ts @@ -2,9 +2,9 @@ import { AccessLevel, SingletonProto, } from '@eggjs/tegg'; -import { AbstractService } from '../../common/AbstractService'; -import { NOT_IMPLEMENTED_PATH } from '../../common/constants'; import { NotFoundError, NotImplementedError } from 'egg-errors'; +import { AbstractService } from '../../common/AbstractService.js'; +import { NOT_IMPLEMENTED_PATH } from '../../common/constants.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/core/service/HookManageService.ts b/app/core/service/HookManageService.ts index 80262bbf..4d49c0f7 100644 --- a/app/core/service/HookManageService.ts +++ b/app/core/service/HookManageService.ts @@ -1,12 +1,12 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { Hook } from '../entity/Hook'; -import { HookType } from '../../common/enum/Hook'; import { ForbiddenError, NotFoundError, } from 'egg-errors'; -import { HookRepository } from '../../repository/HookRepository'; import { EggAppConfig } from 'egg'; +import { HookRepository } from '../../repository/HookRepository.js'; +import { Hook } from '../entity/Hook.js'; +import { HookType } from '../../common/enum/Hook.js'; export interface CreateHookCommand { type: HookType; diff --git a/app/core/service/HookTriggerService.ts b/app/core/service/HookTriggerService.ts index c6d88571..503f8e40 100644 --- a/app/core/service/HookTriggerService.ts +++ b/app/core/service/HookTriggerService.ts @@ -1,16 +1,16 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { TriggerHookTask } from '../entity/Task'; -import { HookEvent } from '../entity/HookEvent'; -import { HookRepository } from '../../repository/HookRepository'; -import { PackageRepository } from '../../repository/PackageRepository'; -import { DistRepository } from '../../repository/DistRepository'; -import { UserRepository } from '../../repository/UserRepository'; -import { Hook } from '../entity/Hook'; import { EggContextHttpClient } from 'egg'; -import { isoNow } from '../../common/LogUtil'; -import { TaskState } from '../../common/enum/Task'; -import { TaskService } from './TaskService'; -import { getScopeAndName } from '../../common/PackageUtil'; +import { TriggerHookTask } from '../entity/Task.js'; +import { HookEvent } from '../entity/HookEvent.js'; +import { HookRepository } from '../../repository/HookRepository.js'; +import { PackageRepository } from '../../repository/PackageRepository.js'; +import { DistRepository } from '../../repository/DistRepository.js'; +import { UserRepository } from '../../repository/UserRepository.js'; +import { Hook } from '../entity/Hook.js'; +import { isoNow } from '../../common/LogUtil.js'; +import { TaskState } from '../../common/enum/Task.js'; +import { TaskService } from './TaskService.js'; +import { getScopeAndName } from '../../common/PackageUtil.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/core/service/PackageManagerService.ts b/app/core/service/PackageManagerService.ts index 4451d0cf..7b25df77 100644 --- a/app/core/service/PackageManagerService.ts +++ b/app/core/service/PackageManagerService.ts @@ -18,19 +18,25 @@ import { getFullname, getScopeAndName, hasShrinkWrapInTgz, -} from '../../common/PackageUtil'; -import { AbstractService } from '../../common/AbstractService'; -import { AbbreviatedPackageJSONType, AbbreviatedPackageManifestType, PackageJSONType, PackageManifestType, PackageRepository } from '../../repository/PackageRepository'; -import { PackageVersionBlockRepository } from '../../repository/PackageVersionBlockRepository'; -import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository'; -import { DistRepository } from '../../repository/DistRepository'; -import { isDuplicateKeyError } from '../../repository/util/ErrorUtil'; -import { Package } from '../entity/Package'; -import { PackageVersion } from '../entity/PackageVersion'; -import { PackageVersionBlock } from '../entity/PackageVersionBlock'; -import { PackageTag } from '../entity/PackageTag'; -import { User } from '../entity/User'; -import { Dist } from '../entity/Dist'; +} from '../../common/PackageUtil.js'; +import { AbstractService } from '../../common/AbstractService.js'; +import { + AbbreviatedPackageJSONType, + AbbreviatedPackageManifestType, + PackageJSONType, + PackageManifestType, + PackageRepository, +} from '../../repository/PackageRepository.js'; +import { PackageVersionBlockRepository } from '../../repository/PackageVersionBlockRepository.js'; +import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository.js'; +import { DistRepository } from '../../repository/DistRepository.js'; +import { isDuplicateKeyError } from '../../repository/util/ErrorUtil.js'; +import { Package } from '../entity/Package.js'; +import { PackageVersion } from '../entity/PackageVersion.js'; +import { PackageVersionBlock } from '../entity/PackageVersionBlock.js'; +import { PackageTag } from '../entity/PackageTag.js'; +import { User } from '../entity/User.js'; +import { Dist } from '../entity/Dist.js'; import { PACKAGE_UNPUBLISHED, PACKAGE_BLOCKED, @@ -43,12 +49,12 @@ import { PACKAGE_TAG_CHANGED, PACKAGE_TAG_REMOVED, PACKAGE_META_CHANGED, -} from '../event'; -import { BugVersionService } from './BugVersionService'; -import { BugVersion } from '../entity/BugVersion'; -import { RegistryManagerService } from './RegistryManagerService'; -import { Registry } from '../entity/Registry'; -import { PackageVersionService } from './PackageVersionService'; +} from '../event/index.js'; +import { BugVersionService } from './BugVersionService.js'; +import { BugVersion } from '../entity/BugVersion.js'; +import { RegistryManagerService } from './RegistryManagerService.js'; +import { Registry } from '../entity/Registry.js'; +import { PackageVersionService } from './PackageVersionService.js'; export interface PublishPackageCmd { // maintainer: Maintainer; @@ -706,8 +712,8 @@ export class PackageManagerService extends AbstractService { fullManifests, abbreviatedManifests, ] = await Promise.all([ - await this._listPackageFullManifests(pkg), - await this._listPackageAbbreviatedManifests(pkg), + this._listPackageFullManifests(pkg), + this._listPackageAbbreviatedManifests(pkg), ]); await this._updatePackageManifestsToDists(pkg, fullManifests, abbreviatedManifests); } @@ -998,7 +1004,7 @@ export class PackageManagerService extends AbstractService { } const pkgVersion = await this.packageVersionService.getVersion(npa(`${fullname}@${spec}`)); assert(pkgVersion); - } catch (e) { + } catch { throw new BadRequestError(`deps ${fullname}@${spec} not found`); } }, { diff --git a/app/core/service/PackageSearchService.ts b/app/core/service/PackageSearchService.ts index 392080ec..fc389490 100644 --- a/app/core/service/PackageSearchService.ts +++ b/app/core/service/PackageSearchService.ts @@ -1,14 +1,13 @@ import { AccessLevel, Inject, SingletonProto } from '@eggjs/tegg'; import { estypes, errors } from '@elastic/elasticsearch'; import dayjs from 'dayjs'; - -import { AbstractService } from '../../common/AbstractService'; -import { formatAuthor, getScopeAndName } from '../../common/PackageUtil'; -import { PackageManagerService } from './PackageManagerService'; -import { SearchManifestType, SearchMappingType, SearchRepository } from '../../repository/SearchRepository'; -import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository'; -import { PackageRepository } from '../../repository/PackageRepository'; -import { PackageVersionBlockRepository } from '../../repository/PackageVersionBlockRepository'; +import { AbstractService } from '../../common/AbstractService.js'; +import { formatAuthor, getScopeAndName } from '../../common/PackageUtil.js'; +import { PackageManagerService } from './PackageManagerService.js'; +import { SearchManifestType, SearchMappingType, SearchRepository } from '../../repository/SearchRepository.js'; +import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository.js'; +import { PackageRepository } from '../../repository/PackageRepository.js'; +import { PackageVersionBlockRepository } from '../../repository/PackageVersionBlockRepository.js'; @SingletonProto({ @@ -58,7 +57,7 @@ export class PackageSearchService extends AbstractService { for (let i = 1; i <= 31; i++) { const day = String(i).padStart(2, '0'); const field = `d${day}`; - const counter = entity[field]; + const counter = entity[field as keyof typeof entity] as number; if (!counter) continue; downloadsAll += counter; } diff --git a/app/core/service/PackageSyncerService.ts b/app/core/service/PackageSyncerService.ts index f8edb09d..2f25749a 100644 --- a/app/core/service/PackageSyncerService.ts +++ b/app/core/service/PackageSyncerService.ts @@ -8,30 +8,30 @@ import { } from '@eggjs/tegg'; import { Pointcut } from '@eggjs/tegg/aop'; import { EggHttpClient } from 'egg'; -import { isEqual, isEmpty } from 'lodash'; +import { isEqual, isEmpty } from 'lodash-es'; import semver from 'semver'; -import { NPMRegistry, RegistryResponse } from '../../common/adapter/NPMRegistry'; -import { detectInstallScript, getScopeAndName } from '../../common/PackageUtil'; -import { downloadToTempfile } from '../../common/FileUtil'; -import { TaskState, TaskType } from '../../common/enum/Task'; -import { AbstractService } from '../../common/AbstractService'; -import { TaskRepository } from '../../repository/TaskRepository'; -import { PackageJSONType, PackageManifestType, PackageRepository } from '../../repository/PackageRepository'; -import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository'; -import { UserRepository } from '../../repository/UserRepository'; -import { Task, SyncPackageTaskOptions, CreateSyncPackageTask } from '../entity/Task'; -import { Package } from '../entity/Package'; -import { UserService } from './UserService'; -import { TaskService } from './TaskService'; -import { PackageManagerService } from './PackageManagerService'; -import { CacheService } from './CacheService'; -import { User } from '../entity/User'; -import { RegistryManagerService } from './RegistryManagerService'; -import { Registry } from '../entity/Registry'; import { BadRequestError } from 'egg-errors'; -import { ScopeManagerService } from './ScopeManagerService'; -import { EventCorkAdvice } from './EventCorkerAdvice'; -import { PresetRegistryName, SyncDeleteMode } from '../../common/constants'; +import { NPMRegistry, RegistryResponse } from '../../common/adapter/NPMRegistry.js'; +import { detectInstallScript, getScopeAndName } from '../../common/PackageUtil.js'; +import { downloadToTempfile } from '../../common/FileUtil.js'; +import { TaskState, TaskType } from '../../common/enum/Task.js'; +import { AbstractService } from '../../common/AbstractService.js'; +import { TaskRepository } from '../../repository/TaskRepository.js'; +import { PackageJSONType, PackageManifestType, PackageRepository } from '../../repository/PackageRepository.js'; +import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository.js'; +import { UserRepository } from '../../repository/UserRepository.js'; +import { Task, SyncPackageTaskOptions, CreateSyncPackageTask } from '../entity/Task.js'; +import { Package } from '../entity/Package.js'; +import { UserService } from './UserService.js'; +import { TaskService } from './TaskService.js'; +import { PackageManagerService } from './PackageManagerService.js'; +import { CacheService } from './CacheService.js'; +import { User } from '../entity/User.js'; +import { RegistryManagerService } from './RegistryManagerService.js'; +import { Registry } from '../entity/Registry.js'; +import { ScopeManagerService } from './ScopeManagerService.js'; +import { EventCorkAdvice } from './EventCorkerAdvice.js'; +import { PresetRegistryName, SyncDeleteMode } from '../../common/constants.js'; type syncDeletePkgOptions = { task: Task, diff --git a/app/core/service/PackageVersionFileService.ts b/app/core/service/PackageVersionFileService.ts index f02827fa..d766f817 100644 --- a/app/core/service/PackageVersionFileService.ts +++ b/app/core/service/PackageVersionFileService.ts @@ -1,6 +1,7 @@ import fs from 'node:fs/promises'; import { join, dirname, basename } from 'node:path'; import { randomUUID } from 'node:crypto'; +// @ts-expect-error type error import tar from '@fengmk2/tar'; import { AccessLevel, @@ -9,24 +10,24 @@ import { } from '@eggjs/tegg'; import { ConflictError, ForbiddenError } from 'egg-errors'; import semver from 'semver'; -import { AbstractService } from '../../common/AbstractService'; +import { AbstractService } from '../../common/AbstractService.js'; import { calculateIntegrity, getFullname, -} from '../../common/PackageUtil'; -import { createTempDir, mimeLookup } from '../../common/FileUtil'; +} from '../../common/PackageUtil.js'; +import { createTempDir, mimeLookup } from '../../common/FileUtil.js'; import { PackageRepository, -} from '../../repository/PackageRepository'; -import { PackageVersionFileRepository } from '../../repository/PackageVersionFileRepository'; -import { PackageVersionRepository } from '../../repository/PackageVersionRepository'; -import { DistRepository } from '../../repository/DistRepository'; -import { isDuplicateKeyError } from '../../repository/util/ErrorUtil'; -import { PackageVersionFile } from '../entity/PackageVersionFile'; -import { PackageVersion } from '../entity/PackageVersion'; -import { Package } from '../entity/Package'; -import { PackageManagerService } from './PackageManagerService'; -import { CacheAdapter } from '../../common/adapter/CacheAdapter'; +} from '../../repository/PackageRepository.js'; +import { PackageVersionFileRepository } from '../../repository/PackageVersionFileRepository.js'; +import { PackageVersionRepository } from '../../repository/PackageVersionRepository.js'; +import { DistRepository } from '../../repository/DistRepository.js'; +import { isDuplicateKeyError } from '../../repository/util/ErrorUtil.js'; +import { PackageVersionFile } from '../entity/PackageVersionFile.js'; +import { PackageVersion } from '../entity/PackageVersion.js'; +import { Package } from '../entity/Package.js'; +import { PackageManagerService } from './PackageManagerService.js'; +import { CacheAdapter } from '../../common/adapter/CacheAdapter.js'; const unpkgWhiteListUrl = 'https://github.com/cnpm/unpkg-white-list'; const CHECK_TIMEOUT = process.env.NODE_ENV === 'test' ? 1 : 60000; @@ -148,7 +149,7 @@ export class PackageVersionFileService extends AbstractService { file: tarFile, cwd: tmpdir, strip: 1, - onentry: entry => { + onentry: (entry: any) => { const filename = this.#formatTarEntryFilename(entry); if (!filename) return; if (this.#matchReadmeFilename(filename)) { @@ -204,7 +205,7 @@ export class PackageVersionFileService extends AbstractService { file: tarFile, cwd: tmpdir, strip: 1, - onentry: entry => { + onentry: (entry: any) => { const filename = this.#formatTarEntryFilename(entry); if (!filename) return; paths.push('/' + filename); diff --git a/app/core/service/PackageVersionService.ts b/app/core/service/PackageVersionService.ts index 8852ca48..71504050 100644 --- a/app/core/service/PackageVersionService.ts +++ b/app/core/service/PackageVersionService.ts @@ -1,13 +1,13 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; import semver, { Range } from 'semver'; import { Result, AliasResult } from 'npm-package-arg'; -import { PackageVersionRepository } from '../../repository/PackageVersionRepository'; -import { getScopeAndName } from '../../common/PackageUtil'; -import { SqlRange } from '../entity/SqlRange'; -import { BugVersionService } from './BugVersionService'; -import type { PackageJSONType } from '../../repository/PackageRepository'; -import { DistRepository } from '../../repository/DistRepository'; -import { BugVersionAdvice } from '../entity/BugVersion'; +import { PackageVersionRepository } from '../../repository/PackageVersionRepository.js'; +import { getScopeAndName } from '../../common/PackageUtil.js'; +import { SqlRange } from '../entity/SqlRange.js'; +import { BugVersionService } from './BugVersionService.js'; +import type { PackageJSONType } from '../../repository/PackageRepository.js'; +import { DistRepository } from '../../repository/DistRepository.js'; +import { BugVersionAdvice } from '../entity/BugVersion.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/core/service/ProxyCacheService.ts b/app/core/service/ProxyCacheService.ts index 4d715bed..1bb40f85 100644 --- a/app/core/service/ProxyCacheService.ts +++ b/app/core/service/ProxyCacheService.ts @@ -3,29 +3,30 @@ import { ForbiddenError } from 'egg-errors'; import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg'; import { BackgroundTaskHelper } from '@eggjs/tegg-background-task'; import { valid as semverValid } from 'semver'; -import { AbstractService } from '../../common/AbstractService'; -import { TaskService } from './TaskService'; -import { CacheService } from './CacheService'; -import { RegistryManagerService } from './RegistryManagerService'; -import { NPMRegistry } from '../../common/adapter/NPMRegistry'; -import { NFSAdapter } from '../../common/adapter/NFSAdapter'; -import { ProxyCache } from '../entity/ProxyCache'; -import { Task, UpdateProxyCacheTaskOptions, CreateUpdateProxyCacheTask } from '../entity/Task'; -import { ProxyCacheRepository } from '../../repository/ProxyCacheRepository'; -import { TaskType, TaskState } from '../../common/enum/Task'; -import { calculateIntegrity } from '../../common/PackageUtil'; -import { ABBREVIATED_META_TYPE, PROXY_CACHE_DIR_NAME } from '../../common/constants'; -import { DIST_NAMES } from '../entity/Package'; -import type { AbbreviatedPackageManifestType, AbbreviatedPackageJSONType, PackageManifestType, PackageJSONType } from '../../repository/PackageRepository'; +import { AbstractService } from '../../common/AbstractService.js'; +import { TaskService } from './TaskService.js'; +import { CacheService } from './CacheService.js'; +import { RegistryManagerService } from './RegistryManagerService.js'; +import { NPMRegistry } from '../../common/adapter/NPMRegistry.js'; +import { NFSAdapter } from '../../common/adapter/NFSAdapter.js'; +import { ProxyCache } from '../entity/ProxyCache.js'; +import { Task, UpdateProxyCacheTaskOptions, CreateUpdateProxyCacheTask } from '../entity/Task.js'; +import { ProxyCacheRepository } from '../../repository/ProxyCacheRepository.js'; +import { TaskType, TaskState } from '../../common/enum/Task.js'; +import { calculateIntegrity } from '../../common/PackageUtil.js'; +import { ABBREVIATED_META_TYPE, PROXY_CACHE_DIR_NAME } from '../../common/constants.js'; +import { DIST_NAMES, isPkgManifest } from '../entity/Package.js'; +import type { + AbbreviatedPackageManifestType, + AbbreviatedPackageJSONType, + PackageManifestType, + PackageJSONType, +} from '../../repository/PackageRepository.js'; function isoNow() { return new Date().toISOString(); } -export function isPkgManifest(fileType: DIST_NAMES) { - return fileType === DIST_NAMES.FULL_MANIFESTS || fileType === DIST_NAMES.ABBREVIATED_MANIFESTS; -} - type GetSourceManifestAndCacheReturnType = T extends DIST_NAMES.ABBREVIATED | DIST_NAMES.MANIFEST ? AbbreviatedPackageJSONType | PackageJSONType : T extends DIST_NAMES.FULL_MANIFESTS | DIST_NAMES.ABBREVIATED_MANIFESTS ? AbbreviatedPackageManifestType|PackageManifestType : never; @@ -228,11 +229,11 @@ export class ProxyCacheService extends AbstractService { } // replace tarball url - const manifest = this.replaceTarballUrl(responseResult.data, fileType); + const manifest = this.replaceTarballUrl(responseResult!.data, fileType); return manifest; } - private async storeRewrittenManifest(manifest, fullname: string, fileType: DIST_NAMES) { + private async storeRewrittenManifest(manifest: any, fullname: string, fileType: DIST_NAMES) { let storeKey: string; if (isPkgManifest(fileType)) { storeKey = `/${PROXY_CACHE_DIR_NAME}/${fullname}/${fileType}`; diff --git a/app/core/service/RegistryManagerService.ts b/app/core/service/RegistryManagerService.ts index 2c18afe2..7442c1c1 100644 --- a/app/core/service/RegistryManagerService.ts +++ b/app/core/service/RegistryManagerService.ts @@ -4,15 +4,15 @@ import { Inject, } from '@eggjs/tegg'; import { E400, NotFoundError } from 'egg-errors'; -import { RegistryRepository } from '../../repository/RegistryRepository'; -import { AbstractService } from '../../common/AbstractService'; -import { Registry } from '../entity/Registry'; -import { PageOptions, PageResult } from '../util/EntityUtil'; -import { ScopeManagerService } from './ScopeManagerService'; -import { TaskService } from './TaskService'; -import { Task } from '../entity/Task'; -import { ChangesStreamMode, PresetRegistryName } from '../../common/constants'; -import { RegistryType } from '../../common/enum/Registry'; +import { RegistryRepository } from '../../repository/RegistryRepository.js'; +import { AbstractService } from '../../common/AbstractService.js'; +import { Registry } from '../entity/Registry.js'; +import { PageOptions, PageResult } from '../util/EntityUtil.js'; +import { ScopeManagerService } from './ScopeManagerService.js'; +import { TaskService } from './TaskService.js'; +import { Task } from '../entity/Task.js'; +import { ChangesStreamMode, PresetRegistryName } from '../../common/constants.js'; +import { RegistryType } from '../../common/enum/Registry.js'; export interface CreateRegistryCmd extends Pick { operatorId?: string; diff --git a/app/core/service/ScopeManagerService.ts b/app/core/service/ScopeManagerService.ts index 35d009ed..87c6da09 100644 --- a/app/core/service/ScopeManagerService.ts +++ b/app/core/service/ScopeManagerService.ts @@ -3,10 +3,10 @@ import { SingletonProto, Inject, } from '@eggjs/tegg'; -import { ScopeRepository } from '../../repository/ScopeRepository'; -import { AbstractService } from '../../common/AbstractService'; -import { Scope } from '../entity/Scope'; -import { PageOptions, PageResult } from '../util/EntityUtil'; +import { ScopeRepository } from '../../repository/ScopeRepository.js'; +import { AbstractService } from '../../common/AbstractService.js'; +import { Scope } from '../entity/Scope.js'; +import { PageOptions, PageResult } from '../util/EntityUtil.js'; export interface CreateScopeCmd extends Pick { operatorId?: string; diff --git a/app/core/service/TaskService.ts b/app/core/service/TaskService.ts index e7b81eb9..9d3e1f65 100644 --- a/app/core/service/TaskService.ts +++ b/app/core/service/TaskService.ts @@ -3,12 +3,12 @@ import { SingletonProto, Inject, } from '@eggjs/tegg'; -import { NFSAdapter } from '../../common/adapter/NFSAdapter'; -import { TaskState, TaskType } from '../../common/enum/Task'; -import { AbstractService } from '../../common/AbstractService'; -import { TaskRepository } from '../../repository/TaskRepository'; -import { Task, CreateSyncPackageTaskData } from '../entity/Task'; -import { QueueAdapter } from '../../common/typing'; +import { NFSAdapter } from '../../common/adapter/NFSAdapter.js'; +import { TaskState, TaskType } from '../../common/enum/Task.js'; +import { AbstractService } from '../../common/AbstractService.js'; +import { TaskRepository } from '../../repository/TaskRepository.js'; +import { Task, CreateSyncPackageTaskData } from '../entity/Task.js'; +import { QueueAdapter } from '../../common/typing.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, @@ -144,6 +144,7 @@ export class TaskService extends AbstractService { this.logger.error( '[TaskService.retryExecuteTimeoutTasks:error] processing task, taskType: %s, targetName: %s, taskId: %s, attempts %s will retry again', task.type, task.targetName, task.taskId, task.attempts); + this.logger.error(e); } } // try waiting timeout tasks in 30 mins @@ -158,6 +159,7 @@ export class TaskService extends AbstractService { this.logger.error( '[TaskService.retryExecuteTimeoutTasks:error] waiting task, taskType: %s, targetName: %s, taskId: %s, attempts %s will retry again', task.type, task.targetName, task.taskId, task.attempts); + this.logger.error(e); } } return { diff --git a/app/core/service/TokenService.ts b/app/core/service/TokenService.ts index dd7dad84..a08f6dd2 100644 --- a/app/core/service/TokenService.ts +++ b/app/core/service/TokenService.ts @@ -4,17 +4,17 @@ import { SingletonProto, Inject, } from '@eggjs/tegg'; -import { isEmpty } from 'lodash'; -import { AbstractService } from '../../common/AbstractService'; -import { Token, isGranularToken } from '../entity/Token'; -import { TokenPackage as TokenPackageModel } from '../../../app/repository/model/TokenPackage'; -import { Package as PackageModel } from '../../../app/repository/model/Package'; -import { ModelConvertor } from '../../../app/repository/util/ModelConvertor'; -import { Package as PackageEntity } from '../entity/Package'; +import { isEmpty } from 'lodash-es'; import { ForbiddenError, UnauthorizedError } from 'egg-errors'; -import { getScopeAndName } from '../../../app/common/PackageUtil'; -import { sha512 } from '../../../app/common/UserUtil'; -import { UserRepository } from '../../../app/repository/UserRepository'; +import { AbstractService } from '../../common/AbstractService.js'; +import { Token, isGranularToken } from '../entity/Token.js'; +import { TokenPackage as TokenPackageModel } from '../../../app/repository/model/TokenPackage.js'; +import { Package as PackageModel } from '../../../app/repository/model/Package.js'; +import { ModelConvertor } from '../../../app/repository/util/ModelConvertor.js'; +import { Package as PackageEntity } from '../entity/Package.js'; +import { getScopeAndName } from '../../../app/common/PackageUtil.js'; +import { sha512 } from '../../../app/common/UserUtil.js'; +import { UserRepository } from '../../../app/repository/UserRepository.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, @@ -73,7 +73,7 @@ export class TokenService extends AbstractService { async getUserAndToken(authorization: string) { if (!authorization) return null; - const matchs = /^Bearer ([\w\.]+?)$/.exec(authorization); + const matchs = /^Bearer ([\w.]+?)$/.exec(authorization); if (!matchs) return null; const tokenValue = matchs[1]; const tokenKey = sha512(tokenValue); diff --git a/app/core/service/UserService.ts b/app/core/service/UserService.ts index fd1f342c..8f34ec16 100644 --- a/app/core/service/UserService.ts +++ b/app/core/service/UserService.ts @@ -5,16 +5,16 @@ import { Inject, } from '@eggjs/tegg'; import { NotFoundError, ForbiddenError } from 'egg-errors'; -import { UserRepository } from '../../repository/UserRepository'; -import { User as UserEntity } from '../entity/User'; -import { Token as TokenEntity, TokenType } from '../entity/Token'; -import { WebauthnCredential as WebauthnCredentialEntity } from '../entity/WebauthnCredential'; -import { LoginResultCode } from '../../common/enum/User'; -import { integrity, checkIntegrity, randomToken, sha512 } from '../../common/UserUtil'; -import { AbstractService } from '../../common/AbstractService'; -import { RegistryManagerService } from './RegistryManagerService'; -import { getPrefixedName } from '../../common/PackageUtil'; -import { Registry } from '../entity/Registry'; +import { UserRepository } from '../../repository/UserRepository.js'; +import { User as UserEntity } from '../entity/User.js'; +import { Token as TokenEntity, TokenType } from '../entity/Token.js'; +import { WebauthnCredential as WebauthnCredentialEntity } from '../entity/WebauthnCredential.js'; +import { LoginResultCode } from '../../common/enum/User.js'; +import { integrity, checkIntegrity, randomToken, sha512 } from '../../common/UserUtil.js'; +import { AbstractService } from '../../common/AbstractService.js'; +import { RegistryManagerService } from './RegistryManagerService.js'; +import { getPrefixedName } from '../../common/PackageUtil.js'; +import { Registry } from '../entity/Registry.js'; type Optional = Omit < T, K > & Partial ; diff --git a/app/core/util/EntityUtil.ts b/app/core/util/EntityUtil.ts index dc28f913..2bfc2cb1 100644 --- a/app/core/util/EntityUtil.ts +++ b/app/core/util/EntityUtil.ts @@ -1,6 +1,7 @@ import ObjectID from 'bson-objectid'; import { E400 } from 'egg-errors'; -import { EntityData } from '../entity/Entity'; + +import { EntityData } from '../entity/Entity.js'; type PartialBy = Omit & Partial>; @@ -29,6 +30,7 @@ export class EntityUtil { } static createId(): string { + // @ts-expect-error ObjectID has no construct signatures return new ObjectID().toHexString(); } diff --git a/app/infra/AuthAdapter.ts b/app/infra/AuthAdapter.ts index 84ca2a09..b99ffe1e 100644 --- a/app/infra/AuthAdapter.ts +++ b/app/infra/AuthAdapter.ts @@ -6,7 +6,8 @@ import { } from '@eggjs/tegg'; import { Redis } from 'ioredis'; import { randomUUID } from 'node:crypto'; -import { AuthClient, AuthUrlResult, userResult } from '../common/typing'; + +import { AuthClient, AuthUrlResult, userResult } from '../common/typing.js'; const ONE_DAY = 3600 * 24; diff --git a/app/infra/NFSClientAdapter.ts b/app/infra/NFSClientAdapter.ts index d18e62bb..cb9d310c 100644 --- a/app/infra/NFSClientAdapter.ts +++ b/app/infra/NFSClientAdapter.ts @@ -1,3 +1,4 @@ +import { Readable } from 'node:stream'; import { AccessLevel, LifecycleInit, @@ -6,8 +7,8 @@ import { } from '@eggjs/tegg'; import { EggAppConfig, EggLogger } from 'egg'; import FSClient from 'fs-cnpm'; -import { AppendResult, NFSClient, UploadOptions, UploadResult, DownloadOptions } from '../common/typing'; -import { Readable } from 'node:stream'; + +import { AppendResult, NFSClient, UploadOptions, UploadResult, DownloadOptions } from '../common/typing.js'; @SingletonProto({ name: 'nfsClient', diff --git a/app/infra/QueueAdapter.ts b/app/infra/QueueAdapter.ts index dd5e3dbf..4b617570 100644 --- a/app/infra/QueueAdapter.ts +++ b/app/infra/QueueAdapter.ts @@ -4,7 +4,8 @@ import { SingletonProto, } from '@eggjs/tegg'; import { Redis } from 'ioredis'; -import { QueueAdapter } from '../common/typing'; + +import { QueueAdapter } from '../common/typing.js'; /** * Use sort set to keep queue in order and keep same value only insert once diff --git a/app/infra/SearchAdapter.ts b/app/infra/SearchAdapter.ts index 4f1dbbd6..80244576 100644 --- a/app/infra/SearchAdapter.ts +++ b/app/infra/SearchAdapter.ts @@ -4,9 +4,9 @@ import { SingletonProto, } from '@eggjs/tegg'; import { EggAppConfig } from 'egg'; - import { Client as ElasticsearchClient, estypes } from '@elastic/elasticsearch'; -import { SearchAdapter } from '../common/typing'; + +import { SearchAdapter } from '../common/typing.js'; /** * Use elasticsearch to search the huge npm packages. diff --git a/app/infra/package.json b/app/infra/package.json index 5ab001dd..bf844a43 100644 --- a/app/infra/package.json +++ b/app/infra/package.json @@ -2,5 +2,6 @@ "name": "cnpmcore-infra", "eggModule": { "name": "cnpmcoreInfra" - } + }, + "type": "module" } diff --git a/app/port/UserRoleManager.ts b/app/port/UserRoleManager.ts index cdb9fc42..073904e0 100644 --- a/app/port/UserRoleManager.ts +++ b/app/port/UserRoleManager.ts @@ -6,13 +6,14 @@ import { } from '@eggjs/tegg'; import { EggAppConfig, EggLogger } from 'egg'; import { UnauthorizedError, ForbiddenError } from 'egg-errors'; -import { PackageRepository } from '../repository/PackageRepository'; -import { Package as PackageEntity } from '../core/entity/Package'; -import { User as UserEntity } from '../core/entity/User'; -import { Token as TokenEntity } from '../core/entity/Token'; -import { getScopeAndName } from '../common/PackageUtil'; -import { RegistryManagerService } from '../core/service/RegistryManagerService'; -import { TokenService } from '../core/service/TokenService'; + +import { PackageRepository } from '../repository/PackageRepository.js'; +import { Package as PackageEntity } from '../core/entity/Package.js'; +import { User as UserEntity } from '../core/entity/User.js'; +import { Token as TokenEntity } from '../core/entity/Token.js'; +import { getScopeAndName } from '../common/PackageUtil.js'; +import { RegistryManagerService } from '../core/service/RegistryManagerService.js'; +import { TokenService } from '../core/service/TokenService.js'; // https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-tokens-on-the-website export type TokenRole = 'read' | 'publish' | 'setting'; diff --git a/app/port/config.ts b/app/port/config.ts index 582d70e1..0b82ffbe 100644 --- a/app/port/config.ts +++ b/app/port/config.ts @@ -1,7 +1,7 @@ -import { SyncDeleteMode, SyncMode, ChangesStreamMode } from '../common/constants'; -import { DATABASE_TYPE } from '../../config/database'; +import { SyncDeleteMode, SyncMode, ChangesStreamMode } from '../common/constants.js'; +import { DATABASE_TYPE } from '../../config/database.js'; -export { cnpmcoreConfig } from '../../config/config.default'; +export { cnpmcoreConfig } from '../../config/config.default.js'; export type CnpmcoreConfig = { name: string, diff --git a/app/port/controller/AbstractController.ts b/app/port/controller/AbstractController.ts index 30c41f2e..4b2205d9 100644 --- a/app/port/controller/AbstractController.ts +++ b/app/port/controller/AbstractController.ts @@ -10,18 +10,19 @@ import { EggLogger, EggAppConfig, } from 'egg'; -import { MiddlewareController } from '../middleware'; -import { UserRoleManager } from '../UserRoleManager'; -import { PackageRepository } from '../../repository/PackageRepository'; -import { UserRepository } from '../../repository/UserRepository'; -import { getFullname, getScopeAndName } from '../../common/PackageUtil'; -import { Package as PackageEntity } from '../../core/entity/Package'; -import { PackageVersion as PackageVersionEntity } from '../../core/entity/PackageVersion'; -import { UserService } from '../../core/service/UserService'; + +import { MiddlewareController } from '../middleware/index.js'; +import { UserRoleManager } from '../UserRoleManager.js'; +import { PackageRepository } from '../../repository/PackageRepository.js'; +import { UserRepository } from '../../repository/UserRepository.js'; +import { getFullname, getScopeAndName } from '../../common/PackageUtil.js'; +import { Package as PackageEntity } from '../../core/entity/Package.js'; +import { PackageVersion as PackageVersionEntity } from '../../core/entity/PackageVersion.js'; +import { UserService } from '../../core/service/UserService.js'; import { VersionRule, -} from '../typebox'; -import { SyncMode } from '../../common/constants'; +} from '../typebox.js'; +import { SyncMode } from '../../common/constants.js'; class PackageNotFoundError extends NotFoundError { redirectToSourceRegistry?: string; diff --git a/app/port/controller/AccessController.ts b/app/port/controller/AccessController.ts index d9de7648..b6b5da6a 100644 --- a/app/port/controller/AccessController.ts +++ b/app/port/controller/AccessController.ts @@ -4,11 +4,12 @@ import { HTTPMethodEnum, HTTPParam, } from '@eggjs/tegg'; -import { AbstractController } from './AbstractController'; -import { FULLNAME_REG_STRING, getFullname, getScopeAndName } from '../../common/PackageUtil'; -import { PackageAccessLevel } from '../../common/constants'; import { ForbiddenError, NotFoundError } from 'egg-errors'; +import { AbstractController } from './AbstractController.js'; +import { FULLNAME_REG_STRING, getFullname, getScopeAndName } from '../../common/PackageUtil.js'; +import { PackageAccessLevel } from '../../common/constants.js'; + @HTTPController() export class AccessController extends AbstractController { @HTTPMethod({ diff --git a/app/port/controller/BinarySyncController.ts b/app/port/controller/BinarySyncController.ts index 3e3dffda..54f576cb 100644 --- a/app/port/controller/BinarySyncController.ts +++ b/app/port/controller/BinarySyncController.ts @@ -9,11 +9,12 @@ import { } from '@eggjs/tegg'; import path from 'node:path'; import { NotFoundError } from 'egg-errors'; -import { AbstractController } from './AbstractController'; -import { BinarySyncerService } from '../../core/service/BinarySyncerService'; -import { Binary } from '../../core/entity/Binary'; -import binaries, { BinaryName } from '../../../config/binaries'; -import { BinaryNameRule, BinarySubpathRule } from '../typebox'; + +import { AbstractController } from './AbstractController.js'; +import { BinarySyncerService } from '../../core/service/BinarySyncerService.js'; +import { Binary } from '../../core/entity/Binary.js'; +import binaries, { BinaryName } from '../../../config/binaries.js'; +import { BinaryNameRule, BinarySubpathRule } from '../typebox.js'; @HTTPController() export class BinarySyncController extends AbstractController { @@ -48,7 +49,7 @@ export class BinarySyncController extends AbstractController { } @HTTPMethod({ - path: '/-/binary/:binaryName(@[^/]{1,220}\/[^/]{1,220}|[^@/]{1,220})/:subpath(.*)', + path: '/-/binary/:binaryName(@[^/]{1,220}/[^/]{1,220}|[^@/]{1,220})/:subpath(.*)', method: HTTPMethodEnum.GET, }) async showBinary(@Context() ctx: EggContext, @HTTPParam() binaryName: BinaryName, @HTTPParam() subpath: string) { @@ -106,14 +107,14 @@ export class BinarySyncController extends AbstractController { } @HTTPMethod({ - path: '/-/binary/:binaryName(@[^/]{1,220}\/[^/]{1,220}|[^@/]{1,220})', + path: '/-/binary/:binaryName(@[^/]{1,220}/[^/]{1,220}|[^@/]{1,220})', method: HTTPMethodEnum.GET, }) async showBinaryIndex(@Context() ctx: EggContext, @HTTPParam() binaryName: BinaryName) { // check binaryName valid try { ctx.tValidate(BinaryNameRule, binaryName); - } catch (e) { + } catch { throw new NotFoundError(`Binary "${binaryName}" not found`); } return await this.showBinary(ctx, binaryName, '/'); diff --git a/app/port/controller/ChangesStreamController.ts b/app/port/controller/ChangesStreamController.ts index 14604f05..e4729992 100644 --- a/app/port/controller/ChangesStreamController.ts +++ b/app/port/controller/ChangesStreamController.ts @@ -7,9 +7,10 @@ import { Context, EggContext, } from '@eggjs/tegg'; -import { Type } from 'egg-typebox-validate-fengmk2/typebox'; -import { AbstractController } from './AbstractController'; -import { ChangeRepository } from '../../repository/ChangeRepository'; +import { Type } from 'egg-typebox-validate/typebox'; + +import { AbstractController } from './AbstractController.js'; +import { ChangeRepository } from '../../repository/ChangeRepository.js'; const ChangeRule = Type.Object({ since: Type.Integer({ minimum: 0 }), diff --git a/app/port/controller/DownloadController.ts b/app/port/controller/DownloadController.ts index 33a615a8..f00c8c1c 100644 --- a/app/port/controller/DownloadController.ts +++ b/app/port/controller/DownloadController.ts @@ -6,10 +6,11 @@ import { Inject, } from '@eggjs/tegg'; import { UnprocessableEntityError, NotFoundError } from 'egg-errors'; -import { AbstractController } from './AbstractController'; -import { FULLNAME_REG_STRING, getScopeAndName } from '../../common/PackageUtil'; -import dayjs from '../../common/dayjs'; -import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository'; + +import { AbstractController } from './AbstractController.js'; +import { FULLNAME_REG_STRING, getScopeAndName } from '../../common/PackageUtil.js'; +import dayjs from '../../common/dayjs.js'; +import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository.js'; const DATE_FORMAT = 'YYYY-MM-DD'; @@ -90,7 +91,7 @@ export class DownloadController extends AbstractController { } private checkAndGetRange(range: string) { - const matchs = /^(\d{4}\-\d{2}\-\d{2}):(\d{4}\-\d{2}\-\d{2})$/.exec(range); + const matchs = /^(\d{4}-\d{2}-\d{2}):(\d{4}-\d{2}-\d{2})$/.exec(range); if (!matchs) { throw new UnprocessableEntityError(`range(${range}) format invalid, must be "${DATE_FORMAT}:${DATE_FORMAT}" style`); } diff --git a/app/port/controller/HomeController.ts b/app/port/controller/HomeController.ts index 38d9e1b7..820378b3 100644 --- a/app/port/controller/HomeController.ts +++ b/app/port/controller/HomeController.ts @@ -7,11 +7,13 @@ import { EggContext, Inject, } from '@eggjs/tegg'; -import { version as EggVersion } from 'egg/package.json'; -import { AbstractController } from './AbstractController'; -import { CacheService, DownloadInfo, UpstreamRegistryInfo } from '../../core/service/CacheService'; -import { HomeService } from '../../core/service/HomeService'; +import pkg from 'egg/package.json' with { type: 'json' }; +import { AbstractController } from './AbstractController.js'; +import { CacheService, DownloadInfo, UpstreamRegistryInfo } from '../../core/service/CacheService.js'; +import { HomeService } from '../../core/service/HomeService.js'; + +const EggVersion = pkg.version; const startTime = new Date(); // registry 站点信息数据 SiteTotalData diff --git a/app/port/controller/HookController.ts b/app/port/controller/HookController.ts index f3cf8a0c..fa6a85bf 100644 --- a/app/port/controller/HookController.ts +++ b/app/port/controller/HookController.ts @@ -8,13 +8,14 @@ import { HTTPParam, Inject, } from '@eggjs/tegg'; -import { HookManageService } from '../../core/service/HookManageService'; -import { TaskService } from '../../core/service/TaskService'; -import { UserRoleManager } from '../UserRoleManager'; -import { HookType } from '../../common/enum/Hook'; -import { TriggerHookTask } from '../../core/entity/Task'; -import { HookConvertor } from './convertor/HookConvertor'; -import { CreateHookRequestRule, UpdateHookRequestRule } from '../typebox'; + +import { HookManageService } from '../../core/service/HookManageService.js'; +import { TaskService } from '../../core/service/TaskService.js'; +import { UserRoleManager } from '../UserRoleManager.js'; +import { HookType } from '../../common/enum/Hook.js'; +import { TriggerHookTask } from '../../core/entity/Task.js'; +import { HookConvertor } from './convertor/HookConvertor.js'; +import { CreateHookRequestRule, UpdateHookRequestRule } from '../typebox.js'; export interface CreateHookRequest { type: string; diff --git a/app/port/controller/PackageBlockController.ts b/app/port/controller/PackageBlockController.ts index 2f9e989c..58989b0e 100644 --- a/app/port/controller/PackageBlockController.ts +++ b/app/port/controller/PackageBlockController.ts @@ -10,12 +10,13 @@ import { Middleware, } from '@eggjs/tegg'; import { ForbiddenError } from 'egg-errors'; -import { AbstractController } from './AbstractController'; -import { FULLNAME_REG_STRING } from '../../common/PackageUtil'; -import { PackageManagerService } from '../../core/service/PackageManagerService'; -import { PackageVersionBlockRepository } from '../../repository/PackageVersionBlockRepository'; -import { BlockPackageRule, BlockPackageType } from '../typebox'; -import { AdminAccess } from '../middleware/AdminAccess'; + +import { AbstractController } from './AbstractController.js'; +import { FULLNAME_REG_STRING } from '../../common/PackageUtil.js'; +import { PackageManagerService } from '../../core/service/PackageManagerService.js'; +import { PackageVersionBlockRepository } from '../../repository/PackageVersionBlockRepository.js'; +import { BlockPackageRule, BlockPackageType } from '../typebox.js'; +import { AdminAccess } from '../middleware/AdminAccess.js'; @HTTPController() export class PackageBlockController extends AbstractController { @@ -35,7 +36,7 @@ export class PackageBlockController extends AbstractController { ctx.tValidate(BlockPackageRule, params); const packageEntity = await this.getPackageEntityByFullname(params.fullname); if (packageEntity.isPrivate) { - throw new ForbiddenError(`Can\'t block private package "${params.fullname}"`); + throw new ForbiddenError(`Can't block private package "${params.fullname}"`); } const authorized = await this.userRoleManager.getAuthorizedUserAndToken(ctx); @@ -60,7 +61,7 @@ export class PackageBlockController extends AbstractController { async unblockPackage(@Context() ctx: EggContext, @HTTPParam() fullname: string) { const packageEntity = await this.getPackageEntityByFullname(fullname); if (packageEntity.isPrivate) { - throw new ForbiddenError(`Can\'t unblock private package "${fullname}"`); + throw new ForbiddenError(`Can't unblock private package "${fullname}"`); } await this.packageManagerService.unblockPackage(packageEntity); diff --git a/app/port/controller/PackageSyncController.ts b/app/port/controller/PackageSyncController.ts index 5adc2021..872a4816 100644 --- a/app/port/controller/PackageSyncController.ts +++ b/app/port/controller/PackageSyncController.ts @@ -11,14 +11,15 @@ import { BackgroundTaskHelper, } from '@eggjs/tegg'; import { ForbiddenError, NotFoundError } from 'egg-errors'; -import { AbstractController } from './AbstractController'; -import { FULLNAME_REG_STRING, getScopeAndName } from '../../common/PackageUtil'; -import { Task } from '../../core/entity/Task'; -import { PackageSyncerService } from '../../core/service/PackageSyncerService'; -import { RegistryManagerService } from '../../core/service/RegistryManagerService'; -import { TaskState } from '../../common/enum/Task'; -import { SyncPackageTaskRule, SyncPackageTaskType } from '../typebox'; -import { SyncMode } from '../../common/constants'; + +import { AbstractController } from './AbstractController.js'; +import { FULLNAME_REG_STRING, getScopeAndName } from '../../common/PackageUtil.js'; +import { Task } from '../../core/entity/Task.js'; +import { PackageSyncerService } from '../../core/service/PackageSyncerService.js'; +import { RegistryManagerService } from '../../core/service/RegistryManagerService.js'; +import { TaskState } from '../../common/enum/Task.js'; +import { SyncPackageTaskRule, SyncPackageTaskType } from '../typebox.js'; +import { SyncMode } from '../../common/constants.js'; @HTTPController() export class PackageSyncController extends AbstractController { @@ -81,10 +82,10 @@ export class PackageSyncController extends AbstractController { const registry = await this.registryManagerService.findByRegistryName(data?.registryName); if (!registry && data.registryName) { - throw new ForbiddenError(`Can\'t find target registry "${data.registryName}"`); + throw new ForbiddenError(`Can't find target registry "${data.registryName}"`); } if (packageEntity?.isPrivate && !registry) { - throw new ForbiddenError(`Can\'t sync private package "${params.fullname}"`); + throw new ForbiddenError(`Can't sync private package "${params.fullname}"`); } if (params.syncDownloadData && !this.packageSyncerService.allowSyncDownloadData) { throw new ForbiddenError('Not allow to sync package download data'); diff --git a/app/port/controller/PackageTagController.ts b/app/port/controller/PackageTagController.ts index a099310f..e30746a0 100644 --- a/app/port/controller/PackageTagController.ts +++ b/app/port/controller/PackageTagController.ts @@ -9,10 +9,11 @@ import { Inject, } from '@eggjs/tegg'; import { ForbiddenError } from 'egg-errors'; -import { AbstractController } from './AbstractController'; -import { FULLNAME_REG_STRING } from '../../common/PackageUtil'; -import { PackageManagerService } from '../../core/service/PackageManagerService'; -import { TagRule, TagWithVersionRule } from '../typebox'; + +import { AbstractController } from './AbstractController.js'; +import { FULLNAME_REG_STRING } from '../../common/PackageUtil.js'; +import { PackageManagerService } from '../../core/service/PackageManagerService.js'; +import { TagRule, TagWithVersionRule } from '../typebox.js'; @HTTPController() export class PackageTagController extends AbstractController { diff --git a/app/port/controller/PackageVersionFileController.ts b/app/port/controller/PackageVersionFileController.ts index d68db1ed..d69be553 100644 --- a/app/port/controller/PackageVersionFileController.ts +++ b/app/port/controller/PackageVersionFileController.ts @@ -1,3 +1,4 @@ +import { join } from 'node:path'; import { HTTPController, HTTPMethod, @@ -10,16 +11,16 @@ import { Middleware, } from '@eggjs/tegg'; import { NotFoundError } from 'egg-errors'; -import { join } from 'node:path'; -import { AbstractController } from './AbstractController'; -import { AdminAccess } from '../middleware/AdminAccess'; -import { getScopeAndName, FULLNAME_REG_STRING } from '../../common/PackageUtil'; -import { PackageVersionFileService } from '../../core/service/PackageVersionFileService'; -import { PackageManagerService } from '../../core/service/PackageManagerService'; -import { PackageVersionFile } from '../../core/entity/PackageVersionFile'; -import { PackageVersion } from '../../core/entity/PackageVersion'; -import { DistRepository } from '../../repository/DistRepository'; -import { Spec } from '../typebox'; + +import { AbstractController } from './AbstractController.js'; +import { AdminAccess } from '../middleware/AdminAccess.js'; +import { getScopeAndName, FULLNAME_REG_STRING } from '../../common/PackageUtil.js'; +import { PackageVersionFileService } from '../../core/service/PackageVersionFileService.js'; +import { PackageManagerService } from '../../core/service/PackageManagerService.js'; +import { PackageVersionFile } from '../../core/entity/PackageVersionFile.js'; +import { PackageVersion } from '../../core/entity/PackageVersion.js'; +import { DistRepository } from '../../repository/DistRepository.js'; +import { Spec } from '../typebox.js'; type FileItem = { path: string, diff --git a/app/port/controller/ProxyCacheController.ts b/app/port/controller/ProxyCacheController.ts index 962e6a09..c9330d4c 100644 --- a/app/port/controller/ProxyCacheController.ts +++ b/app/port/controller/ProxyCacheController.ts @@ -9,17 +9,18 @@ import { EggContext, } from '@eggjs/tegg'; import { ForbiddenError, NotFoundError, UnauthorizedError, NotImplementedError } from 'egg-errors'; -import { AbstractController } from './AbstractController'; -import { ProxyCacheRepository } from '../../repository/ProxyCacheRepository'; -import { Static } from 'egg-typebox-validate-fengmk2/typebox'; -import { QueryPageOptions } from '../typebox'; -import { FULLNAME_REG_STRING } from '../../common/PackageUtil'; + +import { AbstractController } from './AbstractController.js'; +import { ProxyCacheRepository } from '../../repository/ProxyCacheRepository.js'; +import { Static } from 'egg-typebox-validate/typebox'; +import { QueryPageOptions } from '../typebox.js'; +import { FULLNAME_REG_STRING } from '../../common/PackageUtil.js'; import { ProxyCacheService, - isPkgManifest, -} from '../../core/service/ProxyCacheService'; -import { SyncMode } from '../../common/constants'; -import { CacheService } from '../../core/service/CacheService'; +} from '../../core/service/ProxyCacheService.js'; +import { SyncMode } from '../../common/constants.js'; +import { CacheService } from '../../core/service/CacheService.js'; +import { isPkgManifest } from '../../core/entity/Package.js'; @HTTPController() export class ProxyCacheController extends AbstractController { diff --git a/app/port/controller/RegistryController.ts b/app/port/controller/RegistryController.ts index 2222beb1..630321d6 100644 --- a/app/port/controller/RegistryController.ts +++ b/app/port/controller/RegistryController.ts @@ -11,12 +11,13 @@ import { Middleware, } from '@eggjs/tegg'; import { NotFoundError } from 'egg-errors'; -import { AbstractController } from './AbstractController'; -import { Static } from 'egg-typebox-validate-fengmk2/typebox'; -import { RegistryManagerService, UpdateRegistryCmd } from '../../core/service/RegistryManagerService'; -import { AdminAccess } from '../middleware/AdminAccess'; -import { ScopeManagerService } from '../../core/service/ScopeManagerService'; -import { RegistryCreateOptions, QueryPageOptions, RegistryCreateSyncOptions, RegistryUpdateOptions } from '../typebox'; +import { Static } from 'egg-typebox-validate/typebox'; + +import { AbstractController } from './AbstractController.js'; +import { RegistryManagerService, UpdateRegistryCmd } from '../../core/service/RegistryManagerService.js'; +import { AdminAccess } from '../middleware/AdminAccess.js'; +import { ScopeManagerService } from '../../core/service/ScopeManagerService.js'; +import { RegistryCreateOptions, QueryPageOptions, RegistryCreateSyncOptions, RegistryUpdateOptions } from '../typebox.js'; @HTTPController() export class RegistryController extends AbstractController { diff --git a/app/port/controller/ScopeController.ts b/app/port/controller/ScopeController.ts index 61b68fcf..316c7547 100644 --- a/app/port/controller/ScopeController.ts +++ b/app/port/controller/ScopeController.ts @@ -10,12 +10,13 @@ import { Middleware, } from '@eggjs/tegg'; import { E400 } from 'egg-errors'; -import { AbstractController } from './AbstractController'; -import { Static } from 'egg-typebox-validate-fengmk2/typebox'; -import { AdminAccess } from '../middleware/AdminAccess'; -import { ScopeManagerService } from '../../core/service/ScopeManagerService'; -import { RegistryManagerService } from '../../core/service/RegistryManagerService'; -import { ScopeCreateOptions } from '../typebox'; +import { Static } from 'egg-typebox-validate/typebox'; + +import { AbstractController } from './AbstractController.js'; +import { AdminAccess } from '../middleware/AdminAccess.js'; +import { ScopeManagerService } from '../../core/service/ScopeManagerService.js'; +import { RegistryManagerService } from '../../core/service/RegistryManagerService.js'; +import { ScopeCreateOptions } from '../typebox.js'; @HTTPController() diff --git a/app/port/controller/TokenController.ts b/app/port/controller/TokenController.ts index fd25250e..f6a0394d 100644 --- a/app/port/controller/TokenController.ts +++ b/app/port/controller/TokenController.ts @@ -1,5 +1,4 @@ import { ForbiddenError, UnauthorizedError } from 'egg-errors'; -import { AuthAdapter } from '../../infra/AuthAdapter'; import { HTTPController, HTTPMethod, @@ -10,9 +9,11 @@ import { EggContext, Inject, } from '@eggjs/tegg'; -import { Static, Type } from 'egg-typebox-validate-fengmk2/typebox'; -import { AbstractController } from './AbstractController'; -import { TokenType, isGranularToken } from '../../core/entity/Token'; +import { Static, Type } from 'egg-typebox-validate/typebox'; + +import { AuthAdapter } from '../../infra/AuthAdapter.js'; +import { AbstractController } from './AbstractController.js'; +import { TokenType, isGranularToken } from '../../core/entity/Token.js'; // Creating and viewing access tokens // https://docs.npmjs.com/creating-and-viewing-access-tokens#viewing-access-tokens diff --git a/app/port/controller/UserController.ts b/app/port/controller/UserController.ts index 7e12938c..bdf48ac0 100644 --- a/app/port/controller/UserController.ts +++ b/app/port/controller/UserController.ts @@ -13,11 +13,12 @@ import { UnauthorizedError, ForbiddenError, } from 'egg-errors'; -import { Static, Type } from 'egg-typebox-validate-fengmk2/typebox'; -import { AbstractController } from './AbstractController'; -import { LoginResultCode } from '../../common/enum/User'; -import { sha512 } from '../../common/UserUtil'; -import { isGranularToken } from '../../core/entity/Token'; +import { Static, Type } from 'egg-typebox-validate/typebox'; + +import { AbstractController } from './AbstractController.js'; +import { LoginResultCode } from '../../common/enum/User.js'; +import { sha512 } from '../../common/UserUtil.js'; +import { isGranularToken } from '../../core/entity/Token.js'; // body: { // _id: 'org.couchdb.user:dddd', diff --git a/app/port/controller/admin/PaddingVersionController.ts b/app/port/controller/admin/PaddingVersionController.ts index b768c61c..cfcf304f 100644 --- a/app/port/controller/admin/PaddingVersionController.ts +++ b/app/port/controller/admin/PaddingVersionController.ts @@ -5,8 +5,9 @@ import { Inject, HTTPQuery, Context, EggContext, } from '@eggjs/tegg'; -import { AbstractController } from '../AbstractController'; -import { FixNoPaddingVersionService } from '../../../core/service/FixNoPaddingVersionService'; + +import { AbstractController } from '../AbstractController.js'; +import { FixNoPaddingVersionService } from '../../../core/service/FixNoPaddingVersionService.js'; @HTTPController() export class PaddingVersionController extends AbstractController { diff --git a/app/port/controller/convertor/HookConvertor.ts b/app/port/controller/convertor/HookConvertor.ts index c37fdb31..bb43ddfb 100644 --- a/app/port/controller/convertor/HookConvertor.ts +++ b/app/port/controller/convertor/HookConvertor.ts @@ -1,7 +1,7 @@ -import { Hook } from '../../../core/entity/Hook'; -import { TriggerHookTask } from '../../../core/entity/Task'; -import { User } from '../../../core/entity/User'; -import { HookType } from '../../../common/enum/Hook'; +import { Hook } from '../../../core/entity/Hook.js'; +import { TriggerHookTask } from '../../../core/entity/Task.js'; +import { User } from '../../../core/entity/User.js'; +import { HookType } from '../../../common/enum/Hook.js'; export interface HookVo { id: string; diff --git a/app/port/controller/package/DownloadPackageVersionTar.ts b/app/port/controller/package/DownloadPackageVersionTar.ts index 9117d940..eb115723 100644 --- a/app/port/controller/package/DownloadPackageVersionTar.ts +++ b/app/port/controller/package/DownloadPackageVersionTar.ts @@ -11,14 +11,15 @@ import { Context, EggContext, } from '@eggjs/tegg'; -import { AbstractController } from '../AbstractController'; -import { FULLNAME_REG_STRING, getScopeAndName } from '../../../common/PackageUtil'; -import { SyncMode } from '../../../common/constants'; -import { NFSAdapter } from '../../../common/adapter/NFSAdapter'; -import { PackageManagerService } from '../../../core/service/PackageManagerService'; -import { ProxyCacheService } from '../../../core/service/ProxyCacheService'; -import { PackageSyncerService } from '../../../core/service/PackageSyncerService'; -import { RegistryManagerService } from '../../../core/service/RegistryManagerService'; + +import { AbstractController } from '../AbstractController.js'; +import { FULLNAME_REG_STRING, getScopeAndName } from '../../../common/PackageUtil.js'; +import { SyncMode } from '../../../common/constants.js'; +import { NFSAdapter } from '../../../common/adapter/NFSAdapter.js'; +import { PackageManagerService } from '../../../core/service/PackageManagerService.js'; +import { ProxyCacheService } from '../../../core/service/ProxyCacheService.js'; +import { PackageSyncerService } from '../../../core/service/PackageSyncerService.js'; +import { RegistryManagerService } from '../../../core/service/RegistryManagerService.js'; @HTTPController() export class DownloadPackageVersionTarController extends AbstractController { diff --git a/app/port/controller/package/RemovePackageVersionController.ts b/app/port/controller/package/RemovePackageVersionController.ts index 5b0b09ba..2af9df55 100644 --- a/app/port/controller/package/RemovePackageVersionController.ts +++ b/app/port/controller/package/RemovePackageVersionController.ts @@ -11,11 +11,12 @@ import { Context, EggContext, } from '@eggjs/tegg'; -import { AbstractController } from '../AbstractController'; -import { FULLNAME_REG_STRING } from '../../../common/PackageUtil'; -import { PackageManagerService } from '../../../core/service/PackageManagerService'; -import { Package } from '../../../core/entity/Package'; -import { PackageVersion } from '../../../core/entity/PackageVersion'; + +import { AbstractController } from '../AbstractController.js'; +import { FULLNAME_REG_STRING } from '../../../common/PackageUtil.js'; +import { PackageManagerService } from '../../../core/service/PackageManagerService.js'; +import { Package } from '../../../core/entity/Package.js'; +import { PackageVersion } from '../../../core/entity/PackageVersion.js'; @HTTPController() export class RemovePackageVersionController extends AbstractController { diff --git a/app/port/controller/package/SavePackageVersionController.ts b/app/port/controller/package/SavePackageVersionController.ts index fbafb429..9c3e5b75 100644 --- a/app/port/controller/package/SavePackageVersionController.ts +++ b/app/port/controller/package/SavePackageVersionController.ts @@ -1,5 +1,5 @@ import { PackageJson, Simplify } from 'type-fest'; -import { isEqual } from 'lodash'; +import { isEqual } from 'lodash-es'; import { UnprocessableEntityError, ForbiddenError, @@ -17,20 +17,21 @@ import { } from '@eggjs/tegg'; import * as ssri from 'ssri'; import validateNpmPackageName from 'validate-npm-package-name'; -import { Static, Type } from 'egg-typebox-validate-fengmk2/typebox'; -import { AbstractController } from '../AbstractController'; -import { getScopeAndName, FULLNAME_REG_STRING, extractPackageJSON } from '../../../common/PackageUtil'; -import { PackageManagerService } from '../../../core/service/PackageManagerService'; -import { PackageVersion as PackageVersionEntity } from '../../../core/entity/PackageVersion'; +import { Static, Type } from 'egg-typebox-validate/typebox'; + +import { AbstractController } from '../AbstractController.js'; +import { getScopeAndName, FULLNAME_REG_STRING, extractPackageJSON } from '../../../common/PackageUtil.js'; +import { PackageManagerService } from '../../../core/service/PackageManagerService.js'; +import { PackageVersion as PackageVersionEntity } from '../../../core/entity/PackageVersion.js'; import { VersionRule, TagWithVersionRule, Name as NameType, Description as DescriptionType, -} from '../../typebox'; -import { RegistryManagerService } from '../../../core/service/RegistryManagerService'; -import { PackageJSONType } from '../../../repository/PackageRepository'; -import { CacheAdapter } from '../../../common/adapter/CacheAdapter'; +} from '../../typebox.js'; +import { RegistryManagerService } from '../../../core/service/RegistryManagerService.js'; +import { PackageJSONType } from '../../../repository/PackageRepository.js'; +import { CacheAdapter } from '../../../common/adapter/CacheAdapter.js'; const STRICT_CHECK_TARBALL_FIELDS: (keyof PackageJson)[] = [ 'name', 'version', 'scripts', 'dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies', 'license', 'licenses', 'bin' ]; diff --git a/app/port/controller/package/SearchPackageController.ts b/app/port/controller/package/SearchPackageController.ts index 285e0b8f..bee766b0 100644 --- a/app/port/controller/package/SearchPackageController.ts +++ b/app/port/controller/package/SearchPackageController.ts @@ -9,14 +9,14 @@ import { Context, EggContext, } from '@eggjs/tegg'; -import { Static } from 'egg-typebox-validate-fengmk2/typebox'; +import { Static } from 'egg-typebox-validate/typebox'; import { E451 } from 'egg-errors'; -import { AbstractController } from '../AbstractController'; -import { SearchQueryOptions } from '../../typebox'; -import { PackageSearchService } from '../../../core/service/PackageSearchService'; -import { FULLNAME_REG_STRING } from '../../../common/PackageUtil'; -import { AdminAccess } from '../../middleware/AdminAccess'; +import { AbstractController } from '../AbstractController.js'; +import { SearchQueryOptions } from '../../typebox.js'; +import { PackageSearchService } from '../../../core/service/PackageSearchService.js'; +import { FULLNAME_REG_STRING } from '../../../common/PackageUtil.js'; +import { AdminAccess } from '../../middleware/AdminAccess.js'; @HTTPController() export class SearchPackageController extends AbstractController { diff --git a/app/port/controller/package/ShowPackageController.ts b/app/port/controller/package/ShowPackageController.ts index 36738ceb..45f30dd4 100644 --- a/app/port/controller/package/ShowPackageController.ts +++ b/app/port/controller/package/ShowPackageController.ts @@ -7,15 +7,16 @@ import { Context, EggContext, } from '@eggjs/tegg'; -import { AbstractController } from '../AbstractController'; -import { getScopeAndName, FULLNAME_REG_STRING } from '../../../common/PackageUtil'; -import { isSyncWorkerRequest } from '../../../common/SyncUtil'; -import { PackageManagerService } from '../../../core/service/PackageManagerService'; -import { CacheService } from '../../../core/service/CacheService'; -import { ABBREVIATED_META_TYPE, SyncMode } from '../../../common/constants'; -import { ProxyCacheService } from '../../../core/service/ProxyCacheService'; -import { calculateIntegrity } from '../../../common/PackageUtil'; -import { DIST_NAMES } from '../../../core/entity/Package'; + +import { AbstractController } from '../AbstractController.js'; +import { getScopeAndName, FULLNAME_REG_STRING } from '../../../common/PackageUtil.js'; +import { isSyncWorkerRequest } from '../../../common/SyncUtil.js'; +import { PackageManagerService } from '../../../core/service/PackageManagerService.js'; +import { CacheService } from '../../../core/service/CacheService.js'; +import { ABBREVIATED_META_TYPE, SyncMode } from '../../../common/constants.js'; +import { ProxyCacheService } from '../../../core/service/ProxyCacheService.js'; +import { calculateIntegrity } from '../../../common/PackageUtil.js'; +import { DIST_NAMES } from '../../../core/entity/Package.js'; @HTTPController() export class ShowPackageController extends AbstractController { diff --git a/app/port/controller/package/ShowPackageVersionController.ts b/app/port/controller/package/ShowPackageVersionController.ts index 7cf9db16..e86bf0db 100644 --- a/app/port/controller/package/ShowPackageVersionController.ts +++ b/app/port/controller/package/ShowPackageVersionController.ts @@ -7,18 +7,19 @@ import { Context, EggContext, } from '@eggjs/tegg'; -import { AbstractController } from '../AbstractController'; +import { NotFoundError } from 'egg-errors'; + +import { AbstractController } from '../AbstractController.js'; import { getScopeAndName, FULLNAME_REG_STRING, -} from '../../../common/PackageUtil'; -import { isSyncWorkerRequest } from '../../../common/SyncUtil'; -import { PackageManagerService } from '../../../core/service/PackageManagerService'; -import { ProxyCacheService } from '../../../core/service/ProxyCacheService'; -import { Spec } from '../../../port/typebox'; -import { ABBREVIATED_META_TYPE, SyncMode } from '../../../common/constants'; -import { DIST_NAMES } from '../../../core/entity/Package'; -import { NotFoundError } from 'egg-errors'; +} from '../../../common/PackageUtil.js'; +import { isSyncWorkerRequest } from '../../../common/SyncUtil.js'; +import { PackageManagerService } from '../../../core/service/PackageManagerService.js'; +import { ProxyCacheService } from '../../../core/service/ProxyCacheService.js'; +import { Spec } from '../../../port/typebox.js'; +import { ABBREVIATED_META_TYPE, SyncMode } from '../../../common/constants.js'; +import { DIST_NAMES } from '../../../core/entity/Package.js'; @HTTPController() export class ShowPackageVersionController extends AbstractController { diff --git a/app/port/controller/package/UpdatePackageController.ts b/app/port/controller/package/UpdatePackageController.ts index 7ca97dcd..fd05be6c 100644 --- a/app/port/controller/package/UpdatePackageController.ts +++ b/app/port/controller/package/UpdatePackageController.ts @@ -12,11 +12,12 @@ import { Context, EggContext, } from '@eggjs/tegg'; -import { Static, Type } from 'egg-typebox-validate-fengmk2/typebox'; -import { AbstractController } from '../AbstractController'; -import { FULLNAME_REG_STRING } from '../../../common/PackageUtil'; -import { User as UserEntity } from '../../../core/entity/User'; -import { PackageManagerService } from '../../../core/service/PackageManagerService'; +import { Static, Type } from 'egg-typebox-validate/typebox'; + +import { AbstractController } from '../AbstractController.js'; +import { FULLNAME_REG_STRING } from '../../../common/PackageUtil.js'; +import { User as UserEntity } from '../../../core/entity/User.js'; +import { PackageManagerService } from '../../../core/service/PackageManagerService.js'; const MaintainerDataRule = Type.Object({ maintainers: Type.Array(Type.Object({ diff --git a/app/port/middleware/AdminAccess.ts b/app/port/middleware/AdminAccess.ts index ae0e389c..0758da37 100644 --- a/app/port/middleware/AdminAccess.ts +++ b/app/port/middleware/AdminAccess.ts @@ -1,6 +1,7 @@ import { EggContext, Next } from '@eggjs/tegg'; import { ForbiddenError } from 'egg-errors'; -import { UserRoleManager } from '../UserRoleManager'; + +import { UserRoleManager } from '../UserRoleManager.js'; export async function AdminAccess(ctx: EggContext, next: Next) { const userRoleManager = await ctx.getEggObject(UserRoleManager); diff --git a/app/port/middleware/AlwaysAuth.ts b/app/port/middleware/AlwaysAuth.ts index 916d2500..789db016 100644 --- a/app/port/middleware/AlwaysAuth.ts +++ b/app/port/middleware/AlwaysAuth.ts @@ -1,5 +1,6 @@ import { EggContext, Next } from '@eggjs/tegg'; -import { UserRoleManager } from '../UserRoleManager'; + +import { UserRoleManager } from '../UserRoleManager.js'; export async function AlwaysAuth(ctx: EggContext, next: Next) { if (ctx.app.config.cnpmcore.alwaysAuth) { diff --git a/app/port/middleware/ErrorHandler.ts b/app/port/middleware/ErrorHandler.ts index 1dde519b..39364028 100644 --- a/app/port/middleware/ErrorHandler.ts +++ b/app/port/middleware/ErrorHandler.ts @@ -1,5 +1,6 @@ import { EggContext, Next } from '@eggjs/tegg'; -import { PackageSyncerService } from '../../core/service/PackageSyncerService'; + +import { PackageSyncerService } from '../../core/service/PackageSyncerService.js'; const DEFAULT_SERVER_ERROR_STATUS = 500; diff --git a/app/port/middleware/index.ts b/app/port/middleware/index.ts index 00c698ef..2b781c90 100644 --- a/app/port/middleware/index.ts +++ b/app/port/middleware/index.ts @@ -1,7 +1,8 @@ import { Middleware } from '@eggjs/tegg'; -import { AlwaysAuth } from './AlwaysAuth'; -import { ErrorHandler } from './ErrorHandler'; -import { Tracing } from './Tracing'; + +import { AlwaysAuth } from './AlwaysAuth.js'; +import { ErrorHandler } from './ErrorHandler.js'; +import { Tracing } from './Tracing.js'; @Middleware(AlwaysAuth) @Middleware(Tracing) diff --git a/app/port/package.json b/app/port/package.json index c6ebd0f2..e3241fdc 100644 --- a/app/port/package.json +++ b/app/port/package.json @@ -2,5 +2,6 @@ "name": "cnpmcore-port", "eggModule": { "name": "cnpmcorePort" - } + }, + "type": "module" } diff --git a/app/port/schedule/ChangesStreamWorker.ts b/app/port/schedule/ChangesStreamWorker.ts index ebc177c5..ef481084 100644 --- a/app/port/schedule/ChangesStreamWorker.ts +++ b/app/port/schedule/ChangesStreamWorker.ts @@ -1,7 +1,8 @@ import { EggAppConfig, EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { ChangesStreamService } from '../../core/service/ChangesStreamService'; + +import { ChangesStreamService } from '../../core/service/ChangesStreamService.js'; @Schedule({ type: ScheduleType.WORKER, diff --git a/app/port/schedule/CheckProxyCacheUpdateWorker.ts b/app/port/schedule/CheckProxyCacheUpdateWorker.ts index da7b0c72..43ea25cb 100644 --- a/app/port/schedule/CheckProxyCacheUpdateWorker.ts +++ b/app/port/schedule/CheckProxyCacheUpdateWorker.ts @@ -1,9 +1,11 @@ import { EggAppConfig, EggLogger } from 'egg'; import { CronParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { ProxyCacheRepository } from '../../repository/ProxyCacheRepository'; -import { SyncMode } from '../../common/constants'; -import { ProxyCacheService, isPkgManifest } from '../../core/service/ProxyCacheService'; + +import { ProxyCacheRepository } from '../../repository/ProxyCacheRepository.js'; +import { SyncMode } from '../../common/constants.js'; +import { ProxyCacheService } from '../../core/service/ProxyCacheService.js'; +import { isPkgManifest } from '../../core/entity/Package.js'; @Schedule({ type: ScheduleType.WORKER, diff --git a/app/port/schedule/CheckRecentlyUpdatedPackages.ts b/app/port/schedule/CheckRecentlyUpdatedPackages.ts index 3699ceef..134d5a51 100644 --- a/app/port/schedule/CheckRecentlyUpdatedPackages.ts +++ b/app/port/schedule/CheckRecentlyUpdatedPackages.ts @@ -1,10 +1,11 @@ import { EggAppConfig, EggHttpClient, EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { PackageSyncerService } from '../../core/service/PackageSyncerService'; -import { PackageRepository } from '../../repository/PackageRepository'; -import { getScopeAndName } from '../../common/PackageUtil'; -import { SyncMode } from '../../common/constants'; + +import { PackageSyncerService } from '../../core/service/PackageSyncerService.js'; +import { PackageRepository } from '../../repository/PackageRepository.js'; +import { getScopeAndName } from '../../common/PackageUtil.js'; +import { SyncMode } from '../../common/constants.js'; // https://github.com/cnpm/cnpmcore/issues/9 @Schedule({ diff --git a/app/port/schedule/CleanTempDir.ts b/app/port/schedule/CleanTempDir.ts index 63a9bd0b..7cc4e0dd 100644 --- a/app/port/schedule/CleanTempDir.ts +++ b/app/port/schedule/CleanTempDir.ts @@ -1,9 +1,11 @@ +import { rm, access } from 'node:fs/promises'; +import path from 'node:path'; + import { EggAppConfig, EggLogger } from 'egg'; import { CronParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { rm, access } from 'node:fs/promises'; -import path from 'node:path'; -import dayjs from '../../common/dayjs'; + +import dayjs from '../../common/dayjs.js'; @Schedule({ type: ScheduleType.WORKER, @@ -34,8 +36,7 @@ export class CleanTempDir { try { await access(dir); exists = true; - } catch (err) { - // console.log(err); + } catch { exists = false; } this.logger.info('[CleanTempDir.subscribe] dir "%s" exists: %s', dir, exists); diff --git a/app/port/schedule/CreateSyncBinaryTask.ts b/app/port/schedule/CreateSyncBinaryTask.ts index b87c7286..d8b6aafe 100644 --- a/app/port/schedule/CreateSyncBinaryTask.ts +++ b/app/port/schedule/CreateSyncBinaryTask.ts @@ -1,8 +1,9 @@ import { EggAppConfig } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { BinarySyncerService } from '../../core/service/BinarySyncerService'; -import binaries, { BinaryName } from '../../../config/binaries'; + +import { BinarySyncerService } from '../../core/service/BinarySyncerService.js'; +import binaries, { BinaryName } from '../../../config/binaries.js'; @Schedule({ type: ScheduleType.WORKER, diff --git a/app/port/schedule/CreateTriggerHookWorker.ts b/app/port/schedule/CreateTriggerHookWorker.ts index 0f116e8d..29607c63 100644 --- a/app/port/schedule/CreateTriggerHookWorker.ts +++ b/app/port/schedule/CreateTriggerHookWorker.ts @@ -1,10 +1,11 @@ import { EggAppConfig, EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { TaskService } from '../../core/service/TaskService'; -import { TaskType } from '../../common/enum/Task'; -import { CreateHookTask } from '../../core/entity/Task'; -import { CreateHookTriggerService } from '../../core/service/CreateHookTriggerService'; + +import { TaskService } from '../../core/service/TaskService.js'; +import { TaskType } from '../../common/enum/Task.js'; +import { CreateHookTask } from '../../core/entity/Task.js'; +import { CreateHookTriggerService } from '../../core/service/CreateHookTriggerService.js'; let executingCount = 0; diff --git a/app/port/schedule/SavePackageVersionDownloadCounter.ts b/app/port/schedule/SavePackageVersionDownloadCounter.ts index d82e26c6..ca3c66ec 100644 --- a/app/port/schedule/SavePackageVersionDownloadCounter.ts +++ b/app/port/schedule/SavePackageVersionDownloadCounter.ts @@ -1,6 +1,7 @@ import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { PackageManagerService } from '../../core/service/PackageManagerService'; + +import { PackageManagerService } from '../../core/service/PackageManagerService.js'; @Schedule({ type: ScheduleType.WORKER, diff --git a/app/port/schedule/SyncBinaryWorker.ts b/app/port/schedule/SyncBinaryWorker.ts index c757eb34..2d58ff40 100644 --- a/app/port/schedule/SyncBinaryWorker.ts +++ b/app/port/schedule/SyncBinaryWorker.ts @@ -1,8 +1,9 @@ import { EggAppConfig, EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { BinarySyncerService } from '../../core/service/BinarySyncerService'; -import { isTimeoutError } from '../../common/ErrorUtil'; + +import { BinarySyncerService } from '../../core/service/BinarySyncerService.js'; +import { isTimeoutError } from '../../common/ErrorUtil.js'; @Schedule({ type: ScheduleType.ALL, diff --git a/app/port/schedule/SyncPackageWorker.ts b/app/port/schedule/SyncPackageWorker.ts index d8897bae..ee9c1194 100644 --- a/app/port/schedule/SyncPackageWorker.ts +++ b/app/port/schedule/SyncPackageWorker.ts @@ -1,9 +1,9 @@ import { EggAppConfig, EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { PackageSyncerService } from '../../core/service/PackageSyncerService'; -import { SyncMode } from '../../common/constants'; +import { PackageSyncerService } from '../../core/service/PackageSyncerService.js'; +import { SyncMode } from '../../common/constants.js'; let executingCount = 0; diff --git a/app/port/schedule/SyncProxyCacheWorker.ts b/app/port/schedule/SyncProxyCacheWorker.ts index 4185e5ea..d7f8e40c 100644 --- a/app/port/schedule/SyncProxyCacheWorker.ts +++ b/app/port/schedule/SyncProxyCacheWorker.ts @@ -1,9 +1,9 @@ import { EggAppConfig, EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { ProxyCacheService } from '../../core/service/ProxyCacheService'; -import { SyncMode } from '../../common/constants'; +import { ProxyCacheService } from '../../core/service/ProxyCacheService.js'; +import { SyncMode } from '../../common/constants.js'; let executingCount = 0; diff --git a/app/port/schedule/TaskTimeoutHandler.ts b/app/port/schedule/TaskTimeoutHandler.ts index 34b919f0..05bbda6e 100644 --- a/app/port/schedule/TaskTimeoutHandler.ts +++ b/app/port/schedule/TaskTimeoutHandler.ts @@ -1,8 +1,9 @@ import { EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { TaskService } from '../../core/service/TaskService'; -import { CacheAdapter } from '../../common/adapter/CacheAdapter'; + +import { TaskService } from '../../core/service/TaskService.js'; +import { CacheAdapter } from '../../common/adapter/CacheAdapter.js'; @Schedule({ type: ScheduleType.WORKER, diff --git a/app/port/schedule/TriggerHookWorker.ts b/app/port/schedule/TriggerHookWorker.ts index 8b4f2623..8eafea43 100644 --- a/app/port/schedule/TriggerHookWorker.ts +++ b/app/port/schedule/TriggerHookWorker.ts @@ -1,10 +1,11 @@ import { EggAppConfig, EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { HookTriggerService } from '../../core/service/HookTriggerService'; -import { TaskService } from '../../core/service/TaskService'; -import { TaskType } from '../../common/enum/Task'; -import { TriggerHookTask } from '../../core/entity/Task'; + +import { HookTriggerService } from '../../core/service/HookTriggerService.js'; +import { TaskService } from '../../core/service/TaskService.js'; +import { TaskType } from '../../common/enum/Task.js'; +import { TriggerHookTask } from '../../core/entity/Task.js'; let executingCount = 0; @Schedule({ diff --git a/app/port/schedule/UpdateTotalData.ts b/app/port/schedule/UpdateTotalData.ts index 6485cd78..8e48b2cf 100644 --- a/app/port/schedule/UpdateTotalData.ts +++ b/app/port/schedule/UpdateTotalData.ts @@ -1,16 +1,17 @@ import { EggLogger } from 'egg'; import { IntervalParams, Schedule, ScheduleType } from '@eggjs/tegg/schedule'; import { Inject } from '@eggjs/tegg'; -import { ChangesStreamTaskData } from '../../core/entity/Task'; -import { RegistryManagerService } from '../../core/service/RegistryManagerService'; -import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository'; -import { PackageRepository } from '../../repository/PackageRepository'; -import { TaskRepository } from '../../repository/TaskRepository'; -import { ChangeRepository } from '../../repository/ChangeRepository'; -import { CacheService, DownloadInfo, TotalData } from '../../core/service/CacheService'; -import { TaskType } from '../../common/enum/Task'; -import { GLOBAL_WORKER } from '../../common/constants'; -import dayjs from '../../common/dayjs'; + +import { ChangesStreamTaskData } from '../../core/entity/Task.js'; +import { RegistryManagerService } from '../../core/service/RegistryManagerService.js'; +import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository.js'; +import { PackageRepository } from '../../repository/PackageRepository.js'; +import { TaskRepository } from '../../repository/TaskRepository.js'; +import { ChangeRepository } from '../../repository/ChangeRepository.js'; +import { CacheService, DownloadInfo, TotalData } from '../../core/service/CacheService.js'; +import { TaskType } from '../../common/enum/Task.js'; +import { GLOBAL_WORKER } from '../../common/constants.js'; +import dayjs from '../../common/dayjs.js'; @Schedule({ type: ScheduleType.WORKER, diff --git a/app/port/typebox.ts b/app/port/typebox.ts index bf76fa25..e41a7918 100644 --- a/app/port/typebox.ts +++ b/app/port/typebox.ts @@ -1,11 +1,12 @@ -import { Type, Static } from 'egg-typebox-validate-fengmk2/typebox'; -import type { Application } from 'egg'; -import { RegistryType } from '../common/enum/Registry'; +import { Type, Static } from 'egg-typebox-validate/typebox'; import semver from 'semver'; import npa from 'npm-package-arg'; -import { HookType } from '../common/enum/Hook'; -import binaryConfig, { BinaryName } from '../../config/binaries'; -import { uniq } from 'lodash'; +import { uniq } from 'lodash-es'; +import { Ajv } from 'egg-typebox-validate'; + +import { RegistryType } from '../common/enum/Registry.js'; +import { HookType } from '../common/enum/Hook.js'; +import binaryConfig, { BinaryName } from '../../config/binaries.js'; export const Name = Type.String({ transform: [ 'trim' ], @@ -120,7 +121,7 @@ export const CreateHookRequestRule = Type.Object({ // https://github.com/xiekw2010/egg-typebox-validate#%E5%A6%82%E4%BD%95%E5%86%99%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A0%A1%E9%AA%8C%E8%A7%84%E5%88%99 // add custom validate to ajv -export function patchAjv(ajv: Application['ajv']) { +export function patchAjv(ajv: Ajv) { ajv.addFormat('semver-version', { type: 'string', validate: (version: string) => { diff --git a/app/port/webauth/WebauthController.ts b/app/port/webauth/WebauthController.ts index f9c596e3..034a0458 100644 --- a/app/port/webauth/WebauthController.ts +++ b/app/port/webauth/WebauthController.ts @@ -13,7 +13,7 @@ import { EggLogger, EggAppConfig, } from 'egg'; -import { Static, Type } from 'egg-typebox-validate-fengmk2/typebox'; +import { Static, Type } from 'egg-typebox-validate/typebox'; import { ForbiddenError, NotFoundError } from 'egg-errors'; import { createHash } from 'node:crypto'; import base64url from 'base64url'; @@ -26,13 +26,14 @@ import { VerifyAuthenticationResponseOpts, } from '@simplewebauthn/server'; import type { PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/typescript-types'; -import { LoginResultCode, WanStatusCode } from '../../common/enum/User'; -import { CacheAdapter } from '../../common/adapter/CacheAdapter'; -import { UserService } from '../../core/service/UserService'; -import { MiddlewareController } from '../middleware'; -import { AuthAdapter } from '../../infra/AuthAdapter'; -import { genRSAKeys, decryptRSA } from '../../common/CryptoUtil'; -import { getBrowserTypeForWebauthn } from '../../common/UserUtil'; + +import { LoginResultCode, WanStatusCode } from '../../common/enum/User.js'; +import { CacheAdapter } from '../../common/adapter/CacheAdapter.js'; +import { UserService } from '../../core/service/UserService.js'; +import { MiddlewareController } from '../middleware/index.js'; +import { AuthAdapter } from '../../infra/AuthAdapter.js'; +import { genRSAKeys, decryptRSA } from '../../common/CryptoUtil.js'; +import { getBrowserTypeForWebauthn } from '../../common/UserUtil.js'; const LoginRequestRule = Type.Object({ // cli 所在机器的 hostname,最新版本 npm cli 已经不会上报 hostname @@ -157,7 +158,9 @@ export class WebauthController extends MiddlewareController { expectedOrigin, expectedRPID, authenticator: { + // @ts-expect-error type error credentialPublicKey: base64url.toBuffer(credential.publicKey), + // @ts-expect-error type error credentialID: base64url.toBuffer(credential.credentialId), counter: 0, }, @@ -236,7 +239,9 @@ export class WebauthController extends MiddlewareController { const { verified, registrationInfo } = verification; if (verified && registrationInfo) { const { credentialPublicKey, credentialID } = registrationInfo; + // @ts-expect-error type error const base64CredentialPublicKey = base64url.encode(Buffer.from(new Uint8Array(credentialPublicKey))); + // @ts-expect-error type error const base64CredentialID = base64url.encode(Buffer.from(new Uint8Array(credentialID))); this.userService.createWebauthnCredential(user?.userId, { credentialId: base64CredentialID, @@ -278,6 +283,7 @@ export class WebauthController extends MiddlewareController { timeout: 60000, rpID: expectedRPID, allowCredentials: [{ + // @ts-expect-error type error id: base64url.toBuffer(credential.credentialId), type: 'public-key', transports: [ 'internal' ], @@ -290,6 +296,7 @@ export class WebauthController extends MiddlewareController { result.wanCredentialRegiOption = generateRegistrationOptions({ rpName: ctx.app.config.name, rpID: expectedRPID, + // @ts-expect-error type error userID: base64url.encode(Buffer.from(regUserIdBuffer)), userName: name, userDisplayName: name, diff --git a/app/repository/BinaryRepository.ts b/app/repository/BinaryRepository.ts index 3f6752de..f6baba60 100644 --- a/app/repository/BinaryRepository.ts +++ b/app/repository/BinaryRepository.ts @@ -1,8 +1,9 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import type { Binary as BinaryModel } from './model/Binary'; -import { Binary as BinaryEntity } from '../core/entity/Binary'; -import { AbstractRepository } from './AbstractRepository'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import type { Binary as BinaryModel } from './model/Binary.js'; +import { Binary as BinaryEntity } from '../core/entity/Binary.js'; +import { AbstractRepository } from './AbstractRepository.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/ChangeRepository.ts b/app/repository/ChangeRepository.ts index 950ffcf6..dc92abb4 100644 --- a/app/repository/ChangeRepository.ts +++ b/app/repository/ChangeRepository.ts @@ -1,8 +1,9 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import type { Change as ChangeModel } from './model/Change'; -import { Change as ChangeEntity } from '../core/entity/Change'; -import { AbstractRepository } from './AbstractRepository'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import type { Change as ChangeModel } from './model/Change.js'; +import { Change as ChangeEntity } from '../core/entity/Change.js'; +import { AbstractRepository } from './AbstractRepository.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/DistRepository.ts b/app/repository/DistRepository.ts index ca3d12f8..03c476de 100644 --- a/app/repository/DistRepository.ts +++ b/app/repository/DistRepository.ts @@ -1,7 +1,8 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { NFSAdapter } from '../common/adapter/NFSAdapter'; -import { PackageJSONType, PackageRepository } from './PackageRepository'; -import { Dist } from '../core/entity/Dist'; + +import { NFSAdapter } from '../common/adapter/NFSAdapter.js'; +import { PackageJSONType, PackageRepository } from './PackageRepository.js'; +import { Dist } from '../core/entity/Dist.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/HookRepository.ts b/app/repository/HookRepository.ts index 1d6b2453..6afcd82b 100644 --- a/app/repository/HookRepository.ts +++ b/app/repository/HookRepository.ts @@ -1,8 +1,9 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { Hook } from '../core/entity/Hook'; -import type { Hook as HookModel } from './model/Hook'; -import { ModelConvertor } from './util/ModelConvertor'; -import { HookType } from '../common/enum/Hook'; + +import { Hook } from '../core/entity/Hook.js'; +import type { Hook as HookModel } from './model/Hook.js'; +import { ModelConvertor } from './util/ModelConvertor.js'; +import { HookType } from '../common/enum/Hook.js'; export interface UpdateHookCommand { hookId: string; diff --git a/app/repository/PackageRepository.ts b/app/repository/PackageRepository.ts index 71cec497..6c3f3895 100644 --- a/app/repository/PackageRepository.ts +++ b/app/repository/PackageRepository.ts @@ -1,24 +1,25 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { Orm } from '@eggjs/tegg-orm-plugin/lib/SingletonORM'; +import { Orm } from '@eggjs/tegg-orm-plugin'; import { EggAppConfig } from 'egg'; -import { Bone } from 'leoric'; -import { Package as PackageModel } from './model/Package'; -import { Package as PackageEntity } from '../core/entity/Package'; -import { ModelConvertor } from './util/ModelConvertor'; -import { PackageVersion as PackageVersionEntity } from '../core/entity/PackageVersion'; -import { PackageVersion as PackageVersionModel } from './model/PackageVersion'; -import { PackageVersionManifest as PackageVersionManifestEntity } from '../core/entity/PackageVersionManifest'; -import type { PackageVersionManifest as PackageVersionManifestModel } from './model/PackageVersionManifest'; -import type { Dist as DistModel } from './model/Dist'; -import { Dist as DistEntity } from '../core/entity/Dist'; -import { PackageTag as PackageTagEntity } from '../core/entity/PackageTag'; -import type { PackageTag as PackageTagModel } from './model/PackageTag'; -import type { Maintainer as MaintainerModel } from './model/Maintainer'; -import type { User as UserModel } from './model/User'; -import { User as UserEntity } from '../core/entity/User'; -import { AbstractRepository } from './AbstractRepository'; -import { BugVersionPackages } from '../core/entity/BugVersion'; -import { DATABASE_TYPE } from '../../config/database'; + +import { Bone } from './util/leoric.js'; +import { Package as PackageModel } from './model/Package.js'; +import { Package as PackageEntity } from '../core/entity/Package.js'; +import { ModelConvertor } from './util/ModelConvertor.js'; +import { PackageVersion as PackageVersionEntity } from '../core/entity/PackageVersion.js'; +import { PackageVersion as PackageVersionModel } from './model/PackageVersion.js'; +import { PackageVersionManifest as PackageVersionManifestEntity } from '../core/entity/PackageVersionManifest.js'; +import type { PackageVersionManifest as PackageVersionManifestModel } from './model/PackageVersionManifest.js'; +import type { Dist as DistModel } from './model/Dist.js'; +import { Dist as DistEntity } from '../core/entity/Dist.js'; +import { PackageTag as PackageTagEntity } from '../core/entity/PackageTag.js'; +import type { PackageTag as PackageTagModel } from './model/PackageTag.js'; +import type { Maintainer as MaintainerModel } from './model/Maintainer.js'; +import type { User as UserModel } from './model/User.js'; +import { User as UserEntity } from '../core/entity/User.js'; +import { AbstractRepository } from './AbstractRepository.js'; +import { BugVersionPackages } from '../core/entity/BugVersion.js'; +import { DATABASE_TYPE } from '../../config/database.js'; export type PackageManifestType = Pick & { _id: string; diff --git a/app/repository/PackageVersionBlockRepository.ts b/app/repository/PackageVersionBlockRepository.ts index 5359f3e9..e00bf360 100644 --- a/app/repository/PackageVersionBlockRepository.ts +++ b/app/repository/PackageVersionBlockRepository.ts @@ -1,8 +1,9 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import type { PackageVersionBlock as PackageVersionBlockModel } from './model/PackageVersionBlock'; -import { PackageVersionBlock as PackageVersionBlockEntity } from '../core/entity/PackageVersionBlock'; -import { AbstractRepository } from './AbstractRepository'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import type { PackageVersionBlock as PackageVersionBlockModel } from './model/PackageVersionBlock.js'; +import { PackageVersionBlock as PackageVersionBlockEntity } from '../core/entity/PackageVersionBlock.js'; +import { AbstractRepository } from './AbstractRepository.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/PackageVersionDownloadRepository.ts b/app/repository/PackageVersionDownloadRepository.ts index cf13ab6d..38a5b68d 100644 --- a/app/repository/PackageVersionDownloadRepository.ts +++ b/app/repository/PackageVersionDownloadRepository.ts @@ -1,6 +1,7 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { AbstractRepository } from './AbstractRepository'; -import type { PackageVersionDownload as PackageVersionDownloadModel } from './model/PackageVersionDownload'; + +import { AbstractRepository } from './AbstractRepository.js'; +import type { PackageVersionDownload as PackageVersionDownloadModel } from './model/PackageVersionDownload.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/PackageVersionFileRepository.ts b/app/repository/PackageVersionFileRepository.ts index 19077b77..4b6e2875 100644 --- a/app/repository/PackageVersionFileRepository.ts +++ b/app/repository/PackageVersionFileRepository.ts @@ -1,10 +1,11 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import type { PackageVersionFile as PackageVersionFileModel } from './model/PackageVersionFile'; -import type { Dist as DistModel } from './model/Dist'; -import { Dist as DistEntity } from '../core/entity/Dist'; -import { PackageVersionFile as PackageVersionFileEntity } from '../core/entity/PackageVersionFile'; -import { AbstractRepository } from './AbstractRepository'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import type { PackageVersionFile as PackageVersionFileModel } from './model/PackageVersionFile.js'; +import type { Dist as DistModel } from './model/Dist.js'; +import { Dist as DistEntity } from '../core/entity/Dist.js'; +import { PackageVersionFile as PackageVersionFileEntity } from '../core/entity/PackageVersionFile.js'; +import { AbstractRepository } from './AbstractRepository.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/PackageVersionRepository.ts b/app/repository/PackageVersionRepository.ts index 54b2e4fa..3cceaec1 100644 --- a/app/repository/PackageVersionRepository.ts +++ b/app/repository/PackageVersionRepository.ts @@ -1,11 +1,12 @@ import { AccessLevel, Inject, SingletonProto } from '@eggjs/tegg'; -import { PaddingSemVer } from '../core/entity/PaddingSemVer'; -import type { Package as PackageModel } from './model/Package'; -import { PackageVersion } from '../core/entity/PackageVersion'; -import type { PackageTag } from './model/PackageTag'; -import { ModelConvertor } from './util/ModelConvertor'; -import type { PackageVersion as PackageVersionModel } from './model/PackageVersion'; -import { SqlRange } from '../core/entity/SqlRange'; + +import { PaddingSemVer } from '../core/entity/PaddingSemVer.js'; +import type { Package as PackageModel } from './model/Package.js'; +import { PackageVersion } from '../core/entity/PackageVersion.js'; +import type { PackageTag } from './model/PackageTag.js'; +import { ModelConvertor } from './util/ModelConvertor.js'; +import type { PackageVersion as PackageVersionModel } from './model/PackageVersion.js'; +import { SqlRange } from '../core/entity/SqlRange.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/ProxyCacheRepository.ts b/app/repository/ProxyCacheRepository.ts index d1af53c0..2926ab68 100644 --- a/app/repository/ProxyCacheRepository.ts +++ b/app/repository/ProxyCacheRepository.ts @@ -1,10 +1,11 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import type { ProxyCache as ProxyModeCachedFilesModel } from './model/ProxyCache'; -import { ProxyCache as ProxyCacheEntity } from '../core/entity/ProxyCache'; -import { AbstractRepository } from './AbstractRepository'; -import { DIST_NAMES } from '../core/entity/Package'; -import { EntityUtil, PageOptions, PageResult } from '../core/util/EntityUtil'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import type { ProxyCache as ProxyModeCachedFilesModel } from './model/ProxyCache.js'; +import { ProxyCache as ProxyCacheEntity } from '../core/entity/ProxyCache.js'; +import { AbstractRepository } from './AbstractRepository.js'; +import { DIST_NAMES } from '../core/entity/Package.js'; +import { EntityUtil, PageOptions, PageResult } from '../core/util/EntityUtil.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, }) diff --git a/app/repository/RegistryRepository.ts b/app/repository/RegistryRepository.ts index adbf5193..369be306 100644 --- a/app/repository/RegistryRepository.ts +++ b/app/repository/RegistryRepository.ts @@ -1,9 +1,10 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import { Registry, Registry as RegistryEntity } from '../core/entity/Registry'; -import { AbstractRepository } from './AbstractRepository'; -import type { Registry as RegistryModel } from './model/Registry'; -import { EntityUtil, PageOptions, PageResult } from '../core/util/EntityUtil'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import { Registry, Registry as RegistryEntity } from '../core/entity/Registry.js'; +import { AbstractRepository } from './AbstractRepository.js'; +import type { Registry as RegistryModel } from './model/Registry.js'; +import { EntityUtil, PageOptions, PageResult } from '../core/util/EntityUtil.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/ScopeRepository.ts b/app/repository/ScopeRepository.ts index 8e9fbfa4..9b16b540 100644 --- a/app/repository/ScopeRepository.ts +++ b/app/repository/ScopeRepository.ts @@ -1,9 +1,10 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import { AbstractRepository } from './AbstractRepository'; -import { Scope as ScopeModel } from './model/Scope'; -import { Scope } from '../core/entity/Scope'; -import { EntityUtil, PageOptions, PageResult } from '../core/util/EntityUtil'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import { AbstractRepository } from './AbstractRepository.js'; +import { Scope as ScopeModel } from './model/Scope.js'; +import { Scope } from '../core/entity/Scope.js'; +import { EntityUtil, PageOptions, PageResult } from '../core/util/EntityUtil.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/SearchRepository.ts b/app/repository/SearchRepository.ts index 583336fb..537b8a5c 100644 --- a/app/repository/SearchRepository.ts +++ b/app/repository/SearchRepository.ts @@ -1,8 +1,9 @@ import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg'; -import { SearchAdapter } from '../common/typing'; -import { AuthorType, CnpmcorePatchInfo, PackageManifestType } from './PackageRepository'; import { estypes } from '@elastic/elasticsearch'; +import { SearchAdapter } from '../common/typing.js'; +import { AuthorType, CnpmcorePatchInfo, PackageManifestType } from './PackageRepository.js'; + export type SearchJSONPickKey = '_rev' | 'name' | 'description' | 'keywords' | 'license' | 'maintainers' | 'dist-tags' | '_source_registry_name'; export type SearchMappingType = Pick & CnpmcorePatchInfo & { @@ -39,7 +40,7 @@ export class SearchRepository { private readonly searchAdapter: SearchAdapter; - async searchPackage(query): Promise> { + async searchPackage(query: any): Promise> { return await this.searchAdapter.search(query); } diff --git a/app/repository/TaskRepository.ts b/app/repository/TaskRepository.ts index 227947b7..c2c7df8e 100644 --- a/app/repository/TaskRepository.ts +++ b/app/repository/TaskRepository.ts @@ -1,13 +1,14 @@ import { strict as assert } from 'node:assert'; -import { uniq } from 'lodash'; +import { uniq } from 'lodash-es'; import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import { isDuplicateKeyError } from './util/ErrorUtil'; -import type { Task as TaskModel } from './model/Task'; -import type { HistoryTask as HistoryTaskModel } from './model/HistoryTask'; -import { AbstractRepository } from './AbstractRepository'; -import { TaskType, TaskState } from '../../app/common/enum/Task'; -import { Task as TaskEntity, TaskUpdateCondition } from '../core/entity/Task'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import { isDuplicateKeyError } from './util/ErrorUtil.js'; +import type { Task as TaskModel } from './model/Task.js'; +import type { HistoryTask as HistoryTaskModel } from './model/HistoryTask.js'; +import { AbstractRepository } from './AbstractRepository.js'; +import { TaskType, TaskState } from '../../app/common/enum/Task.js'; +import { Task as TaskEntity, TaskUpdateCondition } from '../core/entity/Task.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/UserRepository.ts b/app/repository/UserRepository.ts index 98cfe445..160244fc 100644 --- a/app/repository/UserRepository.ts +++ b/app/repository/UserRepository.ts @@ -1,16 +1,17 @@ import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg'; -import { ModelConvertor } from './util/ModelConvertor'; -import type { User as UserModel } from './model/User'; -import type { Package as PackageModel } from './model/Package'; -import type { Token as TokenModel } from './model/Token'; -import type { WebauthnCredential as WebauthnCredentialModel } from './model/WebauthnCredential'; -import { User as UserEntity } from '../core/entity/User'; -import { Token as TokenEntity, isGranularToken } from '../core/entity/Token'; -import { WebauthnCredential as WebauthnCredentialEntity } from '../core/entity/WebauthnCredential'; -import { AbstractRepository } from './AbstractRepository'; -import { TokenPackage as TokenPackageModel } from './model/TokenPackage'; -import { getFullname, getScopeAndName } from '../common/PackageUtil'; -import { PackageRepository } from './PackageRepository'; + +import { ModelConvertor } from './util/ModelConvertor.js'; +import type { User as UserModel } from './model/User.js'; +import type { Package as PackageModel } from './model/Package.js'; +import type { Token as TokenModel } from './model/Token.js'; +import type { WebauthnCredential as WebauthnCredentialModel } from './model/WebauthnCredential.js'; +import { User as UserEntity } from '../core/entity/User.js'; +import { Token as TokenEntity, isGranularToken } from '../core/entity/Token.js'; +import { WebauthnCredential as WebauthnCredentialEntity } from '../core/entity/WebauthnCredential.js'; +import { AbstractRepository } from './AbstractRepository.js'; +import { TokenPackage as TokenPackageModel } from './model/TokenPackage.js'; +import { getFullname, getScopeAndName } from '../common/PackageUtil.js'; +import { PackageRepository } from './PackageRepository.js'; @SingletonProto({ accessLevel: AccessLevel.PUBLIC, diff --git a/app/repository/model/Binary.ts b/app/repository/model/Binary.ts index b389ac76..b3aac744 100644 --- a/app/repository/model/Binary.ts +++ b/app/repository/model/Binary.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class Binary extends Bone { diff --git a/app/repository/model/Change.ts b/app/repository/model/Change.ts index 61ef8272..84356792 100644 --- a/app/repository/model/Change.ts +++ b/app/repository/model/Change.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class Change extends Bone { diff --git a/app/repository/model/Dist.ts b/app/repository/model/Dist.ts index ea769bbd..0dae5051 100644 --- a/app/repository/model/Dist.ts +++ b/app/repository/model/Dist.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class Dist extends Bone { diff --git a/app/repository/model/HistoryTask.ts b/app/repository/model/HistoryTask.ts index 88fb4561..e8d8c38c 100644 --- a/app/repository/model/HistoryTask.ts +++ b/app/repository/model/HistoryTask.ts @@ -1,6 +1,7 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone, LENGTH_VARIANTS } from 'leoric'; -import { TaskState, TaskType } from '../../common/enum/Task'; + +import { DataTypes, Bone, LENGTH_VARIANTS } from '../util/leoric.js'; +import { TaskState, TaskType } from '../../common/enum/Task.js'; @Model() export class HistoryTask extends Bone { diff --git a/app/repository/model/Hook.ts b/app/repository/model/Hook.ts index 9edefeea..15bdb634 100644 --- a/app/repository/model/Hook.ts +++ b/app/repository/model/Hook.ts @@ -1,6 +1,7 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; -import { HookType } from '../../common/enum/Hook'; + +import { DataTypes, Bone } from '../util/leoric.js'; +import { HookType } from '../../common/enum/Hook.js'; @Model() export class Hook extends Bone { diff --git a/app/repository/model/Maintainer.ts b/app/repository/model/Maintainer.ts index ca1a12b9..0a5842f9 100644 --- a/app/repository/model/Maintainer.ts +++ b/app/repository/model/Maintainer.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class Maintainer extends Bone { diff --git a/app/repository/model/Package.ts b/app/repository/model/Package.ts index 2c8d460d..3f862348 100644 --- a/app/repository/model/Package.ts +++ b/app/repository/model/Package.ts @@ -1,6 +1,7 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; -import { EntityProperty } from '../util/EntityProperty'; + +import { DataTypes, Bone } from '../util/leoric.js'; +import { EntityProperty } from '../util/EntityProperty.js'; @Model() export class Package extends Bone { diff --git a/app/repository/model/PackageDep.ts b/app/repository/model/PackageDep.ts index 5259620b..9db19aa6 100644 --- a/app/repository/model/PackageDep.ts +++ b/app/repository/model/PackageDep.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class PackageDep extends Bone { diff --git a/app/repository/model/PackageTag.ts b/app/repository/model/PackageTag.ts index 91f15b8d..da529b4c 100644 --- a/app/repository/model/PackageTag.ts +++ b/app/repository/model/PackageTag.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class PackageTag extends Bone { diff --git a/app/repository/model/PackageVersion.ts b/app/repository/model/PackageVersion.ts index 1231ab4d..e0ddaf79 100644 --- a/app/repository/model/PackageVersion.ts +++ b/app/repository/model/PackageVersion.ts @@ -1,7 +1,8 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; -import { EntityProperty } from '../util/EntityProperty'; -import { PaddingSemVer } from '../../core/entity/PaddingSemVer'; + +import { DataTypes, Bone } from '../util/leoric.js'; +import { EntityProperty } from '../util/EntityProperty.js'; +import { PaddingSemVer } from '../../core/entity/PaddingSemVer.js'; @Model() export class PackageVersion extends Bone { diff --git a/app/repository/model/PackageVersionBlock.ts b/app/repository/model/PackageVersionBlock.ts index bb1abe43..4c461503 100644 --- a/app/repository/model/PackageVersionBlock.ts +++ b/app/repository/model/PackageVersionBlock.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone, LENGTH_VARIANTS } from 'leoric'; + +import { DataTypes, Bone, LENGTH_VARIANTS } from '../util/leoric.js'; @Model() export class PackageVersionBlock extends Bone { diff --git a/app/repository/model/PackageVersionDownload.ts b/app/repository/model/PackageVersionDownload.ts index d3471b5d..f5f8e57e 100644 --- a/app/repository/model/PackageVersionDownload.ts +++ b/app/repository/model/PackageVersionDownload.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class PackageVersionDownload extends Bone { diff --git a/app/repository/model/PackageVersionFile.ts b/app/repository/model/PackageVersionFile.ts index 4f0b714a..7760cedc 100644 --- a/app/repository/model/PackageVersionFile.ts +++ b/app/repository/model/PackageVersionFile.ts @@ -1,6 +1,7 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; -import { EntityProperty } from '../util/EntityProperty'; + +import { DataTypes, Bone } from '../util/leoric.js'; +import { EntityProperty } from '../util/EntityProperty.js'; @Model() export class PackageVersionFile extends Bone { diff --git a/app/repository/model/PackageVersionManifest.ts b/app/repository/model/PackageVersionManifest.ts index 368da07e..f284cecd 100644 --- a/app/repository/model/PackageVersionManifest.ts +++ b/app/repository/model/PackageVersionManifest.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class PackageVersionManifest extends Bone { diff --git a/app/repository/model/ProxyCache.ts b/app/repository/model/ProxyCache.ts index 8a99e0d1..c62f1985 100644 --- a/app/repository/model/ProxyCache.ts +++ b/app/repository/model/ProxyCache.ts @@ -1,6 +1,7 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; -import { DIST_NAMES } from '../../core/entity/Package'; + +import { DataTypes, Bone } from '../util/leoric.js'; +import { DIST_NAMES } from '../../core/entity/Package.js'; @Model() export class ProxyCache extends Bone { diff --git a/app/repository/model/Registry.ts b/app/repository/model/Registry.ts index 0a151284..0cad3a70 100644 --- a/app/repository/model/Registry.ts +++ b/app/repository/model/Registry.ts @@ -1,6 +1,7 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { RegistryType } from '../../common/enum/Registry'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; +import { RegistryType } from '../../common/enum/Registry.js'; @Model() export class Registry extends Bone { diff --git a/app/repository/model/Scope.ts b/app/repository/model/Scope.ts index b9370597..b6ca61e2 100644 --- a/app/repository/model/Scope.ts +++ b/app/repository/model/Scope.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class Scope extends Bone { diff --git a/app/repository/model/Task.ts b/app/repository/model/Task.ts index 01f2ef7f..bdb91a1c 100644 --- a/app/repository/model/Task.ts +++ b/app/repository/model/Task.ts @@ -1,6 +1,7 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone, LENGTH_VARIANTS } from 'leoric'; -import { TaskState, TaskType } from '../../common/enum/Task'; + +import { DataTypes, Bone, LENGTH_VARIANTS } from '../util/leoric.js'; +import { TaskState, TaskType } from '../../common/enum/Task.js'; @Model() export class Task extends Bone { diff --git a/app/repository/model/Token.ts b/app/repository/model/Token.ts index a9a2ed8a..1fb54d42 100644 --- a/app/repository/model/Token.ts +++ b/app/repository/model/Token.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class Token extends Bone { diff --git a/app/repository/model/TokenPackage.ts b/app/repository/model/TokenPackage.ts index 7f3f34bc..4e1712d4 100644 --- a/app/repository/model/TokenPackage.ts +++ b/app/repository/model/TokenPackage.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class TokenPackage extends Bone { diff --git a/app/repository/model/User.ts b/app/repository/model/User.ts index f6058b82..4c824574 100644 --- a/app/repository/model/User.ts +++ b/app/repository/model/User.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class User extends Bone { diff --git a/app/repository/model/WebauthnCredential.ts b/app/repository/model/WebauthnCredential.ts index fd1648aa..8401f751 100644 --- a/app/repository/model/WebauthnCredential.ts +++ b/app/repository/model/WebauthnCredential.ts @@ -1,5 +1,6 @@ import { Attribute, Model } from '@eggjs/tegg/orm'; -import { DataTypes, Bone } from 'leoric'; + +import { DataTypes, Bone } from '../util/leoric.js'; @Model() export class WebauthnCredential extends Bone { diff --git a/app/repository/package.json b/app/repository/package.json index 8ffe8a5d..c6b05c7e 100644 --- a/app/repository/package.json +++ b/app/repository/package.json @@ -3,7 +3,5 @@ "eggModule": { "name": "cnpmcoreRepository" }, - "devDependencies": { - "@types/lodash": "^4.14.196" - } + "type": "module" } diff --git a/app/repository/util/EntityProperty.ts b/app/repository/util/EntityProperty.ts index ac2f7f76..cda9be03 100644 --- a/app/repository/util/EntityProperty.ts +++ b/app/repository/util/EntityProperty.ts @@ -1,6 +1,7 @@ -import { strict as assert } from 'node:assert'; +import assert from 'node:assert'; import { EggProtoImplClass } from '@eggjs/tegg'; -import { ModelConvertorUtil } from './ModelConvertorUtil'; + +import { ModelConvertorUtil } from './ModelConvertorUtil.js'; export function EntityProperty(entityProperty: string) { return function(target: any, modelProperty: PropertyKey) { diff --git a/app/repository/util/ModelConvertor.ts b/app/repository/util/ModelConvertor.ts index 393d59c6..fdb93653 100644 --- a/app/repository/util/ModelConvertor.ts +++ b/app/repository/util/ModelConvertor.ts @@ -1,15 +1,16 @@ import { ModelMetadataUtil } from '@eggjs/tegg/orm'; -import { Bone } from 'leoric'; import { EggProtoImplClass } from '@eggjs/tegg'; -import _ from 'lodash'; -import { ModelConvertorUtil } from './ModelConvertorUtil'; +import { get as lodashGet, set as lodashSet } from 'lodash-es'; + +import { Bone, type LeoricBone } from './leoric.js'; +import { ModelConvertorUtil } from './ModelConvertorUtil.js'; const CREATED_AT = 'createdAt'; const UPDATED_AT = 'updatedAt'; const ID = 'id'; type BonePatchInfo = { id?: bigint, updatedAt?: Date, createdAt?: Date }; -type PatchedBone = Bone & BonePatchInfo; +type PatchedBone = LeoricBone & BonePatchInfo; export class ModelConvertor { static async convertEntityToModel(entity: object, ModelClazz: EggProtoImplClass, options?: object): Promise { @@ -22,7 +23,7 @@ export class ModelConvertor { const modelPropertyName = attributeMeta.propertyName; const entityPropertyName = ModelConvertorUtil.getEntityPropertyName(ModelClazz, modelPropertyName); if (entityPropertyName === UPDATED_AT || entityPropertyName === CREATED_AT || entityPropertyName === ID) continue; - const attributeValue = _.get(entity, entityPropertyName); + const attributeValue = lodashGet(entity, entityPropertyName); attributes[modelPropertyName] = attributeValue; } const model = await (ModelClazz as unknown as typeof Bone).create(attributes, options) as PatchedBone; @@ -34,7 +35,7 @@ export class ModelConvertor { return model as T; } - static convertEntityToChanges(entity: object, ModelClazz: EggProtoImplClass) { + static convertEntityToChanges(entity: object, ModelClazz: EggProtoImplClass) { const changes: Record = {}; const metadata = ModelMetadataUtil.getModelMetadata(ModelClazz); if (!metadata) { @@ -44,7 +45,7 @@ export class ModelConvertor { const modelPropertyName = attributeMeta.propertyName; const entityPropertyName = ModelConvertorUtil.getEntityPropertyName(ModelClazz, modelPropertyName); if (entityPropertyName === CREATED_AT) continue; - const attributeValue = _.get(entity, entityPropertyName); + const attributeValue = lodashGet(entity, entityPropertyName); changes[modelPropertyName] = attributeValue; } changes[UPDATED_AT] = new Date(); @@ -54,7 +55,7 @@ export class ModelConvertor { // TODO: options is QueryOptions, should let leoric export it to use // Find out which attributes changed and set `updatedAt` to now - static async saveEntityToModel(entity: object, model: T & PatchedBone, options?: object): Promise { + static async saveEntityToModel(entity: object, model: T & PatchedBone, options?: object): Promise { const ModelClazz = model.constructor as EggProtoImplClass; const metadata = ModelMetadataUtil.getModelMetadata(ModelClazz); if (!metadata) { @@ -66,7 +67,7 @@ export class ModelConvertor { if (entityPropertyName === CREATED_AT) continue; // Restricted updates to the primary key if (entityPropertyName === ID && model[ID]) continue; - const attributeValue = _.get(entity, entityPropertyName); + const attributeValue = lodashGet(entity, entityPropertyName); (model as unknown as Record)[modelPropertyName] = attributeValue; } @@ -78,18 +79,18 @@ export class ModelConvertor { return true; } - static convertModelToEntity(bone: Bone, entityClazz: EggProtoImplClass, data?: object): T { + static convertModelToEntity(bone: LeoricBone, entityClazz: EggProtoImplClass, data?: object): T { data = data || {}; - const ModelClazz = bone.constructor; + const ModelClazz = bone.constructor as EggProtoImplClass; const metadata = ModelMetadataUtil.getModelMetadata(ModelClazz); if (!metadata) { throw new Error(`Model ${ModelClazz.name} has no metadata`); } for (const attributeMeta of metadata.attributes) { const modelPropertyName = attributeMeta.propertyName; - const entityPropertyName = ModelConvertorUtil.getEntityPropertyName(ModelClazz as EggProtoImplClass, modelPropertyName); - const attributeValue = bone[attributeMeta.propertyName as keyof Bone]; - _.set(data, entityPropertyName, attributeValue); + const entityPropertyName = ModelConvertorUtil.getEntityPropertyName(ModelClazz, modelPropertyName); + const attributeValue = bone[attributeMeta.propertyName as keyof LeoricBone]; + lodashSet(data, entityPropertyName, attributeValue); } const model = Reflect.construct(entityClazz, [ data ]); return model; diff --git a/app/repository/util/leoric.ts b/app/repository/util/leoric.ts new file mode 100644 index 00000000..a1c9d6db --- /dev/null +++ b/app/repository/util/leoric.ts @@ -0,0 +1,7 @@ +import leoric from 'leoric'; + +const { DataTypes, Bone, LENGTH_VARIANTS } = leoric; + +export { DataTypes, Bone, LENGTH_VARIANTS }; + +export type { Bone as LeoricBone } from 'leoric'; diff --git a/config/binaries.ts b/config/binaries.ts index 06418df2..51178b60 100644 --- a/config/binaries.ts +++ b/config/binaries.ts @@ -1,4 +1,4 @@ -import { BinaryType } from '../app/common/enum/Binary'; +import { BinaryType } from '../app/common/enum/Binary.js'; export type BinaryTaskConfig = { category: CategoryName; // 默认 category 为 binaryName,但是有些 binary 会有不同的 category,比如 canvas,包含 canvas 和 node-canvas-prebuilt 两个 diff --git a/config/config.default.ts b/config/config.default.ts index a2e921cf..ff979a92 100644 --- a/config/config.default.ts +++ b/config/config.default.ts @@ -5,10 +5,11 @@ import { EggAppConfig, PowerPartial, Context } from 'egg'; import OSSClient from 'oss-cnpm'; import S3Client from 's3-cnpmcore'; import { env } from 'read-env-value'; -import { patchAjv } from '../app/port/typebox'; -import { ChangesStreamMode, NOT_IMPLEMENTED_PATH, SyncDeleteMode, SyncMode } from '../app/common/constants'; -import type { CnpmcoreConfig } from '../app/port/config'; -import { database } from './database'; + +import { patchAjv } from '../app/port/typebox.js'; +import { ChangesStreamMode, NOT_IMPLEMENTED_PATH, SyncDeleteMode, SyncMode } from '../app/common/constants.js'; +import type { CnpmcoreConfig } from '../app/port/config.js'; +import { database } from './database.js'; export const cnpmcoreConfig: CnpmcoreConfig = { name: 'cnpm', @@ -163,6 +164,7 @@ export default (appInfo: EggAppConfig): Config => { assert(s3Config.credentials.accessKeyId, 'require env CNPMCORE_NFS_S3_CLIENT_ID'); assert(s3Config.credentials.secretAccessKey, 'require env CNPMCORE_NFS_S3_CLIENT_SECRET'); assert(s3Config.bucket, 'require env CNPMCORE_NFS_S3_CLIENT_BUCKET'); + // @ts-expect-error has no construct signatures config.nfs.client = new S3Client(s3Config); } @@ -228,4 +230,3 @@ export default (appInfo: EggAppConfig): Config => { return config; }; - diff --git a/config/config.unittest.ts b/config/config.unittest.ts index 109f426b..fb3451d0 100644 --- a/config/config.unittest.ts +++ b/config/config.unittest.ts @@ -1,8 +1,10 @@ import { join } from 'node:path'; import { EggAppConfig, PowerPartial } from 'egg'; import Mock from '@elastic/elasticsearch-mock'; -import { database } from './database'; +import { database } from './database.js'; + +// @ts-expect-error has no construct signatures export const mockES = new Mock(); export default (appInfo: EggAppConfig) => { diff --git a/config/plugin.ts b/config/plugin.ts index bc0105de..0d826d7e 100644 --- a/config/plugin.ts +++ b/config/plugin.ts @@ -42,7 +42,7 @@ const plugin: EggPlugin = { }, typeboxValidate: { enable: true, - package: 'egg-typebox-validate-fengmk2', + package: 'egg-typebox-validate', }, redis: { enable: true, diff --git a/package.json b/package.json index 2f48f44d..ff64890b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "files": [ "dist/**/*" ], - "type": "commonjs", + "type": "module", "main": "./dist/app.js", "typings": "./dist/app", "exports": { @@ -39,6 +39,7 @@ "predev": "npm run clean", "dev": "egg-bin dev", "dev:postgresql": "CNPMCORE_DATABASE_TYPE=PostgreSQL egg-bin dev", + "prelint": "oxlint --quiet", "lint": "eslint --cache --ext .ts .", "lint:fix": "eslint --cache --ext .ts --fix .", "test:postgresql": "npm run lint:fix && npm run test:local:postgresql", @@ -84,15 +85,15 @@ "dependencies": { "@eggjs/redis": "^3.0.0", "@eggjs/scripts": "^4.0.0", - "@eggjs/tegg": "^3.12.0", - "@eggjs/tegg-aop-plugin": "^3.12.0", - "@eggjs/tegg-background-task": "^3.29.0", - "@eggjs/tegg-config": "^3.12.0", - "@eggjs/tegg-controller-plugin": "^3.12.0", - "@eggjs/tegg-eventbus-plugin": "^3.12.0", - "@eggjs/tegg-orm-plugin": "^3.12.0", - "@eggjs/tegg-plugin": "^3.12.0", - "@eggjs/tegg-schedule-plugin": "^3.12.0", + "@eggjs/tegg": "4.0.0-beta.2", + "@eggjs/tegg-aop-plugin": "4.0.0-beta.2", + "@eggjs/tegg-background-task": "4.0.0-beta.2", + "@eggjs/tegg-config": "4.0.0-beta.2", + "@eggjs/tegg-controller-plugin": "4.0.0-beta.2", + "@eggjs/tegg-eventbus-plugin": "4.0.0-beta.2", + "@eggjs/tegg-orm-plugin": "4.0.0-beta.2", + "@eggjs/tegg-plugin": "4.0.0-beta.2", + "@eggjs/tegg-schedule-plugin": "4.0.0-beta.2", "@eggjs/tracer": "^3.0.0", "@eggjs/tsconfig": "^1.0.0", "@elastic/elasticsearch": "^8.8.1", @@ -101,20 +102,19 @@ "@simplewebauthn/server": "^7.0.1", "base-x": "^3.0.9", "base64url": "^3.0.1", - "bson-objectid": "^2.0.1", + "bson-objectid": "^2.0.4", "dayjs": "^1.10.7", "egg": "^4.0.8", "egg-cors": "^3.0.0", "egg-errors": "^2.3.0", "egg-status": "^1.0.0", - "egg-typebox-validate": "^2.0.0", - "egg-typebox-validate-fengmk2": "beta", + "egg-typebox-validate": "^3.0.0", "egg-view-nunjucks": "^2.3.0", "eggjs-elasticsearch": "^0.0.6", "fs-cnpm": "^2.4.0", "ioredis": "^5.3.1", "leoric": "^2.12.3", - "lodash": "^4.17.21", + "lodash-es": "^4.17.21", "mime-types": "^2.1.35", "mysql2": "^3.9.4", "node-rsa": "^1.1.1", @@ -138,7 +138,7 @@ "@eggjs/mock": "^6.0.7", "@elastic/elasticsearch-mock": "^2.0.0", "@simplewebauthn/typescript-types": "^7.0.0", - "@types/lodash": "^4.14.196", + "@types/lodash-es": "^4.17.12", "@types/mime-types": "^2.1.1", "@types/mocha": "^10.0.1", "@types/mysql": "^2.15.21", @@ -152,6 +152,7 @@ "coffee": "^5.4.0", "eslint": "^8.29.0", "eslint-config-egg": "^14.0.0", + "oxlint": "^0.15.12", "typescript": "beta" }, "author": "killagu", diff --git a/test/.setup.ts b/test/.setup.ts index 87343279..12987d0b 100644 --- a/test/.setup.ts +++ b/test/.setup.ts @@ -1,5 +1,6 @@ import { mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from './TestUtil'; + +import { TestUtil } from './TestUtil.js'; beforeEach(async () => { // don't show console log on unittest by default diff --git a/test/TestUtil.ts b/test/TestUtil.ts index 2a4aab8f..0c412b80 100644 --- a/test/TestUtil.ts +++ b/test/TestUtil.ts @@ -3,15 +3,22 @@ import fs from 'node:fs/promises'; import coffee from 'coffee'; import { tmpdir } from 'node:os'; import { mkdtempSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; import { Readable } from 'node:stream'; import mysql from 'mysql2'; import pg from 'pg'; import path from 'node:path'; import crypto from 'node:crypto'; -import { cleanUserPrefix, getScopeAndName } from '../app/common/PackageUtil'; import semver from 'semver'; -import { PackageJSONType } from '../app/repository/PackageRepository'; -import { database, DATABASE_TYPE } from '../config/database'; +import { app as globalApp } from '@eggjs/mock/bootstrap'; + +import { cleanUserPrefix, getScopeAndName } from '../app/common/PackageUtil.js'; +import { PackageJSONType } from '../app/repository/PackageRepository.js'; +import { database, DATABASE_TYPE } from '../config/database.js'; +import { Package as PackageModel } from '../app/repository/model/Package.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); type PackageOptions = { name?: string; @@ -40,10 +47,20 @@ type UserOptions = { }; }; +export interface TestUser { + name: string; + displayName: string; + password: string; + email: string; + token: string; + authorization: string; + ua: string; +} + export class TestUtil { - private static connection; - private static tables; - private static _app; + private static connection: any; + private static tables: any; + private static _app: any; private static ua = 'npm/7.0.0 cnpmcore-unittest/1.0.0'; static getDatabaseConfig() { @@ -126,9 +143,7 @@ export class TestUtil { static get app() { if (!this._app) { - /* eslint @typescript-eslint/no-var-requires: "off" */ - const bootstrap = require('@eggjs/mock/bootstrap'); - this._app = bootstrap.app; + this._app = globalApp; } return this._app; } @@ -136,7 +151,7 @@ export class TestUtil { static async rm(filepath: string) { try { await fs.unlink(filepath); - } catch (e) { + } catch { // ignore } } @@ -158,7 +173,7 @@ export class TestUtil { return JSON.parse(bytes.toString()); } - static async getFullPackage(options?: PackageOptions): Promise { + static async getFullPackage(options?: PackageOptions): Promise }> { const fullJSONFile = this.getFixtures('exampleFullPackage.json'); const pkg = JSON.parse((await fs.readFile(fullJSONFile)).toString()); if (options) { @@ -227,13 +242,12 @@ export class TestUtil { if (options?.isPrivate === false) { const [ scope, name ] = getScopeAndName(pkg.name); - const { Package: PackageModel } = require('../app/repository/model/Package'); await PackageModel.update({ scope, name }, { isPrivate: false, registryId: options?.registryId }); } return { user, pkg }; } - static async createUser(user?: UserOptions) { + static async createUser(user?: UserOptions): Promise { if (!user) { user = {}; } @@ -251,7 +265,7 @@ export class TestUtil { email, }) .expect(201); - let token = res.body.token; + let token: string = res.body.token; if (user.tokenOptions) { res = await this.app.httpRequest() .post('/-/npm/v1/tokens') @@ -300,6 +314,7 @@ export class TestUtil { name: adminName, }); } + static async createRegistryAndScope() { // create success const adminUser = await this.createAdmin(); @@ -315,7 +330,7 @@ export class TestUtil { }); } - static async readStreamToLog(urlOrStream) { + static async readStreamToLog(urlOrStream: any) { let stream: Readable; if (typeof urlOrStream === 'string') { const { res } = await this.app.curl(urlOrStream, { streaming: true }); @@ -330,10 +345,10 @@ export class TestUtil { return Buffer.concat(chunks).toString(); } - static pickKeys(obj, keys) { - const d: Record = []; - obj.forEach(item => { - const newItem = {}; + static pickKeys(obj: any, keys: any) { + const d: Record[] = []; + obj.forEach((item: any) => { + const newItem: Record = {}; for (const key of keys) { newItem[key] = item[key]; } diff --git a/test/cli/npm/access.test.ts b/test/cli/npm/access.test.ts index 798f5940..48ca6683 100644 --- a/test/cli/npm/access.test.ts +++ b/test/cli/npm/access.test.ts @@ -2,17 +2,18 @@ import path from 'node:path'; import { app } from '@eggjs/mock/bootstrap'; import coffee from 'coffee'; import semver from 'semver'; -import { TestUtil } from '../../../test/TestUtil'; -import { npmLogin } from '../CliUtil'; + +import { TestUtil } from '../../../test/TestUtil.js'; +import { npmLogin } from '../CliUtil.js'; describe('test/cli/npm/access.test.ts', () => { - let server; - let registry; - let fooPkgDir; - let demoDir; - let userconfig; - let cacheDir; - let useLegacyCommands; + let server: any; + let registry: any; + let fooPkgDir: any; + let demoDir: any; + let userconfig: any; + let cacheDir: any; + let useLegacyCommands: any; before(async () => { cacheDir = TestUtil.mkdtemp(); fooPkgDir = TestUtil.getFixtures('@cnpm/foo'); @@ -71,7 +72,7 @@ describe('test/cli/npm/access.test.ts', () => { cwd: demoDir, }) .debug() - .expect('stdout', /testuser:\sread-write|\"testuser\":\s\"read-write\"/) + .expect('stdout', /testuser:\sread-write|"testuser":\s"read-write"/) .expect('code', 0) .end(); @@ -92,7 +93,7 @@ describe('test/cli/npm/access.test.ts', () => { cwd: demoDir, }) .debug() - .expect('stdout', /@cnpm\/foo: read-write|\"@cnpm\/foo\":\s\"read-write"/) + .expect('stdout', /@cnpm\/foo: read-write|"@cnpm\/foo":\s"read-write"/) .expect('code', 0) .end(); diff --git a/test/cli/npm/install.test.ts b/test/cli/npm/install.test.ts index 7c168f41..89b5ba9a 100644 --- a/test/cli/npm/install.test.ts +++ b/test/cli/npm/install.test.ts @@ -2,16 +2,17 @@ import { strict as assert } from 'node:assert'; import path from 'node:path'; import { app } from '@eggjs/mock/bootstrap'; import coffee from 'coffee'; -import { TestUtil } from '../../../test/TestUtil'; -import { npmLogin } from '../CliUtil'; + +import { TestUtil } from '../../../test/TestUtil.js'; +import { npmLogin } from '../CliUtil.js'; describe('test/cli/npm/install.test.ts', () => { - let server; - let registry; - let fooPkgDir; - let demoDir; - let userconfig; - let cacheDir; + let server: any; + let registry: any; + let fooPkgDir: any; + let demoDir: any; + let userconfig: any; + let cacheDir: any; before(async () => { cacheDir = TestUtil.mkdtemp(); fooPkgDir = TestUtil.getFixtures('@cnpm/foo'); @@ -94,7 +95,7 @@ describe('test/cli/npm/install.test.ts', () => { cwd: demoDir, }) .debug() - .expect('stdout', /\/@cnpm\/foo\/\-\/foo-2.0.0.tgz/) + .expect('stdout', /\/@cnpm\/foo\/-\/foo-2.0.0.tgz/) .expect('code', 0) .end(); @@ -144,7 +145,7 @@ describe('test/cli/npm/install.test.ts', () => { cwd: demoDir, }) .debug() - .expect('stdout', /\- \@cnpm\/foo/) + .expect('stdout', /- @cnpm\/foo/) .expect('code', 0) .end(); await coffee @@ -160,7 +161,7 @@ describe('test/cli/npm/install.test.ts', () => { cwd: demoDir, }) .debug() - .expect('stdout', /\- \@cnpm\/foo/) + .expect('stdout', /- @cnpm\/foo/) .expect('code', 0) .end(); const res = await app.httpclient.request(`${registry}/@cnpm%2ffoo`, { dataType: 'json' }); diff --git a/test/common/CryptoUtil.test.ts b/test/common/CryptoUtil.test.ts index ba5fd076..0e20b0e6 100644 --- a/test/common/CryptoUtil.test.ts +++ b/test/common/CryptoUtil.test.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; -import { genRSAKeys, encryptRSA, decryptRSA } from '../../app/common/CryptoUtil'; + +import { genRSAKeys, encryptRSA, decryptRSA } from '../../app/common/CryptoUtil.js'; describe('test/common/CryptoUtil.test.ts', () => { describe('genRSAKeys()', () => { diff --git a/test/common/FileUtil.test.ts b/test/common/FileUtil.test.ts index ff59dfe6..e037b4c3 100644 --- a/test/common/FileUtil.test.ts +++ b/test/common/FileUtil.test.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; -import { mimeLookup } from '../../app/common/FileUtil'; + +import { mimeLookup } from '../../app/common/FileUtil.js'; describe('test/common/FileUtil.test.ts', () => { describe('mimeLookup()', () => { diff --git a/test/common/PackageUtil.test.ts b/test/common/PackageUtil.test.ts index 6d9b00ab..e56db30f 100644 --- a/test/common/PackageUtil.test.ts +++ b/test/common/PackageUtil.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; -import { formatAuthor, formatTarball, hasShrinkWrapInTgz } from '../../app/common/PackageUtil'; -import { TestUtil } from '../TestUtil'; + +import { formatAuthor, formatTarball, hasShrinkWrapInTgz } from '../../app/common/PackageUtil.js'; +import { TestUtil } from '../TestUtil.js'; describe('test/common/PackageUtil.test.ts', () => { describe('formatTarball()', () => { diff --git a/test/common/UserUtil.test.ts b/test/common/UserUtil.test.ts index d7f69932..bed50e59 100644 --- a/test/common/UserUtil.test.ts +++ b/test/common/UserUtil.test.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; -import { randomToken, checkToken } from '../../app/common/UserUtil'; + +import { randomToken, checkToken } from '../../app/common/UserUtil.js'; describe('test/common/UserUtil.test.ts', () => { describe('randomToken()', () => { diff --git a/test/common/adapter/BugVersionStore.test.ts b/test/common/adapter/BugVersionStore.test.ts index 4255b94e..6ce15acd 100644 --- a/test/common/adapter/BugVersionStore.test.ts +++ b/test/common/adapter/BugVersionStore.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { BugVersionStore } from '../../../app/common/adapter/BugVersionStore'; -import { BugVersion } from '../../../app/core/entity/BugVersion'; + +import { BugVersionStore } from '../../../app/common/adapter/BugVersionStore.js'; +import { BugVersion } from '../../../app/core/entity/BugVersion.js'; describe('test/common/adapter/BugVersionStore.test.ts', () => { let bugVersionStore: BugVersionStore; diff --git a/test/common/adapter/CacheAdapter.test.ts b/test/common/adapter/CacheAdapter.test.ts index e48a9aa8..76640abf 100644 --- a/test/common/adapter/CacheAdapter.test.ts +++ b/test/common/adapter/CacheAdapter.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { setTimeout } from 'node:timers/promises'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { CacheAdapter } from '../../../app/common/adapter/CacheAdapter'; + +import { CacheAdapter } from '../../../app/common/adapter/CacheAdapter.js'; describe('test/common/adapter/CacheAdapter.test.ts', () => { let cache: CacheAdapter; diff --git a/test/common/adapter/NpmRegistry.test.ts b/test/common/adapter/NpmRegistry.test.ts index 901ee10c..a39debcd 100644 --- a/test/common/adapter/NpmRegistry.test.ts +++ b/test/common/adapter/NpmRegistry.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { NPMRegistry } from '../../../app/common/adapter/NPMRegistry'; + +import { NPMRegistry } from '../../../app/common/adapter/NPMRegistry.js'; describe('test/common/adapter/CacheAdapter.test.ts', () => { let npmRegistry: NPMRegistry; diff --git a/test/common/adapter/binary/ApiBinary.test.ts b/test/common/adapter/binary/ApiBinary.test.ts index 4f90f7e1..2b9640c5 100644 --- a/test/common/adapter/binary/ApiBinary.test.ts +++ b/test/common/adapter/binary/ApiBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { ApiBinary } from '../../../../app/common/adapter/binary/ApiBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { ApiBinary } from '../../../../app/common/adapter/binary/ApiBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/ApiBinary.test.ts', () => { let binary: ApiBinary; diff --git a/test/common/adapter/binary/BucketBinary.test.ts b/test/common/adapter/binary/BucketBinary.test.ts index 48425563..0a0b9698 100644 --- a/test/common/adapter/binary/BucketBinary.test.ts +++ b/test/common/adapter/binary/BucketBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { BucketBinary } from '../../../../app/common/adapter/binary/BucketBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { BucketBinary } from '../../../../app/common/adapter/binary/BucketBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/BucketBinary.test.ts', () => { let binary: BucketBinary; @@ -21,7 +22,7 @@ describe('test/common/adapter/binary/BucketBinary.test.ts', () => { let matchFile = false; for (const item of result.items) { if (item.name === '97.0.4692.71/') { - assert(/^\d{4}\-\d{2}\-\d{2}T\d{2}:00:00Z$/.test(item.date)); + assert(/^\d{4}-\d{2}-\d{2}T\d{2}:00:00Z$/.test(item.date)); assert(item.isDir === true); assert(item.size === '-'); matchDir = true; diff --git a/test/common/adapter/binary/ChromeForTestingBinary.test.ts b/test/common/adapter/binary/ChromeForTestingBinary.test.ts index c0990b0b..2e3301a8 100644 --- a/test/common/adapter/binary/ChromeForTestingBinary.test.ts +++ b/test/common/adapter/binary/ChromeForTestingBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { ChromeForTestingBinary } from '../../../../app/common/adapter/binary/ChromeForTestingBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { ChromeForTestingBinary } from '../../../../app/common/adapter/binary/ChromeForTestingBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/ChromeForTestingBinary.test.ts', () => { let binary: ChromeForTestingBinary; @@ -41,9 +42,9 @@ describe('test/common/adapter/binary/ChromeForTestingBinary.test.ts', () => { assert.equal(versions?.length, 3); assert(versionRes?.items[0].name); assert.equal(versionRes?.items[0].isDir, false); - assert.match(versionRes?.items[0].name, /^chrome\-/); - assert.match(versionRes?.items[1].name, /^chromedriver\-/); - assert.match(versionRes?.items[2].name, /^chrome\-headless\-shell\-/); + assert.match(versionRes?.items[0].name, /^chrome-/); + assert.match(versionRes?.items[1].name, /^chromedriver-/); + assert.match(versionRes?.items[2].name, /^chrome-headless-shell-/); } await binary.finishFetch(true); assert(ChromeForTestingBinary.lastTimestamp); diff --git a/test/common/adapter/binary/CypressBinary.test.ts b/test/common/adapter/binary/CypressBinary.test.ts index b3f58215..8a6e8aa9 100644 --- a/test/common/adapter/binary/CypressBinary.test.ts +++ b/test/common/adapter/binary/CypressBinary.test.ts @@ -1,7 +1,8 @@ import assert from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { CypressBinary } from '../../../../app/common/adapter/binary/CypressBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { CypressBinary } from '../../../../app/common/adapter/binary/CypressBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/CypressBinary.test.ts', () => { let binary: CypressBinary; diff --git a/test/common/adapter/binary/EdgedriverBinary.test.ts b/test/common/adapter/binary/EdgedriverBinary.test.ts index 2b0d0718..e52e2ee7 100644 --- a/test/common/adapter/binary/EdgedriverBinary.test.ts +++ b/test/common/adapter/binary/EdgedriverBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { EdgedriverBinary } from '../../../../app/common/adapter/binary/EdgedriverBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { EdgedriverBinary } from '../../../../app/common/adapter/binary/EdgedriverBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/EdgedriverBinary.test.ts', () => { let binary: EdgedriverBinary; diff --git a/test/common/adapter/binary/ElectronBinary.test.ts b/test/common/adapter/binary/ElectronBinary.test.ts index 77e5fc6c..b7ba26ce 100644 --- a/test/common/adapter/binary/ElectronBinary.test.ts +++ b/test/common/adapter/binary/ElectronBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { ElectronBinary } from '../../../../app/common/adapter/binary/ElectronBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { ElectronBinary } from '../../../../app/common/adapter/binary/ElectronBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/ElectronBinary.test.ts', () => { let binary: ElectronBinary; diff --git a/test/common/adapter/binary/GithubBinary.test.ts b/test/common/adapter/binary/GithubBinary.test.ts index cce138ba..87792891 100644 --- a/test/common/adapter/binary/GithubBinary.test.ts +++ b/test/common/adapter/binary/GithubBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { GithubBinary } from '../../../../app/common/adapter/binary/GithubBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { GithubBinary } from '../../../../app/common/adapter/binary/GithubBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/GithubBinary.test.ts', () => { let binary: GithubBinary; diff --git a/test/common/adapter/binary/ImageminBinary.test.ts b/test/common/adapter/binary/ImageminBinary.test.ts index 352e3dbf..ee72d9fe 100644 --- a/test/common/adapter/binary/ImageminBinary.test.ts +++ b/test/common/adapter/binary/ImageminBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { ImageminBinary } from '../../../../app/common/adapter/binary/ImageminBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { ImageminBinary } from '../../../../app/common/adapter/binary/ImageminBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/ImageminBinary.test.ts', () => { let binary: ImageminBinary; diff --git a/test/common/adapter/binary/NodeBinary.test.ts b/test/common/adapter/binary/NodeBinary.test.ts index 970f42aa..e78d19fe 100644 --- a/test/common/adapter/binary/NodeBinary.test.ts +++ b/test/common/adapter/binary/NodeBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { NodeBinary } from '../../../../app/common/adapter/binary/NodeBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { NodeBinary } from '../../../../app/common/adapter/binary/NodeBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/NodeBinary.test.ts', () => { let binary: NodeBinary; diff --git a/test/common/adapter/binary/NodePreGypBinary.test.ts b/test/common/adapter/binary/NodePreGypBinary.test.ts index 9eefa6a7..02103d7e 100644 --- a/test/common/adapter/binary/NodePreGypBinary.test.ts +++ b/test/common/adapter/binary/NodePreGypBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { NodePreGypBinary } from '../../../../app/common/adapter/binary/NodePreGypBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { NodePreGypBinary } from '../../../../app/common/adapter/binary/NodePreGypBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/NodePreGypBinary.test.ts', () => { let binary: NodePreGypBinary; diff --git a/test/common/adapter/binary/NwjsBinary.test.ts b/test/common/adapter/binary/NwjsBinary.test.ts index 615c275d..0e9866db 100644 --- a/test/common/adapter/binary/NwjsBinary.test.ts +++ b/test/common/adapter/binary/NwjsBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { NwjsBinary } from '../../../../app/common/adapter/binary/NwjsBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { NwjsBinary } from '../../../../app/common/adapter/binary/NwjsBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/NwjsBinary.test.ts', () => { let binary: NwjsBinary; diff --git a/test/common/adapter/binary/PlaywrightBinary.test.ts b/test/common/adapter/binary/PlaywrightBinary.test.ts index 047a34ab..b49cb220 100644 --- a/test/common/adapter/binary/PlaywrightBinary.test.ts +++ b/test/common/adapter/binary/PlaywrightBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { PlaywrightBinary } from '../../../../app/common/adapter/binary/PlaywrightBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { PlaywrightBinary } from '../../../../app/common/adapter/binary/PlaywrightBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/PlaywrightBinary.test.ts', () => { let binary: PlaywrightBinary; diff --git a/test/common/adapter/binary/PrismaBinary.test.ts b/test/common/adapter/binary/PrismaBinary.test.ts index 94a4c64b..f6675a2c 100644 --- a/test/common/adapter/binary/PrismaBinary.test.ts +++ b/test/common/adapter/binary/PrismaBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { PrismaBinary } from '../../../../app/common/adapter/binary/PrismaBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { PrismaBinary } from '../../../../app/common/adapter/binary/PrismaBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/PrismaBinary.test.ts', () => { let binary: PrismaBinary; diff --git a/test/common/adapter/binary/PuppeteerBinary.test.ts b/test/common/adapter/binary/PuppeteerBinary.test.ts index 2dbb8c8b..82a22d3e 100644 --- a/test/common/adapter/binary/PuppeteerBinary.test.ts +++ b/test/common/adapter/binary/PuppeteerBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { PuppeteerBinary } from '../../../../app/common/adapter/binary/PuppeteerBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { PuppeteerBinary } from '../../../../app/common/adapter/binary/PuppeteerBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/PuppeteerBinary.test.ts', () => { let binary: PuppeteerBinary; diff --git a/test/common/adapter/binary/SqlcipherBinary.test.ts b/test/common/adapter/binary/SqlcipherBinary.test.ts index 98c03712..86f97f64 100644 --- a/test/common/adapter/binary/SqlcipherBinary.test.ts +++ b/test/common/adapter/binary/SqlcipherBinary.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { SqlcipherBinary } from '../../../../app/common/adapter/binary/SqlcipherBinary'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { SqlcipherBinary } from '../../../../app/common/adapter/binary/SqlcipherBinary.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/common/adapter/binary/SqlcipherBinary.test.ts', () => { let binary: SqlcipherBinary; diff --git a/test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts b/test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts index d576f983..597b840b 100644 --- a/test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts +++ b/test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { ChangesStreamChange } from '../../../../app/common/adapter/changesStream/AbstractChangesStream'; -import { CnpmcoreChangesStream } from '../../../../app/common/adapter/changesStream/CnpmcoreChangesStream'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { Registry } from '../../../../app/core/entity/Registry'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; + +import { ChangesStreamChange } from '../../../../app/common/adapter/changesStream/AbstractChangesStream.js'; +import { CnpmcoreChangesStream } from '../../../../app/common/adapter/changesStream/CnpmcoreChangesStream.js'; +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { Registry } from '../../../../app/core/entity/Registry.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; describe('test/common/adapter/changesStream/CnpmcoreChangesStream.test.ts', () => { let cnpmcoreChangesStream: CnpmcoreChangesStream; diff --git a/test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts b/test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts index 348d407b..03c1c55b 100644 --- a/test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts +++ b/test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { ChangesStreamChange } from '../../../../app/common/adapter/changesStream/AbstractChangesStream'; -import { CnpmjsorgChangesStream } from '../../../../app/common/adapter/changesStream/CnpmjsorgChangesStream'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { Registry } from '../../../../app/core/entity/Registry'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; + +import { ChangesStreamChange } from '../../../../app/common/adapter/changesStream/AbstractChangesStream.js'; +import { CnpmjsorgChangesStream } from '../../../../app/common/adapter/changesStream/CnpmjsorgChangesStream.js'; +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { Registry } from '../../../../app/core/entity/Registry.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; describe('test/common/adapter/changesStream/CnpmjsorgChangesStream.test.ts', () => { let cnpmjsorgChangesStream: CnpmjsorgChangesStream; diff --git a/test/common/adapter/changesStream/NpmChangesStream.test.ts b/test/common/adapter/changesStream/NpmChangesStream.test.ts index 473b9fe0..6bb941f5 100644 --- a/test/common/adapter/changesStream/NpmChangesStream.test.ts +++ b/test/common/adapter/changesStream/NpmChangesStream.test.ts @@ -1,11 +1,12 @@ import { Readable, Duplex } from 'node:stream'; import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { ChangesStreamChange } from '../../../../app/common/adapter/changesStream/AbstractChangesStream'; -import { NpmChangesStream } from '../../../../app/common/adapter/changesStream/NpmChangesStream'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { Registry } from '../../../../app/core/entity/Registry'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; + +import { ChangesStreamChange } from '../../../../app/common/adapter/changesStream/AbstractChangesStream.js'; +import { NpmChangesStream } from '../../../../app/common/adapter/changesStream/NpmChangesStream.js'; +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { Registry } from '../../../../app/core/entity/Registry.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; describe('test/common/adapter/changesStream/NpmChangesStream.test.ts', () => { let npmChangesStream: NpmChangesStream; diff --git a/test/core/entity/BugVersion.test.ts b/test/core/entity/BugVersion.test.ts index e7904adc..3a4c9f9f 100644 --- a/test/core/entity/BugVersion.test.ts +++ b/test/core/entity/BugVersion.test.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; -import { BugVersion } from '../../../app/core/entity/BugVersion'; + +import { BugVersion } from '../../../app/core/entity/BugVersion.js'; describe('test/core/entity/BugVersion.test.ts', () => { const bugVersion = new BugVersion({ diff --git a/test/core/entity/PaddingSemver.test.ts b/test/core/entity/PaddingSemver.test.ts index ecac4f83..cda8383a 100644 --- a/test/core/entity/PaddingSemver.test.ts +++ b/test/core/entity/PaddingSemver.test.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; -import { PaddingSemVer } from '../../../app/core/entity/PaddingSemVer'; + +import { PaddingSemVer } from '../../../app/core/entity/PaddingSemVer.js'; describe('test/npm/core/entity/PaddingSemver.test.ts', () => { it('should parse 16 length version ok', () => { diff --git a/test/core/entity/SqlRange.test.ts b/test/core/entity/SqlRange.test.ts index 901e21af..47d3eb43 100644 --- a/test/core/entity/SqlRange.test.ts +++ b/test/core/entity/SqlRange.test.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; -import { SqlRange } from '../../../app/core/entity/SqlRange'; + +import { SqlRange } from '../../../app/core/entity/SqlRange.js'; describe('test/npm/core/entity/SqlRange.test.ts', () => { it('should support compose range', () => { diff --git a/test/core/event/BugVersionFixHandler.test.ts b/test/core/event/BugVersionFixHandler.test.ts index ea7b5c99..49e2086a 100644 --- a/test/core/event/BugVersionFixHandler.test.ts +++ b/test/core/event/BugVersionFixHandler.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { BUG_VERSIONS } from '../../../app/common/constants'; -import { CacheService } from '../../../app/core/service/CacheService'; -import { BugVersionFixHandler } from '../../../app/core/event/BugVersionFixHandler'; -import { BugVersion } from '../../../app/core/entity/BugVersion'; -import { BugVersionService } from '../../../app/core/service/BugVersionService'; + +import { BUG_VERSIONS } from '../../../app/common/constants.js'; +import { CacheService } from '../../../app/core/service/CacheService.js'; +import { BugVersionFixHandler } from '../../../app/core/event/BugVersionFixHandler.js'; +import { BugVersion } from '../../../app/core/entity/BugVersion.js'; +import { BugVersionService } from '../../../app/core/service/BugVersionService.js'; describe('test/core/event/BugVersionFixHandler.test.ts', () => { let cacheService: CacheService; @@ -15,7 +16,7 @@ describe('test/core/event/BugVersionFixHandler.test.ts', () => { cacheService = await app.getEggObject(CacheService); bugVersionService = await app.getEggObject(BugVersionService); mock(app.config.cnpmcore, 'allowPublishNonScopePackage', true); - mock(cacheService, 'removeCache', async fullname => { + mock(cacheService, 'removeCache', async (fullname: string) => { fullnames.push(fullname); }); mock(bugVersionService, 'getBugVersion', async () => { diff --git a/test/core/event/ChangesStream.test.ts b/test/core/event/ChangesStream.test.ts index 6149b07b..0e12ec43 100644 --- a/test/core/event/ChangesStream.test.ts +++ b/test/core/event/ChangesStream.test.ts @@ -1,6 +1,7 @@ -import { PackageVersionAddedChangesStreamEvent } from '../../../app/core/event/ChangesStream'; import { app, mock } from '@eggjs/mock/bootstrap'; +import { PackageVersionAddedChangesStreamEvent } from '../../../app/core/event/ChangesStream.js'; + describe('test/core/event/BugVersionFixHandler.test.ts', () => { let packageVersionAddedChangesStreamEvent: PackageVersionAddedChangesStreamEvent; diff --git a/test/core/event/StoreManifest.test.ts b/test/core/event/StoreManifest.test.ts index 2da18748..8b899369 100644 --- a/test/core/event/StoreManifest.test.ts +++ b/test/core/event/StoreManifest.test.ts @@ -1,8 +1,9 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../test/TestUtil'; -import { getScopeAndName } from '../../../app/common/PackageUtil'; -import { PackageRepository } from '../../../app/repository/PackageRepository'; + +import { getScopeAndName } from '../../../app/common/PackageUtil.js'; +import { PackageRepository } from '../../../app/repository/PackageRepository.js'; +import { TestUtil } from '../../../test/TestUtil.js'; describe('test/core/event/StoreManifest.test.ts', () => { let packageRepository: PackageRepository; @@ -14,8 +15,6 @@ describe('test/core/event/StoreManifest.test.ts', () => { describe('savePackageVersionManifest()', () => { it('should not store manifest when enableStoreFullPackageVersionManifestsToDatabase = false', async () => { const { pkg } = await TestUtil.createPackage({ version: '1.0.0' }); - const eventWaiter = await app.getEventWaiter(); - await eventWaiter.await('PACKAGE_VERSION_ADDED'); const [ scope, name ] = getScopeAndName(pkg.name); const packageId = await packageRepository.findPackageId(scope, name); assert(packageId); diff --git a/test/core/service/BinarySyncerService/createTask.test.ts b/test/core/service/BinarySyncerService/createTask.test.ts index 47bf5392..e5a27ea2 100644 --- a/test/core/service/BinarySyncerService/createTask.test.ts +++ b/test/core/service/BinarySyncerService/createTask.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { BinarySyncerService } from '../../../../app/core/service/BinarySyncerService'; -import { BinaryName } from '../../../../config/binaries'; + +import { BinarySyncerService } from '../../../../app/core/service/BinarySyncerService.js'; +import { BinaryName } from '../../../../config/binaries.js'; describe('test/core/service/BinarySyncerService/createTask.test.ts', () => { let binarySyncerService: BinarySyncerService; diff --git a/test/core/service/BinarySyncerService/executeTask.test.ts b/test/core/service/BinarySyncerService/executeTask.test.ts index e4cc8651..b9ba04a2 100644 --- a/test/core/service/BinarySyncerService/executeTask.test.ts +++ b/test/core/service/BinarySyncerService/executeTask.test.ts @@ -1,12 +1,13 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { BinarySyncerService } from '../../../../app/core/service/BinarySyncerService'; -import { Task as TaskModel } from '../../../../app/repository/model/Task'; -import { HistoryTask as HistoryTaskModel } from '../../../../app/repository/model/HistoryTask'; -import { NodeBinary } from '../../../../app/common/adapter/binary/NodeBinary'; -import { ApiBinary } from '../../../../app/common/adapter/binary/ApiBinary'; -import { BinaryRepository } from '../../../../app/repository/BinaryRepository'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { BinarySyncerService } from '../../../../app/core/service/BinarySyncerService.js'; +import { Task as TaskModel } from '../../../../app/repository/model/Task.js'; +import { HistoryTask as HistoryTaskModel } from '../../../../app/repository/model/HistoryTask.js'; +import { NodeBinary } from '../../../../app/common/adapter/binary/NodeBinary.js'; +import { ApiBinary } from '../../../../app/common/adapter/binary/ApiBinary.js'; +import { BinaryRepository } from '../../../../app/repository/BinaryRepository.js'; describe('test/core/service/BinarySyncerService/executeTask.test.ts', () => { let binarySyncerService: BinarySyncerService; diff --git a/test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts b/test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts index 2104bcc0..26ea77f8 100644 --- a/test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts +++ b/test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { BugVersionService } from '../../../../app/core/service/BugVersionService'; -import { CacheService } from '../../../../app/core/service/CacheService'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { BugVersionService } from '../../../../app/core/service/BugVersionService.js'; +import { CacheService } from '../../../../app/core/service/CacheService.js'; +import { BugVersion } from '../../../../app/core/entity/BugVersion.js'; describe('test/core/service/BugVersionService/cleanBugVersionPackageCache.test.ts', () => { let bugVersionService: BugVersionService; @@ -37,7 +38,7 @@ describe('test/core/service/BugVersionService/cleanBugVersionPackageCache.test.t }, }, }); - mock(cacheService, 'removeCache', async fullname => { + mock(cacheService, 'removeCache', async (fullname: string) => { cleanPkgs.push(fullname); }); }); diff --git a/test/core/service/BugVersionService/fixPackageBugVersion.test.ts b/test/core/service/BugVersionService/fixPackageBugVersion.test.ts index b7d8f82a..553b70b0 100644 --- a/test/core/service/BugVersionService/fixPackageBugVersion.test.ts +++ b/test/core/service/BugVersionService/fixPackageBugVersion.test.ts @@ -1,13 +1,14 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { BugVersionService } from '../../../../app/core/service/BugVersionService'; -import { DistRepository } from '../../../../app/repository/DistRepository'; -import { PackageRepository } from '../../../../app/repository/PackageRepository'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; -import { Package } from '../../../../app/core/entity/Package'; -import { PackageVersion } from '../../../../app/core/entity/PackageVersion'; -import { Dist } from '../../../../app/core/entity/Dist'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { BugVersionService } from '../../../../app/core/service/BugVersionService.js'; +import { DistRepository } from '../../../../app/repository/DistRepository.js'; +import { PackageRepository } from '../../../../app/repository/PackageRepository.js'; +import { BugVersion } from '../../../../app/core/entity/BugVersion.js'; +import { Package } from '../../../../app/core/entity/Package.js'; +import { PackageVersion } from '../../../../app/core/entity/PackageVersion.js'; +import { Dist } from '../../../../app/core/entity/Dist.js'; describe('test/core/service/BugVersionService/fixPackageBugVersion.test.ts', () => { let bugVersionService: BugVersionService; @@ -45,7 +46,7 @@ describe('test/core/service/BugVersionService/fixPackageBugVersion.test.ts', () }, }, }); - mock(distRepository, 'findPackageVersionManifest', async (_, version) => { + mock(distRepository, 'findPackageVersionManifest', async (_: unknown, version: string) => { if (version !== '199.0.0') { return { name: 'colors', diff --git a/test/core/service/BugVersionService/fixPackageBugVersions.test.ts b/test/core/service/BugVersionService/fixPackageBugVersions.test.ts index d1b25fdf..b92cd418 100644 --- a/test/core/service/BugVersionService/fixPackageBugVersions.test.ts +++ b/test/core/service/BugVersionService/fixPackageBugVersions.test.ts @@ -1,8 +1,9 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { BugVersionService } from '../../../../app/core/service/BugVersionService'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { BugVersionService } from '../../../../app/core/service/BugVersionService.js'; +import { BugVersion } from '../../../../app/core/entity/BugVersion.js'; describe('test/core/service/BugVersionService/fixPackageBugVersions.test.ts', () => { let bugVersionService: BugVersionService; diff --git a/test/core/service/ChangesStreamService.test.ts b/test/core/service/ChangesStreamService.test.ts index a7151690..26672b3a 100644 --- a/test/core/service/ChangesStreamService.test.ts +++ b/test/core/service/ChangesStreamService.test.ts @@ -1,15 +1,16 @@ import { strict as assert } from 'node:assert'; import { Readable } from 'node:stream'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../test/TestUtil'; -import { ChangesStreamService } from '../../../app/core/service/ChangesStreamService'; -import { TaskService } from '../../../app/core/service/TaskService'; -import { ChangesStreamTask, Task } from '../../../app/core/entity/Task'; -import { RegistryManagerService } from '../../../app/core/service/RegistryManagerService'; -import { RegistryType } from '../../../app/common/enum/Registry'; -import { ScopeManagerService } from '../../../app/core/service/ScopeManagerService'; -import { Registry } from '../../../app/core/entity/Registry'; -import { RedisQueueAdapter } from '../../../app/infra/QueueAdapter'; + +import { TestUtil } from '../../../test/TestUtil.js'; +import { ChangesStreamService } from '../../../app/core/service/ChangesStreamService.js'; +import { TaskService } from '../../../app/core/service/TaskService.js'; +import { ChangesStreamTask, Task } from '../../../app/core/entity/Task.js'; +import { RegistryManagerService } from '../../../app/core/service/RegistryManagerService.js'; +import { RegistryType } from '../../../app/common/enum/Registry.js'; +import { ScopeManagerService } from '../../../app/core/service/ScopeManagerService.js'; +import { Registry } from '../../../app/core/entity/Registry.js'; +import { RedisQueueAdapter } from '../../../app/infra/QueueAdapter.js'; describe('test/core/service/ChangesStreamService.test.ts', () => { let changesStreamService: ChangesStreamService; diff --git a/test/core/service/CreateHookTriggerService.test.ts b/test/core/service/CreateHookTriggerService.test.ts index fa037f34..58981b13 100644 --- a/test/core/service/CreateHookTriggerService.test.ts +++ b/test/core/service/CreateHookTriggerService.test.ts @@ -1,17 +1,18 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../test/TestUtil'; -import { HookManageService } from '../../../app/core/service/HookManageService'; -import { HookType } from '../../../app/common/enum/Hook'; -import { UserRepository } from '../../../app/repository/UserRepository'; -import { PACKAGE_VERSION_ADDED } from '../../../app/core/event'; -import { Change } from '../../../app/core/entity/Change'; -import { ChangeRepository } from '../../../app/repository/ChangeRepository'; -import { Task } from '../../../app/core/entity/Task'; -import { HookEvent } from '../../../app/core/entity/HookEvent'; -import { CreateHookTriggerService } from '../../../app/core/service/CreateHookTriggerService'; -import { TaskRepository } from '../../../app/repository/TaskRepository'; -import { Hook } from '../../../app/core/entity/Hook'; + +import { TestUtil } from '../../../test/TestUtil.js'; +import { HookManageService } from '../../../app/core/service/HookManageService.js'; +import { HookType } from '../../../app/common/enum/Hook.js'; +import { UserRepository } from '../../../app/repository/UserRepository.js'; +import { PACKAGE_VERSION_ADDED } from '../../../app/core/event/index.js'; +import { Change } from '../../../app/core/entity/Change.js'; +import { ChangeRepository } from '../../../app/repository/ChangeRepository.js'; +import { Task } from '../../../app/core/entity/Task.js'; +import { HookEvent } from '../../../app/core/entity/HookEvent.js'; +import { CreateHookTriggerService } from '../../../app/core/service/CreateHookTriggerService.js'; +import { TaskRepository } from '../../../app/repository/TaskRepository.js'; +import { Hook } from '../../../app/core/entity/Hook.js'; describe('test/core/service/CreateHookTriggerService.test.ts', () => { let hookManageService: HookManageService; diff --git a/test/core/service/HookManageService/createHook.test.ts b/test/core/service/HookManageService/createHook.test.ts index d8121d89..5015234a 100644 --- a/test/core/service/HookManageService/createHook.test.ts +++ b/test/core/service/HookManageService/createHook.test.ts @@ -1,8 +1,9 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { HookType } from '../../../../app/common/enum/Hook'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { HookManageService } from '../../../../app/core/service/HookManageService.js'; +import { HookType } from '../../../../app/common/enum/Hook.js'; describe('test/core/service/HookManageService/createHook.test.ts', () => { let hookManageService: HookManageService; diff --git a/test/core/service/HookManageService/deleteHook.test.ts b/test/core/service/HookManageService/deleteHook.test.ts index cc08dd1e..1c85665b 100644 --- a/test/core/service/HookManageService/deleteHook.test.ts +++ b/test/core/service/HookManageService/deleteHook.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { Hook } from '../../../../app/core/entity/Hook'; -import { HookType } from '../../../../app/common/enum/Hook'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { HookManageService } from '../../../../app/core/service/HookManageService.js'; +import { Hook } from '../../../../app/core/entity/Hook.js'; +import { HookType } from '../../../../app/common/enum/Hook.js'; describe('test/core/service/HookManageService/deleteHook.test.ts', () => { let hookManageService: HookManageService; diff --git a/test/core/service/HookManageService/getHookByOwnerId.test.ts b/test/core/service/HookManageService/getHookByOwnerId.test.ts index ebd5c657..fe52e6e0 100644 --- a/test/core/service/HookManageService/getHookByOwnerId.test.ts +++ b/test/core/service/HookManageService/getHookByOwnerId.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { Hook } from '../../../../app/core/entity/Hook'; -import { HookType } from '../../../../app/common/enum/Hook'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { HookManageService } from '../../../../app/core/service/HookManageService.js'; +import { Hook } from '../../../../app/core/entity/Hook.js'; +import { HookType } from '../../../../app/common/enum/Hook.js'; describe('test/core/service/HookManageService/getHookByOwnerId.test.ts', () => { let hookManageService: HookManageService; diff --git a/test/core/service/HookManageService/updateHook.test.ts b/test/core/service/HookManageService/updateHook.test.ts index b215bd8a..5f0894fc 100644 --- a/test/core/service/HookManageService/updateHook.test.ts +++ b/test/core/service/HookManageService/updateHook.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { Hook } from '../../../../app/core/entity/Hook'; -import { HookType } from '../../../../app/common/enum/Hook'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { HookManageService } from '../../../../app/core/service/HookManageService.js'; +import { Hook } from '../../../../app/core/entity/Hook.js'; +import { HookType } from '../../../../app/common/enum/Hook.js'; describe('test/core/service/HookManageService/updateHook.test.ts', () => { let hookManageService: HookManageService; diff --git a/test/core/service/HookTriggerService.test.ts b/test/core/service/HookTriggerService.test.ts index 015c17ca..e205527b 100644 --- a/test/core/service/HookTriggerService.test.ts +++ b/test/core/service/HookTriggerService.test.ts @@ -1,19 +1,20 @@ import { strict as assert } from 'node:assert'; import { HttpClientRequestOptions } from 'egg'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../test/TestUtil'; -import { HookManageService } from '../../../app/core/service/HookManageService'; -import { HookType } from '../../../app/common/enum/Hook'; -import { UserRepository } from '../../../app/repository/UserRepository'; -import { PACKAGE_TAG_ADDED, PACKAGE_VERSION_ADDED } from '../../../app/core/event'; -import { Change } from '../../../app/core/entity/Change'; -import { ChangeRepository } from '../../../app/repository/ChangeRepository'; -import { Task, TriggerHookTask } from '../../../app/core/entity/Task'; -import { HookEvent } from '../../../app/core/entity/HookEvent'; -import { CreateHookTriggerService } from '../../../app/core/service/CreateHookTriggerService'; -import { TaskRepository } from '../../../app/repository/TaskRepository'; -import { Hook } from '../../../app/core/entity/Hook'; -import { HookTriggerService } from '../../../app/core/service/HookTriggerService'; + +import { TestUtil } from '../../../test/TestUtil.js'; +import { HookManageService } from '../../../app/core/service/HookManageService.js'; +import { HookType } from '../../../app/common/enum/Hook.js'; +import { UserRepository } from '../../../app/repository/UserRepository.js'; +import { PACKAGE_TAG_ADDED, PACKAGE_VERSION_ADDED } from '../../../app/core/event/index.js'; +import { Change } from '../../../app/core/entity/Change.js'; +import { ChangeRepository } from '../../../app/repository/ChangeRepository.js'; +import { Task, TriggerHookTask } from '../../../app/core/entity/Task.js'; +import { HookEvent } from '../../../app/core/entity/HookEvent.js'; +import { CreateHookTriggerService } from '../../../app/core/service/CreateHookTriggerService.js'; +import { TaskRepository } from '../../../app/repository/TaskRepository.js'; +import { Hook } from '../../../app/core/entity/Hook.js'; +import { HookTriggerService } from '../../../app/core/service/HookTriggerService.js'; describe('test/core/service/HookTriggerService.test.ts', () => { let hookManageService: HookManageService; @@ -83,7 +84,7 @@ describe('test/core/service/HookTriggerService.test.ts', () => { createHookTriggerService.executeTask(tagTask), ]); - mock(app.httpclient, 'request', async (url, options) => { + mock(app.httpclient, 'request', async (url: string, options: HttpClientRequestOptions) => { callEndpoint = url; callOptions = options; return { diff --git a/test/core/service/PackageManagerService/block.test.ts b/test/core/service/PackageManagerService/block.test.ts index 31b61e16..5a869120 100644 --- a/test/core/service/PackageManagerService/block.test.ts +++ b/test/core/service/PackageManagerService/block.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { PackageManagerService } from '../../../../app/core/service/PackageManagerService'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { PackageManagerService } from '../../../../app/core/service/PackageManagerService.js'; describe('test/core/service/PackageManagerService/block.test.ts', () => { let packageManagerService: PackageManagerService; diff --git a/test/core/service/PackageManagerService/publish.test.ts b/test/core/service/PackageManagerService/publish.test.ts index cc7e238d..3a85f134 100644 --- a/test/core/service/PackageManagerService/publish.test.ts +++ b/test/core/service/PackageManagerService/publish.test.ts @@ -1,15 +1,17 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { PackageManagerService } from '../../../../app/core/service/PackageManagerService'; -import { UserService } from '../../../../app/core/service/UserService'; -import { PackageRepository } from '../../../../app/repository/PackageRepository'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { PackageManagerService } from '../../../../app/core/service/PackageManagerService.js'; +import { UserService } from '../../../../app/core/service/UserService.js'; +import { PackageRepository } from '../../../../app/repository/PackageRepository.js'; +import { User } from '../../../../app/core/entity/User.js'; describe('test/core/service/PackageManagerService/publish.test.ts', () => { let packageManagerService: PackageManagerService; let userService: UserService; let packageRepository: PackageRepository; - let publisher; + let publisher: User; beforeEach(async () => { userService = await app.getEggObject(UserService); @@ -90,7 +92,7 @@ describe('test/core/service/PackageManagerService/publish.test.ts', () => { assert(pkgVersion); assert.equal(pkgVersion.version, '1.0.0'); const pkg = await packageRepository.findPackage('', 'foo'); - assert(pkg?.description === '~'.repeat(1024 * 10)); + assert.equal(pkg?.description, '~'.repeat(1024 * 10)); }); it('should work with dist.localFile', async () => { diff --git a/test/core/service/PackageSyncerService/createTask.test.ts b/test/core/service/PackageSyncerService/createTask.test.ts index 37daa344..4c79292e 100644 --- a/test/core/service/PackageSyncerService/createTask.test.ts +++ b/test/core/service/PackageSyncerService/createTask.test.ts @@ -1,12 +1,13 @@ import { strict as assert } from 'node:assert'; import { setTimeout } from 'node:timers/promises'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService'; -import { Task } from '../../../../app/core/entity/Task'; -import { TaskState } from '../../../../app/common/enum/Task'; -import { TaskRepository } from '../../../../app/repository/TaskRepository'; -import { TaskService } from '../../../../app/core/service/TaskService'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService.js'; +import { Task } from '../../../../app/core/entity/Task.js'; +import { TaskState } from '../../../../app/common/enum/Task.js'; +import { TaskRepository } from '../../../../app/repository/TaskRepository.js'; +import { TaskService } from '../../../../app/core/service/TaskService.js'; describe('test/core/service/PackageSyncerService/createTask.test.ts', () => { const pkgName = '@cnpmcore/foo'; diff --git a/test/core/service/PackageSyncerService/executeTask.test.ts b/test/core/service/PackageSyncerService/executeTask.test.ts index b948900f..96461246 100644 --- a/test/core/service/PackageSyncerService/executeTask.test.ts +++ b/test/core/service/PackageSyncerService/executeTask.test.ts @@ -1,25 +1,26 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService'; -import { PackageManagerService } from '../../../../app/core/service/PackageManagerService'; -import { Package as PackageModel } from '../../../../app/repository/model/Package'; -import { Task as TaskModel } from '../../../../app/repository/model/Task'; -import { Task as TaskEntity } from '../../../../app/core/entity/Task'; -import { HistoryTask as HistoryTaskModel } from '../../../../app/repository/model/HistoryTask'; -import { NPMRegistry } from '../../../../app/common/adapter/NPMRegistry'; -import { NFSAdapter } from '../../../../app/common/adapter/NFSAdapter'; -import { getScopeAndName } from '../../../../app/common/PackageUtil'; -import { PackageRepository } from '../../../../app/repository/PackageRepository'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; -import { Registry } from '../../../../app/core/entity/Registry'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { TaskService } from '../../../../app/core/service/TaskService'; -import { ScopeManagerService } from '../../../../app/core/service/ScopeManagerService'; -import { UserService } from '../../../../app/core/service/UserService'; -import { ChangeRepository } from '../../../../app/repository/ChangeRepository'; -import { PackageVersion } from '../../../../app/repository/model/PackageVersion'; -import { TaskState } from '../../../../app/common/enum/Task'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService.js'; +import { PackageManagerService } from '../../../../app/core/service/PackageManagerService.js'; +import { Package as PackageModel } from '../../../../app/repository/model/Package.js'; +import { Task as TaskModel } from '../../../../app/repository/model/Task.js'; +import { Task as TaskEntity } from '../../../../app/core/entity/Task.js'; +import { HistoryTask as HistoryTaskModel } from '../../../../app/repository/model/HistoryTask.js'; +import { NPMRegistry } from '../../../../app/common/adapter/NPMRegistry.js'; +import { NFSAdapter } from '../../../../app/common/adapter/NFSAdapter.js'; +import { getScopeAndName } from '../../../../app/common/PackageUtil.js'; +import { PackageRepository } from '../../../../app/repository/PackageRepository.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; +import { Registry } from '../../../../app/core/entity/Registry.js'; +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { TaskService } from '../../../../app/core/service/TaskService.js'; +import { ScopeManagerService } from '../../../../app/core/service/ScopeManagerService.js'; +import { UserService } from '../../../../app/core/service/UserService.js'; +import { ChangeRepository } from '../../../../app/repository/ChangeRepository.js'; +import { PackageVersion } from '../../../../app/repository/model/PackageVersion.js'; +import { TaskState } from '../../../../app/common/enum/Task.js'; describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => { let packageSyncerService: PackageSyncerService; @@ -480,9 +481,9 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => { const tgzBuffer1_0_0 = await TestUtil.readFixturesFile('registry.npmjs.org/foobar/-/foobar-1.0.0.tgz'); const tgzBuffer1_1_0 = await TestUtil.readFixturesFile('registry.npmjs.org/foobar/-/foobar-1.1.0.tgz'); - let fullManifestsHeader; - let tgzBuffer1_0_0Header; - let tgzBuffer1_1_0Header; + let fullManifestsHeader: any; + let tgzBuffer1_0_0Header: any; + let tgzBuffer1_1_0Header: any; app.mockHttpclient('https://registry.npmjs.org/foobar', 'GET', (_, opts) => { fullManifestsHeader = opts.headers; return { @@ -1760,7 +1761,7 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => { const log = await TestUtil.readStreamToLog(stream); // console.log(log); assert(log.includes(`❌❌❌❌❌ ${name} ❌❌❌❌❌`)); - assert(log.includes('❌ stop sync by block list: [\"cnpmcore-test-sync-blocklist\",\"foo\"]')); + assert(log.includes('❌ stop sync by block list: ["cnpmcore-test-sync-blocklist","foo"]')); }); it('should sync upper case "D" success', async () => { @@ -2603,7 +2604,7 @@ describe('test/core/service/PackageSyncerService/executeTask.test.ts', () => { // already synced pkg beforeEach(async () => { - app.mockHttpclient(/^https:\/\/registry\.npmjs\.org\/invalid\-deps/, 'GET', { + app.mockHttpclient(/^https:\/\/registry\.npmjs\.org\/invalid-deps/, 'GET', { data: await TestUtil.readFixturesFile('registry.npmjs.org/invalid-deps.json'), persist: false, }); diff --git a/test/core/service/PackageSyncerService/findExecuteTask.test.ts b/test/core/service/PackageSyncerService/findExecuteTask.test.ts index 8765163f..7cf64b43 100644 --- a/test/core/service/PackageSyncerService/findExecuteTask.test.ts +++ b/test/core/service/PackageSyncerService/findExecuteTask.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService'; -import { Task as TaskModel } from '../../../../app/repository/model/Task'; -import { HistoryTask as HistoryTaskModel } from '../../../../app/repository/model/HistoryTask'; -import { TaskService } from '../../../../app/core/service/TaskService'; + +import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService.js'; +import { Task as TaskModel } from '../../../../app/repository/model/Task.js'; +import { HistoryTask as HistoryTaskModel } from '../../../../app/repository/model/HistoryTask.js'; +import { TaskService } from '../../../../app/core/service/TaskService.js'; describe('test/core/service/PackageSyncerService/findExecuteTask.test.ts', () => { let packageSyncerService: PackageSyncerService; diff --git a/test/core/service/PackageSyncerService/getTaskRegistry.test.ts b/test/core/service/PackageSyncerService/getTaskRegistry.test.ts index e451cb73..27269214 100644 --- a/test/core/service/PackageSyncerService/getTaskRegistry.test.ts +++ b/test/core/service/PackageSyncerService/getTaskRegistry.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; -import { Registry } from '../../../../app/core/entity/Registry'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { Task } from '../../../../app/core/entity/Task'; + +import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; +import { Registry } from '../../../../app/core/entity/Registry.js'; +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { Task } from '../../../../app/core/entity/Task.js'; describe('test/core/service/PackageSyncerService/getTaskRegistry.test.ts', () => { let packageSyncerService: PackageSyncerService; diff --git a/test/core/service/PackageVersionService.test.ts b/test/core/service/PackageVersionService.test.ts index 34583b02..baa440b9 100644 --- a/test/core/service/PackageVersionService.test.ts +++ b/test/core/service/PackageVersionService.test.ts @@ -2,15 +2,15 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; import npa from 'npm-package-arg'; -import { Package as PackageModel } from '../../../app/repository/model/Package'; -import { PackageVersion as CnpmPackageVersionModel } from '../../../app//repository/model/PackageVersion'; -import { PackageTag as PackageTagModel } from '../../../app/repository/model/PackageTag'; -import { PackageVersionService } from '../../../app/core/service/PackageVersionService'; -import { PaddingSemVer } from '../../../app/core/entity/PaddingSemVer'; -import { BugVersionService } from '../../../app/core/service/BugVersionService'; -import { BugVersion } from '../../../app/core/entity/BugVersion'; -import { PackageVersionRepository } from '../../../app/repository/PackageVersionRepository'; -import { DistRepository } from '../../../app/repository/DistRepository'; +import { Package as PackageModel } from '../../../app/repository/model/Package.js'; +import { PackageVersion as CnpmPackageVersionModel } from '../../../app//repository/model/PackageVersion.js'; +import { PackageTag as PackageTagModel } from '../../../app/repository/model/PackageTag.js'; +import { PackageVersionService } from '../../../app/core/service/PackageVersionService.js'; +import { PaddingSemVer } from '../../../app/core/entity/PaddingSemVer.js'; +import { BugVersionService } from '../../../app/core/service/BugVersionService.js'; +import { BugVersion } from '../../../app/core/entity/BugVersion.js'; +import { PackageVersionRepository } from '../../../app/repository/PackageVersionRepository.js'; +import { DistRepository } from '../../../app/repository/DistRepository.js'; describe('test/core/service/PackageVersionService.test.ts', () => { diff --git a/test/core/service/ProxyCacheService.test.ts b/test/core/service/ProxyCacheService.test.ts index fd7c42da..0c0b0b5a 100644 --- a/test/core/service/ProxyCacheService.test.ts +++ b/test/core/service/ProxyCacheService.test.ts @@ -1,12 +1,13 @@ import assert from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../TestUtil'; -import { ProxyCacheService } from '../../../app/core/service/ProxyCacheService'; -import { ProxyCacheRepository } from '../../../app/repository/ProxyCacheRepository'; -import { DIST_NAMES } from '../../../app/core/entity/Package'; -import { NFSAdapter } from '../../../app/common/adapter/NFSAdapter'; -import { ProxyCache } from '../../../app/core/entity/ProxyCache'; -import { TaskService } from '../../../app/core/service/TaskService'; + +import { TestUtil } from '../../TestUtil.js'; +import { ProxyCacheService } from '../../../app/core/service/ProxyCacheService.js'; +import { ProxyCacheRepository } from '../../../app/repository/ProxyCacheRepository.js'; +import { DIST_NAMES } from '../../../app/core/entity/Package.js'; +import { NFSAdapter } from '../../../app/common/adapter/NFSAdapter.js'; +import { ProxyCache } from '../../../app/core/entity/ProxyCache.js'; +import { TaskService } from '../../../app/core/service/TaskService.js'; describe('test/core/service/ProxyCacheService/index.test.ts', () => { let proxyCacheService: ProxyCacheService; diff --git a/test/core/service/RegistryManagerService/index.test.ts b/test/core/service/RegistryManagerService/index.test.ts index 4203eec4..a63abb3e 100644 --- a/test/core/service/RegistryManagerService/index.test.ts +++ b/test/core/service/RegistryManagerService/index.test.ts @@ -1,12 +1,13 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { ScopeManagerService } from '../../../../app/core/service/ScopeManagerService'; -import { Registry } from '../../../../app/core/entity/Registry'; -import { TaskRepository } from '../../../../app/repository/TaskRepository'; -import { TaskType } from '../../../../app/common/enum/Task'; -import { ChangesStreamTaskData } from '../../../../app/core/entity/Task'; + +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { ScopeManagerService } from '../../../../app/core/service/ScopeManagerService.js'; +import { Registry } from '../../../../app/core/entity/Registry.js'; +import { TaskRepository } from '../../../../app/repository/TaskRepository.js'; +import { TaskType } from '../../../../app/common/enum/Task.js'; +import { ChangesStreamTaskData } from '../../../../app/core/entity/Task.js'; describe('test/core/service/RegistryManagerService/index.test.ts', () => { let registryManagerService: RegistryManagerService; @@ -47,25 +48,25 @@ describe('test/core/service/RegistryManagerService/index.test.ts', () => { it('query success', async () => { // query success const queryRes = await registryManagerService.listRegistries({}); - assert(queryRes.count === 2); + assert.equal(queryRes.count, 2); const [ _, registry ] = queryRes.data; assert(_); - assert(registry.name === 'custom2'); + assert.equal(registry.name, 'custom2'); }); it('pageOptions should work', async () => { // pageOptions should work let queryRes = await registryManagerService.listRegistries({ pageIndex: 0, pageSize: 1 }); - assert(queryRes.count === 2); - assert(queryRes.data.length === 1); + assert.equal(queryRes.count, 2); + assert.equal(queryRes.data.length, 1); const [ firstRegistry ] = queryRes.data; - assert(firstRegistry.name === 'custom'); + assert.equal(firstRegistry.name, 'custom'); queryRes = await registryManagerService.listRegistries({ pageIndex: 1, pageSize: 1 }); - assert(queryRes.count === 2); - assert(queryRes.data.length === 1); + assert.equal(queryRes.count, 2); + assert.equal(queryRes.data.length, 1); const [ secondRegistry ] = queryRes.data; - assert(secondRegistry.name === 'custom2'); + assert.equal(secondRegistry.name, 'custom2'); }); }); @@ -80,13 +81,12 @@ describe('test/core/service/RegistryManagerService/index.test.ts', () => { }); queryRes = await registryManagerService.listRegistries({}); - assert(queryRes.data[0].name === 'custom3'); - + assert.equal(queryRes.data[0].name, 'custom3'); }); it('update should check registry', async () => { const queryRes = await registryManagerService.listRegistries({}); - assert(queryRes.count === 1); + assert.equal(queryRes.count, 1); const [ registry ] = queryRes.data; await assert.rejects( registryManagerService.updateRegistry('not_exist', { @@ -99,10 +99,10 @@ describe('test/core/service/RegistryManagerService/index.test.ts', () => { it('remove should work', async () => { let queryRes = await registryManagerService.listRegistries({}); - assert(queryRes.count === 1); + assert.equal(queryRes.count, 1); await registryManagerService.remove({ registryId: queryRes.data[0].registryId }); queryRes = await registryManagerService.listRegistries({}); - assert(queryRes.count === 0); + assert.equal(queryRes.count, 0); }); describe('createSyncChangesStream()', async () => { @@ -119,11 +119,13 @@ describe('test/core/service/RegistryManagerService/index.test.ts', () => { const targetName = 'CUSTOM_WORKER'; const task = await taskRepository.findTaskByTargetName(targetName, TaskType.ChangesStream); assert(task); - assert((task.data as ChangesStreamTaskData).registryId === registry.registryId); + assert.equal((task.data as ChangesStreamTaskData).registryId, registry.registryId); }); it('should preCheck registry', async () => { - await assert.rejects(registryManagerService.createSyncChangesStream({ registryId: 'mock_invalid_registry_id' }), /not found/); + await assert.rejects(registryManagerService.createSyncChangesStream({ registryId: 'mock_invalid_registry_id' }), + /not found/, + ); }); it('should preCheck scopes', async () => { @@ -134,17 +136,21 @@ describe('test/core/service/RegistryManagerService/index.test.ts', () => { userPrefix: 'cnpm:', type: RegistryType.Cnpmcore, }); - await assert.rejects(registryManagerService.createSyncChangesStream({ registryId: newRegistry.registryId }), /please create scopes first/); + await assert.rejects(registryManagerService.createSyncChangesStream({ registryId: newRegistry.registryId }), + /please create scopes first/, + ); }); it('should create only once', async () => { // create success await registryManagerService.createSyncChangesStream({ registryId: registry.registryId }); await registryManagerService.createSyncChangesStream({ registryId: registry.registryId }); + // won't create new task await registryManagerService.createSyncChangesStream({ registryId: registry.registryId, since: '100' }); const targetName = 'CUSTOM_WORKER'; const task = await taskRepository.findTaskByTargetName(targetName, TaskType.ChangesStream); - assert((task?.data as ChangesStreamTaskData).since === ''); + assert(task); + assert.equal((task.data as ChangesStreamTaskData).since, ''); }); }); }); diff --git a/test/core/service/ScopeManagerService/index.test.ts b/test/core/service/ScopeManagerService/index.test.ts index 189419c1..8c35ada1 100644 --- a/test/core/service/ScopeManagerService/index.test.ts +++ b/test/core/service/ScopeManagerService/index.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { ScopeManagerService } from '../../../../app/core/service/ScopeManagerService'; + +import { ScopeManagerService } from '../../../../app/core/service/ScopeManagerService.js'; describe('test/core/service/ScopeManagerService/index.test.ts', () => { let scopeManagerService: ScopeManagerService; diff --git a/test/core/service/TaskService/findExecuteTask.test.ts b/test/core/service/TaskService/findExecuteTask.test.ts index e152a2e5..9193f6e5 100644 --- a/test/core/service/TaskService/findExecuteTask.test.ts +++ b/test/core/service/TaskService/findExecuteTask.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app, mm } from '@eggjs/mock/bootstrap'; -import { TaskService } from '../../../../app/core/service/TaskService'; -import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService'; -import { TaskState, TaskType } from '../../../../app/common/enum/Task'; -import { RedisQueueAdapter } from '../../../../app/infra/QueueAdapter'; + +import { TaskService } from '../../../../app/core/service/TaskService.js'; +import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService.js'; +import { TaskState, TaskType } from '../../../../app/common/enum/Task.js'; +import { RedisQueueAdapter } from '../../../../app/infra/QueueAdapter.js'; describe('test/core/service/TaskService/findExecuteTask.test.ts', () => { let taskService: TaskService; @@ -74,7 +75,7 @@ describe('test/core/service/TaskService/findExecuteTask.test.ts', () => { const executeTask = await taskService.findExecuteTask(task1.type); // 直接返回下一个 task2 - assert(executeTask?.taskId === task2.taskId); + assert.equal(executeTask?.taskId, task2.taskId); }); it('should return null when no valid task', async () => { @@ -85,7 +86,7 @@ describe('test/core/service/TaskService/findExecuteTask.test.ts', () => { const executeTask = await taskService.findExecuteTask(task1.type); // 直接返回下一个 task2 - assert(executeTask === null); + assert.equal(executeTask, null); }); it('should not task which take be other', async () => { @@ -101,7 +102,7 @@ describe('test/core/service/TaskService/findExecuteTask.test.ts', () => { taskService.findExecuteTask(task1.type), taskService.findExecuteTask(task1.type), ]); - assert(tasks[0]?.taskId !== task1[1]?.taskId); + assert(tasks[0]?.taskId !== tasks[1]?.taskId); }); }); }); diff --git a/test/core/util/EntityUtil.test.ts b/test/core/util/EntityUtil.test.ts index 30aaab8f..0b32d0f6 100644 --- a/test/core/util/EntityUtil.test.ts +++ b/test/core/util/EntityUtil.test.ts @@ -1,5 +1,6 @@ import { strict as assert } from 'node:assert'; -import { EntityUtil } from '../../../app/core/util/EntityUtil'; + +import { EntityUtil } from '../../../app/core/util/EntityUtil.js'; describe('test/core/util/EntityUtil.test.ts', () => { describe('convertPageOptionsToLimitOption', () => { diff --git a/test/infra/QueueAdapter.test.ts b/test/infra/QueueAdapter.test.ts index fdc19efc..26ea133e 100644 --- a/test/infra/QueueAdapter.test.ts +++ b/test/infra/QueueAdapter.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { RedisQueueAdapter } from '../../app/infra/QueueAdapter'; + +import { RedisQueueAdapter } from '../../app/infra/QueueAdapter.js'; describe('test/infra/QueueAdapter.test.ts', () => { let queueAdapter: RedisQueueAdapter; diff --git a/test/port/controller/AccessController/listCollaborators.test.ts b/test/port/controller/AccessController/listCollaborators.test.ts index a442af71..694fd26a 100644 --- a/test/port/controller/AccessController/listCollaborators.test.ts +++ b/test/port/controller/AccessController/listCollaborators.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/AccessController/listCollaborators.test.ts', () => { describe('[GET /-/package/:fullname/collaborators] listCollaborators()', () => { @@ -35,7 +36,7 @@ describe('test/port/controller/AccessController/listCollaborators.test.ts', () = .send(pkg) .expect(201); assert.equal(createRes.body.ok, true); - assert.match(createRes.body.rev, /^\d+\-\w{24}$/); + assert.match(createRes.body.rev, /^\d+-\w{24}$/); const rev = createRes.body.rev; // updateMaintainers diff --git a/test/port/controller/AccessController/listPackagesByUser.test.ts b/test/port/controller/AccessController/listPackagesByUser.test.ts index 92968252..36a853e9 100644 --- a/test/port/controller/AccessController/listPackagesByUser.test.ts +++ b/test/port/controller/AccessController/listPackagesByUser.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/AccessController/listPackagesByUser.test.ts', () => { describe('[GET /-/org/:username/package] listPackagesByUser()', () => { diff --git a/test/port/controller/BinarySyncController/showBinary.test.ts b/test/port/controller/BinarySyncController/showBinary.test.ts index 9aaf70bf..c0b9ed61 100644 --- a/test/port/controller/BinarySyncController/showBinary.test.ts +++ b/test/port/controller/BinarySyncController/showBinary.test.ts @@ -1,12 +1,13 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { BinarySyncerService } from '../../../../app/core/service/BinarySyncerService'; -import { NodeBinary } from '../../../../app/common/adapter/binary/NodeBinary'; -import { SqlcipherBinary } from '../../../../app/common/adapter/binary/SqlcipherBinary'; -import { BinaryRepository } from '../../../../app/repository/BinaryRepository'; -import { Binary } from '../../../../app/core/entity/Binary'; -import { NFSClientAdapter } from '../../../../app/infra/NFSClientAdapter'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { BinarySyncerService } from '../../../../app/core/service/BinarySyncerService.js'; +import { NodeBinary } from '../../../../app/common/adapter/binary/NodeBinary.js'; +import { SqlcipherBinary } from '../../../../app/common/adapter/binary/SqlcipherBinary.js'; +import { BinaryRepository } from '../../../../app/repository/BinaryRepository.js'; +import { Binary } from '../../../../app/core/entity/Binary.js'; +import { NFSClientAdapter } from '../../../../app/infra/NFSClientAdapter.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/BinarySyncController/showBinary.test.ts', () => { let binarySyncerService: BinarySyncerService; diff --git a/test/port/controller/ChangesStreamController/listChanges.test.ts b/test/port/controller/ChangesStreamController/listChanges.test.ts index fbb05ade..a8163039 100644 --- a/test/port/controller/ChangesStreamController/listChanges.test.ts +++ b/test/port/controller/ChangesStreamController/listChanges.test.ts @@ -1,58 +1,56 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/ChangesStreamController/listChanges.test.ts', () => { describe('[GET /_changes] listChanges()', () => { it('should 422 when since is not number', async () => { const res = await app.httpRequest() .get('/_changes?since=abc'); - assert(res.status === 422); - assert(res.body.error === '[INVALID_PARAM] since: must be integer'); + assert.equal(res.status, 422); + assert.equal(res.body.error, '[INVALID_PARAM] since: must be integer'); }); it('should 200', async () => { let res = await app.httpRequest() .get('/_changes'); - assert(res.status === 200); - assert(res.body.results.length === 0); + assert.equal(res.status, 200); + assert.equal(res.body.results.length, 0); res = await app.httpRequest() .get('/_changes?since=100'); - assert(res.status === 200); - assert(res.body.results.length === 0); + assert.equal(res.status, 200); + assert.equal(res.body.results.length, 0); const { pkg } = await TestUtil.createPackage(); - const eventWaiter = await app.getEventWaiter(); - await eventWaiter.await('PACKAGE_VERSION_ADDED'); res = await app.httpRequest() .get('/_changes'); - assert(res.status === 200); - assert(res.body.results.length === 1); - assert(res.body.results[0].type === 'PACKAGE_VERSION_ADDED'); - assert(res.body.results[0].id === pkg.name); + assert.equal(res.status, 200); + assert.equal(res.body.results.length, 1); + assert.equal(res.body.results[0].type, 'PACKAGE_VERSION_ADDED'); + assert.equal(res.body.results[0].id, pkg.name); assert(res.body.results[0].seq); - assert(res.body.results[0].changes.length === 1); + assert.equal(res.body.results[0].changes.length, 1); const since = res.body.results[0].seq; res = await app.httpRequest() .get('/_changes') .query({ since }); - assert(res.status === 200); - assert(res.body.results.length === 1); + assert.equal(res.status, 200); + assert.equal(res.body.results.length, 1); await TestUtil.createPackage({ name: '@cnpm/other-package' }); - await eventWaiter.await('PACKAGE_VERSION_ADDED'); res = await app.httpRequest() .get('/_changes') .query({ since }); - assert(res.status === 200); - assert(res.body.results.length === 2); - assert(res.body.results[0].type === 'PACKAGE_VERSION_ADDED'); + assert.equal(res.status, 200); + assert.equal(res.body.results.length, 2); + assert.equal(res.body.results[0].type, 'PACKAGE_VERSION_ADDED'); res = await app.httpRequest() .get('/_changes'); - assert(res.status === 200); - assert(res.body.results.length === 2); + assert.equal(res.status, 200); + assert.equal(res.body.results.length, 2); }); }); }); diff --git a/test/port/controller/DownloadController/showPackageDownloads.test.ts b/test/port/controller/DownloadController/showPackageDownloads.test.ts index d1285e06..266862ba 100644 --- a/test/port/controller/DownloadController/showPackageDownloads.test.ts +++ b/test/port/controller/DownloadController/showPackageDownloads.test.ts @@ -1,12 +1,17 @@ import { strict as assert } from 'node:assert'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; import { app, mock } from '@eggjs/mock/bootstrap'; -import dayjs from '../../../../app/common/dayjs'; -import { TestUtil } from '../../../../test/TestUtil'; -const SavePackageVersionDownloadCounterPath = require.resolve('../../../../app/port/schedule/SavePackageVersionDownloadCounter'); +import dayjs from '../../../../app/common/dayjs.js'; +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const SavePackageVersionDownloadCounterPath = path.join(__dirname, '../../../../app/port/schedule/SavePackageVersionDownloadCounter.ts'); describe('test/port/controller/DownloadController/showPackageDownloads.test.ts', () => { - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); }); diff --git a/test/port/controller/HomeController/showTotal.test.ts b/test/port/controller/HomeController/showTotal.test.ts index 224520e7..8d3701d4 100644 --- a/test/port/controller/HomeController/showTotal.test.ts +++ b/test/port/controller/HomeController/showTotal.test.ts @@ -1,19 +1,23 @@ import { strict as assert } from 'node:assert'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { version as EggVersion } from 'egg/package.json'; -import { TestUtil } from '../../../../test/TestUtil'; -import { PackageVersionDownload } from '../../../../app/repository/model/PackageVersionDownload'; -import dayjs from '../../../../app/common/dayjs'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; -import { ChangesStreamService } from '../../../../app/core/service/ChangesStreamService'; -import { TaskRepository } from '../../../../app/repository/TaskRepository'; -import { TaskType } from '../../../../app/common/enum/Task'; -import { ChangesStreamTask } from '../../../../app/core/entity/Task'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { ScopeManagerService } from '../../../../app/core/service/ScopeManagerService'; +import { TestUtil } from '../../../../test/TestUtil.js'; +import { PackageVersionDownload } from '../../../../app/repository/model/PackageVersionDownload.js'; +import dayjs from '../../../../app/common/dayjs.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; +import { ChangesStreamService } from '../../../../app/core/service/ChangesStreamService.js'; +import { TaskRepository } from '../../../../app/repository/TaskRepository.js'; +import { TaskType } from '../../../../app/common/enum/Task.js'; +import { ChangesStreamTask } from '../../../../app/core/entity/Task.js'; +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { ScopeManagerService } from '../../../../app/core/service/ScopeManagerService.js'; -const SavePackageVersionDownloadCounterPath = require.resolve('../../../../app/port/schedule/SavePackageVersionDownloadCounter'); -const UpdateTotalDataPath = require.resolve('../../../../app/port/schedule/UpdateTotalData'); +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const SavePackageVersionDownloadCounterPath = path.join(__dirname, '../../../../app/port/schedule/SavePackageVersionDownloadCounter.js'); +const UpdateTotalDataPath = path.join(__dirname, '../../../../app/port/schedule/UpdateTotalData.js'); describe('test/port/controller/HomeController/showTotal.test.ts', () => { describe('[GET /] showTotal()', () => { @@ -32,7 +36,7 @@ describe('test/port/controller/HomeController/showTotal.test.ts', () => { assert(typeof data.download.today === 'number'); assert(data.engine === app.config.orm.client); assert(data.node_version === process.version); - assert(data.egg_version === EggVersion); + assert.match(data.egg_version, /^\d+\.\d+\.\d+/); assert(data.instance_start_time); assert(data.sync_model === 'none'); assert(data.sync_binary === false); @@ -99,7 +103,7 @@ describe('test/port/controller/HomeController/showTotal.test.ts', () => { const lastMonthDate = today.subtract(1, 'month').startOf('month').format('DD'); const lastYearYearMonthInt = Number(today.subtract(1, 'year').startOf('year').format('YYYYMM')); const lastYearDate = today.subtract(1, 'month').startOf('year').format('DD'); - let row = await PackageVersionDownload.findOne({ packageId: 'total', yearMonth: yesterdayYearMonthInt }); + let row: any = await PackageVersionDownload.findOne({ packageId: 'total', yearMonth: yesterdayYearMonthInt }); if (!row) { row = await PackageVersionDownload.create({ packageId: 'total', @@ -254,12 +258,12 @@ describe('test/port/controller/HomeController/showTotal.test.ts', () => { .expect('content-type', 'application/json; charset=utf-8'); const data = res.body; assert(data.upstream_registries.length === 2); - const [ defaultRegistry ] = data.upstream_registries.filter(item => item.registry_name === 'default'); + const [ defaultRegistry ] = data.upstream_registries.filter((item: any) => item.registry_name === 'default'); assert(defaultRegistry.registry_name === 'default'); assert(defaultRegistry.changes_stream_url === 'https://replicate.npmjs.com/_changes'); assert(defaultRegistry.source_registry === 'https://registry.npmjs.org'); - const [ customRegistry ] = data.upstream_registries.filter(item => item.registry_name === 'custom'); + const [ customRegistry ] = data.upstream_registries.filter((item: any) => item.registry_name === 'custom'); assert(customRegistry.registry_name === 'custom'); assert(customRegistry.changes_stream_url === 'https://r.cnpmjs.org/_changes'); assert(customRegistry.source_registry === 'https://cnpmjs.org'); diff --git a/test/port/controller/PackageBlockController/blockPackage.test.ts b/test/port/controller/PackageBlockController/blockPackage.test.ts index aa24637b..ea006e4b 100644 --- a/test/port/controller/PackageBlockController/blockPackage.test.ts +++ b/test/port/controller/PackageBlockController/blockPackage.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/PackageBlockController/blockPackage.test.ts', () => { let adminUser: any; diff --git a/test/port/controller/PackageBlockController/unblockPackage.test.ts b/test/port/controller/PackageBlockController/unblockPackage.test.ts index 996ade5d..9a4403b7 100644 --- a/test/port/controller/PackageBlockController/unblockPackage.test.ts +++ b/test/port/controller/PackageBlockController/unblockPackage.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/PackageBlockController/unblockPackage.test.ts', () => { let adminUser: any; diff --git a/test/port/controller/PackageSyncController/createSyncTask.test.ts b/test/port/controller/PackageSyncController/createSyncTask.test.ts index 3de01b95..20c28d9b 100644 --- a/test/port/controller/PackageSyncController/createSyncTask.test.ts +++ b/test/port/controller/PackageSyncController/createSyncTask.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { setTimeout } from 'node:timers/promises'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { Task as TaskModel } from '../../../../app/repository/model/Task'; -import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { Task as TaskModel } from '../../../../app/repository/model/Task.js'; +import { PackageSyncerService } from '../../../../app/core/service/PackageSyncerService.js'; describe('test/port/controller/PackageSyncController/createSyncTask.test.ts', () => { let publisher: any; diff --git a/test/port/controller/PackageSyncController/showSyncTask.test.ts b/test/port/controller/PackageSyncController/showSyncTask.test.ts index 7d80f3a3..9cd8332d 100644 --- a/test/port/controller/PackageSyncController/showSyncTask.test.ts +++ b/test/port/controller/PackageSyncController/showSyncTask.test.ts @@ -1,13 +1,18 @@ import { strict as assert } from 'node:assert'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { TaskRepository } from '../../../../app/repository/TaskRepository'; -import { TaskState } from '../../../../app/common/enum/Task'; -const SyncPackageWorkerPath = require.resolve('../../../../app/port/schedule/SyncPackageWorker'); +import { TestUtil, TestUser } from '../../../../test/TestUtil.js'; +import { TaskRepository } from '../../../../app/repository/TaskRepository.js'; +import { TaskState } from '../../../../app/common/enum/Task.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const SyncPackageWorkerPath = path.join(__dirname, '../../../../app/port/schedule/SyncPackageWorker.ts'); describe('test/port/controller/PackageSyncController/showSyncTask.test.ts', () => { - let publisher; + let publisher: TestUser; let taskRepository: TaskRepository; beforeEach(async () => { publisher = await TestUtil.createUser(); diff --git a/test/port/controller/PackageSyncController/showSyncTaskLog.test.ts b/test/port/controller/PackageSyncController/showSyncTaskLog.test.ts index a37d2514..76a61fe7 100644 --- a/test/port/controller/PackageSyncController/showSyncTaskLog.test.ts +++ b/test/port/controller/PackageSyncController/showSyncTaskLog.test.ts @@ -1,12 +1,13 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { TaskRepository } from '../../../../app/repository/TaskRepository'; -import { TaskState } from '../../../../app/common/enum/Task'; -import { NFSAdapter } from '../../../../app/common/adapter/NFSAdapter'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; +import { TaskRepository } from '../../../../app/repository/TaskRepository.js'; +import { TaskState } from '../../../../app/common/enum/Task.js'; +import { NFSAdapter } from '../../../../app/common/adapter/NFSAdapter.js'; describe('test/port/controller/PackageSyncController/showSyncTaskLog.test.ts', () => { - let publisher; + let publisher: TestUser; let taskRepository: TaskRepository; let nfsAdapter: NFSAdapter; beforeEach(async () => { diff --git a/test/port/controller/PackageTagController/removeTag.test.ts b/test/port/controller/PackageTagController/removeTag.test.ts index e5ee76b0..151ac9ec 100644 --- a/test/port/controller/PackageTagController/removeTag.test.ts +++ b/test/port/controller/PackageTagController/removeTag.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/PackageTagController/removeTag.test.ts', () => { - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); }); diff --git a/test/port/controller/PackageTagController/saveTag.test.ts b/test/port/controller/PackageTagController/saveTag.test.ts index efb401ac..3894c23b 100644 --- a/test/port/controller/PackageTagController/saveTag.test.ts +++ b/test/port/controller/PackageTagController/saveTag.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/PackageTagController/saveTag.test.ts', () => { - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); }); diff --git a/test/port/controller/PackageTagController/showTags.test.ts b/test/port/controller/PackageTagController/showTags.test.ts index 4f35c420..93140767 100644 --- a/test/port/controller/PackageTagController/showTags.test.ts +++ b/test/port/controller/PackageTagController/showTags.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/PackageTagController/showTags.test.ts', () => { - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); }); diff --git a/test/port/controller/PackageVersionFileController/listFiles.test.ts b/test/port/controller/PackageVersionFileController/listFiles.test.ts index 74793434..08a835bc 100644 --- a/test/port/controller/PackageVersionFileController/listFiles.test.ts +++ b/test/port/controller/PackageVersionFileController/listFiles.test.ts @@ -1,14 +1,15 @@ import { strict as assert } from 'node:assert'; import { setTimeout } from 'node:timers/promises'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { PackageVersionFileService } from '../../../../app/core/service/PackageVersionFileService'; -import { calculateIntegrity } from '../../../../app/common/PackageUtil'; -import { database, DATABASE_TYPE } from '../../../../config/database'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; +import { PackageVersionFileService } from '../../../../app/core/service/PackageVersionFileService.js'; +import { calculateIntegrity } from '../../../../app/common/PackageUtil.js'; +import { database, DATABASE_TYPE } from '../../../../config/database.js'; describe('test/port/controller/PackageVersionFileController/listFiles.test.ts', () => { - let publisher; - let adminUser; + let publisher: TestUser; + let adminUser: TestUser; beforeEach(async () => { adminUser = await TestUtil.createAdmin(); publisher = await TestUtil.createUser(); diff --git a/test/port/controller/PackageVersionFileController/raw.test.ts b/test/port/controller/PackageVersionFileController/raw.test.ts index 26eaf077..5187bb0d 100644 --- a/test/port/controller/PackageVersionFileController/raw.test.ts +++ b/test/port/controller/PackageVersionFileController/raw.test.ts @@ -1,13 +1,17 @@ import { strict as assert } from 'node:assert'; import { setTimeout } from 'node:timers/promises'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { calculateIntegrity } from '../../../../app/common/PackageUtil'; -import { PackageTagChangedSyncPackageVersionFileEvent, PackageTagAddedSyncPackageVersionFileEvent } from '../../../../app/core/event/SyncPackageVersionFile'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; +import { calculateIntegrity } from '../../../../app/common/PackageUtil.js'; +import { + PackageTagChangedSyncPackageVersionFileEvent, + PackageTagAddedSyncPackageVersionFileEvent, +} from '../../../../app/core/event/SyncPackageVersionFile.js'; describe('test/port/controller/PackageVersionFileController/raw.test.ts', () => { - let publisher; - let adminUser; + let publisher: TestUser; + let adminUser: TestUser; beforeEach(async () => { adminUser = await TestUtil.createAdmin(); publisher = await TestUtil.createUser(); @@ -286,7 +290,7 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () => .get(`/${pkg.name}/1.0.0/files/resource/`); assert.equal(res.status, 200); // console.log(res.body); - assert(res.body.files.find(file => file.path === '/resource/ToOneFromχ.js')); + assert(res.body.files.find((file: { path: string }) => file.path === '/resource/ToOneFromχ.js')); // res = await app.httpRequest() // .get(`/${pkg.name}/1.0.0/files/resource/ToOneFromχ.js`); res = await app.httpRequest() @@ -366,8 +370,8 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () => .get(`/${pkg.name}/1.0.0/files/`); assert.equal(res.status, 200); // console.log(res.body); - assert.equal(res.body.files.find(file => file.path === '/.'), undefined); - assert(res.body.files.find(file => file.path === '/dist')); + assert.equal(res.body.files.find((file: { path: string }) => file.path === '/.'), undefined); + assert(res.body.files.find((file: { path: string }) => file.path === '/dist')); const packageTagAdded = await app.getEggObject(PackageTagAddedSyncPackageVersionFileEvent); await packageTagAdded.handle(pkg.name, 'foo'); await packageTagAdded.handle(pkg.name, 'latest'); @@ -415,8 +419,8 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () => .get(`/${pkg.name}/1.0.0/files/`); assert.equal(res.status, 200); // console.log('%o', res.body); - assert(res.body.files.find(file => file.path === '/CONTRIBUTING.md')); - let testDir = res.body.files.find(file => file.path === '/tests'); + assert(res.body.files.find((file: { path: string }) => file.path === '/CONTRIBUTING.md')); + let testDir = res.body.files.find((file: { path: string }) => file.path === '/tests'); assert(testDir); assert.equal(testDir.files.length, 0); assert.equal(res.headers['cache-control'], 'public, s-maxage=600, max-age=60'); @@ -442,8 +446,8 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () => .get(`/${pkg.name}/1.0.0/files?meta=true`); assert.equal(res.status, 200); // console.log('%o', res.body); - assert(res.body.files.find(file => file.path === '/CONTRIBUTING.md')); - testDir = res.body.files.find(file => file.path === '/tests'); + assert(res.body.files.find((file: { path: string }) => file.path === '/CONTRIBUTING.md')); + testDir = res.body.files.find((file: { path: string }) => file.path === '/tests'); assert(testDir); assert.equal(testDir.files.length, 0); assert.equal(res.headers['cache-control'], 'public, s-maxage=600, max-age=60'); @@ -505,7 +509,7 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () => assert.equal(res.headers.vary, 'Origin, Accept, Accept-Encoding'); assert.equal(res.body.path, '/tests'); // make sure sub dirs exists - const integrationDir = res.body.files.find(file => file.path === '/tests/integration'); + const integrationDir = res.body.files.find((file: { path: string }) => file.path === '/tests/integration'); assert(integrationDir); assert.equal(integrationDir.files.length, 0); assert.equal(integrationDir.type, 'directory'); @@ -583,7 +587,7 @@ describe('test/port/controller/PackageVersionFileController/raw.test.ts', () => assert.equal(res.headers['content-type'], 'application/x-sh'); assert(!res.headers['content-disposition']); assert.equal(res.headers['transfer-encoding'], 'chunked'); - assert.match(res.text, /#\!\/bin\/bash/); + assert.match(res.text, /#!\/bin\/bash/); res = await app.httpRequest() .get(`/${pkg.name}/1.0.0/files/docs/manifest.appcache`); diff --git a/test/port/controller/PackageVersionFileController/sync.test.ts b/test/port/controller/PackageVersionFileController/sync.test.ts index 09f7cd2d..106a9ab6 100644 --- a/test/port/controller/PackageVersionFileController/sync.test.ts +++ b/test/port/controller/PackageVersionFileController/sync.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/PackageVersionFileController/sync.test.ts', () => { - let publisher; - let adminUser; + let publisher: TestUser; + let adminUser: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); adminUser = await TestUtil.createAdmin(); diff --git a/test/port/controller/ProxyCacheController/index.test.ts b/test/port/controller/ProxyCacheController/index.test.ts index b0f738b0..bd797e0d 100644 --- a/test/port/controller/ProxyCacheController/index.test.ts +++ b/test/port/controller/ProxyCacheController/index.test.ts @@ -1,12 +1,12 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -// import { TestUtil } from '../../../../test/TestUtil'; -import { DIST_NAMES } from '../../../../app/core/entity/Package'; -import { ProxyCache } from '../../../../app/core/entity/ProxyCache'; -import { ProxyCacheRepository } from '../../../../app/repository/ProxyCacheRepository'; -import { TaskRepository } from '../../../../app/repository/TaskRepository'; -import { SyncMode } from '../../../../app/common/constants'; -import { TestUtil } from '../../../TestUtil'; + +import { DIST_NAMES } from '../../../../app/core/entity/Package.js'; +import { ProxyCache } from '../../../../app/core/entity/ProxyCache.js'; +import { ProxyCacheRepository } from '../../../../app/repository/ProxyCacheRepository.js'; +import { TaskRepository } from '../../../../app/repository/TaskRepository.js'; +import { SyncMode } from '../../../../app/common/constants.js'; +import { TestUtil } from '../../../TestUtil.js'; describe('test/port/controller/PackageVersionFileController/listFiles.test.ts', () => { let proxyCacheRepository: ProxyCacheRepository; diff --git a/test/port/controller/RegistryController/index.test.ts b/test/port/controller/RegistryController/index.test.ts index 1a2d0a3f..c7b42253 100644 --- a/test/port/controller/RegistryController/index.test.ts +++ b/test/port/controller/RegistryController/index.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TaskType } from '../../../../app/common/enum/Task'; -import { Registry } from '../../../../app/core/entity/Registry'; -import { ChangesStreamTaskData } from '../../../../app/core/entity/Task'; -import { TaskService } from '../../../../app/core/service/TaskService'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TaskType } from '../../../../app/common/enum/Task.js'; +import { Registry } from '../../../../app/core/entity/Registry.js'; +import { ChangesStreamTaskData } from '../../../../app/core/entity/Task.js'; +import { TaskService } from '../../../../app/core/service/TaskService.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/RegistryController/index.test.ts', () => { let adminUser: any; @@ -240,8 +241,9 @@ describe('test/port/controller/RegistryController/index.test.ts', () => { .expect(200); const task = await taskService.findExecuteTask(TaskType.ChangesStream); - assert(task?.targetName === 'CUSTOM3_WORKER'); - assert((task?.data as ChangesStreamTaskData).since === '9527'); + assert(task); + assert.equal(task.targetName, 'CUSTOM3_WORKER'); + assert.equal((task.data as ChangesStreamTaskData).since, '9527'); }); }); diff --git a/test/port/controller/ScopeController/index.test.ts b/test/port/controller/ScopeController/index.test.ts index af6474b2..9f4fc39b 100644 --- a/test/port/controller/ScopeController/index.test.ts +++ b/test/port/controller/ScopeController/index.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; -import { TestUtil } from '../../../TestUtil'; -import { Scope } from '../../../../app/core/entity/Scope'; + +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; +import { TestUtil } from '../../../TestUtil.js'; +import { Scope } from '../../../../app/core/entity/Scope.js'; describe('test/port/controller/ScopeController/index.test.ts', () => { let adminUser: any; diff --git a/test/port/controller/TokenController/createToken.test.ts b/test/port/controller/TokenController/createToken.test.ts index 87bb6df2..5377717d 100644 --- a/test/port/controller/TokenController/createToken.test.ts +++ b/test/port/controller/TokenController/createToken.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import dayjs from 'dayjs'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { Token, TokenType } from '../../../../app/core/entity/Token'; -import { AuthAdapter } from '../../../../app/infra/AuthAdapter'; -import { UserRepository } from '../../../../app/repository/UserRepository'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { Token, TokenType } from '../../../../app/core/entity/Token.js'; +import { AuthAdapter } from '../../../../app/infra/AuthAdapter.js'; +import { UserRepository } from '../../../../app/repository/UserRepository.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/TokenController/createToken.test.ts', () => { describe('[POST /-/npm/v1/tokens] createToken()', () => { @@ -100,7 +101,7 @@ describe('test/port/controller/TokenController/createToken.test.ts', () => { .set('user-agent', ua) .send({ password }) .expect(403); - assert.match(res.body.error, /\[FORBIDDEN\] Read-only Token \"cnpm_\w+\" can\'t setting/); + assert.match(res.body.error, /\[FORBIDDEN\] Read-only Token "cnpm_\w+" can't setting/); }); }); @@ -203,7 +204,7 @@ describe('test/port/controller/TokenController/createToken.test.ts', () => { .get('/-/npm/v1/tokens/gat') .expect(200); - granularToken = res.body.objects.find(token => token.type === TokenType.granular); + granularToken = res.body.objects.find((token: Token) => token.type === TokenType.granular); assert(granularToken?.lastUsedAt); assert(dayjs(granularToken?.lastUsedAt).isAfter(start)); diff --git a/test/port/controller/TokenController/listTokens.test.ts b/test/port/controller/TokenController/listTokens.test.ts index 7404955b..0b92acb9 100644 --- a/test/port/controller/TokenController/listTokens.test.ts +++ b/test/port/controller/TokenController/listTokens.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; import dayjs from 'dayjs'; -import { TokenType } from '../../../../app/core/entity/Token'; -import { UserService } from '../../../../app/core/service/UserService'; -import { AuthAdapter } from '../../../../app/infra/AuthAdapter'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TokenType } from '../../../../app/core/entity/Token.js'; +import { UserService } from '../../../../app/core/service/UserService.js'; +import { AuthAdapter } from '../../../../app/infra/AuthAdapter.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/TokenController/listTokens.test.ts', () => { describe('[GET /-/npm/v1/tokens] listTokens()', () => { @@ -60,7 +61,7 @@ describe('test/port/controller/TokenController/listTokens.test.ts', () => { .get('/-/npm/v1/tokens') .set('authorization', authorization) .expect(403); - assert.match(res.body.error, /\[FORBIDDEN\] Read-only Token \"cnpm_\w+\" can\'t setting/); + assert.match(res.body.error, /\[FORBIDDEN\] Read-only Token "cnpm_\w+" can't setting/); }); }); diff --git a/test/port/controller/TokenController/removeToken.test.ts b/test/port/controller/TokenController/removeToken.test.ts index da7b0dbf..5f025bbe 100644 --- a/test/port/controller/TokenController/removeToken.test.ts +++ b/test/port/controller/TokenController/removeToken.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { Token, TokenType } from '../../../../app/core/entity/Token'; -import { UserService } from '../../../../app/core/service/UserService'; -import { AuthAdapter } from '../../../../app/infra/AuthAdapter'; -import { TokenPackage } from '../../../../app/repository/model/TokenPackage'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { Token, TokenType } from '../../../../app/core/entity/Token.js'; +import { UserService } from '../../../../app/core/service/UserService.js'; +import { AuthAdapter } from '../../../../app/infra/AuthAdapter.js'; +import { TokenPackage } from '../../../../app/repository/model/TokenPackage.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/TokenController/removeToken.test.ts', () => { describe('[DELETE /-/npm/v1/tokens/token/:tokenKey] removeToken()', () => { @@ -61,7 +62,7 @@ describe('test/port/controller/TokenController/removeToken.test.ts', () => { .set('authorization', authorization) .set('user-agent', ua) .expect(403); - assert.match(res.body.error, /\[FORBIDDEN\] Read-only Token \"cnpm_\w+\" can\'t setting/); + assert.match(res.body.error, /\[FORBIDDEN\] Read-only Token "cnpm_\w+" can't setting/); }); it('should 403 when automation token access', async () => { @@ -71,7 +72,7 @@ describe('test/port/controller/TokenController/removeToken.test.ts', () => { .set('authorization', authorization) .set('user-agent', ua) .expect(403); - assert.match(res.body.error, /\[FORBIDDEN\] Automation Token \"cnpm_\w+\" can\'t setting/); + assert.match(res.body.error, /\[FORBIDDEN\] Automation Token "cnpm_\w+" can't setting/); }); it('should 404 when token key not exists', async () => { diff --git a/test/port/controller/UserController/logout.test.ts b/test/port/controller/UserController/logout.test.ts index d8f483f5..d05a285c 100644 --- a/test/port/controller/UserController/logout.test.ts +++ b/test/port/controller/UserController/logout.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/UserController/logout.test.ts', () => { describe('[DELETE /-/user/token/:token] logout()', () => { diff --git a/test/port/controller/UserController/saveProfile.test.ts b/test/port/controller/UserController/saveProfile.test.ts index 6adf233f..18a9acee 100644 --- a/test/port/controller/UserController/saveProfile.test.ts +++ b/test/port/controller/UserController/saveProfile.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/UserController/saveProfile.test.ts', () => { describe('[POST /-/npm/v1/user] saveProfile()', () => { diff --git a/test/port/controller/UserController/showProfile.test.ts b/test/port/controller/UserController/showProfile.test.ts index 76eabeb3..fee7f477 100644 --- a/test/port/controller/UserController/showProfile.test.ts +++ b/test/port/controller/UserController/showProfile.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/UserController/showProfile.test.ts', () => { describe('[GET /-/npm/v1/user] showProfile()', () => { diff --git a/test/port/controller/UserController/showUser.test.ts b/test/port/controller/UserController/showUser.test.ts index afddaf67..aa462db9 100644 --- a/test/port/controller/UserController/showUser.test.ts +++ b/test/port/controller/UserController/showUser.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/UserController/showUser.test.ts', () => { describe('[GET /-/user/org.couchdb.user::username] showUser()', () => { diff --git a/test/port/controller/UserController/starredByUser.test.ts b/test/port/controller/UserController/starredByUser.test.ts index 54833320..ae83e2e2 100644 --- a/test/port/controller/UserController/starredByUser.test.ts +++ b/test/port/controller/UserController/starredByUser.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/UserController/starredByUser.test.ts', () => { describe('[GET /-/_view/starredByUser] starredByUser()', () => { diff --git a/test/port/controller/UserController/whoami.test.ts b/test/port/controller/UserController/whoami.test.ts index 1ad832b7..ba2dbf0c 100644 --- a/test/port/controller/UserController/whoami.test.ts +++ b/test/port/controller/UserController/whoami.test.ts @@ -1,8 +1,9 @@ import { strict as assert } from 'node:assert'; import dayjs from 'dayjs'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { AuthAdapter } from '../../../../app/infra/AuthAdapter'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { AuthAdapter } from '../../../../app/infra/AuthAdapter.js'; +import { TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/UserController/whoami.test.ts', () => { describe('[GET /-/whoami] whoami()', () => { diff --git a/test/port/controller/hook/HookController.test.ts b/test/port/controller/hook/HookController.test.ts index 7f0773f2..924cc76a 100644 --- a/test/port/controller/hook/HookController.test.ts +++ b/test/port/controller/hook/HookController.test.ts @@ -1,22 +1,23 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { HookManageService } from '../../../../app/core/service/HookManageService'; -import { Hook } from '../../../../app/core/entity/Hook'; -import { UserRepository } from '../../../../app/repository/UserRepository'; -import { HookType } from '../../../../app/common/enum/Hook'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; +import { HookManageService } from '../../../../app/core/service/HookManageService.js'; +import { Hook } from '../../../../app/core/entity/Hook.js'; +import { UserRepository } from '../../../../app/repository/UserRepository.js'; +import { HookType } from '../../../../app/common/enum/Hook.js'; describe('test/port/controller/hook/HookController.test.ts', () => { let hookManageService: HookManageService; - let user; - let userId; + let user: TestUser; + let userId: string; beforeEach(async () => { user = await TestUtil.createUser(); hookManageService = await app.getEggObject(HookManageService); const userRepository = await app.getEggObject(UserRepository); const userEntity = await userRepository.findUserByName(user.name); - userId = userEntity?.userId; + userId = userEntity!.userId; }); describe('POST /-/npm/v1/hooks/hook', () => { diff --git a/test/port/controller/package/DownloadPackageVersionTarController.test.ts b/test/port/controller/package/DownloadPackageVersionTarController.test.ts index ae7c0014..3378c1ee 100644 --- a/test/port/controller/package/DownloadPackageVersionTarController.test.ts +++ b/test/port/controller/package/DownloadPackageVersionTarController.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { setTimeout } from 'node:timers/promises'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { NFSClientAdapter } from '../../../../app/infra/NFSClientAdapter'; -import { SyncMode } from '../../../../app/common/constants'; + +import { TestUtil } from '../../../../test/TestUtil.js'; +import { NFSClientAdapter } from '../../../../app/infra/NFSClientAdapter.js'; +import { SyncMode } from '../../../../app/common/constants.js'; describe('test/port/controller/package/DownloadPackageVersionTarController.test.ts', () => { let publisher: any; @@ -27,7 +28,7 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test. .expect(201); assert(res.status === 201); assert(res.body.ok === true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); pkg = await TestUtil.getFullPackage({ name: scopedName, version: '1.0.0' }); res = await app.httpRequest() @@ -37,7 +38,7 @@ describe('test/port/controller/package/DownloadPackageVersionTarController.test. .send(pkg); assert(res.status === 201); assert(res.body.ok === true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); }); describe('[GET /:fullname/-/:name-:version.tgz] download()', () => { diff --git a/test/port/controller/package/RemovePackageVersionController.test.ts b/test/port/controller/package/RemovePackageVersionController.test.ts index 6be1d107..eace2432 100644 --- a/test/port/controller/package/RemovePackageVersionController.test.ts +++ b/test/port/controller/package/RemovePackageVersionController.test.ts @@ -1,11 +1,12 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { PackageRepository } from '../../../../app/repository/PackageRepository'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; +import { PackageRepository } from '../../../../app/repository/PackageRepository.js'; describe('test/port/controller/package/RemovePackageVersionController.test.ts', () => { let packageRepository: PackageRepository; - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); packageRepository = await app.getEggObject(PackageRepository); diff --git a/test/port/controller/package/SavePackageVersionController.test.ts b/test/port/controller/package/SavePackageVersionController.test.ts index 9152648c..1e403d64 100644 --- a/test/port/controller/package/SavePackageVersionController.test.ts +++ b/test/port/controller/package/SavePackageVersionController.test.ts @@ -3,20 +3,21 @@ import { setTimeout } from 'node:timers/promises'; import { app, mock } from '@eggjs/mock/bootstrap'; import { ForbiddenError } from 'egg-errors'; import dayjs from 'dayjs'; -import { TestUtil } from '../../../../test/TestUtil'; -import { UserRepository } from '../../../../app/repository/UserRepository'; -import { calculateIntegrity } from '../../../../app/common/PackageUtil'; -import { PackageRepository } from '../../../../app/repository/PackageRepository'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; -import { UserService } from '../../../../app/core/service/UserService'; -import { Token, TokenType } from '../../../../app/core/entity/Token'; -import { Token as TokenModel } from '../../../../app/repository/model/Token'; -import { User } from '../../../../app/core/entity/User'; -import { PackageManagerService } from '../../../../app/core/service/PackageManagerService'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; +import { UserRepository } from '../../../../app/repository/UserRepository.js'; +import { calculateIntegrity } from '../../../../app/common/PackageUtil.js'; +import { PackageRepository } from '../../../../app/repository/PackageRepository.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; +import { UserService } from '../../../../app/core/service/UserService.js'; +import { Token, TokenType } from '../../../../app/core/entity/Token.js'; +import { Token as TokenModel } from '../../../../app/repository/model/Token.js'; +import { User } from '../../../../app/core/entity/User.js'; +import { PackageManagerService } from '../../../../app/core/service/PackageManagerService.js'; describe('test/port/controller/package/SavePackageVersionController.test.ts', () => { let userRepository: UserRepository; - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); userRepository = await app.getEggObject(UserRepository); @@ -173,7 +174,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}/0.0.0`) .expect(200); @@ -194,7 +195,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg2) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); const pkg3 = await TestUtil.getFullPackage({ name, version: '2.0.0', description: '2.0.0 description' }); res = await app.httpRequest() @@ -204,7 +205,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg3) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}/2.0.0`) @@ -290,7 +291,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); }); it('should publish 102 chars length version', async () => { @@ -309,7 +310,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}`) @@ -333,7 +334,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}`) @@ -392,7 +393,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}/0.0.0`) .expect(200); @@ -406,7 +407,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg2) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); }); it('should 422 when dist-tags version not match', async () => { @@ -610,7 +611,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}/0.0.0`) .expect(200); @@ -627,7 +628,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}/0.0.0`) .expect(200); @@ -644,7 +645,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}`) .expect(200); @@ -661,7 +662,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () const pkg = await TestUtil.getFullPackage({ name: '@cnpm/with-readme-object', version: '0.0.0' }); assert(pkg.versions); const version = Object.keys(pkg.versions)[0]; - pkg.versions[version].readme = { foo: 'bar' }; + Reflect.set(pkg.versions[version], 'readme', { foo: 'bar' }); let res = await app.httpRequest() .put(`/${pkg.name}`) .set('authorization', publisher.authorization) @@ -669,7 +670,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}/0.0.0`) .expect(200); @@ -688,7 +689,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}/0.0.0`) .expect(200); @@ -705,7 +706,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}/99.0.0`) .expect(200); @@ -719,7 +720,7 @@ describe('test/port/controller/package/SavePackageVersionController.test.ts', () .set('user-agent', publisher.ua) .send(pkg2) .expect(403); - assert.equal(res.body.error, `[FORBIDDEN] Can\'t modify pre-existing version: ${pkg2.name}@99.0.0`); + assert.equal(res.body.error, `[FORBIDDEN] Can't modify pre-existing version: ${pkg2.name}@99.0.0`); }); it('should 422 when version format error', async () => { diff --git a/test/port/controller/package/SearchPackageController.test.ts b/test/port/controller/package/SearchPackageController.test.ts index 5d4398b4..13699361 100644 --- a/test/port/controller/package/SearchPackageController.test.ts +++ b/test/port/controller/package/SearchPackageController.test.ts @@ -1,11 +1,11 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; import { errors } from '@elastic/elasticsearch'; -import { mockES } from '../../../../config/config.unittest'; -import { TestUtil } from '../../../TestUtil'; +import { mockES } from '../../../../config/config.unittest.js'; +import { TestUser, TestUtil } from '../../../TestUtil.js'; describe('test/port/controller/package/SearchPackageController.test.ts', () => { - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); mock(app.config.cnpmcore, 'enableElasticsearch', true); @@ -110,7 +110,7 @@ describe('test/port/controller/package/SearchPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .put(`/-/v1/search/sync/${name}`); @@ -119,7 +119,7 @@ describe('test/port/controller/package/SearchPackageController.test.ts', () => { }); describe('[DELETE /-/v1/search/sync/:fullname] delete()', async () => { - let admin:Awaited>; + let admin: TestUser; beforeEach(async () => { admin = await TestUtil.createAdmin(); }); diff --git a/test/port/controller/package/ShowPackageController.test.ts b/test/port/controller/package/ShowPackageController.test.ts index 1b6580eb..68c81d9f 100644 --- a/test/port/controller/package/ShowPackageController.test.ts +++ b/test/port/controller/package/ShowPackageController.test.ts @@ -1,17 +1,18 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { PackageManifestType, PackageRepository } from '../../../../app/repository/PackageRepository'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; -import { PackageManagerService } from '../../../../app/core/service/PackageManagerService'; -import { CacheService } from '../../../../app/core/service/CacheService'; -import { DistRepository } from '../../../../app/repository/DistRepository'; -import { BugVersionService } from '../../../../app/core/service/BugVersionService'; -import { SyncMode } from '../../../../app/common/constants'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; +import { PackageManifestType, PackageRepository } from '../../../../app/repository/PackageRepository.js'; +import { BugVersion } from '../../../../app/core/entity/BugVersion.js'; +import { PackageManagerService } from '../../../../app/core/service/PackageManagerService.js'; +import { CacheService } from '../../../../app/core/service/CacheService.js'; +import { DistRepository } from '../../../../app/repository/DistRepository.js'; +import { BugVersionService } from '../../../../app/core/service/BugVersionService.js'; +import { SyncMode } from '../../../../app/common/constants.js'; describe('test/port/controller/package/ShowPackageController.test.ts', () => { let packageRepository: PackageRepository; - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); packageRepository = await app.getEggObject(PackageRepository); @@ -31,7 +32,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); pkg = await TestUtil.getFullPackage({ name, version: '2.0.0' }); res = await app.httpRequest() @@ -41,7 +42,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); pkg = await TestUtil.getFullPackage({ name: scopedName, version: '1.0.0' }); res = await app.httpRequest() @@ -51,7 +52,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); pkg = await TestUtil.getFullPackage({ name: scopedName, version: '2.0.0' }); res = await app.httpRequest() @@ -61,7 +62,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); }); describe('should fallback when cache error', async () => { @@ -449,7 +450,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}`) @@ -476,7 +477,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}`) @@ -503,7 +504,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); res = await app.httpRequest() .get(`/${pkg.name}`) @@ -527,7 +528,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); const pkgModel = await packageRepository.findPackage('@cnpm', 'test-module-mock-dist-not-exists'); await packageRepository.removePackageDist(pkgModel!, false); @@ -555,7 +556,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); const pkgModel = await packageRepository.findPackage('@cnpm', 'test-module-mock-dist-not-exists-full-manifests'); await packageRepository.removePackageDist(pkgModel!, true); @@ -584,7 +585,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); const pkgEntity = await packageRepository.findPackage('@cnpm', name); assert(pkgEntity); @@ -612,7 +613,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); const pkgEntity = await packageRepository.findPackage('@cnpm', name); assert(pkgEntity); diff --git a/test/port/controller/package/ShowPackageVersionController.test.ts b/test/port/controller/package/ShowPackageVersionController.test.ts index f7e254a7..9a38a5d9 100644 --- a/test/port/controller/package/ShowPackageVersionController.test.ts +++ b/test/port/controller/package/ShowPackageVersionController.test.ts @@ -1,12 +1,13 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../../../test/TestUtil'; -import { BugVersion } from '../../../../app/core/entity/BugVersion'; -import { BugVersionService } from '../../../../app/core/service/BugVersionService'; -import { SyncMode } from '../../../../app/common/constants'; + +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; +import { BugVersion } from '../../../../app/core/entity/BugVersion.js'; +import { BugVersionService } from '../../../../app/core/service/BugVersionService.js'; +import { SyncMode } from '../../../../app/common/constants.js'; describe('test/port/controller/package/ShowPackageVersionController.test.ts', () => { - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); }); diff --git a/test/port/controller/package/UpdatePackageController.test.ts b/test/port/controller/package/UpdatePackageController.test.ts index a074cc91..78499589 100644 --- a/test/port/controller/package/UpdatePackageController.test.ts +++ b/test/port/controller/package/UpdatePackageController.test.ts @@ -1,11 +1,12 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { RegistryType } from '../../../../app/common/enum/Registry'; -import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService'; -import { TestUtil } from '../../../../test/TestUtil'; + +import { RegistryType } from '../../../../app/common/enum/Registry.js'; +import { RegistryManagerService } from '../../../../app/core/service/RegistryManagerService.js'; +import { TestUser, TestUtil } from '../../../../test/TestUtil.js'; describe('test/port/controller/package/UpdatePackageController.test.ts', () => { - let publisher; + let publisher: TestUser; beforeEach(async () => { publisher = await TestUtil.createUser(); }); @@ -23,7 +24,7 @@ describe('test/port/controller/package/UpdatePackageController.test.ts', () => { .send(pkg) .expect(201); assert.equal(res.body.ok, true); - assert.match(res.body.rev, /^\d+\-\w{24}$/); + assert.match(res.body.rev, /^\d+-\w{24}$/); rev = res.body.rev; }); @@ -416,7 +417,7 @@ describe('test/port/controller/package/UpdatePackageController.test.ts', () => { ], }) .expect(403); - assert.equal(res.body.error, `[FORBIDDEN] \"${publisher.name}\" not authorized to modify ${scopedName}, please contact maintainers: \"${user.name}, ${user2.name}\"`); + assert.equal(res.body.error, `[FORBIDDEN] "${publisher.name}" not authorized to modify ${scopedName}, please contact maintainers: "${user.name}, ${user2.name}"`); }); it('should support pnpm and other npm clients', async () => { diff --git a/test/port/middleware/AlwaysAuth.test.ts b/test/port/middleware/AlwaysAuth.test.ts index afe8799f..a3d0e300 100644 --- a/test/port/middleware/AlwaysAuth.test.ts +++ b/test/port/middleware/AlwaysAuth.test.ts @@ -1,6 +1,7 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TestUtil } from '../../TestUtil'; + +import { TestUtil } from '../../TestUtil.js'; describe('test/port/middleware/AlwaysAuth.test.ts', () => { it('should 401 when config.cnpmcore.alwaysAuth = true', async () => { diff --git a/test/port/webauth/webauthController.test.ts b/test/port/webauth/webauthController.test.ts index 65c24310..c68605cc 100644 --- a/test/port/webauth/webauthController.test.ts +++ b/test/port/webauth/webauthController.test.ts @@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert'; import crypto from 'node:crypto'; import { basename } from 'node:path'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { AuthAdapter } from '../../../app/infra/AuthAdapter'; -import { CacheAdapter } from '../../../app/common/adapter/CacheAdapter'; -import { UserService } from '../../../app/core/service/UserService'; -import { UserRepository } from '../../../app/repository/UserRepository'; -import { genRSAKeys, encryptRSA } from '../../../app/common/CryptoUtil'; + +import { AuthAdapter } from '../../../app/infra/AuthAdapter.js'; +import { CacheAdapter } from '../../../app/common/adapter/CacheAdapter.js'; +import { UserService } from '../../../app/core/service/UserService.js'; +import { UserRepository } from '../../../app/repository/UserRepository.js'; +import { genRSAKeys, encryptRSA } from '../../../app/common/CryptoUtil.js'; describe('test/port/webauth/webauthController.test.ts', () => { describe('/-/v1/login', () => { diff --git a/test/repository/ChangeRepository.test.ts b/test/repository/ChangeRepository.test.ts index 97e8df8b..68780ff1 100644 --- a/test/repository/ChangeRepository.test.ts +++ b/test/repository/ChangeRepository.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { ChangeRepository } from '../../app/repository/ChangeRepository'; -import { Change as ChangeModel } from '../../app/repository/model/Change'; + +import { ChangeRepository } from '../../app/repository/ChangeRepository.js'; +import { Change as ChangeModel } from '../../app/repository/model/Change.js'; describe('test/repository/ChangeRepository.test.ts', () => { let changeRepository: ChangeRepository; diff --git a/test/repository/PackageRepository.test.ts b/test/repository/PackageRepository.test.ts index 766c1006..de257fce 100644 --- a/test/repository/PackageRepository.test.ts +++ b/test/repository/PackageRepository.test.ts @@ -1,9 +1,10 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { PackageRepository } from '../../app/repository/PackageRepository'; -import { PackageManagerService } from '../../app/core/service/PackageManagerService'; -import { UserService } from '../../app/core/service/UserService'; -import { TestUtil } from '../../test/TestUtil'; + +import { PackageRepository } from '../../app/repository/PackageRepository.js'; +import { PackageManagerService } from '../../app/core/service/PackageManagerService.js'; +import { UserService } from '../../app/core/service/UserService.js'; +import { TestUtil } from '../../test/TestUtil.js'; describe('test/repository/PackageRepository.test.ts', () => { let packageRepository: PackageRepository; diff --git a/test/repository/ProxyCachePepository.test.ts b/test/repository/ProxyCachePepository.test.ts index 6e3e636a..ad43b5c5 100644 --- a/test/repository/ProxyCachePepository.test.ts +++ b/test/repository/ProxyCachePepository.test.ts @@ -1,8 +1,9 @@ import assert from 'node:assert/strict'; import { app } from '@eggjs/mock/bootstrap'; -import { ProxyCacheRepository } from '../../app/repository/ProxyCacheRepository'; -import { ProxyCache } from '../../app/core/entity/ProxyCache'; -import { DIST_NAMES } from '../../app/core/entity/Package'; + +import { ProxyCacheRepository } from '../../app/repository/ProxyCacheRepository.js'; +import { ProxyCache } from '../../app/core/entity/ProxyCache.js'; +import { DIST_NAMES } from '../../app/core/entity/Package.js'; describe('test/repository/ProxyCacheRepository.test.ts', () => { let proxyCacheRepository: ProxyCacheRepository; diff --git a/test/repository/RegistryRepository.test.ts b/test/repository/RegistryRepository.test.ts index a2307569..ef116a71 100644 --- a/test/repository/RegistryRepository.test.ts +++ b/test/repository/RegistryRepository.test.ts @@ -1,8 +1,9 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { RegistryRepository } from '../../app/repository/RegistryRepository'; -import { Registry } from '../../app/core/entity/Registry'; -import { RegistryType } from '../../app/common/enum/Registry'; + +import { RegistryRepository } from '../../app/repository/RegistryRepository.js'; +import { Registry } from '../../app/core/entity/Registry.js'; +import { RegistryType } from '../../app/common/enum/Registry.js'; describe('test/repository/RegistryRepository.test.ts', () => { let registryRepository: RegistryRepository; diff --git a/test/repository/ScopeRepository.test.ts b/test/repository/ScopeRepository.test.ts index 85b073fc..415f4b9f 100644 --- a/test/repository/ScopeRepository.test.ts +++ b/test/repository/ScopeRepository.test.ts @@ -1,7 +1,8 @@ import { strict as assert } from 'node:assert'; import { app } from '@eggjs/mock/bootstrap'; -import { ScopeRepository } from '../../app/repository/ScopeRepository'; -import { Scope } from '../../app/core/entity/Scope'; + +import { ScopeRepository } from '../../app/repository/ScopeRepository.js'; +import { Scope } from '../../app/core/entity/Scope.js'; describe('test/repository/ScopeRepository.test.ts', () => { let scopeRepository: ScopeRepository; diff --git a/test/repository/SearchRepository.test.ts b/test/repository/SearchRepository.test.ts index 7caec85a..2a1ff9f7 100644 --- a/test/repository/SearchRepository.test.ts +++ b/test/repository/SearchRepository.test.ts @@ -1,10 +1,11 @@ import { strict as assert } from 'node:assert'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { SearchManifestType, SearchRepository } from '../../app/repository/SearchRepository'; -import { mockES } from '../../config/config.unittest'; -import { PackageManagerService } from '../../app/core/service/PackageManagerService'; -import { TestUtil } from '../TestUtil'; -import { PackageSearchService } from '../../app/core/service/PackageSearchService'; + +import { SearchManifestType, SearchRepository } from '../../app/repository/SearchRepository.js'; +import { mockES } from '../../config/config.unittest.js'; +import { PackageManagerService } from '../../app/core/service/PackageManagerService.js'; +import { TestUtil } from '../TestUtil.js'; +import { PackageSearchService } from '../../app/core/service/PackageSearchService.js'; describe('test/repository/SearchRepository.test.ts', () => { let searchRepository: SearchRepository; diff --git a/test/repository/TaskRepository.test.ts b/test/repository/TaskRepository.test.ts index 3b010180..7d795b21 100644 --- a/test/repository/TaskRepository.test.ts +++ b/test/repository/TaskRepository.test.ts @@ -2,11 +2,12 @@ import { strict as assert } from 'node:assert'; import { setTimeout } from 'node:timers/promises'; import os from 'node:os'; import { app } from '@eggjs/mock/bootstrap'; -import { TaskRepository } from '../../app/repository/TaskRepository'; -import { Task as TaskModel } from '../../app/repository/model/Task'; -import { ChangesStreamTaskData, Task, TaskData } from '../../app/core/entity/Task'; -import { TaskState, TaskType } from '../../app/common/enum/Task'; -import { EasyData, EntityUtil } from '../../app/core/util/EntityUtil'; + +import { TaskRepository } from '../../app/repository/TaskRepository.js'; +import { Task as TaskModel } from '../../app/repository/model/Task.js'; +import { ChangesStreamTaskData, Task, TaskData } from '../../app/core/entity/Task.js'; +import { TaskState, TaskType } from '../../app/common/enum/Task.js'; +import { EasyData, EntityUtil } from '../../app/core/util/EntityUtil.js'; describe('test/repository/TaskRepository.test.ts', () => { let taskRepository: TaskRepository; diff --git a/test/schedule/ChangesStreamWorker.test.ts b/test/schedule/ChangesStreamWorker.test.ts index ebcd85d5..eb7f1c8b 100644 --- a/test/schedule/ChangesStreamWorker.test.ts +++ b/test/schedule/ChangesStreamWorker.test.ts @@ -1,11 +1,16 @@ import { strict as assert } from 'node:assert'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { ChangesStreamService } from '../../app/core/service/ChangesStreamService'; -import { TaskService } from '../../app/core/service/TaskService'; -import { Task } from '../../app/repository/model/Task'; -import { TestUtil } from '../../test/TestUtil'; -const ChangesStreamWorkerPath = require.resolve('../../app/port/schedule/ChangesStreamWorker'); +import { ChangesStreamService } from '../../app/core/service/ChangesStreamService.js'; +import { TaskService } from '../../app/core/service/TaskService.js'; +import { Task } from '../../app/repository/model/Task.js'; +import { TestUtil } from '../../test/TestUtil.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const ChangesStreamWorkerPath = path.join(__dirname, '../../app/port/schedule/ChangesStreamWorker.ts'); describe('test/schedule/ChangesStreamWorker.test.ts', () => { let changesStreamService: ChangesStreamService; diff --git a/test/schedule/CheckProxyCacheUpdateWorker.test.ts b/test/schedule/CheckProxyCacheUpdateWorker.test.ts index de519fc1..523a00bf 100644 --- a/test/schedule/CheckProxyCacheUpdateWorker.test.ts +++ b/test/schedule/CheckProxyCacheUpdateWorker.test.ts @@ -1,13 +1,18 @@ import assert from 'node:assert'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { SyncMode } from '../../app/common/constants'; -import { ProxyCacheRepository } from '../../app/repository/ProxyCacheRepository'; -import { ProxyCache } from '../../app/core/entity/ProxyCache'; -import { DIST_NAMES } from '../../app/core/entity/Package'; -import { TaskService } from '../../app/core/service/TaskService'; -import { TaskType } from '../../app/common/enum/Task'; -const CheckProxyCacheUpdateWorkerPath = require.resolve('../../app/port/schedule/CheckProxyCacheUpdateWorker'); +import { SyncMode } from '../../app/common/constants.js'; +import { ProxyCacheRepository } from '../../app/repository/ProxyCacheRepository.js'; +import { ProxyCache } from '../../app/core/entity/ProxyCache.js'; +import { DIST_NAMES } from '../../app/core/entity/Package.js'; +import { TaskService } from '../../app/core/service/TaskService.js'; +import { TaskType } from '../../app/common/enum/Task.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const CheckProxyCacheUpdateWorkerPath = path.join(__dirname, '../../app/port/schedule/CheckProxyCacheUpdateWorker.ts'); describe('test/schedule/CheckProxyCacheUpdateWorker.test.ts', () => { it('should create update task by repo', async () => { diff --git a/test/schedule/CheckRecentlyUpdatedPackages.test.ts b/test/schedule/CheckRecentlyUpdatedPackages.test.ts index eb1b1843..d713f5de 100644 --- a/test/schedule/CheckRecentlyUpdatedPackages.test.ts +++ b/test/schedule/CheckRecentlyUpdatedPackages.test.ts @@ -1,9 +1,14 @@ import { strict as assert } from 'node:assert'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { PackageSyncerService } from '../../app/core/service/PackageSyncerService'; -import { TestUtil } from '../../test/TestUtil'; -const CheckRecentlyUpdatedPackagesPath = require.resolve('../../app/port/schedule/CheckRecentlyUpdatedPackages'); +import { PackageSyncerService } from '../../app/core/service/PackageSyncerService.js'; +import { TestUtil } from '../../test/TestUtil.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const CheckRecentlyUpdatedPackagesPath = path.join(__dirname, '../../app/port/schedule/CheckRecentlyUpdatedPackages.ts'); describe('test/schedule/CheckRecentlyUpdatedPackages.test.ts', () => { let packageSyncerService: PackageSyncerService; diff --git a/test/schedule/CleanTempDir.test.ts b/test/schedule/CleanTempDir.test.ts index 4bae3606..3b472e6f 100644 --- a/test/schedule/CleanTempDir.test.ts +++ b/test/schedule/CleanTempDir.test.ts @@ -1,9 +1,13 @@ import { mkdir } from 'node:fs/promises'; import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import { app } from '@eggjs/mock/bootstrap'; -import dayjs from '../../app/common/dayjs'; -const CleanTempDirPath = require.resolve('../../app/port/schedule/CleanTempDir'); +import dayjs from '../../app/common/dayjs.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const CleanTempDirPath = path.join(__dirname, '../../app/port/schedule/CleanTempDir.ts'); describe('test/schedule/CleanTempDir.test.ts', () => { it('should clean dir success', async () => { diff --git a/test/schedule/SyncBinaryWorker.test.ts b/test/schedule/SyncBinaryWorker.test.ts index b00dbb79..aa648392 100644 --- a/test/schedule/SyncBinaryWorker.test.ts +++ b/test/schedule/SyncBinaryWorker.test.ts @@ -1,9 +1,14 @@ import { app, mock } from '@eggjs/mock/bootstrap'; -import { NodeBinary } from '../../app/common/adapter/binary/NodeBinary'; -import { TestUtil } from '../../test/TestUtil'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; -const CreateSyncBinaryTaskPath = require.resolve('../../app/port/schedule/CreateSyncBinaryTask'); -const SyncBinaryWorkerPath = require.resolve('../../app/port/schedule/SyncBinaryWorker'); +import { NodeBinary } from '../../app/common/adapter/binary/NodeBinary.js'; +import { TestUtil } from '../../test/TestUtil.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const CreateSyncBinaryTaskPath = path.join(__dirname, '../../app/port/schedule/CreateSyncBinaryTask.ts'); +const SyncBinaryWorkerPath = path.join(__dirname, '../../app/port/schedule/SyncBinaryWorker.ts'); describe('test/schedule/SyncBinaryWorker.test.ts', () => { it('should ignore when enableSyncBinary=false', async () => { diff --git a/test/schedule/SyncPackageWorker.test.ts b/test/schedule/SyncPackageWorker.test.ts index 1a146ffd..c65b0d63 100644 --- a/test/schedule/SyncPackageWorker.test.ts +++ b/test/schedule/SyncPackageWorker.test.ts @@ -1,9 +1,14 @@ import { strict as assert } from 'node:assert'; +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { PackageSyncerService } from '../../app/core/service/PackageSyncerService'; -import { TestUtil } from '../../test/TestUtil'; -const SyncPackageWorkerPath = require.resolve('../../app/port/schedule/SyncPackageWorker'); +import { PackageSyncerService } from '../../app/core/service/PackageSyncerService.js'; +import { TestUtil } from '../../test/TestUtil.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const SyncPackageWorkerPath = path.join(__dirname, '../../app/port/schedule/SyncPackageWorker.ts'); describe('test/schedule/SyncPackageWorker.test.ts', () => { beforeEach(async () => { diff --git a/test/schedule/SyncProxyCacheWorker.test.ts b/test/schedule/SyncProxyCacheWorker.test.ts index 98ee0b4c..b855fbb3 100644 --- a/test/schedule/SyncProxyCacheWorker.test.ts +++ b/test/schedule/SyncProxyCacheWorker.test.ts @@ -1,11 +1,16 @@ import { app, mock } from '@eggjs/mock/bootstrap'; -import { SyncMode } from '../../app/common/constants'; -import { ProxyCacheRepository } from '../../app/repository/ProxyCacheRepository'; -import { ProxyCache } from '../../app/core/entity/ProxyCache'; -import { DIST_NAMES } from '../../app/core/entity/Package'; -import { ProxyCacheService } from '../../app/core/service/ProxyCacheService'; - -const SyncProxyCacheWorkerPath = require.resolve('../../app/port/schedule/SyncProxyCacheWorker'); +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; + +import { SyncMode } from '../../app/common/constants.js'; +import { ProxyCacheRepository } from '../../app/repository/ProxyCacheRepository.js'; +import { ProxyCache } from '../../app/core/entity/ProxyCache.js'; +import { DIST_NAMES } from '../../app/core/entity/Package.js'; +import { ProxyCacheService } from '../../app/core/service/ProxyCacheService.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const SyncProxyCacheWorkerPath = path.join(__dirname, '../../app/port/schedule/SyncProxyCacheWorker.ts'); describe('test/schedule/SyncProxyCacheWorker.test.ts', () => { diff --git a/test/schedule/TaskTimeoutHandler.test.ts b/test/schedule/TaskTimeoutHandler.test.ts index 58d55744..58b13218 100644 --- a/test/schedule/TaskTimeoutHandler.test.ts +++ b/test/schedule/TaskTimeoutHandler.test.ts @@ -1,12 +1,17 @@ +import { fileURLToPath } from 'node:url'; +import path from 'node:path'; import { app, mock } from '@eggjs/mock/bootstrap'; -import { TaskState } from '../../app/common/enum/Task'; -import { PackageSyncerService } from '../../app/core/service/PackageSyncerService'; -import { HistoryTask } from '../../app/repository/model/HistoryTask'; -import { ModelConvertor } from '../../app/repository/util/ModelConvertor'; -import { Task as TaskModel } from '../../app/repository/model/Task'; -import { TaskService } from '../../app/core/service/TaskService'; -const TaskTimeoutHandlerPath = require.resolve('../../app/port/schedule/TaskTimeoutHandler'); +import { TaskState } from '../../app/common/enum/Task.js'; +import { PackageSyncerService } from '../../app/core/service/PackageSyncerService.js'; +import { HistoryTask } from '../../app/repository/model/HistoryTask.js'; +import { ModelConvertor } from '../../app/repository/util/ModelConvertor.js'; +import { Task as TaskModel } from '../../app/repository/model/Task.js'; +import { TaskService } from '../../app/core/service/TaskService.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const TaskTimeoutHandlerPath = path.join(__dirname, '../../app/port/schedule/TaskTimeoutHandler.ts'); describe('test/schedule/TaskTimeoutHandler.test.ts', () => { it('should work', async () => { diff --git a/tsconfig.json b/tsconfig.json index 8158f514..b38938a4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "target": "ES2021", "module": "NodeNext", "moduleResolution": "NodeNext", + "noImplicitAny": true, "declaration": false, "resolveJsonModule": true, "useUnknownInCatchVariables": false,