diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index ba549555..a0d77dae 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -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 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ac88b8fa..d82dd775 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 diff --git a/package.json b/package.json index 6bcdf734..7a8cc7f7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -119,4 +119,4 @@ } }, "zintVersion": "89518c4" -} \ No newline at end of file +} diff --git a/src/binding/main.cpp b/src/binding/main.cpp index a96375ef..31c8483f 100644 --- a/src/binding/main.cpp +++ b/src/binding/main.cpp @@ -22,7 +22,7 @@ namespace symbology { /** * Returns a bitmap (of type V8 Array) of the image in memory. */ - Local getBitmap(Isolate* isolate, zint_symbol *symbol) { + Local getBitmap (Isolate* isolate, zint_symbol *symbol) { v8::Local context = isolate->GetCurrentContext(); int matrix_size = symbol->bitmap_width * symbol->bitmap_height * 3; @@ -39,7 +39,7 @@ namespace symbology { /** * Renders symbology and returns an object with PNG bitmap data, EPS, or SVG XML. */ - Local createStreamHandle(Isolate* isolate, zint_symbol *symbol, uint8_t *data, char *str, int rotate_angle) { + Local createStreamHandle (Isolate* isolate, zint_symbol *symbol, uint8_t *data, char *str, int rotate_angle) { int status_code; if ((symbol->output_options & BARCODE_STDOUT) != 0) { @@ -186,14 +186,13 @@ namespace symbology { args.GetReturnValue().Set(obj); } - void Init(v8::Local exports) { - v8::Local context = exports->CreationContext(); + void Init (v8::Local exports) { + v8::Local context = exports->GetCreationContext().ToLocalChecked(); (void)exports->Set(context, Nan::New("createStream").ToLocalChecked(), - Nan::New(createStream) - ->GetFunction(context) - .ToLocalChecked()); + Nan::New(createStream)->GetFunction(context).ToLocalChecked() + ); } NODE_MODULE(symbology, Init); diff --git a/src/index.ts b/src/index.ts index ba528b6c..7b10e823 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' @@ -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 -} diff --git a/src/lib/__tests__/binary.test.ts b/src/lib/__tests__/binary.test.ts index a5c6c1dd..ccc191d2 100644 --- a/src/lib/__tests__/binary.test.ts +++ b/src/lib/__tests__/binary.test.ts @@ -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()) @@ -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.' @@ -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) }) }) @@ -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) }) }) diff --git a/test/e2e/transformations.test.ts b/test/e2e/transformations.test.ts index e1c2b062..13f97bbc 100644 --- a/test/e2e/transformations.test.ts +++ b/test/e2e/transformations.test.ts @@ -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', () => { @@ -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) @@ -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) @@ -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) diff --git a/test/helpers.ts b/test/helpers.ts index ed2035d8..0f1622ac 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -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' @@ -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) }