Skip to content

Commit

Permalink
feat: add "browser" condition to main entrypoint for bundlers (#7374)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Nov 6, 2024
1 parent de4a7ce commit b7b34e1
Show file tree
Hide file tree
Showing 197 changed files with 1,144 additions and 754 deletions.
2 changes: 1 addition & 1 deletion maintenance/parse-zwxml-manufacturers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatId } from "@zwave-js/shared";
import { isArray } from "alcalzone-shared/typeguards/index.js";
import { isArray } from "alcalzone-shared/typeguards";
import fs from "node:fs/promises";
import xml2js from "xml2js";

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0",
"@alcalzone/esm2cjs": "^1.2.3",
"@alcalzone/esm2cjs": "^1.3.0",
"@alcalzone/jsonl-db": "^3.1.1",
"@alcalzone/monopack": "^1.3.0",
"@alcalzone/release-script": "~3.8.0",
Expand Down Expand Up @@ -61,7 +61,7 @@
"@zwave-js/serial": "workspace:*",
"@zwave-js/shared": "workspace:*",
"@zwave-js/testing": "workspace:*",
"alcalzone-shared": "^4.0.8",
"alcalzone-shared": "^5.0.0",
"ansi-colors": "^4.1.3",
"chokidar": "^4.0.1",
"comment-json": "^4.2.5",
Expand Down
5 changes: 3 additions & 2 deletions packages/cc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"exports": {
".": {
"@@dev": "./src/index.ts",
"browser": "./build/esm/index_browser.js",
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
},
Expand Down Expand Up @@ -70,12 +71,12 @@
"@zwave-js/core": "workspace:*",
"@zwave-js/host": "workspace:*",
"@zwave-js/shared": "workspace:*",
"alcalzone-shared": "^4.0.8",
"alcalzone-shared": "^5.0.0",
"ansi-colors": "^4.1.3",
"reflect-metadata": "^0.2.2"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.2.3",
"@alcalzone/esm2cjs": "^1.3.0",
"@microsoft/api-extractor": "^7.47.9",
"@types/node": "^18.19.63",
"@zwave-js/maintenance": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/src/cc/AssociationCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
} from "@zwave-js/host/safe";
import { Bytes } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { distinct } from "alcalzone-shared/arrays/index.js";
import { distinct } from "alcalzone-shared/arrays";
import { CCAPI, PhysicalCCAPI } from "../lib/API.js";
import {
type CCRaw,
Expand Down
5 changes: 2 additions & 3 deletions packages/cc/src/cc/CentralSceneCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { getEnumMemberName, pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { padStart } from "alcalzone-shared/strings/index.js";
import {
CCAPI,
POLL_VALUE,
Expand Down Expand Up @@ -80,14 +79,14 @@ export const CentralSceneCCValues = Object.freeze({
...V.dynamicPropertyAndKeyWithName(
"scene",
"scene",
(sceneNumber: number) => padStart(sceneNumber.toString(), 3, "0"),
(sceneNumber: number) => sceneNumber.toString().padStart(3, "0"),
({ property, propertyKey }) =>
property === "scene"
&& typeof propertyKey === "string"
&& /^\d{3}$/.test(propertyKey),
(sceneNumber: number) => ({
...ValueMetadata.ReadOnlyUInt8,
label: `Scene ${padStart(sceneNumber.toString(), 3, "0")}`,
label: `Scene ${sceneNumber.toString().padStart(3, "0")}`,
} as const),
{ stateful: false } as const,
),
Expand Down
11 changes: 4 additions & 7 deletions packages/cc/src/cc/ClimateControlScheduleCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { getEnumMemberName } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { padStart } from "alcalzone-shared/strings/index.js";
import { CCAPI } from "../lib/API.js";
import { type CCRaw, CommandClass } from "../lib/CommandClass.js";
import {
Expand Down Expand Up @@ -274,9 +273,8 @@ export class ClimateControlScheduleCCSet extends ClimateControlScheduleCC {
this.switchPoints
.map(
(sp) => `
· ${padStart(sp.hour.toString(), 2, "0")}:${
padStart(
sp.minute.toString(),
· ${sp.hour.toString().padStart(2, "0")}:${
sp.minute.toString().padStart(
2,
"0",
)
Expand Down Expand Up @@ -349,9 +347,8 @@ export class ClimateControlScheduleCCReport extends ClimateControlScheduleCC {
this.schedule
.map(
(sp) => `
· ${padStart(sp.hour.toString(), 2, "0")}:${
padStart(
sp.minute.toString(),
· ${sp.hour.toString().padStart(2, "0")}:${
sp.minute.toString().padStart(
2,
"0",
)
Expand Down
11 changes: 4 additions & 7 deletions packages/cc/src/cc/ClockCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { getEnumMemberName, pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { padStart } from "alcalzone-shared/strings/index.js";
import { CCAPI } from "../lib/API.js";
import {
type CCRaw,
Expand Down Expand Up @@ -195,9 +194,8 @@ export class ClockCCSet extends ClockCC {
Weekday,
this.weekday,
)
}, ${padStart(this.hour.toString(), 2, "0")}:${
padStart(
this.minute.toString(),
}, ${this.hour.toString().padStart(2, "0")}:${
this.minute.toString().padStart(
2,
"0",
)
Expand Down Expand Up @@ -259,9 +257,8 @@ export class ClockCCReport extends ClockCC {
Weekday,
this.weekday,
)
}, ${padStart(this.hour.toString(), 2, "0")}:${
padStart(
this.minute.toString(),
}, ${this.hour.toString().padStart(2, "0")}:${
this.minute.toString().padStart(
2,
"0",
)
Expand Down
4 changes: 2 additions & 2 deletions packages/cc/src/cc/ColorSwitchCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import {
pick,
} from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { clamp } from "alcalzone-shared/math/index.js";
import { isObject } from "alcalzone-shared/typeguards/index.js";
import { clamp } from "alcalzone-shared/math";
import { isObject } from "alcalzone-shared/typeguards";
import {
CCAPI,
POLL_VALUE,
Expand Down
10 changes: 4 additions & 6 deletions packages/cc/src/cc/ConfigurationCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { getEnumMemberName, pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { distinct } from "alcalzone-shared/arrays/index.js";
import { composeObject } from "alcalzone-shared/objects/index.js";
import { padStart } from "alcalzone-shared/strings/index.js";
import { distinct } from "alcalzone-shared/arrays";
import {
CCAPI,
type CCAPIEndpoint,
Expand Down Expand Up @@ -1409,7 +1407,7 @@ alters capabilities: ${!!properties.altersCapabilities}`;
.map((v) => v.property)
.filter((p) => typeof p === "number"),
);
return composeObject(
return Object.fromEntries(
parameters.map((p) => [
p as any,
this.getParamInformation(ctx, p),
Expand Down Expand Up @@ -1532,7 +1530,7 @@ alters capabilities: ${!!properties.altersCapabilities}`;
writeable: !info.readOnly,
allowManualEntry: info.allowManualEntry,
states: info.options.length > 0
? composeObject(
? Object.fromEntries(
info.options.map(({ label, value }) => [
value.toString(),
label,
Expand Down Expand Up @@ -1592,7 +1590,7 @@ alters capabilities: ${!!properties.altersCapabilities}`;
);
if (paramInfo.label) return paramInfo.label;
// fall back to paramXYZ[_key] if none is defined
let ret = `param${padStart(property.toString(), 3, "0")}`;
let ret = `param${property.toString().padStart(3, "0")}`;
if (propertyKey != undefined) {
ret += "_" + propertyKey.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/src/cc/DoorLockCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { getEnumMemberName, pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { isArray } from "alcalzone-shared/typeguards/index.js";
import { isArray } from "alcalzone-shared/typeguards";
import {
CCAPI,
POLL_VALUE,
Expand Down
4 changes: 2 additions & 2 deletions packages/cc/src/cc/IndicatorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { num2hex } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { clamp, roundTo } from "alcalzone-shared/math/index.js";
import { isArray } from "alcalzone-shared/typeguards/index.js";
import { clamp, roundTo } from "alcalzone-shared/math";
import { isArray } from "alcalzone-shared/typeguards";
import {
CCAPI,
POLL_VALUE,
Expand Down
17 changes: 7 additions & 10 deletions packages/cc/src/cc/IrrigationCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { getEnumMemberName, pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { padStart } from "alcalzone-shared/strings/index.js";
import {
CCAPI,
POLL_VALUE,
Expand Down Expand Up @@ -555,7 +554,7 @@ export const IrrigationCCValues = Object.freeze({

function valveIdToMetadataPrefix(valveId: ValveId): string {
if (valveId === "master") return "Master valve";
return `Valve ${padStart(valveId.toString(), 3, "0")}`;
return `Valve ${valveId.toString().padStart(3, "0")}`;
}

const systemConfigProperties = [
Expand Down Expand Up @@ -1309,8 +1308,7 @@ moisture sensor polarity: ${
ctx.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Querying configuration for valve ${
padStart(
i.toString(),
i.toString().padStart(
3,
"0",
)
Expand All @@ -1322,8 +1320,7 @@ moisture sensor polarity: ${
ctx.logNode(node.id, {
endpoint: this.endpointIndex,
message: `Querying status for valve ${
padStart(
i.toString(),
i.toString().padStart(
3,
"0",
)
Expand All @@ -1342,7 +1339,7 @@ moisture sensor polarity: ${
if (property === "master") {
return "Master valve";
} else if (typeof property === "number") {
return `Valve ${padStart(property.toString(), 3, "0")}`;
return `Valve ${property.toString().padStart(3, "0")}`;
}
return super.translateProperty(ctx, property, propertyKey);
}
Expand Down Expand Up @@ -2522,7 +2519,7 @@ export class IrrigationCCValveTableSet extends IrrigationCC {
};
for (let i = 0; i < this.entries.length; i++) {
const entry = this.entries[i];
const valveLabel = padStart(entry.valveId.toString(), 3, "0");
const valveLabel = entry.valveId.toString().padStart(3, "0");
if (entry.duration) {
message[`valve ${valveLabel} duration`] = `${entry.duration} s`;
} else {
Expand Down Expand Up @@ -2584,7 +2581,7 @@ export class IrrigationCCValveTableReport extends IrrigationCC {
};
for (let i = 0; i < this.entries.length; i++) {
const entry = this.entries[i];
const valveLabel = padStart(entry.valveId.toString(), 3, "0");
const valveLabel = entry.valveId.toString().padStart(3, "0");
if (entry.duration) {
message[`valve ${valveLabel} duration`] = `${entry.duration} s`;
} else {
Expand Down Expand Up @@ -2703,7 +2700,7 @@ export class IrrigationCCValveTableRun extends IrrigationCC {
...super.toLogEntry(ctx),
message: {
"table IDs": this.tableIDs
.map((id) => padStart(id.toString(), 3, "0"))
.map((id) => id.toString().padStart(3, "0"))
.join(", "),
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/src/cc/MultiChannelCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
} from "@zwave-js/host/safe";
import { Bytes } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { distinct } from "alcalzone-shared/arrays/index.js";
import { distinct } from "alcalzone-shared/arrays";
import { CCAPI } from "../lib/API.js";
import {
type CCRaw,
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/src/cc/NotificationCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type {
import { Bytes, isUint8Array } from "@zwave-js/shared/safe";
import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { isArray } from "alcalzone-shared/typeguards/index.js";
import { isArray } from "alcalzone-shared/typeguards";
import {
CCAPI,
POLL_VALUE,
Expand Down
3 changes: 1 addition & 2 deletions packages/cc/src/cc/ProtectionCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { getEnumMemberName, pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { padStart } from "alcalzone-shared/strings/index.js";
import {
CCAPI,
POLL_VALUE,
Expand Down Expand Up @@ -490,7 +489,7 @@ rf ${getEnumMemberName(RFProtectionState, protectionResp.rf)}`;
if (nodeId != undefined) {
ctx.logNode(node.id, {
message: (nodeId !== 0
? `Node ${padStart(nodeId.toString(), 3, "0")}`
? `Node ${nodeId.toString().padStart(3, "0")}`
: `no node`) + ` has exclusive control`,
direction: "inbound",
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cc/src/cc/Security2CC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import type {
} from "@zwave-js/host/safe";
import { Bytes } from "@zwave-js/shared/safe";
import { buffer2hex, getEnumMemberName, pick } from "@zwave-js/shared/safe";
import { wait } from "alcalzone-shared/async/index.js";
import { isArray } from "alcalzone-shared/typeguards/index.js";
import { wait } from "alcalzone-shared/async";
import { isArray } from "alcalzone-shared/typeguards";
import { CCAPI } from "../lib/API.js";
import {
type CCRaw,
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/src/cc/SecurityCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
} from "@zwave-js/host/safe";
import { Bytes } from "@zwave-js/shared/safe";
import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe";
import { wait } from "alcalzone-shared/async/index.js";
import { wait } from "alcalzone-shared/async";
import { randomBytes } from "node:crypto";
import { CCAPI, PhysicalCCAPI } from "../lib/API.js";
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/src/cc/SoundSwitchCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { clamp } from "alcalzone-shared/math/index.js";
import { clamp } from "alcalzone-shared/math";
import {
CCAPI,
POLL_VALUE,
Expand Down
21 changes: 6 additions & 15 deletions packages/cc/src/cc/TimeCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
import { Bytes } from "@zwave-js/shared/safe";
import { pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
import { padStart } from "alcalzone-shared/strings/index.js";
import { CCAPI } from "../lib/API.js";
import {
type CCRaw,
Expand Down Expand Up @@ -286,13 +285,9 @@ export class TimeCCTimeReport extends TimeCC {
return {
...super.toLogEntry(ctx),
message: {
time: `${padStart(this.hour.toString(), 2, "0")}:${
padStart(
this.minute.toString(),
2,
"0",
)
}:${padStart(this.second.toString(), 2, "0")}`,
time: `${this.hour.toString().padStart(2, "0")}:${
this.minute.toString().padStart(2, "0")
}:${this.second.toString().padStart(2, "0")}`,
},
};
}
Expand Down Expand Up @@ -354,13 +349,9 @@ export class TimeCCDateReport extends TimeCC {
return {
...super.toLogEntry(ctx),
message: {
date: `${padStart(this.year.toString(), 4, "0")}-${
padStart(
this.month.toString(),
2,
"0",
)
}-${padStart(this.day.toString(), 2, "0")}`,
date: `${this.year.toString().padStart(4, "0")}-${
this.month.toString().padStart(2, "0")
}-${this.day.toString().padStart(2, "0")}`,
},
};
}
Expand Down
Loading

0 comments on commit b7b34e1

Please sign in to comment.