Skip to content

Commit

Permalink
chore(gatsby): Migrate utils/get-public-path.js to ts (#22093)
Browse files Browse the repository at this point in the history
* migrate get-public-path.js to ts

* update module require statement
  • Loading branch information
cola119 authored Mar 9, 2020
1 parent 920fb1b commit fe04b8e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getPublicPath = require(`../get-public-path`)
import { getPublicPath } from "../get-public-path"

const assetPrefix = `https://cdn.example.com`
const pathPrefix = `/blog`
Expand Down
12 changes: 6 additions & 6 deletions packages/gatsby/src/utils/api-runner-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
buildScalarType,
} = require(`../schema/types/type-builders`)
const { emitter, store } = require(`../redux`)
const getPublicPath = require(`./get-public-path`)
const { getPublicPath } = require(`./get-public-path`)
const { getNonGatsbyCodeFrameFormatted } = require(`./stack-trace-utils`)
const { trackBuildError, decorateEvent } = require(`gatsby-telemetry`)
const { default: errorParser } = require(`./api-runner-error-parser`)
Expand Down Expand Up @@ -170,7 +170,7 @@ const runAPI = (plugin, api, args, activity) => {
},
}
}
let localReporter = getLocalReporter(activity, reporter)
const localReporter = getLocalReporter(activity, reporter)

const apiCallArgs = [
{
Expand Down Expand Up @@ -238,8 +238,8 @@ const runAPI = (plugin, api, args, activity) => {
return null
}

let apisRunningById = new Map()
let apisRunningByTraceId = new Map()
const apisRunningById = new Map()
const apisRunningByTraceId = new Map()
let waitingForCasacadeToFinish = []

module.exports = async (api, args = {}, { pluginSource, activity } = {}) =>
Expand Down Expand Up @@ -332,7 +332,7 @@ module.exports = async (api, args = {}, { pluginSource, activity } = {}) =>
return null
}

let pluginName =
const pluginName =
plugin.name === `default-site-plugin` ? `gatsby-node.js` : plugin.name

return new Promise(resolve => {
Expand All @@ -342,7 +342,7 @@ module.exports = async (api, args = {}, { pluginSource, activity } = {}) =>
pluginName: `${plugin.name}@${plugin.version}`,
})

let localReporter = getLocalReporter(activity, reporter)
const localReporter = getLocalReporter(activity, reporter)

const file = stackTrace
.parse(err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const trimSlashes = part => part.replace(/(^\/)|(\/$)/g, ``)
const trimSlashes = (part: string): string => part.replace(/(^\/)|(\/$)/g, ``)

const isURL = possibleUrl =>
const isURL = (possibleUrl: string): boolean =>
[`http://`, `https://`, `//`].some(expr => possibleUrl.startsWith(expr))

module.exports = function getPublicPath({
export const getPublicPath = ({
assetPrefix,
pathPrefix,
prefixPaths,
}) {
}: {
assetPrefix?: string
pathPrefix?: string
prefixPaths: boolean
}): string => {
if (prefixPaths && (assetPrefix || pathPrefix)) {
const normalized = [assetPrefix, pathPrefix]
.filter(part => part && part.length > 0)
.filter((part): part is string => (part ? part.length > 0 : false))
.map(part => trimSlashes(part))
.join(`/`)

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const dotenv = require(`dotenv`)
const PnpWebpackPlugin = require(`pnp-webpack-plugin`)
const { store } = require(`../redux`)
const { actions } = require(`../redux/actions`)
const getPublicPath = require(`./get-public-path`)
const { getPublicPath } = require(`./get-public-path`)
const debug = require(`debug`)(`gatsby:webpack-config`)
const report = require(`gatsby-cli/lib/reporter`)
const { withBasePath, withTrailingSlash } = require(`./path`)
Expand Down

0 comments on commit fe04b8e

Please sign in to comment.