-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore node_modules in verifyNoTypeScript (#6022)
- Loading branch information
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dependencies": {} | ||
} |