node-thermal-printer-js 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/app.js +7 -5
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -62,18 +62,20 @@ const printViaComPort = async (data, options = {}) => {
62
62
  const baudRate = options.baudRate || 9600;
63
63
 
64
64
  // Dynamically import `serialport` only when COM transport is requested.
65
- let SerialPortModule;
65
+ let SerialPortCtor;
66
66
  try {
67
- SerialPortModule = await import("serialport");
67
+ const SerialPortModule = await import("serialport");
68
+ SerialPortCtor = SerialPortModule.SerialPort || SerialPortModule.default;
69
+
70
+ if (!SerialPortCtor) {
71
+ throw new Error("SerialPort constructor not found in module exports");
72
+ }
68
73
  } catch (e) {
69
74
  return Promise.reject(
70
75
  new Error(`serialport module not available: ${e.message}`),
71
76
  );
72
77
  }
73
78
 
74
- const SerialPortCtor =
75
- SerialPortModule.default || SerialPortModule.SerialPort || SerialPortModule;
76
-
77
79
  const port = new SerialPortCtor({
78
80
  path: portPath,
79
81
  baudRate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-thermal-printer-js",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "ESC/POS printer helper for PSF588 Bluetooth and COM printing.",
5
5
  "main": "app.js",
6
6
  "exports": {