Skip to content

Commit fd38277

Browse files
Matthew Hollowaymrmckeb
Matthew Holloway
authored andcommitted
Ignore node_modules in verifyNoTypeScript (#6022)
1 parent 47e9e2c commit fd38277

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function writeJson(fileName, object) {
2222
}
2323

2424
function verifyNoTypeScript() {
25-
const typescriptFiles = globby('**/*.(ts|tsx)', { cwd: paths.appSrc });
25+
const typescriptFiles = globby(['**/*.(ts|tsx)', '!**/node_modules'], { cwd: paths.appSrc });
2626
if (typescriptFiles.length > 0) {
2727
console.warn(
2828
chalk.yellow(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const testSetup = require('../__shared__/test-setup');
2+
const path = require('path');
3+
const fs = require('fs');
4+
5+
test('Ignores node_modules when detecting TypeScript', async () => {
6+
// CRA build will check for TypeScript files by
7+
// globbing for src/**/*.ts however this shouldn't
8+
// include any node_modules directories within src.
9+
// See https://github.com/facebook/create-react-app/issues/5947
10+
11+
const tsConfigPath = path.join(testSetup.testDirectory, 'tsconfig.json');
12+
const tsPackagePath = [
13+
testSetup.testDirectory,
14+
'src',
15+
'node_modules',
16+
'package',
17+
'index.ts',
18+
];
19+
const tsSrcPath = path.join(testSetup.testDirectory, 'src', 'index.ts');
20+
21+
// Step 1.
22+
// See if src/node_modules/package/index.ts is treated
23+
// as a JS project
24+
fs.mkdirSync(path.join(...tsPackagePath.slice(0, 2)));
25+
fs.mkdirSync(path.join(...tsPackagePath.slice(0, 3)));
26+
fs.mkdirSync(path.join(...tsPackagePath.slice(0, 4)));
27+
fs.writeFileSync(path.join(...tsPackagePath));
28+
await testSetup.scripts.build();
29+
expect(fs.existsSync(tsConfigPath)).toBe(false);
30+
31+
// Step 2.
32+
// Add TS and ensure tsconfig.json is generated
33+
fs.writeFileSync(tsSrcPath);
34+
await testSetup.scripts.build();
35+
expect(fs.existsSync(tsConfigPath)).toBe(true);
36+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dependencies": {}
3+
}

0 commit comments

Comments
 (0)