Skip to content

Commit

Permalink
feat(node): upgrades to support Node 18, 20 #120
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This drops support for Node.js v14.
  • Loading branch information
jshor committed Oct 15, 2023
1 parent 8c35f1a commit 3b7904d
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
os: [windows-2019, macos-latest, ubuntu-latest]
node-version: [14, 16]
node-version: [16, 18, 20]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
os: [windows-2019, ubuntu-latest, macos-latest]
# list only the earliest and latest node versions supported
# this makes PR builds more efficient
node-version: [14, 16]
node-version: [16, 20]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"host": "https://github.com/jshor/symbology/releases/download/"
},
"engines": {
"node": ">=14.0.0 <17.0.0"
"node": ">=14.0.0 <21.0.0"
},
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.10",
Expand Down Expand Up @@ -119,4 +119,4 @@
}
},
"zintVersion": "89518c4"
}
}
13 changes: 6 additions & 7 deletions src/binding/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace symbology {
/**
* Returns a bitmap (of type V8 Array) of the image in memory.
*/
Local<Object> getBitmap(Isolate* isolate, zint_symbol *symbol) {
Local<Object> getBitmap (Isolate* isolate, zint_symbol *symbol) {
v8::Local<v8::Context> context = isolate->GetCurrentContext();

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

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

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

(void)exports->Set(context,
Nan::New("createStream").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(createStream)
->GetFunction(context)
.ToLocalChecked());
Nan::New<v8::FunctionTemplate>(createStream)->GetFunction(context).ToLocalChecked()
);
}

NODE_MODULE(symbology, Init);
Expand Down
21 changes: 0 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import SymbologyType from './types/enums/SymbologyType'
import DataMatrix from './types/enums/DataMatrix'
import EncodingMode from './types/enums/EncodingMode'
import OutputOption from './types/enums/OutputOption'
import OutputType from './types/enums/OutputType'
import { createStream, createFile } from './main'

export { default as SymbologyType } from './types/enums/SymbologyType'
export { default as DataMatrix } from './types/enums/DataMatrix'
export { default as EncodingMode } from './types/enums/EncodingMode'
Expand All @@ -13,17 +6,3 @@ export { default as OutputType } from './types/enums/OutputType'
export { default as SymbologyConfig } from './types/SymbologyConfig'
export { default as SymbologyResult } from './types/SymbologyResult'
export { createStream, createFile } from './main'

export default {
DataMatrix,
EncodingMode,
OutputOption,
OutputType,
SymbologyType,
createStream,
createFile,
/** Legacy support - remove in next major release */
Encoding: EncodingMode,
Output: OutputOption,
Barcode: SymbologyType
}
7 changes: 4 additions & 3 deletions src/lib/__tests__/binary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import OutputType from '../../types/enums/OutputType'
import OutputOption from '../../types/enums/OutputOption'
import binding from '../../binding'
import binary from '../binary'
import SymbologyType from '../../types/enums/SymbologyType'

describe('Binary methods', () => {
afterEach(() => jest.resetAllMocks())
Expand Down Expand Up @@ -143,7 +144,7 @@ describe('Binary methods', () => {
expect.assertions(1)

await expect(binary.invoke({
symbology: 10
symbology: 10 as SymbologyType
}, '12345', OutputType.SVG)).resolves.toEqual({
...result,
message: 'Symbology successfully created.'
Expand Down Expand Up @@ -218,7 +219,7 @@ describe('Binary methods', () => {
expect.assertions(1)

await expect(binary.invoke({
symbology: 10
symbology: 10 as SymbologyType
}, '12345', OutputType.SVG)).resolves.toEqual(result)
})
})
Expand All @@ -241,7 +242,7 @@ describe('Binary methods', () => {
expect.assertions(1)

await expect(binary.invoke({
symbology: 10
symbology: 10 as SymbologyType
}, '12345', OutputType.SVG)).rejects.toEqual(result.message)
})
})
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/transformations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import OutputType from '../../src/types/enums/OutputType'
import OutputOption from '../../src/types/enums/OutputOption'
import SymbologyType from '../../src/types/enums/SymbologyType'
import { createImageFile } from '../helpers'
import symbology from '../../src'
import { createStream } from '../../src'

describe('Symbology Transformations', () => {
describe('rotations', () => {
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('Symbology Transformations', () => {

describe('Scalable Vector Graphics', () => {
it('should stream an SVG image', async () => {
const image = await symbology.createStream({
const image = await createStream({
symbology: SymbologyType.CODE128,
}, '12345', OutputType.SVG)

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

describe('PostScript', () => {
it('should stream a PostScript image', async () => {
const image = await symbology.createStream({
const image = await createStream({
symbology: SymbologyType.CODE128,
}, '12345', OutputType.EPS)

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

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

Expand Down
4 changes: 2 additions & 2 deletions test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
import symbology from '../src'
import { createFile } from '../src'
import OutputType from '../src/types/enums/OutputType'
import SymbologyConfig from '../src/types/SymbologyConfig'

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

await symbology.createFile({ ...symbol, fileName }, data)
await createFile({ ...symbol, fileName }, data)

return fs.readFileSync(fileName)
}

0 comments on commit 3b7904d

Please sign in to comment.