mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
* Lazily initialize models as they're read intead of eagerly when received This ensures that we don't spend CPU cycles processing models that we're not going to end up rendering. This model will also allow us to suspend during this initialization if data is not yet available to satisfy the model. * Refactoring carefully to ensure bundles still compile to something optimal * Remove generic from Response The root model needs to be cast at one point or another same as othe chunks. So we can parameterize the read instead of the whole Response. * Read roots from the 0 key of the map The special case to read the root isn't worth the field and code. * Store response on each Chunk Instead of storing it on the data tuple which is kind of dynamic, we store it on each Chunk. This uses more memory. Especially compared to just making initializeBlock a closure, but overall is simpler. * Rename private fields to underscores Response objects are exposed. * Encode server components as delayed references This allows us to stream in server components one after another over the wire. It also allows parallelizing their fetches and resuming only the server component instead of the whole parent block. This doesn't yet allow us to suspend deeper while waiting on this content because we don't have "lazy elements".
81 lines
2.3 KiB
JavaScript
81 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const minimatch = require('minimatch');
|
|
const CLIEngine = require('eslint').CLIEngine;
|
|
const listChangedFiles = require('../shared/listChangedFiles');
|
|
|
|
const allPaths = ['**/*.js'];
|
|
|
|
let changedFiles = null;
|
|
|
|
function runESLintOnFilesWithOptions(filePatterns, onlyChanged, options) {
|
|
const cli = new CLIEngine(options);
|
|
const formatter = cli.getFormatter();
|
|
|
|
if (onlyChanged && changedFiles === null) {
|
|
// Calculate lazily.
|
|
changedFiles = [...listChangedFiles()];
|
|
}
|
|
const finalFilePatterns = onlyChanged
|
|
? intersect(changedFiles, filePatterns)
|
|
: filePatterns;
|
|
const report = cli.executeOnFiles(finalFilePatterns);
|
|
|
|
if (options != null && options.fix === true) {
|
|
CLIEngine.outputFixes(report);
|
|
}
|
|
|
|
// When using `ignorePattern`, eslint will show `File ignored...` warnings for any ignores.
|
|
// We don't care because we *expect* some passed files will be ignores if `ignorePattern` is used.
|
|
const messages = report.results.filter(item => {
|
|
if (!onlyChanged) {
|
|
// Don't suppress the message on a full run.
|
|
// We only expect it to happen for "only changed" runs.
|
|
return true;
|
|
}
|
|
const ignoreMessage =
|
|
'File ignored because of a matching ignore pattern. Use "--no-ignore" to override.';
|
|
return !(item.messages[0] && item.messages[0].message === ignoreMessage);
|
|
});
|
|
|
|
const ignoredMessageCount = report.results.length - messages.length;
|
|
return {
|
|
output: formatter(messages),
|
|
errorCount: report.errorCount,
|
|
warningCount: report.warningCount - ignoredMessageCount,
|
|
};
|
|
}
|
|
|
|
function intersect(files, patterns) {
|
|
let intersection = [];
|
|
patterns.forEach(pattern => {
|
|
intersection = [
|
|
...intersection,
|
|
...minimatch.match(files, pattern, {matchBase: true}),
|
|
];
|
|
});
|
|
return [...new Set(intersection)];
|
|
}
|
|
|
|
function runESLint({onlyChanged}) {
|
|
if (typeof onlyChanged !== 'boolean') {
|
|
throw new Error('Pass options.onlyChanged as a boolean.');
|
|
}
|
|
const {
|
|
errorCount,
|
|
warningCount,
|
|
output,
|
|
} = runESLintOnFilesWithOptions(allPaths, onlyChanged, {fix: true});
|
|
console.log(output);
|
|
return errorCount === 0 && warningCount === 0;
|
|
}
|
|
|
|
module.exports = runESLint;
|