Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): Convert utils/browserslist to typescript #22089

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Promise = require(`bluebird`)
const telemetry = require(`gatsby-telemetry`)

const apiRunnerNode = require(`../utils/api-runner-node`)
const getBrowserslist = require(`../utils/browserslist`)
import { getBrowsersList } from "../utils/browserslist"
const { store, emitter } = require(`../redux`)
const loadPlugins = require(`./load-plugins`)
const loadThemes = require(`./load-themes`)
Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = async (args: BootstrapArgs) => {

const program = {
...args,
browserslist: getBrowserslist(directory),
browserslist: getBrowsersList(directory),
// Fix program directory path for windows env.
directory,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/__tests__/browserslist.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jest.mock(`browserslist/node`, () => {
}
})
const path = require(`path`)
const getBrowsersList = require(`../browserslist`)
import { getBrowsersList } from "../browserslist"
const { findConfig: mockedFindConfig } = require(`browserslist/node`)

const BASE = path.resolve(`.`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const path = require(`path`)
const browserslist = require(`browserslist/node`)
import path from "path"
import browserslist from "browserslist/node"

function installedGatsbyVersion(directory) {
const installedGatsbyVersion = (directory: string): number | undefined => {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require(path.join(
directory,
`node_modules`,
Expand All @@ -15,7 +16,7 @@ function installedGatsbyVersion(directory) {
}
}

module.exports = function getBrowsersList(directory) {
export const getBrowsersList = (directory: string): string[] => {
const fallback =
installedGatsbyVersion(directory) === 1
? [`>1%`, `last 2 versions`, `IE >= 9`]
Expand Down