Skip to content

Commit

Permalink
chore(gatsby): migrate test-require-error to typescript (#22265)
Browse files Browse the repository at this point in the history
* chore(gatsby): migrate test-require-error to typescript

* fix test

* fix pointed out
  • Loading branch information
sasurau4 committed Mar 19, 2020
1 parent 7d73604 commit 0700cd5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/gatsby/src/bootstrap/get-config-file.js
@@ -1,7 +1,7 @@
/* @flow */
const levenshtein = require(`fast-levenshtein`)
const fs = require(`fs-extra`)
const testRequireError = require(`../utils/test-require-error`).default
import { testRequireError } from "../utils/test-require-error"
const report = require(`gatsby-cli/lib/reporter`)
const path = require(`path`)
const existsSync = require(`fs-exists-cached`).sync
Expand All @@ -20,7 +20,8 @@ module.exports = async function getConfigFile(
distance: number = 3
) {
const configPath = path.join(rootDir, configName)
let configModule, configFilePath
let configModule
let configFilePath
try {
configFilePath = require.resolve(configPath)
configModule = require(configFilePath)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/resolve-module-exports.js
Expand Up @@ -6,7 +6,7 @@ const { codeFrameColumns } = require(`@babel/code-frame`)
const { babelParseToAst } = require(`../utils/babel-parse-to-ast`)
const report = require(`gatsby-cli/lib/reporter`)

const testRequireError = require(`../utils/test-require-error`).default
import { testRequireError } from "../utils/test-require-error"

const staticallyAnalyzeExports = (modulePath, resolver = require.resolve) => {
let absPath
Expand Down
@@ -1,4 +1,4 @@
const testRequireError = require(`../test-require-error`).default
import { testRequireError } from "../test-require-error"

describe(`test-require-error`, () => {
it(`detects require errors`, () => {
Expand Down
@@ -1,6 +1,6 @@
// This module is also copied into the .cache directory some modules copied there
// from cache-dir can also use this module.
export default (moduleName, err) => {
export const testRequireError = (moduleName: string, err: any): boolean => {
// PnP will return the following code when a require is allowed per the
// dependency tree rules but the requested file doesn't exist
if (
Expand Down

0 comments on commit 0700cd5

Please sign in to comment.