build: dual CJS/ESM output, ES2020 target, Node 18 floor
"exports" gains "import" and "types" next to "require": import "alex2node" failed with ERR_PACKAGE_PATH_NOT_EXPORTED. scripts/build.mjs compiles src/ to dist/cjs, dist/esm and dist/types in a staging directory and swaps them in only when both compiler runs passed. "main" and "types" follow for resolvers that do not read "exports". Target ES6 -> ES2020, "engines": node >= 18, relative imports carry ".js" for Node's ESM loader. uuid gives way to crypto.randomUUID(); mqtt is the only runtime dependency left. Tests load the package by name. New: both entry points, the modules the builds import, dist/ equal to a fresh build, a round trip on the ES module build, and two compiled type fixtures in place of the .d.ts regexes. 22 tests pass in 5.7 s. dist/: 16 files, 79,711 B -> 25 files, 132,291 B; the npm tarball is 25,125 B. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
58869d44c1
commit
1d88c7811a
50 changed files with 1472 additions and 195 deletions
|
|
@ -1,8 +1,10 @@
|
|||
import mqtt, { MqttClient, IClientOptions } from "mqtt";
|
||||
import Device from "./Device";
|
||||
// mqtt reaches Node as CommonJS: the default import works from both builds, a named one needs Node to detect it.
|
||||
import mqtt from "mqtt";
|
||||
import type { MqttClient, IClientOptions } from "mqtt";
|
||||
import Device from "./Device.js";
|
||||
import { EventEmitter } from "events";
|
||||
import { DisplayCategory } from "./DisplayCategory";
|
||||
import { AlexaInterfaceType } from "./AlexaInterface";
|
||||
import { DisplayCategory } from "./DisplayCategory.js";
|
||||
import { AlexaInterfaceType } from "./AlexaInterface.js";
|
||||
|
||||
/** Optional settings for the bridge (1.5.1). Everything has the 1.4.0 behaviour as its default. */
|
||||
export interface Alex2MQTTOptions {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import { AlexaInterface, AlexaInterfaceType } from "./AlexaInterface";
|
||||
import { MqttClient } from "mqtt";
|
||||
import { randomUUID } from "crypto";
|
||||
import type { MqttClient } from "mqtt";
|
||||
|
||||
export enum AlexaErrorType {
|
||||
ALREADY_IN_OPERATION = "ALREADY_IN_OPERATION",
|
||||
|
|
@ -102,7 +101,7 @@ export class AlexaErrorResponse {
|
|||
header: {
|
||||
namespace: "Alexa",
|
||||
name: "ErrorResponse",
|
||||
messageId: this.generateMessageId(),
|
||||
messageId: randomUUID(),
|
||||
correlationToken,
|
||||
payloadVersion: "3",
|
||||
},
|
||||
|
|
@ -112,9 +111,6 @@ export class AlexaErrorResponse {
|
|||
payload: {},
|
||||
};
|
||||
}
|
||||
private generateMessageId(): string {
|
||||
return uuidv4();
|
||||
}
|
||||
setErrorMessage(
|
||||
type: string,
|
||||
message: string,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { ActionMapping, AlexaActions } from "./ActionMapping";
|
||||
import type { ActionMapping } from "./ActionMapping.js";
|
||||
|
||||
export enum AlexaInterfaceType {
|
||||
APPLICATION_STATE_REPORTER = "Alexa.ApplicationStateReporter",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import { AlexaInterface, AlexaInterfaceType } from "./AlexaInterface";
|
||||
import { MqttClient } from "mqtt";
|
||||
import { randomUUID } from "crypto";
|
||||
import { AlexaInterfaceType } from "./AlexaInterface.js";
|
||||
import type { MqttClient } from "mqtt";
|
||||
|
||||
export enum EndpointHealth {
|
||||
OK = "OK",
|
||||
|
|
@ -94,7 +94,7 @@ export class AlexaStatusMessage {
|
|||
? "Response"
|
||||
: "StateReport",
|
||||
payloadVersion: "3",
|
||||
messageId: this.generateMessageId(),
|
||||
messageId: randomUUID(),
|
||||
correlationToken,
|
||||
},
|
||||
endpoint: {
|
||||
|
|
@ -104,10 +104,6 @@ export class AlexaStatusMessage {
|
|||
};
|
||||
}
|
||||
|
||||
private generateMessageId(): string {
|
||||
return uuidv4();
|
||||
}
|
||||
|
||||
private getTimestamp(): string {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import { AlexaInterface, AlexaInterfaceType } from "./AlexaInterface";
|
||||
import { DisplayCategory } from "./DisplayCategory";
|
||||
import { AlexaInterface } from "./AlexaInterface.js";
|
||||
import type { AlexaInterfaceType } from "./AlexaInterface.js";
|
||||
import { DisplayCategory } from "./DisplayCategory.js";
|
||||
import { EventEmitter } from "events";
|
||||
import { MqttClient } from "mqtt";
|
||||
import { AlexaStatusMessage, ChangeCause } from "./AlexaStatusMessage";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { AlexaErrorResponse } from "./AlexaErrorResponse";
|
||||
import { randomUUID } from "crypto";
|
||||
import type { MqttClient } from "mqtt";
|
||||
import { AlexaStatusMessage } from "./AlexaStatusMessage.js";
|
||||
import type { ChangeCause } from "./AlexaStatusMessage.js";
|
||||
import { AlexaErrorResponse } from "./AlexaErrorResponse.js";
|
||||
|
||||
class Device extends EventEmitter {
|
||||
protected softwareVersion: string = "1.0.0";
|
||||
|
|
@ -102,7 +104,7 @@ class Device extends EventEmitter {
|
|||
const payload = {
|
||||
context: {},
|
||||
event: {
|
||||
header: { namespace: "Alexa.SceneController", name: activated ? "ActivationStarted" : "DeactivationStarted", messageId: uuidv4(), correlationToken, payloadVersion: "3" },
|
||||
header: { namespace: "Alexa.SceneController", name: activated ? "ActivationStarted" : "DeactivationStarted", messageId: randomUUID(), correlationToken, payloadVersion: "3" },
|
||||
endpoint: { endpointId: this.endpointId },
|
||||
payload: { cause: { type: cause }, timestamp: new Date().toISOString() },
|
||||
},
|
||||
|
|
|
|||
21
src/index.ts
21
src/index.ts
|
|
@ -1,10 +1,11 @@
|
|||
export { default as Alex2MQTT, DEFAULT_HOST } from "./Alex2Node";
|
||||
export type { Alex2MQTTOptions } from "./Alex2Node";
|
||||
export { default as Device } from "./Device";
|
||||
export { AlexaInterface, AlexaInterfaceType } from "./AlexaInterface";
|
||||
export type { SupportedMode } from "./AlexaInterface";
|
||||
export { ActionMapping, AlexaActions } from "./ActionMapping";
|
||||
export { DisplayCategory } from "./DisplayCategory";
|
||||
export { AlexaStatusMessage, PowerController, EndpointHealth, TemperatureSensorScale, ThermostatMode } from "./AlexaStatusMessage";
|
||||
export type { ChangeCause } from "./AlexaStatusMessage";
|
||||
export { AlexaErrorType, AlexaErrorResponse } from "./AlexaErrorResponse";
|
||||
// Relative specifiers carry ".js": Node's ES module loader resolves no extension, and TypeScript maps it back to the .ts.
|
||||
export { default as Alex2MQTT, DEFAULT_HOST } from "./Alex2Node.js";
|
||||
export type { Alex2MQTTOptions } from "./Alex2Node.js";
|
||||
export { default as Device } from "./Device.js";
|
||||
export { AlexaInterface, AlexaInterfaceType } from "./AlexaInterface.js";
|
||||
export type { SupportedMode } from "./AlexaInterface.js";
|
||||
export { ActionMapping, AlexaActions } from "./ActionMapping.js";
|
||||
export { DisplayCategory } from "./DisplayCategory.js";
|
||||
export { AlexaStatusMessage, PowerController, EndpointHealth, TemperatureSensorScale, ThermostatMode } from "./AlexaStatusMessage.js";
|
||||
export type { ChangeCause } from "./AlexaStatusMessage.js";
|
||||
export { AlexaErrorType, AlexaErrorResponse } from "./AlexaErrorResponse.js";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue