From 597c1ecb230745dfa89a8478917f3a7d8fa398ed Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Wed, 12 Dec 2018 09:43:37 +1300 Subject: [PATCH 1/3] TypeScript detection filtering 'node_modules'. See #5947 --- packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js index d8da57a3509..e6bd184a5d7 100644 --- a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js +++ b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js @@ -22,7 +22,7 @@ function writeJson(fileName, object) { } function verifyNoTypeScript() { - const typescriptFiles = globby('**/*.(ts|tsx)', { cwd: paths.appSrc }); + const typescriptFiles = globby(['**/*.(ts|tsx)', '!**/node_modules'], { cwd: paths.appSrc }); if (typescriptFiles.length > 0) { console.warn( chalk.yellow( From 741e9aa9e62c6d890e25bf3c65e30ff43984556d Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Mon, 14 Jan 2019 15:08:18 +1300 Subject: [PATCH 2/3] Tests for ignoring node_modules when detecting TypeScript --- .../issue-5947-not-typescript/index.test.js | 35 +++++++++++++++++++ .../issue-5947-not-typescript/package.json | 3 ++ .../issue-5947-not-typescript/src/index.js | 0 3 files changed, 38 insertions(+) create mode 100644 test/fixtures/issue-5947-not-typescript/index.test.js create mode 100644 test/fixtures/issue-5947-not-typescript/package.json create mode 100644 test/fixtures/issue-5947-not-typescript/src/index.js diff --git a/test/fixtures/issue-5947-not-typescript/index.test.js b/test/fixtures/issue-5947-not-typescript/index.test.js new file mode 100644 index 00000000000..ad77fa71d18 --- /dev/null +++ b/test/fixtures/issue-5947-not-typescript/index.test.js @@ -0,0 +1,35 @@ +const testSetup = require('../__shared__/test-setup'); +const path = require('path'); +const fs = require('fs'); + +test('Ignores node_modules when detecting TypeScript', async () => { + // CRA build will check for TypeScript files by + // globbing for src/**/*.ts however this shouldn't + // include any node_modules directories within src. + // See https://github.com/facebook/create-react-app/issues/5947 + + const tsConfigPath = path.join(testSetup.testDirectory, 'tsconfig.json'); + const tsPackagePath = [ + testSetup.testDirectory, + 'src', + 'node_modules', + 'package', + 'index.ts', + ]; + const tsSrcPath = path.join(testSetup.testDirectory, 'src', 'index.ts'); + + // Step 1. + // See if src/node_modules/package/index.ts is treated + // as a JS project + fs.mkdirSync(path.join(...tsPackagePath.slice(0, 3))); + fs.mkdirSync(path.join(...tsPackagePath.slice(0, 4))); + fs.writeFileSync(path.join(...tsPackagePath)); + await testSetup.scripts.build(); + expect(fs.existsSync(tsConfigPath)).toBe(false); + + // Step 2. + // Add TS and ensure tsconfig.json is generated + fs.writeFileSync(tsSrcPath); + await testSetup.scripts.build(); + expect(fs.existsSync(tsConfigPath)).toBe(true); +}); diff --git a/test/fixtures/issue-5947-not-typescript/package.json b/test/fixtures/issue-5947-not-typescript/package.json new file mode 100644 index 00000000000..18a1e415e56 --- /dev/null +++ b/test/fixtures/issue-5947-not-typescript/package.json @@ -0,0 +1,3 @@ +{ + "dependencies": {} +} diff --git a/test/fixtures/issue-5947-not-typescript/src/index.js b/test/fixtures/issue-5947-not-typescript/src/index.js new file mode 100644 index 00000000000..e69de29bb2d From fc75002ca3746a61b1e7d28c89ea47bf4245640c Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Mon, 14 Jan 2019 23:18:58 +1300 Subject: [PATCH 3/3] Removing empty src/index.js file, changing test to suit --- test/fixtures/issue-5947-not-typescript/index.test.js | 1 + test/fixtures/issue-5947-not-typescript/src/index.js | 0 2 files changed, 1 insertion(+) delete mode 100644 test/fixtures/issue-5947-not-typescript/src/index.js diff --git a/test/fixtures/issue-5947-not-typescript/index.test.js b/test/fixtures/issue-5947-not-typescript/index.test.js index ad77fa71d18..c0d38261f6f 100644 --- a/test/fixtures/issue-5947-not-typescript/index.test.js +++ b/test/fixtures/issue-5947-not-typescript/index.test.js @@ -21,6 +21,7 @@ test('Ignores node_modules when detecting TypeScript', async () => { // Step 1. // See if src/node_modules/package/index.ts is treated // as a JS project + fs.mkdirSync(path.join(...tsPackagePath.slice(0, 2))); fs.mkdirSync(path.join(...tsPackagePath.slice(0, 3))); fs.mkdirSync(path.join(...tsPackagePath.slice(0, 4))); fs.writeFileSync(path.join(...tsPackagePath)); diff --git a/test/fixtures/issue-5947-not-typescript/src/index.js b/test/fixtures/issue-5947-not-typescript/src/index.js deleted file mode 100644 index e69de29bb2d..00000000000