Skip to content

Commit a3d70c4

Browse files
author
Gilad Gray
committed
add INpmPackage version property, straight from package.json
1 parent d0343bc commit a3d70c4

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/__tests__/npm.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ describe("NpmPlugin", () => {
1717
// NOTE: not using snapshot as it would change with every release due to `npm info` call.
1818
expect(documentalist.name).toBe(pkg.name);
1919
expect(documentalist.description).toBe(pkg.description);
20-
expect(documentalist.latestVersion).toBe(pkg.version);
20+
expect(documentalist.version).toBe(pkg.version);
21+
expect(documentalist.latestVersion).toBeDefined(); // npm-info succeeded
2122
});
2223

2324
it("handles npm info fails", async () => {
2425
const { npm: { doesNotExist } } = await dm.documentFiles([
2526
{ path: "package.json", read: () => `{ "name": "doesNotExist", "version": "1.0.0" }` },
2627
]);
2728
expect(doesNotExist.name).toBe("doesNotExist");
28-
expect(doesNotExist.latestVersion).toBe("1.0.0");
29+
expect(doesNotExist.version).toBe("1.0.0");
2930
expect(doesNotExist.published).toBe(false);
31+
expect(doesNotExist.latestVersion).toBeUndefined();
3032
});
3133

3234
it("options", async () => {

src/client/npm.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ export interface INpmPackage {
1212
/** Package description. */
1313
description?: string;
1414

15-
/** Latest version of the package (npm `latest` dist-tag). */
16-
latestVersion: string;
15+
/** Version string from package.json. */
16+
version: string;
1717

18-
/** Next version of the package (npm `next` dist-tag). */
18+
/** NPM `latest` dist-tag version. */
19+
latestVersion?: string;
20+
21+
/** NPM `next` dist-tag version. */
1922
nextVersion?: string;
2023

2124
/** Whether this package is marked `private`. */
@@ -27,7 +30,7 @@ export interface INpmPackage {
2730
/** Relative path from `sourceBaseDir` to this package. */
2831
sourcePath: string;
2932

30-
/** All published versions of this package. */
33+
/** All published versions of this package. If published, this contains only `version`. */
3134
versions: string[];
3235
}
3336

src/plugins/npm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export class NpmPlugin implements IPlugin<INpmPluginData> {
4444
return {
4545
name: json.name,
4646
published: false,
47+
version: json.version,
4748
// tslint:disable-next-line:object-literal-sort-keys
4849
description: json.description,
49-
latestVersion: json.version,
5050
private: json.private === true,
5151
sourcePath,
5252
versions: [json.version],
@@ -57,6 +57,7 @@ export class NpmPlugin implements IPlugin<INpmPluginData> {
5757
return {
5858
name: data.name,
5959
published: true,
60+
version: json.version,
6061
// tslint:disable-next-line:object-literal-sort-keys
6162
description: data.description,
6263
latestVersion: distTags.latest,

0 commit comments

Comments
 (0)