babel-plugin-relay 13.0.0-rc.0 → 13.0.0-rc.1
Sign up to get free protection for your applications and to get access to all the features.
- package/BabelPluginRelay.js.flow +18 -7
- package/babel-plugin-relay.js +2 -2
- package/babel-plugin-relay.min.js +2 -2
- package/index.js +1 -1
- package/lib/BabelPluginRelay.js +15 -6
- package/macro.js +1 -1
- package/package.json +2 -1
package/BabelPluginRelay.js.flow
CHANGED
@@ -12,13 +12,22 @@
|
|
12
12
|
|
13
13
|
const compileGraphQLTag = require('./compileGraphQLTag');
|
14
14
|
const getValidGraphQLTag = require('./getValidGraphQLTag');
|
15
|
+
const cosmiconfig = require('cosmiconfig');
|
16
|
+
|
17
|
+
const configExplorer = cosmiconfig('relay', {
|
18
|
+
searchPlaces: ['relay.config.js', 'relay.config.json', 'package.json'],
|
19
|
+
loaders: {
|
20
|
+
'.json': cosmiconfig.loadJson,
|
21
|
+
'.js': cosmiconfig.loadJs,
|
22
|
+
noExt: cosmiconfig.loadYaml,
|
23
|
+
},
|
24
|
+
});
|
15
25
|
|
16
26
|
let RelayConfig;
|
17
|
-
|
18
|
-
|
19
|
-
RelayConfig =
|
20
|
-
|
21
|
-
} catch (_) {}
|
27
|
+
const result = configExplorer.searchSync();
|
28
|
+
if (result) {
|
29
|
+
RelayConfig = result.config;
|
30
|
+
}
|
22
31
|
|
23
32
|
export type RelayPluginOptions = {
|
24
33
|
// The command to run to compile Relay files, used for error messages.
|
@@ -77,8 +86,10 @@ module.exports = function BabelPluginRelay(context: {
|
|
77
86
|
return {
|
78
87
|
visitor: {
|
79
88
|
Program(path, state) {
|
80
|
-
|
81
|
-
|
89
|
+
path.traverse(visitor, {
|
90
|
+
...state,
|
91
|
+
opts: {...RelayConfig, ...state.opts},
|
92
|
+
});
|
82
93
|
},
|
83
94
|
},
|
84
95
|
};
|
package/babel-plugin-relay.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
/**
|
2
|
-
* Relay v13.0.0-rc.
|
2
|
+
* Relay v13.0.0-rc.1
|
3
3
|
*/
|
4
|
-
module.exports=function(e){var r={};function t(
|
4
|
+
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)t.d(n,i,function(r){return e[r]}.bind(null,i));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=1)}([function(e,r){e.exports=require("graphql")},function(e,r,t){"use strict";var n,i=t(2)(t(3)),o=t(4),a=t(7),s=t(8),l=s("relay",{searchPlaces:["relay.config.js","relay.config.json","package.json"],loaders:{".json":s.loadJson,".js":s.loadJs,noExt:s.loadYaml}}).searchSync();l&&(n=l.config),e.exports=function(e){var r=e.types;if(!r)throw new Error('BabelPluginRelay: Expected plugin context to include "types", but got:'+String(e));var t={TaggedTemplateExpression:function(e,t){var n=a(e);n&&o(r,e,t,n)}};return{visitor:{Program:function(e,r){e.traverse(t,(0,i.default)((0,i.default)({},r),{},{opts:(0,i.default)((0,i.default)({},n),r.opts)}))}}}}},function(e,r){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,r){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,r,t){"use strict";var n=t(5),i=t(0).print,o=t(6),a=o.dirname,s=o.join,l=o.relative,u=o.resolve;e.exports=function(e,r,t,o){if(1!==o.definitions.length)throw new Error("BabelPluginRelay: Expected exactly one definition per graphql tag.");var p=o.definitions[0];if("FragmentDefinition"!==p.kind&&"OperationDefinition"!==p.kind)throw new Error("BabelPluginRelay: Expected a fragment, mutation, query, or subscription, got `"+p.kind+"`.");var f=Boolean(t.opts&&t.opts.eagerESModules),c=Boolean(t.opts&&t.opts.haste),d=t.opts&&t.opts.isDevVariable;return function(e,r,t,o,p){var f=o.name&&o.name.value;if(!f)throw new Error("GraphQL operations and fragments must contain names");var c=f+".graphql",d=p.isHasteMode?c:p.artifactDirectory?function(e,r,t){if(null==e.file)throw new Error("Babel state is missing expected file name");var n=e.file.opts.filename,i=l(a(n),u(r));return(0!==i.length&&i.startsWith(".")?"":"./")+s(i,t)}(r,p.artifactDirectory,c):"./__generated__/"+c,g=n.createHash("md5").update(i(o),"utf8").digest("hex"),m=t.scope;for(;m.parent;)m=m.parent;var v=m.generateUidIdentifier(f),x=e.MemberExpression(v,e.Identifier("hash")),b=function(e,r,t){return e.callExpression(e.memberExpression(e.identifier("console"),e.identifier("error")),[e.stringLiteral("The definition of '".concat(r,"' appears to have changed. Run ")+"`"+t+"` to update the generated files to receive the expected data.")])}(e,f,p.buildCommand),h=e.LogicalExpression("&&",x,e.LogicalExpression("&&",e.BinaryExpression("!==",x,e.StringLiteral(g)),b));if(p.eagerESModules){var y=e.ImportDeclaration([e.ImportDefaultSpecifier(v)],e.StringLiteral(d));t.findParent((function(e){return e.isProgram()})).unshiftContainer("body",y);var E,q=e.SequenceExpression([h,v]);E=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),q,v):p.isDevelopment?q:v,t.replaceWith(E)}else{m.push({id:v});var D,S=e.CallExpression(e.Identifier("require"),[e.StringLiteral(d)]),w=e.AssignmentExpression("=",v,S),j=e.SequenceExpression([w,h,v]);D=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),j,w):p.isDevelopment?j:w;var P=e.UnaryExpression("void",e.NumericLiteral(0));t.replaceWith(e.ConditionalExpression(e.BinaryExpression("!==",v,P),v,D))}}(e,t,r,p,{artifactDirectory:t.opts&&t.opts.artifactDirectory,eagerESModules:f,buildCommand:t.opts&&t.opts.buildCommand||"relay-compiler",isDevelopment:"production"!==(process.env.BABEL_ENV||"development"),isHasteMode:c,isDevVariable:d})}},function(e,r){e.exports=require("crypto")},function(e,r){e.exports=require("path")},function(e,r,t){"use strict";var n=t(0);e.exports=function(e){if(!e.get("tag").isIdentifier({name:"graphql"}))return null;var r=e.node.quasi.quasis;if(1!==r.length)throw new Error("BabelPluginRelay: Substitutions are not allowed in graphql fragments. Included fragments should be referenced as `...MyModule_propName`.");var t=r[0].value.raw,i=n.parse(t);if(0===i.definitions.length)throw new Error("BabelPluginRelay: Unexpected empty graphql tag.");return i}},function(e,r){e.exports=require("cosmiconfig")}]);
|
@@ -1,9 +1,9 @@
|
|
1
1
|
/**
|
2
|
-
* Relay v13.0.0-rc.
|
2
|
+
* Relay v13.0.0-rc.1
|
3
3
|
*
|
4
4
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
5
5
|
*
|
6
6
|
* This source code is licensed under the MIT license found in the
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
8
8
|
*/
|
9
|
-
module.exports=function(e){var r={};function t(
|
9
|
+
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)t.d(n,i,function(r){return e[r]}.bind(null,i));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=1)}([function(e,r){e.exports=require("graphql")},function(e,r,t){"use strict";var n,i=t(2)(t(3)),o=t(4),a=t(7),s=t(8),l=s("relay",{searchPlaces:["relay.config.js","relay.config.json","package.json"],loaders:{".json":s.loadJson,".js":s.loadJs,noExt:s.loadYaml}}).searchSync();l&&(n=l.config),e.exports=function(e){var r=e.types;if(!r)throw new Error('BabelPluginRelay: Expected plugin context to include "types", but got:'+String(e));var t={TaggedTemplateExpression:function(e,t){var n=a(e);n&&o(r,e,t,n)}};return{visitor:{Program:function(e,r){e.traverse(t,(0,i.default)((0,i.default)({},r),{},{opts:(0,i.default)((0,i.default)({},n),r.opts)}))}}}}},function(e,r){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,r){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,r,t){"use strict";var n=t(5),i=t(0).print,o=t(6),a=o.dirname,s=o.join,l=o.relative,u=o.resolve;e.exports=function(e,r,t,o){if(1!==o.definitions.length)throw new Error("BabelPluginRelay: Expected exactly one definition per graphql tag.");var p=o.definitions[0];if("FragmentDefinition"!==p.kind&&"OperationDefinition"!==p.kind)throw new Error("BabelPluginRelay: Expected a fragment, mutation, query, or subscription, got `"+p.kind+"`.");var f=Boolean(t.opts&&t.opts.eagerESModules),c=Boolean(t.opts&&t.opts.haste),d=t.opts&&t.opts.isDevVariable;return function(e,r,t,o,p){var f=o.name&&o.name.value;if(!f)throw new Error("GraphQL operations and fragments must contain names");var c=f+".graphql",d=p.isHasteMode?c:p.artifactDirectory?function(e,r,t){if(null==e.file)throw new Error("Babel state is missing expected file name");var n=e.file.opts.filename,i=l(a(n),u(r));return(0!==i.length&&i.startsWith(".")?"":"./")+s(i,t)}(r,p.artifactDirectory,c):"./__generated__/"+c,g=n.createHash("md5").update(i(o),"utf8").digest("hex"),m=t.scope;for(;m.parent;)m=m.parent;var v=m.generateUidIdentifier(f),x=e.MemberExpression(v,e.Identifier("hash")),b=function(e,r,t){return e.callExpression(e.memberExpression(e.identifier("console"),e.identifier("error")),[e.stringLiteral("The definition of '".concat(r,"' appears to have changed. Run ")+"`"+t+"` to update the generated files to receive the expected data.")])}(e,f,p.buildCommand),h=e.LogicalExpression("&&",x,e.LogicalExpression("&&",e.BinaryExpression("!==",x,e.StringLiteral(g)),b));if(p.eagerESModules){var y=e.ImportDeclaration([e.ImportDefaultSpecifier(v)],e.StringLiteral(d));t.findParent((function(e){return e.isProgram()})).unshiftContainer("body",y);var E,q=e.SequenceExpression([h,v]);E=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),q,v):p.isDevelopment?q:v,t.replaceWith(E)}else{m.push({id:v});var D,S=e.CallExpression(e.Identifier("require"),[e.StringLiteral(d)]),w=e.AssignmentExpression("=",v,S),j=e.SequenceExpression([w,h,v]);D=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),j,w):p.isDevelopment?j:w;var P=e.UnaryExpression("void",e.NumericLiteral(0));t.replaceWith(e.ConditionalExpression(e.BinaryExpression("!==",v,P),v,D))}}(e,t,r,p,{artifactDirectory:t.opts&&t.opts.artifactDirectory,eagerESModules:f,buildCommand:t.opts&&t.opts.buildCommand||"relay-compiler",isDevelopment:"production"!==(process.env.BABEL_ENV||"production"),isHasteMode:c,isDevVariable:d})}},function(e,r){e.exports=require("crypto")},function(e,r){e.exports=require("path")},function(e,r,t){"use strict";var n=t(0);e.exports=function(e){if(!e.get("tag").isIdentifier({name:"graphql"}))return null;var r=e.node.quasi.quasis;if(1!==r.length)throw new Error("BabelPluginRelay: Substitutions are not allowed in graphql fragments. Included fragments should be referenced as `...MyModule_propName`.");var t=r[0].value.raw,i=n.parse(t);if(0===i.definitions.length)throw new Error("BabelPluginRelay: Unexpected empty graphql tag.");return i}},function(e,r){e.exports=require("cosmiconfig")}]);
|
package/index.js
CHANGED
package/lib/BabelPluginRelay.js
CHANGED
@@ -17,12 +17,22 @@ var compileGraphQLTag = require('./compileGraphQLTag');
|
|
17
17
|
|
18
18
|
var getValidGraphQLTag = require('./getValidGraphQLTag');
|
19
19
|
|
20
|
+
var cosmiconfig = require('cosmiconfig');
|
21
|
+
|
22
|
+
var configExplorer = cosmiconfig('relay', {
|
23
|
+
searchPlaces: ['relay.config.js', 'relay.config.json', 'package.json'],
|
24
|
+
loaders: {
|
25
|
+
'.json': cosmiconfig.loadJson,
|
26
|
+
'.js': cosmiconfig.loadJs,
|
27
|
+
noExt: cosmiconfig.loadYaml
|
28
|
+
}
|
29
|
+
});
|
20
30
|
var RelayConfig;
|
31
|
+
var result = configExplorer.searchSync();
|
21
32
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
} catch (_) {}
|
33
|
+
if (result) {
|
34
|
+
RelayConfig = result.config;
|
35
|
+
}
|
26
36
|
|
27
37
|
/**
|
28
38
|
* Using babel-plugin-relay with only the modern runtime?
|
@@ -54,9 +64,8 @@ module.exports = function BabelPluginRelay(context) {
|
|
54
64
|
return {
|
55
65
|
visitor: {
|
56
66
|
Program: function Program(path, state) {
|
57
|
-
var config = RelayConfig && RelayConfig.loadConfig();
|
58
67
|
path.traverse(visitor, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
59
|
-
opts: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({},
|
68
|
+
opts: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, RelayConfig), state.opts)
|
60
69
|
}));
|
61
70
|
}
|
62
71
|
}
|
package/macro.js
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "babel-plugin-relay",
|
3
3
|
"description": "A Babel Plugin for use with Relay applications.",
|
4
|
-
"version": "13.0.0-rc.
|
4
|
+
"version": "13.0.0-rc.1",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay",
|
@@ -14,6 +14,7 @@
|
|
14
14
|
"repository": "facebook/relay",
|
15
15
|
"dependencies": {
|
16
16
|
"babel-plugin-macros": "^2.0.0",
|
17
|
+
"cosmiconfig": "^5.0.5",
|
17
18
|
"graphql": "15.3.0"
|
18
19
|
},
|
19
20
|
"devDependencies": {
|