Skip to content

Commit

Permalink
fix(Build): Avoid use of promisify
Browse files Browse the repository at this point in the history
This fixes a downstream build issue: https://travis-ci.org/stencila/executa/jobs/659007810#L684 caused by this calvinmetcalf/rollup-plugin-node-builtins#49

In the longer term there should be separate builds for browsers and node as we have in Executa and elsewhere.
  • Loading branch information
nokome committed Mar 8, 2020
1 parent 2df9aa1 commit 7dd52a5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ts/util/jsonSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import fs from 'fs'
import path from 'path'
import { promisify } from 'util'
import JsonSchema from '../jsonSchema'

// Lazily loaded set of JSON Schemas
Expand Down Expand Up @@ -56,12 +55,20 @@ export async function jsonSchemas(): Promise<typeof SCHEMAS> {
__dirname,
...(__filename.endsWith('.ts') ? ['..', '..', 'public'] : [])
)
const files = await promisify(fs.readdir)(dir, 'utf8')
const files = await new Promise<string[]>((resolve, reject) =>
fs.readdir(dir, 'utf8', (error, files) =>
error !== null ? reject(error) : resolve(files)
)
)
const schemaFiles = files.filter(filename =>
filename.endsWith('.schema.json')
)
const promises = schemaFiles.map(async file => {
const json = await promisify(fs.readFile)(path.join(dir, file), 'utf8')
const json = await new Promise<string>((resolve, reject) =>
fs.readFile(path.join(dir, file), 'utf8', (error, content) =>
error !== null ? reject(error) : resolve(content)
)
)
return JSON.parse(json) as JsonSchema
})
const schemas = await Promise.all(promises)
Expand Down

0 comments on commit 7dd52a5

Please sign in to comment.