-
Notifications
You must be signed in to change notification settings - Fork 232
Switch back to official npm libs from @qiwi/npm-registry-client
#1245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ef69e27
Switch back to official npm libs from @qiwi/npm-registry-client
jakebailey 530e16d
Changeset
jakebailey 80e5521
Fix type errors I think
jakebailey 49a1c51
fmt
jakebailey 4b13172
update thing
jakebailey 0380425
Don't name drop
jakebailey 83a5233
tag
jakebailey 1f1ca89
bring readme back, npm does it
jakebailey 75e7cf0
Merge branch 'main' into remove-qiwi
jakebailey 812f0ae
remove deprecate, it's been unused for 4 years
jakebailey 79acea9
unused dep
jakebailey f91357f
Don't bother with registry
jakebailey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,89 +1,86 @@ | ||
| 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"; | ||
| import { createTgz, streamToBuffer } from "./io"; | ||
|
|
||
| export const npmRegistryHostName = "registry.npmjs.org"; | ||
| export const npmRegistry = `https://${npmRegistryHostName}/`; | ||
|
|
||
| export const cacheDir = joinPaths(process.env.GITHUB_ACTIONS ? joinPaths(__dirname, "../../..") : os.tmpdir(), "cache"); | ||
|
|
||
| type NeedToFixNpmRegistryClientTypings = any; | ||
|
|
||
| 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?: {}): Promise<NpmPublishClient> { | ||
| return new NpmPublishClient(token, npmRegistry); | ||
| } | ||
|
|
||
| private constructor( | ||
| private readonly client: RegClient, | ||
| private readonly auth: NeedToFixNpmRegistryClientTypings, | ||
| private readonly token: string, | ||
| private readonly registry: string, | ||
| ) {} | ||
|
|
||
| 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} to ${this.registry}`); | ||
| return; | ||
| } | ||
|
|
||
| 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, | ||
| ); | ||
| }), | ||
| ); | ||
| await publish(packageJson as { name: string; version: string }, tarballBuffer, { | ||
| registry: this.registry, | ||
| token: this.token, | ||
| access: "public", | ||
| }); | ||
| } | ||
|
|
||
| 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", | ||
| registry: this.registry, | ||
| 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(); | ||
| } | ||
| async deprecate(packageName: string, version: string, message: string): Promise<void> { | ||
| // Fetch the current package metadata | ||
| const packument = (await npmFetch.json(`/${encodeURIComponent(packageName)}`, { | ||
| registry: this.registry, | ||
| token: this.token, | ||
| })) as { versions: Record<string, { deprecated?: string }> }; | ||
|
|
||
| // Update the deprecated field for the specified version | ||
| if (!packument.versions[version]) { | ||
| throw new Error(`Version ${version} not found in ${packageName}`); | ||
| } | ||
| packument.versions[version].deprecated = message; | ||
|
|
||
| // PUT the updated packument back | ||
| await npmFetch(`/${encodeURIComponent(packageName)}`, { | ||
| method: "PUT", | ||
| registry: this.registry, | ||
| token: this.token, | ||
| body: packument, | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.