relay-compiler 0.0.0-main-f0b65f0b → 0.0.0-main-e0026a71
Sign up to get free protection for your applications and to get access to all the features.
- package/cli.js +23 -0
- package/index.js +19 -3
- package/linux-x64/relay +0 -0
- package/macos-x64/relay +0 -0
- package/package.json +2 -24
- package/win-x64/relay.exe +0 -0
- package/bin/RelayCompilerBin.js.flow +0 -168
- package/bin/RelayCompilerMain.js.flow +0 -515
- package/bin/__fixtures__/plugin-module.js.flow +0 -17
- package/bin/relay-compiler +0 -19068
- package/codegen/CodegenDirectory.js.flow +0 -372
- package/codegen/CodegenRunner.js.flow +0 -424
- package/codegen/CodegenTypes.js.flow +0 -28
- package/codegen/CodegenWatcher.js.flow +0 -250
- package/codegen/NormalizationCodeGenerator.js.flow +0 -566
- package/codegen/ReaderCodeGenerator.js.flow +0 -510
- package/codegen/RelayCodeGenerator.js.flow +0 -85
- package/codegen/RelayFileWriter.js.flow +0 -365
- package/codegen/SourceControl.js.flow +0 -58
- package/codegen/compileRelayArtifacts.js.flow +0 -181
- package/codegen/createPrintRequireModuleDependency.js.flow +0 -19
- package/codegen/sortObjectByKey.js.flow +0 -25
- package/codegen/writeRelayGeneratedFile.js.flow +0 -235
- package/core/ASTCache.js.flow +0 -73
- package/core/ASTConvert.js.flow +0 -230
- package/core/CompilerContext.js.flow +0 -189
- package/core/CompilerError.js.flow +0 -255
- package/core/DotGraphQLParser.js.flow +0 -37
- package/core/GraphQLCompilerProfiler.js.flow +0 -341
- package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
- package/core/GraphQLWatchmanClient.js.flow +0 -109
- package/core/IR.js.flow +0 -326
- package/core/IRPrinter.js.flow +0 -472
- package/core/IRTransformer.js.flow +0 -376
- package/core/IRValidator.js.flow +0 -259
- package/core/IRVisitor.js.flow +0 -150
- package/core/JSModuleParser.js.flow +0 -24
- package/core/RelayCompilerScope.js.flow +0 -199
- package/core/RelayFindGraphQLTags.js.flow +0 -118
- package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
- package/core/RelayIRTransforms.js.flow +0 -138
- package/core/RelayParser.js.flow +0 -1741
- package/core/RelaySourceModuleParser.js.flow +0 -133
- package/core/Schema.js.flow +0 -2035
- package/core/SchemaUtils.js.flow +0 -120
- package/core/filterContextForNode.js.flow +0 -49
- package/core/getFieldDefinition.js.flow +0 -156
- package/core/getIdentifierForArgumentValue.js.flow +0 -49
- package/core/getIdentifierForSelection.js.flow +0 -68
- package/core/getLiteralArgumentValues.js.flow +0 -32
- package/core/getNormalizationOperationName.js.flow +0 -19
- package/core/inferRootArgumentDefinitions.js.flow +0 -322
- package/index.js.flow +0 -198
- package/language/RelayLanguagePluginInterface.js.flow +0 -283
- package/language/javascript/FindGraphQLTags.js.flow +0 -136
- package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
- package/language/javascript/RelayFlowGenerator.js.flow +0 -1096
- package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -181
- package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -33
- package/language/javascript/formatGeneratedModule.js.flow +0 -65
- package/lib/bin/RelayCompilerBin.js +0 -143
- package/lib/bin/RelayCompilerMain.js +0 -488
- package/lib/bin/__fixtures__/plugin-module.js +0 -16
- package/lib/codegen/CodegenDirectory.js +0 -335
- package/lib/codegen/CodegenRunner.js +0 -433
- package/lib/codegen/CodegenTypes.js +0 -11
- package/lib/codegen/CodegenWatcher.js +0 -271
- package/lib/codegen/NormalizationCodeGenerator.js +0 -487
- package/lib/codegen/ReaderCodeGenerator.js +0 -473
- package/lib/codegen/RelayCodeGenerator.js +0 -75
- package/lib/codegen/RelayFileWriter.js +0 -270
- package/lib/codegen/SourceControl.js +0 -60
- package/lib/codegen/compileRelayArtifacts.js +0 -157
- package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
- package/lib/codegen/sortObjectByKey.js +0 -41
- package/lib/codegen/writeRelayGeneratedFile.js +0 -206
- package/lib/core/ASTCache.js +0 -70
- package/lib/core/ASTConvert.js +0 -198
- package/lib/core/CompilerContext.js +0 -165
- package/lib/core/CompilerError.js +0 -252
- package/lib/core/DotGraphQLParser.js +0 -40
- package/lib/core/GraphQLCompilerProfiler.js +0 -299
- package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
- package/lib/core/GraphQLWatchmanClient.js +0 -150
- package/lib/core/IR.js +0 -11
- package/lib/core/IRPrinter.js +0 -388
- package/lib/core/IRTransformer.js +0 -345
- package/lib/core/IRValidator.js +0 -226
- package/lib/core/IRVisitor.js +0 -45
- package/lib/core/JSModuleParser.js +0 -18
- package/lib/core/RelayCompilerScope.js +0 -183
- package/lib/core/RelayFindGraphQLTags.js +0 -79
- package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
- package/lib/core/RelayIRTransforms.js +0 -109
- package/lib/core/RelayParser.js +0 -1381
- package/lib/core/RelaySourceModuleParser.js +0 -104
- package/lib/core/Schema.js +0 -1877
- package/lib/core/SchemaUtils.js +0 -98
- package/lib/core/filterContextForNode.js +0 -50
- package/lib/core/getFieldDefinition.js +0 -145
- package/lib/core/getIdentifierForArgumentValue.js +0 -54
- package/lib/core/getIdentifierForSelection.js +0 -49
- package/lib/core/getLiteralArgumentValues.js +0 -26
- package/lib/core/getNormalizationOperationName.js +0 -17
- package/lib/core/inferRootArgumentDefinitions.js +0 -351
- package/lib/index.js +0 -178
- package/lib/language/RelayLanguagePluginInterface.js +0 -26
- package/lib/language/javascript/FindGraphQLTags.js +0 -126
- package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
- package/lib/language/javascript/RelayFlowGenerator.js +0 -856
- package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
- package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
- package/lib/language/javascript/formatGeneratedModule.js +0 -36
- package/lib/reporters/ConsoleReporter.js +0 -61
- package/lib/reporters/MultiReporter.js +0 -45
- package/lib/reporters/Reporter.js +0 -11
- package/lib/runner/Artifacts.js +0 -323
- package/lib/runner/BufferedFilesystem.js +0 -262
- package/lib/runner/GraphQLASTNodeGroup.js +0 -256
- package/lib/runner/GraphQLASTUtils.js +0 -23
- package/lib/runner/GraphQLNodeMap.js +0 -81
- package/lib/runner/Sources.js +0 -271
- package/lib/runner/StrictMap.js +0 -134
- package/lib/runner/compileArtifacts.js +0 -39
- package/lib/runner/extractAST.js +0 -77
- package/lib/runner/getChangedNodeNames.js +0 -82
- package/lib/runner/getSchemaInstance.js +0 -30
- package/lib/runner/types.js +0 -12
- package/lib/test-utils/TestSchema.js +0 -27
- package/lib/test-utils/parseGraphQLText.js +0 -30
- package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
- package/lib/transforms/ClientExtensionsTransform.js +0 -221
- package/lib/transforms/ConnectionTransform.js +0 -639
- package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -218
- package/lib/transforms/DeferStreamTransform.js +0 -246
- package/lib/transforms/DisallowIdAsAlias.js +0 -40
- package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
- package/lib/transforms/FieldHandleTransform.js +0 -79
- package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
- package/lib/transforms/FilterDirectivesTransform.js +0 -42
- package/lib/transforms/FlattenTransform.js +0 -306
- package/lib/transforms/GenerateIDFieldTransform.js +0 -135
- package/lib/transforms/GenerateTypeNameTransform.js +0 -149
- package/lib/transforms/InlineDataFragmentTransform.js +0 -100
- package/lib/transforms/InlineFragmentsTransform.js +0 -61
- package/lib/transforms/MaskTransform.js +0 -117
- package/lib/transforms/MatchTransform.js +0 -434
- package/lib/transforms/ReactFlightComponentTransform.js +0 -158
- package/lib/transforms/RefetchableFragmentTransform.js +0 -249
- package/lib/transforms/RelayDirectiveTransform.js +0 -83
- package/lib/transforms/RequiredFieldTransform.js +0 -369
- package/lib/transforms/SkipClientExtensionsTransform.js +0 -46
- package/lib/transforms/SkipHandleFieldTransform.js +0 -45
- package/lib/transforms/SkipRedundantNodesTransform.js +0 -261
- package/lib/transforms/SkipSplitOperationTransform.js +0 -32
- package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
- package/lib/transforms/SkipUnusedVariablesTransform.js +0 -75
- package/lib/transforms/SplitModuleImportTransform.js +0 -82
- package/lib/transforms/TestOperationTransform.js +0 -144
- package/lib/transforms/TransformUtils.js +0 -21
- package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -92
- package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -114
- package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -108
- package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
- package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
- package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
- package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
- package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
- package/lib/transforms/query-generators/index.js +0 -60
- package/lib/transforms/query-generators/utils.js +0 -92
- package/lib/util/CodeMarker.js +0 -80
- package/lib/util/DefaultHandleKey.js +0 -15
- package/lib/util/RelayCompilerCache.js +0 -97
- package/lib/util/Rollout.js +0 -40
- package/lib/util/TimeReporter.js +0 -83
- package/lib/util/areEqualArgValues.js +0 -135
- package/lib/util/argumentContainsVariables.js +0 -37
- package/lib/util/dedupeJSONStringify.js +0 -160
- package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
- package/lib/util/getDefinitionNodeHash.js +0 -22
- package/lib/util/getModuleName.js +0 -32
- package/lib/util/joinArgumentDefinitions.js +0 -67
- package/lib/util/md5.js +0 -17
- package/lib/util/murmurHash.js +0 -86
- package/lib/util/nullthrowsOSS.js +0 -23
- package/lib/util/orList.js +0 -36
- package/lib/util/partitionArray.js +0 -35
- package/relay-compiler.js +0 -17
- package/relay-compiler.min.js +0 -22
- package/reporters/ConsoleReporter.js.flow +0 -81
- package/reporters/MultiReporter.js.flow +0 -43
- package/reporters/Reporter.js.flow +0 -19
- package/runner/Artifacts.js.flow +0 -215
- package/runner/BufferedFilesystem.js.flow +0 -194
- package/runner/GraphQLASTNodeGroup.js.flow +0 -174
- package/runner/GraphQLASTUtils.js.flow +0 -26
- package/runner/GraphQLNodeMap.js.flow +0 -55
- package/runner/Sources.js.flow +0 -227
- package/runner/StrictMap.js.flow +0 -96
- package/runner/compileArtifacts.js.flow +0 -75
- package/runner/extractAST.js.flow +0 -98
- package/runner/getChangedNodeNames.js.flow +0 -48
- package/runner/getSchemaInstance.js.flow +0 -36
- package/runner/types.js.flow +0 -37
- package/test-utils/TestSchema.js.flow +0 -30
- package/test-utils/parseGraphQLText.js.flow +0 -41
- package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -524
- package/transforms/ClientExtensionsTransform.js.flow +0 -224
- package/transforms/ConnectionTransform.js.flow +0 -850
- package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -245
- package/transforms/DeferStreamTransform.js.flow +0 -263
- package/transforms/DisallowIdAsAlias.js.flow +0 -46
- package/transforms/DisallowTypenameOnRoot.js.flow +0 -44
- package/transforms/FieldHandleTransform.js.flow +0 -77
- package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
- package/transforms/FilterDirectivesTransform.js.flow +0 -45
- package/transforms/FlattenTransform.js.flow +0 -458
- package/transforms/GenerateIDFieldTransform.js.flow +0 -151
- package/transforms/GenerateTypeNameTransform.js.flow +0 -159
- package/transforms/InlineDataFragmentTransform.js.flow +0 -123
- package/transforms/InlineFragmentsTransform.js.flow +0 -70
- package/transforms/MaskTransform.js.flow +0 -124
- package/transforms/MatchTransform.js.flow +0 -587
- package/transforms/ReactFlightComponentTransform.js.flow +0 -207
- package/transforms/RefetchableFragmentTransform.js.flow +0 -266
- package/transforms/RelayDirectiveTransform.js.flow +0 -96
- package/transforms/RequiredFieldTransform.js.flow +0 -413
- package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
- package/transforms/SkipHandleFieldTransform.js.flow +0 -44
- package/transforms/SkipRedundantNodesTransform.js.flow +0 -277
- package/transforms/SkipSplitOperationTransform.js.flow +0 -37
- package/transforms/SkipUnreachableNodeTransform.js.flow +0 -148
- package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
- package/transforms/SplitModuleImportTransform.js.flow +0 -97
- package/transforms/TestOperationTransform.js.flow +0 -142
- package/transforms/TransformUtils.js.flow +0 -26
- package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -80
- package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -130
- package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -128
- package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -88
- package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -188
- package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -217
- package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
- package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
- package/transforms/query-generators/index.js.flow +0 -89
- package/transforms/query-generators/utils.js.flow +0 -76
- package/util/CodeMarker.js.flow +0 -79
- package/util/DefaultHandleKey.js.flow +0 -17
- package/util/RelayCompilerCache.js.flow +0 -86
- package/util/Rollout.js.flow +0 -39
- package/util/TimeReporter.js.flow +0 -79
- package/util/areEqualArgValues.js.flow +0 -126
- package/util/argumentContainsVariables.js.flow +0 -38
- package/util/dedupeJSONStringify.js.flow +0 -156
- package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
- package/util/getDefinitionNodeHash.js.flow +0 -24
- package/util/getModuleName.js.flow +0 -39
- package/util/joinArgumentDefinitions.js.flow +0 -105
- package/util/md5.js.flow +0 -19
- package/util/murmurHash.js.flow +0 -94
- package/util/nullthrowsOSS.js.flow +0 -25
- package/util/orList.js.flow +0 -37
- package/util/partitionArray.js.flow +0 -37
@@ -1,433 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
|
-
'use strict';
|
12
|
-
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
14
|
-
|
15
|
-
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
16
|
-
|
17
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
18
|
-
|
19
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
20
|
-
|
21
|
-
var Profiler = require('../core/GraphQLCompilerProfiler');
|
22
|
-
|
23
|
-
var GraphQLWatchmanClient = require('../core/GraphQLWatchmanClient');
|
24
|
-
|
25
|
-
var _require = require('../core/Schema'),
|
26
|
-
createSchema = _require.create;
|
27
|
-
|
28
|
-
var CodegenDirectory = require('./CodegenDirectory');
|
29
|
-
|
30
|
-
var CodegenWatcher = require('./CodegenWatcher');
|
31
|
-
/* $FlowFixMe[untyped-import] - importing immutable, which is untyped (and flow
|
32
|
-
* is sad about it) */
|
33
|
-
|
34
|
-
|
35
|
-
var _require2 = require('immutable'),
|
36
|
-
ImmutableMap = _require2.Map;
|
37
|
-
|
38
|
-
var invariant = require('invariant');
|
39
|
-
|
40
|
-
var path = require('path');
|
41
|
-
|
42
|
-
var CodegenRunner = /*#__PURE__*/function () {
|
43
|
-
// parser => writers that are affected by it
|
44
|
-
function CodegenRunner(options) {
|
45
|
-
var _this = this;
|
46
|
-
|
47
|
-
this.parsers = {};
|
48
|
-
this.parserConfigs = options.parserConfigs;
|
49
|
-
this.writerConfigs = options.writerConfigs;
|
50
|
-
this.onlyValidate = options.onlyValidate;
|
51
|
-
this.onComplete = options.onComplete;
|
52
|
-
this._reporter = options.reporter;
|
53
|
-
this._sourceControl = options.sourceControl;
|
54
|
-
this.parserWriters = {};
|
55
|
-
|
56
|
-
for (var _parser in options.parserConfigs) {
|
57
|
-
this.parserWriters[_parser] = new Set();
|
58
|
-
}
|
59
|
-
|
60
|
-
var _loop = function _loop(_writer) {
|
61
|
-
var config = options.writerConfigs[_writer];
|
62
|
-
config.baseParsers && config.baseParsers.forEach(function (parser) {
|
63
|
-
return _this.parserWriters[parser].add(_writer);
|
64
|
-
});
|
65
|
-
|
66
|
-
_this.parserWriters[config.parser].add(_writer);
|
67
|
-
};
|
68
|
-
|
69
|
-
for (var _writer in options.writerConfigs) {
|
70
|
-
_loop(_writer);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
var _proto = CodegenRunner.prototype;
|
75
|
-
|
76
|
-
_proto.compileAll = /*#__PURE__*/function () {
|
77
|
-
var _compileAll = _asyncToGenerator(function* () {
|
78
|
-
// reset the parsers
|
79
|
-
this.parsers = {};
|
80
|
-
|
81
|
-
for (var parserName in this.parserConfigs) {
|
82
|
-
try {
|
83
|
-
yield this.parseEverything(parserName);
|
84
|
-
} catch (e) {
|
85
|
-
this._reporter.reportError('CodegenRunner.compileAll', e);
|
86
|
-
|
87
|
-
return 'ERROR';
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
var hasChanges = false;
|
92
|
-
|
93
|
-
for (var writerName in this.writerConfigs) {
|
94
|
-
var result = yield this.write(writerName);
|
95
|
-
|
96
|
-
if (result === 'ERROR') {
|
97
|
-
return 'ERROR';
|
98
|
-
}
|
99
|
-
|
100
|
-
if (result === 'HAS_CHANGES') {
|
101
|
-
hasChanges = true;
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
return hasChanges ? 'HAS_CHANGES' : 'NO_CHANGES';
|
106
|
-
});
|
107
|
-
|
108
|
-
function compileAll() {
|
109
|
-
return _compileAll.apply(this, arguments);
|
110
|
-
}
|
111
|
-
|
112
|
-
return compileAll;
|
113
|
-
}();
|
114
|
-
|
115
|
-
_proto.compile = /*#__PURE__*/function () {
|
116
|
-
var _compile = _asyncToGenerator(function* (writerName) {
|
117
|
-
var _this2 = this;
|
118
|
-
|
119
|
-
var writerConfig = this.writerConfigs[writerName];
|
120
|
-
var parsers = [writerConfig.parser];
|
121
|
-
|
122
|
-
if (writerConfig.baseParsers) {
|
123
|
-
writerConfig.baseParsers.forEach(function (parser) {
|
124
|
-
return parsers.push(parser);
|
125
|
-
});
|
126
|
-
} // Don't bother resetting the parsers
|
127
|
-
|
128
|
-
|
129
|
-
yield Profiler.asyncContext('CodegenRunner:parseEverything', function () {
|
130
|
-
return Promise.all(parsers.map(function (parser) {
|
131
|
-
return _this2.parseEverything(parser);
|
132
|
-
}));
|
133
|
-
});
|
134
|
-
return yield this.write(writerName);
|
135
|
-
});
|
136
|
-
|
137
|
-
function compile(_x) {
|
138
|
-
return _compile.apply(this, arguments);
|
139
|
-
}
|
140
|
-
|
141
|
-
return compile;
|
142
|
-
}();
|
143
|
-
|
144
|
-
_proto.getDirtyWriters = function getDirtyWriters(filePaths) {
|
145
|
-
var _this3 = this;
|
146
|
-
|
147
|
-
return Profiler.asyncContext('CodegenRunner:getDirtyWriters', /*#__PURE__*/_asyncToGenerator(function* () {
|
148
|
-
var dirtyWriters = new Set(); // Check if any files are in the output
|
149
|
-
|
150
|
-
for (var configName in _this3.writerConfigs) {
|
151
|
-
var config = _this3.writerConfigs[configName];
|
152
|
-
|
153
|
-
var _iterator = (0, _createForOfIteratorHelper2["default"])(filePaths),
|
154
|
-
_step;
|
155
|
-
|
156
|
-
try {
|
157
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
158
|
-
var _filePath = _step.value;
|
159
|
-
|
160
|
-
if (config.isGeneratedFile(_filePath)) {
|
161
|
-
dirtyWriters.add(configName);
|
162
|
-
}
|
163
|
-
}
|
164
|
-
} catch (err) {
|
165
|
-
_iterator.e(err);
|
166
|
-
} finally {
|
167
|
-
_iterator.f();
|
168
|
-
}
|
169
|
-
} // Check for files in the input
|
170
|
-
|
171
|
-
|
172
|
-
yield Promise.all(Object.keys(_this3.parserConfigs).map(function (parserConfigName) {
|
173
|
-
return Profiler.waitFor('Watchman:query', /*#__PURE__*/_asyncToGenerator(function* () {
|
174
|
-
var client = new GraphQLWatchmanClient();
|
175
|
-
var config = _this3.parserConfigs[parserConfigName];
|
176
|
-
var dirs = yield client.watchProject(config.baseDir);
|
177
|
-
var relativeFilePaths = filePaths.map(function (filePath) {
|
178
|
-
return path.relative(config.baseDir, filePath);
|
179
|
-
});
|
180
|
-
var query = {
|
181
|
-
expression: ['allof', config.watchmanExpression, ['name', relativeFilePaths, 'wholename']],
|
182
|
-
fields: ['exists'],
|
183
|
-
relative_root: dirs.relativePath
|
184
|
-
};
|
185
|
-
var result = yield client.command('query', dirs.root, query);
|
186
|
-
client.end();
|
187
|
-
|
188
|
-
if (result.files.length > 0) {
|
189
|
-
_this3.parserWriters[parserConfigName].forEach(function (writerName) {
|
190
|
-
return dirtyWriters.add(writerName);
|
191
|
-
});
|
192
|
-
}
|
193
|
-
}));
|
194
|
-
}));
|
195
|
-
return dirtyWriters;
|
196
|
-
}));
|
197
|
-
};
|
198
|
-
|
199
|
-
_proto.parseEverything = /*#__PURE__*/function () {
|
200
|
-
var _parseEverything = _asyncToGenerator(function* (parserName) {
|
201
|
-
if (this.parsers[parserName]) {
|
202
|
-
// no need to parse
|
203
|
-
return;
|
204
|
-
}
|
205
|
-
|
206
|
-
var parserConfig = this.parserConfigs[parserName];
|
207
|
-
this.parsers[parserName] = parserConfig.getParser(parserConfig.baseDir);
|
208
|
-
var filter = parserConfig.getFileFilter ? parserConfig.getFileFilter(parserConfig.baseDir) : anyFileFilter;
|
209
|
-
|
210
|
-
if (parserConfig.filepaths && parserConfig.watchmanExpression) {
|
211
|
-
throw new Error('Provide either `watchmanExpression` or `filepaths` but not both.');
|
212
|
-
}
|
213
|
-
|
214
|
-
var files;
|
215
|
-
|
216
|
-
if (parserConfig.watchmanExpression) {
|
217
|
-
files = yield CodegenWatcher.queryFiles(parserConfig.baseDir, parserConfig.watchmanExpression, filter);
|
218
|
-
} else if (parserConfig.filepaths) {
|
219
|
-
files = yield CodegenWatcher.queryFilepaths(parserConfig.baseDir, parserConfig.filepaths, filter);
|
220
|
-
} else {
|
221
|
-
throw new Error('Either `watchmanExpression` or `filepaths` is required to query files');
|
222
|
-
}
|
223
|
-
|
224
|
-
this.parseFileChanges(parserName, files);
|
225
|
-
});
|
226
|
-
|
227
|
-
function parseEverything(_x2) {
|
228
|
-
return _parseEverything.apply(this, arguments);
|
229
|
-
}
|
230
|
-
|
231
|
-
return parseEverything;
|
232
|
-
}();
|
233
|
-
|
234
|
-
_proto.parseFileChanges = function parseFileChanges(parserName, files) {
|
235
|
-
var _this4 = this;
|
236
|
-
|
237
|
-
return Profiler.run('CodegenRunner.parseFileChanges', function () {
|
238
|
-
var parser = _this4.parsers[parserName]; // this maybe should be await parser.parseFiles(files);
|
239
|
-
|
240
|
-
parser.parseFiles(files);
|
241
|
-
});
|
242
|
-
} // We cannot do incremental writes right now.
|
243
|
-
// When we can, this could be writeChanges(writerName, parserName, parsedDefinitions)
|
244
|
-
;
|
245
|
-
|
246
|
-
_proto.write = function write(writerName) {
|
247
|
-
var _this5 = this;
|
248
|
-
|
249
|
-
return Profiler.asyncContext('CodegenRunner.write', /*#__PURE__*/_asyncToGenerator(function* () {
|
250
|
-
try {
|
251
|
-
_this5._reporter.reportMessage("\nWriting ".concat(writerName));
|
252
|
-
|
253
|
-
var _this5$writerConfigs$ = _this5.writerConfigs[writerName],
|
254
|
-
writeFiles = _this5$writerConfigs$.writeFiles,
|
255
|
-
_parser2 = _this5$writerConfigs$.parser,
|
256
|
-
baseParsers = _this5$writerConfigs$.baseParsers,
|
257
|
-
isGeneratedFile = _this5$writerConfigs$.isGeneratedFile;
|
258
|
-
var baseDocuments = ImmutableMap();
|
259
|
-
|
260
|
-
if (baseParsers) {
|
261
|
-
baseParsers.forEach(function (baseParserName) {
|
262
|
-
!(_this5.parsers[baseParserName] != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Trying to access an uncompiled base parser config: %s', baseParserName) : invariant(false) : void 0;
|
263
|
-
baseDocuments = baseDocuments.merge(_this5.parsers[baseParserName].documents());
|
264
|
-
});
|
265
|
-
}
|
266
|
-
|
267
|
-
var _this5$parserConfigs$ = _this5.parserConfigs[_parser2],
|
268
|
-
_baseDir = _this5$parserConfigs$.baseDir,
|
269
|
-
generatedDirectoriesWatchmanExpression = _this5$parserConfigs$.generatedDirectoriesWatchmanExpression;
|
270
|
-
var generatedDirectories = [];
|
271
|
-
|
272
|
-
if (generatedDirectoriesWatchmanExpression) {
|
273
|
-
var relativePaths = yield CodegenWatcher.queryDirectories(_baseDir, generatedDirectoriesWatchmanExpression);
|
274
|
-
generatedDirectories = relativePaths.map(function (x) {
|
275
|
-
return path.join(_baseDir, x);
|
276
|
-
});
|
277
|
-
} // always create a new writer: we have to write everything anyways
|
278
|
-
|
279
|
-
|
280
|
-
var documents = _this5.parsers[_parser2].documents();
|
281
|
-
|
282
|
-
var schema = Profiler.run('getSchema', function () {
|
283
|
-
return createSchema(_this5.parserConfigs[_parser2].getSchemaSource(), baseDocuments.toArray(), _this5.parserConfigs[_parser2].schemaExtensions);
|
284
|
-
});
|
285
|
-
var outputDirectories = yield writeFiles({
|
286
|
-
onlyValidate: _this5.onlyValidate,
|
287
|
-
schema: schema,
|
288
|
-
documents: documents,
|
289
|
-
baseDocuments: baseDocuments,
|
290
|
-
generatedDirectories: generatedDirectories,
|
291
|
-
sourceControl: _this5._sourceControl,
|
292
|
-
reporter: _this5._reporter
|
293
|
-
});
|
294
|
-
|
295
|
-
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(outputDirectories.values()),
|
296
|
-
_step2;
|
297
|
-
|
298
|
-
try {
|
299
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
300
|
-
var dir = _step2.value;
|
301
|
-
var all = [].concat((0, _toConsumableArray2["default"])(dir.changes.created), (0, _toConsumableArray2["default"])(dir.changes.updated), (0, _toConsumableArray2["default"])(dir.changes.deleted), (0, _toConsumableArray2["default"])(dir.changes.unchanged));
|
302
|
-
|
303
|
-
var _iterator3 = (0, _createForOfIteratorHelper2["default"])(all),
|
304
|
-
_step3;
|
305
|
-
|
306
|
-
try {
|
307
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
308
|
-
var filename = _step3.value;
|
309
|
-
|
310
|
-
var _filePath2 = dir.getPath(filename);
|
311
|
-
|
312
|
-
!isGeneratedFile(_filePath2) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CodegenRunner: %s returned false for isGeneratedFile, ' + 'but was in generated directory', _filePath2) : invariant(false) : void 0;
|
313
|
-
}
|
314
|
-
} catch (err) {
|
315
|
-
_iterator3.e(err);
|
316
|
-
} finally {
|
317
|
-
_iterator3.f();
|
318
|
-
}
|
319
|
-
}
|
320
|
-
} catch (err) {
|
321
|
-
_iterator2.e(err);
|
322
|
-
} finally {
|
323
|
-
_iterator2.f();
|
324
|
-
}
|
325
|
-
|
326
|
-
var onCompleteCallback = _this5.onComplete;
|
327
|
-
|
328
|
-
if (onCompleteCallback != null) {
|
329
|
-
onCompleteCallback(Array.from(outputDirectories.values()));
|
330
|
-
}
|
331
|
-
|
332
|
-
var combinedChanges = CodegenDirectory.combineChanges(Array.from(outputDirectories.values()));
|
333
|
-
|
334
|
-
_this5._reporter.reportMessage(CodegenDirectory.formatChanges(combinedChanges, {
|
335
|
-
onlyValidate: _this5.onlyValidate
|
336
|
-
}));
|
337
|
-
|
338
|
-
return CodegenDirectory.hasChanges(combinedChanges) ? 'HAS_CHANGES' : 'NO_CHANGES';
|
339
|
-
} catch (e) {
|
340
|
-
_this5._reporter.reportError('CodegenRunner.write', e);
|
341
|
-
|
342
|
-
return 'ERROR';
|
343
|
-
}
|
344
|
-
}));
|
345
|
-
};
|
346
|
-
|
347
|
-
_proto.watchAll = /*#__PURE__*/function () {
|
348
|
-
var _watchAll = _asyncToGenerator(function* () {
|
349
|
-
// get everything set up for watching
|
350
|
-
yield this.compileAll();
|
351
|
-
|
352
|
-
for (var parserName in this.parserConfigs) {
|
353
|
-
yield this.watch(parserName);
|
354
|
-
}
|
355
|
-
});
|
356
|
-
|
357
|
-
function watchAll() {
|
358
|
-
return _watchAll.apply(this, arguments);
|
359
|
-
}
|
360
|
-
|
361
|
-
return watchAll;
|
362
|
-
}();
|
363
|
-
|
364
|
-
_proto.watch = /*#__PURE__*/function () {
|
365
|
-
var _watch = _asyncToGenerator(function* (parserName) {
|
366
|
-
var _this6 = this;
|
367
|
-
|
368
|
-
var parserConfig = this.parserConfigs[parserName];
|
369
|
-
|
370
|
-
if (!parserConfig.watchmanExpression) {
|
371
|
-
throw new Error('`watchmanExpression` is required to watch files');
|
372
|
-
} // watchCompile starts with a full set of files as the changes
|
373
|
-
// But as we need to set everything up due to potential parser dependencies,
|
374
|
-
// we should prevent the first watch callback from doing anything.
|
375
|
-
|
376
|
-
|
377
|
-
var firstChange = true;
|
378
|
-
yield CodegenWatcher.watchCompile(parserConfig.baseDir, parserConfig.watchmanExpression, parserConfig.getFileFilter ? parserConfig.getFileFilter(parserConfig.baseDir) : anyFileFilter, /*#__PURE__*/function () {
|
379
|
-
var _ref4 = _asyncToGenerator(function* (files) {
|
380
|
-
!(_this6.parsers[parserName] != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Trying to watch an uncompiled parser config: %s', parserName) : invariant(false) : void 0;
|
381
|
-
|
382
|
-
if (firstChange) {
|
383
|
-
firstChange = false;
|
384
|
-
return;
|
385
|
-
}
|
386
|
-
|
387
|
-
var dependentWriters = [];
|
388
|
-
|
389
|
-
_this6.parserWriters[parserName].forEach(function (writer) {
|
390
|
-
return dependentWriters.push(writer);
|
391
|
-
});
|
392
|
-
|
393
|
-
try {
|
394
|
-
if (!_this6.parsers[parserName]) {
|
395
|
-
// have to load the parser and make sure all of its dependents are set
|
396
|
-
yield _this6.parseEverything(parserName);
|
397
|
-
} else {
|
398
|
-
_this6.parseFileChanges(parserName, files);
|
399
|
-
}
|
400
|
-
|
401
|
-
yield Promise.all(dependentWriters.map(function (writer) {
|
402
|
-
return _this6.write(writer);
|
403
|
-
}));
|
404
|
-
} catch (error) {
|
405
|
-
_this6._reporter.reportError('CodegenRunner.watch', error);
|
406
|
-
}
|
407
|
-
|
408
|
-
_this6._reporter.reportMessage("Watching for changes to ".concat(parserName, "..."));
|
409
|
-
});
|
410
|
-
|
411
|
-
return function (_x4) {
|
412
|
-
return _ref4.apply(this, arguments);
|
413
|
-
};
|
414
|
-
}());
|
415
|
-
|
416
|
-
this._reporter.reportMessage("Watching for changes to ".concat(parserName, "..."));
|
417
|
-
});
|
418
|
-
|
419
|
-
function watch(_x3) {
|
420
|
-
return _watch.apply(this, arguments);
|
421
|
-
}
|
422
|
-
|
423
|
-
return watch;
|
424
|
-
}();
|
425
|
-
|
426
|
-
return CodegenRunner;
|
427
|
-
}();
|
428
|
-
|
429
|
-
function anyFileFilter(file) {
|
430
|
-
return true;
|
431
|
-
}
|
432
|
-
|
433
|
-
module.exports = CodegenRunner;
|
@@ -1,11 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
|
-
'use strict';
|
@@ -1,271 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
|
-
'use strict';
|
12
|
-
|
13
|
-
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
14
|
-
|
15
|
-
var Profiler = require('../core/GraphQLCompilerProfiler');
|
16
|
-
|
17
|
-
var GraphQLWatchmanClient = require('../core/GraphQLWatchmanClient');
|
18
|
-
|
19
|
-
var crypto = require('crypto');
|
20
|
-
|
21
|
-
var fs = require('fs');
|
22
|
-
|
23
|
-
var path = require('path');
|
24
|
-
|
25
|
-
var SUBSCRIPTION_NAME = 'graphql-codegen';
|
26
|
-
var QUERY_RETRIES = 3;
|
27
|
-
|
28
|
-
function queryFiles(_x, _x2, _x3) {
|
29
|
-
return _queryFiles.apply(this, arguments);
|
30
|
-
}
|
31
|
-
|
32
|
-
function _queryFiles() {
|
33
|
-
_queryFiles = _asyncToGenerator(function* (baseDir, expression, filter) {
|
34
|
-
return yield Profiler.waitFor('Watchman:query', /*#__PURE__*/_asyncToGenerator(function* () {
|
35
|
-
var client = new GraphQLWatchmanClient(QUERY_RETRIES);
|
36
|
-
|
37
|
-
var _await$Promise$all = yield Promise.all([client.watchProject(baseDir), getFields(client)]),
|
38
|
-
watchResp = _await$Promise$all[0],
|
39
|
-
fields = _await$Promise$all[1];
|
40
|
-
|
41
|
-
var resp = yield client.command('query', watchResp.root, {
|
42
|
-
expression: expression,
|
43
|
-
fields: fields,
|
44
|
-
relative_root: watchResp.relativePath
|
45
|
-
});
|
46
|
-
client.end();
|
47
|
-
return updateFiles(new Set(), baseDir, filter, resp.files);
|
48
|
-
}));
|
49
|
-
});
|
50
|
-
return _queryFiles.apply(this, arguments);
|
51
|
-
}
|
52
|
-
|
53
|
-
function queryDirectories(_x4, _x5) {
|
54
|
-
return _queryDirectories.apply(this, arguments);
|
55
|
-
}
|
56
|
-
|
57
|
-
function _queryDirectories() {
|
58
|
-
_queryDirectories = _asyncToGenerator(function* (baseDir, expression) {
|
59
|
-
return yield Profiler.waitFor('Watchman:query', /*#__PURE__*/_asyncToGenerator(function* () {
|
60
|
-
var client = new GraphQLWatchmanClient();
|
61
|
-
var watchResp = yield client.watchProject(baseDir);
|
62
|
-
var resp = yield client.command('query', watchResp.root, {
|
63
|
-
expression: expression,
|
64
|
-
fields: ['name'],
|
65
|
-
relative_root: watchResp.relativePath
|
66
|
-
});
|
67
|
-
client.end();
|
68
|
-
return resp.files;
|
69
|
-
}));
|
70
|
-
});
|
71
|
-
return _queryDirectories.apply(this, arguments);
|
72
|
-
}
|
73
|
-
|
74
|
-
function getFields(_x6) {
|
75
|
-
return _getFields.apply(this, arguments);
|
76
|
-
} // For use when not using Watchman.
|
77
|
-
|
78
|
-
|
79
|
-
function _getFields() {
|
80
|
-
_getFields = _asyncToGenerator(function* (client) {
|
81
|
-
var fields = ['name', 'exists'];
|
82
|
-
|
83
|
-
if (yield client.hasCapability('field-content.sha1hex')) {
|
84
|
-
fields.push('content.sha1hex');
|
85
|
-
}
|
86
|
-
|
87
|
-
return fields;
|
88
|
-
});
|
89
|
-
return _getFields.apply(this, arguments);
|
90
|
-
}
|
91
|
-
|
92
|
-
function queryFilepaths(_x7, _x8, _x9) {
|
93
|
-
return _queryFilepaths.apply(this, arguments);
|
94
|
-
}
|
95
|
-
/**
|
96
|
-
* Provides a simplified API to the watchman API.
|
97
|
-
* Given some base directory and a list of subdirectories it calls the callback
|
98
|
-
* with watchman change events on file changes.
|
99
|
-
*/
|
100
|
-
|
101
|
-
|
102
|
-
function _queryFilepaths() {
|
103
|
-
_queryFilepaths = _asyncToGenerator(function* (baseDir, filepaths, filter) {
|
104
|
-
// Construct WatchmanChange objects as an intermediate step before
|
105
|
-
// calling updateFiles to produce file content.
|
106
|
-
var files = filepaths.map(function (filepath) {
|
107
|
-
return {
|
108
|
-
name: filepath,
|
109
|
-
exists: true,
|
110
|
-
'content.sha1hex': null
|
111
|
-
};
|
112
|
-
});
|
113
|
-
return updateFiles(new Set(), baseDir, filter, files);
|
114
|
-
});
|
115
|
-
return _queryFilepaths.apply(this, arguments);
|
116
|
-
}
|
117
|
-
|
118
|
-
function watch(_x10, _x11, _x12) {
|
119
|
-
return _watch.apply(this, arguments);
|
120
|
-
}
|
121
|
-
|
122
|
-
function _watch() {
|
123
|
-
_watch = _asyncToGenerator(function* (baseDir, expression, callback) {
|
124
|
-
return yield Profiler.waitFor('Watchman:subscribe', /*#__PURE__*/_asyncToGenerator(function* () {
|
125
|
-
var client = new GraphQLWatchmanClient();
|
126
|
-
var watchResp = yield client.watchProject(baseDir);
|
127
|
-
yield makeSubscription(client, watchResp.root, watchResp.relativePath, expression, callback);
|
128
|
-
}));
|
129
|
-
});
|
130
|
-
return _watch.apply(this, arguments);
|
131
|
-
}
|
132
|
-
|
133
|
-
function makeSubscription(_x13, _x14, _x15, _x16, _x17) {
|
134
|
-
return _makeSubscription.apply(this, arguments);
|
135
|
-
}
|
136
|
-
/**
|
137
|
-
* Further simplifies `watch` and calls the callback on every change with a
|
138
|
-
* full list of files that match the conditions.
|
139
|
-
*/
|
140
|
-
|
141
|
-
|
142
|
-
function _makeSubscription() {
|
143
|
-
_makeSubscription = _asyncToGenerator(function* (client, root, relativePath, expression, callback) {
|
144
|
-
client.on('subscription', function (resp) {
|
145
|
-
if (resp.subscription === SUBSCRIPTION_NAME) {
|
146
|
-
callback(resp);
|
147
|
-
}
|
148
|
-
});
|
149
|
-
var fields = yield getFields(client);
|
150
|
-
yield client.command('subscribe', root, SUBSCRIPTION_NAME, {
|
151
|
-
expression: expression,
|
152
|
-
fields: fields,
|
153
|
-
relative_root: relativePath
|
154
|
-
});
|
155
|
-
});
|
156
|
-
return _makeSubscription.apply(this, arguments);
|
157
|
-
}
|
158
|
-
|
159
|
-
function watchFiles(_x18, _x19, _x20, _x21) {
|
160
|
-
return _watchFiles.apply(this, arguments);
|
161
|
-
}
|
162
|
-
/**
|
163
|
-
* Similar to watchFiles, but takes an async function. The `compile` function
|
164
|
-
* is awaited and not called in parallel. If multiple changes are triggered
|
165
|
-
* before a compile finishes, the latest version is called after the compile
|
166
|
-
* finished.
|
167
|
-
*
|
168
|
-
* TODO: Consider changing from a Promise to abortable, so we can abort mid
|
169
|
-
* compilation.
|
170
|
-
*/
|
171
|
-
|
172
|
-
|
173
|
-
function _watchFiles() {
|
174
|
-
_watchFiles = _asyncToGenerator(function* (baseDir, expression, filter, callback) {
|
175
|
-
var files = new Set();
|
176
|
-
yield watch(baseDir, expression, function (changes) {
|
177
|
-
if (!changes.files) {
|
178
|
-
// Watchmen fires a change without files when a watchman state changes,
|
179
|
-
// for example during an hg update.
|
180
|
-
return;
|
181
|
-
}
|
182
|
-
|
183
|
-
files = updateFiles(files, baseDir, filter, changes.files);
|
184
|
-
callback(files);
|
185
|
-
});
|
186
|
-
});
|
187
|
-
return _watchFiles.apply(this, arguments);
|
188
|
-
}
|
189
|
-
|
190
|
-
function watchCompile(_x22, _x23, _x24, _x25) {
|
191
|
-
return _watchCompile.apply(this, arguments);
|
192
|
-
}
|
193
|
-
|
194
|
-
function _watchCompile() {
|
195
|
-
_watchCompile = _asyncToGenerator(function* (baseDir, expression, filter, compile) {
|
196
|
-
var compiling = false;
|
197
|
-
var needsCompiling = false;
|
198
|
-
var latestFiles = null;
|
199
|
-
watchFiles(baseDir, expression, filter, /*#__PURE__*/function () {
|
200
|
-
var _ref5 = _asyncToGenerator(function* (files) {
|
201
|
-
needsCompiling = true;
|
202
|
-
latestFiles = files;
|
203
|
-
|
204
|
-
if (compiling) {
|
205
|
-
return;
|
206
|
-
}
|
207
|
-
|
208
|
-
compiling = true;
|
209
|
-
|
210
|
-
while (needsCompiling) {
|
211
|
-
needsCompiling = false;
|
212
|
-
yield compile(latestFiles);
|
213
|
-
}
|
214
|
-
|
215
|
-
compiling = false;
|
216
|
-
});
|
217
|
-
|
218
|
-
return function (_x26) {
|
219
|
-
return _ref5.apply(this, arguments);
|
220
|
-
};
|
221
|
-
}());
|
222
|
-
});
|
223
|
-
return _watchCompile.apply(this, arguments);
|
224
|
-
}
|
225
|
-
|
226
|
-
function updateFiles(files, baseDir, filter, fileChanges) {
|
227
|
-
var fileMap = new Map();
|
228
|
-
files.forEach(function (file) {
|
229
|
-
file.exists && fileMap.set(file.relPath, file);
|
230
|
-
});
|
231
|
-
fileChanges.forEach(function (_ref) {
|
232
|
-
var name = _ref.name,
|
233
|
-
exists = _ref.exists,
|
234
|
-
hash = _ref['content.sha1hex'];
|
235
|
-
var shouldRemove = !exists;
|
236
|
-
|
237
|
-
if (!shouldRemove) {
|
238
|
-
var _file = {
|
239
|
-
exists: true,
|
240
|
-
relPath: name,
|
241
|
-
hash: hash || hashFile(path.join(baseDir, name))
|
242
|
-
};
|
243
|
-
|
244
|
-
if (filter(_file)) {
|
245
|
-
fileMap.set(name, _file);
|
246
|
-
} else {
|
247
|
-
shouldRemove = true;
|
248
|
-
}
|
249
|
-
}
|
250
|
-
|
251
|
-
shouldRemove && fileMap.set(name, {
|
252
|
-
exists: false,
|
253
|
-
relPath: name
|
254
|
-
});
|
255
|
-
});
|
256
|
-
return new Set(fileMap.values());
|
257
|
-
}
|
258
|
-
|
259
|
-
function hashFile(filename) {
|
260
|
-
var content = fs.readFileSync(filename);
|
261
|
-
return crypto.createHash('sha1').update(content).digest('hex');
|
262
|
-
}
|
263
|
-
|
264
|
-
module.exports = {
|
265
|
-
queryDirectories: queryDirectories,
|
266
|
-
queryFiles: queryFiles,
|
267
|
-
queryFilepaths: queryFilepaths,
|
268
|
-
watch: watch,
|
269
|
-
watchFiles: watchFiles,
|
270
|
-
watchCompile: watchCompile
|
271
|
-
};
|