Skip to content

Commit 2123158

Browse files
authoredMar 10, 2020
chore(gatsby): Convert utils/path to typescript (#22130)
1 parent 623a769 commit 2123158

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed
 

‎packages/gatsby/src/internal-plugins/load-babel-config/gatsby-node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const fs = require(`fs-extra`)
44

55
const apiRunnerNode = require(`../../utils/api-runner-node`)
6-
const { withBasePath } = require(`../../utils/path`)
6+
import { withBasePath } from "../../utils/path"
77

88
exports.onPreBootstrap = async ({ store, parentSpan }) => {
99
const { directory, browserslist } = store.getState().program

‎packages/gatsby/src/utils/__tests__/path.js ‎packages/gatsby/src/utils/__tests__/path.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { joinPath } = require(`gatsby-core-utils`)
2-
const { withBasePath, getCommonDir } = require(`../path`)
3-
const os = require(`os`)
1+
import { joinPath } from "gatsby-core-utils"
2+
import { withBasePath, getCommonDir } from "../path"
3+
import os from "os"
44

55
describe(`paths`, () => {
66
describe(`joinPath`, () => {
@@ -55,7 +55,7 @@ describe(`paths`, () => {
5555
})
5656

5757
describe(`getCommonDir`, () => {
58-
it.each([
58+
it.each<[string, { path1: string; path2: string; expected: string }]>([
5959
[
6060
`posix: path2 is sub-path of path1`,
6161
{

‎packages/gatsby/src/utils/path.js ‎packages/gatsby/src/utils/path.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
const path = require(`path`)
2-
const { joinPath } = require(`gatsby-core-utils`)
1+
import path from "path"
2+
import { joinPath } from "gatsby-core-utils"
33

4-
export function withBasePath(basePath) {
5-
return (...paths) => joinPath(basePath, ...paths)
6-
}
4+
export const withBasePath = (basePath: string) => (
5+
...paths: string[]
6+
): string => joinPath(basePath, ...paths)
77

8-
export function withTrailingSlash(basePath) {
9-
return `${basePath}/`
10-
}
8+
export const withTrailingSlash = (basePath: string): string => `${basePath}/`
119

12-
const posixJoinWithLeadingSlash = paths =>
10+
const posixJoinWithLeadingSlash = (paths: string[]): string =>
1311
path.posix.join(
1412
...paths.map((segment, index) =>
1513
segment === `` && index === 0 ? `/` : segment
1614
)
1715
)
1816

19-
export function getCommonDir(path1, path2) {
17+
export const getCommonDir = (path1: string, path2: string): string => {
2018
const path1Segments = path1.split(/[/\\]/)
2119
const path2Segments = path2.split(/[/\\]/)
2220

‎packages/gatsby/src/utils/webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { actions } = require(`../redux/actions`)
99
const { getPublicPath } = require(`./get-public-path`)
1010
const debug = require(`debug`)(`gatsby:webpack-config`)
1111
const report = require(`gatsby-cli/lib/reporter`)
12-
const { withBasePath, withTrailingSlash } = require(`./path`)
12+
import { withBasePath, withTrailingSlash } from "./path"
1313
const getGatsbyDependents = require(`./gatsby-dependents`)
1414

1515
const apiRunnerNode = require(`./api-runner-node`)

0 commit comments

Comments
 (0)
Please sign in to comment.