-
Notifications
You must be signed in to change notification settings - Fork 151
Add gitHead to package.json #543
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,11 @@ import { sourceBranch } from "./settings"; | |
|
||
const mitLicense = readFileSync(joinPaths(__dirname, "..", "..", "LICENSE"), "utf-8"); | ||
|
||
export async function generateTypingPackage(typing: TypingsData, packages: AllPackages, version: string, dt: FS): Promise<void> { | ||
export async function generateTypingPackage(typing: TypingsData, packages: AllPackages, version: string, dt: FS, gitHead: string): Promise<void> { | ||
const typesDirectory = dt.subDir("types").subDir(typing.name); | ||
const packageFS = typing.isLatest ? typesDirectory : typesDirectory.subDir(`v${typing.major}`); | ||
|
||
const packageJson = await createPackageJSON(typing, version, packages); | ||
const packageJson = await createPackageJSON(typing, version, gitHead, packages); | ||
await writeCommonOutputs(typing, packageJson, createReadme(typing)); | ||
await Promise.all(typing.files.map(async file => writeFile(await outputFilePath(typing, file), await packageFS.readFile(file)))); | ||
} | ||
|
@@ -52,11 +52,12 @@ async function outputFilePath(pkg: AnyPackage, filename: string): Promise<string | |
|
||
interface Dependencies { [name: string]: string; } | ||
|
||
async function createPackageJSON(typing: TypingsData, version: string, packages: AllPackages): Promise<string> { | ||
async function createPackageJSON(typing: TypingsData, version: string, gitHead: string, packages: AllPackages): Promise<string> { | ||
// Use the ordering of fields from https://docs.npmjs.com/files/package.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the documentation doesn't mention gitHead, so I suspect this comment isn't true for gitHead. I'm not sure whether that matters though. Any idea how to find out where npm's package.json puts gitHead? I tried looking at unpgk's version but it doesn't appear to be there either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can find it in the registry API response: http://registry.npmjs.org/commander/latest But the order of keys shouldn't really matter in an object. It gets added by npm here: https://github.com/npm/read-package-json/blob/1b85cf87f5875774e7fbc617f606923d8cbda6a4/read-json.js#L345 |
||
const out: {} = { | ||
name: typing.fullNpmName, | ||
version, | ||
gitHead, | ||
description: `TypeScript definitions for ${typing.libraryName}`, | ||
// keywords, | ||
// homepage, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Fetcher } from "./io"; | ||
import { logger } from "./logging"; | ||
|
||
export async function queryGithub(path: string, githubToken: string, fetcher: Fetcher) { | ||
const [log] = logger(); | ||
log("Requesting from github: " + path); | ||
return fetcher.fetchJson({ | ||
hostname: "api.github.com", | ||
path: path + "&access_token=" + githubToken, | ||
method: "GET", | ||
headers: { | ||
// arbitrary string, but something must be provided | ||
"User-Agent": "types-publisher", | ||
}, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is master the correct SHA to use here? In particular, it's possible that it may have moved between the time that this package was merged. Another package may have been merged in between.
I think it would be better if you use the latest sha just for the package's directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really matter - this SHA will be used to download the zip, so it is guaranteed that
gitHead
points to the exact revision that is being published. That is all that should matter.It would be nice, but I wouldn't know where to get that commit from. Can you point to where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here’s the code I used, although that was using octokit. The rest call shouldn’t be too different though.
DefinitelyTyped/types-publisher-watchdog@f647115#diff-168726dbe96b3ce427e7fedce31bb0bcL76
Look at the part I deleted starting with
const oops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so you would get the latest commit from the git log of that folder. I thought you were suggesting to use the commit ID from the triggering event, e.g. the commit hash of the merge commit of a PR that was merged which triggered the new publish