Skip to content

Commit

Permalink
feat(gatsby-core-utils): add url resolve (#15510)
Browse files Browse the repository at this point in the history
* rename gatsby-utils folder

* feat(gatsby-core-utils): add url resolve

* fix repo field
  • Loading branch information
wardpeet authored and GatsbyJS Bot committed Jul 12, 2019
1 parent 94345ea commit 1dbe332
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 5 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -7,7 +7,7 @@
export declare function createContentDigest(input: any): string

/**
* Joins all given path segments together using a forward slash (/) as a delimiter
* Joins all given path segments and converts
* @param {string[]} paths A sequence of path segments
*/
export declare function joinPath(...paths: string[]): string
Expand All @@ -19,3 +19,9 @@ export declare function joinPath(...paths: string[]): string
* @return {number} Count of the requested type of CPU cores. Defaults to number of physical cores or 1
*/
export declare function cpuCoreCount(ignoreEnvVar?: boolean): number

/**
* Joins all given segments and converts using a forward slash (/) as a delimiter
* @param {string[]} segments A sequence of segments
*/
export declare function urlResolve(...segments: string[]): string
Expand Up @@ -7,13 +7,13 @@
"gatsby-core-utils"
],
"author": "Ward Peeters <ward@coding-tech.com>",
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-utils#readme",
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-core-utils#readme",
"license": "MIT",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby.git",
"directory": "packages/gatsby-utils"
"directory": "packages/gatsby-core-utils"
},
"scripts": {
"build": "babel src --out-dir dist/ --ignore **/__tests__",
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions packages/gatsby-core-utils/src/__tests__/url.js
@@ -0,0 +1,11 @@
const { resolve } = require(`../url`)

describe(`url`, () => {
describe(`resolve`, () => {
it(`resolves segments into valid url pathname`, () => {
const paths = [`/`, ``, `./foo`, `bar`, `baz`]
const actual = resolve(...paths)
expect(actual).toBe(`/foo/bar/baz`)
})
})
})
File renamed without changes.
@@ -1,3 +1,4 @@
exports.createContentDigest = require(`./create-content-digest`)
exports.joinPath = require(`./path`).joinPath
exports.cpuCoreCount = require(`./cpu-core-count`)
exports.urlResolve = require(`./url`).resolve
Expand Up @@ -8,7 +8,7 @@ export function joinPath(...paths) {
const joinedPath = path.join(...paths)
if (os.platform() === `win32`) {
return joinedPath.replace(/\\/g, `\\\\`)
} else {
return joinedPath
}

return joinedPath
}
14 changes: 14 additions & 0 deletions packages/gatsby-core-utils/src/url.js
@@ -0,0 +1,14 @@
const path = require(`path`)
const os = require(`os`)

/**
* @type {import('../index').urlResolve}
*/
export function resolve(...segments) {
const joinedPath = path.join(...segments)
if (os.platform() === `win32`) {
return joinedPath.replace(/\\/g, `/`)
}

return joinedPath
}

0 comments on commit 1dbe332

Please sign in to comment.