Skip to content

Commit

Permalink
port to node-addon-api (remove NAN, v8, libuv)
Browse files Browse the repository at this point in the history
  • Loading branch information
chearon committed Sep 11, 2023
1 parent adf73ee commit e68f740
Show file tree
Hide file tree
Showing 38 changed files with 1,916 additions and 2,102 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
* Avoid calling virtual methods in constructors/destructors to avoid bypassing virtual dispatch. (#2229)
* Remove unused private field `backend` in the `Backend` class. (#2229)
* Add Node.js v20 to CI. (#2237)
* Migrated to N-API (by way of node-addon-api) and removed libuv and v8 dependencies
### Added
* Added string tags to support class detection
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ npm install canvas

By default, binaries for macOS, Linux and Windows will be downloaded. If you want to build from source, use `npm install --build-from-source` and see the **Compiling** section below.

The minimum version of Node.js required is **6.0.0**.
The minimum version of Node.js required is **10.20.0**.

### Compiling

Expand Down
5 changes: 4 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
},
{
'target_name': 'canvas',
'include_dirs': ["<!(node -e \"require('nan')\")"],
'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS', 'NODE_ADDON_API_ENABLE_MAYBE' ],
'sources': [
'src/backend/Backend.cc',
'src/backend/ImageBackend.cc',
Expand Down Expand Up @@ -142,7 +143,9 @@
'cflags_cc!': ['-fno-exceptions']
}],
['OS=="mac"', {
'cflags+': ['-fvisibility=hidden'],
'xcode_settings': {
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
}
}],
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const PDFStream = require('./lib/pdfstream')
const JPEGStream = require('./lib/jpegstream')
const { DOMPoint, DOMMatrix } = require('./lib/DOMMatrix')

bindings.setDOMMatrix(DOMMatrix)
bindings.setParseFont(parseFont)

function createCanvas (width, height, type) {
return new Canvas(width, height, type)
}
Expand Down
3 changes: 0 additions & 3 deletions lib/context2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
*/

const bindings = require('./bindings')
const parseFont = require('./parse-font')
const { DOMMatrix } = require('./DOMMatrix')

bindings.CanvasRenderingContext2dInit(DOMMatrix, parseFont)
module.exports = bindings.CanvasRenderingContext2d
2 changes: 0 additions & 2 deletions lib/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/

const bindings = require('./bindings')
const { DOMMatrix } = require('./DOMMatrix')

bindings.CanvasPatternInit(DOMMatrix)
module.exports = bindings.CanvasPattern

bindings.CanvasPattern.prototype.toString = function () {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"types": "types/index.d.ts",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.0",
"nan": "^2.17.0",
"node-addon-api": "^7.0.0",
"simple-get": "^3.0.3"
},
"devDependencies": {
Expand All @@ -66,7 +66,7 @@
"typescript": "^4.2.2"
},
"engines": {
"node": ">=6"
"node": ">=10.20.0"
},
"license": "MIT"
}
10 changes: 5 additions & 5 deletions src/Backends.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#include "backend/PdfBackend.h"
#include "backend/SvgBackend.h"

using namespace v8;
using namespace Napi;

void Backends::Initialize(Local<Object> target) {
Nan::HandleScope scope;
void
Backends::Initialize(Napi::Env env, Napi::Object exports) {
Napi::Object obj = Napi::Object::New(env);

Local<Object> obj = Nan::New<Object>();
ImageBackend::Initialize(obj);
PdfBackend::Initialize(obj);
SvgBackend::Initialize(obj);

Nan::Set(target, Nan::New<String>("Backends").ToLocalChecked(), obj).Check();
exports.Set("Backends", obj);
}
7 changes: 3 additions & 4 deletions src/Backends.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once

#include "backend/Backend.h"
#include <nan.h>
#include <v8.h>
#include <napi.h>

class Backends : public Nan::ObjectWrap {
class Backends : public Napi::ObjectWrap<Backends> {
public:
static void Initialize(v8::Local<v8::Object> target);
static void Initialize(Napi::Env env, Napi::Object exports);
};
Loading

0 comments on commit e68f740

Please sign in to comment.