Skip to content

Commit

Permalink
chore(gatsby): Convert utils/path to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
kawamataryo committed Mar 10, 2020
1 parent 1aa2974 commit 9fec258
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require(`fs-extra`)

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

exports.onPreBootstrap = async ({ store, parentSpan }) => {
const { directory, browserslist } = store.getState().program
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { joinPath } = require(`gatsby-core-utils`)
const { withBasePath, getCommonDir } = require(`../path`)
const os = require(`os`)
import { joinPath } from "gatsby-core-utils"
import { withBasePath, getCommonDir } from "../path"
import os from "os"

describe(`paths`, () => {
describe(`joinPath`, () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ describe(`paths`, () => {
})

describe(`getCommonDir`, () => {
it.each([
it.each<[string, { path1: string; path2: string; expected: string }]>([
[
`posix: path2 is sub-path of path1`,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
const path = require(`path`)
const { joinPath } = require(`gatsby-core-utils`)
import path from "path"
import { joinPath } from "gatsby-core-utils"

export function withBasePath(basePath) {
return (...paths) => joinPath(basePath, ...paths)
}
export const withBasePath = (basePath: string) => (
...paths: string[]
): string => joinPath(basePath, ...paths)

export function withTrailingSlash(basePath) {
return `${basePath}/`
}
export const withTrailingSlash = (basePath: string): string => `${basePath}/`

const posixJoinWithLeadingSlash = paths =>
const posixJoinWithLeadingSlash = (paths: string[]): string =>
path.posix.join(
...paths.map((segment, index) =>
segment === `` && index === 0 ? `/` : segment
)
)

export function getCommonDir(path1, path2) {
export const getCommonDir = (path1: string, path2: string): string => {
const path1Segments = path1.split(/[/\\]/)
const path2Segments = path2.split(/[/\\]/)

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 @@ -9,7 +9,7 @@ const { actions } = require(`../redux/actions`)
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`)
import { withBasePath, withTrailingSlash } from "./path"
const getGatsbyDependents = require(`./gatsby-dependents`)

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

0 comments on commit 9fec258

Please sign in to comment.