Add type for yarnlockfile (#37144)

This commit is contained in:
Eric Wang
2019-07-26 11:06:30 -07:00
committed by Wesley Wigham
parent e09173a54d
commit 0773a10d01
4 changed files with 65 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
// Type definitions for parse-package-name 1.1
// Project: https://github.com/yarnpkg/yarn/tree/master/packages/lockfile
// Definitions by: Eric Wang <https://github.com/fa93hws>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Dependency {
[packageName: string]: string;
}
interface FirstLevelDependency {
version: string;
resolved?: string;
dependencies?: Dependency;
}
interface LockFileObject {
[packageName: string]: FirstLevelDependency;
}
export = parse;
declare function parse(file: string): { object: LockFileObject };
+26
View File
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@yarnpkg/lockfile": ["yarnpkg__lockfile"]
}
},
"files": [
"index.d.ts",
"yarnpkg__lockfile-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
@@ -0,0 +1,16 @@
import parseYarnLock = require('@yarnpkg/lockfile');
function testFirstLevelDependency(obj: {
version: string;
resolved?: string;
dependencies?: {
[packageName: string]: string;
}
}) {}
const { object } = parseYarnLock('');
Object.keys(object).forEach(k => {
const value = object[k];
testFirstLevelDependency(value);
});