Skip to content

Commit

Permalink
fix(node-12): Add support for node 12 (#10)
Browse files Browse the repository at this point in the history
* Add support for node 12

See mapbox/node-cpp-skel#54
nodejs/nan#849

* updates

* Only need this

* Use compatible versions

* use dockerfile

* updates

* caching

* Run commands from docker

* Fix cov report

* Fixes

* lowercase

* re-add cov check

* change back to yarn run
  • Loading branch information
pdufour authored Dec 9, 2019
1 parent 2184a11 commit d2c3276
Show file tree
Hide file tree
Showing 11 changed files with 992 additions and 510 deletions.
37 changes: 23 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,44 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:6.11.1
- image: alpine:3.10
working_directory: ~/pdffonts
steps:
- checkout

- setup_remote_docker:
docker_layer_caching: true

- run:
name: Install system dependencies
command: |
sudo sh -c 'echo "deb http://deb.debian.org/debian/ jessie main" > /etc/apt/sources.list'
sudo sh -c 'echo "deb-src http://deb.debian.org/debian/ jessie main" >> /etc/apt/sources.list'
sudo sh -c 'echo "deb http://security.debian.org/ jessie/updates main" >> /etc/apt/sources.list'
sudo sh -c 'echo "deb-src http://security.debian.org/ jessie/updates main" >> /etc/apt/sources.list'
sudo sh -c 'echo "deb http://archive.debian.org/debian jessie-backports main" >> /etc/apt/sources.list'
sudo sh -c 'echo "deb-src http://archive.debian.org/debian jessie-backports main" >> /etc/apt/sources.list'
sudo apt-get update -o Acquire::Check-Valid-Until=false -o Acquire::CompressionTypes::Order::=gz
sudo apt-get install -y --no-install-recommends g++-4.9 libpoppler-private-dev poppler-data lcov
apk update --update-cache
apk add --update git openssh-client curl docker-cli
- run:
name: Install Node dependencies
command: yarn
name: Create docker container
command: |
docker build . \
--build-arg NODE_ENV=development \
-t "$CIRCLE_PROJECT_REPONAME"
- run:
name: Run docker container
command: |
docker run --name "$CIRCLE_PROJECT_REPONAME-container" -t -d "$CIRCLE_PROJECT_REPONAME"
- run:
name: Run linter
command: yarn lint
command: docker exec -t "$CIRCLE_PROJECT_REPONAME-container" yarn lint

- run:
name: Run tests
command: yarn test
command: docker exec -t "$CIRCLE_PROJECT_REPONAME-container" yarn test

- run:
name: Enforce coverage
command: ./scripts/enforce_coverage.sh
command: docker exec -t "$CIRCLE_PROJECT_REPONAME-container" ./scripts/enforce_coverage.sh

- run:
name: Remove container
command: docker rm --force "$CIRCLE_PROJECT_REPONAME-container"
28 changes: 28 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.git/

lib-cov
*.seed
*.log
*.err
*.csv
*.dat
*.out
*.pid
*.gz

pids
/logs
results

dump.rdb
npm-debug.log
node_modules/

coverage/

.idea/
.DS_Store

xunit.xml

db/seeds/*
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"extends": "lob",
"extends": "eslint-config-lob",
"globals": {
"expect": false
},
"parserOptions": {
"ecmaVersion": 2018
}
}
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.11.1
12.13.1
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:12.13.1-alpine3.10

ARG NODE_ENV=production
ENV NODE_ENV=$NODE_ENV

COPY ./scripts ./scripts
RUN ./scripts/install-system-dependencies-alpine.sh
RUN ./scripts/install-poppler-alpine.sh

RUN mkdir /app
WORKDIR /app

COPY package.json package.json
COPY yarn.lock yarn.lock
RUN yarn --silent

RUN apk del .build-deps

COPY . .
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.1.1",
"description": "Node bindings for Poppler's pdffonts CLI",
"main": "./lib/pdffonts.js",
"engines": {
"node": ">=12.0.0"
},
"scripts": {
"build": "node-gyp rebuild",
"cover": "lcov -c -d build/Debug/obj.target/pdffonts/src -o coverage.info && lcov -e coverage.info '*pdffonts.cc' -o coverage.info",
Expand Down Expand Up @@ -31,16 +34,15 @@
},
"homepage": "https://github.com/lob/pdffonts#readme",
"dependencies": {
"bindings": "^1.2.1",
"nan": "^2.3.3"
"bindings": "^1.5.0",
"nan": "^2.14.0"
},
"devDependencies": {
"chai": "^3.5.0",
"coveralls": "^2.11.9",
"eslint": "4.8.0",
"eslint-config-lob": "3.0.0",
"eslint-plugin-lob": "1.0.1",
"generate-changelog": "^1.0.1",
"mocha": "^2.4.5"
"chai": "^4.2.0",
"coveralls": "^3.0.9",
"eslint": "^4.19.1",
"eslint-config-lob": "^4.0.0",
"generate-changelog": "^1.8.0",
"mocha": "^6.2.2"
}
}
8 changes: 7 additions & 1 deletion scripts/enforce_coverage.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
#!/usr/bin/env bash

THRESHOLD=100

COVER_OUTPUT="$(yarn run cover)"
status=$?
if [ $status -ne 0 ]; then
exit $status
fi

echo "Checking against threshold of ${THRESHOLD}%"

Expand All @@ -14,3 +18,5 @@ for PERCENT in $PERCENTS; do
exit 1
fi
done

echo "Coverage is 100%"
12 changes: 12 additions & 0 deletions scripts/install-poppler-alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh

# Install Poppler and other dependencies
# Alpine image is small, but lacks some essentials
# - Add build tools, python, etc
# - Add pkgconf, poppler-simple needs pkg-config to build
# - Add poppler-dev, the standard poppler package won't do
# - Add poppler-data from community repo
apk add alpine-sdk
apk add pkgconf
apk add poppler-dev
apk add poppler-data --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
17 changes: 17 additions & 0 deletions scripts/install-system-dependencies-alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

apk update

# Needed for poppler as well as some Node addons
apk add --no-cache --virtual .build-deps python make g++

# Install certs so we can pull from https sources
apk add --no-cache ca-certificates
update-ca-certificates

# For cov reports
apk add lcov --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing

# Install chamber
wget -q -O /usr/bin/chamber https://github.com/segmentio/chamber/releases/download/v2.0.0/chamber-v2.0.0-linux-amd64 \
&& chmod +x /usr/bin/chamber
2 changes: 1 addition & 1 deletion src/pdffonts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ NAN_METHOD(Fonts) {

// Start the async worker
Nan::AsyncQueueWorker(new FontsWorker(
std::string(*Nan::Utf8String(info[0]->ToString())),
std::string(*Nan::Utf8String(info[0])),
new Nan::Callback(info[1].As<v8::Function>())
));
}
Expand Down
Loading

0 comments on commit d2c3276

Please sign in to comment.