CompileManager.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. const fsPromises = require('node:fs/promises')
  2. const os = require('node:os')
  3. const Path = require('node:path')
  4. const { callbackify } = require('node:util')
  5. const Settings = require('@overleaf/settings')
  6. const logger = require('@overleaf/logger')
  7. const OError = require('@overleaf/o-error')
  8. const ResourceWriter = require('./ResourceWriter')
  9. const LatexRunner = require('./LatexRunner')
  10. const OutputFileFinder = require('./OutputFileFinder')
  11. const OutputCacheManager = require('./OutputCacheManager')
  12. const Metrics = require('./Metrics')
  13. const DraftModeManager = require('./DraftModeManager')
  14. const TikzManager = require('./TikzManager')
  15. const LockManager = require('./LockManager')
  16. const Errors = require('./Errors')
  17. const CommandRunner = require('./CommandRunner')
  18. const { emitPdfStats } = require('./ContentCacheMetrics')
  19. const SynctexOutputParser = require('./SynctexOutputParser')
  20. const {
  21. downloadLatestCompileCache,
  22. downloadOutputDotSynctexFromCompileCache,
  23. } = require('./CLSICacheHandler')
  24. const COMPILE_TIME_BUCKETS = [
  25. // NOTE: These buckets are locked in per metric name.
  26. // If you want to change them, you will need to rename metrics.
  27. 0, 1, 2, 3, 4, 6, 8, 11, 15, 22, 31, 43, 61, 86, 121, 170, 240,
  28. ].map(seconds => seconds * 1000)
  29. function getCompileName(projectId, userId) {
  30. if (userId != null) {
  31. return `${projectId}-${userId}`
  32. } else {
  33. return projectId
  34. }
  35. }
  36. function getCompileDir(projectId, userId) {
  37. return Path.join(Settings.path.compilesDir, getCompileName(projectId, userId))
  38. }
  39. function getOutputDir(projectId, userId) {
  40. return Path.join(Settings.path.outputDir, getCompileName(projectId, userId))
  41. }
  42. async function doCompileWithLock(request, stats, timings) {
  43. const compileDir = getCompileDir(request.project_id, request.user_id)
  44. request.isInitialCompile =
  45. (await fsPromises.mkdir(compileDir, { recursive: true })) === compileDir
  46. // prevent simultaneous compiles
  47. const lock = LockManager.acquire(compileDir)
  48. try {
  49. return await doCompile(request, stats, timings)
  50. } finally {
  51. lock.release()
  52. }
  53. }
  54. async function doCompile(request, stats, timings) {
  55. const { project_id: projectId, user_id: userId } = request
  56. const compileDir = getCompileDir(request.project_id, request.user_id)
  57. const timerE2E = new Metrics.Timer(
  58. 'compile-e2e-v2',
  59. 1,
  60. request.metricsOpts,
  61. COMPILE_TIME_BUCKETS
  62. )
  63. if (request.isInitialCompile) {
  64. stats.isInitialCompile = 1
  65. request.metricsOpts.compile = 'initial'
  66. if (request.compileFromClsiCache) {
  67. try {
  68. if (await downloadLatestCompileCache(projectId, userId, compileDir)) {
  69. stats.restoredClsiCache = 1
  70. request.metricsOpts.compile = 'from-clsi-cache'
  71. }
  72. } catch (err) {
  73. logger.warn(
  74. { err, projectId, userId },
  75. 'failed to populate compile dir from cache'
  76. )
  77. }
  78. }
  79. } else {
  80. request.metricsOpts.compile = 'recompile'
  81. }
  82. const writeToDiskTimer = new Metrics.Timer(
  83. 'write-to-disk',
  84. 1,
  85. request.metricsOpts
  86. )
  87. logger.debug(
  88. { projectId: request.project_id, userId: request.user_id },
  89. 'syncing resources to disk'
  90. )
  91. let resourceList
  92. try {
  93. // NOTE: resourceList is insecure, it should only be used to exclude files from the output list
  94. resourceList = await ResourceWriter.promises.syncResourcesToDisk(
  95. request,
  96. compileDir
  97. )
  98. } catch (error) {
  99. if (error instanceof Errors.FilesOutOfSyncError) {
  100. OError.tag(error, 'files out of sync, please retry', {
  101. projectId: request.project_id,
  102. userId: request.user_id,
  103. })
  104. } else {
  105. OError.tag(error, 'error writing resources to disk', {
  106. projectId: request.project_id,
  107. userId: request.user_id,
  108. })
  109. }
  110. throw error
  111. }
  112. logger.debug(
  113. {
  114. projectId: request.project_id,
  115. userId: request.user_id,
  116. timeTaken: Date.now() - writeToDiskTimer.start,
  117. },
  118. 'written files to disk'
  119. )
  120. timings.sync = writeToDiskTimer.done()
  121. // set up environment variables for chktex
  122. const env = {
  123. OVERLEAF_PROJECT_ID: request.project_id,
  124. }
  125. if (Settings.texliveOpenoutAny && Settings.texliveOpenoutAny !== '') {
  126. // override default texlive openout_any environment variable
  127. env.openout_any = Settings.texliveOpenoutAny
  128. }
  129. if (Settings.texliveMaxPrintLine && Settings.texliveMaxPrintLine !== '') {
  130. // override default texlive max_print_line environment variable
  131. env.max_print_line = Settings.texliveMaxPrintLine
  132. }
  133. // only run chktex on LaTeX files (not knitr .Rtex files or any others)
  134. const isLaTeXFile = request.rootResourcePath?.match(/\.tex$/i)
  135. if (request.check != null && isLaTeXFile) {
  136. env.CHKTEX_OPTIONS = '-nall -e9 -e10 -w15 -w16'
  137. env.CHKTEX_ULIMIT_OPTIONS = '-t 5 -v 64000'
  138. if (request.check === 'error') {
  139. env.CHKTEX_EXIT_ON_ERROR = 1
  140. }
  141. if (request.check === 'validate') {
  142. env.CHKTEX_VALIDATE = 1
  143. }
  144. }
  145. // apply a series of file modifications/creations for draft mode and tikz
  146. if (request.draft) {
  147. await DraftModeManager.promises.injectDraftMode(
  148. Path.join(compileDir, request.rootResourcePath)
  149. )
  150. }
  151. const needsMainFile = await TikzManager.promises.checkMainFile(
  152. compileDir,
  153. request.rootResourcePath,
  154. resourceList
  155. )
  156. if (needsMainFile) {
  157. await TikzManager.promises.injectOutputFile(
  158. compileDir,
  159. request.rootResourcePath
  160. )
  161. }
  162. const compileTimer = new Metrics.Timer('run-compile', 1, request.metricsOpts)
  163. // find the image tag to log it as a metric, e.g. 2015.1 (convert . to - for graphite)
  164. let tag = 'default'
  165. if (request.imageName != null) {
  166. const match = request.imageName.match(/:(.*)/)
  167. if (match != null) {
  168. tag = match[1].replace(/\./g, '-')
  169. }
  170. }
  171. // exclude smoke test
  172. if (!request.project_id.match(/^[0-9a-f]{24}$/)) {
  173. tag = 'other'
  174. }
  175. Metrics.inc('compiles', 1, request.metricsOpts)
  176. Metrics.inc(`compiles-with-image.${tag}`, 1, request.metricsOpts)
  177. const compileName = getCompileName(request.project_id, request.user_id)
  178. try {
  179. await LatexRunner.promises.runLatex(compileName, {
  180. directory: compileDir,
  181. mainFile: request.rootResourcePath,
  182. compiler: request.compiler,
  183. timeout: request.timeout,
  184. image: request.imageName,
  185. flags: request.flags,
  186. environment: env,
  187. compileGroup: request.compileGroup,
  188. stopOnFirstError: request.stopOnFirstError,
  189. stats,
  190. timings,
  191. })
  192. // We use errors to return the validation state. It would be nice to use a
  193. // more appropriate mechanism.
  194. if (request.check === 'validate') {
  195. const validationError = new Error('validation')
  196. validationError.validate = 'pass'
  197. throw validationError
  198. }
  199. } catch (originalError) {
  200. let error = originalError
  201. // request was for validation only
  202. if (request.check === 'validate' && !error.validate) {
  203. error = new Error('validation')
  204. error.validate = originalError.code ? 'fail' : 'pass'
  205. }
  206. // request was for compile, and failed on validation
  207. if (request.check === 'error' && originalError.message === 'exited') {
  208. error = new Error('compilation')
  209. error.validate = 'fail'
  210. }
  211. // record timeout errors as a separate counter, success is recorded later
  212. if (error.timedout) {
  213. Metrics.inc('compiles-timeout', 1, request.metricsOpts)
  214. }
  215. const { outputFiles, allEntries, buildId } = await _saveOutputFiles({
  216. request,
  217. compileDir,
  218. resourceList,
  219. stats,
  220. timings,
  221. })
  222. error.outputFiles = outputFiles // return output files so user can check logs
  223. error.buildId = buildId
  224. // Clear project if this compile was abruptly terminated
  225. if (error.terminated || error.timedout) {
  226. await clearProjectWithListing(
  227. request.project_id,
  228. request.user_id,
  229. allEntries
  230. )
  231. }
  232. throw error
  233. }
  234. // compile completed normally
  235. Metrics.inc('compiles-succeeded', 1, request.metricsOpts)
  236. for (const metricKey in stats) {
  237. const metricValue = stats[metricKey]
  238. Metrics.count(metricKey, metricValue, 1, request.metricsOpts)
  239. }
  240. for (const metricKey in timings) {
  241. const metricValue = timings[metricKey]
  242. Metrics.timing(metricKey, metricValue, 1, request.metricsOpts)
  243. }
  244. const loadavg = typeof os.loadavg === 'function' ? os.loadavg() : undefined
  245. if (loadavg != null) {
  246. Metrics.gauge('load-avg', loadavg[0])
  247. }
  248. const ts = compileTimer.done()
  249. logger.debug(
  250. {
  251. projectId: request.project_id,
  252. userId: request.user_id,
  253. timeTaken: ts,
  254. stats,
  255. timings,
  256. loadavg,
  257. },
  258. 'done compile'
  259. )
  260. if (stats['latex-runs'] > 0) {
  261. Metrics.histogram(
  262. 'avg-compile-per-pass-v2',
  263. ts / stats['latex-runs'],
  264. COMPILE_TIME_BUCKETS,
  265. request.metricsOpts
  266. )
  267. Metrics.timing(
  268. 'avg-compile-per-pass-v2',
  269. ts / stats['latex-runs'],
  270. 1,
  271. request.metricsOpts
  272. )
  273. }
  274. if (stats['latex-runs'] > 0 && timings['cpu-time'] > 0) {
  275. Metrics.timing(
  276. 'run-compile-cpu-time-per-pass',
  277. timings['cpu-time'] / stats['latex-runs'],
  278. 1,
  279. request.metricsOpts
  280. )
  281. }
  282. // Emit compile time.
  283. timings.compile = ts
  284. const { outputFiles, buildId } = await _saveOutputFiles({
  285. request,
  286. compileDir,
  287. resourceList,
  288. stats,
  289. timings,
  290. })
  291. // Emit e2e compile time.
  292. timings.compileE2E = timerE2E.done()
  293. Metrics.timing('compile-e2e-v2', timings.compileE2E, 1, request.metricsOpts)
  294. if (stats['pdf-size']) {
  295. emitPdfStats(stats, timings, request)
  296. }
  297. return { outputFiles, buildId }
  298. }
  299. async function _saveOutputFiles({
  300. request,
  301. compileDir,
  302. resourceList,
  303. stats,
  304. timings,
  305. }) {
  306. const timer = new Metrics.Timer(
  307. 'process-output-files',
  308. 1,
  309. request.metricsOpts
  310. )
  311. const outputDir = getOutputDir(request.project_id, request.user_id)
  312. const { outputFiles: rawOutputFiles, allEntries } =
  313. await OutputFileFinder.promises.findOutputFiles(resourceList, compileDir)
  314. const { buildId, outputFiles } =
  315. await OutputCacheManager.promises.saveOutputFiles(
  316. { request, stats, timings },
  317. rawOutputFiles,
  318. compileDir,
  319. outputDir
  320. )
  321. timings.output = timer.done()
  322. return { outputFiles, allEntries, buildId }
  323. }
  324. async function stopCompile(projectId, userId) {
  325. const compileName = getCompileName(projectId, userId)
  326. await LatexRunner.promises.killLatex(compileName)
  327. }
  328. async function clearProject(projectId, userId) {
  329. const compileDir = getCompileDir(projectId, userId)
  330. await fsPromises.rm(compileDir, { force: true, recursive: true })
  331. }
  332. async function clearProjectWithListing(projectId, userId, allEntries) {
  333. const compileDir = getCompileDir(projectId, userId)
  334. const exists = await _checkDirectory(compileDir)
  335. if (!exists) {
  336. // skip removal if no directory present
  337. return
  338. }
  339. for (const pathInProject of allEntries) {
  340. const path = Path.join(compileDir, pathInProject)
  341. if (path.endsWith('/')) {
  342. await fsPromises.rmdir(path)
  343. } else {
  344. await fsPromises.unlink(path)
  345. }
  346. }
  347. await fsPromises.rmdir(compileDir)
  348. }
  349. async function _findAllDirs() {
  350. const root = Settings.path.compilesDir
  351. const files = await fsPromises.readdir(root)
  352. const allDirs = files.map(file => Path.join(root, file))
  353. return allDirs
  354. }
  355. async function clearExpiredProjects(maxCacheAgeMs) {
  356. const now = Date.now()
  357. const dirs = await _findAllDirs()
  358. for (const dir of dirs) {
  359. let stats
  360. try {
  361. stats = await fsPromises.stat(dir)
  362. } catch (err) {
  363. // ignore errors checking directory
  364. continue
  365. }
  366. const age = now - stats.mtime
  367. const hasExpired = age > maxCacheAgeMs
  368. if (hasExpired) {
  369. await fsPromises.rm(dir, { force: true, recursive: true })
  370. }
  371. }
  372. }
  373. async function _checkDirectory(compileDir) {
  374. let stats
  375. try {
  376. stats = await fsPromises.lstat(compileDir)
  377. } catch (err) {
  378. if (err.code === 'ENOENT') {
  379. // directory does not exist
  380. return false
  381. }
  382. OError.tag(err, 'error on stat of project directory for removal', {
  383. dir: compileDir,
  384. })
  385. throw err
  386. }
  387. if (!stats.isDirectory()) {
  388. throw new OError('project directory is not directory', {
  389. dir: compileDir,
  390. stats,
  391. })
  392. }
  393. return true
  394. }
  395. async function syncFromCode(projectId, userId, filename, line, column, opts) {
  396. // If LaTeX was run in a virtual environment, the file path that synctex expects
  397. // might not match the file path on the host. The .synctex.gz file however, will be accessed
  398. // wherever it is on the host.
  399. const compileName = getCompileName(projectId, userId)
  400. const baseDir = Settings.path.synctexBaseDir(compileName)
  401. const inputFilePath = Path.join(baseDir, filename)
  402. const outputFilePath = Path.join(baseDir, 'output.pdf')
  403. const command = [
  404. 'synctex',
  405. 'view',
  406. '-i',
  407. `${line}:${column}:${inputFilePath}`,
  408. '-o',
  409. outputFilePath,
  410. ]
  411. const stdout = await _runSynctex(projectId, userId, command, opts)
  412. logger.debug(
  413. { projectId, userId, filename, line, column, command, stdout },
  414. 'synctex code output'
  415. )
  416. return SynctexOutputParser.parseViewOutput(stdout)
  417. }
  418. async function syncFromPdf(projectId, userId, page, h, v, opts) {
  419. const compileName = getCompileName(projectId, userId)
  420. const baseDir = Settings.path.synctexBaseDir(compileName)
  421. const outputFilePath = `${baseDir}/output.pdf`
  422. const command = [
  423. 'synctex',
  424. 'edit',
  425. '-o',
  426. `${page}:${h}:${v}:${outputFilePath}`,
  427. ]
  428. const stdout = await _runSynctex(projectId, userId, command, opts)
  429. logger.debug({ projectId, userId, page, h, v, stdout }, 'synctex pdf output')
  430. return SynctexOutputParser.parseEditOutput(stdout, baseDir)
  431. }
  432. async function _checkFileExists(dir, filename) {
  433. try {
  434. await fsPromises.stat(dir)
  435. } catch (error) {
  436. if (error.code === 'ENOENT') {
  437. throw new Errors.NotFoundError('no output directory')
  438. }
  439. throw error
  440. }
  441. const file = Path.join(dir, filename)
  442. let stats
  443. try {
  444. stats = await fsPromises.stat(file)
  445. } catch (error) {
  446. if (error.code === 'ENOENT') {
  447. throw new Errors.NotFoundError('no output file')
  448. }
  449. }
  450. if (!stats.isFile()) {
  451. throw new Error('not a file')
  452. }
  453. }
  454. async function _runSynctex(projectId, userId, command, opts) {
  455. const { imageName, editorId, buildId, compileFromClsiCache } = opts
  456. if (imageName && !_isImageNameAllowed(imageName)) {
  457. throw new Errors.InvalidParameter('invalid image')
  458. }
  459. if (editorId && !/^[a-f0-9-]+$/.test(editorId)) {
  460. throw new Errors.InvalidParameter('invalid editorId')
  461. }
  462. if (buildId && !OutputCacheManager.BUILD_REGEX.test(buildId)) {
  463. throw new Errors.InvalidParameter('invalid buildId')
  464. }
  465. const outputDir = getOutputDir(projectId, userId)
  466. const runInOutputDir = buildId && CommandRunner.canRunSyncTeXInOutputDir()
  467. const directory = runInOutputDir
  468. ? Path.join(outputDir, OutputCacheManager.CACHE_SUBDIR, buildId)
  469. : getCompileDir(projectId, userId)
  470. const timeout = 60 * 1000 // increased to allow for large projects
  471. const compileName = getCompileName(projectId, userId)
  472. const compileGroup = runInOutputDir ? 'synctex-output' : 'synctex'
  473. const defaultImageName =
  474. Settings.clsi && Settings.clsi.docker && Settings.clsi.docker.image
  475. // eslint-disable-next-line @typescript-eslint/return-await
  476. return await OutputCacheManager.promises.queueDirOperation(
  477. outputDir,
  478. /**
  479. * @return {Promise<string>}
  480. */
  481. async () => {
  482. try {
  483. await _checkFileExists(directory, 'output.synctex.gz')
  484. } catch (err) {
  485. if (
  486. err instanceof Errors.NotFoundError &&
  487. compileFromClsiCache &&
  488. editorId &&
  489. buildId
  490. ) {
  491. try {
  492. await downloadOutputDotSynctexFromCompileCache(
  493. projectId,
  494. userId,
  495. editorId,
  496. buildId,
  497. directory
  498. )
  499. } catch (err) {
  500. logger.warn(
  501. { err, projectId, userId, editorId, buildId },
  502. 'failed to download output.synctex.gz from clsi-cache'
  503. )
  504. }
  505. await _checkFileExists(directory, 'output.synctex.gz')
  506. } else {
  507. throw err
  508. }
  509. }
  510. try {
  511. const output = await CommandRunner.promises.run(
  512. compileName,
  513. command,
  514. directory,
  515. imageName || defaultImageName,
  516. timeout,
  517. {},
  518. compileGroup
  519. )
  520. return output.stdout
  521. } catch (error) {
  522. throw OError.tag(error, 'error running synctex', {
  523. command,
  524. projectId,
  525. userId,
  526. })
  527. }
  528. }
  529. )
  530. }
  531. async function wordcount(projectId, userId, filename, image) {
  532. logger.debug({ projectId, userId, filename, image }, 'running wordcount')
  533. const filePath = `$COMPILE_DIR/${filename}`
  534. const command = ['texcount', '-nocol', '-inc', filePath]
  535. const compileDir = getCompileDir(projectId, userId)
  536. const timeout = 60 * 1000
  537. const compileName = getCompileName(projectId, userId)
  538. const compileGroup = 'wordcount'
  539. if (image && !_isImageNameAllowed(image)) {
  540. throw new Errors.InvalidParameter('invalid image')
  541. }
  542. try {
  543. await fsPromises.mkdir(compileDir, { recursive: true })
  544. } catch (err) {
  545. throw OError.tag(err, 'error ensuring dir for wordcount', {
  546. projectId,
  547. userId,
  548. filename,
  549. })
  550. }
  551. try {
  552. const { stdout } = await CommandRunner.promises.run(
  553. compileName,
  554. command,
  555. compileDir,
  556. image,
  557. timeout,
  558. {},
  559. compileGroup
  560. )
  561. const results = _parseWordcountFromOutput(stdout)
  562. logger.debug(
  563. { projectId, userId, wordcount: results },
  564. 'word count results'
  565. )
  566. return results
  567. } catch (err) {
  568. throw OError.tag(err, 'error reading word count output', {
  569. command,
  570. compileDir,
  571. projectId,
  572. userId,
  573. })
  574. }
  575. }
  576. function _parseWordcountFromOutput(output) {
  577. const results = {
  578. encode: '',
  579. textWords: 0,
  580. headWords: 0,
  581. outside: 0,
  582. headers: 0,
  583. elements: 0,
  584. mathInline: 0,
  585. mathDisplay: 0,
  586. errors: 0,
  587. messages: '',
  588. }
  589. for (const line of output.split('\n')) {
  590. const [data, info] = line.split(':')
  591. if (data.indexOf('Encoding') > -1) {
  592. results.encode = info.trim()
  593. }
  594. if (data.indexOf('in text') > -1) {
  595. results.textWords = parseInt(info, 10)
  596. }
  597. if (data.indexOf('in head') > -1) {
  598. results.headWords = parseInt(info, 10)
  599. }
  600. if (data.indexOf('outside') > -1) {
  601. results.outside = parseInt(info, 10)
  602. }
  603. if (data.indexOf('of head') > -1) {
  604. results.headers = parseInt(info, 10)
  605. }
  606. if (data.indexOf('Number of floats/tables/figures') > -1) {
  607. results.elements = parseInt(info, 10)
  608. }
  609. if (data.indexOf('Number of math inlines') > -1) {
  610. results.mathInline = parseInt(info, 10)
  611. }
  612. if (data.indexOf('Number of math displayed') > -1) {
  613. results.mathDisplay = parseInt(info, 10)
  614. }
  615. if (data === '(errors') {
  616. // errors reported as (errors:123)
  617. results.errors = parseInt(info, 10)
  618. }
  619. if (line.indexOf('!!! ') > -1) {
  620. // errors logged as !!! message !!!
  621. results.messages += line + '\n'
  622. }
  623. }
  624. return results
  625. }
  626. function _isImageNameAllowed(imageName) {
  627. const ALLOWED_IMAGES =
  628. Settings.clsi && Settings.clsi.docker && Settings.clsi.docker.allowedImages
  629. return !ALLOWED_IMAGES || ALLOWED_IMAGES.includes(imageName)
  630. }
  631. module.exports = {
  632. doCompileWithLock: callbackify(doCompileWithLock),
  633. stopCompile: callbackify(stopCompile),
  634. clearProject: callbackify(clearProject),
  635. clearExpiredProjects: callbackify(clearExpiredProjects),
  636. syncFromCode: callbackify(syncFromCode),
  637. syncFromPdf: callbackify(syncFromPdf),
  638. wordcount: callbackify(wordcount),
  639. promises: {
  640. doCompileWithLock,
  641. stopCompile,
  642. clearProject,
  643. clearExpiredProjects,
  644. syncFromCode,
  645. syncFromPdf,
  646. wordcount,
  647. },
  648. }