From fe722c076e5dbad145963aa8a0254391955e21bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viliam=20Kopeck=C3=BD?= Date: Thu, 30 Nov 2017 03:44:44 +0100 Subject: [PATCH] Prevent type declaration files to generate pages (#3076) --- .../__tests__/gatsby-node.js | 19 +++++++++++++++++++ .../component-page-creator/validate-path.js | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/src/internal-plugins/component-page-creator/__tests__/gatsby-node.js b/packages/gatsby/src/internal-plugins/component-page-creator/__tests__/gatsby-node.js index 5c7b78beee1ef..e06da2fff6673 100644 --- a/packages/gatsby/src/internal-plugins/component-page-creator/__tests__/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/component-page-creator/__tests__/gatsby-node.js @@ -34,6 +34,25 @@ describe(`JavaScript page creator`, () => { expect(files.filter(file => validatePath(file.path)).length).toEqual(1) }) + it(`filters out files that have TypeScript declaration extensions`, () => { + const files = [ + { + path: `something/foo.ts`, + }, + { + path: `something/bar.tsx`, + }, + { + path: `something/declaration-file.d.ts`, + }, + { + path: `something-else/other-declaration-file.d.tsx`, + }, + ] + + expect(files.filter(file => validatePath(file.path)).length).toEqual(2) + }) + describe(`create-path`, () => { it(`should create unix paths`, () => { const basePath = `/a/` diff --git a/packages/gatsby/src/internal-plugins/component-page-creator/validate-path.js b/packages/gatsby/src/internal-plugins/component-page-creator/validate-path.js index e250926022430..89f70ed54a004 100644 --- a/packages/gatsby/src/internal-plugins/component-page-creator/validate-path.js +++ b/packages/gatsby/src/internal-plugins/component-page-creator/validate-path.js @@ -1,11 +1,15 @@ const systemPath = require(`path`) +const tsDeclarationExtTest = /\.d\.tsx?$/ + module.exports = path => { // Disallow paths starting with an underscore // and template-. + // and .d.ts const parsedPath = systemPath.parse(path) return ( parsedPath.name.slice(0, 1) !== `_` && - parsedPath.name.slice(0, 9) !== `template-` + parsedPath.name.slice(0, 9) !== `template-` && + !tsDeclarationExtTest.test(parsedPath.base) ) }