diff --git a/apps/codesandbox-react-northstar-template/package.json b/apps/codesandbox-react-northstar-template/package.json index 6d30ecd9186de..f6a7a5aa34cfe 100644 --- a/apps/codesandbox-react-northstar-template/package.json +++ b/apps/codesandbox-react-northstar-template/package.json @@ -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" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bd44f500bd709..233d9f03d6cfd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -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* diff --git a/change/@fluentui-make-styles-146eefd0-302d-4465-b0de-2002fe6522b7.json b/change/@fluentui-make-styles-146eefd0-302d-4465-b0de-2002fe6522b7.json new file mode 100644 index 0000000000000..85310755d2e06 --- /dev/null +++ b/change/@fluentui-make-styles-146eefd0-302d-4465-b0de-2002fe6522b7.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore(scripts): move prettier to single version policy,make formating abstraction explicit", + "packageName": "@fluentui/make-styles", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "none" +} diff --git a/package.json b/package.json index eed343394e66a..bffb836d0c203 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", diff --git a/packages/fluentui/docs-components/package.json b/packages/fluentui/docs-components/package.json index 3d3c0011989f1..685ed41327f44 100644 --- a/packages/fluentui/docs-components/package.json +++ b/packages/fluentui/docs-components/package.json @@ -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": [ diff --git a/packages/make-styles/package.json b/packages/make-styles/package.json index d6b2a8a80f578..ff0b1bba735e6 100644 --- a/packages/make-styles/package.json +++ b/packages/make-styles/package.json @@ -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", diff --git a/prettier.config.js b/prettier.config.js index c3bfcb60f4934..b6ed35a435982 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -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, diff --git a/scripts/prettier.js b/scripts/format.js similarity index 86% rename from scripts/prettier.js rename to scripts/format.js index 6b078025b6085..dd86ea91f45d4 100644 --- a/scripts/prettier.js +++ b/scripts/format.js @@ -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)`, ); @@ -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, }, }) diff --git a/scripts/gulp/plugins/gulp-doctoc.ts b/scripts/gulp/plugins/gulp-doctoc.ts index 7bf4ebf726875..be0ecf312b183 100644 --- a/scripts/gulp/plugins/gulp-doctoc.ts +++ b/scripts/gulp/plugins/gulp-doctoc.ts @@ -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(() => runPrettier([file.path], false, true)) + .then(() => runPrettier([file.path])) .then(() => insideGitRepo && sh(`git add ${file.path}`)) .then(() => { done(null, file); diff --git a/scripts/package.json b/scripts/package.json index 2ebf4bf8bd25f..7bd708757dc56 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -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", diff --git a/scripts/prettier/prettier-helpers.js b/scripts/prettier/prettier-helpers.js index 61fa3123b1e62..702967fd434b8 100644 --- a/scripts/prettier/prettier-helpers.js +++ b/scripts/prettier/prettier-helpers.js @@ -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. * diff --git a/yarn.lock b/yarn.lock index c762b3610054b..4651f4f2c7ffa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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== @@ -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==