Fix exports in prod (#521)

* Fix exports in prod

* downgrade libs to fit under next.js serverless function size limit
This commit is contained in:
Steve Ruiz 2022-01-18 10:00:58 +00:00 committed by GitHub
parent 8977d296a9
commit 30d1d7721c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 123 additions and 102 deletions

View file

@ -29,12 +29,13 @@
"@tldraw/tldraw": "^1.5.2",
"@types/next-auth": "^3.15.0",
"aws-sdk": "^2.1053.0",
"chrome-aws-lambda": "^9.0.0",
"next": "^12.0.7",
"next-auth": "^4.0.5",
"next-pwa": "^5.4.4",
"next-themes": "^0.0.15",
"next-transpile-modules": "^9.0.0",
"puppeteer": "^13.1.1",
"puppeteer-core": "^9.0.0",
"react": "17.0.2",
"react-dom": "17.0.2"
},

View file

@ -1,7 +1,8 @@
import { NextApiRequest, NextApiResponse } from 'next'
import puppeteer from 'puppeteer'
import chromium from 'chrome-aws-lambda'
import Cors from 'cors'
import { TDExport, TDExportTypes, TldrawApp } from '@tldraw/tldraw'
import { AnyLengthString } from 'aws-sdk/clients/comprehend'
const cors = Cors({
methods: ['POST'],
@ -35,13 +36,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
type,
} = body
if (type === TDExportTypes.PDF) res.status(500).send('Not implemented yet.')
let browser: puppeteer.Browser = null
try {
browser = await puppeteer.launch({
const browser = await chromium.puppeteer.launch({
slowMo: 50,
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
ignoreHTTPSErrors: true,
headless: true,
})
const page = await browser.newPage()
await page.setUserAgent(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
@ -49,7 +52,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await page.setViewport({ width: Math.floor(width), height: Math.floor(height) })
await page.goto(FRONTEND_URL, { timeout: 15 * 1000, waitUntil: 'networkidle0' })
await page.evaluateHandle('document.fonts.ready')
let err: AnyLengthString
await page.evaluate(async (body: TDExport) => {
try {
let app = window.app
if (!app) app = await new Promise((resolve) => setTimeout(() => resolve(window.app), 250))
await app.ready
@ -59,15 +64,20 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
app.selectAll()
app.zoomToSelection()
app.selectNone()
} catch (e) {
err = e.message
}
}, body)
if (err) {
throw err
}
const imageBuffer = await page.screenshot({
type,
})
await browser.close()
res.status(200).send(imageBuffer)
} catch (err) {
console.error(err.message)
res.status(500).send(err)
} finally {
await browser.close()
}
}

View file

@ -300,7 +300,7 @@ export class TldrawApp extends StateManager<TDSnapshot> {
* @returns The final state
*/
protected cleanup = (state: TDSnapshot, prev: TDSnapshot): TDSnapshot => {
const next = { ...state }
const next: TDSnapshot = { ...state }
// Remove deleted shapes and bindings (in Commands, these will be set to undefined)
if (next.document !== prev.document) {

View file

@ -2,7 +2,7 @@
"document": {
"id": "doc",
"name": "New Document",
"version": 14,
"version": 15.3,
"pages": {
"page": {
"id": "page",
@ -771,7 +771,7 @@
"id": "end",
"index": 1,
"point": [
192.38,
194.79,
141.77
],
"canBind": true,
@ -781,7 +781,7 @@
"id": "bend",
"index": 2,
"point": [
96.19,
97.39,
70.89
]
}
@ -926,7 +926,7 @@
"parentId": "page",
"childIndex": 10,
"point": [
1498.4,
1499.22,
350.84
],
"rotation": 0,
@ -936,7 +936,7 @@
"id": "start",
"index": 0,
"point": [
233.38,
232.56,
0
],
"canBind": true,
@ -956,7 +956,7 @@
"id": "bend",
"index": 2,
"point": [
116.69,
116.28,
74.03
]
}
@ -1057,8 +1057,8 @@
"parentId": "page",
"childIndex": 0.125,
"point": [
754.58,
420.14
757.58,
416.37
],
"rotation": 0,
"bend": 0,
@ -1068,7 +1068,7 @@
"index": 0,
"point": [
0,
0.15
0
],
"canBind": true,
"bindingId": "7905d839-e408-452c-205a-a7d04ca5fbe0"
@ -1077,8 +1077,8 @@
"id": "end",
"index": 1,
"point": [
2001.84,
0
1998.84,
3.77
],
"canBind": true
},
@ -1086,8 +1086,8 @@
"id": "bend",
"index": 2,
"point": [
1000.92,
0.07
999.42,
1.88
]
}
},
@ -1131,8 +1131,8 @@
"parentId": "page",
"childIndex": 0.25,
"point": [
791.58,
111.8
797.58,
108.07
],
"rotation": 0,
"bend": 0,
@ -1142,7 +1142,7 @@
"index": 0,
"point": [
0,
0.15
0
],
"canBind": true,
"bindingId": "5321e340-08c7-458a-1606-2897decd8d2c"
@ -1151,8 +1151,8 @@
"id": "end",
"index": 1,
"point": [
1964.84,
0
1958.84,
3.73
],
"canBind": true
},
@ -1160,8 +1160,8 @@
"id": "bend",
"index": 2,
"point": [
982.42,
0.07
979.42,
1.87
]
}
},
@ -1205,8 +1205,8 @@
"parentId": "page",
"childIndex": 1,
"point": [
793.65,
-170.77
798.65,
-174.5
],
"rotation": 0,
"bend": 0,
@ -1216,7 +1216,7 @@
"index": 0,
"point": [
0,
0.15
0
],
"canBind": true,
"bindingId": "ae576ebd-ff60-43f2-0371-6249cc9dee38"
@ -1225,8 +1225,8 @@
"id": "end",
"index": 1,
"point": [
1962.77,
0
1957.77,
3.73
],
"canBind": true
},
@ -1234,8 +1234,8 @@
"id": "bend",
"index": 2,
"point": [
981.38,
0.07
978.88,
1.87
]
}
},
@ -1495,7 +1495,8 @@
"zoom": 1
}
}
}
},
"assets": {}
},
"assets": {}
}

121
yarn.lock
View file

@ -5278,6 +5278,13 @@ chownr@^1.1.1, chownr@^1.1.2, chownr@^1.1.4:
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b"
integrity sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==
chrome-aws-lambda@^9.0.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/chrome-aws-lambda/-/chrome-aws-lambda-9.1.0.tgz#f3a426fa6588f2fa9452ff62d60afaa2103b2c04"
integrity sha512-y6MOarSzL5LmDv8sWUdDe4wHuAAEeWMlCbLwmL6Bj+pBPava37UuEPbWD5YAXyJx6oHoC0efLGqYDi56k4KMUQ==
dependencies:
lambdafs "^2.0.3"
chromium-pickle-js@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/chromium-pickle-js/-/chromium-pickle-js-0.2.0.tgz#04a106672c18b085ab774d983dfa3ea138f22205"
@ -6426,10 +6433,10 @@ detective-typescript-70@^7.0.0:
node-source-walk "^4.2.0"
typescript "^3.9.7"
devtools-protocol@0.0.948846:
version "0.0.948846"
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.948846.tgz#bff47e2d1dba060130fa40ed2e5f78b916ba285f"
integrity sha512-5fGyt9xmMqUl2VI7+rnUkKCiAQIpLns8sfQtTENy5L70ktbNw0Z3TFJ1JoFNYdx/jffz4YXU45VF75wKZD7sZQ==
devtools-protocol@0.0.869402:
version "0.0.869402"
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.869402.tgz#03ade701761742e43ae4de5dc188bcd80f156d8d"
integrity sha512-VvlVYY+VDJe639yHs5PHISzdWTLL3Aw8rO4cvUtwvoxFd6FHbE4OpHHcde52M6096uYYazAmd4l0o5VuFRO2WA==
dezalgo@^1.0.0:
version "1.0.3"
@ -7455,17 +7462,6 @@ extglob@^2.0.4:
snapdragon "^0.8.1"
to-regex "^3.0.1"
extract-zip@2.0.1, extract-zip@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-2.0.1.tgz#663dca56fe46df890d5f131ef4a06d22bb8ba13a"
integrity sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==
dependencies:
debug "^4.1.1"
get-stream "^5.1.0"
yauzl "^2.10.0"
optionalDependencies:
"@types/yauzl" "^2.9.1"
extract-zip@^1.0.3:
version "1.7.0"
resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-1.7.0.tgz#556cc3ae9df7f452c493a0cfb51cc30277940927"
@ -7476,6 +7472,17 @@ extract-zip@^1.0.3:
mkdirp "^0.5.4"
yauzl "^2.10.0"
extract-zip@^2.0.0, extract-zip@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-2.0.1.tgz#663dca56fe46df890d5f131ef4a06d22bb8ba13a"
integrity sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==
dependencies:
debug "^4.1.1"
get-stream "^5.1.0"
yauzl "^2.10.0"
optionalDependencies:
"@types/yauzl" "^2.9.1"
extsprintf@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
@ -8576,14 +8583,6 @@ https-browserify@1.0.0:
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=
https-proxy-agent@5.0.0, https-proxy-agent@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2"
integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==
dependencies:
agent-base "6"
debug "4"
https-proxy-agent@^2.2.3:
version "2.2.4"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz#4ee7a737abd92678a293d9b34a1af4d0d08c787b"
@ -8592,6 +8591,14 @@ https-proxy-agent@^2.2.3:
agent-base "^4.3.0"
debug "^3.1.0"
https-proxy-agent@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2"
integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==
dependencies:
agent-base "6"
debug "4"
human-signals@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
@ -10130,6 +10137,13 @@ koa@^2.13.1:
type-is "^1.6.16"
vary "^1.1.2"
lambdafs@^2.0.3:
version "2.1.1"
resolved "https://registry.yarnpkg.com/lambdafs/-/lambdafs-2.1.1.tgz#4bf8d3037b6c61bbb4a22ab05c73ee47964c25ed"
integrity sha512-x5k8JcoJWkWLvCVBzrl4pzvkEHSgSBqFjg3Dpsc4AcTMq7oUMym4cL/gRTZ6VM4mUMY+M0dIbQ+V1c1tsqqanQ==
dependencies:
tar-fs "^2.1.1"
language-subtag-registry@~0.3.2:
version "0.3.21"
resolved "https://registry.yarnpkg.com/language-subtag-registry/-/language-subtag-registry-0.3.21.tgz#04ac218bea46f04cb039084602c6da9e788dd45a"
@ -12094,13 +12108,6 @@ pirates@^4.0.4:
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.4.tgz#07df81e61028e402735cdd49db701e4885b4e6e6"
integrity sha512-ZIrVPH+A52Dw84R0L3/VS9Op04PuQ2SEoJL6bkshmiTic/HldyW9Tf7oH5mhJZBK7NmDx27vSMrYEXPXclpDKw==
pkg-dir@4.2.0, pkg-dir@^4.1.0, pkg-dir@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
integrity sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==
dependencies:
find-up "^4.0.0"
pkg-dir@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-3.0.0.tgz#2749020f239ed990881b1f71210d51eb6523bea3"
@ -12108,6 +12115,13 @@ pkg-dir@^3.0.0:
dependencies:
find-up "^3.0.0"
pkg-dir@^4.1.0, pkg-dir@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
integrity sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==
dependencies:
find-up "^4.0.0"
platform@1.3.6:
version "1.3.6"
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7"
@ -12305,7 +12319,7 @@ process@0.11.10, process@^0.11.10:
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI=
progress@2.0.3, progress@^2.0.0, progress@^2.0.3:
progress@^2.0.0, progress@^2.0.1, progress@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
@ -12397,7 +12411,7 @@ protoduck@^5.0.1:
dependencies:
genfun "^5.0.0"
proxy-from-env@1.1.0, proxy-from-env@^1.1.0:
proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
@ -12461,23 +12475,23 @@ pupa@^2.1.1:
dependencies:
escape-goat "^2.0.0"
puppeteer@^13.1.1:
version "13.1.1"
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-13.1.1.tgz#63771eb744202aa91918c49123f846e1747da121"
integrity sha512-GwdFy1JQ43Hhxj6MraXme+XfCX2CKe18MuwToXTMEAk0txg6vUEgwqBnzErTTqDVZ7sWYrDtDaRCfD2y7ZwgGw==
puppeteer-core@^9.0.0:
version "9.1.1"
resolved "https://registry.yarnpkg.com/puppeteer-core/-/puppeteer-core-9.1.1.tgz#0c189c3275967d65c39270e6b146e559baca3d47"
integrity sha512-zbedbitVIGhmgz0nt7eIdLsnaoVZSlNJfBivqm2w67T8LR2bU1dvnruDZ8nQO0zn++Iet7zHbAOdnuS5+H2E7A==
dependencies:
debug "4.3.2"
devtools-protocol "0.0.948846"
extract-zip "2.0.1"
https-proxy-agent "5.0.0"
node-fetch "2.6.5"
pkg-dir "4.2.0"
progress "2.0.3"
proxy-from-env "1.1.0"
rimraf "3.0.2"
tar-fs "2.1.1"
unbzip2-stream "1.4.3"
ws "8.2.3"
debug "^4.1.0"
devtools-protocol "0.0.869402"
extract-zip "^2.0.0"
https-proxy-agent "^5.0.0"
node-fetch "^2.6.1"
pkg-dir "^4.2.0"
progress "^2.0.1"
proxy-from-env "^1.1.0"
rimraf "^3.0.2"
tar-fs "^2.0.0"
unbzip2-stream "^1.3.3"
ws "^7.2.3"
q@^1.5.1:
version "1.5.1"
@ -14182,7 +14196,7 @@ tapable@^2.2.0:
resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0"
integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==
tar-fs@2.1.1, tar-fs@^2.0.0:
tar-fs@^2.0.0, tar-fs@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784"
integrity sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==
@ -14762,7 +14776,7 @@ unbox-primitive@^1.0.1:
has-symbols "^1.0.2"
which-boxed-primitive "^1.0.2"
unbzip2-stream@1.4.3, unbzip2-stream@^1.0.9:
unbzip2-stream@^1.0.9, unbzip2-stream@^1.3.3:
version "1.4.3"
resolved "https://registry.yarnpkg.com/unbzip2-stream/-/unbzip2-stream-1.4.3.tgz#b0da04c4371311df771cdc215e87f2130991ace7"
integrity sha512-mlExGW4w71ebDJviH16lQLtZS32VKqsSfk80GCfUlwT/4/hNRFsoscrF/c++9xinkMzECL1uL9DDwXqFWkruPg==
@ -15556,17 +15570,12 @@ write-pkg@^3.1.0:
sort-keys "^2.0.0"
write-json-file "^2.2.0"
ws@8.2.3:
version "8.2.3"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.2.3.tgz#63a56456db1b04367d0b721a0b80cae6d8becbba"
integrity sha512-wBuoj1BDpC6ZQ1B7DWQBYVLphPWkm8i9Y0/3YdHjHKHiohOJ1ws+3OccDWtH+PoC9DZD5WOTrJvNbWvjS6JWaA==
ws@>=7.4.6:
version "8.4.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.4.0.tgz#f05e982a0a88c604080e8581576e2a063802bed6"
integrity sha512-IHVsKe2pjajSUIl4KYMQOdlyliovpEPquKkqbwswulszzI7r0SfQrxnXdWAEqOlDCLrVSJzo+O1hAwdog2sKSQ==
ws@^7.4.3, ws@^7.4.6:
ws@^7.2.3, ws@^7.4.3, ws@^7.4.6:
version "7.5.6"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.6.tgz#e59fc509fb15ddfb65487ee9765c5a51dec5fe7b"
integrity sha512-6GLgCqo2cy2A2rjCNFlxQS6ZljG/coZfZXclldI8FB/1G3CCI36Zd8xy2HrFVACi8tfk5XrgLQEk+P0Tnz9UcA==