Skip to content

Commit 19d30d0

Browse files
author
Samuel Bodin
authored
fix: deprecated facets should be boolean (#638)
* fix: deprecated facets should be boolean * it will be a string * do not change original field
1 parent 4653d89 commit 19d30d0

File tree

8 files changed

+148
-17
lines changed

8 files changed

+148
-17
lines changed

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,27 @@ If the process fails, restart it and the replication process will continue at th
1717
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1818
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1919

20-
21-
- [Algolia Index](#algolia-index)
22-
- [Schema](#schema)
23-
- [Ranking](#ranking)
24-
- [Usage](#usage)
25-
- [Production](#production)
26-
- [Restart](#restart)
27-
- [Development](#development)
28-
- [Env variables](#env-variables)
29-
- [How does it work?](#how-does-it-work)
30-
- [Tests](#tests)
31-
- [Deploying new version](#deploying-new-version)
32-
- [Forcing a complete re-index](#forcing-a-complete-re-index)
20+
- [🗿 npm-search ⛷ 🐌 🛰](#-npm-search---)
21+
- [Algolia Index](#algolia-index)
22+
- [Schema](#schema)
23+
- [Ranking](#ranking)
24+
- [Textual relevance](#textual-relevance)
25+
- [Searchable Attributes](#searchable-attributes)
26+
- [Prefix Search](#prefix-search)
27+
- [Typo-tolerance](#typo-tolerance)
28+
- [Exact Boosting](#exact-boosting)
29+
- [Custom/Business relevance](#custombusiness-relevance)
30+
- [Number of downloads](#number-of-downloads)
31+
- [Popular packages](#popular-packages)
32+
- [Usage](#usage)
33+
- [Production](#production)
34+
- [Restart](#restart)
35+
- [Development](#development)
36+
- [Env variables](#env-variables)
37+
- [How does it work?](#how-does-it-work)
38+
- [Tests](#tests)
39+
- [Deploying new version](#deploying-new-version)
40+
- [Forcing a complete re-index](#forcing-a-complete-re-index)
3341

3442
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3543

@@ -81,7 +89,9 @@ For every single NPM package, we create a record in the Algolia index. The resul
8189
avatar: 'https://github.com/babel.png',
8290
link: 'https://github.com/babel',
8391
},
84-
deprecated: false,
92+
deprecated: 'Deprecated', // This field will be removed, please use `isDeprecated` instead
93+
isDeprecated: true,
94+
deprecatedReason: 'Deprecated',
8595
badPackage: false,
8696
homepage: 'https://babeljs.io/',
8797
license: 'MIT',

src/@types/nice-package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface NicePackageType {
77
bundlesize?: Array<Record<string, unknown>>;
88
created: string;
99
dependencies?: Record<string, string>;
10-
deprecated?: boolean;
10+
deprecated?: boolean | string;
1111
description: string;
1212
devDependencies?: Record<string, string>;
1313
gitHead?: string;

src/@types/pkg.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export interface RawPkg {
5858
gitHead: string | null;
5959
readme: string;
6060
owner: Owner | null;
61-
deprecated: boolean;
61+
deprecated: string | boolean;
62+
isDeprecated: boolean;
63+
deprecatedReason: string | null;
6264
homepage: string | null;
6365
license: string | null;
6466
keywords: string[];

src/__tests__/__snapshots__/formatPkg.test.ts.snap

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,78 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`deprecated log deprecated reason and flag 1`] = `
4+
Object {
5+
"_searchInternal": Object {
6+
"alternativeNames": Array [
7+
"0",
8+
"0.js",
9+
"0js",
10+
],
11+
},
12+
"bin": Object {},
13+
"computedKeywords": Array [],
14+
"computedMetadata": Object {},
15+
"created": NaN,
16+
"dependencies": Object {},
17+
"deprecated": "Yes this is deprecated",
18+
"deprecatedReason": "Yes this is deprecated",
19+
"description": null,
20+
"devDependencies": Object {},
21+
"downloadsLast30Days": 0,
22+
"downloadsRatio": 0,
23+
"gitHead": "master",
24+
"githubRepo": Object {
25+
"head": "master",
26+
"path": "",
27+
"project": "npm-search",
28+
"user": "algolia",
29+
},
30+
"homepage": null,
31+
"humanDownloadsLast30Days": "0",
32+
"isDeprecated": true,
33+
"keywords": Array [],
34+
"lastCrawl": Any<String>,
35+
"lastPublisher": null,
36+
"license": null,
37+
"modified": NaN,
38+
"moduleTypes": Array [
39+
"unknown",
40+
],
41+
"name": "0",
42+
"objectID": "0",
43+
"originalAuthor": undefined,
44+
"owner": Object {
45+
"avatar": "https://github.com/algolia.png",
46+
"link": "https://github.com/algolia",
47+
"name": "algolia",
48+
},
49+
"owners": Array [],
50+
"popular": false,
51+
"readme": "",
52+
"repository": Object {
53+
"branch": "master",
54+
"head": undefined,
55+
"host": "github.com",
56+
"path": "",
57+
"project": "npm-search",
58+
"type": "git",
59+
"url": "https://github.com/algolia/npm-search",
60+
"user": "algolia",
61+
},
62+
"tags": Object {
63+
"latest": "1.2.3",
64+
},
65+
"types": Object {
66+
"ts": Object {
67+
"dtsMain": "index.d.ts",
68+
"possible": true,
69+
},
70+
},
71+
"version": "0.0.0",
72+
"versions": Object {},
73+
}
74+
`;
75+
376
exports[`nice-package should nice atlaskit 1`] = `
477
Package {
578
"_resolved": "file:packages/input",
@@ -661,6 +734,7 @@ Object {
661734
"styled-components": "^1.4.6",
662735
},
663736
"deprecated": false,
737+
"deprecatedReason": null,
664738
"description": "Internal component used by field-base to create field-text. DO NOT USE DIRECTLY",
665739
"devDependencies": Object {
666740
"@atlaskit/field-base": "^8.0.2",
@@ -671,6 +745,7 @@ Object {
671745
"githubRepo": null,
672746
"homepage": "https://bitbucket.org/atlassian/atlaskit#readme",
673747
"humanDownloadsLast30Days": "0",
748+
"isDeprecated": false,
674749
"keywords": Array [
675750
"atlaskit",
676751
"ui",
@@ -856,6 +931,7 @@ Object {
856931
"@atomic-package/utility": "0.0.2",
857932
},
858933
"deprecated": false,
934+
"deprecatedReason": null,
859935
"description": "atomic-package - tab",
860936
"devDependencies": Object {
861937
"@types/node": "^7.0.14",
@@ -893,6 +969,7 @@ Object {
893969
},
894970
"homepage": null,
895971
"humanDownloadsLast30Days": "0",
972+
"isDeprecated": false,
896973
"keywords": Array [],
897974
"lastCrawl": Any<String>,
898975
"lastPublisher": Object {
@@ -990,6 +1067,7 @@ Object {
9901067
"validate-npm-package-name": "3.0.0",
9911068
},
9921069
"deprecated": false,
1070+
"deprecatedReason": null,
9931071
"description": "⚡️ Build InstantSearch apps at the speed of thought",
9941072
"devDependencies": Object {
9951073
"babel-eslint": "10.0.1",
@@ -1019,6 +1097,7 @@ Object {
10191097
},
10201098
"homepage": null,
10211099
"humanDownloadsLast30Days": "0",
1100+
"isDeprecated": false,
10221101
"keywords": Array [
10231102
"algolia",
10241103
"instantsearch",
@@ -1097,6 +1176,7 @@ Object {
10971176
"created": 1346430013243,
10981177
"dependencies": Object {},
10991178
"deprecated": false,
1179+
"deprecatedReason": null,
11001180
"description": "Microsoft sucks",
11011181
"devDependencies": Object {},
11021182
"downloadsLast30Days": 0,
@@ -1105,6 +1185,7 @@ Object {
11051185
"githubRepo": null,
11061186
"homepage": null,
11071187
"humanDownloadsLast30Days": "0",
1188+
"isDeprecated": false,
11081189
"keywords": Array [
11091190
"index",
11101191
"array",
@@ -1183,6 +1264,7 @@ Object {
11831264
"clipboard": "^2.0.0",
11841265
},
11851266
"deprecated": false,
1267+
"deprecatedReason": null,
11861268
"description": "Lightweight, robust, elegant syntax highlighting. A spin-off project from Dabblet.",
11871269
"devDependencies": Object {
11881270
"chai": "^4.2.0",
@@ -1211,6 +1293,7 @@ Object {
12111293
},
12121294
"homepage": null,
12131295
"humanDownloadsLast30Days": "0",
1296+
"isDeprecated": false,
12141297
"keywords": Array [
12151298
"prism",
12161299
"highlight",
@@ -1383,6 +1466,7 @@ Object {
13831466
"created": NaN,
13841467
"dependencies": Object {},
13851468
"deprecated": false,
1469+
"deprecatedReason": null,
13861470
"description": null,
13871471
"devDependencies": Object {},
13881472
"downloadsLast30Days": 0,
@@ -1396,6 +1480,7 @@ Object {
13961480
},
13971481
"homepage": null,
13981482
"humanDownloadsLast30Days": "0",
1483+
"isDeprecated": false,
13991484
"keywords": Array [],
14001485
"lastCrawl": Any<String>,
14011486
"lastPublisher": null,

src/__tests__/formatPkg.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,28 @@ describe('getVersions', () => {
698698
});
699699
});
700700
});
701+
702+
describe('deprecated', () => {
703+
it('log deprecated reason and flag', () => {
704+
const pkg: GetPackage = {
705+
...BASE,
706+
'dist-tags': {
707+
latest: '1.2.3',
708+
},
709+
versions: {
710+
'1.2.3': {
711+
...BASE_VERSION,
712+
deprecated: 'Yes this is deprecated',
713+
},
714+
},
715+
};
716+
const formatted = formatPkg(pkg);
717+
718+
expect(formatted).toMatchSnapshot({
719+
lastCrawl: expect.any(String),
720+
deprecated: 'Yes this is deprecated',
721+
isDeprecated: true,
722+
deprecatedReason: 'Yes this is deprecated',
723+
});
724+
});
725+
});

src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const indexSettings: Settings = {
1616
'searchable(computedKeywords)',
1717
'searchable(owner.name)',
1818
'deprecated',
19+
'isDeprecated',
1920
'types.ts',
2021
'moduleTypes',
2122
],
@@ -35,6 +36,7 @@ const indexSettings: Settings = {
3536
'proximity',
3637
'attribute',
3738
'asc(deprecated)',
39+
'asc(isDeprecated)',
3840
'asc(badPackage)',
3941
'desc(popular)',
4042
'exact',

src/formatPkg.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ export default function formatPkg(pkg: GetPackage): RawPkg | undefined {
137137
const moduleTypes = getModuleTypes(cleaned);
138138

139139
const tags = pkg['dist-tags'];
140+
const isDeprecated =
141+
cleaned.deprecated !== undefined && cleaned.deprecated !== false;
140142

141143
const rawPkg: RawPkg = {
142144
objectID: cleaned.name,
@@ -157,7 +159,9 @@ export default function formatPkg(pkg: GetPackage): RawPkg | undefined {
157159
gitHead: githubRepo ? githubRepo.head : null, // remove this when we update to the new schema frontend
158160
readme: pkg.readme,
159161
owner,
160-
deprecated: cleaned.deprecated !== undefined ? cleaned.deprecated : false,
162+
deprecated: isDeprecated ? cleaned.deprecated! : false,
163+
isDeprecated,
164+
deprecatedReason: isDeprecated ? String(cleaned.deprecated) : null,
161165
homepage: getHomePage(cleaned),
162166
license,
163167
keywords,

src/npm/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface GetVersion {
2020
_id: string;
2121
_npmUser?: GetUser;
2222
_npmVersion?: string;
23+
_nodeVersion?: string;
24+
_npmOperationalInternal?: Record<string, string>;
2325
author?: GetUser;
2426
description: string;
2527
dist: {
@@ -32,6 +34,7 @@ export interface GetVersion {
3234
name: string;
3335
scripts?: Record<string, string>;
3436
version: string;
37+
deprecated?: string | boolean;
3538
}
3639

3740
export interface PackageRepo {

0 commit comments

Comments
 (0)