babel-plugin-transform-relay-hot
Advanced tools
Comparing version 1.0.0 to 1.0.1
31
index.js
@@ -7,5 +7,7 @@ /** | ||
const getBabelRelayPlugin = require('babel-plugin-relay'); | ||
const fs = require('fs'); | ||
const log = (msg) => { | ||
console.log('[transform-relay-hot]', msg); | ||
}; | ||
@@ -30,3 +32,3 @@ // file changes watcher | ||
} catch (e) { | ||
console.error('[transform-relay-hot] ' + e); | ||
log(e); | ||
} | ||
@@ -46,3 +48,3 @@ } | ||
schema = null; | ||
console.error('[transform-relay-hot] Cannot load GraphQL Schema from file \'' | ||
log('Cannot load GraphQL Schema from file \'' | ||
+ schemaJsonFilepath + '\': ' + e); | ||
@@ -53,9 +55,8 @@ } | ||
if (verbose) { | ||
console.log('[transform-relay-hot] GraphQL Schema loaded successfully from \'' | ||
+ schemaJsonFilepath + '\''); | ||
log('GraphQL Schema loaded successfully from \'' + schemaJsonFilepath + '\''); | ||
} | ||
ref.babelRelayPlugin = getBabelRelayPlugin(babel); | ||
ref.babelRelayPlugin = require('babel-plugin-relay')(babel); | ||
} else { | ||
// empty Plugin | ||
console.error('[transform-relay-hot] Relay.QL will not be transformed, cause `schema.data` is empty.'); | ||
log('Relay.QL will not be transformed, cause `schema.data` is empty.'); | ||
ref.babelRelayPlugin = { | ||
@@ -85,3 +86,3 @@ visitor: { | ||
if (pluginOptions.schemaJsonFilepath) { | ||
console.error( | ||
log( | ||
'[transform-relay-hot] Please rename `schemaJsonFilepath` option in .babelrc:' | ||
@@ -101,3 +102,3 @@ + '\n {' | ||
if (!pluginOptions.schema || pluginOptions.schema === '') { | ||
console.error( | ||
log( | ||
'[transform-relay-hot] You should provide `schema` option in .babelrc:' | ||
@@ -123,2 +124,14 @@ + '\n {' | ||
const reinitBabelRelayPlugin = () => { | ||
log('Re-init babel-plugin-relay'); | ||
// decache all babel-plugin-relay modules | ||
Object.keys(require.cache).forEach((key) => { | ||
if (key.indexOf('babel-plugin-relay') > 0) { | ||
delete require.cache[key]; | ||
} | ||
}); | ||
Object.keys(module.constructor._pathCache).forEach((key) => { | ||
if (key.indexOf('babel-plugin-relay') > 0) { | ||
delete module.constructor._pathCache[key]; | ||
} | ||
}); | ||
initBabelRelayPlugin(pluginOptions, babel, ref); | ||
@@ -125,0 +138,0 @@ }; |
{ | ||
"name": "babel-plugin-transform-relay-hot", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Wrapper for babel-relay-plugin which track changes in the graphql schema file and hot swap them without restart dev server with babel", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
131
45638