mirror of
https://github.com/chenasraf/DefinitelyTyped-tools.git
synced 2026-05-18 01:49:03 +00:00
[tslint] Make green and add to CI (#721)
* Use CRLF everywhere * [tslint] Disable a few rules as per current style * [tslint] Run auto fix * [tslint] Disable more rules as per current style * [tslint] Manually fix most failures * [tslint] Wait for promises to finish * [package] Run lint as part of test script Co-authored-by: Orta <orta.therox+github@gmail.com>
This commit is contained in:
committed by
Andrew Branch
parent
3dba1ab9f1
commit
e74ad03f9a
@@ -45,7 +45,7 @@
|
||||
"tslint": "^5.13.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm run build && jest",
|
||||
"test": "npm run lint && npm run build && jest",
|
||||
"build": "node node_modules/typescript/lib/tsc.js",
|
||||
"watch": "node node_modules/typescript/lib/tsc.js --watch",
|
||||
"clean": "node bin/clean.js",
|
||||
|
||||
@@ -2,8 +2,8 @@ import assert = require("assert");
|
||||
|
||||
import { FS, getDefinitelyTyped } from "./get-definitely-typed";
|
||||
import { Options, writeDataFile } from "./lib/common";
|
||||
import { withNpmCache, CachedNpmInfoClient, UncachedNpmInfoClient, NpmInfoVersion } from "./lib/npm-client";
|
||||
import { AllPackages, TypingsData, NotNeededPackage } from "./lib/packages";
|
||||
import { CachedNpmInfoClient, NpmInfoVersion, UncachedNpmInfoClient, withNpmCache } from "./lib/npm-client";
|
||||
import { AllPackages, NotNeededPackage, TypingsData } from "./lib/packages";
|
||||
import { ChangedPackages, ChangedPackagesJson, ChangedTypingJson, Semver, versionsFilename } from "./lib/versions";
|
||||
import { loggerWithErrors, LoggerWithErrors } from "./util/logging";
|
||||
import { assertDefined, best, logUncaughtErrors, mapDefined, mapDefinedAsync } from "./util/util";
|
||||
@@ -15,7 +15,7 @@ if (!module.parent) {
|
||||
export default async function calculateVersions(
|
||||
dt: FS,
|
||||
uncachedClient: UncachedNpmInfoClient,
|
||||
log: LoggerWithErrors
|
||||
log: LoggerWithErrors,
|
||||
): Promise<ChangedPackages> {
|
||||
log.info("=== Calculating versions ===");
|
||||
return withNpmCache(uncachedClient, async client => {
|
||||
@@ -28,7 +28,7 @@ export default async function calculateVersions(
|
||||
async function computeAndSaveChangedPackages(
|
||||
allPackages: AllPackages,
|
||||
log: LoggerWithErrors,
|
||||
client: CachedNpmInfoClient
|
||||
client: CachedNpmInfoClient,
|
||||
): Promise<ChangedPackages> {
|
||||
const cp = await computeChangedPackages(allPackages, log, client);
|
||||
const json: ChangedPackagesJson = {
|
||||
@@ -42,7 +42,7 @@ async function computeAndSaveChangedPackages(
|
||||
async function computeChangedPackages(
|
||||
allPackages: AllPackages,
|
||||
log: LoggerWithErrors,
|
||||
client: CachedNpmInfoClient
|
||||
client: CachedNpmInfoClient,
|
||||
): Promise<ChangedPackages> {
|
||||
log.info("# Computing changed packages...");
|
||||
const changedTypings = await mapDefinedAsync(allPackages.allTypings(), async pkg => {
|
||||
@@ -71,7 +71,7 @@ async function fetchTypesPackageVersionInfo(
|
||||
pkg: TypingsData,
|
||||
client: CachedNpmInfoClient,
|
||||
canPublish: boolean,
|
||||
log?: LoggerWithErrors
|
||||
log?: LoggerWithErrors,
|
||||
): Promise<{ version: string, needsPublish: boolean }> {
|
||||
let info = client.getNpmInfoFromCache(pkg.fullEscapedNpmName);
|
||||
let latestVersion = info && getHighestVersionForMajor(info.versions, pkg);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import appInsights = require("applicationinsights");
|
||||
import * as yargs from "yargs";
|
||||
|
||||
import appInsights = require("applicationinsights");
|
||||
import calculateVersions from "./calculate-versions";
|
||||
import { clean } from "./clean";
|
||||
import createSearchIndex from "./create-search-index";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { createNotNeededPackageJSON, createPackageJSON, createReadme, getLicenseFileText } from "./generate-packages";
|
||||
import { Registry } from "./lib/common";
|
||||
import { TypingsData, TypingsDataRaw, License, AllPackages, readNotNeededPackages, TypesDataFile, NotNeededPackage } from "./lib/packages";
|
||||
import { AllPackages, License, NotNeededPackage, readNotNeededPackages, TypesDataFile, TypingsData, TypingsDataRaw } from "./lib/packages";
|
||||
import { createMockDT } from "./mocks";
|
||||
import { testo } from "./util/test";
|
||||
import { createMockDT } from "./mocks"
|
||||
function createRawPackage(license: License): TypingsDataRaw {
|
||||
return {
|
||||
libraryName: "jquery",
|
||||
@@ -22,14 +22,14 @@ function createRawPackage(license: License): TypingsDataRaw {
|
||||
projectName: "jquery.org",
|
||||
globals: [],
|
||||
declaredModules: ["juqery"],
|
||||
}
|
||||
};
|
||||
}
|
||||
function createTypesData(): TypesDataFile {
|
||||
return {
|
||||
"jquery": {
|
||||
"1": createRawPackage(License.MIT)
|
||||
jquery: {
|
||||
1: createRawPackage(License.MIT),
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
function createUnneededPackage() {
|
||||
return new NotNeededPackage({
|
||||
@@ -37,7 +37,7 @@ function createUnneededPackage() {
|
||||
typingsPackageName: "absalom",
|
||||
asOfVersion: "1.1.1",
|
||||
sourceRepoURL: "https://github.com/aardwulf/absalom",
|
||||
})
|
||||
});
|
||||
}
|
||||
testo({
|
||||
mitLicenseText() {
|
||||
@@ -64,8 +64,8 @@ testo({
|
||||
const typing = new TypingsData(createRawPackage(License.Apache20), /*isLatest*/ true);
|
||||
expect(createReadme(typing)).toEqual(expect.stringContaining("Global values: none"));
|
||||
},
|
||||
async basicPackageJson() {
|
||||
const packages = AllPackages.from(createTypesData(), await readNotNeededPackages(createMockDT()));
|
||||
basicPackageJson() {
|
||||
const packages = AllPackages.from(createTypesData(), readNotNeededPackages(createMockDT()));
|
||||
const typing = new TypingsData(createRawPackage(License.MIT), /*isLatest*/ true);
|
||||
expect(createPackageJSON(typing, "1.0", packages, Registry.NPM)).toEqual(`{
|
||||
"name": "@types/jquery",
|
||||
@@ -92,20 +92,20 @@ testo({
|
||||
"typeScriptVersion": "3.0"
|
||||
}`);
|
||||
},
|
||||
async githubPackageJsonName() {
|
||||
const packages = AllPackages.from(createTypesData(), await readNotNeededPackages(createMockDT()));
|
||||
githubPackageJsonName() {
|
||||
const packages = AllPackages.from(createTypesData(), readNotNeededPackages(createMockDT()));
|
||||
const typing = new TypingsData(createRawPackage(License.MIT), /*isLatest*/ true);
|
||||
expect(createPackageJSON(typing, "1.0", packages, Registry.Github)).toEqual(
|
||||
expect.stringContaining('"name": "@types/jquery"'));
|
||||
},
|
||||
async githubPackageJsonRegistry() {
|
||||
const packages = AllPackages.from(createTypesData(), await readNotNeededPackages(createMockDT()));
|
||||
githubPackageJsonRegistry() {
|
||||
const packages = AllPackages.from(createTypesData(), readNotNeededPackages(createMockDT()));
|
||||
const typing = new TypingsData(createRawPackage(License.MIT), /*isLatest*/ true);
|
||||
const s = createPackageJSON(typing, "1.0", packages, Registry.Github);
|
||||
expect(s).toEqual(expect.stringContaining('publishConfig'));
|
||||
expect(s).toEqual(expect.stringContaining("publishConfig"));
|
||||
expect(s).toEqual(expect.stringContaining('"registry": "https://npm.pkg.github.com/"'));
|
||||
},
|
||||
async basicNotNeededPackageJson() {
|
||||
basicNotNeededPackageJson() {
|
||||
const s = createNotNeededPackageJSON(createUnneededPackage(), Registry.NPM);
|
||||
expect(s).toEqual(`{
|
||||
"name": "@types/absalom",
|
||||
@@ -122,9 +122,9 @@ testo({
|
||||
}
|
||||
}`);
|
||||
},
|
||||
async githubNotNeededPackageJson() {
|
||||
githubNotNeededPackageJson() {
|
||||
const s = createNotNeededPackageJSON(createUnneededPackage(), Registry.Github);
|
||||
expect(s).toEqual(expect.stringContaining('@types'));
|
||||
expect(s).toEqual(expect.stringContaining('npm.pkg.github.com'));
|
||||
expect(s).toEqual(expect.stringContaining("@types"));
|
||||
expect(s).toEqual(expect.stringContaining("npm.pkg.github.com"));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
import { emptyDir } from "fs-extra";
|
||||
import { makeTypesVersionsForPackageJson } from "definitelytyped-header-parser";
|
||||
import { emptyDir, mkdir, mkdirp, readFileSync } from "fs-extra";
|
||||
import * as path from "path";
|
||||
import * as yargs from "yargs";
|
||||
|
||||
import { FS, getDefinitelyTyped } from "./get-definitely-typed";
|
||||
import { Options, Registry } from "./lib/common";
|
||||
import { CachedNpmInfoClient, UncachedNpmInfoClient, withNpmCache } from "./lib/npm-client";
|
||||
import {
|
||||
AllPackages, AnyPackage, DependencyVersion, getFullNpmName, License, NotNeededPackage, PackageJsonDependency, TypingsData,
|
||||
} from "./lib/packages";
|
||||
import { sourceBranch, outputDirPath } from "./lib/settings";
|
||||
import { outputDirPath, sourceBranch } from "./lib/settings";
|
||||
import { ChangedPackages, readChangedPackages, skipBadPublishes } from "./lib/versions";
|
||||
import { writeFile } from "./util/io";
|
||||
import { logger, loggerWithErrors, writeLog, Logger } from "./util/logging";
|
||||
import { logger, Logger, loggerWithErrors, writeLog } from "./util/logging";
|
||||
import { writeTgz } from "./util/tgz";
|
||||
import { assertNever, joinPaths, logUncaughtErrors, sortObjectKeys } from "./util/util";
|
||||
import { makeTypesVersionsForPackageJson } from "definitelytyped-header-parser";
|
||||
import { mkdir, mkdirp, readFileSync } from "fs-extra";
|
||||
import * as path from "path";
|
||||
import { withNpmCache, CachedNpmInfoClient, UncachedNpmInfoClient } from "./lib/npm-client";
|
||||
|
||||
const mitLicense = readFileSync(joinPaths(__dirname, "..", "LICENSE"), "utf-8");
|
||||
|
||||
@@ -43,7 +42,7 @@ export default async function generatePackages(dt: FS, allPackages: AllPackages,
|
||||
log(` * ${pkg.libraryName}`);
|
||||
}
|
||||
log("## Generating deprecated packages");
|
||||
withNpmCache(new UncachedNpmInfoClient(), async client => {
|
||||
await withNpmCache(new UncachedNpmInfoClient(), async client => {
|
||||
for (const pkg of changedPackages.changedNotNeededPackages) {
|
||||
log(` * ${pkg.libraryName}`);
|
||||
await generateNotNeededPackage(pkg, client, log);
|
||||
@@ -150,7 +149,17 @@ function dependencySemver(dependency: DependencyVersion): string {
|
||||
return dependency === "*" ? dependency : `^${dependency}`;
|
||||
}
|
||||
|
||||
export function createNotNeededPackageJSON({ libraryName, license, name, fullNpmName, sourceRepoURL, version }: NotNeededPackage, registry: Registry): string {
|
||||
export function createNotNeededPackageJSON(
|
||||
{
|
||||
libraryName,
|
||||
license,
|
||||
name,
|
||||
fullNpmName,
|
||||
sourceRepoURL,
|
||||
version,
|
||||
}: NotNeededPackage,
|
||||
registry: Registry,
|
||||
): string {
|
||||
const out = {
|
||||
name: fullNpmName,
|
||||
version: version.versionString,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import appInsights = require("applicationinsights");
|
||||
import assert = require("assert");
|
||||
import { ensureDir, readdirSync, statSync, pathExistsSync } from "fs-extra";
|
||||
import { ensureDir, pathExistsSync, readdirSync, statSync } from "fs-extra";
|
||||
import https = require("https");
|
||||
import tarStream = require("tar-stream");
|
||||
import * as yargs from "yargs";
|
||||
@@ -255,11 +255,9 @@ class DiskFS implements FS {
|
||||
function validatePath(path: string): void {
|
||||
if (path.startsWith(".") && path !== ".editorconfig" && !path.startsWith("../")) {
|
||||
throw new Error(`${path}: filesystem doesn't support paths of the form './x'.`);
|
||||
}
|
||||
else if (path.startsWith("/")) {
|
||||
} else if (path.startsWith("/")) {
|
||||
throw new Error(`${path}: filesystem doesn't support paths of the form '/xxx'.`);
|
||||
}
|
||||
else if (path.endsWith("/")) {
|
||||
} else if (path.endsWith("/")) {
|
||||
throw new Error(`${path}: filesystem doesn't support paths of the form 'xxx/'.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,3 @@ export { consoleLogger, loggerWithErrors } from "./util/logging";
|
||||
export { logUncaughtErrors, nAtATime } from "./util/util";
|
||||
|
||||
export { updateLatestTag, updateTypeScriptVersionTags } from "./lib/package-publisher";
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ensureDir } from "fs-extra";
|
||||
|
||||
import { readJson, writeJson } from "../util/io";
|
||||
import { joinPaths } from "../util/util";
|
||||
|
||||
import { dataDirPath } from "./settings";
|
||||
|
||||
if (process.env.LONGJOHN) {
|
||||
|
||||
@@ -21,5 +21,3 @@ if (!module.parent) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ function getTypingDataForSingleTypesVersion(
|
||||
const usedFiles = new Set([...types.keys(), ...tests.keys(), "tsconfig.json", "tslint.json"]);
|
||||
const otherFiles = ls.indexOf(unusedFilesName) > -1 ? (fs.readFile(unusedFilesName)).split(/\r?\n/g).filter(Boolean) : [];
|
||||
checkAllFilesUsed(ls, usedFiles, otherFiles, packageName, fs);
|
||||
for (const untestedTypeFile of filter(otherFiles, name => name.endsWith('.d.ts'))) {
|
||||
for (const untestedTypeFile of filter(otherFiles, name => name.endsWith(".d.ts"))) {
|
||||
// add d.ts files from OTHER_FILES.txt in order get their dependencies
|
||||
types.set(untestedTypeFile, createSourceFile(untestedTypeFile, fs.readFile(untestedTypeFile)));
|
||||
}
|
||||
@@ -168,11 +168,25 @@ function getTypingDataForSingleTypesVersion(
|
||||
const declaredModulesSet = new Set(declaredModules);
|
||||
// Don't count an import of "x" as a dependency if we saw `declare module "x"` somewhere.
|
||||
const dependenciesSet = new Set(filter(dependenciesWithDeclaredModules, m => !declaredModulesSet.has(m)));
|
||||
const testDependencies = Array.from(filter(getTestDependencies(packageName, types, tests.keys(), dependenciesSet, fs), m => !declaredModulesSet.has(m)));
|
||||
const testDependencies = Array.from(
|
||||
filter(
|
||||
getTestDependencies(packageName, types, tests.keys(), dependenciesSet, fs),
|
||||
m => !declaredModulesSet.has(m),
|
||||
),
|
||||
);
|
||||
|
||||
const { dependencies, pathMappings } = calculateDependencies(packageName, tsconfig, dependenciesSet, oldMajorVersion);
|
||||
const tsconfigPathsForHash = JSON.stringify(tsconfig.compilerOptions.paths);
|
||||
return { typescriptVersion, dependencies, testDependencies, pathMappings, globals, declaredModules, declFiles: sort(types.keys()), tsconfigPathsForHash };
|
||||
return {
|
||||
typescriptVersion,
|
||||
dependencies,
|
||||
testDependencies,
|
||||
pathMappings,
|
||||
globals,
|
||||
declaredModules,
|
||||
declFiles: sort(types.keys()),
|
||||
tsconfigPathsForHash,
|
||||
};
|
||||
}
|
||||
|
||||
function checkPackageJsonDependencies(dependencies: unknown, path: string): ReadonlyArray<PackageJsonDependency> {
|
||||
@@ -228,7 +242,7 @@ function checkFilesFromTsConfig(packageName: string, tsconfig: TsConfig, directo
|
||||
}
|
||||
if (file.endsWith(".d.ts") && file !== "index.d.ts") {
|
||||
throw new Error(`${packageName}: Only index.d.ts may be listed explicitly in tsconfig's "files" entry.
|
||||
Other d.ts files must either be referenced through index.d.ts, tests, or added to OTHER_FILES.txt.`)
|
||||
Other d.ts files must either be referenced through index.d.ts, tests, or added to OTHER_FILES.txt.`);
|
||||
}
|
||||
|
||||
if (!file.endsWith(".d.ts") && !file.startsWith("test/")) {
|
||||
@@ -236,7 +250,8 @@ Other d.ts files must either be referenced through index.d.ts, tests, or added t
|
||||
if (file !== expectedName && file !== `${expectedName}x`) {
|
||||
const message = file.endsWith(".ts") || file.endsWith(".tsx")
|
||||
? `Expected file '${file}' to be named '${expectedName}' or to be inside a '${directoryPath}/test/' directory`
|
||||
: `Unexpected file extension for '${file}' -- expected '.ts' or '.tsx' (maybe this should not be in "files", but OTHER_FILES.txt)`;
|
||||
: (`Unexpected file extension for '${file}' -- expected '.ts' or '.tsx' (maybe this should not be in "files", but ` +
|
||||
"OTHER_FILES.txt)");
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
@@ -419,8 +434,7 @@ function checkAllUsedRecur(ls: Iterable<string>, usedFiles: Set<string>, unusedF
|
||||
for (const unusedFile of unusedFiles) {
|
||||
if (usedFiles.has(unusedFile)) {
|
||||
throw new Error(`File ${fs.debugPath()}/${unusedFile} listed in ${unusedFilesName} is already reachable from tsconfig.json.`);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Error(`File ${fs.debugPath()}/${unusedFile} listed in ${unusedFilesName} does not exist.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,49 +1,64 @@
|
||||
import * as ts from "typescript";
|
||||
|
||||
import { Dir, InMemoryDT } from "../get-definitely-typed";
|
||||
import { allReferencedFiles, getModuleInfo, getTestDependencies } from "./module-info";
|
||||
import { createMockDT } from "../mocks";
|
||||
import { testo } from "../util/test";
|
||||
import { createMockDT } from "../mocks"
|
||||
import * as ts from 'typescript'
|
||||
|
||||
import { allReferencedFiles, getModuleInfo, getTestDependencies } from "./module-info";
|
||||
const fs = createMockDT();
|
||||
function getBoringReferences() {
|
||||
return allReferencedFiles(["index.d.ts", "boring-tests.ts"], fs.subDir("types").subDir("boring"), "boring", "types/boring")
|
||||
return allReferencedFiles(["index.d.ts", "boring-tests.ts"], fs.subDir("types").subDir("boring"), "boring", "types/boring");
|
||||
}
|
||||
testo({
|
||||
allReferencedFilesFromTsconfigFiles() {
|
||||
const { types, tests } = getBoringReferences();
|
||||
expect(Array.from(types.keys())).toEqual(["index.d.ts", "secondary.d.ts", "quaternary.d.ts", "tertiary.d.ts", "commonjs.d.ts", "v1.d.ts"])
|
||||
expect(Array.from(tests.keys())).toEqual(["boring-tests.ts"])
|
||||
expect(Array.from(types.keys())).toEqual(["index.d.ts", "secondary.d.ts", "quaternary.d.ts", "tertiary.d.ts", "commonjs.d.ts", "v1.d.ts"]);
|
||||
expect(Array.from(tests.keys())).toEqual(["boring-tests.ts"]);
|
||||
},
|
||||
allReferencedFilesFromTestIncludesSecondaryInternalFiles() {
|
||||
const { types, tests } = allReferencedFiles(["boring-tests.ts"], fs.subDir("types").subDir("boring"), "boring", "types/boring")
|
||||
expect(Array.from(types.keys())).toEqual(["secondary.d.ts", "quaternary.d.ts", "tertiary.d.ts", "commonjs.d.ts", "v1.d.ts"])
|
||||
expect(Array.from(tests.keys())).toEqual(["boring-tests.ts"])
|
||||
const { types, tests } = allReferencedFiles(["boring-tests.ts"], fs.subDir("types").subDir("boring"), "boring", "types/boring");
|
||||
expect(Array.from(types.keys())).toEqual(["secondary.d.ts", "quaternary.d.ts", "tertiary.d.ts", "commonjs.d.ts", "v1.d.ts"]);
|
||||
expect(Array.from(tests.keys())).toEqual(["boring-tests.ts"]);
|
||||
},
|
||||
allReferencedFilesFromTsconfigGlobal() {
|
||||
const { types, tests } = allReferencedFiles(["jquery-tests.ts", "index.d.ts"], fs.subDir("types").subDir("jquery"), "jquery", "types/jquery")
|
||||
expect(Array.from(types.keys())).toEqual(["index.d.ts", "JQuery.d.ts"])
|
||||
expect(Array.from(tests.keys())).toEqual(["jquery-tests.ts"])
|
||||
const { types, tests } = allReferencedFiles(["jquery-tests.ts", "index.d.ts"], fs.subDir("types").subDir("jquery"), "jquery", "types/jquery");
|
||||
expect(Array.from(types.keys())).toEqual(["index.d.ts", "JQuery.d.ts"]);
|
||||
expect(Array.from(tests.keys())).toEqual(["jquery-tests.ts"]);
|
||||
},
|
||||
allReferencedFilesFromTestIncludesSecondaryTripleSlashTypes() {
|
||||
const { types, tests } = allReferencedFiles(["globby-tests.ts", "test/other-tests.ts"], fs.subDir("types").subDir("globby"), "globby", "types/globby")
|
||||
expect(Array.from(types.keys())).toEqual(["merges.d.ts"])
|
||||
expect(Array.from(tests.keys())).toEqual(["globby-tests.ts", "test/other-tests.ts"])
|
||||
const { types, tests } = allReferencedFiles(
|
||||
["globby-tests.ts", "test/other-tests.ts"],
|
||||
fs.subDir("types").subDir("globby"),
|
||||
"globby",
|
||||
"types/globby",
|
||||
);
|
||||
expect(Array.from(types.keys())).toEqual(["merges.d.ts"]);
|
||||
expect(Array.from(tests.keys())).toEqual(["globby-tests.ts", "test/other-tests.ts"]);
|
||||
},
|
||||
getModuleInfoWorksWithOtherFiles() {
|
||||
const { types } = getBoringReferences();
|
||||
// written as if it were from OTHER_FILES.txt
|
||||
types.set("untested.d.ts", ts.createSourceFile("untested.d.ts", fs.subDir("types").subDir("boring").readFile("untested.d.ts"), ts.ScriptTarget.Latest, false));
|
||||
types.set(
|
||||
"untested.d.ts",
|
||||
ts.createSourceFile("untested.d.ts", fs.subDir("types").subDir("boring").readFile("untested.d.ts"), ts.ScriptTarget.Latest, false),
|
||||
);
|
||||
const i = getModuleInfo("boring", types);
|
||||
expect(i.dependencies).toEqual(new Set(['manual', 'react', 'react-default', 'things', 'vorticon']));
|
||||
expect(i.dependencies).toEqual(new Set(["manual", "react", "react-default", "things", "vorticon"]));
|
||||
},
|
||||
getModuleInfoForNestedTypeReferences() {
|
||||
const { types } = allReferencedFiles(["index.d.ts", "globby-tests.ts", "test/other-tests.ts"], fs.subDir("types").subDir("globby"), "globby", "types/globby")
|
||||
expect(Array.from(types.keys())).toEqual(["index.d.ts", "sneaky.d.ts", "merges.d.ts"])
|
||||
const { types } = allReferencedFiles(
|
||||
["index.d.ts", "globby-tests.ts", "test/other-tests.ts"],
|
||||
fs.subDir("types").subDir("globby"),
|
||||
"globby",
|
||||
"types/globby",
|
||||
);
|
||||
expect(Array.from(types.keys())).toEqual(["index.d.ts", "sneaky.d.ts", "merges.d.ts"]);
|
||||
const i = getModuleInfo("globby", types);
|
||||
expect(i.dependencies).toEqual(new Set(['andere']));
|
||||
expect(i.dependencies).toEqual(new Set(["andere"]));
|
||||
},
|
||||
versionTypeRefThrows() {
|
||||
const fail = new Dir(undefined);
|
||||
const fs = new InMemoryDT(fail, "typeref-fails");
|
||||
const memFS = new InMemoryDT(fail, "typeref-fails");
|
||||
fail.set("index.d.ts", `// Type definitions for fail 1.0
|
||||
// Project: https://youtube.com/typeref-fails
|
||||
// Definitions by: Type Ref Fails <https://github.com/typeref-fails>
|
||||
@@ -51,8 +66,8 @@ testo({
|
||||
|
||||
/// <reference types="elser/v3" />
|
||||
`);
|
||||
const { types } = allReferencedFiles(["index.d.ts"], fs, "typeref-fails", "types/typeref-fails")
|
||||
expect(Array.from(types.keys())).toEqual(["index.d.ts"])
|
||||
const { types } = allReferencedFiles(["index.d.ts"], memFS, "typeref-fails", "types/typeref-fails");
|
||||
expect(Array.from(types.keys())).toEqual(["index.d.ts"]);
|
||||
expect(() => getModuleInfo("typeref-fails", types)).toThrow("do not directly import specific versions of another types package");
|
||||
},
|
||||
getTestDependenciesWorks() {
|
||||
@@ -61,4 +76,4 @@ testo({
|
||||
const d = getTestDependencies("boring", types, tests.keys(), i.dependencies, fs.subDir("types").subDir("boring"));
|
||||
expect(d).toEqual(new Set(["super-big-fun-hus"]));
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ export function getModuleInfo(packageName: string, all: Map<string, ts.SourceFil
|
||||
const globals = new Set<string>();
|
||||
|
||||
function addDependency(ref: string): void {
|
||||
if (ref.startsWith(".")) return;
|
||||
if (ref.startsWith(".")) { return; }
|
||||
const dependency = rootName(ref, all);
|
||||
if (dependency !== packageName) {
|
||||
dependencies.add(dependency);
|
||||
@@ -143,7 +143,7 @@ function withoutExtension(str: string, ext: string): string {
|
||||
|
||||
/** Returns a map from filename (path relative to `directory`) to the SourceFile we parsed for it. */
|
||||
export function allReferencedFiles(
|
||||
entryFilenames: ReadonlyArray<string>, fs: FS, packageName: string, baseDirectory: string
|
||||
entryFilenames: ReadonlyArray<string>, fs: FS, packageName: string, baseDirectory: string,
|
||||
): { types: Map<string, ts.SourceFile>, tests: Map<string, ts.SourceFile> } {
|
||||
const seenReferences = new Set<string>();
|
||||
const types = new Map<string, ts.SourceFile>();
|
||||
@@ -166,7 +166,12 @@ export function allReferencedFiles(
|
||||
tests.set(resolvedFilename, src);
|
||||
}
|
||||
|
||||
const refs = findReferencedFiles(src, packageName, path.dirname(resolvedFilename), normalizeSlashes(path.relative(baseDirectory, fs.debugPath())));
|
||||
const refs = findReferencedFiles(
|
||||
src,
|
||||
packageName,
|
||||
path.dirname(resolvedFilename),
|
||||
normalizeSlashes(path.relative(baseDirectory, fs.debugPath())),
|
||||
);
|
||||
refs.forEach(recur);
|
||||
}
|
||||
}
|
||||
@@ -200,7 +205,7 @@ interface Reference {
|
||||
* versionsBaseDirectory may be "" when not in typesVersions or ".." when inside `react-router/ts3.1`
|
||||
*/
|
||||
function findReferencedFiles(src: ts.SourceFile, packageName: string, subDirectory: string, baseDirectory: string) {
|
||||
const refs: Reference[] = []
|
||||
const refs: Reference[] = [];
|
||||
|
||||
for (const ref of src.referencedFiles) {
|
||||
// Any <reference path="foo"> is assumed to be local
|
||||
@@ -230,7 +235,7 @@ function findReferencedFiles(src: ts.SourceFile, packageName: string, subDirecto
|
||||
const full = normalizeSlashes(path.normalize(joinPaths(subDirectory, assertNoWindowsSlashes(src.fileName, ref.text))));
|
||||
// allow files in typesVersions directories (i.e. 'ts3.1') to reference files in parent directory
|
||||
if (full.startsWith("../" + packageName + "/")) {
|
||||
ref.text = full.slice(4 + packageName.length);
|
||||
ref.text = full.slice(packageName.length + 4);
|
||||
refs.push(ref);
|
||||
return;
|
||||
} else if (full.startsWith("..")
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import assert = require("assert");
|
||||
import { Registry } from "./common";
|
||||
import { ensureFile, pathExists } from "fs-extra";
|
||||
import RegClient = require("npm-registry-client");
|
||||
import { resolve as resolveUrl } from "url";
|
||||
@@ -7,8 +6,9 @@ import { resolve as resolveUrl } from "url";
|
||||
import { Fetcher, readFile, readJson, sleep, writeJson } from "../util/io";
|
||||
import { Logger, loggerWithErrors } from "../util/logging";
|
||||
import { createTgz } from "../util/tgz";
|
||||
import { identity, joinPaths, mapToRecord, recordToMap, assertNever } from "../util/util";
|
||||
import { assertNever, identity, joinPaths, mapToRecord, recordToMap } from "../util/util";
|
||||
|
||||
import { Registry } from "./common";
|
||||
import { getSecret, Secret } from "./secrets";
|
||||
import { githubRegistry, npmApi, npmRegistry, npmRegistryHostName } from "./settings";
|
||||
|
||||
@@ -149,7 +149,7 @@ export class NpmPublishClient {
|
||||
}
|
||||
}
|
||||
|
||||
private constructor(private client: RegClient, private auth: RegClient.Credentials, private registry: string) {}
|
||||
private constructor(private readonly client: RegClient, private readonly auth: RegClient.Credentials, private readonly registry: string) {}
|
||||
|
||||
async publish(publishedDirectory: string, packageJson: {}, dry: boolean, log: Logger): Promise<void> {
|
||||
const readme = await readFile(joinPaths(publishedDirectory, "README.md"));
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import assert = require("assert");
|
||||
import { TypeScriptVersion } from "definitelytyped-header-parser";
|
||||
|
||||
import { readFileAndWarn, Registry } from "./common";
|
||||
import { ChangedTyping } from "./versions";
|
||||
import { Logger } from "../util/logging";
|
||||
import { joinPaths } from "../util/util";
|
||||
|
||||
import { readFileAndWarn, Registry } from "./common";
|
||||
import { NpmPublishClient } from "./npm-client";
|
||||
import { AnyPackage, NotNeededPackage } from "./packages";
|
||||
import { ChangedTyping } from "./versions";
|
||||
|
||||
export async function publishTypingsPackage(client: NpmPublishClient, changedTyping: ChangedTyping, dry: boolean, log: Logger, registry: Registry): Promise<void> {
|
||||
export async function publishTypingsPackage(
|
||||
client: NpmPublishClient,
|
||||
changedTyping: ChangedTyping,
|
||||
dry: boolean,
|
||||
log: Logger,
|
||||
registry: Registry,
|
||||
): Promise<void> {
|
||||
const { pkg, version, latestVersion } = changedTyping;
|
||||
await common(client, pkg, log, dry, registry);
|
||||
if (pkg.isLatest) {
|
||||
@@ -24,7 +30,13 @@ export async function publishTypingsPackage(client: NpmPublishClient, changedTyp
|
||||
}
|
||||
}
|
||||
|
||||
export async function publishNotNeededPackage(client: NpmPublishClient, pkg: NotNeededPackage, dry: boolean, log: Logger, registry: Registry): Promise<void> {
|
||||
export async function publishNotNeededPackage(
|
||||
client: NpmPublishClient,
|
||||
pkg: NotNeededPackage,
|
||||
dry: boolean,
|
||||
log: Logger,
|
||||
registry: Registry,
|
||||
): Promise<void> {
|
||||
log(`Deprecating ${pkg.name}`);
|
||||
await common(client, pkg, log, dry, registry);
|
||||
// Don't use a newline in the deprecation message because it will be displayed as "\n" and not as a newline.
|
||||
@@ -48,7 +60,7 @@ export async function deprecateNotNeededPackage(client: NpmPublishClient, pkg: N
|
||||
}
|
||||
|
||||
export async function updateTypeScriptVersionTags(
|
||||
pkg: AnyPackage, version: string, client: NpmPublishClient, log: Logger, dry: boolean
|
||||
pkg: AnyPackage, version: string, client: NpmPublishClient, log: Logger, dry: boolean,
|
||||
): Promise<void> {
|
||||
const tags = TypeScriptVersion.tagsToUpdate(pkg.minTypeScriptVersion);
|
||||
const name = pkg.fullNpmName;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert = require("assert");
|
||||
import { Author, TypeScriptVersion, AllTypeScriptVersion } from "definitelytyped-header-parser";
|
||||
import { AllTypeScriptVersion, Author, TypeScriptVersion } from "definitelytyped-header-parser";
|
||||
|
||||
import { FS } from "../get-definitely-typed";
|
||||
import { assertSorted, joinPaths, mapValues, unmangleScopedPackage } from "../util/util";
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { AuthenticationContext } from "adal-node";
|
||||
import { KeyVaultClient, KeyVaultCredentials } from "azure-keyvault";
|
||||
|
||||
import { mapDefined } from "../util/util";
|
||||
|
||||
import { azureKeyvault } from "./settings";
|
||||
|
||||
export enum Secret {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { assertDefined, best, intOfString } from "../util/util";
|
||||
import { Logger } from "../util/logging";
|
||||
import { assertDefined, best, intOfString } from "../util/util";
|
||||
|
||||
import { readDataFile } from "./common";
|
||||
import { AllPackages, NotNeededPackage, PackageId, TypingsData } from "./packages";
|
||||
import { CachedNpmInfoClient } from "./npm-client";
|
||||
import { AllPackages, NotNeededPackage, PackageId, TypingsData } from "./packages";
|
||||
|
||||
export const versionsFilename = "versions.json";
|
||||
|
||||
@@ -64,9 +64,9 @@ export function skipBadPublishes(pkg: NotNeededPackage, client: CachedNpmInfoCli
|
||||
return pkg;
|
||||
}
|
||||
|
||||
function findActualLatest(times: Map<string,string>) {
|
||||
function findActualLatest(times: Map<string, string>) {
|
||||
const actual = best(
|
||||
times, ([k,v], [bestK,bestV]) =>
|
||||
times, ([k, v], [bestK, bestV]) =>
|
||||
(bestK === "modified" || bestK === "created") ? true :
|
||||
(k === "modified" || k === "created") ? false :
|
||||
new Date(v) > new Date(bestV));
|
||||
|
||||
@@ -27,9 +27,9 @@ export default async function webhookServer(
|
||||
});
|
||||
setInterval((log, timestamp) => {
|
||||
const result = fullOne(log, timestamp);
|
||||
if (!result) return; // already working, so do nothing.
|
||||
if (!result) { return; } // already working, so do nothing.
|
||||
result.catch(e => { log.info(e.toString()); console.error(e); });
|
||||
}, 2_000_000, loggerWithErrors()[0], currentTimeStamp());
|
||||
}, 2_000_000, loggerWithErrors()[0], currentTimeStamp());
|
||||
return listenToGithub(key, fullOne);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createMockDT } from "./mocks";
|
||||
import parseDefinitions from "./parse-definitions";
|
||||
import { loggerWithErrors } from "./util/logging";
|
||||
import { testo } from "./util/test";
|
||||
import { createMockDT } from "./mocks";
|
||||
|
||||
testo({
|
||||
// async parseDefinitions() {
|
||||
@@ -19,12 +19,12 @@ testo({
|
||||
async mockParse() {
|
||||
const log = loggerWithErrors()[0];
|
||||
const defs = await parseDefinitions(createMockDT(), undefined, log);
|
||||
expect(defs.allNotNeeded().length).toBe(1)
|
||||
expect(defs.allTypings().length).toBe(3)
|
||||
const j = defs.tryGetLatestVersion("jquery")
|
||||
expect(j).toBeDefined()
|
||||
expect(j!.fullNpmName).toContain("types")
|
||||
expect(j!.fullNpmName).toContain("jquery")
|
||||
expect(defs.allPackages().length).toEqual(defs.allTypings().length + defs.allNotNeeded().length)
|
||||
}
|
||||
expect(defs.allNotNeeded().length).toBe(1);
|
||||
expect(defs.allTypings().length).toBe(3);
|
||||
const j = defs.tryGetLatestVersion("jquery");
|
||||
expect(j).toBeDefined();
|
||||
expect(j!.fullNpmName).toContain("types");
|
||||
expect(j!.fullNpmName).toContain("jquery");
|
||||
expect(defs.allPackages().length).toEqual(defs.allTypings().length + defs.allNotNeeded().length);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -45,7 +45,7 @@ export default async function parseDefinitions(dt: FS, parallel: ParallelOptions
|
||||
commandLineArgs: [`${parallel.definitelyTypedPath}/types`],
|
||||
workerFile: definitionParserWorkerFilename,
|
||||
nProcesses: parallel.nProcesses,
|
||||
handleOutput({ data, packageName} : { data: TypingsVersionsRaw, packageName: string }) {
|
||||
handleOutput({ data, packageName}: { data: TypingsVersionsRaw, packageName: string }) {
|
||||
typings[packageName] = data;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import appInsights = require("applicationinsights");
|
||||
import * as yargs from "yargs";
|
||||
|
||||
import appInsights = require("applicationinsights");
|
||||
import { getDefinitelyTyped } from "./get-definitely-typed";
|
||||
import { Options, Registry } from "./lib/common";
|
||||
import { withNpmCache, NpmPublishClient, UncachedNpmInfoClient } from "./lib/npm-client";
|
||||
import { NpmPublishClient, UncachedNpmInfoClient, withNpmCache } from "./lib/npm-client";
|
||||
import { deprecateNotNeededPackage, publishNotNeededPackage, publishTypingsPackage } from "./lib/package-publisher";
|
||||
import { AllPackages } from "./lib/packages";
|
||||
import { ChangedPackages, readChangedPackages, skipBadPublishes } from "./lib/versions";
|
||||
@@ -23,8 +23,12 @@ if (!module.parent) {
|
||||
const log = logger()[0];
|
||||
try {
|
||||
await deprecateNotNeededPackage(
|
||||
await NpmPublishClient.create(undefined, Registry.Github), AllPackages.readSingleNotNeeded(deprecateName, dt), /*dry*/ false, log);
|
||||
} catch(e) {
|
||||
await NpmPublishClient.create(undefined, Registry.Github),
|
||||
AllPackages.readSingleNotNeeded(deprecateName, dt),
|
||||
false, /*dry*/
|
||||
log,
|
||||
);
|
||||
} catch (e) {
|
||||
// log and continue
|
||||
log("publishing to github failed: " + e.toString());
|
||||
}
|
||||
@@ -44,8 +48,7 @@ export default async function publishPackages(
|
||||
const [log, logResult] = logger();
|
||||
if (dry) {
|
||||
log("=== DRY RUN ===");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
log("=== Publishing packages ===");
|
||||
}
|
||||
|
||||
@@ -57,7 +60,7 @@ export default async function publishPackages(
|
||||
|
||||
try {
|
||||
await publishTypingsPackage(ghClient, cp, dry, log, Registry.Github);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// log and continue
|
||||
log("publishing to github failed: " + e.toString());
|
||||
}
|
||||
@@ -134,12 +137,12 @@ export default async function publishPackages(
|
||||
}
|
||||
}
|
||||
|
||||
withNpmCache(new UncachedNpmInfoClient(), async infoClient => {
|
||||
await withNpmCache(new UncachedNpmInfoClient(), async infoClient => {
|
||||
for (const n of changedPackages.changedNotNeededPackages) {
|
||||
const target = skipBadPublishes(n, infoClient, log)
|
||||
const target = skipBadPublishes(n, infoClient, log);
|
||||
try {
|
||||
await publishNotNeededPackage(ghClient, target, dry, log, Registry.Github);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// log and continue
|
||||
log("publishing to github failed: " + e.toString());
|
||||
}
|
||||
@@ -147,7 +150,6 @@ export default async function publishPackages(
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
await writeLog("publishing.md", logResult());
|
||||
console.log("Done!");
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
|
||||
|
||||
try {
|
||||
await publishToRegistry(RegistryName.Github);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// log and continue
|
||||
log("publishing to github failed: " + e.toString());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { testo, createTypingsVersionRaw } from "../util/test";
|
||||
import { AllPackages, NotNeededPackage, TypesDataFile } from "../lib/packages";
|
||||
import { createTypingsVersionRaw, testo } from "../util/test";
|
||||
|
||||
import { getAffectedPackages } from "./get-affected-packages";
|
||||
const typesData: TypesDataFile = {
|
||||
jquery: createTypingsVersionRaw("jquery", [], []),
|
||||
@@ -11,7 +12,7 @@ const typesData: TypesDataFile = {
|
||||
};
|
||||
|
||||
const notNeeded = [
|
||||
new NotNeededPackage({ typingsPackageName: "jest", libraryName: "jest", asOfVersion: "100.0.0", sourceRepoURL: "jest.com" })
|
||||
new NotNeededPackage({ typingsPackageName: "jest", libraryName: "jest", asOfVersion: "100.0.0", sourceRepoURL: "jest.com" }),
|
||||
];
|
||||
const allPackages = AllPackages.from(typesData, notNeeded);
|
||||
|
||||
@@ -26,5 +27,5 @@ testo({
|
||||
const affected = getAffectedPackages(allPackages, [{ name: "WAT", majorVersion: "*" }]);
|
||||
expect(affected.changedPackages.length).toEqual(0);
|
||||
expect(affected.dependentPackages.length).toEqual(1);
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AllPackages, PackageBase, TypingsData, PackageId, getMangledNameForScopedPackage } from "../lib/packages";
|
||||
import { AllPackages, getMangledNameForScopedPackage, PackageBase, PackageId, TypingsData } from "../lib/packages";
|
||||
import { mapDefined, mapIter, sort } from "../util/util";
|
||||
|
||||
export interface Affected {
|
||||
@@ -63,30 +63,30 @@ function transitiveClosure<T>(initialItems: Iterable<T>, getRelatedItems: (item:
|
||||
/** Generate a map from a package to packages that depend on it. */
|
||||
function getReverseDependencies(allPackages: AllPackages, changedPackages: PackageId[]): Map<PackageId, Set<PackageId>> {
|
||||
const map = new Map<string, [PackageId, Set<PackageId>]>();
|
||||
for (const changed of changedPackages) {
|
||||
for (const changed of changedPackages) {
|
||||
map.set(packageIdToKey(changed), [changed, new Set()]);
|
||||
}
|
||||
for (const typing of allPackages.allTypings()) {
|
||||
for (const typing of allPackages.allTypings()) {
|
||||
if (!map.has(packageIdToKey(typing.id))) {
|
||||
map.set(packageIdToKey(typing.id), [typing.id, new Set()]);
|
||||
}
|
||||
}
|
||||
for (const typing of allPackages.allTypings()) {
|
||||
for (const typing of allPackages.allTypings()) {
|
||||
for (const dependency of typing.dependencies) {
|
||||
const dependencies = map.get(packageIdToKey(allPackages.tryResolve(dependency)))
|
||||
const dependencies = map.get(packageIdToKey(allPackages.tryResolve(dependency)));
|
||||
if (dependencies) {
|
||||
dependencies[1].add(typing.id);
|
||||
}
|
||||
}
|
||||
for (const dependencyName of typing.testDependencies) {
|
||||
const latest = { name: dependencyName, majorVersion: "*" } as PackageId;
|
||||
const latest: PackageId = { name: dependencyName, majorVersion: "*" };
|
||||
const dependencies = map.get(packageIdToKey(allPackages.tryResolve(latest)));
|
||||
if (dependencies) {
|
||||
dependencies[1].add(typing.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Map(map.values())
|
||||
return new Map(map.values());
|
||||
}
|
||||
|
||||
function packageIdToKey(pkg: PackageId): string {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { testo, createTypingsVersionRaw } from "../util/test";
|
||||
import { AllPackages, NotNeededPackage, TypesDataFile } from "../lib/packages";
|
||||
import { checkNotNeededPackage, getNotNeededPackages, GitDiff } from "./test-runner";
|
||||
import { NpmInfo } from "../lib/npm-client";
|
||||
import { AllPackages, NotNeededPackage, TypesDataFile } from "../lib/packages";
|
||||
import { createTypingsVersionRaw, testo } from "../util/test";
|
||||
|
||||
import { checkNotNeededPackage, getNotNeededPackages, GitDiff } from "./test-runner";
|
||||
|
||||
const typesData: TypesDataFile = {
|
||||
jquery: createTypingsVersionRaw("jquery", [], []),
|
||||
@@ -13,7 +14,7 @@ const typesData: TypesDataFile = {
|
||||
};
|
||||
|
||||
const jestNotNeeded = [
|
||||
new NotNeededPackage({ typingsPackageName: "jest", libraryName: "jest", asOfVersion: "100.0.0", sourceRepoURL: "jest.com" })
|
||||
new NotNeededPackage({ typingsPackageName: "jest", libraryName: "jest", asOfVersion: "100.0.0", sourceRepoURL: "jest.com" }),
|
||||
];
|
||||
const allPackages = AllPackages.from(typesData, jestNotNeeded);
|
||||
|
||||
@@ -23,7 +24,6 @@ const deleteJestDiffs: GitDiff[] = [
|
||||
{ status: "D", file: "types/jest/jest-tests.d.ts" },
|
||||
];
|
||||
|
||||
|
||||
testo({
|
||||
ok() {
|
||||
expect(Array.from(getNotNeededPackages(allPackages, deleteJestDiffs))).toEqual(jestNotNeeded);
|
||||
@@ -32,7 +32,7 @@ testo({
|
||||
expect(() =>
|
||||
Array.from(getNotNeededPackages(
|
||||
AllPackages.from({ jest: createTypingsVersionRaw("jest", [], []) }, jestNotNeeded),
|
||||
deleteJestDiffs))).toThrow('Please delete all files in jest');
|
||||
deleteJestDiffs))).toThrow("Please delete all files in jest");
|
||||
|
||||
},
|
||||
tooManyDeletes() {
|
||||
@@ -55,7 +55,13 @@ testo({
|
||||
Array.from(getNotNeededPackages(
|
||||
AllPackages.from(
|
||||
typesData,
|
||||
[new NotNeededPackage({ typingsPackageName: "ember__object", libraryName: "@ember/object", asOfVersion: "1.0.0", sourceRepoURL: "ember.js" })]),
|
||||
[new NotNeededPackage({
|
||||
typingsPackageName: "ember__object",
|
||||
libraryName: "@ember/object",
|
||||
asOfVersion: "1.0.0",
|
||||
sourceRepoURL: "ember.js",
|
||||
})],
|
||||
),
|
||||
[{ status: "D", file: "types/ember__object/index.d.ts" }]));
|
||||
},
|
||||
// TODO: Test npm info (and with scoped names)
|
||||
@@ -81,30 +87,45 @@ testo({
|
||||
.toThrow("@types/jest is missing the \"latest\" tag");
|
||||
},
|
||||
deprecatedSameVersion() {
|
||||
expect(() => checkNotNeededPackage(jestNotNeeded[0], empty, { distTags: new Map([["latest", "100.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) }))
|
||||
.toThrow(`The specified version 100.0.0 of jest must be newer than the version
|
||||
expect(() => {
|
||||
checkNotNeededPackage(
|
||||
jestNotNeeded[0],
|
||||
empty,
|
||||
{ distTags: new Map([["latest", "100.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) },
|
||||
);
|
||||
}).toThrow(`The specified version 100.0.0 of jest must be newer than the version
|
||||
it is supposed to replace, 100.0.0 of @types/jest.`);
|
||||
},
|
||||
deprecatedOlderVersion() {
|
||||
expect(() => checkNotNeededPackage(jestNotNeeded[0], empty, { distTags: new Map([["latest", "999.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) }))
|
||||
.toThrow(`The specified version 100.0.0 of jest must be newer than the version
|
||||
expect(() => {
|
||||
checkNotNeededPackage(
|
||||
jestNotNeeded[0],
|
||||
empty,
|
||||
{ distTags: new Map([["latest", "999.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) },
|
||||
);
|
||||
}).toThrow(`The specified version 100.0.0 of jest must be newer than the version
|
||||
it is supposed to replace, 999.0.0 of @types/jest.`);
|
||||
},
|
||||
missingNpmVersion() {
|
||||
expect(() => checkNotNeededPackage(jestNotNeeded[0], empty, { distTags: new Map([["latest", "4.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) }))
|
||||
.toThrow(`The specified version 100.0.0 of jest is not on npm.`);
|
||||
expect(() => {
|
||||
checkNotNeededPackage(
|
||||
jestNotNeeded[0],
|
||||
empty,
|
||||
{ distTags: new Map([["latest", "4.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) },
|
||||
);
|
||||
}).toThrow("The specified version 100.0.0 of jest is not on npm.");
|
||||
},
|
||||
olderNpmVersion() {
|
||||
expect(() => checkNotNeededPackage(
|
||||
jestNotNeeded[0],
|
||||
{ distTags: new Map(), versions: new Map([["50.0.0", {}]]), time: new Map([["modified", ""]]) },
|
||||
{ distTags: new Map([["latest", "4.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) }))
|
||||
.toThrow(`The specified version 100.0.0 of jest is not on npm.`);
|
||||
.toThrow("The specified version 100.0.0 of jest is not on npm.");
|
||||
},
|
||||
ok() {
|
||||
checkNotNeededPackage(
|
||||
jestNotNeeded[0],
|
||||
{ distTags: new Map(), versions: new Map([["100.0.0", {}]]), time: new Map([["modified", ""]]) },
|
||||
{ distTags: new Map([["latest", "4.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) })
|
||||
{ distTags: new Map([["latest", "4.0.0"]]), versions: new Map(), time: new Map([["modified", ""]]) });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,30 +1,40 @@
|
||||
import assert = require("assert");
|
||||
import { existsSync, readFileSync } from "fs";
|
||||
import { pathExists } from "fs-extra";
|
||||
import os = require("os");
|
||||
import { existsSync, readFileSync } from "fs";
|
||||
import * as fold from "travis-fold";
|
||||
import * as yargs from "yargs";
|
||||
|
||||
import { Semver } from "../lib/versions";
|
||||
import { parseMajorVersionFromDirectoryName } from "../lib/definition-parser";
|
||||
import { sourceBranch, typesDirectoryName } from "../lib/settings";
|
||||
import { FS, getDefinitelyTyped } from "../get-definitely-typed";
|
||||
import { Options, TesterOptions } from "../lib/common";
|
||||
import { AllPackages, DependencyVersion, PackageId, TypingsData, NotNeededPackage } from "../lib/packages";
|
||||
import { UncachedNpmInfoClient, NpmInfo } from "../lib/npm-client";
|
||||
import { parseMajorVersionFromDirectoryName } from "../lib/definition-parser";
|
||||
import { NpmInfo, UncachedNpmInfoClient } from "../lib/npm-client";
|
||||
import { AllPackages, DependencyVersion, NotNeededPackage, PackageId, TypingsData } from "../lib/packages";
|
||||
import { sourceBranch, typesDirectoryName } from "../lib/settings";
|
||||
import { Semver } from "../lib/versions";
|
||||
import { npmInstallFlags } from "../util/io";
|
||||
import { consoleLogger, Logger, LoggerWithErrors, loggerWithErrors } from "../util/logging";
|
||||
import { assertDefined, exec, execAndThrowErrors, flatMap, joinPaths, logUncaughtErrors, mapIter, numberOfOsProcesses, runWithListeningChildProcesses, CrashRecoveryState } from "../util/util";
|
||||
import {
|
||||
assertDefined,
|
||||
CrashRecoveryState,
|
||||
exec,
|
||||
execAndThrowErrors,
|
||||
flatMap,
|
||||
joinPaths,
|
||||
logUncaughtErrors,
|
||||
mapIter,
|
||||
numberOfOsProcesses,
|
||||
runWithListeningChildProcesses,
|
||||
} from "../util/util";
|
||||
|
||||
import { getAffectedPackages, allDependencies } from "./get-affected-packages";
|
||||
import { allDependencies, getAffectedPackages } from "./get-affected-packages";
|
||||
|
||||
const perfDir = joinPaths(os.homedir(), ".dts", "perf");
|
||||
|
||||
if (!module.parent) {
|
||||
if (yargs.argv.affected) {
|
||||
logUncaughtErrors(testAffectedOnly(Options.defaults));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
const selection = yargs.argv.all ? "all" : yargs.argv._[0] ? new RegExp(yargs.argv._[0]) : "affected";
|
||||
const options = testerOptions(!!yargs.argv.runFromDefinitelyTyped);
|
||||
logUncaughtErrors(
|
||||
@@ -34,7 +44,7 @@ if (!module.parent) {
|
||||
|
||||
export interface GitDiff {
|
||||
status: "A" | "D" | "M";
|
||||
file: string
|
||||
file: string;
|
||||
}
|
||||
|
||||
async function testAffectedOnly(options: TesterOptions): Promise<void> {
|
||||
@@ -82,10 +92,10 @@ export async function getAffectedPackagesFromDiff(dt: FS, definitelyTypedPath: s
|
||||
const allPackages = await AllPackages.read(dt);
|
||||
const diffs = await gitDiff(consoleLogger.info, definitelyTypedPath);
|
||||
if (diffs.find(d => d.file === "notNeededPackages.json")) {
|
||||
const uncached = new UncachedNpmInfoClient()
|
||||
const uncached = new UncachedNpmInfoClient();
|
||||
for (const deleted of getNotNeededPackages(allPackages, diffs)) {
|
||||
const source = await uncached.fetchNpmInfo(deleted.libraryName) // eg @babel/parser
|
||||
const typings = await uncached.fetchNpmInfo(deleted.fullNpmName) // eg @types/babel__parser
|
||||
const source = await uncached.fetchNpmInfo(deleted.libraryName); // eg @babel/parser
|
||||
const typings = await uncached.fetchNpmInfo(deleted.fullNpmName); // eg @types/babel__parser
|
||||
checkNotNeededPackage(deleted, source, typings);
|
||||
}
|
||||
}
|
||||
@@ -107,7 +117,7 @@ export async function getAffectedPackagesFromDiff(dt: FS, definitelyTypedPath: s
|
||||
export function getNotNeededPackages(allPackages: AllPackages, diffs: GitDiff[]): Iterable<NotNeededPackage> {
|
||||
const deletedPackages = new Set(diffs.filter(d => d.status === "D").map(d =>
|
||||
assertDefined(getDependencyFromFile(d.file),
|
||||
`Unexpected file deleted: ${d.file}
|
||||
`Unexpected file deleted: ${d.file}
|
||||
When removing packages, you should only delete files that are a part of removed packages.`)
|
||||
.name));
|
||||
return mapIter(deletedPackages, p => {
|
||||
@@ -131,10 +141,18 @@ export function checkNotNeededPackage(unneeded: NotNeededPackage, source: NpmInf
|
||||
"libraryName": "${unneeded.libraryName}", but there is no npm package with this name.
|
||||
Unneeded packages have to be replaced with a package on npm.`);
|
||||
typings = assertDefined(typings, `Unexpected error: @types package not found for ${unneeded.fullNpmName}`);
|
||||
const latestTypings = Semver.parse(assertDefined(typings.distTags.get("latest"), `Unexpected error: ${unneeded.fullNpmName} is missing the "latest" tag.`));
|
||||
assert(unneeded.version.greaterThan(latestTypings), `The specified version ${unneeded.version.versionString} of ${unneeded.libraryName} must be newer than the version
|
||||
it is supposed to replace, ${latestTypings.versionString} of ${unneeded.fullNpmName}.`);
|
||||
assert(source.versions.has(unneeded.version.versionString), `The specified version ${unneeded.version.versionString} of ${unneeded.libraryName} is not on npm.`);
|
||||
const latestTypings = Semver.parse(
|
||||
assertDefined(typings.distTags.get("latest"), `Unexpected error: ${unneeded.fullNpmName} is missing the "latest" tag.`),
|
||||
);
|
||||
assert(
|
||||
unneeded.version.greaterThan(latestTypings),
|
||||
`The specified version ${unneeded.version.versionString} of ${unneeded.libraryName} must be newer than the version
|
||||
it is supposed to replace, ${latestTypings.versionString} of ${unneeded.fullNpmName}.`,
|
||||
);
|
||||
assert(
|
||||
source.versions.has(unneeded.version.versionString),
|
||||
`The specified version ${unneeded.version.versionString} of ${unneeded.libraryName} is not on npm.`,
|
||||
);
|
||||
}
|
||||
|
||||
async function doInstalls(allPackages: AllPackages, packages: Iterable<TypingsData>, typesPath: string): Promise<void> {
|
||||
@@ -262,7 +280,6 @@ async function runCommand(log: LoggerWithErrors, cwd: string | undefined, cmd: s
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Returns all immediate subdirectories of the root directory that have changed. */
|
||||
export function gitChanges(diffs: GitDiff[]): PackageId[] {
|
||||
const changedPackages = new Map<string, Set<DependencyVersion>>();
|
||||
@@ -310,7 +327,7 @@ export async function gitDiff(log: Logger, definitelyTypedPath: string): Promise
|
||||
diff = (await run(`git diff ${sourceBranch}~1 --name-status`)).trim();
|
||||
}
|
||||
return diff.split("\n").map(line => {
|
||||
var [status, file] = line.split(/\s+/, 2);
|
||||
const [status, file] = line.split(/\s+/, 2);
|
||||
return { status: status.trim(), file: file.trim() } as GitDiff;
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import parseDefinitions from "../parse-definitions";
|
||||
import { loggerWithErrors } from "../util/logging";
|
||||
import { logUncaughtErrors } from "../util/util";
|
||||
|
||||
import runTests, { parseNProcesses, testerOptions, getAffectedPackagesFromDiff } from "./test-runner";
|
||||
import runTests, { getAffectedPackagesFromDiff, parseNProcesses, testerOptions } from "./test-runner";
|
||||
|
||||
if (!module.parent) {
|
||||
const options = testerOptions(!!yargs.argv.runFromDefinitelyTyped);
|
||||
@@ -24,10 +24,9 @@ async function main(options: TesterOptions, nProcesses: number, all: boolean): P
|
||||
await parseDefinitions(dt, { nProcesses, definitelyTypedPath: options.definitelyTypedPath }, log);
|
||||
try {
|
||||
await checkParseResults(/*includeNpmChecks*/false, dt, options, new UncachedNpmInfoClient());
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
if (!all) {
|
||||
await getAffectedPackagesFromDiff(dt, options.definitelyTypedPath, "affected")
|
||||
await getAffectedPackagesFromDiff(dt, options.definitelyTypedPath, "affected");
|
||||
}
|
||||
|
||||
throw e;
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { readFile as readFileWithEncoding, readFileSync as readFileWithEncodingSync, stat, writeFile as writeFileWithEncoding, writeJson as writeJsonRaw } from "fs-extra";
|
||||
import {
|
||||
readFile as readFileWithEncoding,
|
||||
readFileSync as readFileWithEncodingSync,
|
||||
stat,
|
||||
writeFile as writeFileWithEncoding,
|
||||
writeJson as writeJsonRaw,
|
||||
} from "fs-extra";
|
||||
import { request as httpRequest } from "http";
|
||||
import { Agent, request } from "https";
|
||||
import { Readable as ReadableStream } from "stream";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { License, TypingsVersionsRaw, PackageId } from "../lib/packages";
|
||||
import { License, PackageId, TypingsVersionsRaw } from "../lib/packages";
|
||||
export function testo(o: { [s: string]: () => void }) {
|
||||
for (const k in o) {
|
||||
test(k, o[k], 100_000);
|
||||
@@ -6,10 +6,10 @@ export function testo(o: { [s: string]: () => void }) {
|
||||
}
|
||||
|
||||
export function createTypingsVersionRaw(
|
||||
name: string, dependencies: PackageId[], testDependencies: string[]
|
||||
name: string, dependencies: PackageId[], testDependencies: string[],
|
||||
): TypingsVersionsRaw {
|
||||
return {
|
||||
"1": {
|
||||
1: {
|
||||
libraryName: name,
|
||||
typingsPackageName: name,
|
||||
dependencies,
|
||||
@@ -18,7 +18,7 @@ export function createTypingsVersionRaw(
|
||||
libraryMajorVersion: 1,
|
||||
libraryMinorVersion: 0,
|
||||
pathMappings: [],
|
||||
contributors: [{ name: "Bender", url: "futurama.com", githubUsername: "bender" },],
|
||||
contributors: [{ name: "Bender", url: "futurama.com", githubUsername: "bender" }],
|
||||
minTsVersion: "2.3",
|
||||
typesVersions: [],
|
||||
license: License.MIT,
|
||||
@@ -28,5 +28,5 @@ export function createTypingsVersionRaw(
|
||||
globals: [],
|
||||
declaredModules: [],
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createWriteStream } from "fs";
|
||||
import { FStreamEntry, Reader } from "fstream";
|
||||
import { Pack } from "tar";
|
||||
import * as zlib from "zlib";
|
||||
|
||||
import { streamDone } from "./io";
|
||||
|
||||
export function gzip(input: NodeJS.ReadableStream): NodeJS.ReadableStream {
|
||||
|
||||
@@ -4,6 +4,11 @@ import * as crypto from "crypto";
|
||||
import moment = require("moment");
|
||||
import * as os from "os";
|
||||
import * as sourceMapSupport from "source-map-support";
|
||||
|
||||
import { Options } from "../lib/common";
|
||||
|
||||
import ProgressBar from "./progress";
|
||||
|
||||
sourceMapSupport.install();
|
||||
|
||||
export function assertDefined<T>(x: T | undefined, message?: string | Error | undefined): T {
|
||||
@@ -11,9 +16,6 @@ export function assertDefined<T>(x: T | undefined, message?: string | Error | un
|
||||
return x!;
|
||||
}
|
||||
|
||||
import { Options } from "../lib/common";
|
||||
import ProgressBar from "./progress";
|
||||
|
||||
const DEFAULT_CRASH_RECOVERY_MAX_OLD_SPACE_SIZE = 4096;
|
||||
|
||||
export function parseJson(text: string): object {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import appInsights = require("applicationinsights");
|
||||
import * as yargs from "yargs";
|
||||
|
||||
import appInsights = require("applicationinsights");
|
||||
import { Options } from "./lib/common";
|
||||
import { getSecret, Secret } from "./lib/secrets";
|
||||
import webhookServer from "./lib/webhook-server";
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"outDir": "bin",
|
||||
"sourceMap": true,
|
||||
"target": "es2017",
|
||||
"newLine": "crlf",
|
||||
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"no-this-assignment": [true, { "allow-destructuring": true }],
|
||||
"typedef": false,
|
||||
"no-any": false,
|
||||
"no-inferred-empty-object-type": false,
|
||||
"no-unsafe-any": false,
|
||||
"prefer-template": false,
|
||||
"restrict-plus-operands": false,
|
||||
@@ -23,6 +24,7 @@
|
||||
"completed-docs": false,
|
||||
"file-name-casing": false,
|
||||
"forin": false,
|
||||
"increment-decrement": false,
|
||||
"linebreak-style": false,
|
||||
"max-classes-per-file": false,
|
||||
"member-access": false,
|
||||
@@ -31,13 +33,17 @@
|
||||
"newline-per-chained-call": false,
|
||||
"no-console": false,
|
||||
"no-default-export": false,
|
||||
"no-default-import": false,
|
||||
"no-unused-variable": false,
|
||||
"no-magic-numbers": false,
|
||||
"no-namespace": false,
|
||||
"no-non-null-assertion": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-use-before-declare": false,
|
||||
"no-parameter-properties": false,
|
||||
"no-parameter-reassignment": false,
|
||||
"no-require-imports": false,
|
||||
"no-void-expression": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"promise-function-async": false,
|
||||
"type-literal-delimiter": false
|
||||
|
||||
Reference in New Issue
Block a user