Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript support or merge existing rn-cli.config.js #8

Closed
brunolemos opened this issue Aug 12, 2018 · 1 comment
Closed

TypeScript support or merge existing rn-cli.config.js #8

brunolemos opened this issue Aug 12, 2018 · 1 comment

Comments

@brunolemos
Copy link

brunolemos commented Aug 12, 2018

I have a custom rn-cli.config.js to use with TypeScript, it seems this is overriding it.

I'm getting this error:

error: bundling failed: Error: Unable to resolve module `./App.tsx` from `/Users/brunolemos/Projects/workspace/mobile/index.js`: The module `./App.tsx` could not be found from `/Users/brunolemos/Projects/workspace/mobile/index.js`. Indeed, none of these files exist:

  * `/Users/brunolemos/Projects/workspace/mobile/App.tsx(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`
  * `/Users/brunolemos/Projects/workspace/mobile/App.tsx/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`

So in my case I had to copy paste this comment and merge manually to get symlink working.

@brunolemos brunolemos changed the title Merge with existing rn-cli.config.js TypeScript support / or Merge with existing rn-cli.config.js Aug 12, 2018
@brunolemos brunolemos changed the title TypeScript support / or Merge with existing rn-cli.config.js TypeScript support or merge existing rn-cli.config.js Aug 12, 2018
@MrLoh
Copy link
Owner

MrLoh commented Aug 13, 2018

Sorry the usecase for this library is to be a drop in replacement for metro to accept symlinks but it cannot merge a custom rn-cli.config.js. If you need more customization, than you should just build your own script. This library could help you to kickstart a custom rn-cli.config.js or you could use it's source code to build your own.

I have the following config in a project of mine that needed more customization. Maybe that is usefull for you too, if you need some inspiration.

const fs = require('fs');
const path = require('path');
const blacklist = require('metro/src/blacklist');

const linkedDependenciesPaths = fs
	.readdirSync('./node_modules')
	// check if module is symlinked
	.filter((dep) => fs.lstatSync(`node_modules/${dep}`).isSymbolicLink())
	// return path of linked module
	.map((dep) => fs.realpathSync(`node_modules/${dep}`));

const projectRoots = [
	// Include current packaage and workspace root
	path.resolve(__dirname),
	path.resolve(__dirname, '../node_modules/'),
	// Include symlinked packages roots
	...linkedDependenciesPaths.map((depPath) => path.resolve(__dirname, depPath)),
];

const extraNodeModules = Object.assign(
	...linkedDependenciesPaths
		.map((depPath) => require(`${depPath}/package.json`).peerDependencies)
		.map((peerDep) => (peerDep ? Object.keys(peerDep) : []))
		// flatten the array of arrays
		.reduce((flatDeps, deps) => [...flatDeps, ...deps], [])
		// filter to make array elements unique
		.filter((dep, i, deps) => deps.indexOf(dep) === i)
		// return object that maps name to path
		.map((dep) => ({ [dep]: path.resolve(__dirname, `node_modules/${dep}`) }))
);

const blacklistRE = blacklist(
	linkedDependenciesPaths.map(
		(depPath) =>
			new RegExp(
				`${depPath.replace(/\//g, '[/\\\\]')}[/\\\\]node_modules[/\\\\]react-native[/\\\\].*`
			)
	)
);

module.exports = {
	extraNodeModules,
	getBlacklistRE: () => blacklistRE,
	getProjectRoots: () => projectRoots,
};

@MrLoh MrLoh closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants