Skip to content

Commit

Permalink
🏗️ Ignore .babel-cache directory (#33449)
Browse files Browse the repository at this point in the history
* Ignore .babel-cache directory

Also ensure prettier respects its .prettierignore file, which for some reason it ignores when using the API vs the CLI.

* Add ignore functionality to getFilesToCheck

* Separate ignore file param
  • Loading branch information
jridgewell authored Mar 24, 2021
1 parent d4bc64b commit b9c61b0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist.tools/**
firebase/**
out/**
test/coverage/**
.babel-cache/**

# Code directories
build-system/tasks/visual-diff/snippets/*.js
Expand Down
10 changes: 8 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
package.json
package-lock.json
.babel-cache/**
.github/ISSUE_TEMPLATE/**
**/package*.json
**/node_modules/**
**/build/**
**/dist/**
**/dist.3p/**
**/dist.tools/**
14 changes: 10 additions & 4 deletions build-system/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const experimentsConfig = require('../global-configs/experiments-config.json');
const fs = require('fs-extra');
const globby = require('globby');
const {clean} = require('../tasks/clean');
const {default: ignore} = require('ignore');
const {doBuild} = require('../tasks/build');
const {doDist} = require('../tasks/dist');
const {gitDiffNameOnlyMaster} = require('./git');
Expand Down Expand Up @@ -117,21 +118,26 @@ function getFilesFromArgv() {
*
* @param {!Array<string>} globs
* @param {Object=} options
* @param {(string|Array<string>)=} ignoreRules
* @return {!Array<string>}
*/
function getFilesToCheck(globs, options = {}) {
function getFilesToCheck(globs, options = {}, ignoreRules = undefined) {
const ignored = ignore();
if (ignoreRules) {
ignored.add(ignoreRules);
}
if (argv.files) {
return logFiles(getFilesFromArgv());
return logFiles(ignored.filter(getFilesFromArgv()));
}
if (argv.local_changes) {
const filesChanged = getFilesChanged(globs);
const filesChanged = ignored.filter(getFilesChanged(globs));
if (filesChanged.length == 0) {
log(green('INFO: ') + 'No files to check in this PR');
return [];
}
return logFiles(filesChanged);
}
return globby.sync(globs, options);
return ignored.filter(globby.sync(globs, options));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion build-system/tasks/prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const tempDir = tempy.directory();
* Checks files for formatting (and optionally fixes them) with Prettier.
*/
async function prettify() {
const filesToCheck = getFilesToCheck(prettifyGlobs, {dot: true});
// Prettier ignores the `.prettierignore` file when using the API like we
// are. So we need to filter our files down before feeding them to the API.
const ignore = fs.readFileSync('.prettierignore', 'utf8');
const filesToCheck = getFilesToCheck(prettifyGlobs, {dot: true}, ignore);
if (filesToCheck.length == 0) {
return;
}
Expand Down
3 changes: 0 additions & 3 deletions build-system/test-configs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ const prettifyGlobs = [
'**/*.json',
'**/OWNERS',
'**/*.md',
'!**/package*.json',
'!.github/ISSUE_TEMPLATE/**',
'!**/{node_modules,build,dist,dist.3p,dist.tools}/**',
];

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"globby": "11.0.2",
"gulp-connect": "5.7.0",
"html-minifier": "4.0.0",
"ignore": "5.1.8",
"istanbul-middleware": "0.2.2",
"jest-dot-reporter": "1.0.12",
"jest-silent-reporter": "0.5.0",
Expand Down

0 comments on commit b9c61b0

Please sign in to comment.