relay-compiler 1.3.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +16 -26
- package/bin/relay-compiler +7348 -5939
- package/index.js +3 -6
- package/lib/{FileParser.js → ASTCache.js} +17 -14
- package/lib/ASTConvert.js +84 -70
- package/lib/CodegenDirectory.js +122 -28
- package/lib/{RelayCodegenRunner.js → CodegenRunner.js} +110 -186
- package/lib/CodegenTypes.js +12 -0
- package/lib/{RelayCodegenWatcher.js → CodegenWatcher.js} +53 -43
- package/lib/DefaultHandleKey.js +2 -4
- package/lib/DotGraphQLParser.js +27 -0
- package/lib/FilterDirectivesTransform.js +11 -11
- package/lib/FindGraphQLTags.js +33 -52
- package/lib/FlattenTransform.js +197 -0
- package/lib/GraphQLCompilerContext.js +158 -0
- package/lib/GraphQLCompilerProfiler.js +271 -0
- package/lib/GraphQLCompilerPublic.js +27 -22
- package/lib/GraphQLCompilerUserError.js +26 -0
- package/lib/GraphQLConsoleReporter.js +58 -0
- package/lib/GraphQLIR.js +12 -0
- package/lib/{RelayPrinter.js → GraphQLIRPrinter.js} +42 -38
- package/lib/{RelayIRTransformer.js → GraphQLIRTransformer.js} +47 -38
- package/lib/GraphQLIRTransforms.js +6 -15
- package/lib/{RelayIRVisitor.js → GraphQLIRVisitor.js} +7 -6
- package/lib/GraphQLMultiReporter.js +50 -0
- package/lib/GraphQLParser.js +743 -0
- package/lib/GraphQLReporter.js +12 -0
- package/lib/GraphQLSchemaUtils.js +10 -36
- package/lib/GraphQLValidator.js +13 -15
- package/lib/{RelayWatchmanClient.js → GraphQLWatchmanClient.js} +15 -17
- package/lib/InlineFragmentsTransform.js +48 -0
- package/lib/PatchedBabelGenerator.js +58 -0
- package/lib/RelayApplyFragmentArgumentTransform.js +37 -18
- package/lib/RelayCodeGenerator.js +130 -60
- package/lib/RelayCompilerBin.js +80 -35
- package/lib/RelayCompilerCache.js +18 -11
- package/lib/RelayCompilerPublic.js +24 -10
- package/lib/RelayCompilerScope.js +2 -4
- package/lib/RelayConcreteNode.js +31 -14
- package/lib/RelayConnectionConstants.js +2 -4
- package/lib/RelayConnectionTransform.js +34 -38
- package/lib/RelayDefaultHandleKey.js +2 -4
- package/lib/RelayDeferrableFragmentTransform.js +464 -0
- package/lib/RelayError.js +2 -6
- package/lib/RelayFieldHandleTransform.js +15 -11
- package/lib/RelayFileWriter.js +119 -98
- package/lib/RelayFlowBabelFactories.js +113 -0
- package/lib/RelayFlowGenerator.js +180 -200
- package/lib/RelayFlowTypeTransformers.js +109 -0
- package/lib/RelayGenerateIDFieldTransform.js +131 -0
- package/lib/RelayGenerateTypeNameTransform.js +75 -0
- package/lib/RelayGraphQLEnumsGenerator.js +65 -0
- package/lib/RelayIRTransforms.js +19 -23
- package/lib/RelayInternalTypes.js +2 -5
- package/lib/RelayInternals.js +2 -5
- package/lib/RelayJSModuleParser.js +64 -0
- package/lib/RelayMaskTransform.js +129 -0
- package/lib/RelayMetricsRecorder.js +9 -9
- package/lib/RelayMockRenderer.js +3 -8
- package/lib/RelayNetworkDebug.js +4 -7
- package/lib/RelayParser.js +28 -645
- package/lib/RelayProfiler.js +7 -7
- package/lib/RelayQueryCaching.js +2 -5
- package/lib/RelayRelayDirectiveTransform.js +47 -33
- package/lib/RelayRuntimeTypes.js +22 -0
- package/lib/RelayShallowMock.js +4 -7
- package/lib/RelaySkipHandleFieldTransform.js +13 -11
- package/lib/RelayTaskQueue.js +2 -5
- package/lib/RelayTransformUtils.js +20 -0
- package/lib/RelayTypes.js +2 -5
- package/lib/RelayValidator.js +9 -8
- package/lib/RelayViewerHandleTransform.js +22 -18
- package/lib/SkipClientFieldTransform.js +36 -53
- package/lib/SkipRedundantNodesTransform.js +22 -29
- package/lib/SkipUnreachableNodeTransform.js +57 -36
- package/lib/SourceControl.js +61 -0
- package/lib/StripUnusedVariablesTransform.js +86 -41
- package/lib/areEqualOSS.js +2 -4
- package/lib/compileRelayArtifacts.js +72 -0
- package/lib/dedent.js +2 -5
- package/lib/dedupeJSONStringify.js +132 -0
- package/lib/deepFreeze.js +3 -5
- package/lib/deepMergeAssignments.js +68 -0
- package/lib/filterContextForNode.js +5 -7
- package/lib/formatGeneratedModule.js +5 -9
- package/lib/{getIdentifierForRelayArgumentValue.js → getIdentifierForArgumentValue.js} +8 -10
- package/lib/getIdentifierForSelection.js +37 -0
- package/lib/getLiteralArgumentValues.js +26 -0
- package/lib/getModuleName.js +2 -4
- package/lib/getRelayHandleKey.js +2 -4
- package/lib/isCompatibleRelayFragmentType.js +2 -5
- package/lib/isEquivalentType.js +55 -0
- package/lib/isPromise.js +2 -5
- package/lib/isScalarAndEqual.js +3 -5
- package/lib/murmurHash.js +2 -4
- package/lib/nullthrowsOSS.js +7 -5
- package/lib/recycleNodesInto.js +2 -4
- package/lib/relayUnstableBatchedUpdates.js +2 -5
- package/lib/relayUnstableBatchedUpdates.native.js +2 -5
- package/lib/requestsForOperation.js +75 -0
- package/lib/simpleClone.js +2 -4
- package/lib/stableCopy.js +35 -0
- package/lib/testEditDistance.js +2 -5
- package/lib/throwFailedPromise.js +2 -5
- package/lib/writeRelayGeneratedFile.js +84 -50
- package/package.json +16 -15
- package/relay-compiler.js +7208 -5872
- package/relay-compiler.min.js +7200 -5867
- package/ARCHITECTURE.md +0 -94
- package/PATENTS +0 -33
- package/lib/AutoAliasTransform.js +0 -80
- package/lib/GraphQLFileParser.js +0 -27
- package/lib/GraphQLTextParser.js +0 -46
- package/lib/RelayCodegenTypes.js +0 -14
- package/lib/RelayCompiledTypes.js +0 -13
- package/lib/RelayCompiler.js +0 -144
- package/lib/RelayCompilerContext.js +0 -133
- package/lib/RelayCompilerUserError.js +0 -30
- package/lib/RelayConsoleReporter.js +0 -40
- package/lib/RelayFileIRParser.js +0 -66
- package/lib/RelayFlattenTransform.js +0 -278
- package/lib/RelayFlowParser.js +0 -188
- package/lib/RelayGenerateRequisiteFieldsTransform.js +0 -189
- package/lib/RelayIR.js +0 -14
- package/lib/RelayMultiReporter.js +0 -40
- package/lib/RelayReporter.js +0 -14
- package/lib/RelayTestSchema.js +0 -21
- package/lib/formatStorageKey.js +0 -37
- package/lib/getIdentifierForRelaySelection.js +0 -54
- package/lib/getRelayLiteralArgumentValues.js +0 -28
- package/lib/parseGraphQLText.js +0 -33
- package/lib/prettyStringify.js +0 -35
- package/lib/printFlowTypes.js +0 -282
- package/lib/stableJSONStringify.js +0 -45
- package/lib/stableJSONStringifyOSS.js +0 -44
- package/lib/transformInputObjectToIR.js +0 -85
- package/lib/writeLegacyFlowFile.js +0 -24
package/index.js
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
/**
|
2
|
-
* Relay v1.
|
2
|
+
* Relay v1.5.0
|
3
3
|
*
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
5
|
-
* All rights reserved.
|
6
|
-
*
|
7
|
-
* This source code is licensed under the BSD-style license found in the
|
8
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
9
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
10
5
|
*
|
6
|
+
* This source code is licensed under the MIT license found in the
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
11
8
|
*/
|
12
9
|
|
13
10
|
module.exports = require('./lib/RelayCompilerPublic.js');
|
@@ -1,12 +1,10 @@
|
|
1
1
|
/**
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
3
|
*
|
5
|
-
* This source code is licensed under the
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
8
6
|
*
|
9
|
-
* @providesModule
|
7
|
+
* @providesModule ASTCache
|
10
8
|
*
|
11
9
|
* @format
|
12
10
|
*/
|
@@ -20,31 +18,36 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
|
|
20
18
|
var _require = require('immutable'),
|
21
19
|
ImmutableMap = _require.Map;
|
22
20
|
|
23
|
-
var
|
24
|
-
function
|
25
|
-
(0, _classCallCheck3['default'])(this,
|
26
|
-
this._documents = new Map();
|
21
|
+
var ASTCache = function () {
|
22
|
+
function ASTCache(config) {
|
23
|
+
(0, _classCallCheck3['default'])(this, ASTCache);
|
27
24
|
|
25
|
+
this._documents = new Map();
|
28
26
|
this._baseDir = config.baseDir;
|
29
|
-
this._parse = config.parse;
|
27
|
+
this._parse = require('./GraphQLCompilerProfiler').instrument(config.parse, 'ASTCache.parseFn');
|
30
28
|
}
|
31
29
|
|
32
30
|
// Short-term: we don't do subscriptions/delta updates, instead always use all definitions
|
33
31
|
|
34
32
|
|
35
|
-
|
33
|
+
ASTCache.prototype.documents = function documents() {
|
36
34
|
return ImmutableMap(this._documents);
|
37
35
|
};
|
38
36
|
|
39
37
|
// parse should return the set of changes
|
40
38
|
|
41
39
|
|
42
|
-
|
40
|
+
ASTCache.prototype.parseFiles = function parseFiles(files) {
|
43
41
|
var _this = this;
|
44
42
|
|
45
43
|
var documents = ImmutableMap();
|
46
44
|
|
47
45
|
files.forEach(function (file) {
|
46
|
+
if (!file.exists) {
|
47
|
+
_this._documents['delete'](file.relPath);
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
|
48
51
|
var doc = function () {
|
49
52
|
try {
|
50
53
|
return _this._parse(_this._baseDir, file);
|
@@ -65,7 +68,7 @@ var FileParser = function () {
|
|
65
68
|
return documents;
|
66
69
|
};
|
67
70
|
|
68
|
-
return
|
71
|
+
return ASTCache;
|
69
72
|
}();
|
70
73
|
|
71
|
-
module.exports =
|
74
|
+
module.exports = ASTCache;
|
package/lib/ASTConvert.js
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
/**
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
3
|
*
|
5
|
-
* This source code is licensed under the
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
8
6
|
*
|
9
7
|
* @providesModule ASTConvert
|
10
8
|
*
|
@@ -18,7 +16,7 @@ var _toConsumableArray3 = _interopRequireDefault(require('babel-runtime/helpers/
|
|
18
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
19
17
|
|
20
18
|
var _require = require('./GraphQLSchemaUtils'),
|
21
|
-
|
19
|
+
isExecutableDefinitionAST = _require.isExecutableDefinitionAST,
|
22
20
|
isSchemaDefinitionAST = _require.isSchemaDefinitionAST;
|
23
21
|
|
24
22
|
var _require2 = require('graphql'),
|
@@ -26,72 +24,86 @@ var _require2 = require('graphql'),
|
|
26
24
|
parse = _require2.parse,
|
27
25
|
visit = _require2.visit;
|
28
26
|
|
29
|
-
function convertASTDocuments(schema, documents, validationRules) {
|
30
|
-
|
27
|
+
function convertASTDocuments(schema, documents, validationRules, transform) {
|
28
|
+
return require('./GraphQLCompilerProfiler').run('ASTConvert.convertASTDocuments', function () {
|
29
|
+
var definitions = definitionsFromDocuments(documents);
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
var astDefinitions = [];
|
32
|
+
documents.forEach(function (doc) {
|
33
|
+
doc.definitions.forEach(function (definition) {
|
34
|
+
if (isExecutableDefinitionAST(definition)) {
|
35
|
+
astDefinitions.push(definition);
|
36
|
+
}
|
37
|
+
});
|
38
38
|
});
|
39
|
-
});
|
40
39
|
|
41
|
-
|
40
|
+
return convertASTDefinitions(schema, definitions, validationRules, transform);
|
41
|
+
});
|
42
42
|
}
|
43
43
|
|
44
|
-
function convertASTDocumentsWithBase(schema, baseDocuments, documents, validationRules) {
|
45
|
-
|
46
|
-
|
44
|
+
function convertASTDocumentsWithBase(schema, baseDocuments, documents, validationRules, transform) {
|
45
|
+
return require('./GraphQLCompilerProfiler').run('ASTConvert.convertASTDocumentsWithBase', function () {
|
46
|
+
var baseDefinitions = definitionsFromDocuments(baseDocuments);
|
47
|
+
var definitions = definitionsFromDocuments(documents);
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
var requiredDefinitions = new Map();
|
50
|
+
var baseMap = new Map();
|
51
|
+
baseDefinitions.forEach(function (definition) {
|
52
|
+
if (isExecutableDefinitionAST(definition)) {
|
53
|
+
var definitionName = definition.name && definition.name.value;
|
53
54
|
// If there's no name, no reason to put in the map
|
54
|
-
|
55
|
+
if (definitionName) {
|
56
|
+
if (baseMap.has(definitionName)) {
|
57
|
+
throw new Error('Duplicate definition of \'' + definitionName + '\'.');
|
58
|
+
}
|
59
|
+
baseMap.set(definitionName, definition);
|
60
|
+
}
|
55
61
|
}
|
56
|
-
}
|
57
|
-
});
|
62
|
+
});
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
}
|
64
|
-
});
|
65
|
-
while (definitionsToVisit.length > 0) {
|
66
|
-
var definition = definitionsToVisit.pop();
|
67
|
-
var name = definition.name;
|
68
|
-
if (!name || requiredDefinitions.has(name.value)) {
|
69
|
-
continue;
|
70
|
-
}
|
71
|
-
requiredDefinitions.set(name.value, definition);
|
72
|
-
visit(definition, {
|
73
|
-
FragmentSpread: function FragmentSpread(spread) {
|
74
|
-
var baseDefinition = baseMap.get(spread.name.value);
|
75
|
-
if (baseDefinition) {
|
76
|
-
// We only need to add those definitions not already included
|
77
|
-
// in definitions
|
78
|
-
definitionsToVisit.push(baseDefinition);
|
79
|
-
}
|
64
|
+
var definitionsToVisit = [];
|
65
|
+
definitions.forEach(function (definition) {
|
66
|
+
if (isExecutableDefinitionAST(definition)) {
|
67
|
+
definitionsToVisit.push(definition);
|
80
68
|
}
|
81
69
|
});
|
82
|
-
|
70
|
+
while (definitionsToVisit.length > 0) {
|
71
|
+
var _definition = definitionsToVisit.pop();
|
72
|
+
var name = _definition.name && _definition.name.value;
|
73
|
+
if (!name) {
|
74
|
+
continue;
|
75
|
+
}
|
76
|
+
if (requiredDefinitions.has(name)) {
|
77
|
+
if (requiredDefinitions.get(name) !== _definition) {
|
78
|
+
throw new Error('Duplicate definition of \'' + name + '\'.');
|
79
|
+
}
|
80
|
+
continue;
|
81
|
+
}
|
82
|
+
requiredDefinitions.set(name, _definition);
|
83
|
+
visit(_definition, {
|
84
|
+
FragmentSpread: function FragmentSpread(spread) {
|
85
|
+
var baseDefinition = baseMap.get(spread.name.value);
|
86
|
+
if (baseDefinition) {
|
87
|
+
// We only need to add those definitions not already included
|
88
|
+
// in definitions
|
89
|
+
definitionsToVisit.push(baseDefinition);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
});
|
93
|
+
}
|
83
94
|
|
84
|
-
|
85
|
-
|
86
|
-
|
95
|
+
var definitionsToConvert = [];
|
96
|
+
requiredDefinitions.forEach(function (definition) {
|
97
|
+
return definitionsToConvert.push(definition);
|
98
|
+
});
|
99
|
+
return convertASTDefinitions(schema, definitionsToConvert, validationRules, transform);
|
87
100
|
});
|
88
|
-
return convertASTDefinitions(schema, definitionsToConvert, validationRules);
|
89
101
|
}
|
90
102
|
|
91
|
-
function convertASTDefinitions(schema, definitions, validationRules) {
|
103
|
+
function convertASTDefinitions(schema, definitions, validationRules, transform) {
|
92
104
|
var operationDefinitions = [];
|
93
105
|
definitions.forEach(function (definition) {
|
94
|
-
if (
|
106
|
+
if (isExecutableDefinitionAST(definition)) {
|
95
107
|
operationDefinitions.push(definition);
|
96
108
|
}
|
97
109
|
});
|
@@ -105,7 +117,7 @@ function convertASTDefinitions(schema, definitions, validationRules) {
|
|
105
117
|
// Will throw an error if there are validation issues
|
106
118
|
require('./GraphQLValidator').validate(validationAST, schema, validationRules);
|
107
119
|
return operationDefinitions.map(function (definition) {
|
108
|
-
return
|
120
|
+
return transform(schema, definition);
|
109
121
|
});
|
110
122
|
}
|
111
123
|
|
@@ -120,26 +132,28 @@ function definitionsFromDocuments(documents) {
|
|
120
132
|
}
|
121
133
|
|
122
134
|
function transformASTSchema(schema, schemaExtensions) {
|
123
|
-
return
|
135
|
+
return require('./GraphQLCompilerProfiler').run('ASTConvert.transformASTSchema', function () {
|
136
|
+
return schemaExtensions.length > 0 ? extendSchema(schema, parse(schemaExtensions.join('\n'))) : schema;
|
137
|
+
});
|
124
138
|
}
|
125
139
|
|
126
140
|
function extendASTSchema(baseSchema, documents) {
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
141
|
+
return require('./GraphQLCompilerProfiler').run('ASTConvert.extendASTSchema', function () {
|
142
|
+
// Should be TypeSystemDefinitionNode
|
143
|
+
var schemaExtensions = [];
|
144
|
+
documents.forEach(function (doc) {
|
145
|
+
schemaExtensions.push.apply(schemaExtensions, (0, _toConsumableArray3['default'])(doc.definitions.filter(isSchemaDefinitionAST)));
|
146
|
+
});
|
133
147
|
|
134
|
-
|
135
|
-
|
136
|
-
|
148
|
+
if (schemaExtensions.length <= 0) {
|
149
|
+
return baseSchema;
|
150
|
+
}
|
137
151
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
152
|
+
// TODO T24511737 figure out if this is dangerous
|
153
|
+
return extendSchema(baseSchema, {
|
154
|
+
kind: 'Document',
|
155
|
+
definitions: schemaExtensions
|
156
|
+
}, { assumeValid: true });
|
143
157
|
});
|
144
158
|
}
|
145
159
|
|
package/lib/CodegenDirectory.js
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
/**
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
3
|
-
* All rights reserved.
|
4
3
|
*
|
5
|
-
* This source code is licensed under the
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
8
6
|
*
|
9
7
|
* @providesModule CodegenDirectory
|
10
8
|
*
|
@@ -13,8 +11,14 @@
|
|
13
11
|
|
14
12
|
'use strict';
|
15
13
|
|
14
|
+
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
15
|
+
|
16
|
+
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
17
|
+
|
16
18
|
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
17
19
|
|
20
|
+
var _toConsumableArray3 = _interopRequireDefault(require('babel-runtime/helpers/toConsumableArray'));
|
21
|
+
|
18
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
19
23
|
|
20
24
|
/**
|
@@ -52,7 +56,15 @@ var CodegenDirectory = function () {
|
|
52
56
|
if (require('fs').existsSync(dir)) {
|
53
57
|
require('fbjs/lib/invariant')(require('fs').statSync(dir).isDirectory(), 'Expected `%s` to be a directory.', dir);
|
54
58
|
} else if (!this.onlyValidate) {
|
55
|
-
|
59
|
+
var dirs = [dir];
|
60
|
+
var parent = require('path').dirname(dir);
|
61
|
+
while (!require('fs').existsSync(parent)) {
|
62
|
+
dirs.unshift(parent);
|
63
|
+
parent = require('path').dirname(parent);
|
64
|
+
}
|
65
|
+
dirs.forEach(function (d) {
|
66
|
+
return require('fs').mkdirSync(d);
|
67
|
+
});
|
56
68
|
}
|
57
69
|
this._files = new Set();
|
58
70
|
this.changes = {
|
@@ -64,6 +76,82 @@ var CodegenDirectory = function () {
|
|
64
76
|
this._dir = dir;
|
65
77
|
}
|
66
78
|
|
79
|
+
CodegenDirectory.combineChanges = function combineChanges(dirs) {
|
80
|
+
var changes = {
|
81
|
+
deleted: [],
|
82
|
+
updated: [],
|
83
|
+
created: [],
|
84
|
+
unchanged: []
|
85
|
+
};
|
86
|
+
dirs.forEach(function (dir) {
|
87
|
+
var _changes$deleted, _changes$updated, _changes$created, _changes$unchanged;
|
88
|
+
|
89
|
+
(_changes$deleted = changes.deleted).push.apply(_changes$deleted, (0, _toConsumableArray3['default'])(dir.changes.deleted));
|
90
|
+
(_changes$updated = changes.updated).push.apply(_changes$updated, (0, _toConsumableArray3['default'])(dir.changes.updated));
|
91
|
+
(_changes$created = changes.created).push.apply(_changes$created, (0, _toConsumableArray3['default'])(dir.changes.created));
|
92
|
+
(_changes$unchanged = changes.unchanged).push.apply(_changes$unchanged, (0, _toConsumableArray3['default'])(dir.changes.unchanged));
|
93
|
+
});
|
94
|
+
return changes;
|
95
|
+
};
|
96
|
+
|
97
|
+
CodegenDirectory.hasChanges = function hasChanges(changes) {
|
98
|
+
return changes.created.length > 0 || changes.updated.length > 0 || changes.deleted.length > 0;
|
99
|
+
};
|
100
|
+
|
101
|
+
CodegenDirectory.printChanges = function printChanges(changes, options) {
|
102
|
+
require('./GraphQLCompilerProfiler').run('CodegenDirectory.printChanges', function () {
|
103
|
+
var output = [];
|
104
|
+
function printFiles(label, files) {
|
105
|
+
if (files.length > 0) {
|
106
|
+
output.push(label + ':');
|
107
|
+
files.forEach(function (file) {
|
108
|
+
output.push(' - ' + file);
|
109
|
+
});
|
110
|
+
}
|
111
|
+
}
|
112
|
+
if (options.onlyValidate) {
|
113
|
+
printFiles('Missing', changes.created);
|
114
|
+
printFiles('Out of date', changes.updated);
|
115
|
+
printFiles('Extra', changes.deleted);
|
116
|
+
} else {
|
117
|
+
printFiles('Created', changes.created);
|
118
|
+
printFiles('Updated', changes.updated);
|
119
|
+
printFiles('Deleted', changes.deleted);
|
120
|
+
output.push('Unchanged: ' + changes.unchanged.length + ' files');
|
121
|
+
}
|
122
|
+
// eslint-disable-next-line no-console
|
123
|
+
console.log(output.join('\n'));
|
124
|
+
});
|
125
|
+
};
|
126
|
+
|
127
|
+
CodegenDirectory.sourceControlAddRemove = (() => {
|
128
|
+
var _ref = (0, _asyncToGenerator3.default)(function* (sourceControl, dirs) {
|
129
|
+
var allAdded = [];
|
130
|
+
var allRemoved = [];
|
131
|
+
dirs.forEach(function (dir) {
|
132
|
+
dir.changes.created.forEach(function (name) {
|
133
|
+
allAdded.push(dir.getPath(name));
|
134
|
+
});
|
135
|
+
dir.changes.deleted.forEach(function (name) {
|
136
|
+
allRemoved.push(dir.getPath(name));
|
137
|
+
});
|
138
|
+
});
|
139
|
+
sourceControl.addRemove(allAdded, allRemoved);
|
140
|
+
});
|
141
|
+
|
142
|
+
function sourceControlAddRemove(_x2, _x3) {
|
143
|
+
return _ref.apply(this, arguments);
|
144
|
+
}
|
145
|
+
|
146
|
+
return sourceControlAddRemove;
|
147
|
+
})();
|
148
|
+
|
149
|
+
CodegenDirectory.prototype.printChanges = function printChanges() {
|
150
|
+
CodegenDirectory.printChanges(this.changes, {
|
151
|
+
onlyValidate: this.onlyValidate
|
152
|
+
});
|
153
|
+
};
|
154
|
+
|
67
155
|
CodegenDirectory.prototype.read = function read(filename) {
|
68
156
|
var filePath = require('path').join(this._dir, filename);
|
69
157
|
if (require('fs').existsSync(filePath)) {
|
@@ -90,20 +178,24 @@ var CodegenDirectory = function () {
|
|
90
178
|
};
|
91
179
|
|
92
180
|
CodegenDirectory.prototype.writeFile = function writeFile(filename, content) {
|
93
|
-
this
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
181
|
+
var _this = this;
|
182
|
+
|
183
|
+
require('./GraphQLCompilerProfiler').run('CodegenDirectory.writeFile', function () {
|
184
|
+
_this._addGenerated(filename);
|
185
|
+
var filePath = require('path').join(_this._dir, filename);
|
186
|
+
if (require('fs').existsSync(filePath)) {
|
187
|
+
var existingContent = require('fs').readFileSync(filePath, 'utf8');
|
188
|
+
if (existingContent === content) {
|
189
|
+
_this.changes.unchanged.push(filename);
|
190
|
+
} else {
|
191
|
+
_this._writeFile(filePath, content);
|
192
|
+
_this.changes.updated.push(filename);
|
193
|
+
}
|
99
194
|
} else {
|
100
|
-
|
101
|
-
|
195
|
+
_this._writeFile(filePath, content);
|
196
|
+
_this.changes.created.push(filename);
|
102
197
|
}
|
103
|
-
}
|
104
|
-
this._writeFile(filePath, content);
|
105
|
-
this.changes.created.push(filename);
|
106
|
-
}
|
198
|
+
});
|
107
199
|
};
|
108
200
|
|
109
201
|
CodegenDirectory.prototype._writeFile = function _writeFile(filePath, content) {
|
@@ -119,19 +211,21 @@ var CodegenDirectory = function () {
|
|
119
211
|
|
120
212
|
|
121
213
|
CodegenDirectory.prototype.deleteExtraFiles = function deleteExtraFiles() {
|
122
|
-
var
|
123
|
-
|
124
|
-
require('
|
125
|
-
|
126
|
-
if (!
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
214
|
+
var _this2 = this;
|
215
|
+
|
216
|
+
require('./GraphQLCompilerProfiler').run('CodegenDirectory.deleteExtraFiles', function () {
|
217
|
+
require('fs').readdirSync(_this2._dir).forEach(function (actualFile) {
|
218
|
+
if (!_this2._files.has(actualFile) && !/^\./.test(actualFile)) {
|
219
|
+
if (!_this2.onlyValidate) {
|
220
|
+
try {
|
221
|
+
require('fs').unlinkSync(require('path').join(_this2._dir, actualFile));
|
222
|
+
} catch (e) {
|
223
|
+
throw new Error('CodegenDirectory: Failed to delete `' + actualFile + '` in `' + _this2._dir + '`.');
|
224
|
+
}
|
131
225
|
}
|
226
|
+
_this2.changes.deleted.push(actualFile);
|
132
227
|
}
|
133
|
-
|
134
|
-
}
|
228
|
+
});
|
135
229
|
});
|
136
230
|
};
|
137
231
|
|