Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deprecated facets should be boolean #638

Merged
merged 5 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,27 @@ If the process fails, restart it and the replication process will continue at th
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Algolia Index](#algolia-index)
- [Schema](#schema)
- [Ranking](#ranking)
- [Usage](#usage)
- [Production](#production)
- [Restart](#restart)
- [Development](#development)
- [Env variables](#env-variables)
- [How does it work?](#how-does-it-work)
- [Tests](#tests)
- [Deploying new version](#deploying-new-version)
- [Forcing a complete re-index](#forcing-a-complete-re-index)
- [🗿 npm-search ⛷ 🐌 🛰](#-npm-search---)
- [Algolia Index](#algolia-index)
- [Schema](#schema)
- [Ranking](#ranking)
- [Textual relevance](#textual-relevance)
- [Searchable Attributes](#searchable-attributes)
- [Prefix Search](#prefix-search)
- [Typo-tolerance](#typo-tolerance)
- [Exact Boosting](#exact-boosting)
- [Custom/Business relevance](#custombusiness-relevance)
- [Number of downloads](#number-of-downloads)
- [Popular packages](#popular-packages)
- [Usage](#usage)
- [Production](#production)
- [Restart](#restart)
- [Development](#development)
- [Env variables](#env-variables)
- [How does it work?](#how-does-it-work)
- [Tests](#tests)
- [Deploying new version](#deploying-new-version)
- [Forcing a complete re-index](#forcing-a-complete-re-index)

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

Expand Down Expand Up @@ -81,7 +89,9 @@ For every single NPM package, we create a record in the Algolia index. The resul
avatar: 'https://github.com/babel.png',
link: 'https://github.com/babel',
},
deprecated: false,
deprecated: 'Deprecated', // This field will be removed, please use `isDeprecated` instead
isDeprecated: true,
deprecatedReason: 'Deprecated',
badPackage: false,
homepage: 'https://babeljs.io/',
license: 'MIT',
Expand Down
2 changes: 1 addition & 1 deletion src/@types/nice-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface NicePackageType {
bundlesize?: Array<Record<string, unknown>>;
created: string;
dependencies?: Record<string, string>;
deprecated?: boolean;
deprecated?: boolean | string;
description: string;
devDependencies?: Record<string, string>;
gitHead?: string;
Expand Down
4 changes: 3 additions & 1 deletion src/@types/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export interface RawPkg {
gitHead: string | null;
readme: string;
owner: Owner | null;
deprecated: boolean;
deprecated: string | boolean;
isDeprecated: boolean;
deprecatedReason: string | null;
homepage: string | null;
license: string | null;
keywords: string[];
Expand Down
85 changes: 85 additions & 0 deletions src/__tests__/__snapshots__/formatPkg.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,78 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`deprecated log deprecated reason and flag 1`] = `
Object {
"_searchInternal": Object {
"alternativeNames": Array [
"0",
"0.js",
"0js",
],
},
"bin": Object {},
"computedKeywords": Array [],
"computedMetadata": Object {},
"created": NaN,
"dependencies": Object {},
"deprecated": "Yes this is deprecated",
"deprecatedReason": "Yes this is deprecated",
"description": null,
"devDependencies": Object {},
"downloadsLast30Days": 0,
"downloadsRatio": 0,
"gitHead": "master",
"githubRepo": Object {
"head": "master",
"path": "",
"project": "npm-search",
"user": "algolia",
},
"homepage": null,
"humanDownloadsLast30Days": "0",
"isDeprecated": true,
"keywords": Array [],
"lastCrawl": Any<String>,
"lastPublisher": null,
"license": null,
"modified": NaN,
"moduleTypes": Array [
"unknown",
],
"name": "0",
"objectID": "0",
"originalAuthor": undefined,
"owner": Object {
"avatar": "https://github.com/algolia.png",
"link": "https://github.com/algolia",
"name": "algolia",
},
"owners": Array [],
"popular": false,
"readme": "",
"repository": Object {
"branch": "master",
"head": undefined,
"host": "github.com",
"path": "",
"project": "npm-search",
"type": "git",
"url": "https://github.com/algolia/npm-search",
"user": "algolia",
},
"tags": Object {
"latest": "1.2.3",
},
"types": Object {
"ts": Object {
"dtsMain": "index.d.ts",
"possible": true,
},
},
"version": "0.0.0",
"versions": Object {},
}
`;

exports[`nice-package should nice atlaskit 1`] = `
Package {
"_resolved": "file:packages/input",
Expand Down Expand Up @@ -661,6 +734,7 @@ Object {
"styled-components": "^1.4.6",
},
"deprecated": false,
"deprecatedReason": null,
"description": "Internal component used by field-base to create field-text. DO NOT USE DIRECTLY",
"devDependencies": Object {
"@atlaskit/field-base": "^8.0.2",
Expand All @@ -671,6 +745,7 @@ Object {
"githubRepo": null,
"homepage": "https://bitbucket.org/atlassian/atlaskit#readme",
"humanDownloadsLast30Days": "0",
"isDeprecated": false,
"keywords": Array [
"atlaskit",
"ui",
Expand Down Expand Up @@ -856,6 +931,7 @@ Object {
"@atomic-package/utility": "0.0.2",
},
"deprecated": false,
"deprecatedReason": null,
"description": "atomic-package - tab",
"devDependencies": Object {
"@types/node": "^7.0.14",
Expand Down Expand Up @@ -893,6 +969,7 @@ Object {
},
"homepage": null,
"humanDownloadsLast30Days": "0",
"isDeprecated": false,
"keywords": Array [],
"lastCrawl": Any<String>,
"lastPublisher": Object {
Expand Down Expand Up @@ -990,6 +1067,7 @@ Object {
"validate-npm-package-name": "3.0.0",
},
"deprecated": false,
"deprecatedReason": null,
"description": "⚡️ Build InstantSearch apps at the speed of thought",
"devDependencies": Object {
"babel-eslint": "10.0.1",
Expand Down Expand Up @@ -1019,6 +1097,7 @@ Object {
},
"homepage": null,
"humanDownloadsLast30Days": "0",
"isDeprecated": false,
"keywords": Array [
"algolia",
"instantsearch",
Expand Down Expand Up @@ -1097,6 +1176,7 @@ Object {
"created": 1346430013243,
"dependencies": Object {},
"deprecated": false,
"deprecatedReason": null,
"description": "Microsoft sucks",
"devDependencies": Object {},
"downloadsLast30Days": 0,
Expand All @@ -1105,6 +1185,7 @@ Object {
"githubRepo": null,
"homepage": null,
"humanDownloadsLast30Days": "0",
"isDeprecated": false,
"keywords": Array [
"index",
"array",
Expand Down Expand Up @@ -1183,6 +1264,7 @@ Object {
"clipboard": "^2.0.0",
},
"deprecated": false,
"deprecatedReason": null,
"description": "Lightweight, robust, elegant syntax highlighting. A spin-off project from Dabblet.",
"devDependencies": Object {
"chai": "^4.2.0",
Expand Down Expand Up @@ -1211,6 +1293,7 @@ Object {
},
"homepage": null,
"humanDownloadsLast30Days": "0",
"isDeprecated": false,
"keywords": Array [
"prism",
"highlight",
Expand Down Expand Up @@ -1383,6 +1466,7 @@ Object {
"created": NaN,
"dependencies": Object {},
"deprecated": false,
"deprecatedReason": null,
"description": null,
"devDependencies": Object {},
"downloadsLast30Days": 0,
Expand All @@ -1396,6 +1480,7 @@ Object {
},
"homepage": null,
"humanDownloadsLast30Days": "0",
"isDeprecated": false,
"keywords": Array [],
"lastCrawl": Any<String>,
"lastPublisher": null,
Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/formatPkg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,28 @@ describe('getVersions', () => {
});
});
});

describe('deprecated', () => {
it('log deprecated reason and flag', () => {
const pkg: GetPackage = {
...BASE,
'dist-tags': {
latest: '1.2.3',
},
versions: {
'1.2.3': {
...BASE_VERSION,
deprecated: 'Yes this is deprecated',
},
},
};
const formatted = formatPkg(pkg);

expect(formatted).toMatchSnapshot({
lastCrawl: expect.any(String),
deprecated: 'Yes this is deprecated',
isDeprecated: true,
deprecatedReason: 'Yes this is deprecated',
});
});
});
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const indexSettings: Settings = {
'searchable(computedKeywords)',
'searchable(owner.name)',
'deprecated',
'isDeprecated',
'types.ts',
'moduleTypes',
],
Expand All @@ -35,6 +36,7 @@ const indexSettings: Settings = {
'proximity',
'attribute',
'asc(deprecated)',
'asc(isDeprecated)',
'asc(badPackage)',
'desc(popular)',
'exact',
Expand Down
6 changes: 5 additions & 1 deletion src/formatPkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export default function formatPkg(pkg: GetPackage): RawPkg | undefined {
const moduleTypes = getModuleTypes(cleaned);

const tags = pkg['dist-tags'];
const isDeprecated =
cleaned.deprecated !== undefined && cleaned.deprecated !== false;

const rawPkg: RawPkg = {
objectID: cleaned.name,
Expand All @@ -157,7 +159,9 @@ export default function formatPkg(pkg: GetPackage): RawPkg | undefined {
gitHead: githubRepo ? githubRepo.head : null, // remove this when we update to the new schema frontend
readme: pkg.readme,
owner,
deprecated: cleaned.deprecated !== undefined ? cleaned.deprecated : false,
deprecated: isDeprecated ? cleaned.deprecated! : false,
isDeprecated,
deprecatedReason: isDeprecated ? String(cleaned.deprecated) : null,
homepage: getHomePage(cleaned),
license,
keywords,
Expand Down
3 changes: 3 additions & 0 deletions src/npm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface GetVersion {
_id: string;
_npmUser?: GetUser;
_npmVersion?: string;
_nodeVersion?: string;
_npmOperationalInternal?: Record<string, string>;
author?: GetUser;
description: string;
dist: {
Expand All @@ -32,6 +34,7 @@ export interface GetVersion {
name: string;
scripts?: Record<string, string>;
version: string;
deprecated?: string | boolean;
}

export interface PackageRepo {
Expand Down