Skip to content

Commit

Permalink
fix(formatPkg): remove non-existing versions
Browse files Browse the repository at this point in the history
These versions usually are deleted, but more evil things could also have happened, so we don't trust them!

Bonus: unkown keys like created & updated are gone now too.

fixes #534
  • Loading branch information
Haroenv committed Apr 16, 2020
1 parent 715f2f6 commit c37d6d6
Show file tree
Hide file tree
Showing 5 changed files with 2,200 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
},
"engines": {
"node": "12.10.0",
"yarn": "1.18.0"
"yarn": "1.19.1"
},
"jest": {
"testEnvironment": "node",
Expand Down
199 changes: 196 additions & 3 deletions src/__tests__/__snapshots__/formatPkg.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ Are you in trouble? Read through our [contribution guidelines](https://bitbucket
"1.1.1": "2017-04-26T10:47:09.649Z",
"1.1.2": "2017-04-27T05:48:55.305Z",
"1.1.3": "2017-07-13T08:31:37.060Z",
"1.2.0": "2017-07-17T05:23:53.444Z",
"1.3.0": "2017-07-17T06:38:13.785Z",
"1.4.0": "2017-07-17T08:15:21.975Z",
"1.5.0": "2017-07-17T11:37:29.134Z",
"1.5.1": "2017-07-25T02:42:58.085Z",
"1.5.2": "2017-07-27T05:11:40.487Z",
Expand Down Expand Up @@ -519,6 +516,202 @@ index(arr, obj);
}
`;
exports[`transforms correctly: prismjs 1`] = `
Object {
"_searchInternal": Object {
"alternativeNames": Array [
"prismjs",
"prismjs.js",
],
},
"bin": undefined,
"computedKeywords": Array [],
"computedMetadata": Object {},
"created": 1431474880643,
"dependencies": Object {
"clipboard": "^2.0.0",
},
"deprecated": false,
"description": "Lightweight, robust, elegant syntax highlighting. A spin-off project from Dabblet.",
"devDependencies": Object {
"chai": "^4.2.0",
"gulp": "^4.0.2",
"gulp-concat": "^2.3.4",
"gulp-header": "^2.0.7",
"gulp-rename": "^1.2.0",
"gulp-replace": "^1.0.0",
"gulp-uglify": "^3.0.1",
"htmlparser2": "^4.0.0",
"jsdom": "^13.0.0",
"mocha": "^6.2.0",
"pump": "^3.0.0",
"regexpp": "^2.0.1",
"simple-git": "^1.107.0",
"yargs": "^13.2.2",
},
"downloadsLast30Days": 0,
"downloadsRatio": 0,
"gitHead": "81670053da263b0fe814d58de66213a43f439b98",
"githubRepo": Object {
"head": "81670053da263b0fe814d58de66213a43f439b98",
"path": "",
"project": "prism",
"user": "LeaVerou",
},
"homepage": null,
"humanDownloadsLast30Days": "0",
"keywords": Array [
"prism",
"highlight",
],
"lastCrawl": Any<String>,
"lastPublisher": Object {
"avatar": "https://gravatar.com/avatar/9a2965a86b7596abaca73ba46716c2a1",
"email": "[email protected]",
"link": "https://www.npmjs.com/~jamesdigioia",
"name": "jamesdigioia",
},
"license": "MIT",
"modified": 1585962297069,
"moduleTypes": Array [
"unknown",
],
"name": "prismjs",
"objectID": "prismjs",
"originalAuthor": undefined,
"owner": Object {
"avatar": "https://github.com/LeaVerou.png",
"link": "https://github.com/LeaVerou",
"name": "LeaVerou",
},
"owners": Array [
Object {
"avatar": "https://gravatar.com/avatar/db1b1b2f3e2c48fa9ba7fae82a08dfb2",
"email": "[email protected]",
"link": "https://www.npmjs.com/~golmote",
"name": "golmote",
},
Object {
"avatar": "https://gravatar.com/avatar/24e5dceb090d80f5e21c9430820d5373",
"email": "[email protected]",
"link": "https://www.npmjs.com/~gpleiss",
"name": "gpleiss",
},
Object {
"avatar": "https://gravatar.com/avatar/9a2965a86b7596abaca73ba46716c2a1",
"email": "[email protected]",
"link": "https://www.npmjs.com/~jamesdigioia",
"name": "jamesdigioia",
},
Object {
"avatar": "https://gravatar.com/avatar/3869e93ce6b2a22e37cf13281d9e6f75",
"email": "[email protected]",
"link": "https://www.npmjs.com/~leaverou",
"name": "leaverou",
},
Object {
"avatar": "https://gravatar.com/avatar/0fbf1502ee778cc11715219b412c38d5",
"email": "[email protected]",
"link": "https://www.npmjs.com/~rdy",
"name": "rdy",
},
Object {
"avatar": "https://gravatar.com/avatar/1d153775485e41e8474b115e2b30413d",
"email": "[email protected]",
"link": "https://www.npmjs.com/~stubbornella",
"name": "stubbornella",
},
Object {
"avatar": "https://gravatar.com/avatar/1394eef0c510132173c0e7392cac54b6",
"email": "[email protected]",
"link": "https://www.npmjs.com/~vinsonchuong",
"name": "vinsonchuong",
},
],
"popular": false,
"readme": "# [Prism](https://prismjs.com/)
[![Build Status](https://travis-ci.org/PrismJS/prism.svg?branch=master)](https://travis-ci.org/PrismJS/prism)
[![npm](https://img.shields.io/npm/dw/prismjs.svg)](https://www.npmjs.com/package/prismjs)
Prism is a lightweight, robust, elegant syntax highlighting library. It's a spin-off project from [Dabblet](https://dabblet.com/).
You can learn more on [prismjs.com](https://prismjs.com/).
[Why another syntax highlighter?](https://lea.verou.me/2012/07/introducing-prism-an-awesome-new-syntax-highlighter/#more-1841)
[More themes for Prism!](https://github.com/PrismJS/prism-themes)
## Contribute to Prism!
Prism depends on community contributions to expand and cover a wider array of use cases. If you like it, considering giving back by sending a pull request. Here are a few tips:
- Read the [documentation](https://prismjs.com/extending.html). Prism was designed to be extensible.
- Do not edit \`prism.js\`, it’s just the version of Prism used by the Prism website and is built automatically. Limit your changes to the unminified files in the \`components/\` folder. The minified files are also generated automatically.
- The build system uses [gulp](https://github.com/gulpjs/gulp) to minify the files and build \`prism.js\`. Having gulp installed, you just need to run the command \`gulp\`.
- Please follow the code conventions used in the files already. For example, I use [tabs for indentation and spaces for alignment](http://lea.verou.me/2012/01/why-tabs-are-clearly-superior/). Opening braces are on the same line, closing braces on their own line regardless of construct. There is a space before the opening brace. etc etc.
- Please try to err towards more smaller PRs rather than few huge PRs. If a PR includes changes I want to merge and changes I don't, handling it becomes difficult.
- My time is very limited these days, so it might take a long time to review longer PRs (short ones are usually merged very quickly), especially those modifying the Prism Core. This doesn't mean your PR is rejected.
- If you contribute a new language definition, you will be responsible for handling bug reports about that language definition.
- If you add a new language definition, theme or plugin, you need to add it to \`components.json\` as well and rebuild Prism by running \`gulp\`, so that it becomes available to the download build page. For new languages, please also add a few [tests](https://prismjs.com/test-suite.html) and an example in the \`examples/\` folder.
Thank you so much for contributing!!
## Translations
* [![中文说明](http://awesomes.oss-cn-beijing.aliyuncs.com/readme.png)](https://www.awesomes.cn/repo/PrismJS/prism)
",
"repository": Object {
"branch": "81670053da263b0fe814d58de66213a43f439b98",
"head": "81670053da263b0fe814d58de66213a43f439b98",
"host": "github.com",
"path": "",
"project": "prism",
"url": "https://github.com/LeaVerou/prism",
"user": "LeaVerou",
},
"tags": Object {
"latest": "1.20.0",
},
"types": Object {
"ts": Object {
"dtsMain": "prism.d.ts",
"possible": true,
},
},
"version": "1.20.0",
"versions": Object {
"0.0.1": "2015-05-13T00:37:38.541Z",
"1.1.0": "2015-10-06T00:03:04.995Z",
"1.10.0": "2018-01-17T22:58:11.306Z",
"1.11.0": "2018-02-05T08:03:40.974Z",
"1.12.0": "2018-03-07T20:47:42.924Z",
"1.12.2": "2018-03-08T22:48:14.877Z",
"1.13.0": "2018-03-21T07:33:19.843Z",
"1.14.0": "2018-04-11T07:07:37.342Z",
"1.15.0": "2018-06-17T01:52:23.178Z",
"1.16.0": "2019-03-25T11:37:08.871Z",
"1.17.0": "2019-07-22T02:05:58.666Z",
"1.17.1": "2019-07-22T02:08:37.262Z",
"1.18.0": "2020-01-04T21:36:41.973Z",
"1.19.0": "2020-01-13T13:39:48.212Z",
"1.2.0": "2015-10-07T17:35:20.776Z",
"1.20.0": "2020-04-04T01:04:54.672Z",
"1.3.0": "2015-10-27T02:35:27.738Z",
"1.4.1": "2016-02-05T03:02:10.903Z",
"1.5.0": "2016-05-16T19:27:36.144Z",
"1.5.1": "2016-06-07T01:45:09.291Z",
"1.6.0": "2016-12-05T15:15:07.039Z",
"1.7.0": "2017-09-09T13:17:53.558Z",
"1.8.0": "2017-09-16T11:26:30.833Z",
"1.8.1": "2017-09-16T11:35:42.623Z",
"1.8.3": "2017-10-19T19:59:49.084Z",
"1.8.4": "2017-11-05T16:39:11.337Z",
"1.9.0": "2017-12-05T23:52:53.059Z",
},
}
`;
exports[`truncates long readmes 1`] = `
Object {
"_searchInternal": Object {
Expand Down
79 changes: 78 additions & 1 deletion src/__tests__/formatPkg.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import formatPkg, { getRepositoryInfo, getMains } from '../formatPkg.js';
import formatPkg, {
getRepositoryInfo,
getMains,
getVersions,
} from '../formatPkg.js';
import rawPackages from './rawPackages.json';
import preact from './preact-simplified.json';
import isISO8601 from 'validator/lib/isISO8601.js';
Expand Down Expand Up @@ -534,3 +538,76 @@ describe('getMain', () => {
expect(getMains({ main: { something: 'cool.js' } })).toEqual([]);
});
});

describe('getVersions', () => {
test("renames 'time' to versions", () => {
expect(
getVersions(
{
other: {
time: {
'1.2.3': '2020-04-04T01:04:57.069Z',
},
},
},
{
versions: {
'1.2.3': {},
},
}
)
).toEqual({
'1.2.3': '2020-04-04T01:04:57.069Z',
});
});

test("removes the 'created' and 'modified' keys", () => {
expect(
getVersions(
{
other: {
time: {
created: '2020-04-04T01:04:57.069Z',
modified: '2030-04-04T01:04:57.069Z',
'1.2.3': '2020-04-04T01:04:57.069Z',
},
},
},
{
versions: {
'1.2.3': {},
},
}
)
).toEqual({
'1.2.3': '2020-04-04T01:04:57.069Z',
});
});

test("removes versions which don't exist in 'versions'", () => {
expect(
getVersions(
{
other: {
time: {
created: '2020-04-04T01:04:57.069Z',
modified: '2030-04-04T01:04:57.069Z',
'9000.10000.5': '3020-04-04T01:04:57.069Z',
'1.2.3': '2020-04-04T01:04:57.069Z',
'2.3.4': '2020-04-04T01:04:57.069Z',
},
},
},
{
versions: {
'1.2.3': {},
'2.3.4': {},
},
}
)
).toEqual({
'1.2.3': '2020-04-04T01:04:57.069Z',
'2.3.4': '2020-04-04T01:04:57.069Z',
});
});
});
Loading

0 comments on commit c37d6d6

Please sign in to comment.