babel-plugin-relay 11.0.2 → 13.0.0-rc.2
Sign up to get free protection for your applications and to get access to all the features.
- package/BabelPluginRelay.js.flow +28 -14
- package/BabelPluginRelay.macro.js.flow +3 -3
- package/README.md +47 -0
- package/babel-plugin-relay.js +2 -2
- package/babel-plugin-relay.min.js +2 -2
- package/compileGraphQLTag.js.flow +13 -15
- package/getValidGraphQLTag.js.flow +3 -3
- package/index.js +1 -1
- package/lib/BabelPluginRelay.js +16 -7
- package/lib/BabelPluginRelay.macro.js +1 -1
- package/lib/compileGraphQLTag.js +8 -6
- package/lib/getValidGraphQLTag.js +3 -2
- package/macro.js +1 -1
- package/package.json +6 -7
package/BabelPluginRelay.js.flow
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -12,21 +12,33 @@
|
|
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.
|
25
|
-
|
26
|
-
|
27
|
-
haste
|
28
|
-
//
|
29
|
-
|
34
|
+
codegenCommand?: string,
|
35
|
+
|
36
|
+
// Formatting style for generated files. `commonjs` or `haste`.
|
37
|
+
// Default is `commonjs`.
|
38
|
+
jsModuleFormat?: string,
|
39
|
+
|
40
|
+
// Name of the global variable for dev mode
|
41
|
+
isDevVariableName?: string,
|
30
42
|
|
31
43
|
// enable generating eager es modules for modern runtime
|
32
44
|
eagerESModules?: boolean,
|
@@ -64,7 +76,7 @@ module.exports = function BabelPluginRelay(context: {
|
|
64
76
|
}
|
65
77
|
|
66
78
|
const visitor = {
|
67
|
-
TaggedTemplateExpression(path, state) {
|
79
|
+
TaggedTemplateExpression(path: any, state: BabelState) {
|
68
80
|
// Convert graphql`` literals
|
69
81
|
const ast = getValidGraphQLTag(path);
|
70
82
|
if (ast) {
|
@@ -77,8 +89,10 @@ module.exports = function BabelPluginRelay(context: {
|
|
77
89
|
return {
|
78
90
|
visitor: {
|
79
91
|
Program(path, state) {
|
80
|
-
|
81
|
-
|
92
|
+
path.traverse(visitor, {
|
93
|
+
...state,
|
94
|
+
opts: {...RelayConfig, ...state.opts},
|
95
|
+
});
|
82
96
|
},
|
83
97
|
},
|
84
98
|
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -12,11 +12,11 @@
|
|
12
12
|
|
13
13
|
const compileGraphQLTag = require('./compileGraphQLTag');
|
14
14
|
const getValidGraphQLTag = require('./getValidGraphQLTag');
|
15
|
-
|
16
15
|
const {createMacro} = require('babel-plugin-macros');
|
16
|
+
|
17
17
|
const configName = 'relay';
|
18
18
|
|
19
|
-
function BabelPluginRelayMacro({references, state, babel, config}) {
|
19
|
+
function BabelPluginRelayMacro({references, state, babel, config}: any) {
|
20
20
|
const {types: t} = babel;
|
21
21
|
Object.keys(references).forEach(referenceKey => {
|
22
22
|
references[referenceKey].forEach(reference => {
|
package/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
babel-plugin-relay
|
2
|
+
---
|
3
|
+
|
4
|
+
Relay requires a Babel plugin to convert GraphQL tags to runtime artifacts.
|
5
|
+
|
6
|
+
|
7
|
+
A *very* simplified example of what this plugin is doing:
|
8
|
+
|
9
|
+
```js
|
10
|
+
|
11
|
+
// It converts this code
|
12
|
+
const fragment = graphql`
|
13
|
+
fragment User_fragment on User {
|
14
|
+
name
|
15
|
+
}
|
16
|
+
`;
|
17
|
+
|
18
|
+
// To require generated ASTs for fragments and queries
|
19
|
+
const fragment = require('__generated__/User_fragment.graphql');
|
20
|
+
```
|
21
|
+
|
22
|
+
## Plugin Configuration
|
23
|
+
|
24
|
+
`babel-plugin-relay` will discover the config if:
|
25
|
+
|
26
|
+
- There is a `relay.config.json`, `relay.config.js` file at the root of the
|
27
|
+
project (i.e. in the same folder as the `package.json` file).
|
28
|
+
- The `package.json` file contains a `"relay"` key.
|
29
|
+
|
30
|
+
### Supported configuration options for `babel-plugin-relay`
|
31
|
+
|
32
|
+
- `artifactDirectory` A specific directory to output all artifacts to. When
|
33
|
+
enabling this the babel plugin needs `artifactDirectory`
|
34
|
+
to be set as well. [string]
|
35
|
+
- `eagerEsModules` This option enables emitting ES modules artifacts.
|
36
|
+
[boolean][default: false]
|
37
|
+
- `codegenCommand` The command to run to compile Relay files.
|
38
|
+
[string]
|
39
|
+
- `isDevVariableName` Name of the global variable for dev mode
|
40
|
+
(e.g. `__DEV__`).
|
41
|
+
[string]
|
42
|
+
- `jsModuleFormat` Formatting style for generated files. `commonjs`
|
43
|
+
or `haste`. Default is `commonjs`.
|
44
|
+
[string]
|
45
|
+
|
46
|
+
[Configuration Instructions](
|
47
|
+
https://relay.dev/docs/getting-started/installation-and-setup/#set-up-babel-plugin-relay)
|
package/babel-plugin-relay.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
/**
|
2
|
-
* Relay
|
2
|
+
* Relay v13.0.0-rc.2
|
3
3
|
*/
|
4
|
-
module.exports=function(e){var r={};function t
|
4
|
+
module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var i=r[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)n.d(t,i,function(r){return e[r]}.bind(null,i));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=1)}([function(e,r){e.exports=require("graphql")},function(e,r,n){"use strict";var t,i=n(2)(n(3)),o=n(4),a=n(7),l=n(8),s=l("relay",{searchPlaces:["relay.config.js","relay.config.json","package.json"],loaders:{".json":l.loadJson,".js":l.loadJs,noExt:l.loadYaml}}).searchSync();s&&(t=s.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 n={TaggedTemplateExpression:function(e,n){var t=a(e);t&&o(r,e,n,t)}};return{visitor:{Program:function(e,r){e.traverse(n,(0,i.default)((0,i.default)({},r),{},{opts:(0,i.default)((0,i.default)({},t),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,n){"use strict";var t=n(5),i=n(0).print,o=n(6),a=o.dirname,l=o.join,s=o.relative,u=o.resolve;e.exports=function(e,r,n,o){var p,d,f,c,g,v,m;if(1!==o.definitions.length)throw new Error("BabelPluginRelay: Expected exactly one definition per graphql tag.");var x=o.definitions[0];if("FragmentDefinition"!==x.kind&&"OperationDefinition"!==x.kind)throw new Error("BabelPluginRelay: Expected a fragment, mutation, query, or subscription, got `"+x.kind+"`.");var h=null!==(p=null===(d=n.opts)||void 0===d?void 0:d.eagerESModules)&&void 0!==p&&p,b="haste"===(null===(f=n.opts)||void 0===f?void 0:f.jsModuleFormat),y=null===(c=n.opts)||void 0===c?void 0:c.isDevVariableName;return function(e,r,n,o,p){var d=o.name&&o.name.value;if(!d)throw new Error("GraphQL operations and fragments must contain names");var f=d+".graphql",c=p.isHasteMode?f:p.artifactDirectory?function(e,r,n){if(null==e.file)throw new Error("Babel state is missing expected file name");var t=e.file.opts.filename,i=s(a(t),u(r));return(0!==i.length&&i.startsWith(".")?"":"./")+l(i,n)}(r,p.artifactDirectory,f):"./__generated__/"+f,g=t.createHash("md5").update(i(o),"utf8").digest("hex"),v=n.scope;for(;v.parent;)v=v.parent;var m=v.generateUidIdentifier(d),x=e.MemberExpression(m,e.Identifier("hash")),h=function(e,r,n){return e.callExpression(e.memberExpression(e.identifier("console"),e.identifier("error")),[e.stringLiteral("The definition of '".concat(r,"' appears to have changed. Run ")+"`"+n+"` to update the generated files to receive the expected data.")])}(e,d,p.buildCommand),b=e.LogicalExpression("&&",x,e.LogicalExpression("&&",e.BinaryExpression("!==",x,e.StringLiteral(g)),h));if(p.eagerESModules){var y=e.ImportDeclaration([e.ImportDefaultSpecifier(m)],e.StringLiteral(c));n.findParent((function(e){return e.isProgram()})).unshiftContainer("body",y);var E,q=e.SequenceExpression([b,m]);E=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),q,m):p.isDevelopment?q:m,n.replaceWith(E)}else{v.push({id:m});var D,S=e.CallExpression(e.Identifier("require"),[e.StringLiteral(c)]),w=e.AssignmentExpression("=",m,S),j=e.SequenceExpression([w,b,m]);D=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),j,w):p.isDevelopment?j:w;var P=e.UnaryExpression("void",e.NumericLiteral(0));n.replaceWith(e.ConditionalExpression(e.BinaryExpression("!==",m,P),m,D))}}(e,n,r,x,{artifactDirectory:null===(g=n.opts)||void 0===g?void 0:g.artifactDirectory,eagerESModules:h,buildCommand:null!==(v=null===(m=n.opts)||void 0===m?void 0:m.codegenCommand)&&void 0!==v?v:"relay-compiler",isDevelopment:"production"!==(process.env.BABEL_ENV||"development"),isHasteMode:b,isDevVariable:y})}},function(e,r){e.exports=require("crypto")},function(e,r){e.exports=require("path")},function(e,r,n){"use strict";var t=n(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 n=r[0].value.raw,i=t.parse(n);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
|
2
|
+
* Relay v13.0.0-rc.2
|
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 n(t){if(r[t])return r[t].exports;var i=r[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)n.d(t,i,function(r){return e[r]}.bind(null,i));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=1)}([function(e,r){e.exports=require("graphql")},function(e,r,n){"use strict";var t,i=n(2)(n(3)),o=n(4),a=n(7),l=n(8),s=l("relay",{searchPlaces:["relay.config.js","relay.config.json","package.json"],loaders:{".json":l.loadJson,".js":l.loadJs,noExt:l.loadYaml}}).searchSync();s&&(t=s.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 n={TaggedTemplateExpression:function(e,n){var t=a(e);t&&o(r,e,n,t)}};return{visitor:{Program:function(e,r){e.traverse(n,(0,i.default)((0,i.default)({},r),{},{opts:(0,i.default)((0,i.default)({},t),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,n){"use strict";var t=n(5),i=n(0).print,o=n(6),a=o.dirname,l=o.join,s=o.relative,u=o.resolve;e.exports=function(e,r,n,o){var p,d,c,f,g,v,m;if(1!==o.definitions.length)throw new Error("BabelPluginRelay: Expected exactly one definition per graphql tag.");var x=o.definitions[0];if("FragmentDefinition"!==x.kind&&"OperationDefinition"!==x.kind)throw new Error("BabelPluginRelay: Expected a fragment, mutation, query, or subscription, got `"+x.kind+"`.");var h=null!==(p=null===(d=n.opts)||void 0===d?void 0:d.eagerESModules)&&void 0!==p&&p,b="haste"===(null===(c=n.opts)||void 0===c?void 0:c.jsModuleFormat),y=null===(f=n.opts)||void 0===f?void 0:f.isDevVariableName;return function(e,r,n,o,p){var d=o.name&&o.name.value;if(!d)throw new Error("GraphQL operations and fragments must contain names");var c=d+".graphql",f=p.isHasteMode?c:p.artifactDirectory?function(e,r,n){if(null==e.file)throw new Error("Babel state is missing expected file name");var t=e.file.opts.filename,i=s(a(t),u(r));return(0!==i.length&&i.startsWith(".")?"":"./")+l(i,n)}(r,p.artifactDirectory,c):"./__generated__/"+c,g=t.createHash("md5").update(i(o),"utf8").digest("hex"),v=n.scope;for(;v.parent;)v=v.parent;var m=v.generateUidIdentifier(d),x=e.MemberExpression(m,e.Identifier("hash")),h=function(e,r,n){return e.callExpression(e.memberExpression(e.identifier("console"),e.identifier("error")),[e.stringLiteral("The definition of '".concat(r,"' appears to have changed. Run ")+"`"+n+"` to update the generated files to receive the expected data.")])}(e,d,p.buildCommand),b=e.LogicalExpression("&&",x,e.LogicalExpression("&&",e.BinaryExpression("!==",x,e.StringLiteral(g)),h));if(p.eagerESModules){var y=e.ImportDeclaration([e.ImportDefaultSpecifier(m)],e.StringLiteral(f));n.findParent((function(e){return e.isProgram()})).unshiftContainer("body",y);var E,q=e.SequenceExpression([b,m]);E=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),q,m):p.isDevelopment?q:m,n.replaceWith(E)}else{v.push({id:m});var D,S=e.CallExpression(e.Identifier("require"),[e.StringLiteral(f)]),w=e.AssignmentExpression("=",m,S),j=e.SequenceExpression([w,b,m]);D=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),j,w):p.isDevelopment?j:w;var P=e.UnaryExpression("void",e.NumericLiteral(0));n.replaceWith(e.ConditionalExpression(e.BinaryExpression("!==",m,P),m,D))}}(e,n,r,x,{artifactDirectory:null===(g=n.opts)||void 0===g?void 0:g.artifactDirectory,eagerESModules:h,buildCommand:null!==(v=null===(m=n.opts)||void 0===m?void 0:m.codegenCommand)&&void 0!==v?v:"relay-compiler",isDevelopment:"production"!==(process.env.BABEL_ENV||"production"),isHasteMode:b,isDevVariable:y})}},function(e,r){e.exports=require("crypto")},function(e,r){e.exports=require("path")},function(e,r,n){"use strict";var t=n(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 n=r[0].value.raw,i=t.parse(n);if(0===i.definitions.length)throw new Error("BabelPluginRelay: Unexpected empty graphql tag.");return i}},function(e,r){e.exports=require("cosmiconfig")}]);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -10,8 +10,14 @@
|
|
10
10
|
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
|
13
|
+
import type {BabelState} from './BabelPluginRelay';
|
14
|
+
import type {
|
15
|
+
DocumentNode,
|
16
|
+
FragmentDefinitionNode,
|
17
|
+
OperationDefinitionNode,
|
18
|
+
} from 'graphql';
|
14
19
|
|
20
|
+
const crypto = require('crypto');
|
15
21
|
const {print} = require('graphql');
|
16
22
|
const {
|
17
23
|
dirname,
|
@@ -20,13 +26,6 @@ const {
|
|
20
26
|
resolve: resolvePath,
|
21
27
|
} = require('path');
|
22
28
|
|
23
|
-
import type {BabelState} from './BabelPluginRelay';
|
24
|
-
import type {
|
25
|
-
DocumentNode,
|
26
|
-
FragmentDefinitionNode,
|
27
|
-
OperationDefinitionNode,
|
28
|
-
} from 'graphql';
|
29
|
-
|
30
29
|
const GENERATED = './__generated__/';
|
31
30
|
|
32
31
|
/**
|
@@ -57,12 +56,11 @@ function compileGraphQLTag(
|
|
57
56
|
);
|
58
57
|
}
|
59
58
|
|
60
|
-
const eagerESModules =
|
61
|
-
const isHasteMode =
|
62
|
-
const isDevVariable = state.opts
|
63
|
-
const artifactDirectory = state.opts
|
64
|
-
const buildCommand =
|
65
|
-
(state.opts && state.opts.buildCommand) || 'relay-compiler';
|
59
|
+
const eagerESModules = state.opts?.eagerESModules ?? false;
|
60
|
+
const isHasteMode = state.opts?.jsModuleFormat === 'haste';
|
61
|
+
const isDevVariable = state.opts?.isDevVariableName;
|
62
|
+
const artifactDirectory = state.opts?.artifactDirectory;
|
63
|
+
const buildCommand = state.opts?.codegenCommand ?? 'relay-compiler';
|
66
64
|
// Fallback is 'true'
|
67
65
|
const isDevelopment =
|
68
66
|
(process.env.BABEL_ENV || process.env.NODE_ENV) !== 'production';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -10,10 +10,10 @@
|
|
10
10
|
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
const GraphQL = require('graphql');
|
14
|
-
|
15
13
|
import type {DocumentNode} from 'graphql';
|
16
14
|
|
15
|
+
const GraphQL = require('graphql');
|
16
|
+
|
17
17
|
/**
|
18
18
|
* Given a babel AST path to a tagged template literal, return an AST if it is
|
19
19
|
* a graphql literal being used in a valid way.
|
package/index.js
CHANGED
package/lib/BabelPluginRelay.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -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/lib/compileGraphQLTag.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -27,6 +27,8 @@ var GENERATED = './__generated__/';
|
|
27
27
|
*/
|
28
28
|
|
29
29
|
function compileGraphQLTag(t, path, state, ast) {
|
30
|
+
var _state$opts$eagerESMo, _state$opts, _state$opts2, _state$opts3, _state$opts4, _state$opts$codegenCo, _state$opts5;
|
31
|
+
|
30
32
|
if (ast.definitions.length !== 1) {
|
31
33
|
throw new Error('BabelPluginRelay: Expected exactly one definition per graphql tag.');
|
32
34
|
}
|
@@ -37,11 +39,11 @@ function compileGraphQLTag(t, path, state, ast) {
|
|
37
39
|
throw new Error('BabelPluginRelay: Expected a fragment, mutation, query, or ' + 'subscription, got `' + definition.kind + '`.');
|
38
40
|
}
|
39
41
|
|
40
|
-
var eagerESModules =
|
41
|
-
var isHasteMode =
|
42
|
-
var isDevVariable = state.opts
|
43
|
-
var artifactDirectory = state.opts
|
44
|
-
var buildCommand =
|
42
|
+
var eagerESModules = (_state$opts$eagerESMo = (_state$opts = state.opts) === null || _state$opts === void 0 ? void 0 : _state$opts.eagerESModules) !== null && _state$opts$eagerESMo !== void 0 ? _state$opts$eagerESMo : false;
|
43
|
+
var isHasteMode = ((_state$opts2 = state.opts) === null || _state$opts2 === void 0 ? void 0 : _state$opts2.jsModuleFormat) === 'haste';
|
44
|
+
var isDevVariable = (_state$opts3 = state.opts) === null || _state$opts3 === void 0 ? void 0 : _state$opts3.isDevVariableName;
|
45
|
+
var artifactDirectory = (_state$opts4 = state.opts) === null || _state$opts4 === void 0 ? void 0 : _state$opts4.artifactDirectory;
|
46
|
+
var buildCommand = (_state$opts$codegenCo = (_state$opts5 = state.opts) === null || _state$opts5 === void 0 ? void 0 : _state$opts5.codegenCommand) !== null && _state$opts$codegenCo !== void 0 ? _state$opts$codegenCo : 'relay-compiler'; // Fallback is 'true'
|
45
47
|
|
46
48
|
var isDevelopment = (process.env.BABEL_ENV || process.env.NODE_ENV) !== 'production';
|
47
49
|
return createNode(t, state, path, definition, {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
*
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
@@ -10,12 +10,13 @@
|
|
10
10
|
'use strict';
|
11
11
|
|
12
12
|
var GraphQL = require('graphql');
|
13
|
-
|
14
13
|
/**
|
15
14
|
* Given a babel AST path to a tagged template literal, return an AST if it is
|
16
15
|
* a graphql literal being used in a valid way.
|
17
16
|
* If it is some other type of template literal then return nothing.
|
18
17
|
*/
|
18
|
+
|
19
|
+
|
19
20
|
function getValidGraphQLTag(path) {
|
20
21
|
var tag = path.get('tag');
|
21
22
|
|
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": "
|
4
|
+
"version": "13.0.0-rc.2",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay",
|
@@ -13,13 +13,12 @@
|
|
13
13
|
"bugs": "https://github.com/facebook/relay/issues",
|
14
14
|
"repository": "facebook/relay",
|
15
15
|
"dependencies": {
|
16
|
-
"babel-plugin-macros": "^2.0.0"
|
16
|
+
"babel-plugin-macros": "^2.0.0",
|
17
|
+
"cosmiconfig": "^5.0.5",
|
18
|
+
"graphql": "15.3.0"
|
17
19
|
},
|
18
20
|
"devDependencies": {
|
19
|
-
"@babel/core": "^7.
|
20
|
-
"prettier": "
|
21
|
-
},
|
22
|
-
"peerDependencies": {
|
23
|
-
"graphql": "^15.0.0"
|
21
|
+
"@babel/core": "^7.14.0",
|
22
|
+
"prettier": "^2.4.1"
|
24
23
|
}
|
25
24
|
}
|