From 9427879a285e94a1ea99e04619b84e5997c768e7 Mon Sep 17 00:00:00 2001 From: vilicvane Date: Wed, 1 Nov 2023 00:18:58 +0800 Subject: [PATCH] Make examples esm and add esm to node-ble (#422) --- packages/matter-node-ble.js/package.json | 16 ++++++++++++++-- packages/matter-node-ble.js/require/package.json | 4 ++++ packages/matter-node-ble.js/require/require.cjs | 1 + packages/matter-node-ble.js/require/require.d.ts | 1 + packages/matter-node-ble.js/require/require.mjs | 3 +++ .../matter-node-ble.js/src/ble/BleBroadcaster.ts | 2 +- packages/matter-node-ble.js/src/ble/BleNode.ts | 12 ++++++------ .../src/ble/BlePeripheralInterface.ts | 2 +- .../matter-node-ble.js/src/ble/BleScanner.ts | 2 +- .../matter-node-ble.js/src/ble/BlenoBleServer.ts | 3 ++- .../src/ble/NobleBleChannel.ts | 2 +- .../matter-node-ble.js/src/ble/NobleBleClient.ts | 3 ++- packages/matter-node-ble.js/src/ble/export.ts | 4 ++-- packages/matter-node-ble.js/src/tsconfig.json | 2 +- packages/matter-node.js-examples/package.json | 1 + .../matter-node.js-examples/src/tsconfig.json | 2 +- 16 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 packages/matter-node-ble.js/require/package.json create mode 100644 packages/matter-node-ble.js/require/require.cjs create mode 100644 packages/matter-node-ble.js/require/require.d.ts create mode 100644 packages/matter-node-ble.js/require/require.mjs diff --git a/packages/matter-node-ble.js/package.json b/packages/matter-node-ble.js/package.json index a6181aead8..ee9a1b3228 100644 --- a/packages/matter-node-ble.js/package.json +++ b/packages/matter-node-ble.js/package.json @@ -49,13 +49,25 @@ "LICENSE", "README.md" ], + "type": "module", "main": "dist/cjs/ble/export.js", "types": "dist/cjs/ble/export.d.ts", "exports": { "./package.json": "./package.json", "./*": { - "types": "./dist/cjs/*/export.d.ts", - "default": "./dist/cjs/*/export.js" + "import": { + "types": "./dist/esm/*/export.d.ts", + "default": "./dist/esm/*/export.js" + }, + "require": { + "types": "./dist/cjs/*/export.d.ts", + "default": "./dist/cjs/*/export.js" + } + }, + "./require": { + "types": "./require/require.d.ts", + "import": "./require/require.mjs", + "require": "./require/require.cjs" } }, "typesVersions": { diff --git a/packages/matter-node-ble.js/require/package.json b/packages/matter-node-ble.js/require/package.json new file mode 100644 index 0000000000..0ffb6113fb --- /dev/null +++ b/packages/matter-node-ble.js/require/package.json @@ -0,0 +1,4 @@ +{ + "main": "./require.cjs", + "module": "./require.mjs" +} diff --git a/packages/matter-node-ble.js/require/require.cjs b/packages/matter-node-ble.js/require/require.cjs new file mode 100644 index 0000000000..2457758a98 --- /dev/null +++ b/packages/matter-node-ble.js/require/require.cjs @@ -0,0 +1 @@ +exports.require = require; diff --git a/packages/matter-node-ble.js/require/require.d.ts b/packages/matter-node-ble.js/require/require.d.ts new file mode 100644 index 0000000000..ac0743bb71 --- /dev/null +++ b/packages/matter-node-ble.js/require/require.d.ts @@ -0,0 +1 @@ +export declare const require: NodeRequire; diff --git a/packages/matter-node-ble.js/require/require.mjs b/packages/matter-node-ble.js/require/require.mjs new file mode 100644 index 0000000000..540fef1ae6 --- /dev/null +++ b/packages/matter-node-ble.js/require/require.mjs @@ -0,0 +1,3 @@ +import { createRequire } from "module"; + +export const require = createRequire(import.meta.url); diff --git a/packages/matter-node-ble.js/src/ble/BleBroadcaster.ts b/packages/matter-node-ble.js/src/ble/BleBroadcaster.ts index 7bdd6d93cc..7ff332af25 100644 --- a/packages/matter-node-ble.js/src/ble/BleBroadcaster.ts +++ b/packages/matter-node-ble.js/src/ble/BleBroadcaster.ts @@ -13,7 +13,7 @@ import { import { VendorId } from "@project-chip/matter.js/datatype"; import { Logger } from "@project-chip/matter.js/log"; import { ByteArray } from "@project-chip/matter.js/util"; -import { BlenoBleServer } from "./BlenoBleServer"; +import { BlenoBleServer } from "./BlenoBleServer.js"; const logger = Logger.get("BleBroadcaster"); diff --git a/packages/matter-node-ble.js/src/ble/BleNode.ts b/packages/matter-node-ble.js/src/ble/BleNode.ts index ac1da9773f..159424ad23 100644 --- a/packages/matter-node-ble.js/src/ble/BleNode.ts +++ b/packages/matter-node-ble.js/src/ble/BleNode.ts @@ -8,12 +8,12 @@ import { Ble } from "@project-chip/matter.js/ble"; import { InstanceBroadcaster, Scanner, TransportInterface } from "@project-chip/matter.js/common"; import { NetInterface } from "@project-chip/matter.js/net"; import { ByteArray } from "@project-chip/matter.js/util"; -import { BleBroadcaster } from "./BleBroadcaster"; -import { BlePeripheralInterface } from "./BlePeripheralInterface"; -import { BleScanner } from "./BleScanner"; -import { BlenoBleServer } from "./BlenoBleServer"; -import { NobleBleCentralInterface } from "./NobleBleChannel"; -import { NobleBleClient } from "./NobleBleClient"; +import { BleBroadcaster } from "./BleBroadcaster.js"; +import { BlePeripheralInterface } from "./BlePeripheralInterface.js"; +import { BleScanner } from "./BleScanner.js"; +import { BlenoBleServer } from "./BlenoBleServer.js"; +import { NobleBleCentralInterface } from "./NobleBleChannel.js"; +import { NobleBleClient } from "./NobleBleClient.js"; export type BleOptions = { hciId?: number; diff --git a/packages/matter-node-ble.js/src/ble/BlePeripheralInterface.ts b/packages/matter-node-ble.js/src/ble/BlePeripheralInterface.ts index c8f5cb3de7..53b663c20c 100644 --- a/packages/matter-node-ble.js/src/ble/BlePeripheralInterface.ts +++ b/packages/matter-node-ble.js/src/ble/BlePeripheralInterface.ts @@ -6,7 +6,7 @@ import { Channel, Listener, TransportInterface } from "@project-chip/matter.js/common"; import { ByteArray } from "@project-chip/matter.js/util"; -import { BlenoBleServer } from "./BlenoBleServer"; +import { BlenoBleServer } from "./BlenoBleServer.js"; export class BlePeripheralInterface implements TransportInterface { constructor(private readonly blenoServer: BlenoBleServer) {} diff --git a/packages/matter-node-ble.js/src/ble/BleScanner.ts b/packages/matter-node-ble.js/src/ble/BleScanner.ts index 7da2bcde05..b26d1635dd 100644 --- a/packages/matter-node-ble.js/src/ble/BleScanner.ts +++ b/packages/matter-node-ble.js/src/ble/BleScanner.ts @@ -17,7 +17,7 @@ import { VendorId } from "@project-chip/matter.js/datatype"; import { Logger } from "@project-chip/matter.js/log"; import { Time, Timer } from "@project-chip/matter.js/time"; import { ByteArray, createPromise } from "@project-chip/matter.js/util"; -import { NobleBleClient } from "./NobleBleClient"; +import { NobleBleClient } from "./NobleBleClient.js"; const logger = Logger.get("BleScanner"); diff --git a/packages/matter-node-ble.js/src/ble/BlenoBleServer.ts b/packages/matter-node-ble.js/src/ble/BlenoBleServer.ts index afab454141..5dae950140 100644 --- a/packages/matter-node-ble.js/src/ble/BlenoBleServer.ts +++ b/packages/matter-node-ble.js/src/ble/BlenoBleServer.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { require } from "@project-chip/matter-node-ble.js/require"; import { BLE_MATTER_C1_CHARACTERISTIC_UUID, BLE_MATTER_C2_CHARACTERISTIC_UUID, @@ -18,7 +19,7 @@ import { Channel, InternalError } from "@project-chip/matter.js/common"; import { Logger } from "@project-chip/matter.js/log"; import { Time } from "@project-chip/matter.js/time"; import { ByteArray, createPromise } from "@project-chip/matter.js/util"; -import { BleOptions } from "./BleNode"; +import { BleOptions } from "./BleNode.js"; const logger = Logger.get("BlenoBleServer"); let Bleno: typeof import("@abandonware/bleno"); diff --git a/packages/matter-node-ble.js/src/ble/NobleBleChannel.ts b/packages/matter-node-ble.js/src/ble/NobleBleChannel.ts index 378e530a7e..1cd389d442 100644 --- a/packages/matter-node-ble.js/src/ble/NobleBleChannel.ts +++ b/packages/matter-node-ble.js/src/ble/NobleBleChannel.ts @@ -25,7 +25,7 @@ import { Logger } from "@project-chip/matter.js/log"; import { NetInterface } from "@project-chip/matter.js/net"; import { Time } from "@project-chip/matter.js/time"; import { ByteArray, createPromise } from "@project-chip/matter.js/util"; -import { BleScanner } from "./BleScanner"; +import { BleScanner } from "./BleScanner.js"; const logger = Logger.get("BleChannel"); diff --git a/packages/matter-node-ble.js/src/ble/NobleBleClient.ts b/packages/matter-node-ble.js/src/ble/NobleBleClient.ts index 64dfca981f..7b5cb7bd82 100644 --- a/packages/matter-node-ble.js/src/ble/NobleBleClient.ts +++ b/packages/matter-node-ble.js/src/ble/NobleBleClient.ts @@ -5,10 +5,11 @@ */ import type { Peripheral } from "@abandonware/noble"; +import { require } from "@project-chip/matter-node-ble.js/require"; import { BLE_MATTER_SERVICE_UUID } from "@project-chip/matter.js/ble"; import { Logger } from "@project-chip/matter.js/log"; import { ByteArray } from "@project-chip/matter.js/util"; -import { BleOptions } from "./BleNode"; +import { BleOptions } from "./BleNode.js"; const logger = Logger.get("NobleBleClient"); let noble: typeof import("@abandonware/noble"); diff --git a/packages/matter-node-ble.js/src/ble/export.ts b/packages/matter-node-ble.js/src/ble/export.ts index 7e10bb7b77..fd6f651ae7 100644 --- a/packages/matter-node-ble.js/src/ble/export.ts +++ b/packages/matter-node-ble.js/src/ble/export.ts @@ -5,5 +5,5 @@ */ export * from "./BleBroadcaster.js"; -export * from "./BleNode"; -export * from "./BleScanner"; +export * from "./BleNode.js"; +export * from "./BleScanner.js"; diff --git a/packages/matter-node-ble.js/src/tsconfig.json b/packages/matter-node-ble.js/src/tsconfig.json index ca9b350273..39bb699f93 100644 --- a/packages/matter-node-ble.js/src/tsconfig.json +++ b/packages/matter-node-ble.js/src/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../../tools/tsconfig.base.json", "compilerOptions": { - "outDir": "../dist/cjs", + "outDir": "../dist/esm", "types": ["node"] }, "references": [{ "path": "../../matter.js/src" }], diff --git a/packages/matter-node.js-examples/package.json b/packages/matter-node.js-examples/package.json index 78f35f17b8..1cde9b5419 100644 --- a/packages/matter-node.js-examples/package.json +++ b/packages/matter-node.js-examples/package.json @@ -60,6 +60,7 @@ "LICENSE", "README.md" ], + "type": "module", "publishConfig": { "access": "public" } diff --git a/packages/matter-node.js-examples/src/tsconfig.json b/packages/matter-node.js-examples/src/tsconfig.json index 1d0f40a7fb..811e3cdca4 100644 --- a/packages/matter-node.js-examples/src/tsconfig.json +++ b/packages/matter-node.js-examples/src/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../../tools/tsconfig.base.json", "compilerOptions": { - "outDir": "../dist/cjs", + "outDir": "../dist/esm", "types": ["node"] }, "references": [{ "path": "../../matter-node.js/src" }, { "path": "../../matter-node-ble.js/src" }]