Skip to content

Commit

Permalink
fix(flow-self-typed): fix multiple issues and invalid assertions in t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
jedwards1211 committed Dec 4, 2017
1 parent 0370dc3 commit c1b7c1a
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 22 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions cli/src/commands/__tests__/install-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ describe('install (command)', () => {
},
dependencies: {
foo: '1.2.3',
underscore: '^1.0.0',
'@testscope/underscore': '^1.0.0',
underscore: '^1.6.0',
'@testscope/underscore': '^1.6.0',
},
}),
copyDir(
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('install (command)', () => {
FLOWPROJ_DIR,
'flow-typed',
'npm',
'underscore_vx.x.x.js',
'underscore_v1.8.3.js',
),
),
fs.exists(
Expand All @@ -364,7 +364,7 @@ describe('install (command)', () => {
'flow-typed',
'npm',
'@testscope',
'underscore_vx.x.x.js',
'underscore_v1.8.3.js',
),
),
]),
Expand All @@ -378,25 +378,29 @@ describe('install (command)', () => {
expect(fooLibDefContents).toContain('// flow-typed version: ');

const underscoreLibDefContents = (await fs.readFile(
path.join(FLOWPROJ_DIR, 'flow-typed', 'npm', 'underscore_vx.x.x.js'),
path.join(FLOWPROJ_DIR, 'flow-typed', 'npm', 'underscore_v1.8.3.js'),
)).toString();
expect(underscoreLibDefContents).toContain('// flow-typed signature: ');
expect(underscoreLibDefContents).toContain('// flow-typed version: ');
expect(underscoreLibDefContents).toContain('// flow-self-typed test');

const scopedUnderscoreLibDefContents = (await fs.readFile(
path.join(
FLOWPROJ_DIR,
'flow-typed',
'npm',
'@testscope',
'underscore_vx.x.x.js',
'underscore_v1.8.3.js',
),
)).toString();
expect(scopedUnderscoreLibDefContents).toContain(
'// flow-typed signature: ',
'// flow-typed signature: '
);
expect(scopedUnderscoreLibDefContents).toContain(
'// flow-typed version: ',
'// flow-typed version: '
);
expect(scopedUnderscoreLibDefContents).toContain(
'// flow-self-typed test'
);
});
});
Expand Down
23 changes: 14 additions & 9 deletions cli/src/lib/npm/npmLibDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type NpmLibDef = {|
flowVersion: FlowVersion,
path: string,
testFilePaths: Array<string>,
selfTyped?: boolean,
|};

export type NpmLibDefFilter = {|
Expand Down Expand Up @@ -344,9 +345,10 @@ function filterLibDefs(
let filterMatch = false;
switch (filter.type) {
case 'exact':
const fullName = def.scope ? `${def.scope}/${def.name}` : def.name
filterMatch =
filter.pkgName.toLowerCase() === def.name.toLowerCase() &&
pkgVersionMatch(filter.pkgVersion, def.version);
filter.pkgName.toLowerCase() === fullName.toLowerCase() &&
(def.selfTyped || pkgVersionMatch(filter.pkgVersion, def.version));
break;
default:
(filter: empty);
Expand Down Expand Up @@ -515,8 +517,8 @@ export async function getNpmLibDefs(
if (cwd) {
const node_modules = path.join(cwd, 'node_modules');
const pkgDefDirs = [
...(await glob(path.join(node_modules, '@*', '*', 'flow-typed'))),
...(await glob(path.join(node_modules, '*', 'flow-typed'))),
...(await glob(path.join(node_modules, '@*', '*', 'flow-self-typed'))),
...(await glob(path.join(node_modules, '*', 'flow-self-typed'))),
];

await P.all(
Expand Down Expand Up @@ -544,6 +546,7 @@ export async function getNpmLibDefs(
validationErrors,
validating,
);
libDefs.forEach(def => def.selfTyped = true)
if (!npmLibDefs.has(pkgName)) npmLibDefs.set(pkgName, libDefs);
}),
);
Expand Down Expand Up @@ -605,12 +608,14 @@ export async function getNpmLibDefVersionHash(
repoDirPath: string,
libDef: NpmLibDef,
): Promise<string> {
const latestCommitHash = await findLatestFileCommitHash(
repoDirPath,
path.relative(repoDirPath, libDef.path),
);
const latestCommitHash = libDef.selfTyped
? libDef.version
: (await findLatestFileCommitHash(
repoDirPath,
path.relative(repoDirPath, libDef.path),
)).substr(0, 10);
return (
`${latestCommitHash.substr(0, 10)}/` +
`${latestCommitHash}/` +
(libDef.scope === null ? '' : `${libDef.scope}/`) +
`${libDef.name}_${libDef.version}/` +
`flow_${flowVersionToSemver(libDef.flowVersion)}`
Expand Down

0 comments on commit c1b7c1a

Please sign in to comment.