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(dev): upgrade env #592

Merged
merged 8 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
- node/install-packages:
pkg-manager: yarn

# - run:
# name: Lint
# command: yarn lint
- run:
name: Lint
command: yarn lint

# - run:
# name: Test
# command: yarn test
- run:
name: Test
command: yarn test


workflows:
Expand Down
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
"ignorePackages": true
}
]
],
// temp during mig
"jsdoc/require-param-description": "off",
"jsdoc/require-description": "off",
"jsdoc/no-undefined-types": "off"
}
}
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
npm run test
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.10.0
14.16.1
bodinsamuel marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not migrated to v16?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not yet LTS, it's in october

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
before_install:
- curl -o- -L yarnpkg.com/install.sh | bash -s -- --version 1.18.0
- curl -o- -L yarnpkg.com/install.sh | bash -s -- --version 1.22.0
- export PATH=$HOME/.yarn/bin:$PATH
branches:
only:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[npm](https://www.npmjs.com/) ↔️ [Algolia](https://www.algolia.com/) replication tool.

[![CircleCI](https://circleci.com/gh/algolia/npm-search/tree/master.svg?style=svg))](https://circleci.com/gh/algolia/npm-search/tree/master)

---

This is a failure resilient npm registry to Algolia index replication process.
Expand All @@ -13,9 +15,9 @@ The replication should always be running. **Only one instance per Algolia index
If the process fails, restart it and the replication process will continue at the last point it remembers.

<!-- 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)
Expand Down Expand Up @@ -251,8 +253,8 @@ When the process starts with `seq=0`:

Replicate and watch are separated because:

1. In replicate we want to replicate a batch of documents in a fast way
2. In watch we want new changes as fast as possible, one by one. If watch was
1. In replicate we want to replicate a batch of documents in a fast way
2. In watch we want new changes as fast as possible, one by one. If watch was
asking for batches of 100, new packages would be added too late to the index

## Tests
Expand Down
4 changes: 3 additions & 1 deletion __mocks__/dotenv.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable import/no-commonjs */

const { join } = require('path');

const { config } = require('dotenv');
const dotenv = jest.genMockFromModule('dotenv');

const dotenv = jest.createMockFromModule('dotenv');

dotenv.config = () => config({ path: join(__dirname, 'mock.env') });

Expand Down
51 changes: 21 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
"url": "https://www.algolia.com"
},
"scripts": {
"start": "node --max-old-space-size=920 --experimental-modules src/index.js",
"test": "jest --forceExit && eslint .",
"start": "node --max-old-space-size=920 src/index.js",
"test": "jest --forceExit",
"test:watch": "jest --watchAll --no-watchman",
"format": "prettier --write **/*.{js,md,json}",
"doctoc": "doctoc --notitle --maxlevel 3 README.md"
},
"lint-staged": {
"*.js": [
"prettier --write",
"git add"
]
"lint": "eslint --ext=jsx,ts,tsx,js .",
"doctoc": "doctoc --notitle --maxlevel 3 README.md",
"prepare": "husky install"
},
"renovate": {
"extends": [
Expand Down Expand Up @@ -59,37 +54,33 @@
"babel-eslint": "10.1.0",
"babel-jest": "24.9.0",
"doctoc": "1.4.0",
"eslint": "7.26.0",
"eslint-config-algolia": "13.4.0",
"eslint-config-prettier": "6.15.0",
"eslint-import-resolver-webpack": "0.13.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jasmine": "2.10.1",
"eslint-plugin-jest": "22.21.0",
"eslint-plugin-prettier": "3.3.1",
"eslint-plugin-react": "7.22.0",
"husky": "3.1.0",
"jest": "24.9.0",
"lint-staged": "9.5.0",
"eslint": "7.27.0",
"eslint-config-algolia": "18.0.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-import": "2.23.4",
"eslint-plugin-jasmine": "4.1.2",
"eslint-plugin-jest": "24.3.6",
"eslint-plugin-jsdoc": "35.1.2",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.24.0",
"husky": "6.0.0",
"jest": "27.0.4",
"lint-staged": "11.0.0",
"pre-commit": "1.2.2",
"prettier": "1.19.1",
"prettier": "2.3.0",
"renovate-config-algolia": "2.1.3",
"validator": "11.1.0"
},
"engines": {
"node": "12.10.0",
"yarn": "1.18.0"
"node": "14.16.1",
"yarn": "^1.22.0"
},
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": [
"node_modules",
"lib"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
2 changes: 1 addition & 1 deletion src/__tests__/changelog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jest.mock('got', () => {
'https://unpkg.com/@atlaskit/button@13.3.7/CHANGELOG.md',
]);

return url =>
return (url) =>
gotSnapshotUrls.has(url)
? Promise.resolve({ url, redirectUrls: [] })
: Promise.reject(`got mock does not exist for ${url}`); // eslint-disable-line prefer-promise-reject-errors
Expand Down
28 changes: 17 additions & 11 deletions src/__tests__/formatPkg.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import isISO8601 from 'validator/lib/isISO8601.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';
import rawPackages from './rawPackages.json';

it('transforms correctly', () => {
rawPackages
.map(formatPkg)
.map(element => {
.map((element) => {
expect(isISO8601(element.lastCrawl)).toBe(true);
return element;
})
.map(formattedPackage =>
.map((formattedPackage) =>
expect(formattedPackage).toMatchSnapshot(
{
lastCrawl: expect.any(String),
Expand All @@ -26,7 +28,7 @@ it('transforms correctly', () => {

it('keeps .bin intact', () => {
const createInstantSearchApp = rawPackages.find(
pkg => pkg.name === 'create-instantsearch-app'
(pkg) => pkg.name === 'create-instantsearch-app'
);
const formatted = formatPkg(createInstantSearchApp);
expect(formatted.bin).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -115,13 +117,17 @@ describe('adds vue-cli plugins', () => {
const formattedUnofficialDogs = formatPkg(unofficialDogs);
const formattedScopedDogs = formatPkg(scopedDogs);

expect(formattedDogs.keywords).toEqual([]);
expect(formattedUnofficialDogs.keywords).toEqual([]);
expect(formattedScopedDogs.keywords).toEqual([]);
it('should format correctly', () => {
expect(formattedDogs.keywords).toEqual([]);
expect(formattedUnofficialDogs.keywords).toEqual([]);
expect(formattedScopedDogs.keywords).toEqual([]);

expect(formattedDogs.computedKeywords).toEqual(['vue-cli-plugin']);
expect(formattedUnofficialDogs.computedKeywords).toEqual(['vue-cli-plugin']);
expect(formattedScopedDogs.computedKeywords).toEqual(['vue-cli-plugin']);
expect(formattedDogs.computedKeywords).toEqual(['vue-cli-plugin']);
expect(formattedUnofficialDogs.computedKeywords).toEqual([
'vue-cli-plugin',
]);
expect(formattedScopedDogs.computedKeywords).toEqual(['vue-cli-plugin']);
});
});

describe('adds yeoman generators', () => {
Expand Down
7 changes: 0 additions & 7 deletions src/__tests__/nodeVersion.test.js

This file was deleted.

9 changes: 5 additions & 4 deletions src/__tests__/typescript.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
jest.mock('../npm');
jest.mock('../unpkg');
import { getTypeScriptSupport } from '../typescriptSupport.js';
import * as npm from '../npm/index.js';
import { getTypeScriptSupport } from '../typescriptSupport.js';
import { fileExistsInUnpkg } from '../unpkg.js';

jest.mock('../npm');
jest.mock('../unpkg');

describe('getTypeScriptSupport()', () => {
it('If types are already calculated - return early', async () => {
const typesSupport = await getTypeScriptSupport({
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('getTypeScriptSupport()', () => {
});
});

it('Checks for a d.ts resolved version of main ', async () => {
it('Checks for a d.ts resolved version of main', async () => {
npm.validatePackageExists.mockResolvedValue(false);
fileExistsInUnpkg.mockResolvedValue(true);

Expand Down
3 changes: 2 additions & 1 deletion src/algolia/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function createClient(appId, apiKey, indexName) {
}

/**
* Prepare algolia for indexing
* Prepare algolia for indexing.
*
* @param {object} config
*/
async function prepare(config) {
Expand Down
8 changes: 5 additions & 3 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ms from 'ms';

import * as algolia from './algolia/index.js';
import config from './config.js';
import datadog from './datadog.js';
import log from './log.js';
import ms from 'ms';
import * as npm from './npm/index.js';
import saveDocs from './saveDocs.js';

Expand All @@ -15,7 +16,7 @@ let loopStart;
* It is useful if:
* - you are starting this project for the first time
* - you messed up with your Algolia index
* - you lagged too much behind
* - you lagged too much behind.
*
* Watch mode should/can be reliably left running for weeks/months as CouchDB is made for that.
* BUT for the moment it's mandatory to relaunch it because it's the only way to update: typescript, downloads stats.
Expand Down Expand Up @@ -67,7 +68,8 @@ async function run(stateManager, algoliaClient, mainIndex, bootstrapIndex) {

/**
* Execute one loop for bootstrap,
* Fetch N packages from `lastId`, process and save them to Algolia
* Fetch N packages from `lastId`, process and save them to Algolia.
*
* @param {string} lastId
*/
async function loop(lastId, stateManager, bootstrapIndex) {
Expand Down
10 changes: 5 additions & 5 deletions src/changelog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import got from 'got';
import race from 'promise-rat-race';

import datadog from './datadog.js';
import config from './config.js';
import datadog from './datadog.js';

export const baseUrlMap = new Map([
[
Expand Down Expand Up @@ -37,7 +37,7 @@ async function handledGot(file) {
// I am unsure what gitlab does
result &&
result.redirectUrls &&
result.redirectUrls.find(res =>
result.redirectUrls.find((res) =>
res.startsWith('https://bitbucket.org/account/signin')
)
) {
Expand All @@ -49,7 +49,7 @@ async function handledGot(file) {

async function raceFromPaths(files) {
try {
const { url } = await race(files.map(file => handledGot(file)));
const { url } = await race(files.map((file) => handledGot(file)));
return { changelogFilename: url };
} catch (e) {
return { changelogFilename: null };
Expand Down Expand Up @@ -78,7 +78,7 @@ function getChangelog({ repository, name, version }) {
];

const unpkgFiles = fileOptions.map(
file => `${config.unpkgRoot}/${name}@${version}/${file}`
(file) => `${config.unpkgRoot}/${name}@${version}/${file}`
);

if (repository === null) {
Expand All @@ -99,7 +99,7 @@ function getChangelog({ repository, name, version }) {

const baseUrl = baseUrlMap.get(host)(repository);

const files = fileOptions.map(file =>
const files = fileOptions.map((file) =>
[baseUrl.replace(/\/$/, ''), file].join('/')
);

Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import dotenv from 'dotenv';
dotenv.config();
import ms from 'ms';

dotenv.config();

const defaultConfig = {
npmRegistryEndpoint: 'https://replicate.npmjs.com',
npmRegistryDBName: 'registry',
Expand Down
2 changes: 1 addition & 1 deletion src/createStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const defaultState = {
bootstrapLastId: undefined,
};

export default algoliaIndex => {
export default (algoliaIndex) => {
let currentState;

return {
Expand Down
1 change: 1 addition & 0 deletions src/datadog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import StatsD from 'hot-shots';

import log from './log.js';

const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev';
Expand Down
Loading