From 3db49a5dc5f1c51115ca1dadfe06e96da6e4e539 Mon Sep 17 00:00:00 2001 From: Jan Potoms Date: Wed, 11 Dec 2019 20:32:56 +0100 Subject: [PATCH 1/7] [scripts] prettier: don't force a remote when listing changes My master branch is tracking upstream/master, where upstream points to https://github.com/mui-org/material-ui.git My origin/master is so far behind it breaks the `yarn prettier` command for me (stdout overflow). I propose to explictly remove the remote. Like in the script this one is based on: https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/scripts/shared/listChangedFiles.js#L29 --- scripts/listChangedFiles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/listChangedFiles.js b/scripts/listChangedFiles.js index 6c5640c6ed6620..e4689addf1ad4c 100644 --- a/scripts/listChangedFiles.js +++ b/scripts/listChangedFiles.js @@ -27,7 +27,7 @@ async function execGitCmd(args) { } async function listChangedFiles() { - const mergeBase = await execGitCmd(['rev-parse', 'origin/master']); + const mergeBase = await execGitCmd(['rev-parse', 'master']); const gitDiff = await execGitCmd(['diff', '--name-only', mergeBase]); const gitLs = await execGitCmd(['ls-files', '--others', '--exclude-standard']); return new Set([...gitDiff, ...gitLs]); From 33267e5cddc498c4a97e8868f0be602be436f088 Mon Sep 17 00:00:00 2001 From: Jan Potoms Date: Thu, 12 Dec 2019 11:28:20 +0100 Subject: [PATCH 2/7] test prettier in ci --- packages/material-ui/src/Button/Button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/material-ui/src/Button/Button.js b/packages/material-ui/src/Button/Button.js index c4be83a1210232..73cab89f30a86f 100644 --- a/packages/material-ui/src/Button/Button.js +++ b/packages/material-ui/src/Button/Button.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React from 'react' import PropTypes from 'prop-types'; import clsx from 'clsx'; import withStyles from '../styles/withStyles'; From f809c1c44adeab1b0a91dbb7fa0d4720feb44758 Mon Sep 17 00:00:00 2001 From: Jan Potoms Date: Thu, 12 Dec 2019 11:43:39 +0100 Subject: [PATCH 3/7] with upstream/master? --- scripts/listChangedFiles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/listChangedFiles.js b/scripts/listChangedFiles.js index e4689addf1ad4c..0ea4037b2be65a 100644 --- a/scripts/listChangedFiles.js +++ b/scripts/listChangedFiles.js @@ -27,7 +27,7 @@ async function execGitCmd(args) { } async function listChangedFiles() { - const mergeBase = await execGitCmd(['rev-parse', 'master']); + const mergeBase = await execGitCmd(['rev-parse', 'upstream/master']); const gitDiff = await execGitCmd(['diff', '--name-only', mergeBase]); const gitLs = await execGitCmd(['ls-files', '--others', '--exclude-standard']); return new Set([...gitDiff, ...gitLs]); From 3e24ac1bc7fb48883c201372c7d236a653d21c9c Mon Sep 17 00:00:00 2001 From: Jan Potoms Date: Thu, 12 Dec 2019 12:11:39 +0100 Subject: [PATCH 4/7] with origin/master? --- scripts/listChangedFiles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/listChangedFiles.js b/scripts/listChangedFiles.js index 0ea4037b2be65a..6c5640c6ed6620 100644 --- a/scripts/listChangedFiles.js +++ b/scripts/listChangedFiles.js @@ -27,7 +27,7 @@ async function execGitCmd(args) { } async function listChangedFiles() { - const mergeBase = await execGitCmd(['rev-parse', 'upstream/master']); + const mergeBase = await execGitCmd(['rev-parse', 'origin/master']); const gitDiff = await execGitCmd(['diff', '--name-only', mergeBase]); const gitLs = await execGitCmd(['ls-files', '--others', '--exclude-standard']); return new Set([...gitDiff, ...gitLs]); From ef67d8a511232b33462fdf74d28ab391173241bc Mon Sep 17 00:00:00 2001 From: Jan Potoms Date: Thu, 12 Dec 2019 12:21:55 +0100 Subject: [PATCH 5/7] Maybe conditionally? --- scripts/listChangedFiles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/listChangedFiles.js b/scripts/listChangedFiles.js index 6c5640c6ed6620..2c411ba97fa3f0 100644 --- a/scripts/listChangedFiles.js +++ b/scripts/listChangedFiles.js @@ -27,7 +27,7 @@ async function execGitCmd(args) { } async function listChangedFiles() { - const mergeBase = await execGitCmd(['rev-parse', 'origin/master']); + const mergeBase = await execGitCmd(['rev-parse', process.env.CIRCLECI ? 'origin/master' : 'master']); const gitDiff = await execGitCmd(['diff', '--name-only', mergeBase]); const gitLs = await execGitCmd(['ls-files', '--others', '--exclude-standard']); return new Set([...gitDiff, ...gitLs]); From dc425200c43c4a05bef7677325c41cf0ca2f3165 Mon Sep 17 00:00:00 2001 From: Jan Potoms Date: Thu, 12 Dec 2019 12:30:12 +0100 Subject: [PATCH 6/7] after prettier --- packages/material-ui/src/Button/Button.js | 2 +- scripts/listChangedFiles.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/material-ui/src/Button/Button.js b/packages/material-ui/src/Button/Button.js index 73cab89f30a86f..c4be83a1210232 100644 --- a/packages/material-ui/src/Button/Button.js +++ b/packages/material-ui/src/Button/Button.js @@ -1,4 +1,4 @@ -import React from 'react' +import React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import withStyles from '../styles/withStyles'; diff --git a/scripts/listChangedFiles.js b/scripts/listChangedFiles.js index 2c411ba97fa3f0..6adaa87aa99d50 100644 --- a/scripts/listChangedFiles.js +++ b/scripts/listChangedFiles.js @@ -27,7 +27,8 @@ async function execGitCmd(args) { } async function listChangedFiles() { - const mergeBase = await execGitCmd(['rev-parse', process.env.CIRCLECI ? 'origin/master' : 'master']); + const comparedBranch = process.env.CIRCLECI ? 'origin/master' : 'master'; + const mergeBase = await execGitCmd(['rev-parse', comparedBranch]); const gitDiff = await execGitCmd(['diff', '--name-only', mergeBase]); const gitLs = await execGitCmd(['ls-files', '--others', '--exclude-standard']); return new Set([...gitDiff, ...gitLs]); From a0d43b1c4ceaafd8be2bbb7acecdf1e2c73edc1f Mon Sep 17 00:00:00 2001 From: Jan Potoms Date: Thu, 12 Dec 2019 16:00:23 +0100 Subject: [PATCH 7/7] add a test for listChangedFiles --- package.json | 2 +- scripts/listChangedFiles.test.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 scripts/listChangedFiles.test.js diff --git a/package.json b/package.json index 24a8a61b791ca8..7bbce911e4b941 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "test:karma": "cross-env NODE_ENV=test karma start test/karma.conf.js", "test:regressions": "webpack --config test/regressions/webpack.config.js && rimraf test/regressions/screenshots/chrome/* && vrtest run --config test/vrtest.config.js --record", "test:umd": "node packages/material-ui/test/umd/run.js", - "test:unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.js' 'docs/**/*.test.js' --exclude '**/node_modules/**'", + "test:unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.js' 'docs/**/*.test.js' 'scripts/**/*.test.js' --exclude '**/node_modules/**'", "test:watch": "yarn test:unit --watch", "typescript": "lerna run typescript --parallel" }, diff --git a/scripts/listChangedFiles.test.js b/scripts/listChangedFiles.test.js new file mode 100644 index 00000000000000..e14c744be53e9e --- /dev/null +++ b/scripts/listChangedFiles.test.js @@ -0,0 +1,23 @@ +const listChangedFiles = require('./listChangedFiles'); +const fs = require('fs'); +const rimraf = require('rimraf'); +const { promisify } = require('util'); +const { assert } = require('chai'); + +const writeFileAsync = promisify(fs.writeFile); +const rimrafAsync = promisify(rimraf); + +describe('listChangedFiles', () => { + it('should detect changes', async () => { + const changesBefore = await listChangedFiles(); + const testFile = 'someTestFile.js'; + try { + await writeFileAsync(testFile, 'console.log("hello");'); + const changesAfterAdd = await listChangedFiles(); + const addedFiles = Array.from(changesAfterAdd).filter(file => !changesBefore.has(file)); + assert.deepEqual(addedFiles, [testFile]); + } finally { + await rimrafAsync(testFile); + } + }); +});