Skip to content

Commit 8f8e1e1

Browse files
committed
rn-cli.config.js is created upon ejection
1 parent 1089441 commit 8f8e1e1

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
lines changed

react-native-scripts/package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,25 @@
6565
"node_modules/(?!((jest-)?react-native|react-clone-referenced-element|expo(nent)?|@expo(nent)?/.*|react-navigation))"
6666
],
6767
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
68-
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "android.ts", "android.tsx"]
68+
"moduleFileExtensions": [
69+
"ts",
70+
"tsx",
71+
"js",
72+
"jsx",
73+
"json",
74+
"android.ts",
75+
"android.tsx"
76+
]
6977
},
7078
"babel": {
71-
"presets": ["babel-preset-expo"],
79+
"presets": [
80+
"babel-preset-expo"
81+
],
7282
"env": {
7383
"development": {
74-
"plugins": ["transform-react-jsx-source"]
84+
"plugins": [
85+
"transform-react-jsx-source"
86+
]
7587
}
7688
}
7789
}

react-native-scripts/src/scripts/eject.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import rimraf from 'rimraf';
99
import spawn from 'cross-spawn';
1010
import log from '../util/log';
1111
import { hasYarn } from '../util/pm';
12+
import { createRnCliConfig } from '../util/typescript';
1213

1314
import { detach } from '../util/expo';
1415

@@ -256,6 +257,8 @@ Android Studio to build the native code for your project.`
256257
});
257258
}
258259
}
260+
261+
await createRnCliConfig();
259262
} else if (ejectMethod === 'expoKit') {
260263
await detach();
261264
} else {

react-native-scripts/src/scripts/init.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const DEFAULT_DEV_DEPENDENCIES = {
3535
'jest-expo': '~27.0.0',
3636
'react-native-typescript-transformer': '^1.2.3',
3737
'react-test-renderer': '16.3.1',
38-
'tslib': '^1.9.1',
39-
'typescript': '^2.8.3',
38+
tslib: '^1.9.1',
39+
typescript: '^2.8.3',
4040
};
4141

4242
const WEB_DEFAULT_DEV_DEPENDENCIES = {
@@ -122,19 +122,9 @@ We recommend using npm >= 5.7.0 or yarn.
122122
useBabelrc: true,
123123
},
124124
},
125-
moduleFileExtensions: [
126-
'ts',
127-
'tsx',
128-
'js',
129-
'jsx',
130-
'json',
131-
'node',
132-
],
125+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
133126
preset: 'jest-expo',
134-
testMatch: [
135-
'**/__tests__/**/*.[tj]s?(x)',
136-
'**/?(*.)(spec|test).[tj]s?(x)',
137-
],
127+
testMatch: ['**/__tests__/**/*.[tj]s?(x)', '**/?(*.)(spec|test).[tj]s?(x)'],
138128
transform: {
139129
'^.+\\.tsx?$': 'ts-jest',
140130
},

react-native-scripts/src/scripts/start.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ async function printServerInfo() {
6868
emulatorHelp = `Press ${chalk.bold('a')} to start an Android emulator.`;
6969
}
7070
qr.generate(address, qrCode => {
71-
log(`
71+
log(
72+
`
7273
${indent(qrCode, 2)}
7374
7475
Your app is now running at URL: ${chalk.underline(chalk.cyan(address))}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import fse from 'fs-extra';
2+
import path from 'path';
3+
import log from './log';
4+
5+
/**
6+
* Creates a rn-cli.config.js file
7+
* It configures ts transpilation for ejected projects
8+
* @link https://github.com/Microsoft/TypeScript-React-Native-Starter#adding-typescript
9+
*/
10+
export async function createRnCliConfig() {
11+
log(
12+
`
13+
Creating a rn-cli.config.js file.
14+
It includes typescript transpilation config for react-native
15+
`
16+
);
17+
18+
const rnCliConfigContents = `module.exports = {
19+
getTransformModulePath() {
20+
return require.resolve("react-native-typescript-transformer");
21+
},
22+
getSourceExts() {
23+
return ["ts", "tsx"];
24+
}
25+
};
26+
`;
27+
await fse.writeFile(path.resolve('rn-cli.config.js'), rnCliConfigContents);
28+
}

0 commit comments

Comments
 (0)