Skip to content

Commit

Permalink
fix: ensure CC classes are not randomly renamed during CJS transform (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Nov 20, 2024
1 parent ef68078 commit 2cffecf
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 28 deletions.
3 changes: 2 additions & 1 deletion 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.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@alcalzone/jsonl-db": "^3.1.1",
"@alcalzone/monopack": "^1.3.0",
"@alcalzone/release-script": "~3.8.0",
Expand Down Expand Up @@ -81,6 +81,7 @@
"reflect-metadata": "^0.2.2",
"semver": "^7.6.3",
"source-map-support": "^0.5.21",
"ts-morph": "^24.0.0",
"ts-patch": "3.2.1",
"tsx": "^4.19.2",
"turbo": "2.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"reflect-metadata": "^0.2.2"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@types/node": "^18.19.63",
"@zwave-js/maintenance": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"winston": "^3.15.0"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@types/js-levenshtein": "^1.1.3",
"@types/json-logic-js": "^2.0.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"winston-transport": "^4.8.0"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@types/node": "^18.19.63",
"@types/semver": "^7.5.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"lint:ts:fix": "yarn run lint:ts --fix"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@types/eslint": "^9.6.1",
"@typescript-eslint/utils": "^8.8.1",
"@zwave-js/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"alcalzone-shared": "^5.0.0"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@types/node": "^18.19.63",
"del-cli": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/maintenance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"lint:ts:fix": "yarn run lint:ts --fix"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@dprint/formatter": "^0.4.1",
"@dprint/json": "^0.19.4",
"@dprint/markdown": "^0.17.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/nvmedit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"test:dirty": "tsx ../maintenance/src/resolveDirtyTests.ts --run"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@types/node": "^18.19.63",
"@types/semver": "^7.5.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/serial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"winston": "^3.15.0"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@serialport/binding-mock": "^10.2.2",
"@serialport/bindings-interface": "patch:@serialport/bindings-interface@npm%3A1.2.2#~/.yarn/patches/@serialport-bindings-interface-npm-1.2.2-e597dbc676.patch",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"test:dirty": "tsx ../maintenance/src/resolveDirtyTests.ts --run"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@types/node": "^18.19.63",
"@types/sinon": "^17.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"ansi-colors": "^4.1.3"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@types/node": "^18.19.63",
"@types/triple-beam": "^1.3.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/zwave-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"xstate": "4.38.3"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.4.0",
"@alcalzone/esm2cjs": "^1.4.1",
"@microsoft/api-extractor": "^7.47.9",
"@types/node": "^18.19.63",
"@types/proper-lockfile": "^4.1.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {
BinarySwitchCCReport,
BinarySwitchCCValues,
type CommandClass,
MultiChannelCC,
} from "@zwave-js/cc";
import { CommandClasses } from "@zwave-js/core";
import { ccCaps, createMockZWaveRequestFrame } from "@zwave-js/testing";
import { wait } from "alcalzone-shared/async";
import { integrationTest } from "../integrationTestSuite.js";

integrationTest(
"The compat flag mapRootReportsToEndpoint works correctly",
{
// debug: true,

nodeCapabilities: {
// Fibaro FGS221 uses the flag
manufacturerId: 0x010f,
productType: 0x0200,
productId: 0x0102,

commandClasses: [
CommandClasses.Version,
{
ccId: CommandClasses["Multi Channel"],
version: 2,
},
CommandClasses["Manufacturer Specific"],
CommandClasses["Binary Switch"],
],

endpoints: [
{
commandClasses: [
ccCaps({
ccId: CommandClasses["Binary Switch"],
isSupported: true,
defaultValue: false,
}),
],
},
{
commandClasses: [
ccCaps({
ccId: CommandClasses["Binary Switch"],
isSupported: true,
defaultValue: false,
}),
],
},
],
},

async testBody(t, driver, node, mockController, mockNode) {
// Send a report from endpoint 2. It should end up on endpoint 2.
let cc: CommandClass = new BinarySwitchCCReport({
nodeId: 2,
currentValue: true,
});
cc = MultiChannelCC.encapsulate(cc);
cc.endpointIndex = 2;

await mockNode.sendToController(
createMockZWaveRequestFrame(cc, { ackRequested: false }),
);

await wait(100);

t.expect(
node.getValue(BinarySwitchCCValues.currentValue.endpoint(2)),
).toBe(true);

// Send another one from the root. It should end up on endpoint 1.
cc = new BinarySwitchCCReport({
nodeId: 2,
currentValue: true,
});

await mockNode.sendToController(
createMockZWaveRequestFrame(cc, { ackRequested: false }),
);

await wait(100);

t.expect(
node.getValue(BinarySwitchCCValues.currentValue.endpoint(1)),
).toBe(true);
},
},
);
33 changes: 17 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ __metadata:
languageName: node
linkType: hard

"@alcalzone/esm2cjs@npm:^1.4.0":
version: 1.4.0
resolution: "@alcalzone/esm2cjs@npm:1.4.0"
"@alcalzone/esm2cjs@npm:^1.4.1":
version: 1.4.1
resolution: "@alcalzone/esm2cjs@npm:1.4.1"
dependencies:
esbuild: "npm:^0.24.0"
fs-extra: "npm:^10.1.0"
tiny-glob: "npm:^0.2.9"
yargs: "npm:^17.5.1"
bin:
esm2cjs: bin/esm2cjs.cjs
checksum: 10/9ab7c4e383e8762319de1f79bd2dd8134f47b5227a935387764a7b7a159de8bab36806274ca875368e821f95285fb61fa4bc2b09df6af3302e5ec524f7e06463
checksum: 10/9133100b28480d03e03b3aca5777cd48308c01a8ff2cec1fa68e86fdde29b0c28a4559cd658676bc215bdb09b2cb5ba267744cfcb320283ef500c95985ea8c56
languageName: node
linkType: hard

Expand Down Expand Up @@ -2558,7 +2558,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/cc@workspace:packages/cc"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@microsoft/api-extractor": "npm:^7.47.9"
"@types/node": "npm:^18.19.63"
"@zwave-js/core": "workspace:*"
Expand All @@ -2581,7 +2581,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/config@workspace:packages/config"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@microsoft/api-extractor": "npm:^7.47.9"
"@types/js-levenshtein": "npm:^1.1.3"
"@types/json-logic-js": "npm:^2.0.7"
Expand Down Expand Up @@ -2621,7 +2621,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/core@workspace:packages/core"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@alcalzone/jsonl-db": "npm:^3.1.1"
"@microsoft/api-extractor": "npm:^7.47.9"
"@types/node": "npm:^18.19.63"
Expand Down Expand Up @@ -2653,7 +2653,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/eslint-plugin@workspace:packages/eslint-plugin"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@types/eslint": "npm:^9.6.1"
"@typescript-eslint/utils": "npm:^8.8.1"
"@zwave-js/core": "workspace:*"
Expand Down Expand Up @@ -2698,7 +2698,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/host@workspace:packages/host"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@microsoft/api-extractor": "npm:^7.47.9"
"@types/node": "npm:^18.19.63"
"@zwave-js/config": "workspace:*"
Expand All @@ -2714,7 +2714,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/maintenance@workspace:packages/maintenance"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@dprint/formatter": "npm:^0.4.1"
"@dprint/json": "npm:^0.19.4"
"@dprint/markdown": "npm:^0.17.8"
Expand Down Expand Up @@ -2746,7 +2746,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/nvmedit@workspace:packages/nvmedit"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@microsoft/api-extractor": "npm:^7.47.9"
"@types/node": "npm:^18.19.63"
"@types/semver": "npm:^7.5.8"
Expand All @@ -2773,7 +2773,7 @@ __metadata:
"@actions/core": "npm:^1.11.1"
"@actions/exec": "npm:^1.1.1"
"@actions/github": "npm:^6.0.0"
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@alcalzone/jsonl-db": "npm:^3.1.1"
"@alcalzone/monopack": "npm:^1.3.0"
"@alcalzone/release-script": "npm:~3.8.0"
Expand Down Expand Up @@ -2822,6 +2822,7 @@ __metadata:
reflect-metadata: "npm:^0.2.2"
semver: "npm:^7.6.3"
source-map-support: "npm:^0.5.21"
ts-morph: "npm:^24.0.0"
ts-patch: "npm:3.2.1"
tsx: "npm:^4.19.2"
turbo: "npm:2.2.3"
Expand All @@ -2837,7 +2838,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/serial@workspace:packages/serial"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@microsoft/api-extractor": "npm:^7.47.9"
"@serialport/binding-mock": "npm:^10.2.2"
"@serialport/bindings-interface": "patch:@serialport/bindings-interface@npm%3A1.2.2#~/.yarn/patches/@serialport-bindings-interface-npm-1.2.2-e597dbc676.patch"
Expand All @@ -2864,7 +2865,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/shared@workspace:packages/shared"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@microsoft/api-extractor": "npm:^7.47.9"
"@types/node": "npm:^18.19.63"
"@types/sinon": "npm:^17.0.3"
Expand All @@ -2881,7 +2882,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@zwave-js/testing@workspace:packages/testing"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@microsoft/api-extractor": "npm:^7.47.9"
"@types/node": "npm:^18.19.63"
"@types/triple-beam": "npm:^1.3.5"
Expand Down Expand Up @@ -10068,7 +10069,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "zwave-js@workspace:packages/zwave-js"
dependencies:
"@alcalzone/esm2cjs": "npm:^1.4.0"
"@alcalzone/esm2cjs": "npm:^1.4.1"
"@alcalzone/jsonl-db": "npm:^3.1.1"
"@homebridge/ciao": "npm:^1.3.1"
"@microsoft/api-extractor": "npm:^7.47.9"
Expand Down

0 comments on commit 2cffecf

Please sign in to comment.