babel-plugin-relay 14.1.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -1,4 +1,4 @@
1
1
  /**
2
- * Relay v14.1.0
2
+ * Relay v15.0.0
3
3
  */
4
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=(0,n(2).default)(n(3)),o=n(4),a=n(7),s=n(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&&(t=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 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,s=o.join,l=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=l(a(t),u(r));return(0!==i.length&&i.startsWith(".")?"":"./")+s(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,w=e.CallExpression(e.Identifier("require"),[e.StringLiteral(c)]),j=e.AssignmentExpression("=",m,w),S=e.SequenceExpression([j,b,m]);D=null!=p.isDevVariable?e.ConditionalExpression(e.Identifier(p.isDevVariable),S,j):p.isDevelopment?S:j;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,5 +1,5 @@
1
1
  /**
2
- * Relay v14.1.0
2
+ * Relay v15.0.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
@@ -6,6 +6,7 @@
6
6
  *
7
7
  * @flow
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
11
 
11
12
  'use strict';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v14.1.0
2
+ * Relay v15.0.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
@@ -6,19 +6,16 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
11
+
10
12
  'use strict';
11
13
 
12
14
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
13
-
14
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
15
-
16
16
  var compileGraphQLTag = require('./compileGraphQLTag');
17
-
18
17
  var getValidGraphQLTag = require('./getValidGraphQLTag');
19
-
20
18
  var cosmiconfig = require('cosmiconfig');
21
-
22
19
  var configExplorer = cosmiconfig('relay', {
23
20
  searchPlaces: ['relay.config.js', 'relay.config.json', 'package.json'],
24
21
  loaders: {
@@ -29,11 +26,9 @@ var configExplorer = cosmiconfig('relay', {
29
26
  });
30
27
  var RelayConfig;
31
28
  var result = configExplorer.searchSync();
32
-
33
29
  if (result) {
34
30
  RelayConfig = result.config;
35
31
  }
36
-
37
32
  /**
38
33
  * Using babel-plugin-relay with only the modern runtime?
39
34
  *
@@ -45,16 +40,13 @@ if (result) {
45
40
  */
46
41
  module.exports = function BabelPluginRelay(context) {
47
42
  var t = context.types;
48
-
49
43
  if (!t) {
50
44
  throw new Error('BabelPluginRelay: Expected plugin context to include "types", but got:' + String(context));
51
45
  }
52
-
53
46
  var visitor = {
54
47
  TaggedTemplateExpression: function TaggedTemplateExpression(path, state) {
55
48
  // Convert graphql`` literals
56
49
  var ast = getValidGraphQLTag(path);
57
-
58
50
  if (ast) {
59
51
  compileGraphQLTag(t, path, state, ast);
60
52
  return;
@@ -6,29 +6,26 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
11
+
10
12
  'use strict';
11
13
 
12
14
  var compileGraphQLTag = require('./compileGraphQLTag');
13
-
14
15
  var getValidGraphQLTag = require('./getValidGraphQLTag');
15
-
16
16
  var _require = require('babel-plugin-macros'),
17
- createMacro = _require.createMacro;
18
-
17
+ createMacro = _require.createMacro;
19
18
  var configName = 'relay';
20
-
21
19
  function BabelPluginRelayMacro(_ref) {
22
20
  var references = _ref.references,
23
- state = _ref.state,
24
- babel = _ref.babel,
25
- config = _ref.config;
21
+ state = _ref.state,
22
+ babel = _ref.babel,
23
+ config = _ref.config;
26
24
  var t = babel.types;
27
25
  Object.keys(references).forEach(function (referenceKey) {
28
26
  references[referenceKey].forEach(function (reference) {
29
27
  var path = reference.parentPath;
30
28
  var ast = getValidGraphQLTag(path);
31
-
32
29
  if (ast) {
33
30
  compileGraphQLTag(t, path, Object.assign(state, config ? {
34
31
  opts: config
@@ -37,7 +34,6 @@ function BabelPluginRelayMacro(_ref) {
37
34
  });
38
35
  });
39
36
  }
40
-
41
37
  module.exports = createMacro(BabelPluginRelayMacro, {
42
38
  configName: configName
43
39
  });
@@ -6,45 +6,40 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
11
+
10
12
  'use strict';
11
13
 
12
14
  var crypto = require('crypto');
13
-
14
15
  var _require = require('graphql'),
15
- print = _require.print;
16
-
16
+ print = _require.print;
17
17
  var _require2 = require('path'),
18
- dirname = _require2.dirname,
19
- joinPath = _require2.join,
20
- relativePath = _require2.relative,
21
- resolvePath = _require2.resolve;
22
-
18
+ dirname = _require2.dirname,
19
+ joinPath = _require2.join,
20
+ relativePath = _require2.relative,
21
+ resolvePath = _require2.resolve;
23
22
  var GENERATED = './__generated__/';
23
+
24
24
  /**
25
25
  * Given a graphql`` tagged template literal, replace it with the appropriate
26
26
  * runtime artifact.
27
27
  */
28
-
29
28
  function compileGraphQLTag(t, path, state, ast) {
30
29
  var _state$opts$eagerEsMo, _state$opts, _state$opts2, _state$opts3, _state$opts4, _state$opts$codegenCo, _state$opts5;
31
-
32
30
  if (ast.definitions.length !== 1) {
33
31
  throw new Error('BabelPluginRelay: Expected exactly one definition per graphql tag.');
34
32
  }
35
-
36
33
  var definition = ast.definitions[0];
37
-
38
34
  if (definition.kind !== 'FragmentDefinition' && definition.kind !== 'OperationDefinition') {
39
35
  throw new Error('BabelPluginRelay: Expected a fragment, mutation, query, or ' + 'subscription, got `' + definition.kind + '`.');
40
36
  }
41
-
42
37
  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
38
  var isHasteMode = ((_state$opts2 = state.opts) === null || _state$opts2 === void 0 ? void 0 : _state$opts2.jsModuleFormat) === 'haste';
44
39
  var isDevVariable = (_state$opts3 = state.opts) === null || _state$opts3 === void 0 ? void 0 : _state$opts3.isDevVariableName;
45
40
  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'
47
-
41
+ 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';
42
+ // Fallback is 'true'
48
43
  var isDevelopment = (process.env.BABEL_ENV || process.env.NODE_ENV) !== 'production';
49
44
  return createNode(t, state, path, definition, {
50
45
  artifactDirectory: artifactDirectory,
@@ -55,35 +50,29 @@ function compileGraphQLTag(t, path, state, ast) {
55
50
  isDevVariable: isDevVariable
56
51
  });
57
52
  }
53
+
58
54
  /**
59
55
  * The Relay compiler generates separate modules that contain the compiled code.
60
56
  * Here we generate:
61
57
  * - a memoized `require` call for that generated code
62
58
  * - for development mode, runtime validation that the artifacts are up to date
63
59
  */
64
-
65
-
66
60
  function createNode(t, state, path, graphqlDefinition, options) {
67
61
  var definitionName = graphqlDefinition.name && graphqlDefinition.name.value;
68
-
69
62
  if (!definitionName) {
70
63
  throw new Error('GraphQL operations and fragments must contain names');
71
64
  }
72
-
73
65
  var requiredFile = definitionName + '.graphql';
74
66
  var requiredPath = options.isHasteMode ? requiredFile : options.artifactDirectory ? getRelativeImportPath(state, options.artifactDirectory, requiredFile) : GENERATED + requiredFile;
75
67
  var hash = crypto.createHash('md5').update(print(graphqlDefinition), 'utf8').digest('hex');
76
68
  var topScope = path.scope;
77
-
78
69
  while (topScope.parent) {
79
70
  topScope = topScope.parent;
80
71
  }
81
-
82
72
  var id = topScope.generateUidIdentifier(definitionName);
83
73
  var expHash = t.MemberExpression(id, t.Identifier('hash'));
84
74
  var expWarn = warnNeedsRebuild(t, definitionName, options.buildCommand);
85
75
  var expWarnIfOutdated = t.LogicalExpression('&&', expHash, t.LogicalExpression('&&', t.BinaryExpression('!==', expHash, t.StringLiteral(hash)), expWarn));
86
-
87
76
  if (options.eagerEsModules) {
88
77
  var importDeclaration = t.ImportDeclaration([t.ImportDefaultSpecifier(id)], t.StringLiteral(requiredPath));
89
78
  var program = path.findParent(function (parent) {
@@ -92,7 +81,6 @@ function createNode(t, state, path, graphqlDefinition, options) {
92
81
  program.unshiftContainer('body', importDeclaration);
93
82
  var expAssignAndCheck = t.SequenceExpression([expWarnIfOutdated, id]);
94
83
  var expAssign;
95
-
96
84
  if (options.isDevVariable != null) {
97
85
  expAssign = t.ConditionalExpression(t.Identifier(options.isDevVariable), expAssignAndCheck, id);
98
86
  } else if (options.isDevelopment) {
@@ -100,7 +88,6 @@ function createNode(t, state, path, graphqlDefinition, options) {
100
88
  } else {
101
89
  expAssign = id;
102
90
  }
103
-
104
91
  path.replaceWith(expAssign);
105
92
  } else {
106
93
  topScope.push({
@@ -108,11 +95,8 @@ function createNode(t, state, path, graphqlDefinition, options) {
108
95
  });
109
96
  var requireGraphQLModule = t.CallExpression(t.Identifier('require'), [t.StringLiteral(requiredPath)]);
110
97
  var expAssignProd = t.AssignmentExpression('=', id, requireGraphQLModule);
111
-
112
98
  var _expAssignAndCheck = t.SequenceExpression([expAssignProd, expWarnIfOutdated, id]);
113
-
114
99
  var _expAssign;
115
-
116
100
  if (options.isDevVariable != null) {
117
101
  _expAssign = t.ConditionalExpression(t.Identifier(options.isDevVariable), _expAssignAndCheck, expAssignProd);
118
102
  } else if (options.isDevelopment) {
@@ -120,25 +104,20 @@ function createNode(t, state, path, graphqlDefinition, options) {
120
104
  } else {
121
105
  _expAssign = expAssignProd;
122
106
  }
123
-
124
107
  var expVoid0 = t.UnaryExpression('void', t.NumericLiteral(0));
125
108
  path.replaceWith(t.ConditionalExpression(t.BinaryExpression('!==', id, expVoid0), id, _expAssign));
126
109
  }
127
110
  }
128
-
129
111
  function warnNeedsRebuild(t, definitionName, buildCommand) {
130
112
  return t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('error')), [t.stringLiteral("The definition of '".concat(definitionName, "' appears to have changed. Run ") + '`' + buildCommand + '` to update the generated files to receive the expected data.')]);
131
113
  }
132
-
133
114
  function getRelativeImportPath(state, artifactDirectory, fileToRequire) {
134
115
  if (state.file == null) {
135
116
  throw new Error('Babel state is missing expected file name');
136
117
  }
137
-
138
118
  var filename = state.file.opts.filename;
139
119
  var relative = relativePath(dirname(filename), resolvePath(artifactDirectory));
140
120
  var relativeReference = relative.length === 0 || !relative.startsWith('.') ? './' : '';
141
121
  return relativeReference + joinPath(relative, fileToRequire);
142
122
  }
143
-
144
123
  module.exports = compileGraphQLTag;
@@ -6,40 +6,34 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
11
+
10
12
  'use strict';
11
13
 
12
14
  var GraphQL = require('graphql');
15
+
13
16
  /**
14
17
  * Given a babel AST path to a tagged template literal, return an AST if it is
15
18
  * a graphql literal being used in a valid way.
16
19
  * If it is some other type of template literal then return nothing.
17
20
  */
18
-
19
-
20
21
  function getValidGraphQLTag(path) {
21
22
  var tag = path.get('tag');
22
-
23
23
  if (!tag.isIdentifier({
24
24
  name: 'graphql'
25
25
  })) {
26
26
  return null;
27
27
  }
28
-
29
28
  var quasis = path.node.quasi.quasis;
30
-
31
29
  if (quasis.length !== 1) {
32
30
  throw new Error('BabelPluginRelay: Substitutions are not allowed in graphql fragments. ' + 'Included fragments should be referenced as `...MyModule_propName`.');
33
31
  }
34
-
35
32
  var text = quasis[0].value.raw;
36
33
  var ast = GraphQL.parse(text);
37
-
38
34
  if (ast.definitions.length === 0) {
39
35
  throw new Error('BabelPluginRelay: Unexpected empty graphql tag.');
40
36
  }
41
-
42
37
  return ast;
43
38
  }
44
-
45
39
  module.exports = getValidGraphQLTag;
package/macro.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Relay v14.1.0
2
+ * Relay v15.0.0
3
3
  *
4
4
  * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
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": "14.1.0",
4
+ "version": "15.0.0",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "relay",
@@ -22,7 +22,7 @@
22
22
  "graphql": "15.3.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@babel/core": "^7.14.0",
26
- "prettier": "^2.4.1"
25
+ "@babel/core": "^7.20.0",
26
+ "prettier": "2.7.1"
27
27
  }
28
28
  }