Reskindex to a temp file, to confuse the babel watcher less (#908)
I'm seeing a lot of instances where the babel watcher picks up a half-written src/component-index, and generates an empty lib file - which it then doesn't update when src/component-index is updated. Empirically, this seems to make it better.
This commit is contained in:
parent
19d727ab88
commit
4df51a2b0b
1 changed files with 19 additions and 8 deletions
|
@ -6,6 +6,7 @@ var args = require('optimist').argv;
|
|||
var chokidar = require('chokidar');
|
||||
|
||||
var componentIndex = path.join('src', 'component-index.js');
|
||||
var componentIndexTmp = componentIndex+".tmp";
|
||||
var componentsDir = path.join('src', 'components');
|
||||
var componentGlob = '**/*.js';
|
||||
var prevFiles = [];
|
||||
|
@ -20,7 +21,7 @@ function reskindex() {
|
|||
var header = args.h || args.header;
|
||||
var packageJson = JSON.parse(fs.readFileSync('./package.json'));
|
||||
|
||||
var strm = fs.createWriteStream(componentIndex);
|
||||
var strm = fs.createWriteStream(componentIndexTmp);
|
||||
|
||||
if (header) {
|
||||
strm.write(fs.readFileSync(header));
|
||||
|
@ -35,13 +36,16 @@ function reskindex() {
|
|||
strm.write(" */\n\n");
|
||||
|
||||
if (packageJson['matrix-react-parent']) {
|
||||
const parentIndex = packageJson['matrix-react-parent'] +
|
||||
'/lib/component-index';
|
||||
strm.write(
|
||||
"module.exports.components = require('"+
|
||||
packageJson['matrix-react-parent']+
|
||||
"/lib/component-index').components;\n\n"
|
||||
);
|
||||
`let components = require('${parentIndex}').components;
|
||||
if (!components) {
|
||||
throw new Error("'${parentIndex}' didn't export components");
|
||||
}
|
||||
`);
|
||||
} else {
|
||||
strm.write("module.exports.components = {};\n");
|
||||
strm.write("let components = {};\n");
|
||||
}
|
||||
|
||||
for (var i = 0; i < files.length; ++i) {
|
||||
|
@ -51,13 +55,20 @@ function reskindex() {
|
|||
var importName = moduleName.replace(/\./g, "$");
|
||||
|
||||
strm.write("import " + importName + " from './components/" + file + "';\n");
|
||||
strm.write(importName + " && (module.exports.components['"+moduleName+"'] = " + importName + ");");
|
||||
strm.write(importName + " && (components['"+moduleName+"'] = " + importName + ");");
|
||||
strm.write('\n');
|
||||
strm.uncork();
|
||||
}
|
||||
|
||||
strm.write("export {components};\n");
|
||||
strm.end();
|
||||
console.log('Reskindex: completed');
|
||||
fs.rename(componentIndexTmp, componentIndex, function(err) {
|
||||
if(err) {
|
||||
console.error("Error moving new index into place: " + err);
|
||||
} else {
|
||||
console.log('Reskindex: completed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Expects both arrays of file names to be sorted
|
||||
|
|
Loading…
Reference in a new issue