From 85f754d1234818f9edf4fbf54edf10ee54fb556c Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Sat, 14 Mar 2020 17:59:02 +0900 Subject: [PATCH 1/3] chore(gatsby): migrate test-require-error to typescript --- packages/gatsby/src/bootstrap/get-config-file.js | 5 +++-- packages/gatsby/src/bootstrap/index.js | 4 ++-- packages/gatsby/src/bootstrap/resolve-module-exports.js | 2 +- .../{test-require-error.js => test-require-error.ts} | 2 +- .../utils/{test-require-error.js => test-require-error.ts} | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) rename packages/gatsby/src/utils/__tests__/{test-require-error.js => test-require-error.ts} (98%) rename packages/gatsby/src/utils/{test-require-error.js => test-require-error.ts} (90%) diff --git a/packages/gatsby/src/bootstrap/get-config-file.js b/packages/gatsby/src/bootstrap/get-config-file.js index eabc24e26c837..dc99ccc5d0b82 100644 --- a/packages/gatsby/src/bootstrap/get-config-file.js +++ b/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 @@ -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) diff --git a/packages/gatsby/src/bootstrap/index.js b/packages/gatsby/src/bootstrap/index.js index a32983bce70ab..a08c9d231c81b 100644 --- a/packages/gatsby/src/bootstrap/index.js +++ b/packages/gatsby/src/bootstrap/index.js @@ -310,12 +310,12 @@ module.exports = async (args: BootstrapArgs) => { activity.start() const srcDir = `${__dirname}/../../cache-dir` const siteDir = cacheDirectory - const tryRequire = `${__dirname}/../utils/test-require-error.js` + const tryRequire = `${__dirname}/../utils/test-require-error.ts` try { await fs.copy(srcDir, siteDir, { clobber: true, }) - await fs.copy(tryRequire, `${siteDir}/test-require-error.js`, { + await fs.copy(tryRequire, `${siteDir}/test-require-error.ts`, { clobber: true, }) await fs.ensureDirSync(`${cacheDirectory}/json`) diff --git a/packages/gatsby/src/bootstrap/resolve-module-exports.js b/packages/gatsby/src/bootstrap/resolve-module-exports.js index 0fbc9ffdd0b29..6ad756dde6fc9 100644 --- a/packages/gatsby/src/bootstrap/resolve-module-exports.js +++ b/packages/gatsby/src/bootstrap/resolve-module-exports.js @@ -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 diff --git a/packages/gatsby/src/utils/__tests__/test-require-error.js b/packages/gatsby/src/utils/__tests__/test-require-error.ts similarity index 98% rename from packages/gatsby/src/utils/__tests__/test-require-error.js rename to packages/gatsby/src/utils/__tests__/test-require-error.ts index c243f69167ad2..3f7f195f3f086 100644 --- a/packages/gatsby/src/utils/__tests__/test-require-error.js +++ b/packages/gatsby/src/utils/__tests__/test-require-error.ts @@ -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`, () => { diff --git a/packages/gatsby/src/utils/test-require-error.js b/packages/gatsby/src/utils/test-require-error.ts similarity index 90% rename from packages/gatsby/src/utils/test-require-error.js rename to packages/gatsby/src/utils/test-require-error.ts index 56fdb35187ad6..62b603727d017 100644 --- a/packages/gatsby/src/utils/test-require-error.js +++ b/packages/gatsby/src/utils/test-require-error.ts @@ -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, err): 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 ( From e8cb206f8bacecd152f77468d9f5750b5b85b62e Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Sat, 14 Mar 2020 18:44:07 +0900 Subject: [PATCH 2/3] fix test --- packages/gatsby/src/bootstrap/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/bootstrap/index.js b/packages/gatsby/src/bootstrap/index.js index a08c9d231c81b..a32983bce70ab 100644 --- a/packages/gatsby/src/bootstrap/index.js +++ b/packages/gatsby/src/bootstrap/index.js @@ -310,12 +310,12 @@ module.exports = async (args: BootstrapArgs) => { activity.start() const srcDir = `${__dirname}/../../cache-dir` const siteDir = cacheDirectory - const tryRequire = `${__dirname}/../utils/test-require-error.ts` + const tryRequire = `${__dirname}/../utils/test-require-error.js` try { await fs.copy(srcDir, siteDir, { clobber: true, }) - await fs.copy(tryRequire, `${siteDir}/test-require-error.ts`, { + await fs.copy(tryRequire, `${siteDir}/test-require-error.js`, { clobber: true, }) await fs.ensureDirSync(`${cacheDirectory}/json`) From fedcb8480c88a22d5199e2ed85118ea03872100f Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Thu, 19 Mar 2020 21:47:59 +0900 Subject: [PATCH 3/3] fix pointed out --- packages/gatsby/src/utils/test-require-error.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/utils/test-require-error.ts b/packages/gatsby/src/utils/test-require-error.ts index 62b603727d017..ea3cf0463a492 100644 --- a/packages/gatsby/src/utils/test-require-error.ts +++ b/packages/gatsby/src/utils/test-require-error.ts @@ -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 const testRequireError = (moduleName, err): boolean => { +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 (