diff --git a/packages/misskey-js/.swcrc b/packages/misskey-js/.swcrc deleted file mode 100644 index 6fd7486370..0000000000 --- a/packages/misskey-js/.swcrc +++ /dev/null @@ -1,23 +0,0 @@ -{ - "$schema": "https://swc.rs/schema.json", - "jsc": { - "parser": { - "syntax": "typescript", - "dynamicImport": true, - "decorators": true - }, - "transform": { - "legacyDecorator": true, - "decoratorMetadata": true - }, - "experimental": { - "keepImportAssertions": true - }, - "baseUrl": "src", - "paths": { - "@/*": ["*"] - }, - "target": "es2022" - }, - "minify": false -} diff --git a/packages/misskey-js/api-extractor.json b/packages/misskey-js/api-extractor.json index 627a245a49..2e98ae663e 100644 --- a/packages/misskey-js/api-extractor.json +++ b/packages/misskey-js/api-extractor.json @@ -45,7 +45,7 @@ * * SUPPORTED TOKENS: , , */ - "mainEntryPointFilePath": "/built/index.d.ts", + "mainEntryPointFilePath": "/built/src/index.d.ts", /** * A list of NPM package names whose exports should be treated as part of this package. diff --git a/packages/misskey-js/build.js b/packages/misskey-js/build.js deleted file mode 100644 index 76a95fb3f5..0000000000 --- a/packages/misskey-js/build.js +++ /dev/null @@ -1,109 +0,0 @@ -import fs from 'node:fs'; -import { fileURLToPath } from 'node:url'; -import { dirname } from 'node:path'; -import * as esbuild from 'esbuild'; -import { build } from 'esbuild'; -import { globSync } from 'glob'; -import { execa } from 'execa'; - -const _filename = fileURLToPath(import.meta.url); -const _dirname = dirname(_filename); -const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8')); - -const entryPoints = globSync('./src/**/**.{ts,tsx}'); - -/** @type {import('esbuild').BuildOptions} */ -const options = { - entryPoints, - minify: process.env.NODE_ENV === 'production', - outdir: './built', - target: 'es2022', - platform: 'browser', - format: 'esm', - sourcemap: 'linked', -}; - -// built配下をすべて削除する -const args = process.argv.slice(2).map(arg => arg.toLowerCase()); - -// built配下をすべて削除する -if (!args.includes('--no-clean')) { - fs.rmSync('./built', { recursive: true, force: true }); -} - -if (args.includes('--watch')) { - await watchSrc(); -} else { - await buildSrc(); -} - -async function buildSrc() { - console.log(`[${_package.name}] start building...`); - - await build(options) - .then(() => { - console.log(`[${_package.name}] build succeeded.`); - }) - .catch((err) => { - process.stderr.write(err.stderr); - process.exit(1); - }); - - if (process.env.NODE_ENV === 'production') { - console.log(`[${_package.name}] skip building d.ts because NODE_ENV is production.`); - } else { - await buildDts(); - } - - console.log(`[${_package.name}] finish building.`); -} - -function buildDts() { - return execa( - 'tsc', - [ - '--project', 'tsconfig.json', - '--outDir', 'built', - '--declaration', 'true', - '--emitDeclarationOnly', 'true', - ], - { - stdout: process.stdout, - stderr: process.stderr, - }, - ); -} - -async function watchSrc() { - const plugins = [{ - name: 'gen-dts', - setup(build) { - build.onStart(() => { - console.log(`[${_package.name}] detect changed...`); - }); - build.onEnd(async result => { - if (result.errors.length > 0) { - console.error(`[${_package.name}] watch build failed:`, result); - return; - } - await buildDts(); - }); - }, - }]; - - console.log(`[${_package.name}] start watching...`); - - const context = await esbuild.context({ ...options, plugins }); - await context.watch(); - - await new Promise((resolve, reject) => { - process.on('SIGHUP', resolve); - process.on('SIGINT', resolve); - process.on('SIGTERM', resolve); - process.on('uncaughtExceptionMonitor', reject); - process.on('exit', resolve); - }).finally(async () => { - await context.dispose(); - console.log(`[${_package.name}] finish watching.`); - }); -} diff --git a/packages/misskey-js/eslint.config.js b/packages/misskey-js/eslint.config.js index bbfc5c50c6..07bfe32dda 100644 --- a/packages/misskey-js/eslint.config.js +++ b/packages/misskey-js/eslint.config.js @@ -18,10 +18,11 @@ export default [ '**/built/', '**/coverage/', '**/node_modules/', + 'scripts', ], }, { - files: ['**/*.ts', '**/*.tsx'], + files: ['src/**/*.ts', 'src/**/*.tsx'], languageOptions: { parserOptions: { parser: tsParser, diff --git a/packages/misskey-js/etc/misskey-js.api.md b/packages/misskey-js/etc/misskey-js.api.md index a8e477af8e..d98af977aa 100644 --- a/packages/misskey-js/etc/misskey-js.api.md +++ b/packages/misskey-js/etc/misskey-js.api.md @@ -2775,7 +2775,7 @@ type IResponse = operations['i']['responses']['200']['content']['application/jso type IRevokeTokenRequest = operations['i___revoke-token']['requestBody']['content']['application/json']; // @public (undocumented) -function isAPIError(reason: Record): reason is APIError; +function isAPIError(reason: unknown): reason is APIError; // @public (undocumented) type ISharedAccessListRequest = operations['i___shared-access___list']['requestBody']['content']['application/json']; @@ -3725,7 +3725,7 @@ type SponsorsResponse = operations['sponsors']['responses']['200']['content']['a // @public (undocumented) type StatsResponse = operations['stats']['responses']['200']['content']['application/json']; -// @public (undocumented) +// @public export class Stream extends EventEmitter implements IStream { constructor(origin: string, user: { token: string; @@ -3733,7 +3733,6 @@ export class Stream extends EventEmitter implements IStream { WebSocket?: Options['WebSocket']; binaryType?: ReconnectingWebSocket['binaryType']; }); - // (undocumented) close(): void; // (undocumented) disconnectToChannel(connection: NonSharedConnection): void; @@ -3745,7 +3744,6 @@ export class Stream extends EventEmitter implements IStream { removeSharedConnection(connection: SharedConnection): void; // (undocumented) removeSharedConnectionPool(pool: Pool): void; - // (undocumented) send(typeOrPayload: string): void; // (undocumented) send(typeOrPayload: string, payload: unknown): void; diff --git a/packages/misskey-js/package.json b/packages/misskey-js/package.json index 2cc3ed4d47..4bf24280b9 100644 --- a/packages/misskey-js/package.json +++ b/packages/misskey-js/package.json @@ -4,26 +4,17 @@ "version": "2025.5.2-dev", "description": "Misskey SDK for JavaScript", "license": "MIT", - "main": "./built/index.js", - "types": "./built/index.d.ts", - "exports": { - ".": { - "import": "./built/index.js", - "types": "./built/index.d.ts" - }, - "./*": { - "import": "./built/*", - "types": "./built/*" - } - }, + "main": "./built/src/index.js", + "types": "./built/src/index.d.ts", "scripts": { - "build": "node ./build.js", - "watch": "nodemon -w package.json -e json --exec \"node ./build.js --watch\"", - "tsd": "tsd", + "clean": "node scripts/clean.mjs", + "build": "tsc -b && ncp test-d ./built/test-d", + "rebuild": "pnpm clean && pnpm build", + "tsd": "tsd --files \"./built/test-d/**/*.ts\"", "api": "pnpm api-extractor run --local --verbose", "api-prod": "pnpm api-extractor run --verbose", - "eslint": "eslint --quiet \"{src,test,js,@types}/**/*.{js,jsx,ts,tsx,vue}\" --cache", - "typecheck": "tsc --noEmit", + "eslint": "eslint --quiet \"{src,test,test-d,scripts}/**/*.{js,jsx,ts,tsx,vue}\" --cache", + "typecheck": "tsc -b --noEmit", "lint": "pnpm typecheck && pnpm eslint", "jest": "jest --coverage --detectOpenHandles", "test": "pnpm jest && pnpm tsd", @@ -31,13 +22,12 @@ }, "repository": { "type": "git", - "url": "https://github.com/misskey-dev/misskey.git", + "url": "https://activitypub.software/TransFem-org/Sharkey.git", "directory": "packages/misskey-js" }, "devDependencies": { "@microsoft/api-extractor": "7.52.5", "@simplewebauthn/types": "12.0.0", - "@swc/jest": "0.2.38", "@types/jest": "29.5.14", "@types/node": "22.15.2", "@typescript-eslint/eslint-plugin": "8.31.0", @@ -47,15 +37,11 @@ "jest-websocket-mock": "2.5.0", "mock-socket": "9.3.1", "ncp": "2.0.0", - "nodemon": "3.1.10", - "execa": "9.5.2", "tsd": "0.32.0", - "typescript": "5.8.3", - "esbuild": "0.25.3", - "glob": "11.0.2" + "typescript": "5.8.3" }, "files": [ - "built" + "built/src" ], "dependencies": { "eventemitter3": "5.0.1", diff --git a/packages/misskey-js/scripts/_common.mjs b/packages/misskey-js/scripts/_common.mjs new file mode 100644 index 0000000000..3c824ff1ee --- /dev/null +++ b/packages/misskey-js/scripts/_common.mjs @@ -0,0 +1,5 @@ +import * as nodepath from 'path'; + +export const scriptsDir = import.meta.dirname; +export const rootDir = nodepath.join(scriptsDir, '../'); +export const outDir = nodepath.join(rootDir, './built'); diff --git a/packages/misskey-js/scripts/clean.mjs b/packages/misskey-js/scripts/clean.mjs new file mode 100644 index 0000000000..4060d6e036 --- /dev/null +++ b/packages/misskey-js/scripts/clean.mjs @@ -0,0 +1,5 @@ +import { rm } from 'fs/promises'; +import { outDir } from './_common.mjs'; + +console.log(`Cleaning ${outDir}...`); +await rm(outDir, { recursive: true, force: true }); diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts index e663d712a7..f07c7e70db 100644 --- a/packages/misskey-js/src/api.ts +++ b/packages/misskey-js/src/api.ts @@ -18,7 +18,11 @@ export type APIError = { info: Record; }; -export function isAPIError(reason: Record): reason is APIError { +export function isAPIError(reason: unknown): reason is APIError { + if (reason == null) return false; + if (typeof(reason) !== 'object') return false; + if (!(MK_API_ERROR in reason)) return false; + if (typeof(reason[MK_API_ERROR]) !== 'boolean') return false; return reason[MK_API_ERROR] === true; } diff --git a/packages/misskey-js/test/nyaize.test.ts b/packages/misskey-js/test/nyaize.test.ts index 24b19bc2b9..bda9bbbef8 100644 --- a/packages/misskey-js/test/nyaize.test.ts +++ b/packages/misskey-js/test/nyaize.test.ts @@ -5,7 +5,7 @@ import { nyaize } from '../src/nyaize.js'; -function runTests(cases) { +function runTests(cases: [string, string][]) { for (const c of cases) { const [input,expected] = c; const got = nyaize(input); diff --git a/packages/misskey-js/test/streaming.ts b/packages/misskey-js/test/streaming.ts index 7e784cd20c..2324bcfabb 100644 --- a/packages/misskey-js/test/streaming.ts +++ b/packages/misskey-js/test/streaming.ts @@ -1,4 +1,4 @@ -import WS from 'jest-websocket-mock'; +import { WS } from 'jest-websocket-mock'; import Stream from '../src/streaming.js'; describe('Streaming', () => { @@ -43,7 +43,7 @@ describe('Streaming', () => { const server = new WS('wss://misskey.test/streaming'); const stream = new Stream('https://misskey.test', { token: 'TOKEN' }); const chatChannelReceived: any[] = []; - const chat = stream.useChannel('chat', { other: 'aaa' }); + const chat = stream.useChannel('chatUser', { otherId: 'aaa' }); chat.on('message', payload => { chatChannelReceived.push(payload); }); @@ -54,8 +54,8 @@ describe('Streaming', () => { const msg = JSON.parse(await server.nextMessage as string); const chatChannelId = msg.body.id; expect(msg.type).toEqual('connect'); - expect(msg.body.channel).toEqual('chat'); - expect(msg.body.params).toEqual({ other: 'aaa' }); + expect(msg.body.channel).toEqual('chatUser'); + expect(msg.body.params).toEqual({ otherId: 'aaa' }); expect(chatChannelId != null).toEqual(true); server.send(JSON.stringify({ @@ -81,8 +81,8 @@ describe('Streaming', () => { const server = new WS('wss://misskey.test/streaming'); const stream = new Stream('https://misskey.test', { token: 'TOKEN' }); - stream.useChannel('chat', { other: 'aaa' }); - stream.useChannel('chat', { other: 'bbb' }); + stream.useChannel('chatUser', { otherId: 'aaa' }); + stream.useChannel('chatUser', { otherId: 'bbb' }); const ws = await server.connected; expect(new URLSearchParams(new URL(ws.url).search).get('i')).toEqual('TOKEN'); @@ -104,7 +104,7 @@ describe('Streaming', () => { const server = new WS('wss://misskey.test/streaming'); const stream = new Stream('https://misskey.test', { token: 'TOKEN' }); - const chat = stream.useChannel('chat', { other: 'aaa' }); + const chat = stream.useChannel('chatUser', { otherId: 'aaa' }); chat.send('read', { id: 'aaa' }); const ws = await server.connected; diff --git a/packages/misskey-js/tsconfig.json b/packages/misskey-js/tsconfig.json index e0603832c7..5775a68dae 100644 --- a/packages/misskey-js/tsconfig.json +++ b/packages/misskey-js/tsconfig.json @@ -6,9 +6,11 @@ "moduleResolution": "nodenext", "declaration": true, "declarationMap": true, - "sourceMap": false, + "sourceMap": true, + "inlineSources": true, + "allowJs": true, + "checkJs": true, "outDir": "./built/", - "removeComments": true, "strict": true, "strictFunctionTypes": true, "strictNullChecks": true, @@ -16,21 +18,26 @@ "noImplicitReturns": true, "esModuleInterop": true, "exactOptionalPropertyTypes": true, - "skipLibCheck": true, + "rootDir": ".", "incremental": true, + "composite": true, "typeRoots": [ "./node_modules/@types" ], "lib": [ "esnext", - "dom" + "dom", + "dom.iterable" // https://dev.to/deciduously/formdata-in-typescript-24cl ] }, + "compileOnSave": false, "include": [ - "src/**/*" + "src/**/*", + "test/**/*", + "test-d/**/*", + "scripts/**/*", ], "exclude": [ - "node_modules", - "test/**/*" + "node_modules" ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index faf9725c3b..a8ecf6287e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -938,7 +938,7 @@ importers: version: 5.2.3(vite@6.3.4(@types/node@22.15.2)(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3))(vue@3.5.14(typescript@5.8.3)) '@vitest/coverage-v8': specifier: 3.1.2 - version: 3.1.2(vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0)(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3)) + version: 3.1.2(vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3)) '@vue/compiler-core': specifier: 3.5.14 version: 3.5.14 @@ -1040,7 +1040,7 @@ importers: version: 1.0.3 vitest: specifier: 3.1.2 - version: 3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0)(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3) + version: 3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3) vitest-fetch-mock: specifier: 0.4.5 version: 0.4.5(vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3)) @@ -1140,7 +1140,7 @@ importers: version: 5.2.3(vite@6.3.4(@types/node@22.15.2)(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3))(vue@3.5.14(typescript@5.8.3)) '@vitest/coverage-v8': specifier: 3.1.2 - version: 3.1.2(vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0)(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3)) + version: 3.1.2(vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3)) '@vue/compiler-sfc': specifier: 3.5.14 version: 3.5.14 @@ -1346,9 +1346,6 @@ importers: '@simplewebauthn/types': specifier: 12.0.0 version: 12.0.0 - '@swc/jest': - specifier: 0.2.38 - version: 0.2.38(@swc/core@1.11.24) '@types/jest': specifier: 29.5.14 version: 29.5.14 @@ -1361,15 +1358,6 @@ importers: '@typescript-eslint/parser': specifier: 8.31.0 version: 8.31.0(eslint@9.25.1)(typescript@5.8.3) - esbuild: - specifier: 0.25.3 - version: 0.25.3 - execa: - specifier: 9.5.2 - version: 9.5.2 - glob: - specifier: 11.0.2 - version: 11.0.2 jest: specifier: 29.7.0 version: 29.7.0(@types/node@22.15.2) @@ -1385,9 +1373,6 @@ importers: ncp: specifier: 2.0.0 version: 2.0.0 - nodemon: - specifier: 3.1.10 - version: 3.1.10 tsd: specifier: 0.32.0 version: 0.32.0 @@ -14674,7 +14659,7 @@ snapshots: vite: 6.3.4(@types/node@22.15.2)(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3) vue: 3.5.14(typescript@5.8.3) - '@vitest/coverage-v8@3.1.2(vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0)(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3))': + '@vitest/coverage-v8@3.1.2(vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3))': dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 1.0.2 @@ -14688,7 +14673,7 @@ snapshots: std-env: 3.9.0 test-exclude: 7.0.1 tinyrainbow: 2.0.0 - vitest: 3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0)(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3) + vitest: 3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3) transitivePeerDependencies: - supports-color @@ -21764,9 +21749,9 @@ snapshots: vitest-fetch-mock@0.4.5(vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3)): dependencies: - vitest: 3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0)(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3) + vitest: 3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3) - vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0)(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3): + vitest@3.1.2(@types/debug@4.1.12)(@types/node@22.15.2)(happy-dom@17.4.4)(jsdom@26.1.0(bufferutil@4.0.9)(utf-8-validate@6.0.5))(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3): dependencies: '@vitest/expect': 3.1.2 '@vitest/mocker': 3.1.2(msw@2.7.5(@types/node@22.15.2)(typescript@5.8.3))(vite@6.3.4(@types/node@22.15.2)(sass@1.87.0)(terser@5.39.0)(tsx@4.19.3))