Skip to content

Commit

Permalink
Merge pull request #124 from PrismarineJS/karang_fix
Browse files Browse the repository at this point in the history
Safe require optional package
  • Loading branch information
Karang authored Jan 23, 2021
2 parents 3f30f85 + 4635c4c commit 8f13f8d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lib/headless.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/* global THREE */

function safeRequire (path) {
try {
return require(path)
} catch (e) {
return {}
}
}
const { spawn } = require('child_process')
const net = require('net')
global.THREE = require('three')
global.Worker = require('worker_threads').Worker
const { createCanvas } = require('node-canvas-webgl/lib')
const { createCanvas } = safeRequire('node-canvas-webgl/lib')

const { WorldView, Viewer, getBufferFromStream } = require('../viewer')

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prismarine-viewer",
"version": "1.13.2",
"version": "1.13.3",
"description": "Web based viewer",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 8 additions & 2 deletions viewer/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@

const { loadImage } = require('node-canvas-webgl/lib')
function safeRequire (path) {
try {
return require(path)
} catch (e) {
return {}
}
}
const { loadImage } = safeRequire('node-canvas-webgl/lib')
const THREE = require('three')
const path = require('path')

Expand Down

0 comments on commit 8f13f8d

Please sign in to comment.