Skip to content

Commit

Permalink
ESM Upgrades (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoe-codez authored Nov 16, 2024
1 parent aad257e commit 8c7f322
Show file tree
Hide file tree
Showing 88 changed files with 1,272 additions and 2,213 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
12 changes: 8 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export default [
"plugin:prettier/recommended",
"plugin:@cspell/recommended",
)
.map(config => ({ ...config, files: ["src/**/*.ts"] })),
.map(config => ({ ...config, files: ["src/**/*.mts"] })),
{
files: ["src/**/*.ts"],
files: ["src/**/*.mts"],
languageOptions: {
parser: tsParser,
ecmaVersion: 5,
Expand All @@ -64,7 +64,11 @@ export default [
"@typescript-eslint/no-magic-numbers": "warn",
"unicorn/no-object-as-default-parameter": "off",
"unicorn/no-null": "off",
"sonarjs/no-empty-function": "off",
"sonarjs/no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "off",
"unicorn/no-empty-file": "off",
"unicorn/expiring-todo-comments": "off",
"sonarjs/no-skipped-test": "off",
"sonarjs/prefer-single-boolean-return": "off",
"unicorn/no-array-callback-reference": "off",
Expand Down Expand Up @@ -117,7 +121,7 @@ export default [
},
// module definitions
{
files: ["src/**/*.module.ts"],
files: ["src/**/*.module.mts"],
languageOptions: {
parser: tsParser,
ecmaVersion: 5,
Expand All @@ -131,7 +135,7 @@ export default [
},
},
{
files: ["src/**/*.spec.ts"],
files: ["src/**/*.spec.mts"],
languageOptions: {
globals: { ...globals.jest },
parser: tsParser,
Expand Down
77 changes: 18 additions & 59 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"name": "@digital-alchemy/synapse",
"repository": "https://github.com/Digital-Alchemy-TS/synapse",
"homepage": "https://docs.digital-alchemy.app/Synapse",
"version": "24.11.1",
"version": "24.11.3",
"scripts": {
"start:mock": "tsx src/mock/main.ts",
"start:mock": "tsx src/mock/main.mts",
"build": "rm -rf dist; tsc",
"test": "./scripts/test.sh",
"test": "vitest --no-file-parallelism",
"lint": "eslint src",
"prepublishOnly": "npm run build",
"upgrade": "yarn up '@digital-alchemy/*'",
Expand All @@ -24,7 +24,7 @@
"node": ">=20"
},
"exports": {
".": "./dist/index.js"
".": "./dist/index.mjs"
},
"license": "MIT",
"peerDependencies": {
Expand All @@ -36,81 +36,40 @@
},
"devDependencies": {
"@cspell/eslint-plugin": "^8.16.0",
"@digital-alchemy/core": "^24.10.8",
"@digital-alchemy/hass": "^24.11.1",
"@eslint/compat": "^1.2.2",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.14.0",
"@digital-alchemy/core": "^24.11.3",
"@digital-alchemy/hass": "^24.11.3",
"@eslint/compat": "^1.2.3",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.15.0",
"@types/better-sqlite3": "^7.6.11",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
"@types/node-cron": "^3.0.11",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "8.13.0",
"@typescript-eslint/parser": "8.13.0",
"@typescript-eslint/eslint-plugin": "8.14.0",
"@typescript-eslint/parser": "8.14.0",
"better-sqlite3": "^11.5.0",
"dayjs": "^1.11.13",
"dotenv": "^16.4.5",
"eslint": "9.14.0",
"eslint": "9.15.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jsonc": "^2.16.0",
"eslint-plugin-jsonc": "^2.18.1",
"eslint-plugin-no-unsanitized": "^4.1.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-sonarjs": "^2.0.4",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-unicorn": "^56.0.0",
"globals": "^15.12.0",
"jest": "^29.7.0",
"jest-environment-node": "^29.7.0",
"node-cron": "^3.0.3",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"tsx": "^4.19.2",
"type-fest": "^4.26.1",
"typescript": "^5.6.3",
"uuid": "^11.0.2",
"type-fest": "^4.27.0",
"typescript": "^5.7.0-beta",
"uuid": "^11.0.3",
"vitest": "^2.1.5",
"ws": "^8.18.0"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"collectCoverage": true,
"coverageReporters": [
"text",
"cobertura"
],
"coveragePathIgnorePatterns": [
"src/mock/",
"src/test/"
],
"preset": "ts-jest",
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
"js",
"json",
"node"
],
"setupFiles": [
"<rootDir>/test-setup.ts"
],
"testMatch": [
"**/test/?(*.)+(spec|test).ts"
],
"transform": {
"^.+\\.ts$": [
"ts-jest",
{
"tsconfig": "tsconfig.spec.json",
"useESM": true
}
]
}
},
"packageManager": "yarn@4.5.0"
"packageManager": "yarn@4.5.1"
}
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" npx jest --pass-with-no-tests --runInBand "$1" || exit 1
NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" npx vi --pass-with-no-tests --runInBand "$1" || exit 1
29 changes: 0 additions & 29 deletions src/extensions/domains/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/extensions/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { TRawDomains } from "@digital-alchemy/hass";
import { createHash } from "crypto";
import { EmptyObject } from "type-fest";

import { EntityConfigCommon } from "./common-config.helper";
import { TSynapseId } from "./utility.helper";
import { EntityConfigCommon } from "./common-config.mts";
import { TSynapseId } from "./utility.mts";

export type RemovableCallback<DATA extends unknown = unknown> = (
data: DATA,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
} from "@digital-alchemy/hass";
import { CamelCase } from "type-fest";

import { CreateRemovableCallback, TEventMap } from "./base-domain.helper";
import { TSynapseEntityStorage } from "./storage";
import { TSynapseDeviceId } from "./utility.helper";
import { CreateRemovableCallback, TEventMap } from "./base-domain.mts";
import { TSynapseEntityStorage } from "./storage.mts";
import { TSynapseDeviceId } from "./utility.mts";

export type EntityConfigCommon<ATTRIBUTES extends object, LOCALS extends object> = {
/**
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./base-domain.mts";
export * from "./common-config.mts";
export * from "./sensor.mts";
export * from "./sqlite.mts";
export * from "./storage.mts";
export * from "./utility.mts";
6 changes: 0 additions & 6 deletions src/helpers/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/helpers/sensor.ts → src/helpers/sensor.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dayjs } from "dayjs";

import { EntityConfigCommon, SettableConfiguration } from "./common-config.helper";
import { EntityConfigCommon, SettableConfiguration } from "./common-config.mts";

type DurationSensor = {
device_class: "duration";
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/helpers/storage.ts → src/helpers/storage.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ENTITY_STATE, PICK_ENTITY, TRawDomains } from "@digital-alchemy/hass";

import { AddEntityOptions } from "./base-domain.helper";
import { EntityConfigCommon } from "./common-config.helper";
import { TSynapseId } from "./utility.helper";
import { AddEntityOptions } from "./base-domain.mts";
import { EntityConfigCommon } from "./common-config.mts";
import { TSynapseId } from "./utility.mts";

export type TSynapseEntityStorage<CONFIGURATION extends object = object> = {
unique_id: TSynapseId;
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions src/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./helpers/index.mts";
export * from "./services/index.mts";
export * from "./synapse.module.mts";
3 changes: 0 additions & 3 deletions src/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function MockSynapseConfiguration({
mock_assistant,
}: TServiceParams) {
internal.boilerplate.configuration.set("synapse", "EMIT_HEARTBEAT", false);
internal.boilerplate.configuration.set("synapse", "SQLITE_DB", join(cwd(), "jest_sqlite.db"));
internal.boilerplate.configuration.set("synapse", "SQLITE_DB", join(cwd(), "vi_sqlite.db"));

lifecycle.onPreInit(() => {
if (config.mock_synapse.CLEANUP_DB !== "before") {
Expand Down
1 change: 1 addition & 0 deletions src/mock/extensions/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./configuration.service.mts";
1 change: 0 additions & 1 deletion src/mock/extensions/index.ts

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions src/mock/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./mock-synapse.module.mts";
1 change: 0 additions & 1 deletion src/mock/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/mock/main.ts → src/mock/main.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import weekOfYear from "dayjs/plugin/weekOfYear";

import { LIB_SYNAPSE } from "../synapse.module";
import { EntityGenerator } from "./generator";
import { LIB_SYNAPSE } from "../synapse.module.mts";
import { EntityGenerator } from "./generator.mts";

dayjs.extend(weekOfYear);
dayjs.extend(advancedFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CreateLibrary, createModule, StringConfig } from "@digital-alchemy/core
import { LIB_HASS } from "@digital-alchemy/hass";
import { LIB_MOCK_ASSISTANT } from "@digital-alchemy/hass/mock-assistant";

import { LIB_SYNAPSE } from "../synapse.module";
import { MockSynapseConfiguration } from "./extensions";
import { LIB_SYNAPSE } from "../synapse.module.mts";
import { MockSynapseConfiguration } from "./extensions/configuration.service.mts";

enum CleanupOptions {
before = "before",
Expand Down Expand Up @@ -49,5 +49,6 @@ export const synapseTestRunner = createModule
.fromLibrary(LIB_SYNAPSE)
.extend()
.toTest()
.setOptions({ configSources: { argv: false, env: false, file: false } })
.appendLibrary(LIB_MOCK_SYNAPSE)
.appendLibrary(LIB_MOCK_ASSISTANT);
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { dirname } from "path";
import { cwd } from "process";
import { fileURLToPath } from "url";

import { HassDeviceMetadata, md5ToUUID, TSynapseDeviceId } from "../helpers";
import { HassDeviceMetadata, md5ToUUID, TSynapseDeviceId } from "../helpers/utility.mts";

const host = hostname();

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TServiceParams } from "@digital-alchemy/core";

import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../..";
import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../../helpers/index.mts";

export type AlarmControlPanelStates =
| "disarmed"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TServiceParams } from "@digital-alchemy/core";
import { BinarySensorDeviceClass } from "@digital-alchemy/hass";

import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../..";
import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../../helpers/index.mts";

export type BinarySensorConfiguration = {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TServiceParams } from "@digital-alchemy/core";
import { ButtonDeviceClass } from "@digital-alchemy/hass";

import { AddEntityOptions, BasicAddParams } from "../..";
import { AddEntityOptions, BasicAddParams } from "../../helpers/index.mts";

export type ButtonConfiguration = {
device_class?: `${ButtonDeviceClass}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TServiceParams } from "@digital-alchemy/core";

import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../..";
import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../../helpers/index.mts";

export type CameraConfiguration = {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TServiceParams } from "@digital-alchemy/core";
import { HVACAction, HVACMode } from "@digital-alchemy/hass";

import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../..";
import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../../helpers/index.mts";

export type ClimateConfiguration<
PRESET_MODES extends string = string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TServiceParams } from "@digital-alchemy/core";
import { CoverDeviceClass } from "@digital-alchemy/hass";

import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../..";
import { AddEntityOptions, BasicAddParams, SettableConfiguration } from "../../helpers/index.mts";

export type CoverConfiguration = {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
AddEntityOptions,
BasicAddParams,
BuildCallbacks,
DateTimeConfiguration,
SettableConfiguration,
SynapseEntityException,
} from "../..";
} from "../../helpers/index.mts";
import { DateTimeConfiguration } from "./datetime.service.mts";

type Year = `${number}${number}${number}${number}`;
type MD = `${number}${number}`;
Expand Down
Loading

0 comments on commit 8c7f322

Please sign in to comment.