Skip to content

Commit

Permalink
fix: šŸ› list all versions, including the newly published one when compā€¦
Browse files Browse the repository at this point in the history
ā€¦uting deprecations
  • Loading branch information
ghusse authored Jan 3, 2022
2 parents 557f069 + 096ce4a commit eae29b2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.3.1-alpha.1](https://github.com/ghusse/semantic-release-npm-deprecate-old-versions/compare/v1.3.0...v1.3.1-alpha.1) (2022-01-03)


### Bug Fixes

* :bug: list all versions, including the newly published one when computing deprecations ([#34](https://github.com/ghusse/semantic-release-npm-deprecate-old-versions/issues/34)) ([24e3067](https://github.com/ghusse/semantic-release-npm-deprecate-old-versions/commit/24e3067eea8fb96c0cdc06d173ce65aff5c06fe6))

# [1.3.0](https://github.com/ghusse/semantic-release-npm-deprecate-old-versions/compare/v1.2.3...v1.3.0) (2021-12-31)


Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "semantic-release-npm-deprecate-old-versions",
"version": "1.3.0",
"version": "1.3.1-alpha.1",
"description": "A plugin for semantic-release, to automatically deprecate old versions on npm, based on a custom configuration",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/package-info.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface PackageBasicInfo {
name: string;
version: string;
versions: string[];
}

Expand Down
1 change: 1 addition & 0 deletions src/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ describe("npm", () => {

const info: PackageBasicInfo = {
name: "name",
version: "1.0.0",
versions: ["1.0.0"],
};

Expand Down
46 changes: 46 additions & 0 deletions src/package-info-retriever.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,52 @@ describe("PackageInfoRetriever", () => {

verifyAll();
});

it("should add the version from basic info when the api did not return it", async () => {
const { packageInfoRetriever, npmApi, npm } = setup();
const npmConfig = mock<NpmConfig>();
const context = mock<Context & Config>();

const basicInfo = {
name: "my-package",
version: "1.1.0",
};
when(npm.getBasicInfo(instance(context))).thenResolve(basicInfo as any);

const packageInfo: PackageInfo = {
name: "my-package",
versions: {
"1.0.0": {
name: "my-package",
version: "1.0.0",
},
},
};
when(
npmApi.getInfo(basicInfo.name, instance(npmConfig), instance(context))
).thenResolve(packageInfo);

const info = await packageInfoRetriever.getInfo(
instance(npmConfig),
instance(context)
);

expect(info).toEqual({
name: "my-package",
versions: {
"1.0.0": {
name: "my-package",
version: "1.0.0",
},
"1.1.0": {
name: "my-package",
version: "1.1.0",
},
},
});

verifyAll();
});
});
});
});
21 changes: 20 additions & 1 deletion src/package-info-retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,26 @@ export class PackageInfoRetriever {
return undefined;
}

return this.npmApi.getInfo(basicInfo.name, npmConfig, context);
const completeInfo = await this.npmApi.getInfo(
basicInfo.name,
npmConfig,
context
);

if (completeInfo && !completeInfo.versions[basicInfo.version]) {
return {
...completeInfo,
versions: {
...completeInfo.versions,
[basicInfo.version]: {
name: basicInfo.name,
version: basicInfo.version,
},
},
};
}

return completeInfo;
}

private async getBasicInfo(
Expand Down

0 comments on commit eae29b2

Please sign in to comment.