Skip to content

Commit

Permalink
chore(gatsby): Convert util/worker/render-html to typescript (#22263)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawamataryo committed Mar 16, 2020
1 parent dbe239e commit 3904e50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/gatsby/src/utils/worker/child.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Note: this doesn't check for conflicts between module exports
import { getFilePath } from "./page-data"
import { renderHTML } from "./render-html"

module.exports = {
getFilePath,
...require(`./render-html`),
renderHTML,
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const fs = require(`fs-extra`)
const Promise = require(`bluebird`)
const { join } = require(`path`)
import fs from "fs-extra"
import Promise from "bluebird"
import { join } from "path"
import { getPageHtmlFilePath } from "../../utils/page-html"

export function renderHTML({ htmlComponentRendererPath, paths, envVars }) {
export const renderHTML = ({
htmlComponentRendererPath,
paths,
envVars,
}: {
htmlComponentRendererPath: string
paths: string
envVars: [string, string][]
}): Promise<unknown[]> => {
// This is being executed in child process, so we need to set some vars
// for modules that aren't bundled by webpack.
envVars.forEach(([key, value]) => (process.env[key] = value))
Expand All @@ -14,7 +22,7 @@ export function renderHTML({ htmlComponentRendererPath, paths, envVars }) {
new Promise((resolve, reject) => {
const htmlComponentRenderer = require(htmlComponentRendererPath)
try {
htmlComponentRenderer.default(path, (throwAway, htmlString) => {
htmlComponentRenderer.default(path, (_throwAway, htmlString) => {
resolve(
fs.outputFile(
getPageHtmlFilePath(join(process.cwd(), `public`), path),
Expand Down

0 comments on commit 3904e50

Please sign in to comment.