Skip to content

Commit 6abfaca

Browse files
committed
feat(node): upgrades to support Node 18, 20 #120
BREAKING CHANGE: This drops support for Node.js v14.
1 parent 8c35f1a commit 6abfaca

File tree

8 files changed

+20
-41
lines changed

8 files changed

+20
-41
lines changed

.github/workflows/merge.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
os: [windows-2019, macos-latest, ubuntu-latest]
22-
node-version: [14, 16]
22+
node-version: [16, 18, 20]
2323
steps:
2424
- uses: actions/checkout@v2
2525
- uses: actions/setup-node@v1

.github/workflows/pr.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
os: [windows-2019, ubuntu-latest, macos-latest]
1717
# list only the earliest and latest node versions supported
1818
# this makes PR builds more efficient
19-
node-version: [14, 16]
19+
node-version: [16, 20]
2020
steps:
2121
- uses: actions/checkout@v2
2222
- uses: actions/setup-node@v1

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"host": "https://github.com/jshor/symbology/releases/download/"
4949
},
5050
"engines": {
51-
"node": ">=14.0.0 <17.0.0"
51+
"node": ">=14.0.0 <21.0.0"
5252
},
5353
"dependencies": {
5454
"@mapbox/node-pre-gyp": "^1.0.10",
@@ -119,4 +119,4 @@
119119
}
120120
},
121121
"zintVersion": "89518c4"
122-
}
122+
}

src/binding/main.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace symbology {
2222
/**
2323
* Returns a bitmap (of type V8 Array) of the image in memory.
2424
*/
25-
Local<Object> getBitmap(Isolate* isolate, zint_symbol *symbol) {
25+
Local<Object> getBitmap (Isolate* isolate, zint_symbol *symbol) {
2626
v8::Local<v8::Context> context = isolate->GetCurrentContext();
2727

2828
int matrix_size = symbol->bitmap_width * symbol->bitmap_height * 3;
@@ -39,7 +39,7 @@ namespace symbology {
3939
/**
4040
* Renders symbology and returns an object with PNG bitmap data, EPS, or SVG XML.
4141
*/
42-
Local<Object> createStreamHandle(Isolate* isolate, zint_symbol *symbol, uint8_t *data, char *str, int rotate_angle) {
42+
Local<Object> createStreamHandle (Isolate* isolate, zint_symbol *symbol, uint8_t *data, char *str, int rotate_angle) {
4343
int status_code;
4444

4545
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
@@ -186,14 +186,13 @@ namespace symbology {
186186
args.GetReturnValue().Set(obj);
187187
}
188188

189-
void Init(v8::Local<v8::Object> exports) {
190-
v8::Local<v8::Context> context = exports->CreationContext();
189+
void Init (v8::Local<v8::Object> exports) {
190+
v8::Local<v8::Context> context = exports->GetCreationContext().ToLocalChecked();
191191

192192
(void)exports->Set(context,
193193
Nan::New("createStream").ToLocalChecked(),
194-
Nan::New<v8::FunctionTemplate>(createStream)
195-
->GetFunction(context)
196-
.ToLocalChecked());
194+
Nan::New<v8::FunctionTemplate>(createStream)->GetFunction(context).ToLocalChecked()
195+
);
197196
}
198197

199198
NODE_MODULE(symbology, Init);

src/index.ts

-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
import SymbologyType from './types/enums/SymbologyType'
2-
import DataMatrix from './types/enums/DataMatrix'
3-
import EncodingMode from './types/enums/EncodingMode'
4-
import OutputOption from './types/enums/OutputOption'
5-
import OutputType from './types/enums/OutputType'
6-
import { createStream, createFile } from './main'
7-
81
export { default as SymbologyType } from './types/enums/SymbologyType'
92
export { default as DataMatrix } from './types/enums/DataMatrix'
103
export { default as EncodingMode } from './types/enums/EncodingMode'
@@ -13,17 +6,3 @@ export { default as OutputType } from './types/enums/OutputType'
136
export { default as SymbologyConfig } from './types/SymbologyConfig'
147
export { default as SymbologyResult } from './types/SymbologyResult'
158
export { createStream, createFile } from './main'
16-
17-
export default {
18-
DataMatrix,
19-
EncodingMode,
20-
OutputOption,
21-
OutputType,
22-
SymbologyType,
23-
createStream,
24-
createFile,
25-
/** Legacy support - remove in next major release */
26-
Encoding: EncodingMode,
27-
Output: OutputOption,
28-
Barcode: SymbologyType
29-
}

src/lib/__tests__/binary.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import OutputType from '../../types/enums/OutputType'
33
import OutputOption from '../../types/enums/OutputOption'
44
import binding from '../../binding'
55
import binary from '../binary'
6+
import SymbologyType from '../../types/enums/SymbologyType'
67

78
describe('Binary methods', () => {
89
afterEach(() => jest.resetAllMocks())
@@ -143,7 +144,7 @@ describe('Binary methods', () => {
143144
expect.assertions(1)
144145

145146
await expect(binary.invoke({
146-
symbology: 10
147+
symbology: 10 as SymbologyType
147148
}, '12345', OutputType.SVG)).resolves.toEqual({
148149
...result,
149150
message: 'Symbology successfully created.'
@@ -218,7 +219,7 @@ describe('Binary methods', () => {
218219
expect.assertions(1)
219220

220221
await expect(binary.invoke({
221-
symbology: 10
222+
symbology: 10 as SymbologyType
222223
}, '12345', OutputType.SVG)).resolves.toEqual(result)
223224
})
224225
})
@@ -241,7 +242,7 @@ describe('Binary methods', () => {
241242
expect.assertions(1)
242243

243244
await expect(binary.invoke({
244-
symbology: 10
245+
symbology: 10 as SymbologyType
245246
}, '12345', OutputType.SVG)).rejects.toEqual(result.message)
246247
})
247248
})

test/e2e/transformations.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import OutputType from '../../src/types/enums/OutputType'
22
import OutputOption from '../../src/types/enums/OutputOption'
33
import SymbologyType from '../../src/types/enums/SymbologyType'
44
import { createImageFile } from '../helpers'
5-
import symbology from '../../src'
5+
import { createStream } from '../../src'
66

77
describe('Symbology Transformations', () => {
88
describe('rotations', () => {
@@ -57,7 +57,7 @@ describe('Symbology Transformations', () => {
5757

5858
describe('Scalable Vector Graphics', () => {
5959
it('should stream an SVG image', async () => {
60-
const image = await symbology.createStream({
60+
const image = await createStream({
6161
symbology: SymbologyType.CODE128,
6262
}, '12345', OutputType.SVG)
6363

@@ -75,7 +75,7 @@ describe('Symbology Transformations', () => {
7575

7676
describe('PostScript', () => {
7777
it('should stream a PostScript image', async () => {
78-
const image = await symbology.createStream({
78+
const image = await createStream({
7979
symbology: SymbologyType.CODE128,
8080
}, '12345', OutputType.EPS)
8181

@@ -93,7 +93,7 @@ describe('Symbology Transformations', () => {
9393

9494
describe('Portable Network Graphics', () => {
9595
it('should stream a base64-encoded image', async () => {
96-
const image = await symbology.createStream({
96+
const image = await createStream({
9797
symbology: SymbologyType.CODE128
9898
}, '12345', OutputType.PNG)
9999

test/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs'
22
import path from 'path'
3-
import symbology from '../src'
3+
import { createFile } from '../src'
44
import OutputType from '../src/types/enums/OutputType'
55
import SymbologyConfig from '../src/types/SymbologyConfig'
66

@@ -16,7 +16,7 @@ export async function createImageFile (symbol: SymbologyConfig, ext: OutputType,
1616
const random = Math.ceil(Math.random() * 10000)
1717
const fileName = path.join(__dirname, 'e2e/__rendered__', `${random}.${ext}`)
1818

19-
await symbology.createFile({ ...symbol, fileName }, data)
19+
await createFile({ ...symbol, fileName }, data)
2020

2121
return fs.readFileSync(fileName)
2222
}

0 commit comments

Comments
 (0)