Drop support for Node.js < 10.13.0

This commit is contained in:
Linus Unnebäck 2020-04-16 22:35:43 +01:00
parent 48b4cdc93e
commit a5a8563ba4
No known key found for this signature in database
GPG key ID: CE70CEAE9C0FA66F
12 changed files with 4529 additions and 4478 deletions

View file

@ -1,10 +1,9 @@
language: node_js
node_js:
- '4'
- '6'
- '8'
- '10.13.0'
- '10'
- '12'
- 'node'
env:

View file

@ -1,23 +1,19 @@
var spawn = require('child_process').spawn
var fs = require('fs')
var path = require('path')
const childProcess = require('child_process')
const fs = require('fs')
const path = require('path')
require('colors')
function createFolder (folderPath, onDone) {
function createFolder (folderPath) {
console.log('*'.green + ' creating folder: '.grey + folderPath.white)
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath)
}
onDone()
fs.mkdirSync(folderPath, { recursive: true })
}
function bundle (inputFile, exportName, outputFile, onDone) {
console.log('*'.green + ' bundling: '.grey +
inputFile.white + ' -> '.grey + outputFile.white)
console.log('*'.green + ' bundling: '.grey + inputFile.white + ' -> '.grey + outputFile.white)
var browserify = spawn('node', [
const { status, stderr } = childProcess.spawnSync('node', [
'node_modules/.bin/browserify',
inputFile,
'-s', exportName,
@ -25,61 +21,32 @@ function bundle (inputFile, exportName, outputFile, onDone) {
'-o', outputFile
])
browserify.stdin.end()
browserify.stdout.pipe(process.stdout)
browserify.stderr.pipe(process.stderr)
browserify.on('exit', function (code) {
if (code) {
console.error('browserify failed!')
process.exit(code)
}
onDone()
})
if (status !== 0) {
console.error(stderr.toString())
process.exit(status)
}
}
function minify (inputFile, outputFile, onDone) {
console.log('*'.green + ' minifying: '.grey +
inputFile.white + ' -> '.grey + outputFile.white)
function minify (inputFile, outputFile) {
console.log('*'.green + ' minifying: '.grey + inputFile.white + ' -> '.grey + outputFile.white)
var uglify = spawn('node', [
const { status, stderr } = childProcess.spawnSync('node', [
'node_modules/.bin/uglifyjs',
'--compress', '--mangle',
'--source-map', outputFile + '.map',
'--source-map-url', path.basename(outputFile) + '.map',
'--', inputFile])
'--output', outputFile,
'--source-map', `url='${path.basename(outputFile)}.map'`,
'--', inputFile
])
var minStream = fs.createWriteStream(outputFile)
uglify.stdout.pipe(minStream)
uglify.stdin.end()
uglify.on('exit', function (code) {
if (code) {
console.error('uglify failed!')
fs.unlink(outputFile, function () {
process.exit(code)
})
}
onDone()
})
if (status !== 0) {
console.error(stderr.toString())
process.exit(status)
}
}
var q = [
createFolder.bind(null, './build', done),
bundle.bind(null, 'lib/index.js', 'QRCode', 'build/qrcode.js', done),
bundle.bind(null, 'helper/to-sjis.js', 'QRCode.toSJIS', 'build/qrcode.tosjis.js', done),
minify.bind(null, 'build/qrcode.js', 'build/qrcode.min.js', done),
minify.bind(null, 'build/qrcode.tosjis.js', 'build/qrcode.tosjis.min.js', done)
]
function done () {
var j = q.shift()
if (j) j()
else complete()
}
function complete () {
console.log('\nBuild complete =)\n'.green)
}
done()
createFolder('./build')
bundle('lib/index.js', 'QRCode', 'build/qrcode.js')
bundle('helper/to-sjis.js', 'QRCode.toSJIS', 'build/qrcode.tosjis.js')
minify('build/qrcode.js', 'build/qrcode.min.js')
minify('build/qrcode.tosjis.js', 'build/qrcode.tosjis.min.js')
console.log('\nBuild complete =)\n'.green)

View file

@ -4,8 +4,7 @@ var http = require('http')
var fs = require('fs')
var QRCode = require('../lib')
var canvasutil = require('canvasutil')
var Canvas = require('canvas')
var Image = Canvas.Image
var { createCanvas, loadImage } = require('canvas')
var path = require('path')
@ -73,7 +72,7 @@ effectHandlers.bacon = function (args, cb) {
}
effectHandlers.rounded = function (args, cb) {
var canvas = new Canvas(200, 200)
var canvas = createCanvas(200, 200)
QRCode.toCanvas(canvas, args.text || '', function (err) {
if (err) {
cb(err, canvas)
@ -223,12 +222,9 @@ effectHandlers.remoteImage = function (args, cb) {
}
effectHandlers.image = function (args, cb) {
var src = args.src || ''
var img = new Image()
var convert = canvasutil.conversionLib
img.onload = function () {
var canvas = new Canvas(200, 200)
loadImage(args.src || '').then((img) => {
var convert = canvasutil.conversionLib
var canvas = createCanvas(200, 200)
QRCode.toCanvas(canvas, args.text || '', function (err) {
if (err) {
cb(err, false)
@ -238,7 +234,7 @@ effectHandlers.image = function (args, cb) {
var codeCtx = canvas.getContext('2d')
var frame = codeCtx.getImageData(0, 0, canvas.width, canvas.width)
var tpx = new canvasutil.PixelCore()
var baconCanvas = new Canvas(canvas.width, canvas.width)
var baconCanvas = createCanvas(canvas.width, canvas.width)
var ctx = baconCanvas.getContext('2d')
var topThreshold = args.darkThreshold || 25
var bottomThreshold = args.lightThreshold || 75
@ -294,18 +290,13 @@ effectHandlers.image = function (args, cb) {
cb(null, baconCanvas)
})
}
img.onerror = function (error) {
error.message += ' (' + src + ')'
}, (error) => {
cb(error, null)
}
img.src = src
})
}
effectHandlers.plain = function (args, cb) {
var canvas = new Canvas(200, 200)
var canvas = createCanvas(200, 200)
var text = args.text || ''
QRCode.toCanvas(canvas, text || '', function (err) {
cb(err, canvas)

8810
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -39,29 +39,28 @@
"dependencies": {
"dijkstrajs": "^1.0.1",
"encode-utf8": "^1.0.3",
"isarray": "^2.0.1",
"pngjs": "^3.3.0",
"yargs": "^13.2.4"
"isarray": "^2.0.5",
"pngjs": "^5.0.0",
"uglify-js": "^3.9.1",
"yargs": "^15.3.1"
},
"devDependencies": {
"browserify": "^16.2.3",
"canvas": "^1.6.11",
"canvasutil": "*",
"colors": "*",
"express": "^4.16.4",
"htmlparser2": "^3.9.2",
"os-tmpdir": "^1.0.2",
"sinon": "^1.17.7",
"browserify": "^16.5.1",
"canvas": "^2.6.1",
"canvasutil": "0.0.4",
"colors": "^1.4.0",
"express": "^4.17.1",
"htmlparser2": "^4.1.0",
"sinon": "^9.0.2",
"standard": "^14.3.3",
"tap": "^12.1.1",
"uglify-js": "^2.7.5"
"tap": "^14.10.7"
},
"repository": {
"type": "git",
"url": "git://github.com/soldair/node-qrcode.git"
},
"engines": {
"node": ">=4"
"node": ">=10.13.0"
},
"standard": {
"ignore": [

View file

@ -1,5 +1,5 @@
var test = require('tap').test
var Canvas = require('canvas')
var { Canvas, createCanvas } = require('canvas')
var QRCode = require('lib')
var Helpers = require('test/helpers')
@ -10,11 +10,11 @@ test('toCanvas - no promise available', function (t) {
global.document = {
createElement: function (el) {
if (el === 'canvas') {
return new Canvas(200, 200)
return createCanvas(200, 200)
}
}
}
var canvasEl = new Canvas(200, 200)
var canvasEl = createCanvas(200, 200)
t.throw(function () { QRCode.toCanvas() },
'Should throw if no arguments are provided')
@ -39,7 +39,7 @@ test('toCanvas', function (t) {
global.document = {
createElement: function (el) {
if (el === 'canvas') {
return new Canvas(200, 200)
return createCanvas(200, 200)
}
}
}
@ -79,7 +79,7 @@ test('toCanvas', function (t) {
})
test('toCanvas with specified canvas element', function (t) {
var canvasEl = new Canvas(200, 200)
var canvasEl = createCanvas(200, 200)
t.plan(6)

View file

@ -1,7 +1,7 @@
var test = require('tap').test
var QRCode = require('lib')
var QRCodeBrowser = require('lib/browser')
var Canvas = require('canvas')
var { createCanvas } = require('canvas')
var Helpers = require('test/helpers')
test('toDataURL - no promise available', function (t) {
@ -126,7 +126,7 @@ test('Canvas toDataURL - image/png', function (t) {
t.throw(function () { QRCodeBrowser.toDataURL(function () {}) },
'Should throw if text is not provided')
var canvas = new Canvas(200, 200)
var canvas = createCanvas(200, 200)
QRCodeBrowser.toDataURL(canvas, 'i am a pony!', {
errorCorrectionLevel: 'H',
type: 'image/png'
@ -163,7 +163,7 @@ test('Canvas toDataURL - image/png', function (t) {
global.document = {
createElement: function (el) {
if (el === 'canvas') {
return new Canvas(200, 200)
return createCanvas(200, 200)
}
}
}

View file

@ -1,7 +1,7 @@
var test = require('tap').test
var fs = require('fs')
var path = require('path')
var tmpDir = require('os-tmpdir')
var os = require('os')
var sinon = require('sinon')
var QRCode = require('lib')
var Helpers = require('test/helpers')
@ -9,7 +9,7 @@ var StreamMock = require('test/mocks/writable-stream')
test('toFile - no promise available', function (t) {
Helpers.removeNativePromise()
var fileName = path.join(tmpDir(), 'qrimage.png')
var fileName = path.join(os.tmpdir(), 'qrimage.png')
t.throw(function () { QRCode.toFile(fileName, 'some text') },
'Should throw if a callback is not provided')
@ -23,7 +23,7 @@ test('toFile - no promise available', function (t) {
})
test('toFile', function (t) {
var fileName = path.join(tmpDir(), 'qrimage.png')
var fileName = path.join(os.tmpdir(), 'qrimage.png')
t.throw(function () { QRCode.toFile('some text', function () {}) },
'Should throw if path is not provided')
@ -38,7 +38,7 @@ test('toFile', function (t) {
})
test('toFile png', function (t) {
var fileName = path.join(tmpDir(), 'qrimage.png')
var fileName = path.join(os.tmpdir(), 'qrimage.png')
var expectedBase64Output = [
'iVBORw0KGgoAAAANSUhEUgAAAHQAAAB0CAYAAABUmhYnAAAAAklEQVR4AewaftIAAAKzSU',
'RBVO3BQW7kQAwEwSxC//9y7h55akCQxvYQjIj/scYo1ijFGqVYoxRrlGKNUqxRijVKsUYp',
@ -101,7 +101,6 @@ test('toFile png', function (t) {
var fsStub = sinon.stub(fs, 'createWriteStream')
fsStub.returns(new StreamMock().forceErrorOnWrite())
fsStub.reset()
QRCode.toFile(fileName, 'i am a pony!', {
errorCorrectionLevel: 'L'
@ -119,7 +118,7 @@ test('toFile png', function (t) {
})
test('toFile svg', function (t) {
var fileName = path.join(tmpDir(), 'qrimage.svg')
var fileName = path.join(os.tmpdir(), 'qrimage.svg')
var expectedOutput = fs.readFileSync(
path.join(__dirname, '/svg.expected.out'), 'UTF-8')
@ -166,7 +165,7 @@ test('toFile svg', function (t) {
})
test('toFile utf8', function (t) {
var fileName = path.join(tmpDir(), 'qrimage.txt')
var fileName = path.join(os.tmpdir(), 'qrimage.txt')
var expectedOutput = [
' ',
' ',
@ -226,7 +225,7 @@ test('toFile utf8', function (t) {
})
test('toFile manual segments', function (t) {
var fileName = path.join(tmpDir(), 'qrimage.txt')
var fileName = path.join(os.tmpdir(), 'qrimage.txt')
var segs = [
{ data: 'ABCDEFG', mode: 'alphanumeric' },
{ data: '0123456', mode: 'numeric' }

View file

@ -1,5 +1,5 @@
var test = require('tap').test
var Canvas = require('canvas')
var { Canvas, createCanvas } = require('canvas')
var QRCode = require('core/qrcode')
var CanvasRenderer = require('renderer/canvas')
@ -18,7 +18,7 @@ test('CanvasRenderer render', function (t) {
global.document = {
createElement: function (el) {
if (el === 'canvas') {
return new Canvas(200, 200)
return createCanvas(200, 200)
}
}
}
@ -56,7 +56,7 @@ test('CanvasRenderer render', function (t) {
test('CanvasRenderer render to provided canvas', function (t) {
var sampleQrData = QRCode.create('sample text', { version: 2 })
var canvasEl = new Canvas(200, 200)
var canvasEl = createCanvas(200, 200)
t.notThrow(function () { CanvasRenderer.render(sampleQrData, canvasEl) },
'Should not throw with only qrData and canvas param')
@ -83,7 +83,7 @@ test('CanvasRenderer renderToDataURL', function (t) {
global.document = {
createElement: function (el) {
if (el === 'canvas') {
return new Canvas(200, 200)
return createCanvas(200, 200)
}
}
}
@ -118,7 +118,7 @@ test('CanvasRenderer renderToDataURL', function (t) {
test('CanvasRenderer renderToDataURL to provided canvas', function (t) {
var sampleQrData = QRCode.create('sample text', { version: 2 })
var canvasEl = new Canvas(200, 200)
var canvasEl = createCanvas(200, 200)
var url
t.notThrow(function () {

View file

@ -91,7 +91,6 @@ test('PNG renderToFile', function (t) {
var fileName = 'qrimage.png'
var fsStub = sinon.stub(fs, 'createWriteStream')
fsStub.returns(new StreamMock())
fsStub.reset()
t.plan(6)
@ -117,7 +116,6 @@ test('PNG renderToFile', function (t) {
fsStub.restore()
fsStub = sinon.stub(fs, 'createWriteStream')
fsStub.returns(new StreamMock().forceErrorOnWrite())
fsStub.reset()
PngRenderer.renderToFile(fileName, sampleQrData, function (err) {
t.ok(err,

View file

@ -144,7 +144,6 @@ test('Svg renderToFile', function (t) {
var sampleQrData = QRCode.create('sample text', { version: 2 })
var fileName = 'qrimage.svg'
var fsStub = sinon.stub(fs, 'writeFile').callsArg(2)
fsStub.reset()
t.plan(5)
@ -169,7 +168,6 @@ test('Svg renderToFile', function (t) {
fsStub.restore()
fsStub = sinon.stub(fs, 'writeFile').callsArgWith(2, new Error())
fsStub.reset()
SvgRenderer.renderToFile(fileName, sampleQrData, function (err) {
t.ok(err,

View file

@ -35,7 +35,6 @@ test('Utf8 renderToFile', function (t) {
var sampleQrData = QRCode.create('sample text', { version: 2 })
var fileName = 'qrimage.txt'
var fsStub = sinon.stub(fs, 'writeFile').callsArg(2)
fsStub.reset()
t.plan(5)
@ -60,7 +59,6 @@ test('Utf8 renderToFile', function (t) {
fsStub.restore()
fsStub = sinon.stub(fs, 'writeFile').callsArgWith(2, new Error())
fsStub.reset()
Utf8Renderer.renderToFile(fileName, sampleQrData, function (err) {
t.ok(err,