From 1de29e5566e4d44250b1949a41ce54fc0178bb40 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 20 Jan 2024 13:57:03 +0900 Subject: [PATCH] refactor: migrate to ESM --- packages/frontend/vite.config.ts | 5 ----- packages/misskey-bubble-game/package.json | 18 +++++++++++++++--- packages/misskey-js/package.json | 18 +++++++++++++++--- packages/misskey-js/src/api.ts | 8 ++++---- packages/misskey-js/src/api.types.ts | 8 ++++---- packages/misskey-js/src/entities.ts | 6 +++--- packages/misskey-js/src/streaming.ts | 6 ++++-- 7 files changed, 45 insertions(+), 24 deletions(-) diff --git a/packages/frontend/vite.config.ts b/packages/frontend/vite.config.ts index df37192583..35d112f6ec 100644 --- a/packages/frontend/vite.config.ts +++ b/packages/frontend/vite.config.ts @@ -101,11 +101,6 @@ export function getConfig(): UserConfig { __VUE_PROD_DEVTOOLS__: false, }, - // https://vitejs.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies - optimizeDeps: { - include: ['misskey-js', 'misskey-reversi', 'misskey-bubble-game'], - }, - build: { target: [ 'chrome116', diff --git a/packages/misskey-bubble-game/package.json b/packages/misskey-bubble-game/package.json index 852c923c34..787a956185 100644 --- a/packages/misskey-bubble-game/package.json +++ b/packages/misskey-bubble-game/package.json @@ -1,10 +1,22 @@ { + "type": "module", "name": "misskey-bubble-game", "version": "0.0.1", - "main": "./built/index.js", - "types": "./built/index.d.ts", + "exports": { + ".": { + "import": "./built/esm/index.js", + "types": "./built/dts/index.d.ts" + }, + "./*": { + "import": "./built/esm/*", + "types": "./built/dts/*" + } + }, "scripts": { - "build": "tsc", + "build": "npm run ts", + "ts": "npm run ts-esm && npm run ts-dts", + "ts-esm": "tsc --outDir built/esm", + "ts-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true", "watch": "nodemon -w src -e ts,js,cjs,mjs,json --exec \"pnpm run build\"", "eslint": "eslint . --ext .js,.jsx,.ts,.tsx", "typecheck": "tsc --noEmit", diff --git a/packages/misskey-js/package.json b/packages/misskey-js/package.json index 1e3ed99a9b..4c2d9e7254 100644 --- a/packages/misskey-js/package.json +++ b/packages/misskey-js/package.json @@ -1,11 +1,23 @@ { + "type": "module", "name": "misskey-js", "version": "0.0.16", "description": "Misskey SDK for JavaScript", - "main": "./built/index.js", - "types": "./built/index.d.ts", + "exports": { + ".": { + "import": "./built/esm/index.js", + "types": "./built/dts/index.d.ts" + }, + "./*": { + "import": "./built/esm/*", + "types": "./built/dts/*" + } + }, "scripts": { - "build": "tsc", + "build": "npm run ts", + "ts": "npm run ts-esm && npm run ts-dts", + "ts-esm": "tsc --outDir built/esm", + "ts-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true", "watch": "nodemon -w src -e ts,js,cjs,mjs,json --exec \"pnpm run build\"", "tsd": "tsd", "api": "pnpm api-extractor run --local --verbose", diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts index 0d10faaada..2e85fc2939 100644 --- a/packages/misskey-js/src/api.ts +++ b/packages/misskey-js/src/api.ts @@ -1,11 +1,11 @@ -import './autogen/apiClientJSDoc'; +import './autogen/apiClientJSDoc.js'; -import { SwitchCaseResponseType } from './api.types'; -import type { Endpoints } from './api.types'; +import { SwitchCaseResponseType } from './api.types.js'; +import type { Endpoints } from './api.types.js'; export { SwitchCaseResponseType, -} from './api.types'; +} from './api.types.js'; const MK_API_ERROR = Symbol(); diff --git a/packages/misskey-js/src/api.types.ts b/packages/misskey-js/src/api.types.ts index 75ab7d91b1..6320081928 100644 --- a/packages/misskey-js/src/api.types.ts +++ b/packages/misskey-js/src/api.types.ts @@ -1,6 +1,6 @@ -import { Endpoints as Gen } from './autogen/endpoint'; -import { UserDetailed } from './autogen/models'; -import { UsersShowRequest } from './autogen/entities'; +import { Endpoints as Gen } from './autogen/endpoint.js'; +import { UserDetailed } from './autogen/models.js'; +import { UsersShowRequest } from './autogen/entities.js'; import { SigninRequest, SigninResponse, @@ -8,7 +8,7 @@ import { SignupPendingResponse, SignupRequest, SignupResponse, -} from './entities'; +} from './entities.js'; type Overwrite = Omit< T, diff --git a/packages/misskey-js/src/entities.ts b/packages/misskey-js/src/entities.ts index e00e192e0d..bab518e635 100644 --- a/packages/misskey-js/src/entities.ts +++ b/packages/misskey-js/src/entities.ts @@ -1,8 +1,8 @@ import { ModerationLogPayloads } from './consts.js'; -import { Announcement, EmojiDetailed, MeDetailed, MeDetailedOnly, Page, User, UserDetailed } from './autogen/models'; +import { Announcement, EmojiDetailed, MeDetailed, MeDetailedOnly, Page, User, UserDetailed } from './autogen/models.js'; -export * from './autogen/entities'; -export * from './autogen/models'; +export * from './autogen/entities.js'; +export * from './autogen/models.js'; export type ID = string; export type DateString = string; diff --git a/packages/misskey-js/src/streaming.ts b/packages/misskey-js/src/streaming.ts index c641706a4b..0f26857782 100644 --- a/packages/misskey-js/src/streaming.ts +++ b/packages/misskey-js/src/streaming.ts @@ -1,7 +1,9 @@ import { EventEmitter } from 'eventemitter3'; -import ReconnectingWebsocket from 'reconnecting-websocket'; +import _ReconnectingWebsocket from 'reconnecting-websocket'; import type { BroadcastEvents, Channels } from './streaming.types.js'; +const ReconnectingWebsocket = _ReconnectingWebsocket as unknown as typeof _ReconnectingWebsocket['default']; + export function urlQuery(obj: Record): string { const params = Object.entries(obj) .filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined) @@ -24,7 +26,7 @@ type StreamEvents = { * Misskey stream connection */ export default class Stream extends EventEmitter { - private stream: ReconnectingWebsocket; + private stream: _ReconnectingWebsocket.default; public state: 'initializing' | 'reconnecting' | 'connected' = 'initializing'; private sharedConnectionPools: Pool[] = []; private sharedConnections: SharedConnection[] = [];