From f250d270246847ff8a0219bd3ba18da835cdfdf9 Mon Sep 17 00:00:00 2001 From: Brian Chen Date: Wed, 2 Feb 2022 16:33:01 +1100 Subject: [PATCH 1/2] comment out validate-def --- cli/src/lib/npm/npmLibDefs.js | 71 ++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/cli/src/lib/npm/npmLibDefs.js b/cli/src/lib/npm/npmLibDefs.js index ef98c74057..6dcb18ceee 100644 --- a/cli/src/lib/npm/npmLibDefs.js +++ b/cli/src/lib/npm/npmLibDefs.js @@ -1,5 +1,4 @@ // @flow - import { ensureCacheRepo, getCacheRepoDir, @@ -31,7 +30,7 @@ import { import semver from 'semver'; -import got from 'got'; +// import got from 'got'; import {ValidationError} from '../ValidationError'; import {TEST_FILE_NAME_RE} from '../libDefs'; @@ -58,6 +57,8 @@ async function extractLibDefsFromNpmPkgDir( pkgDirPath: string, scope: null | string, pkgNameVer: string, + // Remove eslint error after `core.es5` change + // eslint-disable-next-line no-unused-vars validating?: boolean, ): Promise> { const parsedPkgNameVer = parsePkgNameVer(pkgNameVer); @@ -70,31 +71,36 @@ async function extractLibDefsFromNpmPkgDir( const libDefFileName = `${pkgName}_${pkgVersionStr}.js`; const pkgDirItems = await fs.readdir(pkgDirPath); - if (validating) { - const fullPkgName = `${scope === null ? '' : scope + '/'}${pkgName}`; - await _npmExists(fullPkgName) - .then() - .catch(error => { - if (error.HTTPError && error.HTTPError.response.statusCode === 404) { - // Some times NPM returns 404 even though the package exists. - // Try to avoid false negatives by retrying - return new Promise((resolve, reject) => - setTimeout(() => { - _npmExists(fullPkgName) - .then(resolve) - .catch(reject); - }, 1000), - ); - } - }) - .then() - .catch(error => { - // Only fail on 404, not on timeout - if (error.HTTPError && error.HTTPError.statusCode === 404) { - throw new ValidationError(`Package does not exist on npm!`); - } - }); - } + /** + * TODO: + * The following block is commented out until `core.es5` has been moved to + * somewhere else such as core + */ + // if (validating) { + // const fullPkgName = `${scope === null ? '' : scope + '/'}${pkgName}`; + // await _npmExists(fullPkgName) + // .then() + // .catch(error => { + // if (error.HTTPError && error.HTTPError.response.statusCode === 404) { + // // Some times NPM returns 404 even though the package exists. + // // Try to avoid false negatives by retrying + // return new Promise((resolve, reject) => + // setTimeout(() => { + // _npmExists(fullPkgName) + // .then(resolve) + // .catch(reject); + // }, 1000), + // ); + // } + // }) + // .then() + // .catch(error => { + // // Only fail on 404, not on timeout + // if (error.HTTPError && error.HTTPError.statusCode === 404) { + // throw new ValidationError(`Package does not exist on npm!`); + // } + // }); + // } const commonTestFiles = []; const parsedFlowDirs: Array<[string, FlowVersion]> = []; @@ -360,10 +366,13 @@ function filterLibDefs( }); } -async function _npmExists(pkgName: string): Promise { - const pkgUrl = `https://www.npmjs.com/package/${pkgName}`; - return got(pkgUrl, {method: 'HEAD'}); -} +// TODO Unused until `core.es5` +// async function _npmExists(pkgName: string): Promise { +// const pkgUrl = `https://api.npms.io/v2/package/${encodeURIComponent( +// pkgName, +// )}`; +// return got(pkgUrl, {method: 'HEAD'}); +// } export async function findNpmLibDef( pkgName: string, From 07201b2fda30bbb584372378b3567597cc9af657 Mon Sep 17 00:00:00 2001 From: Brian Chen Date: Wed, 2 Feb 2022 19:43:51 +1100 Subject: [PATCH 2/2] update docs with more detail --- docs/validate.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/validate.md b/docs/validate.md index cd31b82611..b16c5240bf 100644 --- a/docs/validate.md +++ b/docs/validate.md @@ -1,11 +1,13 @@ # validate-defs -Validate the structure of the `/definitions` directory. +Validate the structure of the `/definitions` directory given a path that contains an `npm` dir. ### Examples ``` -flow-typed validate-defs +flow-typed validate-defs definitions +flow-typed validate-defs ../definitions +flow-typed validate-defs ~/projects/flow-typed/definitions ``` ## Flags