Skip to content

Commit

Permalink
Ignore node_modules in verifyNoTypeScript (#6022)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Holloway authored and mrmckeb committed Jan 14, 2019
1 parent 47e9e2c commit fd38277
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
36 changes: 36 additions & 0 deletions test/fixtures/issue-5947-not-typescript/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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, 2)));
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);
});
3 changes: 3 additions & 0 deletions test/fixtures/issue-5947-not-typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dependencies": {}
}

0 comments on commit fd38277

Please sign in to comment.