Skip to content

Commit

Permalink
Update imports for publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Mar 5, 2020
1 parent c8a7c5d commit ed92171
Show file tree
Hide file tree
Showing 102 changed files with 572 additions and 5,514 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.DS_Store
*.log
dist
dist
*.tsbuildinfo
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
testEnvironment: "node",
globals: {
"ts-jest": {
tsConfig: "./tsconfig.test.json"
tsConfig: "./tsconfig.test.json",
diagnostics: false
}
}
};
17 changes: 17 additions & 0 deletions packages/definitions-parser/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "parse-definitions.js",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/bin/parse-definitions.js",
"args": [],
"sourceMaps": true
}
]
}
16 changes: 16 additions & 0 deletions packages/definitions-parser/src/dataFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ensureDir } from "fs-extra";
import { writeJson, joinPaths, readFileAndWarn } from "@definitelytyped/utils";
import { dataDirPath } from "./lib/settings";

export function readDataFile(generatedBy: string, fileName: string): Promise<object> {
return readFileAndWarn(generatedBy, dataFilePath(fileName));
}

export async function writeDataFile(filename: string, content: {}, formatted = true): Promise<void> {
await ensureDir(dataDirPath);
await writeJson(dataFilePath(filename), content, formatted);
}

export function dataFilePath(filename: string): string {
return joinPaths(dataDirPath, filename);
}
16 changes: 15 additions & 1 deletion packages/definitions-parser/src/getDefinitelyTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ import {
} from "@definitelytyped/utils";

import { dataDirPath, definitelyTypedZipUrl } from "./lib/settings";
import { ParseDefinitionsOptions } from "./lib/common";

/** Settings that may be determined dynamically. */
export interface ParseDefinitionsOptions {
/**
* e.g. '../DefinitelyTyped'
* This is overridden to `cwd` when running the tester, as that is run from within DefinitelyTyped.
* If undefined, downloads instead.
*/
readonly definitelyTypedPath: string | undefined;
/** Whether to show progress bars. Good when running locally, bad when running in CI. */
readonly progress: boolean;
/** Disabled in CI since it has problems logging errors from other processes. */
readonly parseInParallel: boolean;
}

export async function getDefinitelyTyped(options: ParseDefinitionsOptions, log: LoggerWithErrors): Promise<FS> {
if (options.definitelyTypedPath === undefined) {
Expand All @@ -27,3 +40,4 @@ export async function getDefinitelyTyped(options: ParseDefinitionsOptions, log:
export function getLocallyInstalledDefinitelyTyped(path: string): FS {
return new DiskFS(`${path}/`);
}

2 changes: 2 additions & 0 deletions packages/definitions-parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from "./dataFile";
export * from "./getDefinitelyTyped";
export * from "./parseDefinitions";
export * from "./packages";
44 changes: 0 additions & 44 deletions packages/definitions-parser/src/lib/common.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/definitions-parser/src/lib/definition-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TypingsDataRaw,
TypingsVersionsRaw,
TypingVersion,
} from "./packages";
} from "../packages";
import { dependenciesWhitelist } from "./settings";
import { FS, split, mapDefined, filter, sort, withoutStart, computeHash, hasWindowsSlashes, join, flatMap, unique, unmangleScopedPackage } from "@definitelytyped/utils";

Expand Down
3 changes: 3 additions & 0 deletions packages/definitions-parser/src/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ export const definitelyTypedZipUrl = "https://codeload.github.com/DefinitelyType

export const dependenciesWhitelist: ReadonlySet<string> =
new Set(readFileSync(joinPaths(root, "dependenciesWhitelist.txt")).split(/\r?\n/));

/** Note: this is 'types' and not '@types' */
export const scopeName = "types";
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import assert = require("assert");
import { AllTypeScriptVersion, Author, TypeScriptVersion } from "definitelytyped-header-parser";

import { FS } from "../getDefinitelyTyped";
import { assertSorted, joinPaths, mapValues, unmangleScopedPackage } from "../util/util";

import { readDataFile } from "./common";
import { outputDirPath, scopeName } from "./settings";
import { compare as compareSemver, Semver } from "./versions";
import { AllTypeScriptVersion, Author, TypeScriptVersion } from "@definitelytyped/header-parser";
import { FS, mapValues, assertSorted, unmangleScopedPackage, joinPaths, Semver } from "@definitelytyped/utils";
import { readDataFile } from "./dataFile";
import { outputDirPath, scopeName } from "./lib/settings";

export class AllPackages {
static async read(dt: FS): Promise<AllPackages> {
Expand Down Expand Up @@ -451,7 +447,7 @@ export class TypingsVersions {
* Sorted from latest to oldest so that we publish the current version first.
* This is important because older versions repeatedly reset the "latest" tag to the current version.
*/
this.versions = Array.from(versionMappings.keys()).sort(compareSemver).reverse();
this.versions = Array.from(versionMappings.keys()).sort(Semver.compare).reverse();

this.map = new Map(this.versions.map(version => {
const dataKey = versionMappings.get(version)!;
Expand Down
6 changes: 3 additions & 3 deletions packages/definitions-parser/src/parseDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { FS, LoggerWithErrors, filterNAtATimeOrdered, runWithChildProcesses } from "@definitelytyped/utils";
import { writeDataFile } from "./lib/common";
import { writeDataFile } from "./dataFile";
import { getTypingInfo } from "./lib/definition-parser";
import { definitionParserWorkerFilename } from "./lib/definition-parser-worker";
import { AllPackages, readNotNeededPackages, typesDataFilename, TypingsVersionsRaw } from "./lib/packages";
import { AllPackages, readNotNeededPackages, typesDataFilename, TypingsVersionsRaw } from "./packages";

export interface ParallelOptions {
readonly nProcesses: number;
readonly definitelyTypedPath: string;
}

export default async function parseDefinitions(dt: FS, parallel: ParallelOptions | undefined, log: LoggerWithErrors): Promise<AllPackages> {
export async function parseDefinitions(dt: FS, parallel: ParallelOptions | undefined, log: LoggerWithErrors): Promise<AllPackages> {
log.info("Parsing definitions...");
const typesFS = dt.subDir("types");
const packageNames = await filterNAtATimeOrdered(parallel ? parallel.nProcesses : 1, typesFS.readdir(), name => typesFS.isDirectory(name));
Expand Down
10 changes: 10 additions & 0 deletions packages/definitions-parser/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"references": [
{ "path": ".." },
{ "path": "../../definitions-parser" }
]
}
2 changes: 1 addition & 1 deletion packages/header-parser/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
Expand Down
3 changes: 1 addition & 2 deletions packages/header-parser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"noFallthroughCasesInSwitch": true
"rootDir": "src"
}
}

Loading

0 comments on commit ed92171

Please sign in to comment.