Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/two-books-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@definitelytyped/definitions-parser": patch
"@definitelytyped/utils": patch
---

Switch back to official npm libs
3 changes: 1 addition & 2 deletions .knip.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
},
"packages/utils": {
"entry": ["src/index.ts", "src/types/*.ts"],
"project": "**/*.ts",
"ignoreDependencies": ["@qiwi/npm-types"]
"project": "**/*.ts"
},
"packages/mergebot": {
"entry": ["src/functions/index.ts", "src/run.ts", "src/commands/create-fixture.ts", "src/commands/update-all-fixtures.ts", "src/commands/update-test-data.ts", "src/scripts/updateJSONFixtures.ts"],
Expand Down
2 changes: 1 addition & 1 deletion packages/definitions-parser/src/data-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "fs";
import { writeJson, joinPaths, readFileAndWarn } from "@definitelytyped/utils";
import { dataDirPath } from "./lib/settings";

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

Expand Down
2 changes: 1 addition & 1 deletion packages/publisher/src/lib/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ChangedPackages {
}

export async function readChangedPackages(allPackages: AllPackages): Promise<ChangedPackages> {
const json = (await readDataFile("calculate-versions", versionsFilename)) as ChangedPackagesJson;
const json = (await readDataFile("calculate-versions", versionsFilename)) as unknown as ChangedPackagesJson;
return {
changedTypings: await Promise.all(
json.changedTypings.map(async ({ id, version, latestVersion }) => ({
Expand Down
2 changes: 1 addition & 1 deletion packages/publisher/src/publish-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default async function publishPackages(
log("=== Publishing packages ===");
}

const client = await NpmPublishClient.create(await getSecret(Secret.NPM_TYPES_TOKEN), undefined);
const client = await NpmPublishClient.create(await getSecret(Secret.NPM_TYPES_TOKEN));

for (const cp of changedPackages.changedTypings) {
log(`Publishing ${cp.pkg.desc}...`);
Expand Down
10 changes: 7 additions & 3 deletions packages/publisher/src/publish-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default async function publishRegistry(dt: FS, allPackages: AllPackages,
}
}

async function generate(registry: string, packageJson: {}): Promise<void> {
async function generate(registry: string, packageJson: Record<string, unknown>): Promise<void> {
await fs.promises.rm(registryOutputPath, { recursive: true, force: true });
await fs.promises.mkdir(registryOutputPath, { recursive: true });
await writeOutputJson("package.json", packageJson);
Expand All @@ -118,7 +118,7 @@ async function generate(registry: string, packageJson: {}): Promise<void> {
async function publish(
client: NpmPublishClient,
packageName: string,
packageJson: {},
packageJson: Record<string, unknown>,
version: string,
dry: boolean,
log: Logger,
Expand Down Expand Up @@ -211,7 +211,11 @@ function assertJsonNewer(newer: { [s: string]: any }, older: { [s: string]: any
}
}

function generatePackageJson(name: string, version: string, typesPublisherContentHash: string): object {
function generatePackageJson(
name: string,
version: string,
typesPublisherContentHash: string,
): Record<string, unknown> {
const json = {
name,
version,
Expand Down
2 changes: 1 addition & 1 deletion packages/retag/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function tag(dry: boolean, definitelyTypedPath: string, name?: string) {
const dt = await getDefinitelyTyped(options, log);
const token = process.env.NPM_TOKEN as string;

const publishClient = await NpmPublishClient.create(token, {});
const publishClient = await NpmPublishClient.create(token);
if (name) {
const pkg = await AllPackages.readSingle(dt, name);
const version = await getLatestTypingVersion(pkg);
Expand Down
6 changes: 4 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
"url": "https://github.com/microsoft/DefinitelyTyped-tools/issues"
},
"dependencies": {
"@qiwi/npm-registry-client": "^8.9.1",
"@types/node": "^25.1.0",
"cachedir": "^2.4.0",
"charm": "^1.0.2",
"libnpmpublish": "^11.1.3",
"minimatch": "^10.1.1",
"npm-registry-fetch": "^19.1.1",
"tar": "^7.5.7",
"tar-stream": "^3.1.7",
"which": "^6.0.0"
},
"devDependencies": {
"@qiwi/npm-types": "^1.0.3",
"@types/charm": "^1.0.6",
"@types/libnpmpublish": "^9.0.1",
"@types/npm-registry-fetch": "^8.0.8",
"@types/tar-stream": "^3.1.4",
"@types/which": "^3.0.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function readFileSync(path: string): string {
}

/** If a file doesn't exist, warn and tell the step it should have been generated by. */
export async function readFileAndWarn(generatedBy: string, filePath: string): Promise<object> {
export async function readFileAndWarn(generatedBy: string, filePath: string): Promise<Record<string, unknown>> {
try {
return await readJson(filePath, isObject);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/miscellany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function identity<T>(t: T): T {
return t;
}

export function isObject(value: unknown): value is object {
export function isObject(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object";
}

Expand Down
104 changes: 41 additions & 63 deletions packages/utils/src/npm.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,67 @@
import * as os from "os";
import process from "process";
import fs from "fs";
import RegClient from "@qiwi/npm-registry-client";
import { resolve as resolveUrl } from "url";
import { publish } from "libnpmpublish";
import npmFetch from "npm-registry-fetch";
import { joinPaths } from "./fs";
import { Logger } from "./logging";
import { createTgz } from "./io";

export const npmRegistryHostName = "registry.npmjs.org";
export const npmRegistry = `https://${npmRegistryHostName}/`;
import { createTgz, streamToBuffer } from "./io";

export const cacheDir = joinPaths(process.env.GITHUB_ACTIONS ? joinPaths(__dirname, "../../..") : os.tmpdir(), "cache");

type NeedToFixNpmRegistryClientTypings = any;
export interface NpmPublishClientConfig {
defaultTag?: string;
}

export class NpmPublishClient {
static async create(token: string, config?: NeedToFixNpmRegistryClientTypings): Promise<NpmPublishClient> {
return new NpmPublishClient(new RegClient(config), { token }, npmRegistry);
static async create(token: string, config: NpmPublishClientConfig = {}): Promise<NpmPublishClient> {
return new NpmPublishClient(token, config.defaultTag);
}

private constructor(
private readonly client: RegClient,
private readonly auth: NeedToFixNpmRegistryClientTypings,
private readonly registry: string,
private readonly token: string,
private readonly defaultTag: string | undefined,
) {}

async publish(publishedDirectory: string, packageJson: {}, dry: boolean, log: Logger): Promise<void> {
const readme = await fs.promises.readFile(joinPaths(publishedDirectory, "README.md"));
async publish(
publishedDirectory: string,
packageJson: Record<string, unknown>,
dry: boolean,
log: Logger,
): Promise<void> {
if (dry) {
log(`(dry) Skip publish of ${publishedDirectory}`);
return;
}

const readme = await fs.promises.readFile(joinPaths(publishedDirectory, "README.md"), "utf-8");
const tarballBuffer = await streamToBuffer(
createTgz(publishedDirectory, (err) => {
throw err;
}),
);

return new Promise<void>((resolve, reject) => {
const body = createTgz(publishedDirectory, reject);
const metadata = { readme, ...packageJson };
if (dry) {
log(`(dry) Skip publish of ${publishedDirectory} to ${this.registry}`);
}
resolve(
dry
? undefined
: promisifyVoid((cb) => {
this.client.publish(
this.registry,
{
access: "public",
auth: this.auth,
metadata: metadata as NeedToFixNpmRegistryClientTypings,
body: body as NeedToFixNpmRegistryClientTypings,
},
cb,
);
}),
);
const manifest = { ...packageJson, readme } as unknown as { name: string; version: string };
await publish(manifest, tarballBuffer, {
token: this.token,
access: "public",
tag: this.defaultTag,
});
}

tag(packageName: string, version: string, distTag: string, dry: boolean, log: Logger): Promise<void> {
async tag(packageName: string, version: string, distTag: string, dry: boolean, log: Logger): Promise<void> {
if (dry) {
log(`(dry) Skip tag of ${packageName}@${distTag} as ${version}`);
return Promise.resolve();
return;
}
return promisifyVoid((cb) => {
this.client.distTags.add(this.registry, { package: packageName, version, distTag, auth: this.auth }, cb);
});
}

deprecate(packageName: string, version: string, message: string): Promise<void> {
const url = resolveUrl(npmRegistry, packageName);
const params = {
message,
version,
auth: this.auth,
};
return promisifyVoid((cb) => {
this.client.deprecate(url, params, cb);
await npmFetch(`/-/package/${encodeURIComponent(packageName)}/dist-tags/${encodeURIComponent(distTag)}`, {
method: "PUT",
token: this.token,
body: JSON.stringify(version),
headers: {
"content-type": "application/json",
},
});
}
}

function promisifyVoid(callsBack: (cb: (error: Error | undefined) => void) => void): Promise<void> {
return new Promise<void>((resolve, reject) => {
callsBack((error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}
Loading
Loading