@risleylima/escpos 0.0.13 → 0.1.0
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.
- package/CHANGELOG.md +60 -0
- package/README.md +798 -8
- package/docs/COVERAGE_ANALYSIS.md +98 -0
- package/docs/DEPENDENCIES_REVIEW.md +127 -0
- package/docs/JSDOC_REVIEW.md +122 -0
- package/docs/LIBRARY_OVERVIEW.md +383 -0
- package/docs/PRE_PUBLISH_CHECKLIST.md +331 -0
- package/docs/PUBLIC_API_ANALYSIS.md +224 -0
- package/docs/README.md +34 -0
- package/docs/SERIALPORT_V13_MIGRATION_COMPLETE.md +127 -0
- package/docs/TESTS_IMPLEMENTED.md +129 -0
- package/docs/USB_V2_REVIEW.md +148 -0
- package/docs/VERIFICATION_RESULTS.md +172 -0
- package/jest.config.js +16 -0
- package/package.json +12 -7
- package/src/adapter/index.js +37 -0
- package/src/printer/commands.js +6 -4
- package/src/printer/image.js +28 -7
- package/src/printer/index.js +7 -2
- package/src/printer/utils.js +21 -14
- package/src/serial-adapter/index.js +133 -84
- package/src/usb-adapter/index.js +157 -43
- package/tests/README.md +67 -0
- package/tests/integration/printer-flow.test.js +128 -0
- package/tests/unit/adapters/adapter.test.js +49 -0
- package/tests/unit/adapters/serial-adapter.test.js +224 -0
- package/tests/unit/adapters/usb-adapter.test.js +319 -0
- package/tests/unit/image/image.test.js +157 -0
- package/tests/unit/printer/buffer.test.js +60 -0
- package/tests/unit/printer/commands.test.js +109 -0
- package/tests/unit/printer/printer.test.js +405 -0
- package/tests/unit/utils/utils.test.js +96 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
# Library Overview - @risleylima/escpos
|
|
2
|
+
|
|
3
|
+
## 📋 General Information
|
|
4
|
+
|
|
5
|
+
- **Name**: `@risleylima/escpos`
|
|
6
|
+
- **Version**: `0.0.14`
|
|
7
|
+
- **License**: MIT
|
|
8
|
+
- **Node.js**: `>=18.0.0`
|
|
9
|
+
- **Description**: Library to manage ESC/POS commands in Buffer (Node.js), then use an adapter to send the resulting data to the printer.
|
|
10
|
+
|
|
11
|
+
## 🏗️ Architecture
|
|
12
|
+
|
|
13
|
+
### Core Components
|
|
14
|
+
|
|
15
|
+
The library follows a modular architecture with clear separation of concerns:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
escpos/
|
|
19
|
+
├── src/
|
|
20
|
+
│ ├── adapter/ # Base adapter class (EventEmitter)
|
|
21
|
+
│ ├── usb-adapter/ # USB communication adapter
|
|
22
|
+
│ ├── serial-adapter/ # Serial port communication adapter
|
|
23
|
+
│ └── printer/ # ESC/POS command generation
|
|
24
|
+
│ ├── commands.js # ESC/POS command definitions
|
|
25
|
+
│ ├── image.js # Image processing for thermal printers
|
|
26
|
+
│ ├── utils.js # Utility functions
|
|
27
|
+
│ └── index.js # Main Printer class
|
|
28
|
+
├── tests/ # Comprehensive test suite
|
|
29
|
+
│ ├── unit/ # Unit tests
|
|
30
|
+
│ └── integration/ # Integration tests
|
|
31
|
+
└── examples/ # Usage examples
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Public API
|
|
35
|
+
|
|
36
|
+
The library exports the following modules:
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
const { USB, Serial, Printer, Adapter, Image } = require('@risleylima/escpos');
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- **USB**: USB adapter instance (EventEmitter)
|
|
43
|
+
- **Serial**: Serial port adapter instance (EventEmitter)
|
|
44
|
+
- **Printer**: ESC/POS command generator class
|
|
45
|
+
- **Adapter**: Base adapter class
|
|
46
|
+
- **Image**: Image processing utilities
|
|
47
|
+
|
|
48
|
+
## 🔌 Adapters
|
|
49
|
+
|
|
50
|
+
### USB Adapter (`usb-adapter`)
|
|
51
|
+
|
|
52
|
+
- **Technology**: `node-usb` v2.16.0 (Promise-based API)
|
|
53
|
+
- **Features**:
|
|
54
|
+
- Device discovery and listing
|
|
55
|
+
- VID/PID-based connection
|
|
56
|
+
- Automatic printer interface detection
|
|
57
|
+
- Kernel driver handling (Linux/macOS)
|
|
58
|
+
- Event-driven architecture (connect, disconnect, close, detach)
|
|
59
|
+
- Error handling and recovery
|
|
60
|
+
|
|
61
|
+
**Key Methods**:
|
|
62
|
+
- `listUSB()`: List all USB printer devices
|
|
63
|
+
- `connect(vid, pid)`: Connect to a specific device
|
|
64
|
+
- `open()`: Open device and claim interface
|
|
65
|
+
- `write(data)`: Send data to printer
|
|
66
|
+
- `close()`: Close device connection
|
|
67
|
+
- `disconnect()`: Disconnect device
|
|
68
|
+
|
|
69
|
+
### Serial Adapter (`serial-adapter`)
|
|
70
|
+
|
|
71
|
+
- **Technology**: `serialport` v13.0.0 (Promise-based API)
|
|
72
|
+
- **Features**:
|
|
73
|
+
- Port verification
|
|
74
|
+
- Auto-open disabled (manual control)
|
|
75
|
+
- Event-driven architecture (connect, disconnect, close)
|
|
76
|
+
- Error handling via events
|
|
77
|
+
- Flush and drain operations
|
|
78
|
+
|
|
79
|
+
**Key Methods**:
|
|
80
|
+
- `connect(port, options)`: Connect to serial port
|
|
81
|
+
- `open()`: Open port if closed
|
|
82
|
+
- `write(data)`: Send data to printer
|
|
83
|
+
- `read()`: Read data from port
|
|
84
|
+
- `close(timeout)`: Close port with optional timeout
|
|
85
|
+
- `disconnect(timeout)`: Disconnect port
|
|
86
|
+
|
|
87
|
+
## 🖨️ Printer Class
|
|
88
|
+
|
|
89
|
+
The `Printer` class generates ESC/POS commands and manages a buffer system.
|
|
90
|
+
|
|
91
|
+
### Core Features
|
|
92
|
+
|
|
93
|
+
- **Buffer Management**: Dynamic buffer for command accumulation
|
|
94
|
+
- **Text Operations**: Print text with encoding support
|
|
95
|
+
- **Formatting**: Alignment, size, style (bold, italic, underline)
|
|
96
|
+
- **Hardware Control**: Cut, beep, cash drawer
|
|
97
|
+
- **Barcode Generation**: Multiple barcode formats
|
|
98
|
+
- **Image Printing**: Convert and print images
|
|
99
|
+
- **Method Chaining**: Fluent API for command composition
|
|
100
|
+
|
|
101
|
+
### Key Methods
|
|
102
|
+
|
|
103
|
+
**Text Operations**:
|
|
104
|
+
- `print(data)`: Print raw data
|
|
105
|
+
- `println(data)`: Print with line break
|
|
106
|
+
- `text(content, encoding)`: Print encoded text
|
|
107
|
+
- `textln(content, encoding)`: Print encoded text with line break
|
|
108
|
+
|
|
109
|
+
**Formatting**:
|
|
110
|
+
- `align(position)`: Set text alignment (left, center, right)
|
|
111
|
+
- `size(width, height)`: Set text size
|
|
112
|
+
- `style(style)`: Set text style (NORMAL, BOLD, ITALIC, UNDERLINE)
|
|
113
|
+
- `encode(codeTable)`: Set character encoding table
|
|
114
|
+
|
|
115
|
+
**Hardware**:
|
|
116
|
+
- `cut(partial)`: Cut paper
|
|
117
|
+
- `beep(count, time)`: Beep buzzer
|
|
118
|
+
- `cashdraw(pin)`: Open cash drawer
|
|
119
|
+
- `hardware(command)`: Hardware initialization
|
|
120
|
+
|
|
121
|
+
**Barcode**:
|
|
122
|
+
- `barcode(code, type, width, height, position, font)`: Print barcode
|
|
123
|
+
|
|
124
|
+
**Image**:
|
|
125
|
+
- `image(image, density)`: Print image
|
|
126
|
+
|
|
127
|
+
**Control**:
|
|
128
|
+
- `flush()`: Send buffered data to printer
|
|
129
|
+
- `close(options)`: Close connection and flush
|
|
130
|
+
|
|
131
|
+
## 📊 Test Coverage
|
|
132
|
+
|
|
133
|
+
### Test Statistics
|
|
134
|
+
|
|
135
|
+
- **Total Test Files**: 9
|
|
136
|
+
- **Total Tests**: 145
|
|
137
|
+
- **Test Suites**: 9
|
|
138
|
+
- **Coverage**: 100% (100% statements, 100% branches, 100% functions, 100% lines) ✅
|
|
139
|
+
- **Test Framework**: Jest 30.2.0
|
|
140
|
+
|
|
141
|
+
### Test Structure
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
tests/
|
|
145
|
+
├── unit/
|
|
146
|
+
│ ├── adapters/
|
|
147
|
+
│ │ ├── adapter.test.js # Base adapter tests
|
|
148
|
+
│ │ ├── usb-adapter.test.js # USB adapter tests
|
|
149
|
+
│ │ └── serial-adapter.test.js # Serial adapter tests
|
|
150
|
+
│ ├── printer/
|
|
151
|
+
│ │ ├── buffer.test.js # Buffer tests
|
|
152
|
+
│ │ └── printer.test.js # Printer class tests
|
|
153
|
+
│ ├── image/
|
|
154
|
+
│ │ └── image.test.js # Image processing tests
|
|
155
|
+
│ └── utils/
|
|
156
|
+
│ └── utils.test.js # Utility function tests
|
|
157
|
+
└── integration/
|
|
158
|
+
└── printer-flow.test.js # End-to-end flow tests
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Test Coverage by Module
|
|
162
|
+
|
|
163
|
+
| Module | Statements | Branches | Functions | Lines |
|
|
164
|
+
|--------|-----------|----------|-----------|-------|
|
|
165
|
+
| All files | 100% | 100% | 100% | 100% |
|
|
166
|
+
| commands.js | 100% | 100% | 100% | 100% |
|
|
167
|
+
| image.js | 100% | 100% | 100% | 100% |
|
|
168
|
+
| utils.js | 100% | 100% | 100% | 100% |
|
|
169
|
+
|
|
170
|
+
## 📦 Dependencies
|
|
171
|
+
|
|
172
|
+
### Production Dependencies
|
|
173
|
+
|
|
174
|
+
| Package | Version | Purpose |
|
|
175
|
+
|---------|---------|---------|
|
|
176
|
+
| `debug` | ^4.4.3 | Debug logging |
|
|
177
|
+
| `get-pixels` | custom fork | Image pixel extraction |
|
|
178
|
+
| `iconv-lite` | ^0.7.0 | Text encoding conversion |
|
|
179
|
+
| `serialport` | ^13.0.0 | Serial port communication |
|
|
180
|
+
| `usb` | ^2.16.0 | USB device communication |
|
|
181
|
+
|
|
182
|
+
### Development Dependencies
|
|
183
|
+
|
|
184
|
+
| Package | Version | Purpose |
|
|
185
|
+
|---------|---------|---------|
|
|
186
|
+
| `jest` | ^30.2.0 | Testing framework |
|
|
187
|
+
|
|
188
|
+
**All dependencies are up to date!** ✅
|
|
189
|
+
|
|
190
|
+
## 🔄 Recent Improvements
|
|
191
|
+
|
|
192
|
+
### 1. Dependency Updates
|
|
193
|
+
|
|
194
|
+
- ✅ **USB Library**: Migrated from v1.9.1 (callbacks) to v2.16.0 (Promises)
|
|
195
|
+
- ✅ **SerialPort**: Migrated from v12.0.0 to v13.0.0 (Promise-based API)
|
|
196
|
+
- ✅ **iconv-lite**: Updated from 0.6.3 to 0.7.0
|
|
197
|
+
- ✅ **debug**: Updated from 4.3.1 to 4.4.3
|
|
198
|
+
- ✅ **jest**: Updated from 29.7.0 to 30.2.0
|
|
199
|
+
|
|
200
|
+
### 2. Architecture Improvements
|
|
201
|
+
|
|
202
|
+
- ✅ **Event Consistency**: Fixed adapter event emission by using the same object instance internally and externally
|
|
203
|
+
- ✅ **Adapter Pattern**: Simplified Printer to use adapter directly instead of creating wrapper instances
|
|
204
|
+
- ✅ **Code Cleanup**: Removed unused imports and dependencies
|
|
205
|
+
|
|
206
|
+
### 3. Test Suite
|
|
207
|
+
|
|
208
|
+
- ✅ **Comprehensive Coverage**: 126 tests covering all major functionality
|
|
209
|
+
- ✅ **Unit Tests**: All core components tested in isolation
|
|
210
|
+
- ✅ **Integration Tests**: End-to-end printer flow validation
|
|
211
|
+
- ✅ **Mock Strategy**: Proper mocking of USB and Serial adapters
|
|
212
|
+
|
|
213
|
+
### 4. Documentation
|
|
214
|
+
|
|
215
|
+
- ✅ **Migration Guides**: Detailed documentation for USB v2 and SerialPort v13 migrations
|
|
216
|
+
- ✅ **Test Documentation**: Complete test suite documentation
|
|
217
|
+
- ✅ **Dependency Review**: Comprehensive dependency status tracking
|
|
218
|
+
|
|
219
|
+
## 🎯 Key Features
|
|
220
|
+
|
|
221
|
+
### 1. Multi-Adapter Support
|
|
222
|
+
|
|
223
|
+
The library supports multiple connection types:
|
|
224
|
+
- **USB**: Direct USB printer connection
|
|
225
|
+
- **Serial**: Serial port (RS-232) connection
|
|
226
|
+
|
|
227
|
+
Both adapters share the same interface and can be used interchangeably.
|
|
228
|
+
|
|
229
|
+
### 2. Event-Driven Architecture
|
|
230
|
+
|
|
231
|
+
All adapters extend EventEmitter, providing:
|
|
232
|
+
- `connect` event: Emitted when device connects
|
|
233
|
+
- `disconnect` event: Emitted when device disconnects
|
|
234
|
+
- `close` event: Emitted when connection closes
|
|
235
|
+
- `detach` event: Emitted when USB device is unplugged
|
|
236
|
+
|
|
237
|
+
### 3. Fluent API
|
|
238
|
+
|
|
239
|
+
The Printer class supports method chaining:
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
printer
|
|
243
|
+
.hardware('init')
|
|
244
|
+
.align('ct')
|
|
245
|
+
.size(2, 2)
|
|
246
|
+
.textln('Hello World')
|
|
247
|
+
.cut(true);
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### 4. Encoding Support
|
|
251
|
+
|
|
252
|
+
Full support for various character encodings:
|
|
253
|
+
- GB18030 (default)
|
|
254
|
+
- UTF-8
|
|
255
|
+
- ASCII
|
|
256
|
+
- And more via iconv-lite
|
|
257
|
+
|
|
258
|
+
### 5. Image Processing
|
|
259
|
+
|
|
260
|
+
Built-in image processing for thermal printers:
|
|
261
|
+
- Image loading and conversion
|
|
262
|
+
- Bitmap and raster format support
|
|
263
|
+
- Density control
|
|
264
|
+
|
|
265
|
+
## 📝 Usage Example
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
const { USB, Printer } = require('@risleylima/escpos');
|
|
269
|
+
|
|
270
|
+
(async () => {
|
|
271
|
+
// Connect to USB printer
|
|
272
|
+
await USB.connect(1046, 20497);
|
|
273
|
+
await USB.open();
|
|
274
|
+
|
|
275
|
+
// Create printer instance
|
|
276
|
+
const printer = new Printer(USB);
|
|
277
|
+
|
|
278
|
+
// Print receipt
|
|
279
|
+
printer
|
|
280
|
+
.hardware('init')
|
|
281
|
+
.align('ct')
|
|
282
|
+
.size(2, 2)
|
|
283
|
+
.textln('RECEIPT')
|
|
284
|
+
.size(1, 1)
|
|
285
|
+
.align('lt')
|
|
286
|
+
.textln('Item 1: $10.00')
|
|
287
|
+
.textln('Item 2: $20.00')
|
|
288
|
+
.align('rt')
|
|
289
|
+
.textln('Total: $30.00')
|
|
290
|
+
.cut(true);
|
|
291
|
+
|
|
292
|
+
// Send to printer
|
|
293
|
+
await printer.flush();
|
|
294
|
+
|
|
295
|
+
// Close connection
|
|
296
|
+
await USB.close();
|
|
297
|
+
await USB.disconnect();
|
|
298
|
+
})();
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## 🔍 Code Quality
|
|
302
|
+
|
|
303
|
+
### Metrics
|
|
304
|
+
|
|
305
|
+
- **Files**: 7 source files
|
|
306
|
+
- **Test Files**: 8 test files
|
|
307
|
+
- **Test Coverage**: 88.09% (excellent)
|
|
308
|
+
- **All Tests Passing**: ✅ 126/126
|
|
309
|
+
|
|
310
|
+
### Architecture Quality
|
|
311
|
+
|
|
312
|
+
- ✅ **Separation of Concerns**: Clear module boundaries
|
|
313
|
+
- ✅ **Single Responsibility**: Each module has a focused purpose
|
|
314
|
+
- ✅ **Event-Driven**: Proper use of EventEmitter pattern
|
|
315
|
+
- ✅ **Promise-Based**: Modern async/await patterns
|
|
316
|
+
- ✅ **Error Handling**: Comprehensive error handling
|
|
317
|
+
- ✅ **Type Safety**: JSDoc comments for better IDE support
|
|
318
|
+
|
|
319
|
+
## 🚀 Performance
|
|
320
|
+
|
|
321
|
+
- **Buffer Management**: Efficient buffer accumulation and flushing
|
|
322
|
+
- **Async Operations**: Non-blocking I/O operations
|
|
323
|
+
- **Event System**: Lightweight event emission
|
|
324
|
+
- **Memory**: Efficient buffer reuse
|
|
325
|
+
|
|
326
|
+
## 🔒 Stability
|
|
327
|
+
|
|
328
|
+
- **Test Coverage**: 88.09% with 126 tests
|
|
329
|
+
- **All Tests Passing**: ✅
|
|
330
|
+
- **Dependencies**: All up to date
|
|
331
|
+
- **Breaking Changes**: None in recent updates
|
|
332
|
+
- **API Compatibility**: Maintained throughout updates
|
|
333
|
+
|
|
334
|
+
## 📚 Documentation
|
|
335
|
+
|
|
336
|
+
Comprehensive documentation available in `docs/`:
|
|
337
|
+
|
|
338
|
+
- `DEPENDENCIES_REVIEW.md`: Dependency status and update history
|
|
339
|
+
- `PUBLIC_API_ANALYSIS.md`: Public API documentation
|
|
340
|
+
- `TESTS_IMPLEMENTED.md`: Test suite documentation
|
|
341
|
+
- `USB_V2_MIGRATION.md`: USB v2 migration guide
|
|
342
|
+
- `USB_V2_REVIEW.md`: USB v2 review and changes
|
|
343
|
+
- `SERIALPORT_V13_MIGRATION_PLAN.md`: SerialPort v13 migration plan
|
|
344
|
+
- `SERIALPORT_V13_MIGRATION_COMPLETE.md`: SerialPort v13 migration completion
|
|
345
|
+
- `SERIALPORT_V13_ANALYSIS.md`: SerialPort v13 analysis
|
|
346
|
+
|
|
347
|
+
## 🎓 Best Practices
|
|
348
|
+
|
|
349
|
+
The library follows Node.js best practices:
|
|
350
|
+
|
|
351
|
+
1. **Error Handling**: Try-catch blocks and error events
|
|
352
|
+
2. **Async/Await**: Modern Promise-based async operations
|
|
353
|
+
3. **EventEmitter**: Proper event-driven architecture
|
|
354
|
+
4. **Modularity**: Clear separation of concerns
|
|
355
|
+
5. **Testing**: Comprehensive test coverage
|
|
356
|
+
6. **Documentation**: JSDoc comments and detailed guides
|
|
357
|
+
|
|
358
|
+
## 🔮 Future Considerations
|
|
359
|
+
|
|
360
|
+
Potential areas for future enhancement:
|
|
361
|
+
|
|
362
|
+
1. **TypeScript**: Consider migrating to TypeScript for better type safety
|
|
363
|
+
2. **Network Adapter**: Add support for network printers (TCP/IP)
|
|
364
|
+
3. **Bluetooth Adapter**: Add support for Bluetooth printers
|
|
365
|
+
4. **More Barcode Types**: Expand barcode format support
|
|
366
|
+
5. **PDF Support**: Direct PDF to ESC/POS conversion
|
|
367
|
+
6. **QR Code**: Native QR code generation
|
|
368
|
+
7. **Printer Status**: Query printer status and paper levels
|
|
369
|
+
|
|
370
|
+
## 📊 Summary
|
|
371
|
+
|
|
372
|
+
**@risleylima/escpos** is a modern, well-architected ESC/POS library for Node.js with:
|
|
373
|
+
|
|
374
|
+
- ✅ **Modern Architecture**: Event-driven, Promise-based
|
|
375
|
+
- ✅ **Comprehensive Testing**: 126 tests, 88% coverage
|
|
376
|
+
- ✅ **Up-to-Date Dependencies**: All dependencies current
|
|
377
|
+
- ✅ **Multi-Adapter Support**: USB and Serial
|
|
378
|
+
- ✅ **Rich Feature Set**: Text, images, barcodes, formatting
|
|
379
|
+
- ✅ **Excellent Documentation**: Comprehensive guides and examples
|
|
380
|
+
- ✅ **Production Ready**: Stable, tested, and maintained
|
|
381
|
+
|
|
382
|
+
The library is ready for production use and provides a solid foundation for thermal printer integration in Node.js applications.
|
|
383
|
+
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
# Pre-Publish Checklist
|
|
2
|
+
|
|
3
|
+
This document lists all additional checks possible before publishing a new version to NPM.
|
|
4
|
+
|
|
5
|
+
## ✅ Basic Checks (Already Done)
|
|
6
|
+
|
|
7
|
+
- [x] Tests passing (145 tests, 100% coverage)
|
|
8
|
+
- [x] Exports working correctly
|
|
9
|
+
- [x] Essential files present (index.js, README.md, LICENSE)
|
|
10
|
+
- [x] Valid package.json
|
|
11
|
+
- [x] CHANGELOG.md created
|
|
12
|
+
|
|
13
|
+
## 🔍 Additional Recommended Checks
|
|
14
|
+
|
|
15
|
+
### 1. NPM Package Verification
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Simulate what will be published
|
|
19
|
+
npm pack --dry-run
|
|
20
|
+
|
|
21
|
+
# Check package size
|
|
22
|
+
npm pack
|
|
23
|
+
tar -tzf *.tgz | wc -l # Count files
|
|
24
|
+
du -h *.tgz # Tarball size
|
|
25
|
+
rm *.tgz # Clean up
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**What to check:**
|
|
29
|
+
- ✅ Only necessary files are included
|
|
30
|
+
- ✅ `node_modules` is not included
|
|
31
|
+
- ✅ Build/test files are not included
|
|
32
|
+
- ✅ `.git` is not included
|
|
33
|
+
- ✅ Reasonable package size
|
|
34
|
+
|
|
35
|
+
### 2. Dependencies Verification
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Check installed dependencies
|
|
39
|
+
yarn list --depth=0
|
|
40
|
+
|
|
41
|
+
# Check vulnerabilities
|
|
42
|
+
npm audit
|
|
43
|
+
# or
|
|
44
|
+
yarn audit
|
|
45
|
+
|
|
46
|
+
# Check outdated dependencies
|
|
47
|
+
npm outdated
|
|
48
|
+
# or
|
|
49
|
+
yarn outdated
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**What to check:**
|
|
53
|
+
- ✅ No known vulnerabilities
|
|
54
|
+
- ✅ Dependencies are at correct versions
|
|
55
|
+
- ✅ Peer dependencies documented (if any)
|
|
56
|
+
|
|
57
|
+
### 3. Code Verification
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Check syntax (if using linter)
|
|
61
|
+
npm run lint # if configured
|
|
62
|
+
|
|
63
|
+
# Check types (if using TypeScript)
|
|
64
|
+
npm run type-check # if configured
|
|
65
|
+
|
|
66
|
+
# Check formatting
|
|
67
|
+
npm run format:check # if configured
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**What to check:**
|
|
71
|
+
- ✅ No syntax errors
|
|
72
|
+
- ✅ No critical warnings
|
|
73
|
+
- ✅ Code consistently formatted
|
|
74
|
+
|
|
75
|
+
### 4. Test Verification
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Run all tests
|
|
79
|
+
yarn test
|
|
80
|
+
|
|
81
|
+
# Run tests with coverage
|
|
82
|
+
yarn test:coverage
|
|
83
|
+
|
|
84
|
+
# Check if coverage is above threshold
|
|
85
|
+
# (if configured in jest.config.js)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**What to check:**
|
|
89
|
+
- ✅ All tests passing
|
|
90
|
+
- ✅ Adequate coverage (100% in our case)
|
|
91
|
+
- ✅ Integration tests passing
|
|
92
|
+
- ✅ Tests on different Node.js versions (if applicable)
|
|
93
|
+
|
|
94
|
+
### 5. Compatibility Verification
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Test on different Node.js versions
|
|
98
|
+
nvm use 18
|
|
99
|
+
yarn test
|
|
100
|
+
|
|
101
|
+
nvm use 20
|
|
102
|
+
yarn test
|
|
103
|
+
|
|
104
|
+
# Check engines in package.json
|
|
105
|
+
node -e "console.log(require('./package.json').engines)"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**What to check:**
|
|
109
|
+
- ✅ Compatible with Node.js >= 18.0.0 (as per package.json)
|
|
110
|
+
- ✅ Tested on minimum supported version
|
|
111
|
+
- ✅ Tested on current LTS version
|
|
112
|
+
|
|
113
|
+
### 6. Documentation Verification
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Check if README is updated
|
|
117
|
+
# Check if CHANGELOG is updated
|
|
118
|
+
# Check if examples work
|
|
119
|
+
node examples/printTest.js # (without connecting real hardware)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**What to check:**
|
|
123
|
+
- ✅ README.md complete and updated
|
|
124
|
+
- ✅ CHANGELOG.md with all changes
|
|
125
|
+
- ✅ Code examples work
|
|
126
|
+
- ✅ API documentation is correct
|
|
127
|
+
- ✅ Links working
|
|
128
|
+
|
|
129
|
+
### 7. Git Verification
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# Check git status
|
|
133
|
+
git status
|
|
134
|
+
|
|
135
|
+
# Check for uncommitted changes
|
|
136
|
+
git diff
|
|
137
|
+
|
|
138
|
+
# Check existing tags
|
|
139
|
+
git tag -l
|
|
140
|
+
|
|
141
|
+
# Check last commit
|
|
142
|
+
git log -1
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**What to check:**
|
|
146
|
+
- ✅ All changes committed (or intentionally uncommitted)
|
|
147
|
+
- ✅ Correct branch (usually `main` or `master`)
|
|
148
|
+
- ✅ No sensitive files (tokens, passwords, etc.)
|
|
149
|
+
- ✅ `.gitignore` properly configured
|
|
150
|
+
|
|
151
|
+
### 8. Build Verification (if applicable)
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# If there's a build step
|
|
155
|
+
npm run build
|
|
156
|
+
|
|
157
|
+
# Check if build files were generated
|
|
158
|
+
ls -la dist/ # or build folder
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**What to check:**
|
|
162
|
+
- ✅ Build completes without errors
|
|
163
|
+
- ✅ Build files generated correctly
|
|
164
|
+
- ✅ Build files included in package (if necessary)
|
|
165
|
+
|
|
166
|
+
### 9. Local Publication Verification
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Install package locally to test
|
|
170
|
+
npm link
|
|
171
|
+
# or
|
|
172
|
+
cd /tmp
|
|
173
|
+
npm install /path/to/escpos
|
|
174
|
+
|
|
175
|
+
# Test import
|
|
176
|
+
node -e "const { USB, Serial, Printer } = require('@risleylima/escpos'); console.log('OK')"
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**What to check:**
|
|
180
|
+
- ✅ Package can be installed
|
|
181
|
+
- ✅ Exports work after installation
|
|
182
|
+
- ✅ Dependencies are installed correctly
|
|
183
|
+
|
|
184
|
+
### 10. Versioning Verification
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Check current version
|
|
188
|
+
node -e "console.log(require('./package.json').version)"
|
|
189
|
+
|
|
190
|
+
# Check if version follows semantic versioning
|
|
191
|
+
# MAJOR.MINOR.PATCH
|
|
192
|
+
# 0.0.14 -> 0.0.15 (minor update)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**What to check:**
|
|
196
|
+
- ✅ Version follows Semantic Versioning
|
|
197
|
+
- ✅ Version in package.json is correct
|
|
198
|
+
- ✅ Version in CHANGELOG is correct
|
|
199
|
+
- ✅ Breaking changes documented (if any)
|
|
200
|
+
|
|
201
|
+
### 11. Package Metadata Verification
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Check package.json
|
|
205
|
+
node -e "const pkg = require('./package.json'); console.log(JSON.stringify({
|
|
206
|
+
name: pkg.name,
|
|
207
|
+
version: pkg.version,
|
|
208
|
+
description: pkg.description,
|
|
209
|
+
main: pkg.main,
|
|
210
|
+
keywords: pkg.keywords,
|
|
211
|
+
author: pkg.author,
|
|
212
|
+
license: pkg.license,
|
|
213
|
+
repository: pkg.repository,
|
|
214
|
+
bugs: pkg.bugs,
|
|
215
|
+
homepage: pkg.homepage
|
|
216
|
+
}, null, 2))"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**What to check:**
|
|
220
|
+
- ✅ Package name correct
|
|
221
|
+
- ✅ Clear and updated description
|
|
222
|
+
- ✅ Relevant keywords
|
|
223
|
+
- ✅ Correct author and license
|
|
224
|
+
- ✅ Repository, bugs, and homepage links working
|
|
225
|
+
|
|
226
|
+
### 12. Security Verification
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# Check vulnerabilities
|
|
230
|
+
npm audit
|
|
231
|
+
yarn audit
|
|
232
|
+
|
|
233
|
+
# Check for sensitive files
|
|
234
|
+
grep -r "password\|secret\|token\|api_key" --exclude-dir=node_modules .
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**What to check:**
|
|
238
|
+
- ✅ No known vulnerabilities
|
|
239
|
+
- ✅ No hardcoded credentials
|
|
240
|
+
- ✅ No tokens or API keys in code
|
|
241
|
+
|
|
242
|
+
### 13. Performance Verification (Optional)
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
# Test load time
|
|
246
|
+
time node -e "require('./index.js')"
|
|
247
|
+
|
|
248
|
+
# Check bundle size (if applicable)
|
|
249
|
+
npm run build:analyze # if configured
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**What to check:**
|
|
253
|
+
- ✅ Reasonable load time
|
|
254
|
+
- ✅ Optimized package size
|
|
255
|
+
- ✅ No unnecessary dependencies
|
|
256
|
+
|
|
257
|
+
### 14. Accessibility Verification (Optional)
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# Check if README is readable
|
|
261
|
+
# Check if examples are clear
|
|
262
|
+
# Check if documentation is complete
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**What to check:**
|
|
266
|
+
- ✅ README well formatted
|
|
267
|
+
- ✅ Clear and functional examples
|
|
268
|
+
- ✅ Complete documentation
|
|
269
|
+
|
|
270
|
+
## 🚀 `np` Commands
|
|
271
|
+
|
|
272
|
+
The `np` tool automatically performs many of these checks:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
npx np minor
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**What `np` automatically checks:**
|
|
279
|
+
- ✅ Git status (uncommitted changes)
|
|
280
|
+
- ✅ Correct branch
|
|
281
|
+
- ✅ Tests (if configured)
|
|
282
|
+
- ✅ Build (if configured)
|
|
283
|
+
- ✅ Versioning
|
|
284
|
+
- ✅ Git tag
|
|
285
|
+
- ✅ NPM publication
|
|
286
|
+
|
|
287
|
+
## 📋 Final Checklist Before Publishing
|
|
288
|
+
|
|
289
|
+
- [ ] All tests passing
|
|
290
|
+
- [ ] Adequate test coverage
|
|
291
|
+
- [ ] CHANGELOG.md updated
|
|
292
|
+
- [ ] README.md updated
|
|
293
|
+
- [ ] No known vulnerabilities
|
|
294
|
+
- [ ] Dependencies updated
|
|
295
|
+
- [ ] Code reviewed
|
|
296
|
+
- [ ] Git status clean (or intentional changes)
|
|
297
|
+
- [ ] Correct version in package.json
|
|
298
|
+
- [ ] Correct version in CHANGELOG
|
|
299
|
+
- [ ] Package metadata correct
|
|
300
|
+
- [ ] Examples tested (if possible)
|
|
301
|
+
- [ ] Compatibility verified
|
|
302
|
+
|
|
303
|
+
## 🎯 Specific Recommendations for This Version
|
|
304
|
+
|
|
305
|
+
For v0.0.15, check especially:
|
|
306
|
+
|
|
307
|
+
1. **Major Dependency Updates:**
|
|
308
|
+
- [x] `usb@^2.16.0` - Promise-based API working
|
|
309
|
+
- [x] `serialport@^13.0.0` - Promise-based API working
|
|
310
|
+
- [x] Tests updated for new APIs
|
|
311
|
+
|
|
312
|
+
2. **Documentation:**
|
|
313
|
+
- [x] Complete README
|
|
314
|
+
- [x] CHANGELOG created
|
|
315
|
+
- [x] Complete JSDoc
|
|
316
|
+
|
|
317
|
+
3. **Tests:**
|
|
318
|
+
- [x] 100% coverage
|
|
319
|
+
- [x] All tests passing
|
|
320
|
+
|
|
321
|
+
4. **Compatibility:**
|
|
322
|
+
- [x] Public API maintained (no breaking changes)
|
|
323
|
+
- [x] Exports working
|
|
324
|
+
|
|
325
|
+
## ⚠️ Important Notes
|
|
326
|
+
|
|
327
|
+
- **Internal Breaking Changes**: The `usb` and `serialport` updates are major, but the library's public API has not changed. It's safe to publish as a minor update.
|
|
328
|
+
|
|
329
|
+
- **Hardware Testing**: If possible, test with real hardware before publishing, especially after the `usb` and `serialport` updates.
|
|
330
|
+
|
|
331
|
+
- **Rollback Plan**: Have a rollback plan in case something goes wrong after publication.
|