Skip to content

Commit

Permalink
feat: improve TS types
Browse files Browse the repository at this point in the history
  • Loading branch information
dbstratta committed Jul 25, 2019
1 parent 83f260e commit 0251002
Show file tree
Hide file tree
Showing 7 changed files with 522 additions and 858 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ jobs:

variables:
CI: true
defaultNodeVersion: '12.2.0'
defaultNodeVersion: '12.7.0'

8 changes: 4 additions & 4 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { DangerDSLType, warn } from 'danger';

declare const danger: DangerDSLType;

const warnIfLockfileNotUpdated = () => {
warnIfLockfileNotUpdated();

function warnIfLockfileNotUpdated(): void {
const packageChanged = danger.git.modified_files.includes('package.json');
const lockfileChanged = danger.git.modified_files.includes('yarn.lock');

Expand All @@ -12,6 +14,4 @@ const warnIfLockfileNotUpdated = () => {

warn(`${message} - <em>${idea}</em>`);
}
};

warnIfLockfileNotUpdated();
}
2 changes: 1 addition & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
'*.json': ['prettier --write', 'git add'],
'*.{js,jsx,ts,tsx}': ['prettier-eslint --write', 'git add'],
'*.{js,jsx,ts,tsx}': ['eslint --fix', 'git add'],
};
31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@
"private": false,
"dependencies": {
"debug": "^4.1.1",
"validator": "^11.0.0"
"validator": "^11.1.0"
},
"devDependencies": {
"@babel/cli": "7.5.5",
"@babel/core": "7.5.5",
"@babel/preset-env": "7.5.5",
"@babel/preset-typescript": "7.3.3",
"@commitlint/cli": "7.6.1",
"@commitlint/config-conventional": "7.6.0",
"@commitlint/prompt-cli": "7.6.1",
"@commitlint/travis-cli": "7.6.1",
"@commitlint/cli": "8.1.0",
"@commitlint/config-conventional": "8.1.0",
"@commitlint/prompt-cli": "8.1.0",
"@semantic-release/changelog": "3.0.4",
"@semantic-release/git": "7.0.16",
"@types/debug": "4.1.4",
"@types/jest": "24.0.15",
"@types/node": "11.13.18",
"@types/node": "12.6.8",
"@types/validator": "10.11.2",
"@typescript-eslint/eslint-plugin": "1.13.0",
"@typescript-eslint/parser": "1.13.0",
Expand All @@ -55,10 +54,10 @@
"babel-plugin-dynamic-import-node": "2.3.0",
"codecov": "3.5.0",
"cross-env": "5.2.0",
"danger": "7.1.4",
"eslint": "5.16.0",
"danger": "9.1.3",
"eslint": "6.1.0",
"eslint-config-airbnb-base": "13.2.0",
"eslint-config-prettier": "4.3.0",
"eslint-config-prettier": "6.0.0",
"eslint-plugin-eslint-comments": "3.1.2",
"eslint-plugin-fp": "2.3.0",
"eslint-plugin-import": "2.18.2",
Expand All @@ -67,13 +66,11 @@
"eslint-plugin-prettier": "3.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-security": "1.4.0",
"eslint-plugin-unicorn": "8.0.2",
"husky": "2.7.0",
"eslint-plugin-unicorn": "9.1.1",
"husky": "3.0.1",
"jest": "24.8.0",
"lint-staged": "8.2.1",
"prettier": "1.17.1",
"prettier-eslint": "8.8.2",
"prettier-eslint-cli": "4.7.1",
"lint-staged": "9.2.0",
"prettier": "1.18.2",
"rimraf": "2.6.3",
"semantic-release": "15.13.18",
"typescript": "3.5.3"
Expand All @@ -91,12 +88,12 @@
],
"author": {
"name": "Diego Stratta",
"email": "strattadb@gmail.com",
"email": "dbstratta@gmail.com",
"url": "https://diegostratta.com"
},
"bugs": {
"url": "https://github.com/strattadb/environment/issues",
"email": "strattadb@gmail.com"
"email": "dbstratta@gmail.com"
},
"license": "MIT",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
singleQuote: true,
trailingComma: 'all',
semi: true,
overrides: [
{
files: '*.json',
Expand Down
9 changes: 5 additions & 4 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Parser } from './parsers';
import { logDebug } from './debug';

export type Env<TSchemaData> = {
[TKey in keyof Schema<TSchemaData>]: TSchemaData[TKey]
[TKey in keyof TSchemaData]: TSchemaData[TKey];
};

/**
* A schema defines the environment variable
* requirements.
*/
export type Schema<TSchemaData> = {
[TKey in keyof TSchemaData]: SchemaEntry<TSchemaData[TKey]>
[TKey in keyof TSchemaData]: SchemaEntry<TSchemaData[TKey]>;
};

export type SchemaEntry<TType> = {
Expand All @@ -33,6 +33,7 @@ export type SchemaEntry<TType> = {
export type SchemaEntryRequiredInfo<TType> =
| {
required: true;
defaultValue?: undefined;
}
| {
required: false;
Expand All @@ -46,14 +47,14 @@ export type SchemaEntryRequiredInfo<TType> =
/**
* Returns an env object based on a schema.
*/
export function makeEnv<TSchemaData extends { [key: string]: any }>(
export function makeEnv<TSchemaData extends Record<string, any>>(
schema: Schema<TSchemaData>,
processEnv: NodeJS.ProcessEnv = process.env,
): Env<TSchemaData> {
logDebug('making env object...');

const env = Object.entries(schema).reduce((acc, [key, schemaEntry]) => {
const value = getValue(key, schemaEntry as any, processEnv);
const value = getValue(key, schemaEntry, processEnv);

return { ...acc, [key]: value };
}, {}) as Env<TSchemaData>;
Expand Down
Loading

0 comments on commit 0251002

Please sign in to comment.