mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-13 09:30:23 +08:00
Don't rewrite import paths for non-existent modules or types. They will attempt to be imported from the package's main export. This change currently requires a module map to be generated for the babel-plugin to use. The map is automatically regenerated for any commit that alters the entry file of react-native-web. Fix #822
25 lines
893 B
JavaScript
25 lines
893 B
JavaScript
/**
|
|
* Creates a map of exported modules, allowing the RNW babel plugin to rewrite
|
|
* paths only for modules it knows are exported by RNW.
|
|
*/
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const isDirectory = source => fs.lstatSync(source).isDirectory();
|
|
const getDirectories = source =>
|
|
fs.readdirSync(source).filter(name => isDirectory(path.join(source, name)));
|
|
|
|
const packagesDir = path.join(__dirname, '../../packages/');
|
|
const exportsDir = path.join(packagesDir, 'react-native-web/src/exports');
|
|
const moduleMapOutfile = path.join(__dirname, 'babel-plugin-react-native-web/src/moduleMap.js');
|
|
|
|
const moduleMap = getDirectories(exportsDir).reduce((acc, curr) => {
|
|
acc[curr] = true;
|
|
return acc;
|
|
}, {});
|
|
|
|
const data = `// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
|
|
module.exports = ${JSON.stringify(moduleMap, null, 2)}`;
|
|
|
|
fs.writeFileSync(moduleMapOutfile, data);
|