diff --git a/bun.lockb b/bun.lockb index b43de28..dc9102e 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 7980ad0..cbcdde9 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ci": "bun run lint && bun run test && bun run build", "lint": "eslint .", "clean": "rimraf dist", - "build": "bun run clean && rollup -c && tsc --declaration true --emitDeclarationOnly true --declarationMap", + "build": "bun run clean && rollup -c", "docs": "typedoc --options typedoc.json", "test": "vitest run --pool=forks --config ./vitest.config.ts", "test-browser": "vitest run --browser.name=chrome --browser.headless --config ./vitest.config.ts" @@ -66,6 +66,7 @@ "eslint-plugin-named-import-spacing": "^1.0.3", "rimraf": "^5.0.1", "rollup": "^3.28.1", + "rollup-plugin-dts": "^6.1.1", "rollup-plugin-esbuild": "^5.0.0", "rollup-plugin-polyfill-node": "^0.12.0", "rollup-plugin-typescript-paths": "^1.4.0", diff --git a/rollup.config.mjs b/rollup.config.mjs index 50f2de7..93b968d 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -8,7 +8,7 @@ import commonjs from '@rollup/plugin-commonjs' import { typescriptPaths } from 'rollup-plugin-typescript-paths' import nodePolyfills from 'rollup-plugin-polyfill-node' -//import dts from 'rollup-plugin-dts' +import dts from 'rollup-plugin-dts' const generatedCode = { arrowFunctions: true, @@ -38,22 +38,22 @@ const source = { external: [...Object.keys(pkg.dependencies)], output: [esm, umd], plugins: [ - typescriptPaths({ preserveExtensions: true }), json(), nodePolyfills(), + typescriptPaths({ preserveExtensions: true }), resolve({ preferBuiltins: true }), commonjs({ requireReturnsDefault: 'auto' }), esbuild({ exclude: ["**/*.test.ts"] }) ] } -// const types = { -// input: 'src/types/index.ts', -// output: [{ -// file: 'dist/types.d.ts', -// format: 'es' -// }], -// plugins: [dts()] -// } +const types = { + input: 'src/types/index.ts', + output: [{ + file: pkg.types, + format: 'es' + }], + plugins: [dts()] +} -export default [source] \ No newline at end of file +export default [source, types] \ No newline at end of file diff --git a/src/OAPI.ts b/src/OAPI.ts index 2d3e0ef..770fad4 100644 --- a/src/OAPI.ts +++ b/src/OAPI.ts @@ -7,10 +7,10 @@ import type { OAPINation, RawServerInfoV2, RawServerInfoV3 -} from 'types' +} from './types' -import { townyData } from 'utils/endpoint.js' -import { FetchError } from 'utils/errors.js' +import { townyData } from './utils/endpoint.js' +import { FetchError } from './utils/errors.js' const parseResident = (res: RawResident) => { const obj: any = {} diff --git a/src/api/common.ts b/src/api/common.ts index 60da71e..b32b73e 100644 --- a/src/api/common.ts +++ b/src/api/common.ts @@ -1,5 +1,5 @@ -import type { StrictPoint2D, Point2D, TownBounds } from "types" -import { hypot, safeParseInt, strictFalsy } from "utils/functions.js" +import type { StrictPoint2D, Point2D, TownBounds } from ".././types" +import { hypot, safeParseInt, strictFalsy } from ".././utils/functions.js" type LocOrNation = Partial { diff --git a/src/api/dynmap/Residents.ts b/src/api/dynmap/Residents.ts index d1a09d5..ea9b282 100644 --- a/src/api/dynmap/Residents.ts +++ b/src/api/dynmap/Residents.ts @@ -5,15 +5,15 @@ import type Dynmap from "./Dynmap.js" import type { Resident, Town -} from 'types' +} from '../../types' import { FetchError, InvalidError, type NotFoundError -} from "utils/errors.js" +} from "../../utils/errors.js" -import type { EntityApi } from 'helpers/EntityApi.js' +import type { EntityApi } from '../../helpers/EntityApi.js' class Residents implements EntityApi { #map: Dynmap diff --git a/src/api/dynmap/Towns.ts b/src/api/dynmap/Towns.ts index c52deb0..edeaa7a 100644 --- a/src/api/dynmap/Towns.ts +++ b/src/api/dynmap/Towns.ts @@ -6,16 +6,16 @@ import { calcArea, range, getExisting, isInvitable -} from 'utils/functions.js' +} from '../../utils/functions.js' import { FetchError, InvalidError, NotFoundError -} from "utils/errors.js" +} from "../../utils/errors.js" -import type { EntityApi } from 'helpers/EntityApi.js' -import type { Nation, StrictPoint2D, Town } from 'types' +import type { EntityApi } from '../../helpers/EntityApi.js' +import type { Nation, StrictPoint2D, Town } from '../../types' import { getNearest } from '../common.js' class Towns implements EntityApi { diff --git a/src/api/squaremap/Nations.ts b/src/api/squaremap/Nations.ts index b22fefc..0e82d8e 100644 --- a/src/api/squaremap/Nations.ts +++ b/src/api/squaremap/Nations.ts @@ -1,10 +1,10 @@ import type Squaremap from "./Squaremap.js" -import { FetchError, type NotFoundError } from "utils/errors.js" -import type { EntityApi } from "helpers/EntityApi.js" -import type { Nation, SquaremapTown, StrictPoint2D } from "types" +import { FetchError, type NotFoundError } from "../../utils/errors.js" +import type { EntityApi } from "../../helpers/EntityApi.js" +import type { Nation, SquaremapTown, StrictPoint2D } from "../../types" -import { getExisting, sqr } from "utils/functions.js" +import { getExisting, sqr } from "../../utils/functions.js" import { getNearest } from "../common.js" import { parseNations } from "./parser.js" diff --git a/src/api/squaremap/Players.ts b/src/api/squaremap/Players.ts index e06e714..fdca38e 100644 --- a/src/api/squaremap/Players.ts +++ b/src/api/squaremap/Players.ts @@ -3,11 +3,11 @@ import type Squaremap from "./Squaremap.js" import type { EntityApi -} from "helpers/EntityApi.js" +} from "../../helpers/EntityApi.js" -import type { OnlinePlayer, Player, StrictPoint2D } from "types" -import { FetchError, type NotFoundError } from "utils/errors.js" -import { getExisting } from "utils/functions.js" +import type { OnlinePlayer, Player, StrictPoint2D } from "../../types" +import { FetchError, type NotFoundError } from "../../utils/errors.js" +import { getExisting } from "../../utils/functions.js" import { parseInfoString } from "./parser.js" import { getNearest } from "../common.js" diff --git a/src/api/squaremap/Residents.ts b/src/api/squaremap/Residents.ts index a84c05c..ba0538e 100644 --- a/src/api/squaremap/Residents.ts +++ b/src/api/squaremap/Residents.ts @@ -1,9 +1,10 @@ import type Squaremap from "./Squaremap.js" -import type { EntityApi } from "helpers/EntityApi.js" -import type { Resident, SquaremapTown } from "types" -import { InvalidError, type NotFoundError } from "utils/errors.js" -import { getExisting } from "utils/functions.js" +import type { Resident, SquaremapTown } from "../../types" + +import type { EntityApi } from "../../helpers/EntityApi.js" +import { InvalidError, type NotFoundError } from "../../utils/errors.js" +import { getExisting } from "../../utils/functions.js" import { parseResidents } from "./parser.js" class Residents implements EntityApi { diff --git a/src/api/squaremap/Squaremap.ts b/src/api/squaremap/Squaremap.ts index 88d03ee..31ef5fd 100644 --- a/src/api/squaremap/Squaremap.ts +++ b/src/api/squaremap/Squaremap.ts @@ -4,9 +4,9 @@ import type { SquaremapMapResponse, SquaremapPlayersResponse, TownBounds -} from "types" +} from "../../types" -import DataHandler from "helpers/DataHandler.js" +import DataHandler from "../../helpers/DataHandler.js" import Towns from './Towns.js' import Nations from './Nations.js' diff --git a/src/api/squaremap/Towns.ts b/src/api/squaremap/Towns.ts index 129c0c8..305e150 100644 --- a/src/api/squaremap/Towns.ts +++ b/src/api/squaremap/Towns.ts @@ -1,15 +1,15 @@ import type Squaremap from "./Squaremap.js" -import type { Nation, SquaremapTown, StrictPoint2D } from "types" +import type { Nation, SquaremapTown, StrictPoint2D } from "../../types" -import type { EntityApi } from "helpers/EntityApi.js" +import type { EntityApi } from "../../helpers/EntityApi.js" import { parseTowns } from "./parser.js" import { FetchError, InvalidError, NotFoundError -} from "utils/errors.js" +} from "../../utils/errors.js" -import { getExisting, isInvitable } from "utils/functions.js" +import { getExisting, isInvitable } from "../../utils/functions.js" import { getNearest } from "../common.js" class Towns implements EntityApi { diff --git a/src/api/squaremap/parser.ts b/src/api/squaremap/parser.ts index 5bea378..b85a6f1 100644 --- a/src/api/squaremap/parser.ts +++ b/src/api/squaremap/parser.ts @@ -1,7 +1,7 @@ /* eslint-disable no-unused-vars */ /* eslint-disable @typescript-eslint/no-unused-vars */ import striptags from 'striptags' -import { asBool, calcArea, fastMergeUnique, formatString, range, roundToNearest16 } from 'utils/functions.js' +import { asBool, calcArea, fastMergeUnique, formatString, range, roundToNearest16 } from '../../utils/functions.js' import type { Nation, @@ -11,7 +11,7 @@ import type { SquaremapRawPlayer, SquaremapTown, StrictPoint2D -} from 'types' +} from '../../types' /** * Parses the tooltip on a marker - removing white space, new lines and HTML tags. diff --git a/src/helpers/DataHandler.ts b/src/helpers/DataHandler.ts index dd21b14..0988d03 100644 --- a/src/helpers/DataHandler.ts +++ b/src/helpers/DataHandler.ts @@ -1,7 +1,7 @@ -import * as endpoint from 'utils/endpoint.js' +import * as endpoint from '../utils/endpoint.js' import { Mutex } from 'async-mutex' -import type { AnyMap } from 'types' +import type { AnyMap } from '../types' class DataHandler { #map: AnyMap diff --git a/src/helpers/EventEmitter.ts b/src/helpers/EventEmitter.ts index 1b46960..8341dd4 100644 --- a/src/helpers/EventEmitter.ts +++ b/src/helpers/EventEmitter.ts @@ -15,7 +15,6 @@ export default class Mitt { protected emit: any constructor() { - // @ts-expect-error const emitter = mitt() Object.keys(emitter).forEach(() => { diff --git a/src/main.ts b/src/main.ts index 6d08276..7939fdf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,7 +6,7 @@ import Squaremap from './api/squaremap/Squaremap.js' import MCAPI from "mojang-lib" import { OAPIV2, OAPIV3 } from './OAPI.js' -import type { PlayersResponse } from 'types' +import type { PlayersResponse } from './types' const Aurora = new Squaremap('aurora') const Nova = new Dynmap('nova') @@ -60,6 +60,6 @@ export { Dynmap, Squaremap } -export * from "types" +export * from "./types/index.js" export * from "./utils/errors.js" export { formatString } from './utils/functions.js' \ No newline at end of file diff --git a/src/types/dynmap.ts b/src/types/dynmap.ts index 2b34769..3cdf2b3 100644 --- a/src/types/dynmap.ts +++ b/src/types/dynmap.ts @@ -3,7 +3,7 @@ import type { StringContainedWithin, HexString, Opacity -} from 'types' +} from '../types' export type MapResponse = { timestamp: number diff --git a/src/types/nation.ts b/src/types/nation.ts index cd4f100..5f473bd 100644 --- a/src/types/nation.ts +++ b/src/types/nation.ts @@ -3,7 +3,7 @@ import type { RawEntitySpawn, RawEntityStats, RawEntityStatus -} from "types" +} from "../types" import type { Prettify } from "./util.js" diff --git a/src/types/oapi.ts b/src/types/oapi.ts index f0835b0..f19d619 100644 --- a/src/types/oapi.ts +++ b/src/types/oapi.ts @@ -2,7 +2,7 @@ import type { Location, NestedOmit, Prettify -} from 'types' +} from '../types' //#region V2 //#region Parsed diff --git a/src/types/player.ts b/src/types/player.ts index 64cc804..c2649ab 100644 --- a/src/types/player.ts +++ b/src/types/player.ts @@ -1,4 +1,4 @@ -import type { Location, Resident } from 'types' +import type { Location, Resident } from '../types' export type OnlinePlayer = Location & { name: string diff --git a/src/types/squaremap.ts b/src/types/squaremap.ts index 2db2f9c..cc9ab25 100644 --- a/src/types/squaremap.ts +++ b/src/types/squaremap.ts @@ -4,7 +4,7 @@ import type { Opacity, Prettify, StrictPoint2D -} from 'types' +} from '../types' export interface SquaremapPlayersResponse { max: number diff --git a/src/utils/endpoint.ts b/src/utils/endpoint.ts index 90656ad..a49401a 100644 --- a/src/utils/endpoint.ts +++ b/src/utils/endpoint.ts @@ -1,7 +1,7 @@ import endpoints from '../endpoints.json' import { request, type Dispatcher } from "undici" -import type { AnyMap } from "types" +import type { AnyMap } from "../types" import { genRandomString } from './functions.js' diff --git a/src/utils/functions.ts b/src/utils/functions.ts index 92b7a7d..faad0d8 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -5,7 +5,7 @@ import type { Point2D, RawPlayer, Player, Town, BaseTown, BaseNation -} from 'types' +} from '../types' import { NotFound } from './errors.js' diff --git a/tests/squaremap/nations.test.ts b/tests/squaremap/nations.test.ts index ac835e9..36a1501 100644 --- a/tests/squaremap/nations.test.ts +++ b/tests/squaremap/nations.test.ts @@ -13,7 +13,7 @@ describe('[Squaremap/Aurora] Nations', () => { it('can get single nation', async () => { const nation = await Aurora.Nations.get('madagascar') - expect(nation).toBeDefined() + expect(nation).toBeTruthy() expectTypeOf(nation).not.toEqualTypeOf assertType(nation) diff --git a/tsconfig.json b/tsconfig.json index 9ef97f0..ffcf0db 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { - "module": "NodeNext", - "moduleResolution": "NodeNext", + "module": "ESNext", + "moduleResolution": "bundler", "moduleDetection": "force", "target": "ES2017", "lib": ["ES2023"], @@ -15,13 +15,9 @@ "importHelpers": true, "esModuleInterop": true, "resolveJsonModule": true, - "incremental": true, "types": ["node"], "baseUrl": ".", "paths": { - "types": ["src/types", "src/types/index", "./src/types", "./src/types/index.ts"], - "helpers/*": ["./src/helpers/*"], - "utils/*": ["src/utils/*"], "tslib": ["node_modules/tslib/tslib.d.ts"] } }, diff --git a/vitest.config.ts b/vitest.config.ts index 7911756..ed74d7a 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -8,7 +8,6 @@ export default defineConfig({ globals: true, watch: false, globalSetup: "./tests/setup.ts", - reporters: 'verbose', - threads: false + reporters: 'verbose' } }) \ No newline at end of file