Skip to content

Commit

Permalink
prettierx: make flow-parser an optional dependency
Browse files Browse the repository at this point in the history
- move flow-parser to devDependencies
- specify as optional in peerDependenciesMeta
- update dependency notes in package.json
- disable import/no-extraneous-dependencies when importing flow-parser
  in src/language-js/parser-flow.js
- add a few more comments
  • Loading branch information
brodybits committed Aug 10, 2020
1 parent 9333e68 commit f026be0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"* installing dependencies from GitHub is not desired in prettierx",
" due to a possible issue with firewalls in certain organizations",
"* latest updates of ci-info from GitHub are not needed for prettierx",
"* typescript is moved to devDependencies, and",
" it is specified as optional in peerDependenciesMeta",
"* flow-parser & typescript are moved to devDependencies, and",
" they are specified as optional in peerDependenciesMeta",
"* codecov is removed from devDependencies",
"<!-- -->"
],
Expand Down Expand Up @@ -52,7 +52,6 @@
"fast-glob": "3.2.4",
"find-parent-dir": "0.3.0",
"find-project-root": "1.1.1",
"flow-parser": "0.122.0",
"get-stream": "6.0.0",
"globby": "11.0.1",
"graphql": "15.3.0",
Expand Down Expand Up @@ -109,6 +108,7 @@
"eslint-plugin-react": "7.20.5",
"eslint-plugin-unicorn": "21.0.0",
"execa": "4.0.3",
"flow-parser": "0.122.0",
"jest": "26.3.0",
"jest-snapshot-serializer-ansi": "1.0.0",
"jest-snapshot-serializer-raw": "1.1.0",
Expand All @@ -129,6 +129,9 @@
"webpack": "4.44.1"
},
"peerDependenciesMeta": {
"flow-parser": {
"optional": true
},
"typescript": {
"optional": true
}
Expand Down
3 changes: 2 additions & 1 deletion src/language-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const languages = [
createLanguage(require("linguist-languages/data/JavaScript"), () => ({
name: "Flow",
since: "0.0.0",
parsers: ["babel", "flow"],
parsers: ["babel", "flow"], // [prettierx] must use Babel by default
// (since the flow-parser is now an optional dependency in prettierx)
vscodeLanguageIds: ["javascript"],
aliases: [],
filenames: [],
Expand Down
2 changes: 2 additions & 0 deletions src/language-js/parser-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const locFns = require("./loc");
const postprocess = require("./postprocess");

function parse(text, parsers, opts) {
// [prettierx] optional dependency here:
// Inline the require to avoid loading all the JS if we don't use it
// eslint-disable-next-line import/no-extraneous-dependencies
const flowParser = require("flow-parser");

const ast = flowParser.parse(text, {
Expand Down

0 comments on commit f026be0

Please sign in to comment.