diff --git a/README.md b/README.md index bd92c07f0..4afce7599 100644 --- a/README.md +++ b/README.md @@ -17,19 +17,27 @@ If the process fails, restart it and the replication process will continue at th - -- [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) @@ -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', diff --git a/src/@types/nice-package.ts b/src/@types/nice-package.ts index fc391179d..2e6bde6cd 100644 --- a/src/@types/nice-package.ts +++ b/src/@types/nice-package.ts @@ -7,7 +7,7 @@ export interface NicePackageType { bundlesize?: Array>; created: string; dependencies?: Record; - deprecated?: boolean; + deprecated?: boolean | string; description: string; devDependencies?: Record; gitHead?: string; diff --git a/src/@types/pkg.ts b/src/@types/pkg.ts index 64f10fbe8..7d37b67b3 100644 --- a/src/@types/pkg.ts +++ b/src/@types/pkg.ts @@ -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[]; diff --git a/src/__tests__/__snapshots__/formatPkg.test.ts.snap b/src/__tests__/__snapshots__/formatPkg.test.ts.snap index c838251e1..8f72ec473 100644 --- a/src/__tests__/__snapshots__/formatPkg.test.ts.snap +++ b/src/__tests__/__snapshots__/formatPkg.test.ts.snap @@ -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, + "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", @@ -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", @@ -671,6 +745,7 @@ Object { "githubRepo": null, "homepage": "https://bitbucket.org/atlassian/atlaskit#readme", "humanDownloadsLast30Days": "0", + "isDeprecated": false, "keywords": Array [ "atlaskit", "ui", @@ -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", @@ -893,6 +969,7 @@ Object { }, "homepage": null, "humanDownloadsLast30Days": "0", + "isDeprecated": false, "keywords": Array [], "lastCrawl": Any, "lastPublisher": Object { @@ -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", @@ -1019,6 +1097,7 @@ Object { }, "homepage": null, "humanDownloadsLast30Days": "0", + "isDeprecated": false, "keywords": Array [ "algolia", "instantsearch", @@ -1097,6 +1176,7 @@ Object { "created": 1346430013243, "dependencies": Object {}, "deprecated": false, + "deprecatedReason": null, "description": "Microsoft sucks", "devDependencies": Object {}, "downloadsLast30Days": 0, @@ -1105,6 +1185,7 @@ Object { "githubRepo": null, "homepage": null, "humanDownloadsLast30Days": "0", + "isDeprecated": false, "keywords": Array [ "index", "array", @@ -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", @@ -1211,6 +1293,7 @@ Object { }, "homepage": null, "humanDownloadsLast30Days": "0", + "isDeprecated": false, "keywords": Array [ "prism", "highlight", @@ -1383,6 +1466,7 @@ Object { "created": NaN, "dependencies": Object {}, "deprecated": false, + "deprecatedReason": null, "description": null, "devDependencies": Object {}, "downloadsLast30Days": 0, @@ -1396,6 +1480,7 @@ Object { }, "homepage": null, "humanDownloadsLast30Days": "0", + "isDeprecated": false, "keywords": Array [], "lastCrawl": Any, "lastPublisher": null, diff --git a/src/__tests__/formatPkg.test.ts b/src/__tests__/formatPkg.test.ts index 7dfa39bb5..c070aff85 100644 --- a/src/__tests__/formatPkg.test.ts +++ b/src/__tests__/formatPkg.test.ts @@ -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', + }); + }); +}); diff --git a/src/config.ts b/src/config.ts index c7b2060e6..23581f480 100644 --- a/src/config.ts +++ b/src/config.ts @@ -16,6 +16,7 @@ const indexSettings: Settings = { 'searchable(computedKeywords)', 'searchable(owner.name)', 'deprecated', + 'isDeprecated', 'types.ts', 'moduleTypes', ], @@ -35,6 +36,7 @@ const indexSettings: Settings = { 'proximity', 'attribute', 'asc(deprecated)', + 'asc(isDeprecated)', 'asc(badPackage)', 'desc(popular)', 'exact', diff --git a/src/formatPkg.ts b/src/formatPkg.ts index 91cc67266..adcfa8d7b 100644 --- a/src/formatPkg.ts +++ b/src/formatPkg.ts @@ -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, @@ -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, diff --git a/src/npm/types.ts b/src/npm/types.ts index 641d65e43..61c5e53f1 100644 --- a/src/npm/types.ts +++ b/src/npm/types.ts @@ -20,6 +20,8 @@ export interface GetVersion { _id: string; _npmUser?: GetUser; _npmVersion?: string; + _nodeVersion?: string; + _npmOperationalInternal?: Record; author?: GetUser; description: string; dist: { @@ -32,6 +34,7 @@ export interface GetVersion { name: string; scripts?: Record; version: string; + deprecated?: string | boolean; } export interface PackageRepo {