Skip to content

Commit

Permalink
chore: transition modules to hybrid ESM/CJS, switch to vitest for tes…
Browse files Browse the repository at this point in the history
…ting (#7349)
  • Loading branch information
AlCalzone authored Nov 4, 2024
1 parent e2ad6a1 commit 96fbc85
Show file tree
Hide file tree
Showing 597 changed files with 18,274 additions and 16,542 deletions.
77 changes: 67 additions & 10 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,27 @@ jobs:
npm init -y
npm i .tarballs/zwave-js.tgz
echo "Testing entry points..."
echo "Testing ESM entry points..."
# Now all entrypoints should work
node -e '(async () => { await import("zwave-js") })()'
node -e '(async () => { await import("@zwave-js/cc") })()'
node -e '(async () => { await import("@zwave-js/config") })()'
node -e '(async () => { await import("@zwave-js/core") })()'
node -e '(async () => { await import("@zwave-js/host") })()'
node -e '(async () => { await import("@zwave-js/nvmedit") })()'
node -e '(async () => { await import("@zwave-js/serial") })()'
node -e '(async () => { await import("@zwave-js/shared") })()'
node -e '(async () => { await import("@zwave-js/testing") })()'
node -e '(async () => { await import("zwave-js/safe") })()'
node -e '(async () => { await import("@zwave-js/cc/safe") })()'
node -e '(async () => { await import("@zwave-js/config/safe") })()'
node -e '(async () => { await import("@zwave-js/core/safe") })()'
node -e '(async () => { await import("@zwave-js/host/safe") })()'
node -e '(async () => { await import("@zwave-js/nvmedit/safe") })()'
node -e '(async () => { await import("@zwave-js/serial/safe") })()'
node -e '(async () => { await import("@zwave-js/shared/safe") })()'
echo "Testing CJS entry points..."
# Now all entrypoints should work
node -e 'require("zwave-js")'
node -e 'require("@zwave-js/cc")'
Expand Down Expand Up @@ -194,11 +214,13 @@ jobs:
# ===================
# Runs unit tests on all supported node versions and OSes
unit-tests:
name: "Unit tests: ${{ matrix.os }}, Node.js ${{ matrix.node-version }} (part ${{ matrix.shard }})"
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18, 20]
os: [ubuntu-latest]
shard: [1/4, 2/4, 3/4, 4/4]

steps:
- name: Checkout code
Expand All @@ -214,18 +236,47 @@ jobs:
- name: Perform code generation
run: yarn turbo run codegen

# For pull requests, only run tests for changed files
- name: Run component tests (changes)
if: github.event_name == 'pull_request'
run: |
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
yarn run test:dirty --resolve --base origin/${{ github.event.pull_request.base.ref }}
# # For pull requests, only run tests for changed files
# - name: Run component tests (changes)
# if: github.event_name == 'pull_request'
# run: |
# git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
# yarn run test:dirty --resolve --base origin/${{ github.event.pull_request.base.ref }}

# For all other events, especially on master and releases, run the full test suite
# Run the full test suite on master, release branches and tags
- name: Run component tests (full)
if: github.event_name != 'pull_request'
run: yarn run test:ts $TURBO_FLAGS
# if: github.event_name != 'pull_request'
run: yarn run test:ts --shard ${{ matrix.shard }}

# ===================
# Test if the transformers are working
test-transformers:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18, 20]
os: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Prepare testing environment
uses: ./.github/actions/prepare-env
with:
node-version: ${{ matrix.node-version }}
githubToken: ${{ secrets.GITHUB_TOKEN }}

# Transformer tests need their dependencies to be compiled
- name: Compile test dependencies
run: |
yarn workspace @zwave-js/shared run build
yarn workspace @zwave-js/core run build
# For pull requests, only run tests for changed files
- name: Test transformers
run: yarn workspace @zwave-js/transformers run test:ts

# # ===================
# # This job checks if a PR changes the public API surface
Expand Down Expand Up @@ -353,7 +404,13 @@ jobs:
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')
needs: [build, lint, lint-zwave, unit-tests, test-packages]
needs:
- build
- lint
- lint-zwave
- unit-tests
- test-transformers
- test-packages

runs-on: ubuntu-latest
strategy:
Expand Down
24 changes: 6 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
"name": "Debug locally",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"node",
"tsx",
"--async-stack-traces",
"-r",
"./maintenance/esbuild-register.js",
"--conditions=@@dev",
"${workspaceFolder}/test/run.ts"
],
Expand All @@ -52,10 +50,8 @@
"name": "Debug primary and secondary",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"node",
"tsx",
"--async-stack-traces",
"-r",
"./maintenance/esbuild-register.js",
"--conditions=@@dev",
"${workspaceFolder}/test/run_duplex.ts"
],
Expand All @@ -75,11 +71,9 @@
"name": "Generate typed docs",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"node",
"tsx",
"--async-stack-traces",
"--inspect-brk=9229",
"-r",
"./maintenance/esbuild-register.js",
"${workspaceFolder}/packages/maintenance/src/generateTypedDocs.ts"
],
"console": "integratedTerminal",
Expand All @@ -94,11 +88,9 @@
"name": "Decode message",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"node",
"tsx",
"--async-stack-traces",
"--inspect-brk=9229",
"-r",
"./maintenance/esbuild-register.js",
"--conditions=@@dev",
"${workspaceFolder}/test/decodeMessage.ts"
],
Expand All @@ -114,11 +106,9 @@
"cwd": "${workspaceFolder}",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"node",
"tsx",
"--async-stack-traces",
"--inspect=9229",
"-r",
"./maintenance/esbuild-register.js",
"--conditions=@@dev",
"${workspaceFolder}/packages/config/maintenance/importConfig.ts",
"-dm -s zwa"
Expand All @@ -131,10 +121,8 @@
"name": "Run Zniffer",
"runtimeExecutable": "yarn",
"runtimeArgs": [
"node",
"tsx",
"--async-stack-traces",
"-r",
"./maintenance/esbuild-register.js",
"--conditions=@@dev",
"${workspaceFolder}/test/run_zniffer.ts"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/dist/index-esm.mjs b/dist/index-esm.mjs
deleted file mode 100644
index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000
--- a/dist/index-esm.mjs
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/package.json b/package.json
index 1f46c413862b1b4df9bc152a21f1c7405923074e..f0db3ef8b2643b5a37922dc5362c83e36abd4f87 100644
--- a/package.json
+++ b/package.json
@@ -4,10 +4,6 @@
"description": "SerialPort Bindings Typescript Types",
"types": "dist/index.d.ts",
"main": "./dist/index.js",
- "exports": {
- "require": "./dist/index.js",
- "default": "./dist/index-esm.mjs"
- },
"publishConfig": {
"access": "public"
},
13 changes: 13 additions & 0 deletions .yarn/patches/ts-pegjs-npm-4.2.1-0f567a1059.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/tspegjs.mjs b/dist/tspegjs.mjs
index 80c07aa0716f74f7c23c2e51d2b0fb8613941071..ac02b7d22be46a708821755efe4d5d2b9442259d 100644
--- a/dist/tspegjs.mjs
+++ b/dist/tspegjs.mjs
@@ -20,7 +20,7 @@ var __privateMethod = (obj, member, method) => {
var _renameGrammarRules, renameGrammarRules_fn, _initNameMap, initNameMap_fn, _initSourceHeader, initSourceHeader_fn;
import { ts, Project, ScriptTarget } from "ts-morph";
import * as peggy from "peggy";
-import * as prettierPluginTypescript from "prettier/parser-typescript";
+import prettierPluginTypescript from "prettier/parser-typescript";
import prettier from "prettier/standalone";
function wrapNodeInAsConstDeclaration(node) {
node.transform(
2 changes: 1 addition & 1 deletion api-extractor-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
*/
"mainEntryPointFilePath": "<projectFolder>/build/index.d.ts",
"mainEntryPointFilePath": "<projectFolder>/build/esm/index.d.ts",

/**
* A list of NPM package names whose exports should be treated as part of this package.
Expand Down
9 changes: 0 additions & 9 deletions ava.config.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion commitlint.config.js → commitlint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
extends: ["@commitlint/config-conventional"],
rules: {
"body-max-length": [0, "always", Infinity],
Expand Down
2 changes: 1 addition & 1 deletion docs/api/CCs/AlarmSensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Retrieves the current value from this sensor.
### `getSupportedSensorTypes`

```ts
async getSupportedSensorTypes(): Promise<readonly AlarmSensorType[] | undefined>;
async getSupportedSensorTypes(): Promise<AlarmSensorType[] | undefined>;
```

## Alarm Sensor CC values
Expand Down
2 changes: 1 addition & 1 deletion docs/api/CCs/Association.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Returns information about an association group.

```ts
async sendReport(
options: AssociationCCReportSpecificOptions,
options: AssociationCCReportOptions,
): Promise<void>;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/api/CCs/AssociationGroupInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async getGroupInfo(groupId: number, refreshCache: boolean = false): Promise<{ mo

```ts
async reportGroupInfo(
options: AssociationGroupInfoCCInfoReportSpecificOptions,
options: AssociationGroupInfoCCInfoReportOptions,
): Promise<void>;
```

Expand Down
6 changes: 3 additions & 3 deletions docs/api/CCs/FirmwareUpdateMetaData.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ async reportMetaData(
```ts
async requestUpdate(
options: FirmwareUpdateMetaDataCCRequestGetOptions,
): Promise<FirmwareUpdateInitResult>;
): Promise<void>;
```

Requests the device to start the firmware update process.
WARNING: This method may wait up to 60 seconds for a reply.
This does not wait for the reply - that is up to the caller of this method.

### `sendFirmwareFragment`

```ts
async sendFirmwareFragment(
fragmentNumber: number,
isLastFragment: boolean,
data: Buffer,
data: Uint8Array,
): Promise<void>;
```

Expand Down
2 changes: 1 addition & 1 deletion docs/api/CCs/Indicator.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async set(

```ts
async sendReport(
options: IndicatorCCReportSpecificOptions,
options: IndicatorCCReportOptions,
): Promise<void>;
```

Expand Down
4 changes: 2 additions & 2 deletions docs/api/CCs/ManufacturerProprietary.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
```ts
async sendData(
manufacturerId: number,
data?: Buffer,
data?: Uint8Array,
): Promise<void>;
```

### `sendAndReceiveData`

```ts
async sendAndReceiveData(manufacturerId: number, data?: Buffer): Promise<{ manufacturerId: number | undefined; data: Buffer; } | undefined>;
async sendAndReceiveData(manufacturerId: number, data?: Uint8Array): Promise<{ manufacturerId: number | undefined; data: Bytes; } | undefined>;
```
5 changes: 1 addition & 4 deletions docs/api/CCs/MultiChannel.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ async getAggregatedMembers(

```ts
async sendEncapsulated(
options: Omit<
MultiChannelCCCommandEncapsulationOptions,
keyof CCCommandOptions
>,
options: MultiChannelCCCommandEncapsulationOptions,
): Promise<void>;
```

Expand Down
4 changes: 2 additions & 2 deletions docs/api/CCs/Notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```ts
async getInternal(
options: NotificationCCGetSpecificOptions,
options: NotificationCCGetOptions,
): Promise<NotificationCCReport | undefined>;
```

Expand All @@ -25,7 +25,7 @@ async sendReport(
### `get`

```ts
async get(options: NotificationCCGetSpecificOptions): Promise<Pick<NotificationCCReport, "notificationStatus" | "notificationEvent" | "alarmLevel" | "zensorNetSourceNodeId" | "eventParameters" | "sequenceNumber"> | undefined>;
async get(options: NotificationCCGetOptions): Promise<Pick<NotificationCCReport, "notificationStatus" | "notificationEvent" | "alarmLevel" | "eventParameters" | "sequenceNumber"> | undefined>;
```

### `set`
Expand Down
4 changes: 2 additions & 2 deletions docs/api/CCs/Security.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async sendEncapsulated(
### `getNonce`

```ts
async getNonce(): Promise<Buffer | undefined>;
async getNonce(): Promise<Uint8Array | undefined>;
```

Requests a new nonce for Security CC encapsulation which is not directly linked to a specific command.
Expand Down Expand Up @@ -51,7 +51,7 @@ async inheritSecurityScheme(): Promise<void>;
### `setNetworkKey`

```ts
async setNetworkKey(networkKey: Buffer): Promise<void>;
async setNetworkKey(networkKey: Uint8Array): Promise<void>;
```

### `verifyNetworkKey`
Expand Down
6 changes: 3 additions & 3 deletions docs/api/CCs/Security2.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Notifies the target node that the MPAN state is out of sync.
```ts
async sendMPAN(
groupId: number,
innerMPANState: Buffer,
innerMPANState: Uint8Array,
): Promise<boolean>;
```

Expand Down Expand Up @@ -115,7 +115,7 @@ Notifies the other node that the ongoing key exchange was aborted.

```ts
async sendPublicKey(
publicKey: Buffer,
publicKey: Uint8Array,
includingNode: boolean = true,
): Promise<void>;
```
Expand All @@ -133,7 +133,7 @@ async requestNetworkKey(
```ts
async sendNetworkKey(
securityClass: SecurityClass,
networkKey: Buffer,
networkKey: Uint8Array,
): Promise<void>;
```

Expand Down
Loading

0 comments on commit 96fbc85

Please sign in to comment.