1 line
21 KiB
Plaintext
1 line
21 KiB
Plaintext
{"version":3,"sources":["eject.js"],"names":["filesUsingExpoSdk","filesWithExpo","usingExpo","length","expoSdkWarning","bold","filename","cyan","yellow","italic","reactNativeOptionMessage","questions","type","name","message","default","choices","value","prompt","ejectMethod","exists","resolve","useYarn","npmOrYarn","JSON","readFile","appJson","parse","pkgJson","newName","newDisplayName","displayName","expName","expo","stripDashes","validate","s","indexOf","enteredName","enteredDisplayname","writeFile","green","ejectCommand","ejectArgs","sync","stdio","status","red","process","exit","newDevDependencies","projectBabelPath","projectBabelRc","toString","babelRcJson","presets","includes","map","preset","push","main","dependencies","devDependencies","scripts","start","ios","android","jest","eject","lolThatsSomeComplexCode","args","stdin","stderr","console","error","findJavaScriptProjectFilesInRoot","cwd","projectJsFiles","all","f","buf","i","contents","jsFileContents","filesUsingExpo","requires","findAll","sort","root","stat","stats","isFile","endsWith","isDirectory","readdir","children","join","jsFilesInChildren","concat","apply","ret","c","then","catch","e"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;sFAaA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAEgCA,mBAFhC;;AAAA;AAEUC,yBAFV;AAGUC,qBAHV,GAGsBD,cAAcE,MAAd,GAAuB,CAH7C;AAKQC,0BALR;;AAAA,iBAMQF,SANR;AAAA;AAAA;AAAA;;AAOME,6BAAoB,gBAAMC,IAAN,CAAW,UAAX,CAApB;;AAPN;AAAA;AAAA;AAAA;AAUM,wDAAqBJ,aAArB,qGAAoC;AAA3BK,sBAA2B;;AAClCF,uCAAuB,gBAAMG,IAAN,CAAWD,QAAX,CAAvB;AACD;;AAZP;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAcMF,qCACJ,gBAAMI,MAAN,CAAaH,IAAb,CAAkB,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;;AA+BDhC,QACGkC,IADH,CACQ,YAAM;AACV;AACA;AACAtD,UAAQC,IAAR,CAAa,CAAb;AACD,CALH,EAMGsD,KANH,CAMS,aAAK;AACV9B,UAAQC,KAAR,6BAAwC8B,CAAxC;AACAxD,UAAQC,IAAR,CAAa,CAAb;AACD,CATH","file":"eject.js","sourcesContent":["// @flow\n\nimport chalk from 'chalk';\nimport fse from 'fs-extra';\nimport inquirer from 'inquirer';\nimport matchRequire from 'match-require';\nimport path from 'path';\nimport rimraf from 'rimraf';\nimport spawn from 'cross-spawn';\nimport log from '../util/log';\n\nimport { detach } from '../util/expo';\n\nasync function eject() {\n try {\n const filesWithExpo = await filesUsingExpoSdk();\n const usingExpo = filesWithExpo.length > 0;\n\n let expoSdkWarning;\n if (usingExpo) {\n expoSdkWarning = `${chalk.bold('Warning!')} We found at least one file where your project imports the Expo SDK:\n`;\n\n for (let filename of filesWithExpo) {\n expoSdkWarning += ` ${chalk.cyan(filename)}\\n`;\n }\n\n expoSdkWarning += `\n${chalk.yellow.bold('If you choose the \"plain\" React Native option below, these imports will stop working.')}`;\n } else {\n expoSdkWarning = `\\\nWe didn't find any uses of the Expo SDK in your project, so you should be fine to eject to\n\"Plain\" React Native. (This check isn't very sophisticated, though.)`;\n }\n\n log(\n `\n${expoSdkWarning}\n\nWe ${chalk.italic('strongly')} recommend that you read this document before you proceed:\n ${chalk.cyan('https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md')}\n\nEjecting is permanent! Please be careful with your selection.\n`\n );\n\n let reactNativeOptionMessage = \"React Native: I'd like a regular React Native project.\";\n\n if (usingExpo) {\n reactNativeOptionMessage = chalk.italic(\n \"(WARNING: See above message for why this option may break your project's build)\\n \"\n ) + reactNativeOptionMessage;\n }\n\n const questions = [\n {\n type: 'list',\n name: 'ejectMethod',\n message: 'How would you like to eject from create-react-native-app?',\n default: usingExpo ? 'expoKit' : 'raw',\n choices: [\n {\n name: reactNativeOptionMessage,\n value: 'raw',\n },\n {\n name: \"ExpoKit: I'll create or log in with an Expo account to use React Native and the Expo SDK.\",\n value: 'expoKit',\n },\n {\n name: \"Cancel: I'll continue with my current project structure.\",\n value: 'cancel',\n },\n ],\n },\n ];\n\n const { ejectMethod } = await inquirer.prompt(questions);\n\n if (ejectMethod === 'raw') {\n const useYarn = await fse.exists(path.resolve('yarn.lock'));\n const npmOrYarn = useYarn ? 'yarn' : 'npm';\n const appJson = JSON.parse(await fse.readFile(path.resolve('app.json')));\n const pkgJson = JSON.parse(await fse.readFile(path.resolve('package.json')));\n let {\n name: newName,\n displayName: newDisplayName,\n expo: { name: expName },\n } = appJson;\n\n // we ask user to provide a project name (default is package name stripped of dashes)\n // but we want to infer some good default choices, especially if they've set them up in app.json\n if (!newName) {\n newName = stripDashes(pkgJson.name);\n }\n\n if (!newDisplayName && expName) {\n newDisplayName = expName;\n }\n\n log(\"We have a couple of questions to ask you about how you'd like to name your app:\");\n const { enteredName, enteredDisplayname } = await inquirer.prompt([\n {\n name: 'enteredDisplayname',\n message: \"What should your app appear as on a user's home screen?\",\n default: newDisplayName,\n validate: s => {\n return s.length > 0;\n },\n },\n {\n name: 'enteredName',\n message: 'What should your Android Studio and Xcode projects be called?',\n default: newName,\n validate: s => {\n return s.length > 0 && s.indexOf('-') === -1 && s.indexOf(' ') === -1;\n },\n },\n ]);\n\n appJson.name = enteredName;\n appJson.displayName = enteredDisplayname;\n\n log('Writing your selections to app.json...');\n // write the updated app.json file\n await fse.writeFile(path.resolve('app.json'), JSON.stringify(appJson, null, 2));\n log(chalk.green('Wrote to app.json, please update it manually in the future.'));\n\n const ejectCommand = 'node';\n const ejectArgs = [\n path.resolve('node_modules', 'react-native', 'local-cli', 'cli.js'),\n 'eject',\n ];\n\n const { status } = spawn.sync(ejectCommand, ejectArgs, {\n stdio: 'inherit',\n });\n\n if (status !== 0) {\n log(chalk.red(`Eject failed with exit code ${status}, see above output for any issues.`));\n log(chalk.yellow('You may want to delete the `ios` and/or `android` directories.'));\n process.exit(1);\n } else {\n log('Successfully copied template native code.');\n }\n\n const newDevDependencies = [];\n // Try to replace the Babel preset.\n try {\n const projectBabelPath = path.resolve('.babelrc');\n // If .babelrc doesn't exist, the app is using the default config and\n // editing the config is not necessary.\n if (await fse.exists(projectBabelPath)) {\n const projectBabelRc = (await fse.readFile(projectBabelPath)).toString();\n\n // We assume the .babelrc is valid JSON. If we can't parse it (e.g. if\n // it's JSON5) the error is caught and a message asking to change it\n // manually gets printed.\n const babelRcJson = JSON.parse(projectBabelRc);\n if (babelRcJson.presets && babelRcJson.presets.includes('babel-preset-expo')) {\n babelRcJson.presets = babelRcJson.presets.map(\n preset =>\n preset === 'babel-preset-expo'\n ? 'babel-preset-react-native-stage-0/decorator-support'\n : preset\n );\n await fse.writeFile(projectBabelPath, JSON.stringify(babelRcJson, null, 2));\n newDevDependencies.push('babel-preset-react-native-stage-0');\n log(\n chalk.green(\n `Babel preset changed to \\`babel-preset-react-native-stage-0/decorator-support\\`.`\n )\n );\n }\n }\n } catch (e) {\n log(\n chalk.yellow(\n `We had an issue preparing your .babelrc for ejection.\nIf you have a .babelrc in your project, make sure to change the preset\nfrom \\`babel-preset-expo\\` to \\`babel-preset-react-native-stage-0/decorator-support\\`.`\n )\n );\n log(chalk.red(e));\n }\n\n delete pkgJson.main;\n\n // NOTE: expo won't work after performing a raw eject, so we should delete this\n // it will be a better error message for the module to not be found than for whatever problems\n // missing native modules will cause\n delete pkgJson.dependencies.expo;\n delete pkgJson.devDependencies['react-native-scripts'];\n delete pkgJson.devDependencies['jest-expo'];\n\n pkgJson.scripts.start = 'react-native start';\n pkgJson.scripts.ios = 'react-native run-ios';\n pkgJson.scripts.android = 'react-native run-android';\n\n if (pkgJson.jest.preset === 'jest-expo') {\n pkgJson.jest.preset = 'react-native';\n newDevDependencies.push('jest-react-native');\n } else {\n log(`${chalk.bold('Warning')}: it looks like you've changed the Jest preset from jest-expo to ${pkgJson.jest.preset}. We recommend you make sure this Jest preset is compatible with ejected apps.`)\n }\n\n // no longer relevant to an ejected project (maybe build is?)\n delete pkgJson.scripts.eject;\n\n log(`Updating your ${npmOrYarn} scripts in package.json...`);\n\n await fse.writeFile(path.resolve('package.json'), JSON.stringify(pkgJson, null, 2));\n\n log(chalk.green('Your package.json is up to date!'));\n\n log(`Adding entry point...`);\n\n const lolThatsSomeComplexCode = `import { AppRegistry } from 'react-native';\nimport App from './App';\nAppRegistry.registerComponent('${newName}', () => App);\n`;\n\n await fse.writeFile(path.resolve('index.js'), lolThatsSomeComplexCode);\n\n log(chalk.green('Added new entry points!'));\n\n log(\n `\nNote that using \\`${npmOrYarn} start\\` will now require you to run Xcode and/or\nAndroid Studio to build the native code for your project.`\n );\n\n log('Removing node_modules...');\n rimraf.sync(path.resolve('node_modules'));\n if (useYarn) {\n log('Installing packages with yarn...');\n const args = newDevDependencies.length > 0 ? ['add', '--dev', ...newDevDependencies] : [];\n spawn.sync('yarnpkg', args, { stdio: 'inherit' });\n } else {\n // npm prints the whole package tree to stdout unless we ignore it.\n const stdio = [process.stdin, 'ignore', process.stderr];\n\n log('Installing existing packages with npm...');\n spawn.sync('npm', ['install'], { stdio });\n\n if (newDevDependencies.length > 0) {\n log('Installing new packages with npm...');\n spawn.sync('npm', ['install', '--save-dev', ...newDevDependencies], {\n stdio,\n });\n }\n }\n } else if (ejectMethod === 'expoKit') {\n await detach();\n } else {\n // we don't want to print the survey for cancellations\n log('OK! If you change your mind you can run this command again.');\n return;\n }\n\n log(\n `${chalk.green('Ejected successfully!')}\nPlease consider letting us know why you ejected in this survey:\n ${chalk.cyan('https://goo.gl/forms/iD6pl218r7fn9N0d2')}`\n );\n } catch (e) {\n console.error(chalk.red(`Error running eject: ${e}`));\n }\n}\n\nasync function filesUsingExpoSdk(): Promise<Array<string>> {\n const projectJsFiles = await findJavaScriptProjectFilesInRoot(process.cwd());\n\n const jsFileContents = (await Promise.all(\n projectJsFiles.map(f => fse.readFile(f))\n )).map((buf, i) => {\n return {\n filename: projectJsFiles[i],\n contents: buf.toString(),\n };\n });\n\n const filesUsingExpo = [];\n\n for (let { filename, contents } of jsFileContents) {\n const requires = matchRequire.findAll(contents);\n\n if (requires.includes('expo')) {\n filesUsingExpo.push(filename);\n }\n }\n\n filesUsingExpo.sort();\n\n return filesUsingExpo;\n}\n\nfunction stripDashes(s: string): string {\n let ret = '';\n\n for (let c of s) {\n if (c !== ' ' && c !== '-') {\n ret += c;\n }\n }\n\n return ret;\n}\n\nasync function findJavaScriptProjectFilesInRoot(root: string): Promise<Array<string>> {\n // ignore node_modules\n if (root.includes('node_modules')) {\n return [];\n }\n\n const stats = await fse.stat(root);\n\n if (stats.isFile()) {\n if (root.endsWith('.js')) {\n return [root];\n } else {\n return [];\n }\n } else if (stats.isDirectory()) {\n const children = await fse.readdir(root);\n\n // we want to do this concurrently in large project folders\n const jsFilesInChildren = await Promise.all(\n children.map(f => findJavaScriptProjectFilesInRoot(path.join(root, f)))\n );\n\n return [].concat.apply([], jsFilesInChildren);\n } else {\n // lol it's not a file or directory, we can't return a honey badger, 'cause it don't give a\n return [];\n }\n}\n\neject()\n .then(() => {\n // the expo local github auth server leaves a setTimeout for 5 minutes\n // so we need to explicitly exit (for now, this will be resolved in the nearish future)\n process.exit(0);\n })\n .catch(e => {\n console.error(`Problem running eject: ${e}`);\n process.exit(1);\n });\n"]} |