Skip to content

Commit

Permalink
Deploy 2023, Jan 31 (Merge PR #381)
Browse files Browse the repository at this point in the history
* Update dependencies
* Move to typescript
* Implemented the redirection for contribute.json using router.redirect
  • Loading branch information
julienw committed Jan 31, 2023
2 parents 2bbdd93 + 8dd6930 commit 8027cf1
Show file tree
Hide file tree
Showing 103 changed files with 2,961 additions and 12,303 deletions.
5 changes: 1 addition & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
presets: [
["@babel/preset-env", { targets: { node: true }}],
// The "all" property is needed for Flow to properly parse the syntax. It has
// trouble understanding when the flow comment is the second comment.
// See: https://github.com/babel/babel/issues/9845
["@babel/preset-flow", { all: true }]
"@babel/preset-typescript"
],
plugins: [
// Without `loose`, the transformation uses `Object.defineProperty` which
Expand Down
9 changes: 4 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ workflows:
- lint-js
- build
- yarn_lock
- flow
- typescript
- license-check
- shellcheck/check:
name: "Shellcheck"
Expand Down Expand Up @@ -102,11 +102,11 @@ jobs:
- run: yarn test-python
- run: yarn lint-python

flow:
typescript:
executor: node
steps:
- checkout-and-dependencies
- run: yarn flow:ci
- run: yarn ts

yarn_lock:
executor: node
Expand All @@ -133,8 +133,7 @@ jobs:
steps:
- checkout-and-dependencies
# This sets up a remote environment that's necessary to run docker commands.
- setup_remote_docker:
version: 19.03.12
- setup_remote_docker
- run:
name: "Build the Docker image"
command: yarn docker:build --pull --build-arg circle_build_url=$CIRCLE_BUILD_URL
Expand Down
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

47 changes: 32 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
module.exports = {
env: {
es6: true,
Expand All @@ -7,7 +6,6 @@ module.exports = {
parser: '@babel/eslint-parser',
extends: [
'eslint:recommended',
'plugin:flowtype/recommended',
// This works with the prettier plugin, this needs to be at the end always.
// Replace it with the "prettier" config if we remove the plugin.
'plugin:prettier/recommended',
Expand All @@ -19,22 +17,20 @@ module.exports = {
},
sourceType: 'module',
},
plugins: ['@babel', 'flowtype', 'import', 'prettier'],
plugins: ['@babel', 'import', 'prettier'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
rules: {
// Plugin rules:
'import/no-duplicates': 'error',
'import/no-unresolved': 'error',
'import/no-default-export': 'error',
'import/named': 'error',
'flowtype/require-valid-file-annotation': [
'error',
'always',
{ annotationStyle: 'line' },
],
// no-dupe-keys crashes with recent eslint. See
// https://github.com/gajus/eslint-plugin-flowtype/pull/266 and
// https://github.com/gajus/eslint-plugin-flowtype/pull/302
// 'flowtype/no-dupe-keys': 'error',

// overriding recommended rules
'no-constant-condition': ['error', { checkLoops: false }],
Expand Down Expand Up @@ -65,9 +61,6 @@ module.exports = {
'no-self-compare': 'error',
'no-throw-literal': 'error',
'no-unmodified-loop-condition': 'error',
// We use the version from the flowtype plugin so that flow assertions don't
// output an error.
'flowtype/no-unused-expressions': 'error',
'no-useless-call': 'error',
'no-useless-computed-key': 'error',
'no-useless-concat': 'error',
Expand All @@ -83,4 +76,28 @@ module.exports = {
'prefer-spread': 'error',
'no-else-return': 'error',
},
overrides: [
{
// TypeScript linting
files: ['**/*.{ts,tsx}'],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/recommended',
// FIXME: This should be uncommented once we have stricter types.
// 'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-explicit-any': 'off',
},
},
],
};
10 changes: 0 additions & 10 deletions .flowconfig

This file was deleted.

1 change: 0 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
parser: "babel-flow",
};
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ RUN set -x \
# Install the dependencies, including dev dependencies.
&& yarn install --frozen-lockfile \
# Run tests
# Note we don't use test-all because we don't want to start the flow server. So
# we run all test commands separately.
&& yarn flow:ci \
&& yarn ts \
&& yarn lint \
&& yarn test-lockfile \
&& yarn test \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
// This was mostly stolen from https://gist.github.com/nfarina/90ba99a5187113900c86289e67586aaa.
// And then rewritten to remove the dependency to stream-buffers and add the
// `exists` method.
Expand Down Expand Up @@ -46,15 +45,14 @@ class MockBucket {
}

type Metadata = {
+metadata: { ... },
...
metadata: Object;
};

class MockFile {
bucket: MockBucket;
name: string;
contents: Buffer;
metadata: Metadata;
metadata: Partial<Metadata>;
_exists: boolean;

// The constructor doesn't follow the same API as the real type.
Expand All @@ -67,7 +65,7 @@ class MockFile {
}

get(): [MockFile, Metadata] {
return [this, this.metadata];
return [this, this.metadata as Metadata];
}

setMetadata(metadata: Metadata) {
Expand All @@ -82,7 +80,7 @@ class MockFile {
return readable;
}

createWriteStream({ metadata }: Object) {
createWriteStream({ metadata }: any) {
this._exists = true;
this.setMetadata(metadata);
const writable = new Concatenator();
Expand Down
2 changes: 1 addition & 1 deletion bin/check-warn-yarn-changed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @noflow
// MIT © Sindre Sorhus - sindresorhus.com
// via https://gist.github.com/sindresorhus/7996717
// @ts-check

const { execFile } = require('child_process');

Expand Down
2 changes: 1 addition & 1 deletion bin/docker-run.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
// @ts-check

// This file is used to run profiler server docker images in new containers. We
// have to use this moderately complex script because handling of the --mount
Expand Down
14 changes: 3 additions & 11 deletions bin/generate-version-file.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
// @ts-check

/* This script generates the version file, as requested by the dockerflow
* requirements described in
Expand Down Expand Up @@ -32,29 +32,21 @@ function checkEnvironment() {
console.log('We are in the root directory, good!');
}

function getGitCommitHash() /*: string */ {
function getGitCommitHash() {
const hash = execFileSync('git', ['rev-parse', 'HEAD'], {
encoding: 'utf8',
});
// Because execFileSync can return both a string or a buffer depending on the
// `encoding` option, Flow isn't happy about calling `trim` on it. But _we_
// know that it's a string.
// $FlowExpectedError[prop-missing]
return hash.trim();
}

function findLocalBranch() /*: string */ {
function findLocalBranch() {
const branch = execFileSync(
'git',
['symbolic-ref', '--short', '-q', 'HEAD'],
{
encoding: 'utf8',
}
);
// Because execFileSync can return both a string or a buffer depending on the
// `encoding` option, Flow isn't happy about calling `trim` on it. But _we_
// know that it's a string.
// $FlowExpectedError[prop-missing]
return branch.trim();
}

Expand Down
2 changes: 1 addition & 1 deletion bin/post-checkout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @noflow
// @ts-check

const [origHead, head, flag] = process.env.HUSKY_GIT_PARAMS.split(' ');

Expand Down
3 changes: 2 additions & 1 deletion bin/post-merge.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// @noflow
// @ts-check

require('./check-warn-yarn-changed.js')('ORIG_HEAD', 'HEAD');
2 changes: 1 addition & 1 deletion bin/post-rewrite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @noflow
// @ts-check

// This is either 'rebase' or 'amend'.
if (process.env.HUSKY_GIT_PARAMS !== 'rebase') {
Expand Down
47 changes: 34 additions & 13 deletions bin/pre-install.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
// @ts-check

/*:: type AgentsVersion = { [agentName: string]: string }; */
/**
* @typedef {Object.<string, string>} AgentsVersion
*/

/*
* This file is run when a user runs `yarn install`, before doing anything else.
Expand All @@ -22,13 +24,18 @@ function checkVersions() {
return;
}

const agents /*: AgentsVersion */ = userAgent
.split(' ')
.reduce((agents, agent) => {
const [key, value] = agent.split('/');
agents[key] = value;
return agents;
}, {});
/**
* @type {AgentsVersion}
*/
const init = {};
/**
* @type {AgentsVersion}
*/
const agents = userAgent.split(' ').reduce((agents, agent) => {
const [key, value] = agent.split('/');
agents[key] = value;
return agents;
}, init);

const checks = [checkNode(agents), checkYarn(agents)];

Expand All @@ -42,13 +49,23 @@ function checkVersions() {
process.exit(-1);
}

// This function compares two string versions. This compares only major.minor
// and disrespect any textual prevision (like pre or beta).
/**
* This function compares two string versions. This compares only major.minor
* and disrespect any textual prevision (like pre or beta).
*
* @param {string} a
* @param {string} b
* @returns {number}
*/
function versionCompare(a, b) {
return a.localeCompare(b, undefined, { numeric: true });
}

function checkNode(agents /*: AgentsVersion */) {
/**
* @param {AgentsVersion} agents
* @returns {boolean}
*/
function checkNode(agents) {
// Node versions usually have a starting `v`.
const nodeVersion = agents.node.replace(/^v/, '');
const expectedNodeVersion = parseExpectedNodeVersion();
Expand Down Expand Up @@ -76,7 +93,11 @@ function checkNode(agents /*: AgentsVersion */) {
return true;
}

function checkYarn(agents /*: AgentsVersion */) {
/**
* @param {AgentsVersion} agents
* @returns {boolean}
*/
function checkYarn(agents) {
if (!('yarn' in agents)) {
console.error(
'This project uses Yarn instead of npm, please run `yarn install` instead of `npm install`.\n'
Expand Down
5 changes: 2 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow

module.exports = {
collectCoverageFrom: [
'src/**/*.js',
'src/**/*.ts',
'!**/node_modules/**',
'!src/types/libdef/**',
],
setupFilesAfterEnv: ['./test/setup.js'],
setupFilesAfterEnv: ['./test/setup.ts'],
verbose: false,
};
3 changes: 2 additions & 1 deletion loadtest/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def jwt_base64_decode(payload):


def payload_from_raw_data(raw_data):
"""Returns a data suitable to publish, that's accepted by the profiler server.
"""
Returns a data suitable to publish, that's accepted by the profiler server.
This concatenates separate pre-created gzip-compressed chunks, because we
want that we do as less work as possible at runtime. Here at runtime we
Expand Down
3 changes: 2 additions & 1 deletion loadtest/publish_short_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def jwt_base64_decode(payload):


def payload_from_raw_data(raw_data):
"""Returns a data suitable to publish, that's accepted by the profiler server.
"""
Returns a data suitable to publish, that's accepted by the profiler server.
This concatenates separate pre-created gzip-compressed chunks, because we
want that we do as less work as possible at runtime. Here at runtime we
Expand Down
Loading

0 comments on commit 8027cf1

Please sign in to comment.