flow-scripts
Advanced tools
Comparing version
@@ -17,6 +17,6 @@ const fs = require('fs'); | ||
const libdefDir = path.join(process.cwd(), dir, constants.DEFAULT_FLOW_TYPED_NPM_DIR); | ||
let packagesWithLibdef = []; | ||
let packagesWithLibdef = constants.DEFAULT_FLOW_LIBDEFS; | ||
if (fs.existsSync(libdefDir)) { | ||
const libdefFiles = fs.readdirSync(libdefDir); | ||
packagesWithLibdef = libdefFiles.map(file => { | ||
const libdefs = libdefFiles.map(file => { | ||
const [, match] = constants.LIBDEF_REGEX.exec(file) || []; | ||
@@ -26,2 +26,4 @@ return match; | ||
.filter(Boolean); | ||
packagesWithLibdef = packagesWithLibdef.concat(libdefs); | ||
} else { | ||
@@ -28,0 +30,0 @@ console.log('No existing community libdefs found. It is recommended to run ' + |
@@ -19,9 +19,22 @@ const fs = require('fs'); | ||
} | ||
const unmonitoredFiles = files.filter(file => fs.readFileSync(file).indexOf(constants.FLOW_MARKER) === -1); | ||
const unmonitoredFiles = []; | ||
const ignoredFiles = []; | ||
files.forEach(file => { | ||
const content = fs.readFileSync(file); | ||
if (content.indexOf(constants.NOFLOW_MARKER) > -1) { | ||
ignoredFiles.push(file); | ||
} else if (content.indexOf(constants.FLOW_MARKER) === -1) { | ||
unmonitoredFiles.push(file); | ||
} | ||
}); | ||
if (!unmonitoredFiles.length) { | ||
console.log(`All files contain "${constants.FLOW_MARKER}"!`); | ||
console.log(`There are no unmonitored files that do not contain "${constants.FLOW_MARKER}"!`); | ||
return; | ||
} | ||
console.log(`Found ${unmonitoredFiles.length} file(s) that do not contain "${constants.FLOW_MARKER}":\n`); | ||
if (ignoredFiles.length) { | ||
console.log(`Found ${ignoredFiles.length} file(s) that contain ` + | ||
`"${constants.NOFLOW_MARKER}". They will be excluded.`); | ||
} | ||
console.log(`Found ${unmonitoredFiles.length} file(s) that do ` + | ||
`not contain "${constants.FLOW_MARKER}":\n`); | ||
unmonitoredFiles.forEach(file => { | ||
@@ -34,6 +47,9 @@ console.log(` ${file.replace(/^\.\//, '')}`); | ||
console.log(); | ||
if (!fix) { | ||
console.log(); | ||
console.log('Run the command again with --fix to automatically append ' + | ||
`"${constants.FLOW_MARKER}" to those files.`); | ||
} else { | ||
console.log(`${unmonitoredFiles.length} fixed by automatically ` + | ||
`appending "${constants.FLOW_MARKER}"`); | ||
} | ||
@@ -40,0 +56,0 @@ |
@@ -5,3 +5,6 @@ const config = { | ||
DEFAULT_FLOW_TYPED_NPM_DIR: 'npm', | ||
// These are bundled with Flow, so we do not generate stubs for them | ||
DEFAULT_FLOW_LIBDEFS: ['react', 'react-dom', 'react-dom/server'], | ||
FLOW_MARKER: '@flow', | ||
NOFLOW_MARKER: '@noflow', | ||
LIBDEF_REGEX: /^(.+)_v\w+\.\w+\.\w+\.js$/, | ||
@@ -8,0 +11,0 @@ }; |
{ | ||
"name": "flow-scripts", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Utility scripts for Flowtypes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,3 +19,3 @@ # Flow Scripts | ||
### Stub | ||
## `Stub` | ||
@@ -32,4 +32,8 @@ ``` | ||
If you are thoroughly annoyed by your web app project taking so long to start up because of Flow and want to flowignore the `node_modules` folder but not might want to check in community libdefs into your repository and you are okay with not having Flow libdefs for external libraries. | ||
If you are: | ||
1. You are thoroughly annoyed by your web app project taking so long to start up because of Flow and want to `flowignore` the `node_modules` folder | ||
1. You do not want to check in community libdefs into your repository | ||
1. You are okay with not having Flow libdefs for external libraries. | ||
It also possible to combine usage of `flow-typed install` with `flow-scripts stub` as stubs for existing libdefs found in `flow-typed/npm/` will not be generated. | ||
@@ -45,3 +49,3 @@ | ||
The workaround is to flowignore the `node_modules` directory and include the libdefs inside the `flow-typed/` directory or provide a stub for it. This can be done manually or automatically via the `flow-typed install` command. | ||
The workaround is to `flowignore` the `node_modules` directory and include the libdefs inside the `flow-typed/` directory or provide a stub for it. This can be done manually or automatically via the `flow-typed install` command. | ||
@@ -51,3 +55,3 @@ The `flow-typed install` command does fetch community libdefs and generates stubs pretty well, but has a few problems: | ||
1. Some users might not want to fetch community libdefs because it adds many files to the source. | ||
2. The libdefs of some libraries are not pulled into `flow-typed/npm/`, such as `immutable` because it is already present in `node_modules/immutable`. This is not picked up because we flowignore the `node_modules`. | ||
1. The libdefs of some libraries are not pulled into `flow-typed/npm/`, such as `immutable` because it is already present in `node_modules/immutable`. This is not picked up because we `flowignore` the `node_modules`. | ||
@@ -92,3 +96,3 @@ The `flow-scripts stub` command fixes some of these problems by generating the stubs required for the `dependencies` in `package.json`. If there are existing libdef files in the `flow-typed/npm` directory, the stubs for these libraries will not be generated. | ||
### Unmonitored | ||
## `Unmonitored` | ||
@@ -101,3 +105,3 @@ ``` | ||
Searches for files matching the specified [glob pattern](https://www.wikiwand.com/en/Glob_(programming)) and checks if they contain `@flow`. If `pattern` is not specified, it defaults to `./**/*.{js,jsx}`. Please note that this commands works on files only, and not directories, hence you will have to specify a file extension. You will also have to quote your parameter (using double quotes if you need it to run in Windows). An example as follows: | ||
Searches for files matching the specified [glob pattern](https://www.wikiwand.com/en/Glob_(programming)) and lists the files that do not contain `@flow`. Files that have `@noflow` are ignored. If `pattern` is not specified, it defaults to `./**/*.{js,jsx}`. Please note that this commands works on files only, and not directories, hence you will have to explicitly specify a file extension. You will also have to quote your parameter (use double quotes if you need it to run in Windows). An example as follows: | ||
@@ -104,0 +108,0 @@ ``` |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12651
7.89%146
16.8%120
3.45%