Skip to content

Commit

Permalink
chore(scripts): move prettier to single version policy,make formating… (
Browse files Browse the repository at this point in the history
#17102)

* chore(scripts): move prettier to single version policy,make formating abstraction explicit
* fix(scripts): properly call prettierRun from gulp task
* refactor(script): resolve prettier node CLI path in way that will not break on bumps
  • Loading branch information
Hotell authored Mar 2, 2021
1 parent 183f82f commit 2ca35f1
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apps/codesandbox-react-northstar-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@fluentui/code-sandbox": "^0.52.0",
"@fluentui/react-northstar": "^0.52.0",
"prettier": "~1.19.1",
"prettier": "1.19.1",
"react": "16.8.6",
"react-dom": "16.8.6",
"tslib": "^1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
## manually call this since lage is now used and it calls lint per package, not per repo
- script: |
yarn prelint &&
yarn prettier $(targetBranch) --check
yarn format $(targetBranch) --check
displayName: do syncpack, lint-files, and prettier checks
## Danger.js checks for Fluent UI N*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore(scripts): move prettier to single version policy,make formating abstraction explicit",
"packageName": "@fluentui/make-styles",
"email": "[email protected]",
"dependentChangeType": "none"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"preinstall": "node ./scripts/use-yarn-please.js",
"prelint": "yarn satisfied && yarn syncpack:list && node ./scripts/lint-files/index.js",
"postinstall": "node ./scripts/postinstall.js",
"prettier": "node scripts/prettier.js",
"format": "node scripts/format.js",
"rebuild": "node ./scripts/invalidate-just-cache.js && yarn build --reset-cache",
"release:fluentui:minor": "node -r ./scripts/ts-node-register ./scripts/fluentui-publish publish-minor",
"release:fluentui:patch": "node -r ./scripts/ts-node-register ./scripts/fluentui-publish publish-patch",
Expand Down Expand Up @@ -73,7 +73,7 @@
"devDependencies": {
"@types/jest": "24.9.1",
"@types/jest-axe": "3.2.2",
"@types/prettier": "^1.0.0",
"@types/prettier": "1.19.1",
"@types/webpack-dev-middleware": "4.1.0",
"@storybook/addon-a11y": "6.0.28",
"@storybook/addons": "6.0.28",
Expand All @@ -92,6 +92,7 @@
"jest-cli": "24.9.0",
"jest-environment-jsdom": "24.9.0",
"jest-watch-typeahead": "0.4.2",
"prettier": "1.19.1",
"lage": "0.27.0",
"lerna": "^3.15.0",
"lint-staged": "^10.2.9",
Expand Down
1 change: 0 additions & 1 deletion packages/fluentui/docs-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@types/react": "16.9.42",
"@fluentui/scripts": "^1.0.0",
"gulp": "^4.0.2",
"prettier": "~1.19.1",
"react": "16.8.6"
},
"files": [
Expand Down
3 changes: 1 addition & 2 deletions packages/make-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"@fluentui/eslint-plugin": "^1.0.1",
"@fluentui/scripts": "^1.0.0",
"@fluentui/test-utilities": "^8.0.1",
"@types/stylis": "^4.0.0",
"prettier": "~1.19.1"
"@types/stylis": "^4.0.0"
},
"dependencies": {
"@emotion/hash": "^0.8.0",
Expand Down
7 changes: 6 additions & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// https://prettier.io/docs/en/configuration.html
// @ts-check

/**
* https://prettier.io/docs/en/configuration.html
* @type {import('prettier').Options}
*/
module.exports = {
printWidth: 120,
tabWidth: 2,
Expand Down
12 changes: 6 additions & 6 deletions scripts/prettier.js → scripts/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
const { all: runOnAllFiles, check: checkMode } = parsedArgs;

console.log(
`Running prettier on ${runOnAllFiles ? 'all' : 'changed'} files (on ${numberOfCpus} processes | in ${
`Running format on ${runOnAllFiles ? 'all' : 'changed'} files (on ${numberOfCpus} processes | in ${
checkMode ? 'check' : 'write'
} mode)`,
);
Expand All @@ -42,16 +42,16 @@ async function main() {

function parseArgs() {
return require('yargs')
.usage('Usage: prettier [commitHash] [options]')
.example('prettier', 'Run prettier only on changed files')
.example('prettier HEAD~3', 'Run prettier only on changed files since HEAD~3')
.usage('Usage: format [commitHash] [options]')
.example('format', 'Run format only on changed files')
.example('format HEAD~3', 'Run format only on changed files since HEAD~3')
.options({
all: {
description: 'Run prettier on all files',
description: 'Run format on all files',
boolean: true,
},
check: {
description: 'Run prettier in check mode. useful for CI',
description: 'Run format in check mode. useful for CI',
boolean: true,
},
})
Expand Down
2 changes: 1 addition & 1 deletion scripts/gulp/plugins/gulp-doctoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const insideGitRepo = fs.existsSync(config.paths.base('.git'));
export default () =>
through2.obj((file, enc, done) => {
sh(`doctoc ${file.path} --github --maxlevel 4`)
.then<any>(() => runPrettier([file.path], false, true))
.then<any>(() => runPrettier([file.path]))
.then<any>(() => insideGitRepo && sh(`git add ${file.path}`))
.then(() => {
done(null, file);
Expand Down
1 change: 0 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
"path-browserify": "^1.0.1",
"plop": "^2.6.0",
"portfinder": "^1.0.20",
"prettier": "~1.19.1",
"progress": "^2.0.3",
"prompts": "^2.3.0",
"puppeteer": "^1.13.0",
Expand Down
15 changes: 14 additions & 1 deletion scripts/prettier/prettier-helpers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
// @ts-check
const path = require('path');
const fs = require('fs');
const execSync = require('../exec-sync');
const exec = require('../exec');
const findGitRoot = require('../monorepo/findGitRoot');

const repoRoot = findGitRoot();
const prettierBin = getPrettierBinary();
const prettierRulesConfig = path.join(repoRoot, 'prettier.config.js');
const prettierIgnorePath = path.join(repoRoot, '.prettierignore');
const prettierBin = require.resolve('prettier/bin-prettier.js');

const prettierExtensions = ['ts', 'tsx', 'js', 'jsx', 'json', 'scss', 'css', 'html', 'htm', 'md', 'yml'];

/**
* NOTE:
* we should use public prettier node API. This is a temporary workaround
* https://prettier.io/docs/en/api.html
*/
function getPrettierBinary() {
const prettierPath = path.dirname(require.resolve('prettier'));
const pkg = JSON.parse(fs.readFileSync(path.join(prettierPath, 'package.json'), 'utf-8'));

return path.join(prettierPath, pkg.bin);
}

/**
* Run prettier for a given set of files.
*
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5080,7 +5080,7 @@
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-5.0.3.tgz#e7b5aebbac150f8b5fdd4a46e7f0bd8e65e19109"
integrity sha512-kUNnecmtkunAoQ3CnjmMkzNU/gtxG8guhi+Fk2U/kOpIKjIMKnXGp4IJCgQJrXSgMsWYimYG4TGjz/UzbGEBTw==

"@types/prettier@^1.0.0":
"@types/prettier@1.19.1":
version "1.19.1"
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.19.1.tgz#33509849f8e679e4add158959fdb086440e9553f"
integrity sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ==
Expand Down Expand Up @@ -21189,7 +21189,7 @@ prepend-http@^2.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=

prettier@^1.16.4, prettier@~1.19.1:
prettier@1.19.1, prettier@^1.16.4, prettier@~1.19.1:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
Expand Down

0 comments on commit 2ca35f1

Please sign in to comment.