mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
* Enable Yarn workspaces for packages/* * Move src/isomorphic/* into packages/react/src/* * Create index.js stubs for all packages in packages/* This makes the test pass again, but breaks the build because npm/ folders aren't used yet. I'm not sure if we'll keep this structure--I'll just keep working and fix the build after it settles down. * Put FB entry point for react-dom into packages/* * Move src/renderers/testing/* into packages/react-test-renderer/src/* Note that this is currently broken because Jest ignores node_modules, and so Yarn linking makes Jest skip React source when transforming. * Remove src/node_modules It is now unnecessary. Some tests fail though. * Add a hacky workaround for Jest/Workspaces issue Jest sees node_modules and thinks it's third party code. This is a hacky way to teach Jest to still transform anything in node_modules/react* if it resolves outside of node_modules (such as to our packages/*) folder. I'm not very happy with this and we should revisit. * Add a fake react-native package * Move src/renderers/art/* into packages/react-art/src/* * Move src/renderers/noop/* into packages/react-noop-renderer/src/* * Move src/renderers/dom/* into packages/react-dom/src/* * Move src/renderers/shared/fiber/* into packages/react-reconciler/src/* * Move DOM/reconciler tests I previously forgot to move * Move src/renderers/native-*/* into packages/react-native-*/src/* * Move shared code into packages/shared It's not super clear how to organize this properly yet. * Add back files that somehow got lost * Fix the build * Prettier * Add missing license headers * Fix an issue that caused mocks to get included into build * Update other references to src/ * Re-run Prettier * Fix lint * Fix weird Flow violation I didn't change this file but Flow started complaining. Caleb said this annotation was unnecessarily using $Abstract though so I removed it. * Update sizes * Fix stats script * Fix packaging fixtures Use file: instead of NODE_PATH since NODE_PATH. NODE_PATH trick only worked because we had no react/react-dom in root node_modules, but now we do. file: dependency only works as I expect in Yarn, so I moved the packaging fixtures to use Yarn and committed lockfiles. Verified that the page shows up. * Fix art fixture * Fix reconciler fixture * Fix SSR fixture * Rename native packages
126 lines
3.1 KiB
JavaScript
126 lines
3.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
'use strict';
|
|
|
|
// Based on similar script in Jest
|
|
// https://github.com/facebook/jest/blob/master/scripts/prettier.js
|
|
|
|
const chalk = require('chalk');
|
|
const glob = require('glob');
|
|
const path = require('path');
|
|
const execFileSync = require('child_process').execFileSync;
|
|
|
|
const mode = process.argv[2] || 'check';
|
|
const shouldWrite = mode === 'write' || mode === 'write-changed';
|
|
const onlyChanged = mode === 'check-changed' || mode === 'write-changed';
|
|
|
|
const isWindows = process.platform === 'win32';
|
|
const prettier = isWindows ? 'prettier.cmd' : 'prettier';
|
|
const prettierCmd = path.resolve(
|
|
__dirname,
|
|
'../../node_modules/.bin/' + prettier
|
|
);
|
|
const defaultOptions = {
|
|
'bracket-spacing': 'false',
|
|
'single-quote': 'true',
|
|
'jsx-bracket-same-line': 'true',
|
|
'trailing-comma': 'all',
|
|
'print-width': 80,
|
|
};
|
|
const config = {
|
|
default: {
|
|
patterns: [
|
|
// Internal forwarding modules
|
|
'packages/*/*.js',
|
|
// Source files
|
|
'packages/*/src/**/*.js',
|
|
],
|
|
ignore: ['**/node_modules/**'],
|
|
},
|
|
scripts: {
|
|
patterns: [
|
|
// Forwarding modules that get published to npm (must be ES5)
|
|
'packages/*/npm/**/*.js',
|
|
// Need to work on Node
|
|
'scripts/**/*.js',
|
|
'fixtures/**/*.js',
|
|
],
|
|
ignore: [
|
|
'**/node_modules/**',
|
|
// Built files and React repo clone
|
|
'scripts/bench/benchmarks/**',
|
|
],
|
|
options: {
|
|
'trailing-comma': 'es5',
|
|
},
|
|
},
|
|
};
|
|
|
|
function exec(command, args) {
|
|
console.log('> ' + [command].concat(args).join(' '));
|
|
var options = {
|
|
cwd: process.cwd(),
|
|
env: process.env,
|
|
stdio: 'pipe',
|
|
encoding: 'utf-8',
|
|
};
|
|
return execFileSync(command, args, options);
|
|
}
|
|
|
|
var mergeBase = exec('git', ['merge-base', 'HEAD', 'master']).trim();
|
|
var changedFiles = new Set(
|
|
exec('git', [
|
|
'diff',
|
|
'-z',
|
|
'--name-only',
|
|
'--diff-filter=ACMRTUB',
|
|
mergeBase,
|
|
]).match(/[^\0]+/g)
|
|
);
|
|
|
|
Object.keys(config).forEach(key => {
|
|
const patterns = config[key].patterns;
|
|
const options = config[key].options;
|
|
const ignore = config[key].ignore;
|
|
|
|
const globPattern = patterns.length > 1
|
|
? `{${patterns.join(',')}}`
|
|
: `${patterns.join(',')}`;
|
|
const files = glob
|
|
.sync(globPattern, {ignore})
|
|
.filter(f => !onlyChanged || changedFiles.has(f));
|
|
|
|
if (!files.length) {
|
|
return;
|
|
}
|
|
|
|
const args = Object.keys(defaultOptions).map(
|
|
k => `--${k}=${(options && options[k]) || defaultOptions[k]}`
|
|
);
|
|
args.push(`--${shouldWrite ? 'write' : 'l'}`);
|
|
|
|
try {
|
|
exec(prettierCmd, [...args, ...files]).trim();
|
|
} catch (e) {
|
|
if (!shouldWrite) {
|
|
console.log(
|
|
'\n' +
|
|
chalk.red(
|
|
` This project uses prettier to format all JavaScript code.\n`
|
|
) +
|
|
chalk.dim(` Please run `) +
|
|
chalk.reset('yarn prettier-all') +
|
|
chalk.dim(` and add changes to files listed below to your commit:`) +
|
|
`\n\n` +
|
|
e.stdout
|
|
);
|
|
process.exit(1);
|
|
}
|
|
throw e;
|
|
}
|
|
});
|