Skip to content

Commit

Permalink
fix(configuration): improvements to TypeScript configuration
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed Aug 16, 2024
1 parent 4496b36 commit 6314a37
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
9 changes: 1 addition & 8 deletions configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,8 @@ export const configureTsConfig = () => {
// Ignored
}

// Base package in our setup is ESM, type: module.
if (typeof configuration.compilerOptions.module === 'undefined') {
configuration.compilerOptions.module = 'NodeNext'
}

// Avoid the need to add (.js) file endings (already handled by Metro bundler).
// Currently set to NodeNext in official React Native TypeScript Configuration.
if (typeof configuration.compilerOptions.moduleResolution === 'undefined') {
configuration.compilerOptions.moduleResolution = 'node'
configuration.compilerOptions.module = 'ESNext' // RN default is ES2015??
}

writeFileSync(tsconfigPath, JSON.stringify(configuration, null, 2))
Expand Down
4 changes: 2 additions & 2 deletions template/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
},
"devDependencies": {
"@testing-library/jest-native": "^5.4.3",
"@testing-library/react-native": "^12.5.3",
"@testing-library/react-native": "^12.6.0",
"@types/jest": "^29.5.12",
"@types/react": "^18.3.3",
"@types/react-native": "^0.73.0",
"android-sdk-numic-plugin": "^1.0.5",
"babel-jest": "^29.7.0",
"icon-numic-plugin": "^1.4.4",
"jest": "^29.7.0",
"numic": "^2.3.0",
"numic": "^2.4.1",
"react-test-renderer": "^18.3.1",
"typescript": "^5.5.4"
},
Expand Down
2 changes: 1 addition & 1 deletion template/app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "@react-native/typescript-config/tsconfig.json",
"compilerOptions": {
"strict": false,
"module": "ESNext"
}
}

2 changes: 1 addition & 1 deletion template/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"babel-jest": "^29.7.0",
"icon-numic-plugin": "^1.4.4",
"jest": "^29.7.0",
"numic": "^2.3.0",
"numic": "^2.4.1",
"react-test-renderer": "18.2.0",
"typescript": "^5.5.4"
},
Expand Down
6 changes: 3 additions & 3 deletions test/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ test('Extended tsconfig properties are removed.', async () => {
// Always extend RN template config.
expect(tsconfigContents.extends).toBe('@react-native/typescript-config/tsconfig.json')
// Always added.
expect(tsconfigContents.compilerOptions.module).toBe('NodeNext')
expect(tsconfigContents.compilerOptions.moduleResolution).toBe('node')
expect(tsconfigContents.compilerOptions.module).toBe('ESNext')
expect(tsconfigContents.compilerOptions.moduleResolution).toBe(undefined)
expect(tsconfigContents.compilerOptions.skipLibCheck).toBe(true)
// Extended excludes removed.
expect(tsconfigContents.exclude).toEqual(['node_modules', 'my-stuff'])
Expand Down Expand Up @@ -309,7 +309,7 @@ test('tsconfig from package.json is merged in.', async () => {
expect(tsconfigContents.extends).toBe('@react-native/typescript-config/tsconfig.json')
// Always added.
expect(tsconfigContents.compilerOptions.skipLibCheck).toBe(false)
expect(tsconfigContents.compilerOptions.moduleResolution).toBe('node')
expect(tsconfigContents.compilerOptions.moduleResolution).toBe(undefined)
expect(tsconfigContents.include).toEqual(['global.d.ts'])
expect(tsconfigContents.compilerOptions.module).toBe('esm')
})
Expand Down

0 comments on commit 6314a37

Please sign in to comment.